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 @@
#include "CPUID.hpp"
#if defined(_WIN32)
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#include <windows.h>
#include <intrin.h>
#include <float.h>
# ifndef WIN32_LEAN_AND_MEAN
# define WIN32_LEAN_AND_MEAN
# endif
# include <windows.h>
# include <intrin.h>
# include <float.h>
#else
#include <unistd.h>
#include <sched.h>
#include <sys/types.h>
# include <unistd.h>
# include <sched.h>
# include <sys/types.h>
#endif
namespace rr {
......@@ -162,18 +162,20 @@ void CPUID::setEnableSSE4_1(bool enable)
static void cpuid(int registers[4], int info)
{
#if defined(__i386__) || defined(__x86_64__)
#if defined(_WIN32)
__cpuid(registers, info);
#else
__asm volatile("cpuid": "=a" (registers[0]), "=b" (registers[1]), "=c" (registers[2]), "=d" (registers[3]): "a" (info));
#endif
#else
registers[0] = 0;
registers[1] = 0;
registers[2] = 0;
registers[3] = 0;
#endif
#if defined(__i386__) || defined(__x86_64__)
# if defined(_WIN32)
__cpuid(registers, info);
# else
__asm volatile("cpuid"
: "=a"(registers[0]), "=b"(registers[1]), "=c"(registers[2]), "=d"(registers[3])
: "a"(info));
# endif
#else
registers[0] = 0;
registers[1] = 0;
registers[2] = 0;
registers[3] = 0;
#endif
}
bool CPUID::detectMMX()
......
......@@ -18,11 +18,11 @@
namespace rr {
#if !defined(__i386__) && defined(_M_IX86)
#define __i386__ 1
# define __i386__ 1
#endif
#if !defined(__x86_64__) && (defined(_M_AMD64) || defined (_M_X64))
#define __x86_64__ 1
#if !defined(__x86_64__) && (defined(_M_AMD64) || defined(_M_X64))
# define __x86_64__ 1
#endif
class CPUID
......@@ -30,7 +30,7 @@ class CPUID
public:
static bool supportsMMX();
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 supportsSSE2();
static bool supportsSSE3();
......@@ -89,7 +89,7 @@ inline bool CPUID::supportsCMOV()
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()
......@@ -119,4 +119,4 @@ inline bool CPUID::supportsSSE4_1()
} // namespace rr
#endif // rr_CPUID_hpp
#endif // rr_CPUID_hpp
......@@ -17,7 +17,7 @@
#include <memory>
#ifndef rr_ReactorCoroutine_hpp
#define rr_ReactorCoroutine_hpp
# define rr_ReactorCoroutine_hpp
namespace rr {
......@@ -26,17 +26,19 @@ class StreamBase
{
protected:
StreamBase(const std::shared_ptr<Routine> &routine, Nucleus::CoroutineHandle handle)
: routine(routine), handle(handle) {}
: routine(routine)
, handle(handle)
{}
~StreamBase()
{
auto pfn = (Nucleus::CoroutineDestroy*)routine->getEntry(Nucleus::CoroutineEntryDestroy);
auto pfn = (Nucleus::CoroutineDestroy *)routine->getEntry(Nucleus::CoroutineEntryDestroy);
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);
}
......@@ -53,13 +55,14 @@ class Stream : public StreamBase
{
public:
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.
// Returns true if the coroutine yieled a value and out was assigned a
// new value. If await() returns false, the coroutine has finished
// 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>
......@@ -143,7 +146,7 @@ public:
protected:
std::unique_ptr<Nucleus> core;
std::shared_ptr<Routine> routine;
std::vector<Type*> arguments;
std::vector<Type *> arguments;
};
template<typename Return, typename... Arguments>
......@@ -151,7 +154,7 @@ Coroutine<Return(Arguments...)>::Coroutine()
{
core.reset(new Nucleus());
std::vector<Type*> types = {CToReactorT<Arguments>::getType()...};
std::vector<Type *> types = { CToReactorT<Arguments>::getType()... };
for(auto type : types)
{
if(type != Void::getType())
......@@ -180,20 +183,23 @@ Coroutine<Return(Arguments...)>::operator()(Arguments... args)
finalize();
using Sig = Nucleus::CoroutineBegin<Arguments...>;
auto pfn = (Sig*)routine->getEntry(Nucleus::CoroutineEntryBegin);
auto pfn = (Sig *)routine->getEntry(Nucleus::CoroutineEntryBegin);
auto handle = pfn(args...);
return std::unique_ptr<Stream<Return>>(new Stream<Return>(routine, handle));
}
#ifdef Yield // Defined in WinBase.h
#undef Yield
#endif
# ifdef Yield // Defined in WinBase.h
# undef Yield
# endif
// Suspends execution of the coroutine and yields val to the caller.
// Execution of the coroutine will resume after val is retrieved.
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
\ No newline at end of file
#endif // rr_ReactorCoroutine_hpp
\ No newline at end of file
......@@ -14,8 +14,8 @@
#include "Debug.hpp"
#include <string>
#include <stdarg.h>
#include <string>
namespace rr {
......
......@@ -17,18 +17,18 @@
#ifndef rr_DEBUG_H_
#define rr_DEBUG_H_
#include <stdlib.h>
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#if !defined(TRACE_OUTPUT_FILE)
#define TRACE_OUTPUT_FILE "debug.txt"
# define TRACE_OUTPUT_FILE "debug.txt"
#endif
#if defined(__GNUC__) || defined(__clang__)
#define CHECK_PRINTF_ARGS __attribute__((format(printf, 1, 2)))
# define CHECK_PRINTF_ARGS __attribute__((format(printf, 1, 2)))
#else
#define CHECK_PRINTF_ARGS
# define CHECK_PRINTF_ARGS
#endif
namespace rr {
......@@ -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
// debugging log. Disabled if RR_DISABLE_TRACE is defined.
#if defined(RR_DISABLE_TRACE)
#define TRACE(message, ...) (void(0))
# define TRACE(message, ...) (void(0))
#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
// 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;
// WARN() in release builds (NDEBUG && !DCHECK_ALWAYS_ON)
#undef DABORT
#if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)
#define DABORT(message, ...) ABORT(message, ##__VA_ARGS__)
# define DABORT(message, ...) ABORT(message, ##__VA_ARGS__)
#else
#define DABORT(message, ...) WARN(message, ##__VA_ARGS__)
# define DABORT(message, ...) WARN(message, ##__VA_ARGS__)
#endif
// A macro asserting a condition.
// If the condition fails, the condition and message is passed to DABORT().
#undef ASSERT_MSG
#define ASSERT_MSG(expression, format, ...) do { \
if(!(expression)) { \
DABORT("ASSERT(%s): " format "\n", #expression, ##__VA_ARGS__); \
} } while(0)
#define ASSERT_MSG(expression, format, ...) \
do \
{ \
if(!(expression)) \
{ \
DABORT("ASSERT(%s): " format "\n", #expression, ##__VA_ARGS__); \
} \
} while(0)
// A macro asserting a condition.
// If the condition fails, the condition is passed to DABORT().
#undef ASSERT
#define ASSERT(expression) do { \
if(!(expression)) { \
DABORT("ASSERT(%s)\n", #expression); \
} } while(0)
#define ASSERT(expression) \
do \
{ \
if(!(expression)) \
{ \
DABORT("ASSERT(%s)\n", #expression); \
} \
} while(0)
// A macro to indicate unimplemented functionality.
#undef UNIMPLEMENTED
......@@ -107,12 +115,16 @@ void abort(const char *format, ...) CHECK_PRINTF_ARGS;
// A macro asserting a condition and performing a return.
#undef ASSERT_OR_RETURN
#if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)
#define ASSERT_OR_RETURN(expression) ASSERT(expression)
# define ASSERT_OR_RETURN(expression) ASSERT(expression)
#else
#define ASSERT_OR_RETURN(expression) do { \
if(!(expression)) { \
return; \
} } while(0)
# define ASSERT_OR_RETURN(expression) \
do \
{ \
if(!(expression)) \
{ \
return; \
} \
} while(0)
#endif
#endif // rr_DEBUG_H_
#endif // rr_DEBUG_H_
......@@ -14,16 +14,16 @@
#include "DebugAndroid.hpp"
#include <cutils/properties.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <cutils/properties.h>
#include <unistd.h>
void AndroidEnterDebugger()
{
ALOGE(__FUNCTION__);
#ifndef NDEBUG
static volatile int * const makefault = nullptr;
static volatile int *const makefault = nullptr;
char value[PROPERTY_VALUE_MAX];
property_get("debug.db.uid", value, "-1");
int debug_uid = atoi(value);
......@@ -31,7 +31,8 @@ void AndroidEnterDebugger()
{
ALOGE("Waiting for debugger: gdbserver :${PORT} --attach %u. Look for thread %u", getpid(), gettid());
volatile int waiting = 1;
while(waiting) {
while(waiting)
{
sleep(1);
}
}
......
......@@ -16,11 +16,11 @@
#define DebugAndroid_hpp
#if ANDROID_PLATFORM_SDK_VERSION < 27
#include <cutils/log.h>
# include <cutils/log.h>
#elif ANDROID_PLATFORM_SDK_VERSION >= 27
#include <log/log.h>
# include <log/log.h>
#else
#error "ANDROID_PLATFORM_SDK_VERSION is not defined"
# error "ANDROID_PLATFORM_SDK_VERSION is not defined"
#endif
#include <cassert>
......@@ -48,52 +48,61 @@
*/
void AndroidEnterDebugger();
#define ASSERT(E) do { \
if(!(E)) { \
ALOGE("badness: assertion_failed %s in %s at %s:%d", #E, \
__FUNCTION__, __FILE__, __LINE__); \
AndroidEnterDebugger(); \
} \
#define ASSERT(E) \
do \
{ \
if(!(E)) \
{ \
ALOGE("badness: assertion_failed %s in %s at %s:%d", #E, \
__FUNCTION__, __FILE__, __LINE__); \
AndroidEnterDebugger(); \
} \
} while(0)
#undef assert
#define assert(E) ASSERT(E)
#define ERR(format, ...) \
do { \
#define ERR(format, ...) \
do \
{ \
ALOGE("badness: err %s %s:%d (" format ")", __FUNCTION__, __FILE__, \
__LINE__, ##__VA_ARGS__); \
AndroidEnterDebugger(); \
__LINE__, ##__VA_ARGS__); \
AndroidEnterDebugger(); \
} while(0)
#define FIXME(format, ...) \
do { \
#define FIXME(format, ...) \
do \
{ \
ALOGE("badness: fixme %s %s:%d (" format ")", __FUNCTION__, __FILE__, \
__LINE__, ##__VA_ARGS__); \
AndroidEnterDebugger(); \
__LINE__, ##__VA_ARGS__); \
AndroidEnterDebugger(); \
} while(0)
// TODO: Handle __VA_ARGS__ (can be empty)
#define UNIMPLEMENTED(...) do { \
ALOGE("badness: unimplemented: %s %s:%d", \
__FUNCTION__, __FILE__, __LINE__); \
AndroidEnterDebugger(); \
#define UNIMPLEMENTED(...) \
do \
{ \
ALOGE("badness: unimplemented: %s %s:%d", \
__FUNCTION__, __FILE__, __LINE__); \
AndroidEnterDebugger(); \
} while(0)
#define UNREACHABLE(value) do { \
#define UNREACHABLE(value) \
do \
{ \
ALOGE("badness: unreachable case reached: %s %s:%d. %s: %d", \
__FUNCTION__, __FILE__, __LINE__, #value, value); \
AndroidEnterDebugger(); \
__FUNCTION__, __FILE__, __LINE__, #value, value); \
AndroidEnterDebugger(); \
} while(0)
#ifndef NDEBUG
#define TRACE(format, ...) \
# define TRACE(format, ...) \
ALOGV("%s %s:%d (" format ")", __FUNCTION__, __FILE__, \
__LINE__, ##__VA_ARGS__)
__LINE__, ##__VA_ARGS__)
#else
#define TRACE(...) ((void)0)
# define TRACE(...) ((void)0)
#endif
void trace(const char *format, ...);
#endif // DebugAndroid_hpp
#endif // DebugAndroid_hpp
......@@ -7,18 +7,18 @@
namespace rr {
namespace {
template <typename T>
template<typename T>
struct UnderlyingType
{
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;
// Call single arg function on a vector type
template <typename Func, typename T>
RValue<T> call4(Func func, const RValue<T>& x)
template<typename Func, typename T>
RValue<T> call4(Func func, const RValue<T> &x)
{
T result;
result = Insert(result, Call(func, Extract(x, 0)), 0);
......@@ -29,8 +29,8 @@ RValue<T> call4(Func func, const RValue<T>& x)
}
// Call two arg function on a vector type
template <typename Func, typename T>
RValue<T> call4(Func func, const RValue<T>& x, const RValue<T>& y)
template<typename Func, typename T>
RValue<T> call4(Func func, const RValue<T> &x, const RValue<T> &y)
{
T result;
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)
return result;
}
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)
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)
{
constexpr bool atomic = false;
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>
}
}
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)
{
constexpr bool atomic = false;
......
......@@ -23,7 +23,8 @@ namespace rr {
size_t memoryPageSize();
enum MemoryPermission {
enum MemoryPermission
{
PERMISSION_READ = 1,
PERMISSION_WRITE = 2,
PERMISSION_EXECUTE = 4,
......@@ -31,7 +32,7 @@ enum MemoryPermission {
// Allocates memory with the specified permissions. If |need_exec| is true then
// 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().
void protectMemoryPages(void *memory, size_t bytes, int permissions);
......@@ -58,7 +59,9 @@ template<typename P>
class unaligned_ref
{
public:
explicit unaligned_ref(void *ptr) : ptr((P*)ptr) {}
explicit unaligned_ref(void *ptr)
: ptr((P *)ptr)
{}
template<typename V>
P operator=(V value)
......@@ -69,7 +72,7 @@ public:
operator P()
{
return unaligned_read((P*)ptr);
return unaligned_read((P *)ptr);
}
private:
......@@ -83,7 +86,9 @@ class unaligned_ptr
friend class unaligned_ptr;
public:
unaligned_ptr(P *ptr) : ptr(ptr) {}
unaligned_ptr(P *ptr)
: ptr(ptr)
{}
unaligned_ref<P> operator*()
{
......@@ -102,4 +107,4 @@ private:
} // 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);
inline Type *T(llvm::Type *t)
{
return reinterpret_cast<Type*>(t);
return reinterpret_cast<Type *>(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)
{
return reinterpret_cast<Value*>(t);
return reinterpret_cast<Value *>(t);
}
// Emits a no-op instruction that will not be optimized away.
......@@ -51,4 +51,4 @@ void Nop();
} // namespace rr
#endif // rr_LLVMReactor_hpp
#endif // rr_LLVMReactor_hpp
......@@ -19,10 +19,10 @@
#ifdef ENABLE_RR_DEBUG_INFO
#include <unordered_set>
#include <unordered_map>
#include <vector>
#include <memory>
# include <memory>
# include <unordered_map>
# include <unordered_set>
# include <vector>
// Forward declarations
namespace llvm {
......@@ -46,12 +46,12 @@ class Module;
class Type;
class Value;
namespace object
{
class ObjectFile;
namespace object {
class ObjectFile;
}
template <typename T, typename Inserter> class IRBuilder;
template<typename T, typename Inserter>
class IRBuilder;
} // namespace llvm
......@@ -68,9 +68,9 @@ public:
using IRBuilder = llvm::IRBuilder<llvm::ConstantFolder, llvm::IRBuilderDefaultInserter>;
DebugInfo(IRBuilder *builder,
llvm::LLVMContext *context,
llvm::Module *module,
llvm::Function *function);
llvm::LLVMContext *context,
llvm::Module *module,
llvm::Function *function);
~DebugInfo();
......@@ -116,15 +116,15 @@ private:
std::string name;
std::string 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 name == rhs.name && file == rhs.file; }
bool operator!=(const FunctionLocation &rhs) const { return !(*this == rhs); }
struct Hash
{
std::size_t operator()(const FunctionLocation &l) const noexcept
{
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:
FunctionLocation function;
unsigned int line = 0;
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 function == rhs.function && line == rhs.line; }
bool operator!=(const Location &rhs) const { return !(*this == rhs); }
struct Hash
{
std::size_t operator()(const Location &l) const noexcept
{
return FunctionLocation::Hash()(l.function) * 31 +
std::hash<unsigned int>()(l.line);
std::hash<unsigned int>()(l.line);
}
};
};
......@@ -181,14 +181,14 @@ private:
// frames will be returned.
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::DIFile *getOrCreateFile(const char* path);
LineTokens const *getOrParseFileTokens(const char* path);
llvm::DIType *getOrCreateType(llvm::Type *type);
llvm::DIFile *getOrCreateFile(const char *path);
LineTokens const *getOrParseFileTokens(const char *path);
// Synchronizes diScope with the current backtrace.
void syncScope(Backtrace const& backtrace);
void syncScope(Backtrace const &backtrace);
IRBuilder *builder;
llvm::LLVMContext *context;
......@@ -200,14 +200,14 @@ private:
llvm::DISubprogram *diSubprogram;
llvm::DILocation *diRootLocation;
std::vector<Scope> diScope;
std::unordered_map<std::string, llvm::DIFile*> diFiles;
std::unordered_map<llvm::Type*, llvm::DIType*> diTypes;
std::unordered_map<std::string, llvm::DIFile *> diFiles;
std::unordered_map<llvm::Type *, llvm::DIType *> diTypes;
std::unordered_map<std::string, std::unique_ptr<LineTokens>> fileTokens;
std::vector<void const*> pushed;
std::vector<void const *> pushed;
};
} // namespace rr
#endif // ENABLE_RR_DEBUG_INFO
#endif // ENABLE_RR_DEBUG_INFO
#endif // rr_LLVMReactorDebugInfo_hpp
#endif // rr_LLVMReactorDebugInfo_hpp
......@@ -20,7 +20,7 @@
#if defined(__linux__)
// 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.
#include <pthread.h>
# include <pthread.h>
namespace rr {
......@@ -58,9 +58,9 @@ private:
} // namespace rr
#else // !__linux__
#else // !__linux__
#include <atomic>
# include <atomic>
namespace rr {
......@@ -174,6 +174,6 @@ using MutexLock = BackoffLock;
} // namespace rr
#endif // !__linux__
#endif // !__linux__
#endif // rr_MutexLock_hpp
#endif // rr_MutexLock_hpp
......@@ -23,7 +23,7 @@
#include <vector>
#ifdef None
#undef None // TODO(b/127920555)
# undef None // TODO(b/127920555)
#endif
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:
using Passes = std::vector<Pass>;
Optimization(Level level = Level::Default, const Passes& passes = {})
: level(level), passes(passes)
Optimization(Level level = Level::Default, const 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;
}
#endif
#endif
}
Level getLevel() const { return level; }
const Passes & getPasses() const { return passes; }
const Passes &getPasses() const { return passes; }
private:
Level level = Level::Default;
......@@ -98,19 +99,41 @@ public:
public:
static const Edit None;
Edit & set(Optimization::Level level) { optLevel = level; 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; }
Edit &set(Optimization::Level level)
{
optLevel = level;
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;
private:
enum class ListEdit { Add, Remove, Clear };
enum class ListEdit
{
Add,
Remove,
Clear
};
using OptPassesEdit = std::pair<ListEdit, Optimization::Pass>;
template <typename T>
void apply(const std::vector<std::pair<ListEdit, T>> & edits, std::vector<T>& list) const;
template<typename T>
void apply(const std::vector<std::pair<ListEdit, T>> &edits, std::vector<T> &list) const;
Optimization::Level optLevel;
bool optLevelChanged = false;
......@@ -118,9 +141,11 @@ public:
};
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:
Optimization optimization;
......@@ -146,15 +171,15 @@ public:
static BasicBlock *getInsertBlock();
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);
// Coroutines
using CoroutineHandle = void*;
using CoroutineHandle = void *;
template <typename... ARGS>
template<typename... ARGS>
using CoroutineBegin = CoroutineHandle(ARGS...);
using CoroutineAwait = bool(CoroutineHandle, void* yieldValue);
using CoroutineAwait = bool(CoroutineHandle, void *yieldValue);
using CoroutineDestroy = void(CoroutineHandle);
enum CoroutineEntries
......@@ -165,9 +190,9 @@ public:
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);
static void yield(Value*);
static void yield(Value *);
// Terminators
static void createRetVoid();
......@@ -201,7 +226,7 @@ public:
static Value *createNot(Value *V);
// 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 *createGEP(Value *ptr, Type *type, Value *index, bool unsignedIndex);
......@@ -294,4 +319,4 @@ public:
} // namespace rr
#endif // rr_Nucleus_hpp
#endif // rr_Nucleus_hpp
......@@ -50,45 +50,45 @@ private:
Ice::Cfg *function;
Ice::GlobalContext *context;
struct Uses : std::vector<Ice::Inst*>
struct Uses : std::vector<Ice::Inst *>
{
bool areOnlyLoadStore() const;
void insert(Ice::Operand *value, Ice::Inst *instruction);
void erase(Ice::Inst *instruction);
std::vector<Ice::Inst*> loads;
std::vector<Ice::Inst*> stores;
std::vector<Ice::Inst *> loads;
std::vector<Ice::Inst *> stores;
};
struct LoadStoreInst
{
LoadStoreInst(Ice::Inst* inst, bool isStore)
: inst(inst),
address(isStore ? storeAddress(inst) : loadAddress(inst)),
isStore(isStore)
LoadStoreInst(Ice::Inst *inst, bool isStore)
: inst(inst)
, address(isStore ? storeAddress(inst) : loadAddress(inst))
, isStore(isStore)
{
}
Ice::Inst* inst;
Ice::Inst *inst;
Ice::Operand *address;
bool isStore;
};
Optimizer::Uses* getUses(Ice::Operand*);
void setUses(Ice::Operand*, Optimizer::Uses*);
bool hasUses(Ice::Operand*) const;
Optimizer::Uses *getUses(Ice::Operand *);
void setUses(Ice::Operand *, Optimizer::Uses *);
bool hasUses(Ice::Operand *) const;
Ice::CfgNode* getNode(Ice::Inst*);
void setNode(Ice::Inst*, Ice::CfgNode*);
Ice::CfgNode *getNode(Ice::Inst *);
void setNode(Ice::Inst *, Ice::CfgNode *);
Ice::Inst* getDefinition(Ice::Variable*);
void setDefinition(Ice::Variable*, Ice::Inst*);
Ice::Inst *getDefinition(Ice::Variable *);
void setDefinition(Ice::Variable *, Ice::Inst *);
const std::vector<LoadStoreInst>& getLoadStoreInsts(Ice::CfgNode*);
void setLoadStoreInsts(Ice::CfgNode*, std::vector<LoadStoreInst>*);
bool hasLoadStoreInsts(Ice::CfgNode* node) const;
const std::vector<LoadStoreInst> &getLoadStoreInsts(Ice::CfgNode *);
void setLoadStoreInsts(Ice::CfgNode *, std::vector<LoadStoreInst> *);
bool hasLoadStoreInsts(Ice::CfgNode *node) const;
std::vector<Optimizer::Uses*> allocatedUses;
std::vector<Optimizer::Uses *> allocatedUses;
};
void Optimizer::run(Ice::Cfg *function)
......@@ -133,8 +133,7 @@ void Optimizer::eliminateDeadCode()
}
}
}
}
while(modified);
} while(modified);
}
void Optimizer::eliminateUnitializedLoads()
......@@ -150,7 +149,7 @@ void Optimizer::eliminateUnitializedLoads()
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();
......@@ -213,7 +212,7 @@ void Optimizer::eliminateLoadsFollowingSingleStore()
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();
......@@ -313,7 +312,7 @@ void Optimizer::optimizeStoresInSingleBasicBlock()
{
Ice::CfgNode *entryBlock = function->getEntryNode();
std::vector<std::vector<LoadStoreInst>* > allocatedVectors;
std::vector<std::vector<LoadStoreInst> *> allocatedVectors;
for(Ice::Inst &alloca : entryBlock->getInsts())
{
......@@ -324,7 +323,7 @@ void Optimizer::optimizeStoresInSingleBasicBlock()
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();
......@@ -357,7 +356,7 @@ void Optimizer::optimizeStoresInSingleBasicBlock()
{
if(!hasLoadStoreInsts(singleBasicBlock))
{
std::vector<LoadStoreInst>* loadStoreInstVector = new std::vector<LoadStoreInst>();
std::vector<LoadStoreInst> *loadStoreInstVector = new std::vector<LoadStoreInst>();
setLoadStoreInsts(singleBasicBlock, loadStoreInstVector);
allocatedVectors.push_back(loadStoreInstVector);
for(Ice::Inst &inst : singleBasicBlock->getInsts())
......@@ -381,9 +380,9 @@ void Optimizer::optimizeStoresInSingleBasicBlock()
Ice::Operand *storeValue = nullptr;
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())
{
......@@ -478,7 +477,7 @@ void Optimizer::replace(Ice::Inst *instruction, Ice::Operand *newValue)
{
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++)
{
......@@ -547,12 +546,12 @@ bool Optimizer::isDead(Ice::Inst *instruction)
{
if(hasUses(address))
{
Optimizer::Uses* uses = getUses(address);
return uses->size() == uses->stores.size(); // Dead if all uses are stores
Optimizer::Uses *uses = getUses(address);
return uses->size() == uses->stores.size(); // Dead if all uses are stores
}
else
{
return true; // No uses
return true; // No uses
}
}
}
......@@ -700,16 +699,16 @@ bool Optimizer::loadTypeMatchesStore(const Ice::Inst *load, const Ice::Inst *sto
// Check for matching type and sub-vector width.
return storeSubVector->getSrc(1)->getType() == loadSubVector->getDest()->getType() &&
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;
}
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)
{
uses = new Optimizer::Uses;
......@@ -719,47 +718,47 @@ Optimizer::Uses* Optimizer::getUses(Ice::Operand* operand)
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);
}
bool Optimizer::hasUses(Ice::Operand* operand) const
bool Optimizer::hasUses(Ice::Operand *operand) const
{
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);
}
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);
}
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);
}
bool Optimizer::hasLoadStoreInsts(Ice::CfgNode* node) const
bool Optimizer::hasLoadStoreInsts(Ice::CfgNode *node) const
{
return node->Ice::CfgNode::getExternalData() != nullptr;
}
......@@ -825,7 +824,7 @@ void Optimizer::Uses::erase(Ice::Inst *instruction)
}
}
} // anonymous namespace
} // anonymous namespace
namespace rr {
......
......@@ -23,4 +23,4 @@ void optimize(Ice::Cfg *function);
} // namespace rr
#endif // rr_Optimizer_hpp
#endif // rr_Optimizer_hpp
......@@ -38,12 +38,12 @@ class RoutineT<Return(Arguments...)>
public:
RoutineT() = default;
explicit RoutineT(const std::shared_ptr<Routine>& routine)
: routine(routine)
explicit RoutineT(const std::shared_ptr<Routine> &routine)
: routine(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:
return callable != nullptr;
}
template <typename... Args>
Return operator()(Args&&... args) const
template<typename... Args>
Return operator()(Args &&... args) const
{
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:
std::shared_ptr<Routine> routine;
using CallableType = Return(*)(Arguments...);
using CallableType = Return (*)(Arguments...);
CallableType callable = nullptr;
};
} // namespace rr
#endif // rr_Routine_hpp
#endif // rr_Routine_hpp
......@@ -19,74 +19,74 @@ namespace rr {
Thread::Thread(void (*threadFunction)(void *parameters), void *parameters)
{
Event init;
Entry entry = {threadFunction, parameters, &init};
Entry entry = { threadFunction, parameters, &init };
#if defined(_WIN32)
handle = CreateThread(NULL, 1024 * 1024, startFunction, &entry, 0, NULL);
#else
pthread_create(&handle, NULL, startFunction, &entry);
#endif
#if defined(_WIN32)
handle = CreateThread(NULL, 1024 * 1024, startFunction, &entry, 0, NULL);
#else
pthread_create(&handle, NULL, startFunction, &entry);
#endif
init.wait();
}
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()
{
if(!hasJoined)
{
#if defined(_WIN32)
WaitForSingleObject(handle, INFINITE);
CloseHandle(handle);
#else
pthread_join(handle, NULL);
#endif
#if defined(_WIN32)
WaitForSingleObject(handle, INFINITE);
CloseHandle(handle);
#else
pthread_join(handle, NULL);
#endif
hasJoined = true;
}
}
#if defined(_WIN32)
unsigned long __stdcall Thread::startFunction(void *parameters)
{
Entry entry = *(Entry*)parameters;
entry.init->signal();
entry.threadFunction(entry.threadParameters);
return 0;
}
unsigned long __stdcall Thread::startFunction(void *parameters)
{
Entry entry = *(Entry *)parameters;
entry.init->signal();
entry.threadFunction(entry.threadParameters);
return 0;
}
#else
void *Thread::startFunction(void *parameters)
{
Entry entry = *(Entry*)parameters;
entry.init->signal();
entry.threadFunction(entry.threadParameters);
return nullptr;
}
void *Thread::startFunction(void *parameters)
{
Entry entry = *(Entry *)parameters;
entry.init->signal();
entry.threadFunction(entry.threadParameters);
return nullptr;
}
#endif
Event::Event()
{
#if defined(_WIN32)
handle = CreateEvent(NULL, FALSE, FALSE, NULL);
#else
pthread_cond_init(&handle, NULL);
pthread_mutex_init(&mutex, NULL);
signaled = false;
#endif
#if defined(_WIN32)
handle = CreateEvent(NULL, FALSE, FALSE, NULL);
#else
pthread_cond_init(&handle, NULL);
pthread_mutex_init(&mutex, NULL);
signaled = false;
#endif
}
Event::~Event()
{
#if defined(_WIN32)
CloseHandle(handle);
#else
pthread_cond_destroy(&handle);
pthread_mutex_destroy(&mutex);
#endif
#if defined(_WIN32)
CloseHandle(handle);
#else
pthread_cond_destroy(&handle);
pthread_mutex_destroy(&mutex);
#endif
}
} // namespace rr
......@@ -20,7 +20,7 @@ namespace rr {
// Non-specialized implementation of CToReactorPtr::cast() defaults to
// returning a ConstantPointer for v.
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);
}
......@@ -29,13 +29,13 @@ Pointer<Byte> CToReactorPtr<T, ENABLE>::cast(const T* v)
// specialization.
template<typename 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);
}
// 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);
}
......@@ -43,7 +43,7 @@ Pointer<Byte> CToReactorPtr<void, void>::cast(const void* v)
// CToReactorPtrT specialization for function pointer types.
template<typename T>
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);
}
......@@ -51,7 +51,7 @@ CToReactorPtr<T, enable_if_t< std::is_function<T>::value > >::cast(T* v)
// CToReactor specialization for pointer types.
template<typename T>
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);
}
......@@ -59,11 +59,11 @@ CToReactor<T, enable_if_t<std::is_pointer<T>::value> >::cast(T v)
// CToReactor specialization for enum types.
template<typename T>
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);
}
} // namespace rr
#endif // rr_Traits_inl
#endif // rr_Traits_inl
......@@ -106,4 +106,4 @@ RValue<Int4> pmovsxwd(RValue<Short8> x);
} // namespace x86
} // namespace rr
#endif // rr_x86_hpp
\ No newline at end of file
#endif // rr_x86_hpp
\ 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