swr: [rasterizer jitter] cleanup supporting different llvm versions

Reviewed-by: Bruce Cherniak <bruce.cherniak@intel.com>
This commit is contained in:
Tim Rowley 2016-06-06 19:13:22 -06:00
parent 42215e6116
commit d3d97f8395
8 changed files with 73 additions and 34 deletions

View file

@ -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

View 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"
@ -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")

View 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());

View 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
{

View 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 = "");

View 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());

View 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 += [
'}',
'',
]

View 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());