swr: [rasterizer jitter] cleanup supporting different llvm versions
authorTim Rowley <timothy.o.rowley@intel.com>
Tue, 7 Jun 2016 01:13:22 +0000 (19:13 -0600)
committerTim Rowley <timothy.o.rowley@intel.com>
Thu, 23 Jun 2016 15:50:19 +0000 (10:50 -0500)
Reviewed-by: Bruce Cherniak <bruce.cherniak@intel.com>
src/gallium/drivers/swr/rasterizer/jitter/JitManager.cpp
src/gallium/drivers/swr/rasterizer/jitter/JitManager.h
src/gallium/drivers/swr/rasterizer/jitter/blend_jit.cpp
src/gallium/drivers/swr/rasterizer/jitter/builder_misc.cpp
src/gallium/drivers/swr/rasterizer/jitter/builder_misc.h
src/gallium/drivers/swr/rasterizer/jitter/fetch_jit.cpp
src/gallium/drivers/swr/rasterizer/jitter/scripts/gen_llvm_ir_macros.py
src/gallium/drivers/swr/rasterizer/jitter/streamout_jit.cpp

index 4bbd9ad62fcabf2b1bde726a5d7e2db15cae1558..6e00a70c8875580d4424786d6895e1bec7773d66 100644 (file)
 #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
index 14ba893fc256c8bf73d249c3c1d587e6fe29a905..354bfe869baf0698ee18e12cde5b6c73d0f7b5cd 100644 (file)
@@ -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"
 
 #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")
index 1b5290ce230ada65feac9e4b0f45b85471d63099..940399c2020496a77475bf388090b6025d072749 100644 (file)
@@ -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());
index 2f4fa382ebf152cd40d322b9b4b8613f68e404f7..671178f719fffc6c6428c52dd922e269d76104a7 100644 (file)
@@ -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
     {
index f43ef69d1ed084eae50eb5c4013f853222cf31d4..b01ffa26d0d32d421ad96760da082320ea58e0b5 100644 (file)
@@ -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 = "");
index bae0f244fb44b0d14ac6a52eeaa39b92f1693873..fbd8ecb3a18ac4f49d832c2eb062ac9bc09bbc33 100644 (file)
@@ -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());
index a8b101a30a2130109055fd8f8a1f77b0f9e06caf..4963c5ef593a8cabf890c6817aa41c09db25af9f 100644 (file)
@@ -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 += [
             '}',
             '',
         ]
index d3ac29815e79bea036af73ee4f990305584e75b9..289422b11e153cc08119f1492fddf1bede7d4ce2 100644 (file)
@@ -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());