Skip to content
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

Merged
merged 2 commits into from
May 19, 2023

Conversation

jikechao
Copy link
Contributor

@jikechao jikechao commented May 18, 2023

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

@tvm-bot
Copy link
Collaborator

tvm-bot commented May 18, 2023

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.

  • No users to tag found in teams: bugfix See #10317 for details

Generated by tvm-bot

@jikechao
Copy link
Contributor Author

@tvm-bot rerun

@@ -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* {
Copy link
Contributor

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?

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor

@Lunderberg Lunderberg left a 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.

@@ -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));
Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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?

junrushao
junrushao previously approved these changes May 18, 2023
Copy link
Member

@junrushao junrushao left a 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!

@junrushao junrushao dismissed their stale review May 18, 2023 16:58

Will have Eric to shepherd the PR

Copy link
Contributor

@Lunderberg Lunderberg left a 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!

Copy link
Contributor

@quic-sanirudh quic-sanirudh left a 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.

@quic-sanirudh quic-sanirudh merged commit 613ad5c into apache:main May 19, 2023
mei-ye pushed a commit to mei-ye/tvm that referenced this pull request Jun 1, 2023
* fix the undeclared identifier 'f'

* Update codegen_cpu.cc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants