Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix -mfloat-abi=soft compilation for ARM with OpenCL target #6150

Merged
merged 1 commit into from
Aug 5, 2020
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
7 changes: 6 additions & 1 deletion src/target/llvm/codegen_blob.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,17 @@ namespace codegen {
std::pair<std::unique_ptr<llvm::Module>, std::shared_ptr<llvm::LLVMContext>> 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<llvm::LLVMContext>();
std::string module_name = "devc";
std::unique_ptr<llvm::Module> 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(
Expand Down
5 changes: 5 additions & 0 deletions src/target/llvm/llvm_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down