-
Notifications
You must be signed in to change notification settings - Fork 104
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][Lowering][CXXABI]lower var_arg op #570
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.
Some minor nits
static mlir::Value createGetMemberOp(CIRBaseBuilderTy &builder, | ||
mlir::Location &loc, mlir::Value structPtr, | ||
const char *fldName, unsigned idx) { | ||
|
||
assert(structPtr.getType().isa<mlir::cir::PointerType>()); | ||
auto structBaseTy = | ||
structPtr.getType().cast<mlir::cir::PointerType>().getPointee(); | ||
assert(structBaseTy.isa<mlir::cir::StructType>()); | ||
auto fldTy = structBaseTy.cast<mlir::cir::StructType>().getMembers()[idx]; | ||
auto fldPtrTy = ::mlir::cir::PointerType::get(builder.getContext(), fldTy); | ||
return builder.create<mlir::cir::GetMemberOp>(loc, fldPtrTy, structPtr, | ||
fldName, idx); | ||
} |
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.
Is this function general or is it specific to ARM64 ABI? If it is general you can move it to CIRBaseBuilderTy
.
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 general, will move to CIRBaseBuilderTy
//====- LoweringPrepareItaniumCXXABI.cpp - Itanium ABI specific code | ||
//--------===// |
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.
Please keep these 2 lines of file header in the same line.
//====- LoweringPrepareItaniumCXXABI.cpp - Itanium ABI specific code | |
//--------===// | |
//====- LoweringPrepareItaniumCXXABI.cpp - Itanium ABI specific code ------===// |
// TODO: implement va_arg for more generic Itanium ABI. | ||
return mlir::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.
Maybe an assertion here would be better?
// TODO: implement va_arg for more generic Itanium ABI. | |
return mlir::Value(); | |
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.
This header is unnecessary.
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.
its needed by clang/lib/CIR/Dialect/Transforms/LoweringPrepareArm64CXXABI.cpp as LoweringPrepareArm64CXXABI inherits from LoweringPrepareItaniumCXXABI
builder.setInsertionPoint(op); | ||
|
||
auto res = cxxABI->lowerVAArg(builder, op); | ||
if (res) { |
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 understand lowerVAArg
could never return an empty value so the branching here is unnecessary.
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.
lowerVAArg returns null from LoweringPrepareItaniumCXXABI. This is the current way of prevent lowering of cir.var_arg if Lowering is not ready for an ABI (e.g. x86_64)
lowering var_arg op for ARM64 architecture. This is CIR lowering.
This PR modified LoweringPrepare CXXABI code to make LoweringPrepareArm64CXXABI class inherit more generic LoweringPrepareItaniumCXXABI, this way lowering var_arg would be only meaningful for arm64 targets and for other arch its no op for now.
The ABI doc and detailed algorithm description can be found in this official doc.
https://github.com/ARM-software/abi-aa/blob/617079d8a0d45bec83d351974849483cf0cc66d5/aapcs64/aapcs64.rst#appendix-variable-argument-lists
The following pic is a easier-to-understand and close to lowered code explaination