Skip to content
Open
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
38 changes: 38 additions & 0 deletions cmake/utils/FindLLVM.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -237,4 +237,42 @@ macro(find_llvm use_llvm)
message(FATAL_ERROR "TVM requires LLVM 15.0 or higher.")
endif()
message(STATUS "Found TVM_LLVM_HAS_AARCH64_TARGET=" ${TVM_LLVM_HAS_AARCH64_TARGET})

# Detect whether DIBuilder insertion APIs (insertDeclare,
# insertDbgValueIntrinsic) accept BasicBlock::iterator as the insertion point
# (upstream LLVM 20+) vs Instruction* (pre-LLVM 20 and ROCm-bundled LLVM 20,
# which reports version 200 but retains the legacy Instruction* overload).
if (${TVM_LLVM_VERSION} GREATER_EQUAL 200)
include(CheckCXXSourceCompiles)
include(CMakePushCheckState)
cmake_push_check_state(RESET)
set(CMAKE_REQUIRED_INCLUDES ${LLVM_INCLUDE_DIRS})
# Only force -std= when the outer project hasn't already selected a
# standard; signature-only probe does not need -fno-rtti. Use the
# compiler-appropriate form so the probe works under MSVC as well.
if(NOT CMAKE_CXX_STANDARD)
if(MSVC)
set(CMAKE_REQUIRED_FLAGS "/std:c++17")
else()
set(CMAKE_REQUIRED_FLAGS "-std=c++17")
endif()
endif()
check_cxx_source_compiles("
#include <llvm/IR/DIBuilder.h>
#include <llvm/IR/Instructions.h>
void f(llvm::DIBuilder* b, llvm::Value* v, llvm::DILocalVariable* var,
llvm::DIExpression* e, const llvm::DILocation* dl,
llvm::Instruction* i) {
b->insertDeclare(v, var, e, dl, llvm::BasicBlock::iterator(i));
b->insertDbgValueIntrinsic(v, var, e, dl, llvm::BasicBlock::iterator(i));
}
" TVM_LLVM_DIBUILDER_USES_ITERATOR)
cmake_pop_check_state()
if(TVM_LLVM_DIBUILDER_USES_ITERATOR)
add_definitions(-DTVM_LLVM_DIBUILDER_USES_ITERATOR=1)
message(STATUS "LLVM DIBuilder insertion APIs use BasicBlock::iterator")
else()
message(STATUS "LLVM DIBuilder insertion APIs use Instruction* (ROCm or older LLVM 20)")
endif()
endif()
endmacro(find_llvm)
11 changes: 6 additions & 5 deletions src/target/llvm/codegen_llvm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2147,7 +2147,7 @@ void CodeGenLLVM::AddDebugInformation(llvm::Function* f_llvm,

auto* store = builder.CreateStore(iter_param, paramAlloca);
auto* di_loc = llvm::DILocation::get(*ctx, 0, 0, di_subprogram_);
#if TVM_LLVM_VERSION >= 200
#if TVM_LLVM_DIBUILDER_USES_ITERATOR
dbg_info_->di_builder_->insertDeclare(
paramAlloca, param, dbg_info_->di_builder_->createExpression(), llvm::DebugLoc(di_loc),
llvm::BasicBlock::iterator(store));
Expand Down Expand Up @@ -2193,9 +2193,10 @@ void CodeGenLLVM::AddDebugInformation(llvm::Value* llvm_value, const Var& tir_va
// the SSA value directly rather than a memory location.
if (!llvm_value->getType()->isPointerTy()) {
if (insert_before) {
// LLVM 20+ changed insertDbgValueIntrinsic to take BasicBlock::iterator
// instead of Instruction* for the insertion point.
#if TVM_LLVM_VERSION >= 200
// Upstream LLVM 20+ changed insertDbgValueIntrinsic to take
// BasicBlock::iterator; ROCm-bundled LLVM 20 retains Instruction*.
// TVM_LLVM_DIBUILDER_USES_ITERATOR is set by CMake feature detection.
#if TVM_LLVM_DIBUILDER_USES_ITERATOR
dbg_info_->di_builder_->insertDbgValueIntrinsic(
llvm_value, local_var, dbg_info_->di_builder_->createExpression(), llvm::DebugLoc(di_loc),
llvm::BasicBlock::iterator(insert_before));
Expand All @@ -2213,7 +2214,7 @@ void CodeGenLLVM::AddDebugInformation(llvm::Value* llvm_value, const Var& tir_va
}

if (insert_before) {
#if TVM_LLVM_VERSION >= 200
#if TVM_LLVM_DIBUILDER_USES_ITERATOR
dbg_info_->di_builder_->insertDeclare(
llvm_value, local_var, dbg_info_->di_builder_->createExpression(), llvm::DebugLoc(di_loc),
llvm::BasicBlock::iterator(insert_before));
Expand Down
Loading