[LLVM] Fix build failures when building with llvm>=22#18818
[LLVM] Fix build failures when building with llvm>=22#18818mshr-h merged 1 commit intoapache:mainfrom
Conversation
Summary of ChangesHello @mshr-h, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request resolves critical build failures encountered when compiling TVM with LLVM version 22 or newer. The changes primarily involve updating the TVM codebase to align with recent API modifications in LLVM's target and command-line option handling, ensuring continued compatibility and successful compilation across different LLVM versions. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request successfully addresses build failures with LLVM versions 22 and above by adapting to API changes in llvm::cl::getRegisteredOptions() and llvm::TargetRegistry::lookupTarget. The changes introduce conditional compilation blocks to ensure compatibility across different LLVM versions. Additionally, the handling of command-line options has been made more robust with safer lookup mechanisms and explicit null checks.
src/target/llvm/llvm_instance.cc
Outdated
| parse_error = true; | ||
| continue; | ||
| } | ||
| auto& options = llvm::cl::getRegisteredOptions(); |
There was a problem hiding this comment.
The llvm::cl::getRegisteredOptions() function returns a reference to a static StringMap. Calling it repeatedly inside the loop, as done here, is inefficient. It would be better to call it once before the loop and store the reference, then reuse that reference within the loop. This applies to the similar change in ApplyLLVMOptions as well.
auto& options = llvm::cl::getRegisteredOptions();
bool parse_error = false;
for (const ffi::String& s : v.value()) {
Option opt = ParseOptionString(s);
if (opt.type == Option::OptType::Invalid) {
parse_error = true;
continue;
}
#if TVM_LLVM_VERSION >= 220
if (options.find(opt.name) != options.end()) {
#else
if (options.count(opt.name)) {
src/target/llvm/llvm_instance.cc
Outdated
|
|
||
| llvm::cl::Option* base_op = options[new_opt.name]; | ||
| llvm::cl::Option* base_op = nullptr; | ||
| auto& options = llvm::cl::getRegisteredOptions(); |
There was a problem hiding this comment.
Similar to the comment in LLVMTargetInfo constructor, llvm::cl::getRegisteredOptions() returns a reference to a static StringMap. Calling it repeatedly inside this loop is inefficient. It should be called once before the loop and the reference reused.
const auto& new_options = GetCommandLineOptions();
auto& options = llvm::cl::getRegisteredOptions();
for (size_t i = 0, e = saved_llvm_options_.size(); i != e; ++i) {
const Option& new_opt = new_options[i];
const Option& saved_opt = saved_llvm_options_[i];
llvm::cl::Option* base_op = nullptr;
#if TVM_LLVM_VERSION >= 220
auto it = options.find(new_opt.name);
if (it != options.end()) {
base_op = it->second;
}
#else
if (options.count(new_opt.name)) {
base_op = options[new_opt.name];
}
#endifc78d5a2 to
24bbefe
Compare
cbalint13
left a comment
There was a problem hiding this comment.
LGTM.
Thank you for the fix !
|
@tvm-bot rerun |
|
Failed to re-run CI in https://github.com/apache/tvm/actions/runs/22421146231 Detailswith response |
|
@tvm-bot rerun |
|
Failed to re-run CI in https://github.com/apache/tvm/actions/runs/22424690235 Detailswith response |
24bbefe to
2e6ba06
Compare
This PR fixes Windows/macOS GitHub Actions build failures when building TVM with LLVM 22 (
TVM_LLVM_VERSION=221), caused by LLVM API changes in target/command-line option handling.Link to the recent build failure log: https://github.com/apache/tvm/actions/runs/22387355836/job/64820136927?pr=18817