From 5e28fb0cdc45b26cf01e674bac26cdb9ac98b926 Mon Sep 17 00:00:00 2001 From: Trevor Morris Date: Wed, 5 Aug 2020 10:04:08 -0700 Subject: [PATCH] Pass mfloat-abi to LLVMModule::Init (#6150) Fix lint --- src/target/llvm/codegen_blob.cc | 7 ++++++- src/target/llvm/llvm_module.cc | 5 +++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/target/llvm/codegen_blob.cc b/src/target/llvm/codegen_blob.cc index af2562ed7868..6df481730548 100644 --- a/src/target/llvm/codegen_blob.cc +++ b/src/target/llvm/codegen_blob.cc @@ -33,12 +33,17 @@ namespace codegen { std::pair, std::shared_ptr> CodeGenBlob( const std::string& data, bool system_lib, const std::string& target_triple) { InitializeLLVM(); - auto tm = GetLLVMTargetMachine(std::string("-mtriple ") + target_triple); + std::string full_target_triple = std::string("-mtriple ") + target_triple; + auto tm = GetLLVMTargetMachine(full_target_triple); auto triple = tm->getTargetTriple(); auto ctx = std::make_shared(); std::string module_name = "devc"; std::unique_ptr module(new llvm::Module(module_name, *ctx)); module->setTargetTriple(triple.str()); + // Store full target string in metadata, because flags such as -mfloat-abi must be preserved for + // ModulePackImportsToLLVM. + module->addModuleFlag(llvm::Module::ModFlagBehavior::Override, "tvm_target", + llvm::MDString::get(*ctx, full_target_triple)); module->setDataLayout(tm->createDataLayout()); auto* blob_value = llvm::ConstantDataArray::getString(*ctx, data, false); auto* tvm_dev_mblob = new llvm::GlobalVariable( diff --git a/src/target/llvm/llvm_module.cc b/src/target/llvm/llvm_module.cc index a3e2123568af..9e585d7b4492 100644 --- a/src/target/llvm/llvm_module.cc +++ b/src/target/llvm/llvm_module.cc @@ -61,6 +61,11 @@ class LLVMModuleNode final : public runtime::ModuleNode { return PackedFunc([flag](TVMArgs args, TVMRetValue* rv) { *rv = flag; }); } else if (name == "_get_target_triple") { std::string target_triple = tm_->getTargetTriple().str(); + // getTargetTriple() doesn't include other flags besides the triple. Add back flags which are + // important for ModulePackImportsToLLVM. + if (tm_->Options.FloatABIType == llvm::FloatABI::ABIType::Soft) { + target_triple += " -mfloat-abi=soft"; + } return PackedFunc([target_triple](TVMArgs args, TVMRetValue* rv) { *rv = target_triple; }); } if (ee_ == nullptr) LazyInitJIT();