mirror of
https://github.com/ZDoom/qzdoom.git
synced 2024-11-29 15:32:54 +00:00
Change how the LLVM execution engine to constructed and printf which target triple and CPU is being used
This commit is contained in:
parent
1c2dcad36e
commit
1cd27ca98a
1 changed files with 29 additions and 35 deletions
|
@ -446,10 +446,18 @@ LLVMProgram::LLVMProgram()
|
|||
InitializeNativeTarget();
|
||||
InitializeNativeTargetAsmPrinter();
|
||||
|
||||
mContext = std::make_unique<LLVMContext>();
|
||||
mModule = std::make_unique<Module>("render", context());
|
||||
}
|
||||
|
||||
void LLVMProgram::CreateEE()
|
||||
{
|
||||
using namespace llvm;
|
||||
|
||||
std::string errorstring;
|
||||
|
||||
#if 0
|
||||
std::string targetTriple = sys::getProcessTriple();
|
||||
std::string cpuName = sys::getHostCPUName();
|
||||
StringMap<bool> cpuFeatures;
|
||||
sys::getHostCPUFeatures(cpuFeatures);
|
||||
std::string cpuFeaturesStr;
|
||||
|
@ -461,40 +469,32 @@ LLVMProgram::LLVMProgram()
|
|||
cpuFeaturesStr += it.getKey();
|
||||
}
|
||||
|
||||
DPrintf(DMSG_SPAMMY, "LLVM target triple: %s\n", targetTriple.c_str());
|
||||
DPrintf(DMSG_SPAMMY, "LLVM CPU and features: %s, %s\n", cpuName.c_str(), cpuFeaturesStr.c_str());
|
||||
|
||||
const Target *target = TargetRegistry::lookupTarget(targetTriple, errorstring);
|
||||
if (!target)
|
||||
I_FatalError("Could not find LLVM target: %s", errorstring.c_str());
|
||||
|
||||
TargetOptions opt;
|
||||
#if LLVM_VERSION_MAJOR < 3 || (LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR < 9)
|
||||
Reloc::Model relocModel = Reloc::Default;
|
||||
#else
|
||||
auto relocModel = Optional<Reloc::Model>();
|
||||
Printf("LLVM CPU features: %s\n", cpuFeaturesStr.c_str());
|
||||
#endif
|
||||
machine = target->createTargetMachine(targetTriple, cpuName, cpuFeaturesStr, opt, relocModel, CodeModel::JITDefault, CodeGenOpt::Aggressive);
|
||||
|
||||
llvm::Module *module = mModule.get();
|
||||
EngineBuilder engineBuilder(std::move(mModule));
|
||||
engineBuilder.setErrorStr(&errorstring);
|
||||
engineBuilder.setOptLevel(CodeGenOpt::Aggressive);
|
||||
engineBuilder.setEngineKind(EngineKind::JIT);
|
||||
engineBuilder.setMCPU(sys::getHostCPUName());
|
||||
machine = engineBuilder.selectTarget();
|
||||
if (!machine)
|
||||
I_FatalError("Could not create LLVM target machine");
|
||||
|
||||
mContext = std::make_unique<LLVMContext>();
|
||||
std::string targetTriple = machine->getTargetTriple().getTriple();
|
||||
std::string cpuName = machine->getTargetCPU();
|
||||
Printf("LLVM target triple: %s\n", targetTriple.c_str());
|
||||
Printf("LLVM target CPU: %s\n", cpuName.c_str());
|
||||
|
||||
mModule = std::make_unique<Module>("render", context());
|
||||
mModule->setTargetTriple(targetTriple);
|
||||
module->setTargetTriple(targetTriple);
|
||||
#if LLVM_VERSION_MAJOR < 3 || (LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR < 8)
|
||||
mModule->setDataLayout(new DataLayout(*machine->getSubtargetImpl()->getDataLayout()));
|
||||
module->setDataLayout(new DataLayout(*machine->getSubtargetImpl()->getDataLayout()));
|
||||
#else
|
||||
mModule->setDataLayout(machine->createDataLayout());
|
||||
module->setDataLayout(machine->createDataLayout());
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
void LLVMProgram::CreateEE()
|
||||
{
|
||||
using namespace llvm;
|
||||
|
||||
legacy::FunctionPassManager PerFunctionPasses(mModule.get());
|
||||
legacy::FunctionPassManager PerFunctionPasses(module);
|
||||
legacy::PassManager PerModulePasses;
|
||||
|
||||
#if LLVM_VERSION_MAJOR > 3 || (LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 8)
|
||||
|
@ -514,7 +514,7 @@ void LLVMProgram::CreateEE()
|
|||
|
||||
// Run function passes:
|
||||
PerFunctionPasses.doInitialization();
|
||||
for (llvm::Function &func : *mModule.get())
|
||||
for (llvm::Function &func : *module)
|
||||
{
|
||||
if (!func.isDeclaration())
|
||||
PerFunctionPasses.run(func);
|
||||
|
@ -522,15 +522,9 @@ void LLVMProgram::CreateEE()
|
|||
PerFunctionPasses.doFinalization();
|
||||
|
||||
// Run module passes:
|
||||
PerModulePasses.run(*mModule.get());
|
||||
PerModulePasses.run(*module);
|
||||
|
||||
std::string errorstring;
|
||||
|
||||
EngineBuilder engineBuilder(std::move(mModule));
|
||||
engineBuilder.setErrorStr(&errorstring);
|
||||
engineBuilder.setOptLevel(CodeGenOpt::Aggressive);
|
||||
engineBuilder.setRelocationModel(Reloc::Static);
|
||||
engineBuilder.setEngineKind(EngineKind::JIT);
|
||||
// Create execution engine and generate machine code
|
||||
mEngine.reset(engineBuilder.create(machine));
|
||||
if (!mEngine)
|
||||
I_FatalError("Could not create LLVM execution engine: %s", errorstring.c_str());
|
||||
|
|
Loading…
Reference in a new issue