diff --git a/src/target/llvm/llvm_instance.h b/src/target/llvm/llvm_instance.h index fd63140a0b37..add2af6002c6 100644 --- a/src/target/llvm/llvm_instance.h +++ b/src/target/llvm/llvm_instance.h @@ -215,6 +215,16 @@ class LLVMTargetInfo { * \return `llvm::TargetOptions` object for this target */ const llvm::TargetOptions& GetTargetOptions() const { return target_options_; } + /*! + * \brief Get the LLVM target reloc model + * \return `llvm::Reloc::Model` object for this target + */ + const llvm::Reloc::Model& GetTargetRelocModel() const { return reloc_model_; } + /*! + * \brief Get the LLVM target code model + * \return `llvm::CodeModel::Model` object for this target + */ + const llvm::CodeModel::Model& GetTargetCodeModel() const { return code_model_; } /*! * \brief Get fast math flags * \return `llvm::FastMathFlags` for this target diff --git a/src/target/llvm/llvm_module.cc b/src/target/llvm/llvm_module.cc index baa68feedfa2..34bbb6a0c6a9 100644 --- a/src/target/llvm/llvm_module.cc +++ b/src/target/llvm/llvm_module.cc @@ -482,6 +482,14 @@ void LLVMModuleNode::InitORCJIT() { tm_builder.setCodeGenOptLevel(llvm::CodeGenOptLevel::Aggressive); #endif + // Default is no explicit JIT code & reloc model + // Propagate instance code & reloc for RISCV case. + auto arch = tm_builder.getTargetTriple().getArch(); + if (arch == llvm::Triple::riscv32 || arch == llvm::Triple::riscv64) { + tm_builder.setRelocationModel(llvm_target->GetTargetRelocModel()); + tm_builder.setCodeModel(llvm_target->GetTargetCodeModel()); + } + // create the taget machine std::unique_ptr tm = llvm::cantFail(tm_builder.createTargetMachine()); if (!IsCompatibleWithHost(tm.get())) {