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

[CIR][Lowering][CXXABI]lower var_arg op #570

Closed
wants to merge 0 commits into from
Closed

Conversation

ghehg
Copy link
Collaborator

@ghehg ghehg commented Apr 27, 2024

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

Screenshot 2024-04-27 at 2 30 52 PM

Copy link
Member

@Lancern Lancern left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some minor nits

Comment on lines 32 to 44
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);
}
Copy link
Member

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.

Copy link
Collaborator Author

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

Comment on lines 1 to 2
//====- LoweringPrepareItaniumCXXABI.cpp - Itanium ABI specific code
//--------===//
Copy link
Member

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.

Suggested change
//====- LoweringPrepareItaniumCXXABI.cpp - Itanium ABI specific code
//--------===//
//====- LoweringPrepareItaniumCXXABI.cpp - Itanium ABI specific code ------===//

Comment on lines 116 to 117
// TODO: implement va_arg for more generic Itanium ABI.
return mlir::Value();
Copy link
Member

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?

Suggested change
// TODO: implement va_arg for more generic Itanium ABI.
return mlir::Value();
llvm_unreachable("NYI");

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This header is unnecessary.

Copy link
Collaborator Author

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) {
Copy link
Member

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.

Copy link
Collaborator Author

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)

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.

2 participants