swr/rast: New execution engine per JIT
Fixes relocation errors with LLVM 7.0.0
This commit is contained in:
parent
b135db5d58
commit
bb98be61f4
|
@ -63,39 +63,29 @@ JitManager::JitManager(uint32_t simdWidth, const char* arch, const char* core) :
|
||||||
mContext(), mBuilder(mContext), mIsModuleFinalized(true), mJitNumber(0), mVWidth(simdWidth),
|
mContext(), mBuilder(mContext), mIsModuleFinalized(true), mJitNumber(0), mVWidth(simdWidth),
|
||||||
mArch(arch)
|
mArch(arch)
|
||||||
{
|
{
|
||||||
|
mpCurrentModule = nullptr;
|
||||||
|
mpExec = nullptr;
|
||||||
|
|
||||||
InitializeNativeTarget();
|
InitializeNativeTarget();
|
||||||
InitializeNativeTargetAsmPrinter();
|
InitializeNativeTargetAsmPrinter();
|
||||||
InitializeNativeTargetDisassembler();
|
InitializeNativeTargetDisassembler();
|
||||||
|
|
||||||
|
|
||||||
TargetOptions tOpts;
|
|
||||||
tOpts.AllowFPOpFusion = FPOpFusion::Fast;
|
|
||||||
tOpts.NoInfsFPMath = false;
|
|
||||||
tOpts.NoNaNsFPMath = false;
|
|
||||||
tOpts.UnsafeFPMath = false;
|
|
||||||
|
|
||||||
// tOpts.PrintMachineCode = true;
|
|
||||||
|
|
||||||
std::unique_ptr<Module> newModule(new Module("", mContext));
|
|
||||||
mpCurrentModule = newModule.get();
|
|
||||||
|
|
||||||
StringRef hostCPUName;
|
|
||||||
|
|
||||||
// force JIT to use the same CPU arch as the rest of swr
|
// force JIT to use the same CPU arch as the rest of swr
|
||||||
if (mArch.AVX512F())
|
if (mArch.AVX512F())
|
||||||
{
|
{
|
||||||
#if USE_SIMD16_SHADERS
|
#if USE_SIMD16_SHADERS
|
||||||
if (mArch.AVX512ER())
|
if (mArch.AVX512ER())
|
||||||
{
|
{
|
||||||
hostCPUName = StringRef("knl");
|
mHostCpuName = StringRef("knl");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
hostCPUName = StringRef("skylake-avx512");
|
mHostCpuName = StringRef("skylake-avx512");
|
||||||
}
|
}
|
||||||
mUsingAVX512 = true;
|
mUsingAVX512 = true;
|
||||||
#else
|
#else
|
||||||
hostCPUName = StringRef("core-avx2");
|
mHostCpuName = StringRef("core-avx2");
|
||||||
#endif
|
#endif
|
||||||
if (mVWidth == 0)
|
if (mVWidth == 0)
|
||||||
{
|
{
|
||||||
|
@ -104,7 +94,7 @@ JitManager::JitManager(uint32_t simdWidth, const char* arch, const char* core) :
|
||||||
}
|
}
|
||||||
else if (mArch.AVX2())
|
else if (mArch.AVX2())
|
||||||
{
|
{
|
||||||
hostCPUName = StringRef("core-avx2");
|
mHostCpuName = StringRef("core-avx2");
|
||||||
if (mVWidth == 0)
|
if (mVWidth == 0)
|
||||||
{
|
{
|
||||||
mVWidth = 8;
|
mVWidth = 8;
|
||||||
|
@ -114,11 +104,11 @@ JitManager::JitManager(uint32_t simdWidth, const char* arch, const char* core) :
|
||||||
{
|
{
|
||||||
if (mArch.F16C())
|
if (mArch.F16C())
|
||||||
{
|
{
|
||||||
hostCPUName = StringRef("core-avx-i");
|
mHostCpuName = StringRef("core-avx-i");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
hostCPUName = StringRef("corei7-avx");
|
mHostCpuName = StringRef("corei7-avx");
|
||||||
}
|
}
|
||||||
if (mVWidth == 0)
|
if (mVWidth == 0)
|
||||||
{
|
{
|
||||||
|
@ -131,31 +121,21 @@ JitManager::JitManager(uint32_t simdWidth, const char* arch, const char* core) :
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
auto optLevel = CodeGenOpt::Aggressive;
|
mOptLevel = CodeGenOpt::Aggressive;
|
||||||
|
|
||||||
if (KNOB_JIT_OPTIMIZATION_LEVEL >= CodeGenOpt::None &&
|
if (KNOB_JIT_OPTIMIZATION_LEVEL >= CodeGenOpt::None &&
|
||||||
KNOB_JIT_OPTIMIZATION_LEVEL <= CodeGenOpt::Aggressive)
|
KNOB_JIT_OPTIMIZATION_LEVEL <= CodeGenOpt::Aggressive)
|
||||||
{
|
{
|
||||||
optLevel = CodeGenOpt::Level(KNOB_JIT_OPTIMIZATION_LEVEL);
|
mOptLevel = CodeGenOpt::Level(KNOB_JIT_OPTIMIZATION_LEVEL);
|
||||||
}
|
}
|
||||||
|
|
||||||
mpCurrentModule->setTargetTriple(sys::getProcessTriple());
|
|
||||||
mpExec = EngineBuilder(std::move(newModule))
|
|
||||||
.setTargetOptions(tOpts)
|
|
||||||
.setOptLevel(optLevel)
|
|
||||||
.setMCPU(hostCPUName)
|
|
||||||
.create();
|
|
||||||
|
|
||||||
if (KNOB_JIT_ENABLE_CACHE)
|
if (KNOB_JIT_ENABLE_CACHE)
|
||||||
{
|
{
|
||||||
mCache.Init(this, hostCPUName, optLevel);
|
mCache.Init(this, mHostCpuName, mOptLevel);
|
||||||
mpExec->setObjectCache(&mCache);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if LLVM_USE_INTEL_JITEVENTS
|
SetupNewModule();
|
||||||
JITEventListener* vTune = JITEventListener::createIntelJITEventListener();
|
mIsModuleFinalized = true;
|
||||||
mpExec->RegisterJITEventListener(vTune);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// fetch function signature
|
// fetch function signature
|
||||||
#if USE_SIMD16_SHADERS
|
#if USE_SIMD16_SHADERS
|
||||||
|
@ -198,6 +178,35 @@ JitManager::JitManager(uint32_t simdWidth, const char* arch, const char* core) :
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void JitManager::CreateExecEngine(std::unique_ptr<Module> pModule)
|
||||||
|
{
|
||||||
|
TargetOptions tOpts;
|
||||||
|
tOpts.AllowFPOpFusion = FPOpFusion::Fast;
|
||||||
|
tOpts.NoInfsFPMath = false;
|
||||||
|
tOpts.NoNaNsFPMath = false;
|
||||||
|
tOpts.UnsafeFPMath = false;
|
||||||
|
|
||||||
|
// tOpts.PrintMachineCode = true;
|
||||||
|
|
||||||
|
mpExec = EngineBuilder(std::move(pModule))
|
||||||
|
.setTargetOptions(tOpts)
|
||||||
|
.setOptLevel(mOptLevel)
|
||||||
|
.setMCPU(mHostCpuName)
|
||||||
|
.create();
|
||||||
|
|
||||||
|
if (KNOB_JIT_ENABLE_CACHE)
|
||||||
|
{
|
||||||
|
mpExec->setObjectCache(&mCache);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if LLVM_USE_INTEL_JITEVENTS
|
||||||
|
JITEventListener* vTune = JITEventListener::createIntelJITEventListener();
|
||||||
|
mpExec->RegisterJITEventListener(vTune);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
mvExecEngines.push_back(mpExec);
|
||||||
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// @brief Create new LLVM module.
|
/// @brief Create new LLVM module.
|
||||||
void JitManager::SetupNewModule()
|
void JitManager::SetupNewModule()
|
||||||
|
@ -207,7 +216,7 @@ void JitManager::SetupNewModule()
|
||||||
std::unique_ptr<Module> newModule(new Module("", mContext));
|
std::unique_ptr<Module> newModule(new Module("", mContext));
|
||||||
mpCurrentModule = newModule.get();
|
mpCurrentModule = newModule.get();
|
||||||
mpCurrentModule->setTargetTriple(sys::getProcessTriple());
|
mpCurrentModule->setTargetTriple(sys::getProcessTriple());
|
||||||
mpExec->addModule(std::move(newModule));
|
CreateExecEngine(std::move(newModule));
|
||||||
mIsModuleFinalized = false;
|
mIsModuleFinalized = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -124,12 +124,21 @@ private:
|
||||||
struct JitManager
|
struct JitManager
|
||||||
{
|
{
|
||||||
JitManager(uint32_t w, const char* arch, const char* core);
|
JitManager(uint32_t w, const char* arch, const char* core);
|
||||||
~JitManager(){};
|
~JitManager()
|
||||||
|
{
|
||||||
|
for (auto* pExec : mvExecEngines)
|
||||||
|
{
|
||||||
|
delete pExec;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
JitLLVMContext mContext; ///< LLVM compiler
|
JitLLVMContext mContext; ///< LLVM compiler
|
||||||
llvm::IRBuilder<> mBuilder; ///< LLVM IR Builder
|
llvm::IRBuilder<> mBuilder; ///< LLVM IR Builder
|
||||||
llvm::ExecutionEngine* mpExec;
|
llvm::ExecutionEngine* mpExec;
|
||||||
JitCache mCache;
|
std::vector<llvm::ExecutionEngine*> mvExecEngines;
|
||||||
|
JitCache mCache;
|
||||||
|
llvm::StringRef mHostCpuName;
|
||||||
|
llvm::CodeGenOpt::Level mOptLevel;
|
||||||
|
|
||||||
// Need to be rebuilt after a JIT and before building new IR
|
// Need to be rebuilt after a JIT and before building new IR
|
||||||
llvm::Module* mpCurrentModule;
|
llvm::Module* mpCurrentModule;
|
||||||
|
@ -148,11 +157,14 @@ struct JitManager
|
||||||
// Debugging support
|
// Debugging support
|
||||||
std::unordered_map<llvm::StructType*, llvm::DIType*> mDebugStructMap;
|
std::unordered_map<llvm::StructType*, llvm::DIType*> mDebugStructMap;
|
||||||
|
|
||||||
|
void CreateExecEngine(std::unique_ptr<llvm::Module> M);
|
||||||
void SetupNewModule();
|
void SetupNewModule();
|
||||||
|
|
||||||
void DumpAsm(llvm::Function* pFunction, const char* fileName);
|
void DumpAsm(llvm::Function* pFunction, const char* fileName);
|
||||||
static void DumpToFile(llvm::Function* f, const char* fileName);
|
static void DumpToFile(llvm::Function* f, const char* fileName);
|
||||||
static void DumpToFile(llvm::Module* M, const char* fileName, llvm::AssemblyAnnotationWriter* annotater = nullptr);
|
static void DumpToFile(llvm::Module* M,
|
||||||
|
const char* fileName,
|
||||||
|
llvm::AssemblyAnnotationWriter* annotater = nullptr);
|
||||||
static std::string GetOutputDir();
|
static std::string GetOutputDir();
|
||||||
|
|
||||||
// Debugging support methods
|
// Debugging support methods
|
||||||
|
@ -183,8 +195,10 @@ struct JitManager
|
||||||
class InterleaveAssemblyAnnotater : public llvm::AssemblyAnnotationWriter
|
class InterleaveAssemblyAnnotater : public llvm::AssemblyAnnotationWriter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void emitInstructionAnnot(const llvm::Instruction *pInst, llvm::formatted_raw_ostream &OS) override;
|
void emitInstructionAnnot(const llvm::Instruction* pInst,
|
||||||
|
llvm::formatted_raw_ostream& OS) override;
|
||||||
std::vector<std::string> mAssembly;
|
std::vector<std::string> mAssembly;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint32_t mCurrentLineNo = 0;
|
uint32_t mCurrentLineNo = 0;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue