Skip to content

Commit d7e0af2

Browse files
authored
[LLVM][RUNTIME] Fix RISC-V CodeModel propagation to ORCJIT runtime executor (#17347)
1 parent f02d295 commit d7e0af2

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/target/llvm/llvm_instance.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,16 @@ class LLVMTargetInfo {
215215
* \return `llvm::TargetOptions` object for this target
216216
*/
217217
const llvm::TargetOptions& GetTargetOptions() const { return target_options_; }
218+
/*!
219+
* \brief Get the LLVM target reloc model
220+
* \return `llvm::Reloc::Model` object for this target
221+
*/
222+
const llvm::Reloc::Model& GetTargetRelocModel() const { return reloc_model_; }
223+
/*!
224+
* \brief Get the LLVM target code model
225+
* \return `llvm::CodeModel::Model` object for this target
226+
*/
227+
const llvm::CodeModel::Model& GetTargetCodeModel() const { return code_model_; }
218228
/*!
219229
* \brief Get fast math flags
220230
* \return `llvm::FastMathFlags` for this target

src/target/llvm/llvm_module.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,14 @@ void LLVMModuleNode::InitORCJIT() {
482482
tm_builder.setCodeGenOptLevel(llvm::CodeGenOptLevel::Aggressive);
483483
#endif
484484

485+
// Default is no explicit JIT code & reloc model
486+
// Propagate instance code & reloc for RISCV case.
487+
auto arch = tm_builder.getTargetTriple().getArch();
488+
if (arch == llvm::Triple::riscv32 || arch == llvm::Triple::riscv64) {
489+
tm_builder.setRelocationModel(llvm_target->GetTargetRelocModel());
490+
tm_builder.setCodeModel(llvm_target->GetTargetCodeModel());
491+
}
492+
485493
// create the taget machine
486494
std::unique_ptr<llvm::TargetMachine> tm = llvm::cantFail(tm_builder.createTargetMachine());
487495
if (!IsCompatibleWithHost(tm.get())) {

0 commit comments

Comments
 (0)