Commit 8157e5b1 by Hiroshi Inoue Committed by Tianqi Chen

Fix compilation failure with latest LLVM (#1208)

* fix problem with the latest LLVM

* add if-defs to support older LLVMs
parent 18d60866
......@@ -209,16 +209,28 @@ runtime::Module BuildAMDGPU(Array<LoweredFunc> funcs, std::string target) {
#endif
llvm::legacy::PassManager pass;
#if TVM_LLVM_VERSION <= 60
CHECK(tm->addPassesToEmitFile(
pass, destObj, llvm::TargetMachine::CGFT_ObjectFile) == 0)
<< "Cannot emit target CGFT_ObjectFile";
#else
CHECK(tm->addPassesToEmitFile(
pass, destObj, nullptr, llvm::TargetMachine::CGFT_ObjectFile) == 0)
<< "Cannot emit target CGFT_ObjectFile";
#endif
pass.run(*mObj);
std::string obj(dataObj.begin(), dataObj.end());
llvm::legacy::PassManager passAsm;
#if TVM_LLVM_VERSION <= 60
CHECK(tm->addPassesToEmitFile(passAsm, destAsm,
llvm::TargetMachine::CGFT_AssemblyFile) == 0)
<< "Cannot emit target CGFT_AssemblyFile";
#else
CHECK(tm->addPassesToEmitFile(passAsm, destAsm, nullptr,
llvm::TargetMachine::CGFT_AssemblyFile) == 0)
<< "Cannot emit target CGFT_AssemblyFile";
#endif
passAsm.run(*mAsm);
std::string assembly(dataAsm.begin(), dataAsm.end());
......
......@@ -194,9 +194,15 @@ runtime::Module BuildNVPTX(Array<LoweredFunc> funcs, std::string target) {
std::string ll(data_ll.begin(), data_ll.end());
// emit ptx
llvm::legacy::PassManager pass;
#if TVM_LLVM_VERSION <= 60
CHECK(tm->addPassesToEmitFile(
pass, dest_ptx, llvm::TargetMachine::CGFT_AssemblyFile) == 0)
<< "Cannot emit target CGFT_ObjectFile";
#else
CHECK(tm->addPassesToEmitFile(
pass, dest_ptx, nullptr, llvm::TargetMachine::CGFT_AssemblyFile) == 0)
<< "Cannot emit target CGFT_ObjectFile";
#endif
pass.run(*module);
std::string ptx(data_ptx.begin(), data_ptx.end());
return CUDAModuleCreate(ptx, "ptx", ExtractFuncInfo(funcs), ll);
......
......@@ -69,9 +69,15 @@ class LLVMModuleNode final : public runtime::ModuleNode {
#endif
llvm::legacy::PassManager pass;
CHECK(tm_);
#if TVM_LLVM_VERSION <= 60
CHECK(tm_->addPassesToEmitFile(
pass, dest, llvm::TargetMachine::CGFT_ObjectFile) == 0)
<< "Cannot emit target CGFT_ObjectFile";
#else
CHECK(tm_->addPassesToEmitFile(
pass, dest, nullptr, llvm::TargetMachine::CGFT_ObjectFile) == 0)
<< "Cannot emit target CGFT_ObjectFile";
#endif
pass.run(*m);
} else if (fmt == "s" || fmt == "asm") {
#if TVM_LLVM_VERSION <= 60
......@@ -81,9 +87,15 @@ class LLVMModuleNode final : public runtime::ModuleNode {
#endif
llvm::legacy::PassManager pass;
CHECK(tm_);
#if TVM_LLVM_VERSION <= 60
CHECK(tm_->addPassesToEmitFile(
pass, dest, llvm::TargetMachine::CGFT_AssemblyFile) == 0)
<< "Cannot emit target CGFT_AssemblyFile";
#else
CHECK(tm_->addPassesToEmitFile(
pass, dest, nullptr, llvm::TargetMachine::CGFT_AssemblyFile) == 0)
<< "Cannot emit target CGFT_AssemblyFile";
#endif
pass.run(*m);
} else if (fmt == "ll") {
mptr_->print(dest, nullptr);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment