Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/target/llvm/codegen_amdgpu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,11 @@ runtime::Module BuildAMDGPU(IRModule mod, Target target) {

for (auto& bitcode_path : bitcode_files) {
std::unique_ptr<llvm::Module> mlib = llvm_instance.LoadIR(bitcode_path);
#if TVM_LLVM_VERSION >= 210
mlib->setTargetTriple(llvm::Triple(llvm_target->GetTargetTriple()));
#else
mlib->setTargetTriple(llvm_target->GetTargetTriple());
#endif
mlib->setDataLayout(tm->createDataLayout());

for (llvm::Function& f : mlib->functions()) {
Expand Down
4 changes: 4 additions & 0 deletions src/target/llvm/codegen_blob.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ std::unique_ptr<llvm::Module> CodeGenBlob(const std::string& data, bool system_l
llvm::LLVMContext* ctx = llvm_target->GetContext();
std::string module_name = c_symbol_prefix + "devc";
auto module = std::make_unique<llvm::Module>(module_name, *ctx);
#if TVM_LLVM_VERSION >= 210
module->setTargetTriple(triple);
#else
module->setTargetTriple(triple.str());
#endif
llvm_target->SetTargetMetadata(module.get());
module->setDataLayout(tm->createDataLayout());
auto* blob_value = llvm::ConstantDataArray::getString(*ctx, data, false);
Expand Down
8 changes: 8 additions & 0 deletions src/target/llvm/codegen_llvm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,11 @@ void CodeGenLLVM::SetFastMathFlags(llvm::FastMathFlags fmf) { builder_->setFastM

void CodeGenLLVM::InitTarget() {
llvm::TargetMachine* tm = llvm_target_->GetOrCreateTargetMachine();
#if TVM_LLVM_VERSION >= 210
module_->setTargetTriple(tm->getTargetTriple());
#else
module_->setTargetTriple(tm->getTargetTriple().str());
#endif
module_->setDataLayout(tm->createDataLayout());
#if TVM_LLVM_VERSION >= 200
data_layout_.reset(new llvm::DataLayout(module_.get()->getDataLayout()));
Expand Down Expand Up @@ -374,7 +378,11 @@ void CodeGenLLVM::HandleImport(const std::string& code) {
mlib = llvm_target_->GetInstance().ParseIR(code);
}

#if TVM_LLVM_VERSION >= 210
mlib->setTargetTriple(llvm::Triple(llvm_target_->GetTargetTriple()));
#else
mlib->setTargetTriple(llvm_target_->GetTargetTriple());
#endif
mlib->setDataLayout(llvm_target_->GetOrCreateTargetMachine()->createDataLayout());
// mark all the functions as force inline
for (llvm::Function& f : mlib->functions()) {
Expand Down
8 changes: 8 additions & 0 deletions src/target/llvm/codegen_nvptx.cc
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,11 @@ class CodeGenNVPTX : public CodeGenLLVM {
} else if (sync == "shared" || sync == "shared.dyn") {
#if TVM_LLVM_VERSION >= 200
llvm::Function* f = llvm::cast<llvm::Function>(llvm::Intrinsic::getOrInsertDeclaration(
#if TVM_LLVM_VERSION >= 210
module_.get(), llvm::Intrinsic::nvvm_barrier_cta_sync_aligned_all, {}));
#else
module_.get(), llvm::Intrinsic::nvvm_barrier0, {}));
#endif
#else
llvm::Function* f =
llvm::Intrinsic::getDeclaration(module_.get(), llvm::Intrinsic::nvvm_barrier0);
Expand Down Expand Up @@ -335,7 +339,11 @@ runtime::Module BuildNVPTX(IRModule mod, Target target) {
std::string path = (*flibdevice_path)(compute_ver).cast<std::string>();
if (path.length() != 0) {
std::unique_ptr<llvm::Module> mlib = llvm_instance.LoadIR(path);
#if TVM_LLVM_VERSION >= 210
mlib->setTargetTriple(llvm::Triple(llvm_target->GetTargetTriple()));
#else
mlib->setTargetTriple(llvm_target->GetTargetTriple());
#endif
mlib->setDataLayout(tm->createDataLayout());
cg->AddLinkModule(std::move(mlib));
}
Expand Down
4 changes: 4 additions & 0 deletions src/target/llvm/llvm_instance.cc
Original file line number Diff line number Diff line change
Expand Up @@ -981,7 +981,11 @@ std::string LLVMTarget::GetTargetMetadata(const llvm::Module& module) {
return meta.str();
}
}
#if TVM_LLVM_VERSION >= 210
return "llvm -mtriple " + module.getTargetTriple().str();
#else
return "llvm -mtriple " + module.getTargetTriple();
#endif
}

void LLVMTarget::SetTargetMetadata(llvm::Module* module) const {
Expand Down
27 changes: 26 additions & 1 deletion src/target/llvm/llvm_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,11 @@ void LLVMModuleNode::InitMCJIT() {
// create MCJIT
mcjit_ee_ = builder.create(tm.release());
ICHECK(mcjit_ee_ != nullptr) << "Failed to initialize LLVM MCJIT engine for "
#if TVM_LLVM_VERSION >= 210
<< module_->getTargetTriple().str();
#else
<< module_->getTargetTriple();
#endif

VLOG(2) << "LLVM MCJIT execute " << module_->getModuleIdentifier() << " for triple `"
<< llvm_target->GetTargetTriple() << "`"
Expand Down Expand Up @@ -503,21 +507,34 @@ void LLVMModuleNode::InitORCJIT() {
#if TVM_LLVM_VERSION >= 130
// linker
const auto linkerBuilder =
#if TVM_LLVM_VERSION >= 210
[&](llvm::orc::ExecutionSession& session)
-> llvm::Expected<std::unique_ptr<llvm::orc::ObjectLayer>> {
#else
[&](llvm::orc::ExecutionSession& session,
const llvm::Triple& triple) -> std::unique_ptr<llvm::orc::ObjectLayer> {
#endif
#if _WIN32
auto GetMemMgr = []() { return std::make_unique<llvm::SectionMemoryManager>(); };
auto ObjLinkingLayer =
std::make_unique<llvm::orc::RTDyldObjectLinkingLayer>(session, std::move(GetMemMgr));
#else
auto ObjLinkingLayer = std::make_unique<llvm::orc::ObjectLinkingLayer>(session);
#endif
#if TVM_LLVM_VERSION >= 210
if (tm_builder.getTargetTriple().isOSBinFormatCOFF()) {
#else
if (triple.isOSBinFormatCOFF()) {
#endif
ObjLinkingLayer->setOverrideObjectFlagsWithResponsibilityFlags(true);
ObjLinkingLayer->setAutoClaimResponsibilityForObjectSymbols(true);
}
#if TVM_LLVM_VERSION >= 210
return llvm::Expected<std::unique_ptr<llvm::orc::ObjectLayer>>(std::move(ObjLinkingLayer));
#else
return ObjLinkingLayer;
};
#endif
}; // NOLINT(readability/braces)
#endif

// create LLJIT
Expand All @@ -532,7 +549,11 @@ void LLVMModuleNode::InitORCJIT() {
.create());

ICHECK(orcjit_ee_ != nullptr) << "Failed to initialize LLVM ORCJIT engine for "
#if TVM_LLVM_VERSION >= 210
<< module_->getTargetTriple().str();
#else
<< module_->getTargetTriple();
#endif

// store ctors
auto ctors = llvm::orc::getConstructors(*module_);
Expand Down Expand Up @@ -638,7 +659,11 @@ static void LLVMReflectionRegister() {
// Generate a LLVM module from an input target string
auto module = std::make_unique<llvm::Module>(module_name, *llvm_target->GetContext());
llvm_target->SetTargetMetadata(module.get());
#if TVM_LLVM_VERSION >= 210
module->setTargetTriple(llvm::Triple(llvm_target->GetTargetTriple()));
#else
module->setTargetTriple(llvm_target->GetTargetTriple());
#endif
module->setDataLayout(llvm_target->GetOrCreateTargetMachine()->createDataLayout());
n->Init(std::move(module), std::move(llvm_instance));
n->SetJITEngine(llvm_target->GetJITEngine());
Expand Down
4 changes: 2 additions & 2 deletions tests/cpp/target/parsers/aprofile_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ TEST_F(AProfileParser, DefaultSVESupportSVESupport) {
TargetJSON target = ParseTargetWithAttrs("", "aarch64-arm-none-eabi", {arch_attr});
TargetFeatures features = Downcast<TargetFeatures>(target.at("features"));
EXPECT_TRUE(IsArch(target));
#if TVM_LLVM_VERSION >= 190
#if TVM_LLVM_VERSION >= 190 || (TVM_LLVM_VERSION / 10) == 13
// The generic aarch64 should not have SVE enabled
EXPECT_FALSE(Downcast<Bool>(features.at("has_sve")));
#else
Expand Down Expand Up @@ -364,7 +364,7 @@ TEST_F(AProfileParser, DefaultFP16Support) {
TargetJSON target = ParseTargetWithAttrs("", "aarch64-arm-none-eabi", {arch_attr});
TargetFeatures features = Downcast<TargetFeatures>(target.at("features"));
EXPECT_TRUE(IsArch(target));
#if TVM_LLVM_VERSION >= 190
#if TVM_LLVM_VERSION >= 190 || (TVM_LLVM_VERSION / 10) == 13
// The generic aarch64 should not have FP16 enabled
EXPECT_FALSE(Downcast<Bool>(features.at("has_fp16_simd")));
#else
Expand Down
Loading