Commit d7282a3
authored
[BugFix][LLVM] Fix
## Problem
Closes #18709.
ROCm ships its own LLVM 20 build that still uses the pre-LLVM-20
`Instruction*` overload of `DIBuilder::insertDeclare`, while upstream
LLVM 20 switched to `BasicBlock::iterator`. The previous guard `#if
TVM_LLVM_VERSION >= 200` in `codegen_llvm.cc` broke ROCm users because
their LLVM reports version 20 but lacks the new overload, causing a
compile error like:
```
error: no matching function for call to
'llvm::DIBuilder::insertDeclare(..., llvm::BasicBlock::iterator)'
note: candidate: insertDeclare(..., llvm::Instruction*)
```
## Fix
Replace the version-number guard with a CMake
`check_cxx_source_compiles` feature probe in
`cmake/utils/FindLLVM.cmake`. The probe compiles a small test program
that calls `insertDeclare` with `BasicBlock::iterator`. The result is
exposed as the preprocessor macro
`TVM_LLVM_INSERTDECLARE_USES_ITERATOR`.
`cmake_push_check_state`/`cmake_pop_check_state` is used to avoid
leaking `CMAKE_REQUIRED_*` variables into the rest of the build.
Three call sites in `src/target/llvm/codegen_llvm.cc` are updated to use
`#if TVM_LLVM_INSERTDECLARE_USES_ITERATOR` instead of `#if
TVM_LLVM_VERSION >= 200`.
**Behavior by configuration:**
| LLVM build | Probe result | Macro set | Code path |
|---|---|---|---|
| Upstream LLVM >= 20 with new overload | Compiles | Yes |
`BasicBlock::iterator` |
| ROCm LLVM 20 (old overload) | Fails | No | `Instruction*` |
| Any LLVM < 20 | Probe skipped | No | `Instruction*` |
## Testing
Tested locally with LLVM 20.1.8 (Ubuntu package):
```
tests/python/codegen/test_target_codegen_llvm.py 39 passed
```insertDeclare API mismatch for ROCm-bundled LLVM 20 (#19390)1 parent 21993a5 commit d7282a3
2 files changed
+44
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
237 | 237 | | |
238 | 238 | | |
239 | 239 | | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
240 | 278 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2147 | 2147 | | |
2148 | 2148 | | |
2149 | 2149 | | |
2150 | | - | |
| 2150 | + | |
2151 | 2151 | | |
2152 | 2152 | | |
2153 | 2153 | | |
| |||
2193 | 2193 | | |
2194 | 2194 | | |
2195 | 2195 | | |
2196 | | - | |
2197 | | - | |
2198 | | - | |
| 2196 | + | |
| 2197 | + | |
| 2198 | + | |
| 2199 | + | |
2199 | 2200 | | |
2200 | 2201 | | |
2201 | 2202 | | |
| |||
2213 | 2214 | | |
2214 | 2215 | | |
2215 | 2216 | | |
2216 | | - | |
| 2217 | + | |
2217 | 2218 | | |
2218 | 2219 | | |
2219 | 2220 | | |
| |||
0 commit comments