[Mesa-dev] [PATCH v2 05/14] swr: [rasterizer jitter] cleanup supporting different llvm versions
Tim Rowley
timothy.o.rowley at intel.com
Mon Jun 20 21:36:59 UTC 2016
---
.../drivers/swr/rasterizer/jitter/JitManager.cpp | 9 +++++--
.../drivers/swr/rasterizer/jitter/JitManager.h | 7 ++++-
.../drivers/swr/rasterizer/jitter/blend_jit.cpp | 8 +-----
.../drivers/swr/rasterizer/jitter/builder_misc.cpp | 31 +++++++++++++++++++---
.../drivers/swr/rasterizer/jitter/builder_misc.h | 6 +++++
.../drivers/swr/rasterizer/jitter/fetch_jit.cpp | 15 ++---------
.../jitter/scripts/gen_llvm_ir_macros.py | 24 ++++++++++++++++-
.../swr/rasterizer/jitter/streamout_jit.cpp | 7 +----
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 4bbd9ad..6e00a70 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 14ba893..354bfe8 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 1b5290c..940399c 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 2f4fa38..671178f 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 f43ef69..b01ffa2 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 bae0f24..fbd8ecb 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 a8b101a..4963c5e 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 d3ac298..289422b 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());
--
1.9.1
More information about the mesa-dev
mailing list