-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[bugfix] fix the undeclared identifier 'f' #14879
Conversation
Thanks for contributing to TVM! Please refer to the contributing guidelines https://tvm.apache.org/docs/contribute/ for useful information and tips. Please request code reviews from Reviewers by @-ing them in a comment.
Generated by tvm-bot |
@tvm-bot rerun |
src/target/llvm/codegen_cpu.cc
Outdated
@@ -466,13 +466,14 @@ llvm::Value* CodeGenCPU::CreateCallExtern(Type ret_type, String global_symbol, | |||
llvm::FunctionType* ftype = llvm::FunctionType::get(GetLLVMType(ret_type), arg_types, false); | |||
// Check if it is available in global function table as injected function. | |||
|
|||
llvm::Function* f = module_->getFunction(MakeStringRef(global_symbol)); | |||
auto callee = [&]() -> llvm::Value* { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
callee
is only used when #if TVM_LLVM_VERSION >= 90
is true. So, could we just move the whole callee
initialization lambda into that branch of the conditional directive?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The callee
was intended to be used in both cases, with the #if
normalizing callee
into either a llvm::Value*
or a llvm::FunctionCallee
depending on the LLVM version. I think we should keep the definition of callee
outside the conditional, but should replace auto ext_callee = f;
with auto ext_callee = callee;
. That way, callee
is initialized as appropriate module/context/external function pointer in both branches, and is then converted to the type required by the LLVM API inside the directive.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes more sense, thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the catch! I think we could have a smaller fix within the ifdef, which would also avoid needing to expose the definition of f
to the larger scope.
src/target/llvm/codegen_cpu.cc
Outdated
@@ -466,13 +466,14 @@ llvm::Value* CodeGenCPU::CreateCallExtern(Type ret_type, String global_symbol, | |||
llvm::FunctionType* ftype = llvm::FunctionType::get(GetLLVMType(ret_type), arg_types, false); | |||
// Check if it is available in global function table as injected function. | |||
|
|||
llvm::Function* f = module_->getFunction(MakeStringRef(global_symbol)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of exposing llvm::Function* f
outside the scope, could we instead replace auto ext_callee = f;
on line 490 with auto ext_callee = callee;
? The current change would allow compilation, but would skip the optional pointer-cast of the callee.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or, alternatively, I think we could simplify it by returning builder_->CreateCall(ftype, callee, arg_values);
. This method is available as far back as 3.7.0 (commit link), and since TVM requires LLVM 4.0 or higher, we would avoid needing the #if
directive altogether.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Lunderberg @quic-sanirudh Thanks for your guidance. I have corrected the patch, could you recheck the code change again?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for fixing the legacy issue!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the changes, and looks good to me!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, Thanks. Guess we can merge this now as Eric has already approved it.
* fix the undeclared identifier 'f' * Update codegen_cpu.cc
This pr fixed the source code build problem found in issue #14878
The variable 'f' is a local variable that is inviable for the outside code. This pr moved the 'f' definition to the outside of the condition and fix the crash.
cc @Lunderberg @kparzysz-quic