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) { ...@@ -209,16 +209,28 @@ runtime::Module BuildAMDGPU(Array<LoweredFunc> funcs, std::string target) {
#endif #endif
llvm::legacy::PassManager pass; llvm::legacy::PassManager pass;
#if TVM_LLVM_VERSION <= 60
CHECK(tm->addPassesToEmitFile( CHECK(tm->addPassesToEmitFile(
pass, destObj, llvm::TargetMachine::CGFT_ObjectFile) == 0) pass, destObj, llvm::TargetMachine::CGFT_ObjectFile) == 0)
<< "Cannot emit target CGFT_ObjectFile"; << "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); pass.run(*mObj);
std::string obj(dataObj.begin(), dataObj.end()); std::string obj(dataObj.begin(), dataObj.end());
llvm::legacy::PassManager passAsm; llvm::legacy::PassManager passAsm;
#if TVM_LLVM_VERSION <= 60
CHECK(tm->addPassesToEmitFile(passAsm, destAsm, CHECK(tm->addPassesToEmitFile(passAsm, destAsm,
llvm::TargetMachine::CGFT_AssemblyFile) == 0) llvm::TargetMachine::CGFT_AssemblyFile) == 0)
<< "Cannot emit target CGFT_AssemblyFile"; << "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); passAsm.run(*mAsm);
std::string assembly(dataAsm.begin(), dataAsm.end()); std::string assembly(dataAsm.begin(), dataAsm.end());
......
...@@ -194,9 +194,15 @@ runtime::Module BuildNVPTX(Array<LoweredFunc> funcs, std::string target) { ...@@ -194,9 +194,15 @@ runtime::Module BuildNVPTX(Array<LoweredFunc> funcs, std::string target) {
std::string ll(data_ll.begin(), data_ll.end()); std::string ll(data_ll.begin(), data_ll.end());
// emit ptx // emit ptx
llvm::legacy::PassManager pass; llvm::legacy::PassManager pass;
#if TVM_LLVM_VERSION <= 60
CHECK(tm->addPassesToEmitFile( CHECK(tm->addPassesToEmitFile(
pass, dest_ptx, llvm::TargetMachine::CGFT_AssemblyFile) == 0) pass, dest_ptx, llvm::TargetMachine::CGFT_AssemblyFile) == 0)
<< "Cannot emit target CGFT_ObjectFile"; << "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); pass.run(*module);
std::string ptx(data_ptx.begin(), data_ptx.end()); std::string ptx(data_ptx.begin(), data_ptx.end());
return CUDAModuleCreate(ptx, "ptx", ExtractFuncInfo(funcs), ll); return CUDAModuleCreate(ptx, "ptx", ExtractFuncInfo(funcs), ll);
......
...@@ -69,9 +69,15 @@ class LLVMModuleNode final : public runtime::ModuleNode { ...@@ -69,9 +69,15 @@ class LLVMModuleNode final : public runtime::ModuleNode {
#endif #endif
llvm::legacy::PassManager pass; llvm::legacy::PassManager pass;
CHECK(tm_); CHECK(tm_);
#if TVM_LLVM_VERSION <= 60
CHECK(tm_->addPassesToEmitFile( CHECK(tm_->addPassesToEmitFile(
pass, dest, llvm::TargetMachine::CGFT_ObjectFile) == 0) pass, dest, llvm::TargetMachine::CGFT_ObjectFile) == 0)
<< "Cannot emit target CGFT_ObjectFile"; << "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); pass.run(*m);
} else if (fmt == "s" || fmt == "asm") { } else if (fmt == "s" || fmt == "asm") {
#if TVM_LLVM_VERSION <= 60 #if TVM_LLVM_VERSION <= 60
...@@ -81,9 +87,15 @@ class LLVMModuleNode final : public runtime::ModuleNode { ...@@ -81,9 +87,15 @@ class LLVMModuleNode final : public runtime::ModuleNode {
#endif #endif
llvm::legacy::PassManager pass; llvm::legacy::PassManager pass;
CHECK(tm_); CHECK(tm_);
#if TVM_LLVM_VERSION <= 60
CHECK(tm_->addPassesToEmitFile( CHECK(tm_->addPassesToEmitFile(
pass, dest, llvm::TargetMachine::CGFT_AssemblyFile) == 0) pass, dest, llvm::TargetMachine::CGFT_AssemblyFile) == 0)
<< "Cannot emit target CGFT_AssemblyFile"; << "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); pass.run(*m);
} else if (fmt == "ll") { } else if (fmt == "ll") {
mptr_->print(dest, nullptr); 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