diff options
author | Tim Rowley <[email protected]> | 2016-06-06 19:13:22 -0600 |
---|---|---|
committer | Tim Rowley <[email protected]> | 2016-06-23 10:50:19 -0500 |
commit | d3d97f8395513bf365d2fe8e4292c8098290586f (patch) | |
tree | 08f006baa8802158e10d63e2bfb8f666e99f8bd7 /src/gallium/drivers/swr | |
parent | 42215e61168edb01482cbfe4dcf5031613e5e4c5 (diff) |
swr: [rasterizer jitter] cleanup supporting different llvm versions
Reviewed-by: Bruce Cherniak <[email protected]>
Diffstat (limited to 'src/gallium/drivers/swr')
8 files changed, 73 insertions, 34 deletions
diff --git a/src/gallium/drivers/swr/rasterizer/jitter/JitManager.cpp b/src/gallium/drivers/swr/rasterizer/jitter/JitManager.cpp index 4bbd9ad62fc..6e00a70c887 100644 --- a/src/gallium/drivers/swr/rasterizer/jitter/JitManager.cpp +++ b/src/gallium/drivers/swr/rasterizer/jitter/JitManager.cpp @@ -35,11 +35,13 @@ #include "JitManager.h" #include "fetch_jit.h" +#pragma push_macro("DEBUG") +#undef DEBUG + #if defined(_WIN32) #include "llvm/ADT/Triple.h" #endif #include "llvm/IR/Function.h" -#include "llvm/Support/DynamicLibrary.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/SourceMgr.h" @@ -53,6 +55,8 @@ #include "llvm/ExecutionEngine/JITEventListener.h" #endif +#pragma pop_macro("DEBUG") + #include "core/state.h" #include "state_llvm.h" @@ -237,6 +241,8 @@ bool JitManager::SetupModuleFromIR(const uint8_t *pIR) return false; } + newModule->setDataLayout(mpExec->getDataLayout()); + mpCurrentModule = newModule.get(); #if defined(_WIN32) // Needed for MCJIT on windows @@ -251,7 +257,6 @@ bool JitManager::SetupModuleFromIR(const uint8_t *pIR) return true; } - ////////////////////////////////////////////////////////////////////////// /// @brief Dump function x86 assembly to file. /// @note This should only be called after the module has been jitted to x86 and the diff --git a/src/gallium/drivers/swr/rasterizer/jitter/JitManager.h b/src/gallium/drivers/swr/rasterizer/jitter/JitManager.h index 14ba893fc25..354bfe869ba 100644 --- a/src/gallium/drivers/swr/rasterizer/jitter/JitManager.h +++ b/src/gallium/drivers/swr/rasterizer/jitter/JitManager.h @@ -54,7 +54,7 @@ #endif #ifndef HAVE_LLVM -#define HAVE_LLVM (LLVM_VERSION_MAJOR << 8) || LLVM_VERSION_MINOR +#define HAVE_LLVM ((LLVM_VERSION_MAJOR << 8) | LLVM_VERSION_MINOR) #endif #include "llvm/IR/Verifier.h" @@ -66,8 +66,12 @@ #if HAVE_LLVM == 0x306 #include "llvm/PassManager.h" +using FunctionPassManager = llvm::FunctionPassManager; +using PassManager = llvm::PassManager; #else #include "llvm/IR/LegacyPassManager.h" +using FunctionPassManager = llvm::legacy::FunctionPassManager; +using PassManager = llvm::legacy::PassManager; #endif #include "llvm/CodeGen/Passes.h" @@ -77,6 +81,7 @@ #include "llvm/Transforms/IPO.h" #include "llvm/Transforms/Scalar.h" #include "llvm/Support/Host.h" +#include "llvm/Support/DynamicLibrary.h" #pragma pop_macro("DEBUG") diff --git a/src/gallium/drivers/swr/rasterizer/jitter/blend_jit.cpp b/src/gallium/drivers/swr/rasterizer/jitter/blend_jit.cpp index 1b5290ce230..940399c2020 100644 --- a/src/gallium/drivers/swr/rasterizer/jitter/blend_jit.cpp +++ b/src/gallium/drivers/swr/rasterizer/jitter/blend_jit.cpp @@ -31,7 +31,6 @@ #include "blend_jit.h" #include "builder.h" #include "state_llvm.h" -#include "llvm/IR/DataLayout.h" #include <sstream> @@ -725,12 +724,7 @@ struct BlendJit : public Builder JitManager::DumpToFile(blendFunc, ""); -#if HAVE_LLVM == 0x306 - FunctionPassManager -#else - llvm::legacy::FunctionPassManager -#endif - passes(JM()->mpCurrentModule); + ::FunctionPassManager passes(JM()->mpCurrentModule); passes.add(createBreakCriticalEdgesPass()); passes.add(createCFGSimplificationPass()); diff --git a/src/gallium/drivers/swr/rasterizer/jitter/builder_misc.cpp b/src/gallium/drivers/swr/rasterizer/jitter/builder_misc.cpp index 2f4fa382ebf..671178f719f 100644 --- a/src/gallium/drivers/swr/rasterizer/jitter/builder_misc.cpp +++ b/src/gallium/drivers/swr/rasterizer/jitter/builder_misc.cpp @@ -30,8 +30,6 @@ #include "builder.h" #include "common/rdtsc_buckets.h" -#include "llvm/Support/DynamicLibrary.h" - void __cdecl CallPrint(const char* fmt, ...); ////////////////////////////////////////////////////////////////////////// @@ -322,6 +320,32 @@ CallInst *Builder::CALL(Value *Callee, const std::initializer_list<Value*> &args return CALLA(Callee, args); } +#if HAVE_LLVM > 0x306 +CallInst *Builder::CALL(Value *Callee, Value* arg) +{ + std::vector<Value*> args; + args.push_back(arg); + return CALLA(Callee, args); +} + +CallInst *Builder::CALL2(Value *Callee, Value* arg1, Value* arg2) +{ + std::vector<Value*> args; + args.push_back(arg1); + args.push_back(arg2); + return CALLA(Callee, args); +} + +CallInst *Builder::CALL3(Value *Callee, Value* arg1, Value* arg2, Value* arg3) +{ + std::vector<Value*> args; + args.push_back(arg1); + args.push_back(arg2); + args.push_back(arg3); + return CALLA(Callee, args); +} +#endif + Value *Builder::VRCP(Value *va) { return FDIV(VIMMED1(1.0f), va); // 1 / a @@ -726,8 +750,7 @@ Value *Builder::PERMD(Value* a, Value* idx) // use avx2 permute instruction if available if(JM()->mArch.AVX2()) { - // llvm 3.6.0 swapped the order of the args to vpermd - res = VPERMD(idx, a); + res = VPERMD(a, idx); } else { diff --git a/src/gallium/drivers/swr/rasterizer/jitter/builder_misc.h b/src/gallium/drivers/swr/rasterizer/jitter/builder_misc.h index f43ef69d1ed..b01ffa26d0d 100644 --- a/src/gallium/drivers/swr/rasterizer/jitter/builder_misc.h +++ b/src/gallium/drivers/swr/rasterizer/jitter/builder_misc.h @@ -72,6 +72,12 @@ int32_t S_IMMED(Value* i); Value *GEP(Value* ptr, const std::initializer_list<Value*> &indexList); Value *GEP(Value* ptr, const std::initializer_list<uint32_t> &indexList); CallInst *CALL(Value *Callee, const std::initializer_list<Value*> &args); +#if HAVE_LLVM > 0x306 +CallInst *CALL(Value *Callee) { return CALLA(Callee); } +CallInst *CALL(Value *Callee, Value* arg); +CallInst *CALL2(Value *Callee, Value* arg1, Value* arg2); +CallInst *CALL3(Value *Callee, Value* arg1, Value* arg2, Value* arg3); +#endif LoadInst *LOAD(Value *BasePtr, const std::initializer_list<uint32_t> &offset, const llvm::Twine& name = ""); LoadInst *LOADV(Value *BasePtr, const std::initializer_list<Value*> &offset, const llvm::Twine& name = ""); diff --git a/src/gallium/drivers/swr/rasterizer/jitter/fetch_jit.cpp b/src/gallium/drivers/swr/rasterizer/jitter/fetch_jit.cpp index bae0f244fb4..fbd8ecb3a18 100644 --- a/src/gallium/drivers/swr/rasterizer/jitter/fetch_jit.cpp +++ b/src/gallium/drivers/swr/rasterizer/jitter/fetch_jit.cpp @@ -31,7 +31,6 @@ #include "fetch_jit.h" #include "builder.h" #include "state_llvm.h" -#include "llvm/IR/DataLayout.h" #include <sstream> #include <tuple> @@ -181,12 +180,7 @@ Function* FetchJit::Create(const FETCH_COMPILE_STATE& fetchState) verifyFunction(*fetch); -#if HAVE_LLVM == 0x306 - FunctionPassManager -#else - llvm::legacy::FunctionPassManager -#endif - setupPasses(JM()->mpCurrentModule); + ::FunctionPassManager setupPasses(JM()->mpCurrentModule); ///@todo We don't need the CFG passes for fetch. (e.g. BreakCriticalEdges and CFGSimplification) setupPasses.add(createBreakCriticalEdgesPass()); @@ -198,12 +192,7 @@ Function* FetchJit::Create(const FETCH_COMPILE_STATE& fetchState) JitManager::DumpToFile(fetch, "se"); -#if HAVE_LLVM == 0x306 - FunctionPassManager -#else - llvm::legacy::FunctionPassManager -#endif - optPasses(JM()->mpCurrentModule); + ::FunctionPassManager optPasses(JM()->mpCurrentModule); ///@todo Haven't touched these either. Need to remove some of these and add others. optPasses.add(createCFGSimplificationPass()); diff --git a/src/gallium/drivers/swr/rasterizer/jitter/scripts/gen_llvm_ir_macros.py b/src/gallium/drivers/swr/rasterizer/jitter/scripts/gen_llvm_ir_macros.py index a8b101a30a2..4963c5ef593 100644 --- a/src/gallium/drivers/swr/rasterizer/jitter/scripts/gen_llvm_ir_macros.py +++ b/src/gallium/drivers/swr/rasterizer/jitter/scripts/gen_llvm_ir_macros.py @@ -102,7 +102,7 @@ intrinsics = [ ["VPSHUFB", "x86_avx2_pshuf_b", ["a", "b"]], ["VPMOVSXBD", "x86_avx2_pmovsxbd", ["a"]], # sign extend packed 8bit components ["VPMOVSXWD", "x86_avx2_pmovsxwd", ["a"]], # sign extend packed 16bit components - ["VPERMD", "x86_avx2_permd", ["idx", "a"]], + ["VPERMD", "x86_avx2_permd", ["a", "idx"]], ["VPERMPS", "x86_avx2_permps", ["idx", "a"]], ["VCVTPH2PS", "x86_vcvtph2ps_256", ["a"]], ["VCVTPS2PH", "x86_vcvtps2ph_256", ["a", "round"]], @@ -352,7 +352,29 @@ def generate_x86_cpp(output_file): 'Value *Builder::%s(%s)' % (inst[0], args), '{', ' Function *func = Intrinsic::getDeclaration(JM()->mpCurrentModule, Intrinsic::%s);' % inst[1], + ] + if inst[0] == "VPERMD": + rev_args = '' + first = True + for arg in reversed(inst[2]): + if not first: + rev_args += ', ' + rev_args += arg + first = False + + output_lines += [ + '#if (HAVE_LLVM == 0x306) && (LLVM_VERSION_PATCH == 0)', + ' return CALL(func, std::initializer_list<Value*>{%s});' % rev_args, + '#else', + ] + output_lines += [ ' return CALL(func, std::initializer_list<Value*>{%s});' % pass_args, + ] + if inst[0] == "VPERMD": + output_lines += [ + '#endif', + ] + output_lines += [ '}', '', ] diff --git a/src/gallium/drivers/swr/rasterizer/jitter/streamout_jit.cpp b/src/gallium/drivers/swr/rasterizer/jitter/streamout_jit.cpp index d3ac29815e7..289422b11e1 100644 --- a/src/gallium/drivers/swr/rasterizer/jitter/streamout_jit.cpp +++ b/src/gallium/drivers/swr/rasterizer/jitter/streamout_jit.cpp @@ -292,12 +292,7 @@ struct StreamOutJit : public Builder JitManager::DumpToFile(soFunc, "SoFunc"); -#if HAVE_LLVM == 0x306 - FunctionPassManager -#else - llvm::legacy::FunctionPassManager -#endif - passes(JM()->mpCurrentModule); + ::FunctionPassManager passes(JM()->mpCurrentModule); passes.add(createBreakCriticalEdgesPass()); passes.add(createCFGSimplificationPass()); |