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][LowerToLLVM][CXXABI] Lower cir.va.arg #573

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

ghehg
Copy link
Contributor

@ghehg ghehg commented Apr 29, 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.

The following pic is a easier-to-understand and close to lowered code explanation

Screenshot 2024-04-29 at 4 02 17 PM

Copy link
Member

@bcardosolopes bcardosolopes left a comment

Choose a reason for hiding this comment

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

Hey, thanks for the PR, this is much needed.

You should also add LLVM checks on the relevant part of the end result, we need to make sure it's correct overall (i.e. if parts are connected right).

@ghehg ghehg force-pushed the main branch 3 times, most recently from 168ca49 to 0a6e761 Compare May 6, 2024 16:31
@bcardosolopes bcardosolopes changed the title [CIR][Lowering][CXXABI]lower var_arg op [CIR][LowerToLLVM][CXXABI] Lower cir.va.arg May 7, 2024
@@ -1,4 +1,5 @@
//====- LoweringPrepareItaniumCXXABI.h - Itanium ABI specific code --------===//
//====- 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.

ops, this should fit in 80 instead

Copy link
Member

Choose a reason for hiding this comment

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

Not resolved, please address this.

clang/test/CIR/CodeGen/var-arg-float.c Outdated Show resolved Hide resolved
@ghehg ghehg force-pushed the main branch 2 times, most recently from 3adfff7 to acede3e Compare May 10, 2024 01:29
@ghehg ghehg requested a review from bcardosolopes May 10, 2024 19:11
clang/lib/CIR/Dialect/Transforms/LoweringPrepare.cpp Outdated Show resolved Hide resolved
@@ -1,4 +1,5 @@
//====- LoweringPrepareItaniumCXXABI.h - Itanium ABI specific code --------===//
//====- 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.

Not resolved, please address this.


va_copy(args_copy, args);
// CHECK: cir.va.copy %{{[0-9]+}} to %{{[0-9]+}} : !cir.ptr<[[VALISTTYPE]]>, !cir.ptr<[[VALISTTYPE]]>

// ARM64_CHECK: cir.va.copy %{{[0-9]+}} to %{{[0-9]+}} : !cir.ptr<[[VALISTTYPE]]>, !cir.ptr<[[VALISTTYPE]]>
Copy link
Member

Choose a reason for hiding this comment

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

Previous review I gave you an outline of how you should deal with the tests, but seems none was applied?

Copy link
Member

@bcardosolopes bcardosolopes 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 applying the reviews, few more nits!

auto castRegTop = builder.createBitcast(regTop, i8PtrTy);
// On big-endian platforms, the value will be right-aligned in its stack slot.
// and we also need to think about other ABI lowering concerns listed below.
assert(!cir::MissingFeatures::handleBigEndian());
Copy link
Member

Choose a reason for hiding this comment

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

We should go a bit further here. The skeleton is really important:

// TODO(cir): implement check for jomogeneous aggregate
assert(!cir::MissingFeatures::supportisHomogeneousAggregateQueryForAArch64());
...
uint64_t NumMembers = <expected-default>...
bool IsHFA = <expected-default>...
if (IsHFA && NumMembers > 1) {
    ... // or unrecheable
}  else {
    ... // or unrecheable
}

For the path that it's not unrecheable, add more skeleton and perhaps more unrecheable for other inner/sub checks that are not implemented/tested.

// which are all ABI defined thus need ABI lowering query system.
// The implementation we have now supports most common cases which assumes
// no indirectness, no alignment greater than 8, and little endian.
assert(!cir::MissingFeatures::handleBigEndian());
Copy link
Member

Choose a reason for hiding this comment

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

I rather see the big endian check in the place where it happens in the original code (this should be applied elsewhere in this function where big endian is queried), skeleton is important! Also, CIRDataLayout does support big endian queriers, so you can query it and assert on the leg that's not implemented.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

lib/CIR/CodeGen/CIRDataLayout.h:22:class CIRDataLayout
The problem (again) is CIRDataLayout is declared and defined in CodeGen dir.
So I just added another missing feature.

Copy link
Member

Choose a reason for hiding this comment

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

Oh right, as part of LoweringPrepare we gonna have to keep adding these bits as we go. Sorry for the detour, but please create another PR that moves CIRDataLayout to include/clang/CIR/Dialect/IR/, should be straight fwd. We land that and you rebase this one on top so you can use it here.

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.

None yet

2 participants