-
Notifications
You must be signed in to change notification settings - Fork 110
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
[CIR][CIRGen] Use Clang Codegen's skeleton in CIRGenFunction::buildBuiltinExpr #967
Conversation
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.
This is a great idea!
/// in OG code `CodeGenFunction::EmitBuiltinExpr`. | ||
/// NOTE: Every time we implement handling of a case in | ||
/// the function `CIRGenFunction::buildBuiltinExpr`, it should be remove here. | ||
static std::string getUnhandledBuiltinName(unsigned builtinID) { |
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.
This should return StringRef.
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.
I'll use StringRef if we do return name.
switch (builtinID) { | ||
default: | ||
return std::string(); | ||
case Builtin::BI__builtin_acos: |
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.
These builtins are defined in tablegen, and I usually search in my build directory to find the corresponding .inc
file (tools/clang/include/clang/Basic/Builtins.inc
in this case). Those files define all the builtins using macros, and you can provide an appropriate macro definition before including the file to autogenerate this switch instead of needing to manually write out every intrinsic.
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 great advice. This situation is a bit different though because these builtin names are a selection of tools/clang/include/clang/Basic/Builtins.inc. They are actually a manual selection of builtins that has implementation in OG but not yet in CIRGen, And the idea was just to capture names and NYI early of those builtins (and them only) as those implemented in CIRGen should never hit the NYI I created here, and those not implemented in OG should go through and never hit NYI I created.
i.e. I used command like
"sed -n '2573,6333p' /data/users/guojinhe/clangir-llvm-ghehg/clang/lib/CodeGen/CGBuiltin.cpp | grep -o 'Builtin::BI__[^:]*' | sed 's/^/case /;s/$/:/' " to get them from oG.
and exclude what's from sed -n '305,1416p' /data/users/guojinhe/clangir-llvm-ghehg/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp | grep "case Builtin:"
to pick them.
Yeah, let me know if we have better way to generate them
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.
With the current implementation, I think it'd be okay to have this function handle all built-ins and not just unimplemented ones. Bruno's suggestion changes that, of course.
std::string unhandledName = getUnhandledBuiltinName(BuiltinID); | ||
if (!unhandledName.empty()) { | ||
llvm::errs() << unhandledName << " "; | ||
llvm_unreachable("NYI"); |
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.
I think it'll be easier to parse the error if the unreachable message itself includes the builtin name.
return std::string(); | ||
case Builtin::BI__builtin_acos: | ||
return "Builtin::BI__builtin_acos"; | ||
case Builtin::BI__builtin_acosf: |
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.
When you did similar for Aarch64 my feedback was to make those inline (without a function that returns the name), and you did implement like that. The idea is to get an accurate account of source line of failure, I'm confused on why you took a different approach here.
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.
Example:
llvm_unreachable("NYI"); |
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.
I see, sounds like better approach!
Let me see if I understand the tradeoff, because if we do have them inline instead of returning the name, not only we can have source line of failures (and name can be known by looking up source code), we would have a skeleton that we can fill when we have implementation ready. Plus, we don't need to keep and maintain this "return name" function as they may not be needed eventually. The only con with this alternative is every time we change the code, failing line number would change, but I think it might be Ok.
I'll change this PR to use this approach.
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.
exactly, good point on the maintain bits too
This PR currently has no content, should probably be a draft to prevent generating noise if it's not ready for review |
Skeleton of OG introduced with informative NYIs. |
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.
This is awesome, many thanks!
…iltinExpr (llvm#967) This PR helps us to triage unimplemented builtins (that are target independent). There are unhandled builtins in CIR Codegen `[CIRGenFunction::buildBuiltinExpr](https://github.com/llvm/clangir/blob/4c446b3287895879da598e23164d338d04bced3e/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp#L305)`. And those builtins have implementation in [OG](https://github.com/llvm/clangir/blob/4c446b3287895879da598e23164d338d04bced3e/clang/lib/CodeGen/CGBuiltin.cpp#L2573). Currently, those builtins just are treated as LibraryCall or some other ways which eventually get failure, and failure messages are confusing. This PR address this problem by refactoring `CIRGenFunction::buildBuiltinExpr` to keep the same skeleton as OG counterpart `CodeGenFunction::EmitBuiltinExpr`, and add builtin name to NYI message
…iltinExpr (#967) This PR helps us to triage unimplemented builtins (that are target independent). There are unhandled builtins in CIR Codegen `[CIRGenFunction::buildBuiltinExpr](https://github.com/llvm/clangir/blob/4c446b3287895879da598e23164d338d04bced3e/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp#L305)`. And those builtins have implementation in [OG](https://github.com/llvm/clangir/blob/4c446b3287895879da598e23164d338d04bced3e/clang/lib/CodeGen/CGBuiltin.cpp#L2573). Currently, those builtins just are treated as LibraryCall or some other ways which eventually get failure, and failure messages are confusing. This PR address this problem by refactoring `CIRGenFunction::buildBuiltinExpr` to keep the same skeleton as OG counterpart `CodeGenFunction::EmitBuiltinExpr`, and add builtin name to NYI message
This PR helps us to triage unimplemented builtins (that are target independent).
There are unhandled builtins in CIR Codegen
[CIRGenFunction::buildBuiltinExpr](https://github.com/llvm/clangir/blob/4c446b3287895879da598e23164d338d04bced3e/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp#L305)
.And those builtins have implementation in OG.
Currently, those builtins just are treated as LibraryCall or some other ways which eventually get failure, and failure messages are confusing.
This PR address this problem by refactoring
CIRGenFunction::buildBuiltinExpr
to keep the same skeleton as OGcounterpart
CodeGenFunction::EmitBuiltinExpr
, and add builtin name to NYI message