Skip to content

[bugfix] fix the undeclared identifier 'f'#14879

Merged
quic-sanirudh merged 2 commits intoapache:mainfrom
jikechao:fix_undefined_f
May 19, 2023
Merged

[bugfix] fix the undeclared identifier 'f'#14879
quic-sanirudh merged 2 commits intoapache:mainfrom
jikechao:fix_undefined_f

Conversation

@jikechao
Copy link
Copy Markdown
Member

@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
Copy Markdown
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
Copy Markdown
Member Author

@tvm-bot rerun

// 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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

Comment thread src/target/llvm/codegen_cpu.cc Outdated
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member 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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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