You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by cb...@apache.org on 2024/09/10 07:52:42 UTC

(tvm) branch main updated: [LLVM][RUNTIME] Fix RISC-V CodeModel propagation to ORCJIT runtime executor (#17347)

This is an automated email from the ASF dual-hosted git repository.

cbalint13 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tvm.git


The following commit(s) were added to refs/heads/main by this push:
     new d7e0af2d88 [LLVM][RUNTIME] Fix RISC-V CodeModel propagation to ORCJIT runtime executor (#17347)
d7e0af2d88 is described below

commit d7e0af2d88f75e2ab21c6dbde43813a033c0fb35
Author: Balint Cristian <cr...@gmail.com>
AuthorDate: Tue Sep 10 10:52:35 2024 +0300

    [LLVM][RUNTIME] Fix RISC-V CodeModel propagation to ORCJIT runtime executor (#17347)
---
 src/target/llvm/llvm_instance.h | 10 ++++++++++
 src/target/llvm/llvm_module.cc  |  8 ++++++++
 2 files changed, 18 insertions(+)

diff --git a/src/target/llvm/llvm_instance.h b/src/target/llvm/llvm_instance.h
index fd63140a0b..add2af6002 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 baa68feedf..34bbb6a0c6 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<llvm::TargetMachine> tm = llvm::cantFail(tm_builder.createTargetMachine());
   if (!IsCompatibleWithHost(tm.get())) {