Commit 713b8d35 by Ben Clayton

clang-format the src/Reactor directory

Bug: b/144825072 Change-Id: I1f14af4446536c760d11d32aa03edb5f497e75e4 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/39656 Kokoro-Presubmit: kokoro <noreply+kokoro@google.com> Tested-by: 's avatarBen Clayton <bclayton@google.com> Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com>
parent bc1c067b
...@@ -15,16 +15,16 @@ ...@@ -15,16 +15,16 @@
#include "CPUID.hpp" #include "CPUID.hpp"
#if defined(_WIN32) #if defined(_WIN32)
#ifndef WIN32_LEAN_AND_MEAN # ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN # define WIN32_LEAN_AND_MEAN
#endif # endif
#include <windows.h> # include <windows.h>
#include <intrin.h> # include <intrin.h>
#include <float.h> # include <float.h>
#else #else
#include <unistd.h> # include <unistd.h>
#include <sched.h> # include <sched.h>
#include <sys/types.h> # include <sys/types.h>
#endif #endif
namespace rr { namespace rr {
...@@ -162,18 +162,20 @@ void CPUID::setEnableSSE4_1(bool enable) ...@@ -162,18 +162,20 @@ void CPUID::setEnableSSE4_1(bool enable)
static void cpuid(int registers[4], int info) static void cpuid(int registers[4], int info)
{ {
#if defined(__i386__) || defined(__x86_64__) #if defined(__i386__) || defined(__x86_64__)
#if defined(_WIN32) # if defined(_WIN32)
__cpuid(registers, info); __cpuid(registers, info);
#else # else
__asm volatile("cpuid": "=a" (registers[0]), "=b" (registers[1]), "=c" (registers[2]), "=d" (registers[3]): "a" (info)); __asm volatile("cpuid"
#endif : "=a"(registers[0]), "=b"(registers[1]), "=c"(registers[2]), "=d"(registers[3])
#else : "a"(info));
registers[0] = 0; # endif
registers[1] = 0; #else
registers[2] = 0; registers[0] = 0;
registers[3] = 0; registers[1] = 0;
#endif registers[2] = 0;
registers[3] = 0;
#endif
} }
bool CPUID::detectMMX() bool CPUID::detectMMX()
......
...@@ -18,11 +18,11 @@ ...@@ -18,11 +18,11 @@
namespace rr { namespace rr {
#if !defined(__i386__) && defined(_M_IX86) #if !defined(__i386__) && defined(_M_IX86)
#define __i386__ 1 # define __i386__ 1
#endif #endif
#if !defined(__x86_64__) && (defined(_M_AMD64) || defined (_M_X64)) #if !defined(__x86_64__) && (defined(_M_AMD64) || defined(_M_X64))
#define __x86_64__ 1 # define __x86_64__ 1
#endif #endif
class CPUID class CPUID
...@@ -30,7 +30,7 @@ class CPUID ...@@ -30,7 +30,7 @@ class CPUID
public: public:
static bool supportsMMX(); static bool supportsMMX();
static bool supportsCMOV(); static bool supportsCMOV();
static bool supportsMMX2(); // MMX instructions added by SSE: pshufw, pmulhuw, pmovmskb, pavgw/b, pextrw, pinsrw, pmaxsw/ub, etc. static bool supportsMMX2(); // MMX instructions added by SSE: pshufw, pmulhuw, pmovmskb, pavgw/b, pextrw, pinsrw, pmaxsw/ub, etc.
static bool supportsSSE(); static bool supportsSSE();
static bool supportsSSE2(); static bool supportsSSE2();
static bool supportsSSE3(); static bool supportsSSE3();
...@@ -89,7 +89,7 @@ inline bool CPUID::supportsCMOV() ...@@ -89,7 +89,7 @@ inline bool CPUID::supportsCMOV()
inline bool CPUID::supportsMMX2() inline bool CPUID::supportsMMX2()
{ {
return supportsSSE(); // Coincides with 64-bit integer vector instructions supported by SSE return supportsSSE(); // Coincides with 64-bit integer vector instructions supported by SSE
} }
inline bool CPUID::supportsSSE() inline bool CPUID::supportsSSE()
...@@ -119,4 +119,4 @@ inline bool CPUID::supportsSSE4_1() ...@@ -119,4 +119,4 @@ inline bool CPUID::supportsSSE4_1()
} // namespace rr } // namespace rr
#endif // rr_CPUID_hpp #endif // rr_CPUID_hpp
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
#include <memory> #include <memory>
#ifndef rr_ReactorCoroutine_hpp #ifndef rr_ReactorCoroutine_hpp
#define rr_ReactorCoroutine_hpp # define rr_ReactorCoroutine_hpp
namespace rr { namespace rr {
...@@ -26,17 +26,19 @@ class StreamBase ...@@ -26,17 +26,19 @@ class StreamBase
{ {
protected: protected:
StreamBase(const std::shared_ptr<Routine> &routine, Nucleus::CoroutineHandle handle) StreamBase(const std::shared_ptr<Routine> &routine, Nucleus::CoroutineHandle handle)
: routine(routine), handle(handle) {} : routine(routine)
, handle(handle)
{}
~StreamBase() ~StreamBase()
{ {
auto pfn = (Nucleus::CoroutineDestroy*)routine->getEntry(Nucleus::CoroutineEntryDestroy); auto pfn = (Nucleus::CoroutineDestroy *)routine->getEntry(Nucleus::CoroutineEntryDestroy);
pfn(handle); pfn(handle);
} }
bool await(void* out) bool await(void *out)
{ {
auto pfn = (Nucleus::CoroutineAwait*)routine->getEntry(Nucleus::CoroutineEntryAwait); auto pfn = (Nucleus::CoroutineAwait *)routine->getEntry(Nucleus::CoroutineEntryAwait);
return pfn(handle, out); return pfn(handle, out);
} }
...@@ -53,13 +55,14 @@ class Stream : public StreamBase ...@@ -53,13 +55,14 @@ class Stream : public StreamBase
{ {
public: public:
inline Stream(const std::shared_ptr<Routine> &routine, Nucleus::CoroutineHandle handle) inline Stream(const std::shared_ptr<Routine> &routine, Nucleus::CoroutineHandle handle)
: StreamBase(routine, handle) {} : StreamBase(routine, handle)
{}
// await() retrieves the next yielded value from the coroutine. // await() retrieves the next yielded value from the coroutine.
// Returns true if the coroutine yieled a value and out was assigned a // Returns true if the coroutine yieled a value and out was assigned a
// new value. If await() returns false, the coroutine has finished // new value. If await() returns false, the coroutine has finished
// execution and await() will return false for all future calls. // execution and await() will return false for all future calls.
inline bool await(T& out) { return StreamBase::await(&out); } inline bool await(T &out) { return StreamBase::await(&out); }
}; };
template<typename FunctionType> template<typename FunctionType>
...@@ -143,7 +146,7 @@ public: ...@@ -143,7 +146,7 @@ public:
protected: protected:
std::unique_ptr<Nucleus> core; std::unique_ptr<Nucleus> core;
std::shared_ptr<Routine> routine; std::shared_ptr<Routine> routine;
std::vector<Type*> arguments; std::vector<Type *> arguments;
}; };
template<typename Return, typename... Arguments> template<typename Return, typename... Arguments>
...@@ -151,7 +154,7 @@ Coroutine<Return(Arguments...)>::Coroutine() ...@@ -151,7 +154,7 @@ Coroutine<Return(Arguments...)>::Coroutine()
{ {
core.reset(new Nucleus()); core.reset(new Nucleus());
std::vector<Type*> types = {CToReactorT<Arguments>::getType()...}; std::vector<Type *> types = { CToReactorT<Arguments>::getType()... };
for(auto type : types) for(auto type : types)
{ {
if(type != Void::getType()) if(type != Void::getType())
...@@ -180,20 +183,23 @@ Coroutine<Return(Arguments...)>::operator()(Arguments... args) ...@@ -180,20 +183,23 @@ Coroutine<Return(Arguments...)>::operator()(Arguments... args)
finalize(); finalize();
using Sig = Nucleus::CoroutineBegin<Arguments...>; using Sig = Nucleus::CoroutineBegin<Arguments...>;
auto pfn = (Sig*)routine->getEntry(Nucleus::CoroutineEntryBegin); auto pfn = (Sig *)routine->getEntry(Nucleus::CoroutineEntryBegin);
auto handle = pfn(args...); auto handle = pfn(args...);
return std::unique_ptr<Stream<Return>>(new Stream<Return>(routine, handle)); return std::unique_ptr<Stream<Return>>(new Stream<Return>(routine, handle));
} }
#ifdef Yield // Defined in WinBase.h # ifdef Yield // Defined in WinBase.h
#undef Yield # undef Yield
#endif # endif
// Suspends execution of the coroutine and yields val to the caller. // Suspends execution of the coroutine and yields val to the caller.
// Execution of the coroutine will resume after val is retrieved. // Execution of the coroutine will resume after val is retrieved.
template<typename T> template<typename T>
inline void Yield(const T &val) { Nucleus::yield(ValueOf(val)); } inline void Yield(const T &val)
{
Nucleus::yield(ValueOf(val));
}
} // namespace rr } // namespace rr
#endif // rr_ReactorCoroutine_hpp #endif // rr_ReactorCoroutine_hpp
\ No newline at end of file \ No newline at end of file
...@@ -14,8 +14,8 @@ ...@@ -14,8 +14,8 @@
#include "Debug.hpp" #include "Debug.hpp"
#include <string>
#include <stdarg.h> #include <stdarg.h>
#include <string>
namespace rr { namespace rr {
......
...@@ -17,18 +17,18 @@ ...@@ -17,18 +17,18 @@
#ifndef rr_DEBUG_H_ #ifndef rr_DEBUG_H_
#define rr_DEBUG_H_ #define rr_DEBUG_H_
#include <stdlib.h>
#include <assert.h> #include <assert.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#if !defined(TRACE_OUTPUT_FILE) #if !defined(TRACE_OUTPUT_FILE)
#define TRACE_OUTPUT_FILE "debug.txt" # define TRACE_OUTPUT_FILE "debug.txt"
#endif #endif
#if defined(__GNUC__) || defined(__clang__) #if defined(__GNUC__) || defined(__clang__)
#define CHECK_PRINTF_ARGS __attribute__((format(printf, 1, 2))) # define CHECK_PRINTF_ARGS __attribute__((format(printf, 1, 2)))
#else #else
#define CHECK_PRINTF_ARGS # define CHECK_PRINTF_ARGS
#endif #endif
namespace rr { namespace rr {
...@@ -49,9 +49,9 @@ void abort(const char *format, ...) CHECK_PRINTF_ARGS; ...@@ -49,9 +49,9 @@ void abort(const char *format, ...) CHECK_PRINTF_ARGS;
// A macro to output a trace of a function call and its arguments to the // A macro to output a trace of a function call and its arguments to the
// debugging log. Disabled if RR_DISABLE_TRACE is defined. // debugging log. Disabled if RR_DISABLE_TRACE is defined.
#if defined(RR_DISABLE_TRACE) #if defined(RR_DISABLE_TRACE)
#define TRACE(message, ...) (void(0)) # define TRACE(message, ...) (void(0))
#else #else
#define TRACE(message, ...) rr::trace("%s:%d TRACE: " message "\n", __FILE__, __LINE__, ##__VA_ARGS__) # define TRACE(message, ...) rr::trace("%s:%d TRACE: " message "\n", __FILE__, __LINE__, ##__VA_ARGS__)
#endif #endif
// A macro to print a warning message to the debugging log and stderr to denote // A macro to print a warning message to the debugging log and stderr to denote
...@@ -75,26 +75,34 @@ void abort(const char *format, ...) CHECK_PRINTF_ARGS; ...@@ -75,26 +75,34 @@ void abort(const char *format, ...) CHECK_PRINTF_ARGS;
// WARN() in release builds (NDEBUG && !DCHECK_ALWAYS_ON) // WARN() in release builds (NDEBUG && !DCHECK_ALWAYS_ON)
#undef DABORT #undef DABORT
#if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON) #if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)
#define DABORT(message, ...) ABORT(message, ##__VA_ARGS__) # define DABORT(message, ...) ABORT(message, ##__VA_ARGS__)
#else #else
#define DABORT(message, ...) WARN(message, ##__VA_ARGS__) # define DABORT(message, ...) WARN(message, ##__VA_ARGS__)
#endif #endif
// A macro asserting a condition. // A macro asserting a condition.
// If the condition fails, the condition and message is passed to DABORT(). // If the condition fails, the condition and message is passed to DABORT().
#undef ASSERT_MSG #undef ASSERT_MSG
#define ASSERT_MSG(expression, format, ...) do { \ #define ASSERT_MSG(expression, format, ...) \
if(!(expression)) { \ do \
DABORT("ASSERT(%s): " format "\n", #expression, ##__VA_ARGS__); \ { \
} } while(0) if(!(expression)) \
{ \
DABORT("ASSERT(%s): " format "\n", #expression, ##__VA_ARGS__); \
} \
} while(0)
// A macro asserting a condition. // A macro asserting a condition.
// If the condition fails, the condition is passed to DABORT(). // If the condition fails, the condition is passed to DABORT().
#undef ASSERT #undef ASSERT
#define ASSERT(expression) do { \ #define ASSERT(expression) \
if(!(expression)) { \ do \
DABORT("ASSERT(%s)\n", #expression); \ { \
} } while(0) if(!(expression)) \
{ \
DABORT("ASSERT(%s)\n", #expression); \
} \
} while(0)
// A macro to indicate unimplemented functionality. // A macro to indicate unimplemented functionality.
#undef UNIMPLEMENTED #undef UNIMPLEMENTED
...@@ -107,12 +115,16 @@ void abort(const char *format, ...) CHECK_PRINTF_ARGS; ...@@ -107,12 +115,16 @@ void abort(const char *format, ...) CHECK_PRINTF_ARGS;
// A macro asserting a condition and performing a return. // A macro asserting a condition and performing a return.
#undef ASSERT_OR_RETURN #undef ASSERT_OR_RETURN
#if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON) #if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)
#define ASSERT_OR_RETURN(expression) ASSERT(expression) # define ASSERT_OR_RETURN(expression) ASSERT(expression)
#else #else
#define ASSERT_OR_RETURN(expression) do { \ # define ASSERT_OR_RETURN(expression) \
if(!(expression)) { \ do \
return; \ { \
} } while(0) if(!(expression)) \
{ \
return; \
} \
} while(0)
#endif #endif
#endif // rr_DEBUG_H_ #endif // rr_DEBUG_H_
...@@ -14,16 +14,16 @@ ...@@ -14,16 +14,16 @@
#include "DebugAndroid.hpp" #include "DebugAndroid.hpp"
#include <cutils/properties.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h>
#include <sys/types.h> #include <sys/types.h>
#include <cutils/properties.h> #include <unistd.h>
void AndroidEnterDebugger() void AndroidEnterDebugger()
{ {
ALOGE(__FUNCTION__); ALOGE(__FUNCTION__);
#ifndef NDEBUG #ifndef NDEBUG
static volatile int * const makefault = nullptr; static volatile int *const makefault = nullptr;
char value[PROPERTY_VALUE_MAX]; char value[PROPERTY_VALUE_MAX];
property_get("debug.db.uid", value, "-1"); property_get("debug.db.uid", value, "-1");
int debug_uid = atoi(value); int debug_uid = atoi(value);
...@@ -31,7 +31,8 @@ void AndroidEnterDebugger() ...@@ -31,7 +31,8 @@ void AndroidEnterDebugger()
{ {
ALOGE("Waiting for debugger: gdbserver :${PORT} --attach %u. Look for thread %u", getpid(), gettid()); ALOGE("Waiting for debugger: gdbserver :${PORT} --attach %u. Look for thread %u", getpid(), gettid());
volatile int waiting = 1; volatile int waiting = 1;
while(waiting) { while(waiting)
{
sleep(1); sleep(1);
} }
} }
......
...@@ -16,11 +16,11 @@ ...@@ -16,11 +16,11 @@
#define DebugAndroid_hpp #define DebugAndroid_hpp
#if ANDROID_PLATFORM_SDK_VERSION < 27 #if ANDROID_PLATFORM_SDK_VERSION < 27
#include <cutils/log.h> # include <cutils/log.h>
#elif ANDROID_PLATFORM_SDK_VERSION >= 27 #elif ANDROID_PLATFORM_SDK_VERSION >= 27
#include <log/log.h> # include <log/log.h>
#else #else
#error "ANDROID_PLATFORM_SDK_VERSION is not defined" # error "ANDROID_PLATFORM_SDK_VERSION is not defined"
#endif #endif
#include <cassert> #include <cassert>
...@@ -48,52 +48,61 @@ ...@@ -48,52 +48,61 @@
*/ */
void AndroidEnterDebugger(); void AndroidEnterDebugger();
#define ASSERT(E) do { \ #define ASSERT(E) \
if(!(E)) { \ do \
ALOGE("badness: assertion_failed %s in %s at %s:%d", #E, \ { \
__FUNCTION__, __FILE__, __LINE__); \ if(!(E)) \
AndroidEnterDebugger(); \ { \
} \ ALOGE("badness: assertion_failed %s in %s at %s:%d", #E, \
__FUNCTION__, __FILE__, __LINE__); \
AndroidEnterDebugger(); \
} \
} while(0) } while(0)
#undef assert #undef assert
#define assert(E) ASSERT(E) #define assert(E) ASSERT(E)
#define ERR(format, ...) \ #define ERR(format, ...) \
do { \ do \
{ \
ALOGE("badness: err %s %s:%d (" format ")", __FUNCTION__, __FILE__, \ ALOGE("badness: err %s %s:%d (" format ")", __FUNCTION__, __FILE__, \
__LINE__, ##__VA_ARGS__); \ __LINE__, ##__VA_ARGS__); \
AndroidEnterDebugger(); \ AndroidEnterDebugger(); \
} while(0) } while(0)
#define FIXME(format, ...) \ #define FIXME(format, ...) \
do { \ do \
{ \
ALOGE("badness: fixme %s %s:%d (" format ")", __FUNCTION__, __FILE__, \ ALOGE("badness: fixme %s %s:%d (" format ")", __FUNCTION__, __FILE__, \
__LINE__, ##__VA_ARGS__); \ __LINE__, ##__VA_ARGS__); \
AndroidEnterDebugger(); \ AndroidEnterDebugger(); \
} while(0) } while(0)
// TODO: Handle __VA_ARGS__ (can be empty) // TODO: Handle __VA_ARGS__ (can be empty)
#define UNIMPLEMENTED(...) do { \ #define UNIMPLEMENTED(...) \
ALOGE("badness: unimplemented: %s %s:%d", \ do \
__FUNCTION__, __FILE__, __LINE__); \ { \
AndroidEnterDebugger(); \ ALOGE("badness: unimplemented: %s %s:%d", \
__FUNCTION__, __FILE__, __LINE__); \
AndroidEnterDebugger(); \
} while(0) } while(0)
#define UNREACHABLE(value) do { \ #define UNREACHABLE(value) \
do \
{ \
ALOGE("badness: unreachable case reached: %s %s:%d. %s: %d", \ ALOGE("badness: unreachable case reached: %s %s:%d. %s: %d", \
__FUNCTION__, __FILE__, __LINE__, #value, value); \ __FUNCTION__, __FILE__, __LINE__, #value, value); \
AndroidEnterDebugger(); \ AndroidEnterDebugger(); \
} while(0) } while(0)
#ifndef NDEBUG #ifndef NDEBUG
#define TRACE(format, ...) \ # define TRACE(format, ...) \
ALOGV("%s %s:%d (" format ")", __FUNCTION__, __FILE__, \ ALOGV("%s %s:%d (" format ")", __FUNCTION__, __FILE__, \
__LINE__, ##__VA_ARGS__) __LINE__, ##__VA_ARGS__)
#else #else
#define TRACE(...) ((void)0) # define TRACE(...) ((void)0)
#endif #endif
void trace(const char *format, ...); void trace(const char *format, ...);
#endif // DebugAndroid_hpp #endif // DebugAndroid_hpp
...@@ -7,18 +7,18 @@ ...@@ -7,18 +7,18 @@
namespace rr { namespace rr {
namespace { namespace {
template <typename T> template<typename T>
struct UnderlyingType struct UnderlyingType
{ {
using Type = typename decltype(rr::Extract(std::declval<RValue<T>>(), 0))::rvalue_underlying_type; using Type = typename decltype(rr::Extract(std::declval<RValue<T>>(), 0))::rvalue_underlying_type;
}; };
template <typename T> template<typename T>
using UnderlyingTypeT = typename UnderlyingType<T>::Type; using UnderlyingTypeT = typename UnderlyingType<T>::Type;
// Call single arg function on a vector type // Call single arg function on a vector type
template <typename Func, typename T> template<typename Func, typename T>
RValue<T> call4(Func func, const RValue<T>& x) RValue<T> call4(Func func, const RValue<T> &x)
{ {
T result; T result;
result = Insert(result, Call(func, Extract(x, 0)), 0); result = Insert(result, Call(func, Extract(x, 0)), 0);
...@@ -29,8 +29,8 @@ RValue<T> call4(Func func, const RValue<T>& x) ...@@ -29,8 +29,8 @@ RValue<T> call4(Func func, const RValue<T>& x)
} }
// Call two arg function on a vector type // Call two arg function on a vector type
template <typename Func, typename T> template<typename Func, typename T>
RValue<T> call4(Func func, const RValue<T>& x, const RValue<T>& y) RValue<T> call4(Func func, const RValue<T> &x, const RValue<T> &y)
{ {
T result; T result;
result = Insert(result, Call(func, Extract(x, 0), Extract(y, 0)), 0); result = Insert(result, Call(func, Extract(x, 0), Extract(y, 0)), 0);
...@@ -40,8 +40,8 @@ RValue<T> call4(Func func, const RValue<T>& x, const RValue<T>& y) ...@@ -40,8 +40,8 @@ RValue<T> call4(Func func, const RValue<T>& x, const RValue<T>& y)
return result; return result;
} }
template <typename T, typename EL = UnderlyingTypeT<T>> template<typename T, typename EL = UnderlyingTypeT<T>>
void gather(T& out, RValue<Pointer<EL>> base, RValue<Int4> offsets, RValue<Int4> mask, unsigned int alignment, bool zeroMaskedLanes) void gather(T &out, RValue<Pointer<EL>> base, RValue<Int4> offsets, RValue<Int4> mask, unsigned int alignment, bool zeroMaskedLanes)
{ {
constexpr bool atomic = false; constexpr bool atomic = false;
constexpr std::memory_order order = std::memory_order_relaxed; constexpr std::memory_order order = std::memory_order_relaxed;
...@@ -64,7 +64,7 @@ void gather(T& out, RValue<Pointer<EL>> base, RValue<Int4> offsets, RValue<Int4> ...@@ -64,7 +64,7 @@ void gather(T& out, RValue<Pointer<EL>> base, RValue<Int4> offsets, RValue<Int4>
} }
} }
template <typename T, typename EL = UnderlyingTypeT<T>> template<typename T, typename EL = UnderlyingTypeT<T>>
void scatter(RValue<Pointer<EL>> base, RValue<T> val, RValue<Int4> offsets, RValue<Int4> mask, unsigned int alignment) void scatter(RValue<Pointer<EL>> base, RValue<T> val, RValue<Int4> offsets, RValue<Int4> mask, unsigned int alignment)
{ {
constexpr bool atomic = false; constexpr bool atomic = false;
......
...@@ -23,7 +23,8 @@ namespace rr { ...@@ -23,7 +23,8 @@ namespace rr {
size_t memoryPageSize(); size_t memoryPageSize();
enum MemoryPermission { enum MemoryPermission
{
PERMISSION_READ = 1, PERMISSION_READ = 1,
PERMISSION_WRITE = 2, PERMISSION_WRITE = 2,
PERMISSION_EXECUTE = 4, PERMISSION_EXECUTE = 4,
...@@ -31,7 +32,7 @@ enum MemoryPermission { ...@@ -31,7 +32,7 @@ enum MemoryPermission {
// Allocates memory with the specified permissions. If |need_exec| is true then // Allocates memory with the specified permissions. If |need_exec| is true then
// the allocate memory can be made marked executable using protectMemoryPages(). // the allocate memory can be made marked executable using protectMemoryPages().
void* allocateMemoryPages(size_t bytes, int permissions, bool need_exec); void *allocateMemoryPages(size_t bytes, int permissions, bool need_exec);
// Sets permissions for memory allocated with allocateMemoryPages(). // Sets permissions for memory allocated with allocateMemoryPages().
void protectMemoryPages(void *memory, size_t bytes, int permissions); void protectMemoryPages(void *memory, size_t bytes, int permissions);
...@@ -58,7 +59,9 @@ template<typename P> ...@@ -58,7 +59,9 @@ template<typename P>
class unaligned_ref class unaligned_ref
{ {
public: public:
explicit unaligned_ref(void *ptr) : ptr((P*)ptr) {} explicit unaligned_ref(void *ptr)
: ptr((P *)ptr)
{}
template<typename V> template<typename V>
P operator=(V value) P operator=(V value)
...@@ -69,7 +72,7 @@ public: ...@@ -69,7 +72,7 @@ public:
operator P() operator P()
{ {
return unaligned_read((P*)ptr); return unaligned_read((P *)ptr);
} }
private: private:
...@@ -83,7 +86,9 @@ class unaligned_ptr ...@@ -83,7 +86,9 @@ class unaligned_ptr
friend class unaligned_ptr; friend class unaligned_ptr;
public: public:
unaligned_ptr(P *ptr) : ptr(ptr) {} unaligned_ptr(P *ptr)
: ptr(ptr)
{}
unaligned_ref<P> operator*() unaligned_ref<P> operator*()
{ {
...@@ -102,4 +107,4 @@ private: ...@@ -102,4 +107,4 @@ private:
} // namespace rr } // namespace rr
#endif // rr_ExecutableMemory_hpp #endif // rr_ExecutableMemory_hpp
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -31,17 +31,17 @@ llvm::Type *T(Type *t); ...@@ -31,17 +31,17 @@ llvm::Type *T(Type *t);
inline Type *T(llvm::Type *t) inline Type *T(llvm::Type *t)
{ {
return reinterpret_cast<Type*>(t); return reinterpret_cast<Type *>(t);
} }
inline llvm::Value *V(Value *t) inline llvm::Value *V(Value *t)
{ {
return reinterpret_cast<llvm::Value*>(t); return reinterpret_cast<llvm::Value *>(t);
} }
inline Value *V(llvm::Value *t) inline Value *V(llvm::Value *t)
{ {
return reinterpret_cast<Value*>(t); return reinterpret_cast<Value *>(t);
} }
// Emits a no-op instruction that will not be optimized away. // Emits a no-op instruction that will not be optimized away.
...@@ -51,4 +51,4 @@ void Nop(); ...@@ -51,4 +51,4 @@ void Nop();
} // namespace rr } // namespace rr
#endif // rr_LLVMReactor_hpp #endif // rr_LLVMReactor_hpp
...@@ -19,10 +19,10 @@ ...@@ -19,10 +19,10 @@
#ifdef ENABLE_RR_DEBUG_INFO #ifdef ENABLE_RR_DEBUG_INFO
#include <unordered_set> # include <memory>
#include <unordered_map> # include <unordered_map>
#include <vector> # include <unordered_set>
#include <memory> # include <vector>
// Forward declarations // Forward declarations
namespace llvm { namespace llvm {
...@@ -46,12 +46,12 @@ class Module; ...@@ -46,12 +46,12 @@ class Module;
class Type; class Type;
class Value; class Value;
namespace object namespace object {
{ class ObjectFile;
class ObjectFile;
} }
template <typename T, typename Inserter> class IRBuilder; template<typename T, typename Inserter>
class IRBuilder;
} // namespace llvm } // namespace llvm
...@@ -68,9 +68,9 @@ public: ...@@ -68,9 +68,9 @@ public:
using IRBuilder = llvm::IRBuilder<llvm::ConstantFolder, llvm::IRBuilderDefaultInserter>; using IRBuilder = llvm::IRBuilder<llvm::ConstantFolder, llvm::IRBuilderDefaultInserter>;
DebugInfo(IRBuilder *builder, DebugInfo(IRBuilder *builder,
llvm::LLVMContext *context, llvm::LLVMContext *context,
llvm::Module *module, llvm::Module *module,
llvm::Function *function); llvm::Function *function);
~DebugInfo(); ~DebugInfo();
...@@ -116,15 +116,15 @@ private: ...@@ -116,15 +116,15 @@ private:
std::string name; std::string name;
std::string file; std::string file;
bool operator == (const FunctionLocation &rhs) const { return name == rhs.name && file == rhs.file; } bool operator==(const FunctionLocation &rhs) const { return name == rhs.name && file == rhs.file; }
bool operator != (const FunctionLocation &rhs) const { return !(*this == rhs); } bool operator!=(const FunctionLocation &rhs) const { return !(*this == rhs); }
struct Hash struct Hash
{ {
std::size_t operator()(const FunctionLocation &l) const noexcept std::size_t operator()(const FunctionLocation &l) const noexcept
{ {
return std::hash<std::string>()(l.file) * 31 + return std::hash<std::string>()(l.file) * 31 +
std::hash<std::string>()(l.name); std::hash<std::string>()(l.name);
} }
}; };
}; };
...@@ -134,15 +134,15 @@ private: ...@@ -134,15 +134,15 @@ private:
FunctionLocation function; FunctionLocation function;
unsigned int line = 0; unsigned int line = 0;
bool operator == (const Location &rhs) const { return function == rhs.function && line == rhs.line; } bool operator==(const Location &rhs) const { return function == rhs.function && line == rhs.line; }
bool operator != (const Location &rhs) const { return !(*this == rhs); } bool operator!=(const Location &rhs) const { return !(*this == rhs); }
struct Hash struct Hash
{ {
std::size_t operator()(const Location &l) const noexcept std::size_t operator()(const Location &l) const noexcept
{ {
return FunctionLocation::Hash()(l.function) * 31 + return FunctionLocation::Hash()(l.function) * 31 +
std::hash<unsigned int>()(l.line); std::hash<unsigned int>()(l.line);
} }
}; };
}; };
...@@ -181,14 +181,14 @@ private: ...@@ -181,14 +181,14 @@ private:
// frames will be returned. // frames will be returned.
Backtrace getCallerBacktrace(size_t limit = 0) const; Backtrace getCallerBacktrace(size_t limit = 0) const;
llvm::DILocation* getLocation(const Backtrace &backtrace, size_t i); llvm::DILocation *getLocation(const Backtrace &backtrace, size_t i);
llvm::DIType *getOrCreateType(llvm::Type* type); llvm::DIType *getOrCreateType(llvm::Type *type);
llvm::DIFile *getOrCreateFile(const char* path); llvm::DIFile *getOrCreateFile(const char *path);
LineTokens const *getOrParseFileTokens(const char* path); LineTokens const *getOrParseFileTokens(const char *path);
// Synchronizes diScope with the current backtrace. // Synchronizes diScope with the current backtrace.
void syncScope(Backtrace const& backtrace); void syncScope(Backtrace const &backtrace);
IRBuilder *builder; IRBuilder *builder;
llvm::LLVMContext *context; llvm::LLVMContext *context;
...@@ -200,14 +200,14 @@ private: ...@@ -200,14 +200,14 @@ private:
llvm::DISubprogram *diSubprogram; llvm::DISubprogram *diSubprogram;
llvm::DILocation *diRootLocation; llvm::DILocation *diRootLocation;
std::vector<Scope> diScope; std::vector<Scope> diScope;
std::unordered_map<std::string, llvm::DIFile*> diFiles; std::unordered_map<std::string, llvm::DIFile *> diFiles;
std::unordered_map<llvm::Type*, llvm::DIType*> diTypes; std::unordered_map<llvm::Type *, llvm::DIType *> diTypes;
std::unordered_map<std::string, std::unique_ptr<LineTokens>> fileTokens; std::unordered_map<std::string, std::unique_ptr<LineTokens>> fileTokens;
std::vector<void const*> pushed; std::vector<void const *> pushed;
}; };
} // namespace rr } // namespace rr
#endif // ENABLE_RR_DEBUG_INFO #endif // ENABLE_RR_DEBUG_INFO
#endif // rr_LLVMReactorDebugInfo_hpp #endif // rr_LLVMReactorDebugInfo_hpp
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
#if defined(__linux__) #if defined(__linux__)
// Use a pthread mutex on Linux. Since many processes may use Reactor // Use a pthread mutex on Linux. Since many processes may use Reactor
// at the same time it's best to just have the scheduler overhead. // at the same time it's best to just have the scheduler overhead.
#include <pthread.h> # include <pthread.h>
namespace rr { namespace rr {
...@@ -58,9 +58,9 @@ private: ...@@ -58,9 +58,9 @@ private:
} // namespace rr } // namespace rr
#else // !__linux__ #else // !__linux__
#include <atomic> # include <atomic>
namespace rr { namespace rr {
...@@ -174,6 +174,6 @@ using MutexLock = BackoffLock; ...@@ -174,6 +174,6 @@ using MutexLock = BackoffLock;
} // namespace rr } // namespace rr
#endif // !__linux__ #endif // !__linux__
#endif // rr_MutexLock_hpp #endif // rr_MutexLock_hpp
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
#include <vector> #include <vector>
#ifdef None #ifdef None
#undef None // TODO(b/127920555) # undef None // TODO(b/127920555)
#endif #endif
static_assert(sizeof(short) == 2, "Reactor's 'Short' type is 16-bit, and requires the C++ 'short' to match that."); static_assert(sizeof(short) == 2, "Reactor's 'Short' type is 16-bit, and requires the C++ 'short' to match that.");
...@@ -68,18 +68,19 @@ public: ...@@ -68,18 +68,19 @@ public:
using Passes = std::vector<Pass>; using Passes = std::vector<Pass>;
Optimization(Level level = Level::Default, const Passes& passes = {}) Optimization(Level level = Level::Default, const Passes &passes = {})
: level(level), passes(passes) : level(level)
, passes(passes)
{ {
#if defined(REACTOR_DEFAULT_OPT_LEVEL) #if defined(REACTOR_DEFAULT_OPT_LEVEL)
{ {
this->level = Level::REACTOR_DEFAULT_OPT_LEVEL; this->level = Level::REACTOR_DEFAULT_OPT_LEVEL;
} }
#endif #endif
} }
Level getLevel() const { return level; } Level getLevel() const { return level; }
const Passes & getPasses() const { return passes; } const Passes &getPasses() const { return passes; }
private: private:
Level level = Level::Default; Level level = Level::Default;
...@@ -98,19 +99,41 @@ public: ...@@ -98,19 +99,41 @@ public:
public: public:
static const Edit None; static const Edit None;
Edit & set(Optimization::Level level) { optLevel = level; optLevelChanged = true; return *this; } Edit &set(Optimization::Level level)
Edit & add(Optimization::Pass pass) { optPassEdits.push_back({ListEdit::Add, pass}); return *this; } {
Edit & remove(Optimization::Pass pass) { optPassEdits.push_back({ListEdit::Remove, pass}); return *this; } optLevel = level;
Edit & clearOptimizationPasses() { optPassEdits.push_back({ListEdit::Clear, Optimization::Pass::Disabled}); return *this; } optLevelChanged = true;
return *this;
}
Edit &add(Optimization::Pass pass)
{
optPassEdits.push_back({ ListEdit::Add, pass });
return *this;
}
Edit &remove(Optimization::Pass pass)
{
optPassEdits.push_back({ ListEdit::Remove, pass });
return *this;
}
Edit &clearOptimizationPasses()
{
optPassEdits.push_back({ ListEdit::Clear, Optimization::Pass::Disabled });
return *this;
}
Config apply(const Config &cfg) const; Config apply(const Config &cfg) const;
private: private:
enum class ListEdit { Add, Remove, Clear }; enum class ListEdit
{
Add,
Remove,
Clear
};
using OptPassesEdit = std::pair<ListEdit, Optimization::Pass>; using OptPassesEdit = std::pair<ListEdit, Optimization::Pass>;
template <typename T> template<typename T>
void apply(const std::vector<std::pair<ListEdit, T>> & edits, std::vector<T>& list) const; void apply(const std::vector<std::pair<ListEdit, T>> &edits, std::vector<T> &list) const;
Optimization::Level optLevel; Optimization::Level optLevel;
bool optLevelChanged = false; bool optLevelChanged = false;
...@@ -118,9 +141,11 @@ public: ...@@ -118,9 +141,11 @@ public:
}; };
Config() = default; Config() = default;
Config(const Optimization & optimization) : optimization(optimization) {} Config(const Optimization &optimization)
: optimization(optimization)
{}
const Optimization & getOptimization() const { return optimization; } const Optimization &getOptimization() const { return optimization; }
private: private:
Optimization optimization; Optimization optimization;
...@@ -146,15 +171,15 @@ public: ...@@ -146,15 +171,15 @@ public:
static BasicBlock *getInsertBlock(); static BasicBlock *getInsertBlock();
static void setInsertBlock(BasicBlock *basicBlock); static void setInsertBlock(BasicBlock *basicBlock);
static void createFunction(Type *ReturnType, std::vector<Type*> &Params); static void createFunction(Type *ReturnType, std::vector<Type *> &Params);
static Value *getArgument(unsigned int index); static Value *getArgument(unsigned int index);
// Coroutines // Coroutines
using CoroutineHandle = void*; using CoroutineHandle = void *;
template <typename... ARGS> template<typename... ARGS>
using CoroutineBegin = CoroutineHandle(ARGS...); using CoroutineBegin = CoroutineHandle(ARGS...);
using CoroutineAwait = bool(CoroutineHandle, void* yieldValue); using CoroutineAwait = bool(CoroutineHandle, void *yieldValue);
using CoroutineDestroy = void(CoroutineHandle); using CoroutineDestroy = void(CoroutineHandle);
enum CoroutineEntries enum CoroutineEntries
...@@ -165,9 +190,9 @@ public: ...@@ -165,9 +190,9 @@ public:
CoroutineEntryCount CoroutineEntryCount
}; };
static void createCoroutine(Type *ReturnType, std::vector<Type*> &Params); static void createCoroutine(Type *ReturnType, std::vector<Type *> &Params);
std::shared_ptr<Routine> acquireCoroutine(const char *name, const Config::Edit &cfg = Config::Edit::None); std::shared_ptr<Routine> acquireCoroutine(const char *name, const Config::Edit &cfg = Config::Edit::None);
static void yield(Value*); static void yield(Value *);
// Terminators // Terminators
static void createRetVoid(); static void createRetVoid();
...@@ -201,7 +226,7 @@ public: ...@@ -201,7 +226,7 @@ public:
static Value *createNot(Value *V); static Value *createNot(Value *V);
// Memory instructions // Memory instructions
static Value *createLoad(Value *ptr, Type *type, bool isVolatile = false, unsigned int alignment = 0, bool atomic = false , std::memory_order memoryOrder = std::memory_order_relaxed); static Value *createLoad(Value *ptr, Type *type, bool isVolatile = false, unsigned int alignment = 0, bool atomic = false, std::memory_order memoryOrder = std::memory_order_relaxed);
static Value *createStore(Value *value, Value *ptr, Type *type, bool isVolatile = false, unsigned int aligment = 0, bool atomic = false, std::memory_order memoryOrder = std::memory_order_relaxed); static Value *createStore(Value *value, Value *ptr, Type *type, bool isVolatile = false, unsigned int aligment = 0, bool atomic = false, std::memory_order memoryOrder = std::memory_order_relaxed);
static Value *createGEP(Value *ptr, Type *type, Value *index, bool unsignedIndex); static Value *createGEP(Value *ptr, Type *type, Value *index, bool unsignedIndex);
...@@ -294,4 +319,4 @@ public: ...@@ -294,4 +319,4 @@ public:
} // namespace rr } // namespace rr
#endif // rr_Nucleus_hpp #endif // rr_Nucleus_hpp
...@@ -50,45 +50,45 @@ private: ...@@ -50,45 +50,45 @@ private:
Ice::Cfg *function; Ice::Cfg *function;
Ice::GlobalContext *context; Ice::GlobalContext *context;
struct Uses : std::vector<Ice::Inst*> struct Uses : std::vector<Ice::Inst *>
{ {
bool areOnlyLoadStore() const; bool areOnlyLoadStore() const;
void insert(Ice::Operand *value, Ice::Inst *instruction); void insert(Ice::Operand *value, Ice::Inst *instruction);
void erase(Ice::Inst *instruction); void erase(Ice::Inst *instruction);
std::vector<Ice::Inst*> loads; std::vector<Ice::Inst *> loads;
std::vector<Ice::Inst*> stores; std::vector<Ice::Inst *> stores;
}; };
struct LoadStoreInst struct LoadStoreInst
{ {
LoadStoreInst(Ice::Inst* inst, bool isStore) LoadStoreInst(Ice::Inst *inst, bool isStore)
: inst(inst), : inst(inst)
address(isStore ? storeAddress(inst) : loadAddress(inst)), , address(isStore ? storeAddress(inst) : loadAddress(inst))
isStore(isStore) , isStore(isStore)
{ {
} }
Ice::Inst* inst; Ice::Inst *inst;
Ice::Operand *address; Ice::Operand *address;
bool isStore; bool isStore;
}; };
Optimizer::Uses* getUses(Ice::Operand*); Optimizer::Uses *getUses(Ice::Operand *);
void setUses(Ice::Operand*, Optimizer::Uses*); void setUses(Ice::Operand *, Optimizer::Uses *);
bool hasUses(Ice::Operand*) const; bool hasUses(Ice::Operand *) const;
Ice::CfgNode* getNode(Ice::Inst*); Ice::CfgNode *getNode(Ice::Inst *);
void setNode(Ice::Inst*, Ice::CfgNode*); void setNode(Ice::Inst *, Ice::CfgNode *);
Ice::Inst* getDefinition(Ice::Variable*); Ice::Inst *getDefinition(Ice::Variable *);
void setDefinition(Ice::Variable*, Ice::Inst*); void setDefinition(Ice::Variable *, Ice::Inst *);
const std::vector<LoadStoreInst>& getLoadStoreInsts(Ice::CfgNode*); const std::vector<LoadStoreInst> &getLoadStoreInsts(Ice::CfgNode *);
void setLoadStoreInsts(Ice::CfgNode*, std::vector<LoadStoreInst>*); void setLoadStoreInsts(Ice::CfgNode *, std::vector<LoadStoreInst> *);
bool hasLoadStoreInsts(Ice::CfgNode* node) const; bool hasLoadStoreInsts(Ice::CfgNode *node) const;
std::vector<Optimizer::Uses*> allocatedUses; std::vector<Optimizer::Uses *> allocatedUses;
}; };
void Optimizer::run(Ice::Cfg *function) void Optimizer::run(Ice::Cfg *function)
...@@ -133,8 +133,7 @@ void Optimizer::eliminateDeadCode() ...@@ -133,8 +133,7 @@ void Optimizer::eliminateDeadCode()
} }
} }
} }
} } while(modified);
while(modified);
} }
void Optimizer::eliminateUnitializedLoads() void Optimizer::eliminateUnitializedLoads()
...@@ -150,7 +149,7 @@ void Optimizer::eliminateUnitializedLoads() ...@@ -150,7 +149,7 @@ void Optimizer::eliminateUnitializedLoads()
if(!llvm::isa<Ice::InstAlloca>(alloca)) if(!llvm::isa<Ice::InstAlloca>(alloca))
{ {
break; // Allocas are all at the top break; // Allocas are all at the top
} }
Ice::Operand *address = alloca.getDest(); Ice::Operand *address = alloca.getDest();
...@@ -213,7 +212,7 @@ void Optimizer::eliminateLoadsFollowingSingleStore() ...@@ -213,7 +212,7 @@ void Optimizer::eliminateLoadsFollowingSingleStore()
if(!llvm::isa<Ice::InstAlloca>(alloca)) if(!llvm::isa<Ice::InstAlloca>(alloca))
{ {
break; // Allocas are all at the top break; // Allocas are all at the top
} }
Ice::Operand *address = alloca.getDest(); Ice::Operand *address = alloca.getDest();
...@@ -313,7 +312,7 @@ void Optimizer::optimizeStoresInSingleBasicBlock() ...@@ -313,7 +312,7 @@ void Optimizer::optimizeStoresInSingleBasicBlock()
{ {
Ice::CfgNode *entryBlock = function->getEntryNode(); Ice::CfgNode *entryBlock = function->getEntryNode();
std::vector<std::vector<LoadStoreInst>* > allocatedVectors; std::vector<std::vector<LoadStoreInst> *> allocatedVectors;
for(Ice::Inst &alloca : entryBlock->getInsts()) for(Ice::Inst &alloca : entryBlock->getInsts())
{ {
...@@ -324,7 +323,7 @@ void Optimizer::optimizeStoresInSingleBasicBlock() ...@@ -324,7 +323,7 @@ void Optimizer::optimizeStoresInSingleBasicBlock()
if(!llvm::isa<Ice::InstAlloca>(alloca)) if(!llvm::isa<Ice::InstAlloca>(alloca))
{ {
break; // Allocas are all at the top break; // Allocas are all at the top
} }
Ice::Operand *address = alloca.getDest(); Ice::Operand *address = alloca.getDest();
...@@ -357,7 +356,7 @@ void Optimizer::optimizeStoresInSingleBasicBlock() ...@@ -357,7 +356,7 @@ void Optimizer::optimizeStoresInSingleBasicBlock()
{ {
if(!hasLoadStoreInsts(singleBasicBlock)) if(!hasLoadStoreInsts(singleBasicBlock))
{ {
std::vector<LoadStoreInst>* loadStoreInstVector = new std::vector<LoadStoreInst>(); std::vector<LoadStoreInst> *loadStoreInstVector = new std::vector<LoadStoreInst>();
setLoadStoreInsts(singleBasicBlock, loadStoreInstVector); setLoadStoreInsts(singleBasicBlock, loadStoreInstVector);
allocatedVectors.push_back(loadStoreInstVector); allocatedVectors.push_back(loadStoreInstVector);
for(Ice::Inst &inst : singleBasicBlock->getInsts()) for(Ice::Inst &inst : singleBasicBlock->getInsts())
...@@ -381,9 +380,9 @@ void Optimizer::optimizeStoresInSingleBasicBlock() ...@@ -381,9 +380,9 @@ void Optimizer::optimizeStoresInSingleBasicBlock()
Ice::Operand *storeValue = nullptr; Ice::Operand *storeValue = nullptr;
bool unmatchedLoads = false; bool unmatchedLoads = false;
for(auto& loadStoreInst : getLoadStoreInsts(singleBasicBlock)) for(auto &loadStoreInst : getLoadStoreInsts(singleBasicBlock))
{ {
Ice::Inst* inst = loadStoreInst.inst; Ice::Inst *inst = loadStoreInst.inst;
if((loadStoreInst.address != address) || inst->isDeleted()) if((loadStoreInst.address != address) || inst->isDeleted())
{ {
...@@ -478,7 +477,7 @@ void Optimizer::replace(Ice::Inst *instruction, Ice::Operand *newValue) ...@@ -478,7 +477,7 @@ void Optimizer::replace(Ice::Inst *instruction, Ice::Operand *newValue)
{ {
for(Ice::Inst *use : *getUses(oldValue)) for(Ice::Inst *use : *getUses(oldValue))
{ {
assert(!use->isDeleted()); // Should have been removed from uses already assert(!use->isDeleted()); // Should have been removed from uses already
for(Ice::SizeT i = 0; i < use->getSrcSize(); i++) for(Ice::SizeT i = 0; i < use->getSrcSize(); i++)
{ {
...@@ -547,12 +546,12 @@ bool Optimizer::isDead(Ice::Inst *instruction) ...@@ -547,12 +546,12 @@ bool Optimizer::isDead(Ice::Inst *instruction)
{ {
if(hasUses(address)) if(hasUses(address))
{ {
Optimizer::Uses* uses = getUses(address); Optimizer::Uses *uses = getUses(address);
return uses->size() == uses->stores.size(); // Dead if all uses are stores return uses->size() == uses->stores.size(); // Dead if all uses are stores
} }
else else
{ {
return true; // No uses return true; // No uses
} }
} }
} }
...@@ -700,16 +699,16 @@ bool Optimizer::loadTypeMatchesStore(const Ice::Inst *load, const Ice::Inst *sto ...@@ -700,16 +699,16 @@ bool Optimizer::loadTypeMatchesStore(const Ice::Inst *load, const Ice::Inst *sto
// Check for matching type and sub-vector width. // Check for matching type and sub-vector width.
return storeSubVector->getSrc(1)->getType() == loadSubVector->getDest()->getType() && return storeSubVector->getSrc(1)->getType() == loadSubVector->getDest()->getType() &&
llvm::cast<Ice::ConstantInteger32>(storeSubVector->getSrc(3))->getValue() == llvm::cast<Ice::ConstantInteger32>(storeSubVector->getSrc(3))->getValue() ==
llvm::cast<Ice::ConstantInteger32>(loadSubVector->getSrc(2))->getValue(); llvm::cast<Ice::ConstantInteger32>(loadSubVector->getSrc(2))->getValue();
} }
} }
return false; return false;
} }
Optimizer::Uses* Optimizer::getUses(Ice::Operand* operand) Optimizer::Uses *Optimizer::getUses(Ice::Operand *operand)
{ {
Optimizer::Uses* uses = (Optimizer::Uses*)operand->Ice::Operand::getExternalData(); Optimizer::Uses *uses = (Optimizer::Uses *)operand->Ice::Operand::getExternalData();
if(!uses) if(!uses)
{ {
uses = new Optimizer::Uses; uses = new Optimizer::Uses;
...@@ -719,47 +718,47 @@ Optimizer::Uses* Optimizer::getUses(Ice::Operand* operand) ...@@ -719,47 +718,47 @@ Optimizer::Uses* Optimizer::getUses(Ice::Operand* operand)
return uses; return uses;
} }
void Optimizer::setUses(Ice::Operand* operand, Optimizer::Uses* uses) void Optimizer::setUses(Ice::Operand *operand, Optimizer::Uses *uses)
{ {
operand->Ice::Operand::setExternalData(uses); operand->Ice::Operand::setExternalData(uses);
} }
bool Optimizer::hasUses(Ice::Operand* operand) const bool Optimizer::hasUses(Ice::Operand *operand) const
{ {
return operand->Ice::Operand::getExternalData() != nullptr; return operand->Ice::Operand::getExternalData() != nullptr;
} }
Ice::CfgNode* Optimizer::getNode(Ice::Inst* inst) Ice::CfgNode *Optimizer::getNode(Ice::Inst *inst)
{ {
return (Ice::CfgNode*)inst->Ice::Inst::getExternalData(); return (Ice::CfgNode *)inst->Ice::Inst::getExternalData();
} }
void Optimizer::setNode(Ice::Inst* inst, Ice::CfgNode* node) void Optimizer::setNode(Ice::Inst *inst, Ice::CfgNode *node)
{ {
inst->Ice::Inst::setExternalData(node); inst->Ice::Inst::setExternalData(node);
} }
Ice::Inst* Optimizer::getDefinition(Ice::Variable* var) Ice::Inst *Optimizer::getDefinition(Ice::Variable *var)
{ {
return (Ice::Inst*)var->Ice::Variable::getExternalData(); return (Ice::Inst *)var->Ice::Variable::getExternalData();
} }
void Optimizer::setDefinition(Ice::Variable* var, Ice::Inst* inst) void Optimizer::setDefinition(Ice::Variable *var, Ice::Inst *inst)
{ {
var->Ice::Variable::setExternalData(inst); var->Ice::Variable::setExternalData(inst);
} }
const std::vector<Optimizer::LoadStoreInst>& Optimizer::getLoadStoreInsts(Ice::CfgNode* node) const std::vector<Optimizer::LoadStoreInst> &Optimizer::getLoadStoreInsts(Ice::CfgNode *node)
{ {
return *((const std::vector<LoadStoreInst>*)node->Ice::CfgNode::getExternalData()); return *((const std::vector<LoadStoreInst> *)node->Ice::CfgNode::getExternalData());
} }
void Optimizer::setLoadStoreInsts(Ice::CfgNode* node, std::vector<LoadStoreInst>* insts) void Optimizer::setLoadStoreInsts(Ice::CfgNode *node, std::vector<LoadStoreInst> *insts)
{ {
node->Ice::CfgNode::setExternalData(insts); node->Ice::CfgNode::setExternalData(insts);
} }
bool Optimizer::hasLoadStoreInsts(Ice::CfgNode* node) const bool Optimizer::hasLoadStoreInsts(Ice::CfgNode *node) const
{ {
return node->Ice::CfgNode::getExternalData() != nullptr; return node->Ice::CfgNode::getExternalData() != nullptr;
} }
...@@ -825,7 +824,7 @@ void Optimizer::Uses::erase(Ice::Inst *instruction) ...@@ -825,7 +824,7 @@ void Optimizer::Uses::erase(Ice::Inst *instruction)
} }
} }
} // anonymous namespace } // anonymous namespace
namespace rr { namespace rr {
......
...@@ -23,4 +23,4 @@ void optimize(Ice::Cfg *function); ...@@ -23,4 +23,4 @@ void optimize(Ice::Cfg *function);
} // namespace rr } // namespace rr
#endif // rr_Optimizer_hpp #endif // rr_Optimizer_hpp
...@@ -38,12 +38,12 @@ class RoutineT<Return(Arguments...)> ...@@ -38,12 +38,12 @@ class RoutineT<Return(Arguments...)>
public: public:
RoutineT() = default; RoutineT() = default;
explicit RoutineT(const std::shared_ptr<Routine>& routine) explicit RoutineT(const std::shared_ptr<Routine> &routine)
: routine(routine) : routine(routine)
{ {
if(routine) if(routine)
{ {
callable = reinterpret_cast<CallableType>(const_cast<void*>(routine->getEntry(0))); callable = reinterpret_cast<CallableType>(const_cast<void *>(routine->getEntry(0)));
} }
} }
...@@ -52,23 +52,23 @@ public: ...@@ -52,23 +52,23 @@ public:
return callable != nullptr; return callable != nullptr;
} }
template <typename... Args> template<typename... Args>
Return operator()(Args&&... args) const Return operator()(Args &&... args) const
{ {
return callable(std::forward<Args>(args)...); return callable(std::forward<Args>(args)...);
} }
const void* getEntry() const const void *getEntry() const
{ {
return reinterpret_cast<void*>(callable); return reinterpret_cast<void *>(callable);
} }
private: private:
std::shared_ptr<Routine> routine; std::shared_ptr<Routine> routine;
using CallableType = Return(*)(Arguments...); using CallableType = Return (*)(Arguments...);
CallableType callable = nullptr; CallableType callable = nullptr;
}; };
} // namespace rr } // namespace rr
#endif // rr_Routine_hpp #endif // rr_Routine_hpp
...@@ -19,74 +19,74 @@ namespace rr { ...@@ -19,74 +19,74 @@ namespace rr {
Thread::Thread(void (*threadFunction)(void *parameters), void *parameters) Thread::Thread(void (*threadFunction)(void *parameters), void *parameters)
{ {
Event init; Event init;
Entry entry = {threadFunction, parameters, &init}; Entry entry = { threadFunction, parameters, &init };
#if defined(_WIN32) #if defined(_WIN32)
handle = CreateThread(NULL, 1024 * 1024, startFunction, &entry, 0, NULL); handle = CreateThread(NULL, 1024 * 1024, startFunction, &entry, 0, NULL);
#else #else
pthread_create(&handle, NULL, startFunction, &entry); pthread_create(&handle, NULL, startFunction, &entry);
#endif #endif
init.wait(); init.wait();
} }
Thread::~Thread() Thread::~Thread()
{ {
join(); // Make threads exit before deleting them to not block here join(); // Make threads exit before deleting them to not block here
} }
void Thread::join() void Thread::join()
{ {
if(!hasJoined) if(!hasJoined)
{ {
#if defined(_WIN32) #if defined(_WIN32)
WaitForSingleObject(handle, INFINITE); WaitForSingleObject(handle, INFINITE);
CloseHandle(handle); CloseHandle(handle);
#else #else
pthread_join(handle, NULL); pthread_join(handle, NULL);
#endif #endif
hasJoined = true; hasJoined = true;
} }
} }
#if defined(_WIN32) #if defined(_WIN32)
unsigned long __stdcall Thread::startFunction(void *parameters) unsigned long __stdcall Thread::startFunction(void *parameters)
{ {
Entry entry = *(Entry*)parameters; Entry entry = *(Entry *)parameters;
entry.init->signal(); entry.init->signal();
entry.threadFunction(entry.threadParameters); entry.threadFunction(entry.threadParameters);
return 0; return 0;
} }
#else #else
void *Thread::startFunction(void *parameters) void *Thread::startFunction(void *parameters)
{ {
Entry entry = *(Entry*)parameters; Entry entry = *(Entry *)parameters;
entry.init->signal(); entry.init->signal();
entry.threadFunction(entry.threadParameters); entry.threadFunction(entry.threadParameters);
return nullptr; return nullptr;
} }
#endif #endif
Event::Event() Event::Event()
{ {
#if defined(_WIN32) #if defined(_WIN32)
handle = CreateEvent(NULL, FALSE, FALSE, NULL); handle = CreateEvent(NULL, FALSE, FALSE, NULL);
#else #else
pthread_cond_init(&handle, NULL); pthread_cond_init(&handle, NULL);
pthread_mutex_init(&mutex, NULL); pthread_mutex_init(&mutex, NULL);
signaled = false; signaled = false;
#endif #endif
} }
Event::~Event() Event::~Event()
{ {
#if defined(_WIN32) #if defined(_WIN32)
CloseHandle(handle); CloseHandle(handle);
#else #else
pthread_cond_destroy(&handle); pthread_cond_destroy(&handle);
pthread_mutex_destroy(&mutex); pthread_mutex_destroy(&mutex);
#endif #endif
} }
} // namespace rr } // namespace rr
...@@ -20,7 +20,7 @@ namespace rr { ...@@ -20,7 +20,7 @@ namespace rr {
// Non-specialized implementation of CToReactorPtr::cast() defaults to // Non-specialized implementation of CToReactorPtr::cast() defaults to
// returning a ConstantPointer for v. // returning a ConstantPointer for v.
template<typename T, typename ENABLE> template<typename T, typename ENABLE>
Pointer<Byte> CToReactorPtr<T, ENABLE>::cast(const T* v) Pointer<Byte> CToReactorPtr<T, ENABLE>::cast(const T *v)
{ {
return ConstantPointer(v); return ConstantPointer(v);
} }
...@@ -29,13 +29,13 @@ Pointer<Byte> CToReactorPtr<T, ENABLE>::cast(const T* v) ...@@ -29,13 +29,13 @@ Pointer<Byte> CToReactorPtr<T, ENABLE>::cast(const T* v)
// specialization. // specialization.
template<typename T> template<typename T>
Pointer<CToReactorT<T>> Pointer<CToReactorT<T>>
CToReactorPtr<T, enable_if_t< HasReactorType<T>::value > >::cast(const T* v) CToReactorPtr<T, enable_if_t<HasReactorType<T>::value>>::cast(const T *v)
{ {
return type(v); return type(v);
} }
// CToReactorPtr specialization for void*. // CToReactorPtr specialization for void*.
Pointer<Byte> CToReactorPtr<void, void>::cast(const void* v) Pointer<Byte> CToReactorPtr<void, void>::cast(const void *v)
{ {
return ConstantPointer(v); return ConstantPointer(v);
} }
...@@ -43,7 +43,7 @@ Pointer<Byte> CToReactorPtr<void, void>::cast(const void* v) ...@@ -43,7 +43,7 @@ Pointer<Byte> CToReactorPtr<void, void>::cast(const void* v)
// CToReactorPtrT specialization for function pointer types. // CToReactorPtrT specialization for function pointer types.
template<typename T> template<typename T>
Pointer<Byte> Pointer<Byte>
CToReactorPtr<T, enable_if_t< std::is_function<T>::value > >::cast(T* v) CToReactorPtr<T, enable_if_t<std::is_function<T>::value>>::cast(T *v)
{ {
return ConstantPointer(v); return ConstantPointer(v);
} }
...@@ -51,7 +51,7 @@ CToReactorPtr<T, enable_if_t< std::is_function<T>::value > >::cast(T* v) ...@@ -51,7 +51,7 @@ CToReactorPtr<T, enable_if_t< std::is_function<T>::value > >::cast(T* v)
// CToReactor specialization for pointer types. // CToReactor specialization for pointer types.
template<typename T> template<typename T>
CToReactorPtrT<typename std::remove_pointer<T>::type> CToReactorPtrT<typename std::remove_pointer<T>::type>
CToReactor<T, enable_if_t<std::is_pointer<T>::value> >::cast(T v) CToReactor<T, enable_if_t<std::is_pointer<T>::value>>::cast(T v)
{ {
return CToReactorPtr<elem>::cast(v); return CToReactorPtr<elem>::cast(v);
} }
...@@ -59,11 +59,11 @@ CToReactor<T, enable_if_t<std::is_pointer<T>::value> >::cast(T v) ...@@ -59,11 +59,11 @@ CToReactor<T, enable_if_t<std::is_pointer<T>::value> >::cast(T v)
// CToReactor specialization for enum types. // CToReactor specialization for enum types.
template<typename T> template<typename T>
CToReactorT<typename std::underlying_type<T>::type> CToReactorT<typename std::underlying_type<T>::type>
CToReactor<T, enable_if_t<std::is_enum<T>::value> >::cast(T v) CToReactor<T, enable_if_t<std::is_enum<T>::value>>::cast(T v)
{ {
return CToReactor<underlying>::cast(v); return CToReactor<underlying>::cast(v);
} }
} // namespace rr } // namespace rr
#endif // rr_Traits_inl #endif // rr_Traits_inl
...@@ -106,4 +106,4 @@ RValue<Int4> pmovsxwd(RValue<Short8> x); ...@@ -106,4 +106,4 @@ RValue<Int4> pmovsxwd(RValue<Short8> x);
} // namespace x86 } // namespace x86
} // namespace rr } // namespace rr
#endif // rr_x86_hpp #endif // rr_x86_hpp
\ No newline at end of file \ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment