Skip to content

[CIR][ABI] Implement basic struct CC lowering for x86_64 #784

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

Merged

Conversation

sitio-couto
Copy link
Collaborator

This patch adds the necessary bits for unraveling struct arguments and
return values for the x86_64 calling convention.

@sitio-couto sitio-couto self-assigned this Aug 11, 2024
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.

I'm going to approve and land, please address all comments in follow up PRs.

@@ -458,6 +458,10 @@ LogicalResult CastOp::verify() {
return success();
}
case cir::CastKind::bitcast: {
// Allow bitcast of structs for calling conventions.
if (isa<StructType>(srcType) || isa<StructType>(resType))
Copy link
Member

Choose a reason for hiding this comment

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

Feels hacky, I don't see documentation supporting this or a good explanation of the semantics. Sounds like we need a new style of cast operation instead.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Feels hacky, I don't see documentation supporting this or a good explanation of the semantics.

I don't think I follow. I'ts a bitcast. We reinterpret struct bits as integers for the calling convention.

Sounds like we need a new style of cast operation instead.

Do you have something in mind?

@@ -42,7 +43,7 @@ class CIRLowerContext : public llvm::RefCountedBase<CIRLowerContext> {

/// The language options used to create the AST associated with
/// this ASTContext object.
clang::LangOptions &LangOpts;
clang::LangOptions LangOpts;
Copy link
Member

Choose a reason for hiding this comment

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

Why do we now need to make a new copy of this? I'd expect langoptions to survive til the end.

Copy link
Collaborator Author

@sitio-couto sitio-couto Aug 14, 2024

Choose a reason for hiding this comment

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

Someone has to retain ownership of LangOpts to prevent dangling refs. CIRLowerContext is the owner in this case. I can try using move semantics here instead.


// FIXME(cir): Create a custom rewriter class to abstract this away.
Value createBitcast(Value Src, Type Ty, LowerFunction &LF) {
return LF.getRewriter().create<CastOp>(Src.getLoc(), Ty, CastKind::bitcast,
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 where the bitcast between struct comes from?

Copy link
Collaborator Author

@sitio-couto sitio-couto Aug 14, 2024

Choose a reason for hiding this comment

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

In the literal sense, yes, this line creates it. Semantically, we need the bitcast to circumvent MLIR's type-checking and properly abide by the calling convention by re-interpreting structs as integers.

@bcardosolopes bcardosolopes merged commit 828b089 into llvm:main Aug 12, 2024
6 checks passed
sitio-couto added a commit to sitio-couto/clangir that referenced this pull request Aug 15, 2024
This patch fixes a bunch of pending review comments:

 - Remove data layout attribute from address space testing
 - Remove incoherent comment
 - Rename abi_or_pref to abiOrPref
 - Make comments impersonal
 - Implement feature guard for ARM's CMSE secure call feature
 - Track volatile return times feature in CC lowering
 - Track missing features in Itanium record builder
 - Remove incoherent fixme
 - Clarify comment regarding CIR record layout getter
 - Track missing cache for record layout getter
 - Remove unecessary todo's
@sitio-couto sitio-couto deleted the vinicius/add-x86-basic-struct-cc-lowering branch August 15, 2024 11:15
bcardosolopes pushed a commit that referenced this pull request Aug 15, 2024
This patch fixes a bunch of pending review comments in #784:

 - Remove data layout attribute from address space testing
 - Remove incoherent comment
 - Rename abi_or_pref to abiOrPref
 - Make comments impersonal
 - Implement feature guard for ARM's CMSE secure call feature
 - Track volatile return times feature in CC lowering
 - Track missing features in the Itanium record builder
 - Remove incoherent fix me
 - Clarify comment regarding CIR record layout getter
 - Track missing cache for record layout getter
 - Remove unnecessary todo's
Hugobros3 pushed a commit to shady-gang/clangir that referenced this pull request Oct 2, 2024
This patch adds the necessary bits for unraveling struct arguments and
return values for the x86_64 calling convention.
Hugobros3 pushed a commit to shady-gang/clangir that referenced this pull request Oct 2, 2024
This patch fixes a bunch of pending review comments in llvm#784:

 - Remove data layout attribute from address space testing
 - Remove incoherent comment
 - Rename abi_or_pref to abiOrPref
 - Make comments impersonal
 - Implement feature guard for ARM's CMSE secure call feature
 - Track volatile return times feature in CC lowering
 - Track missing features in the Itanium record builder
 - Remove incoherent fix me
 - Clarify comment regarding CIR record layout getter
 - Track missing cache for record layout getter
 - Remove unnecessary todo's
smeenai pushed a commit to smeenai/clangir that referenced this pull request Oct 9, 2024
This patch adds the necessary bits for unraveling struct arguments and
return values for the x86_64 calling convention.
smeenai pushed a commit to smeenai/clangir that referenced this pull request Oct 9, 2024
This patch fixes a bunch of pending review comments in llvm#784:

 - Remove data layout attribute from address space testing
 - Remove incoherent comment
 - Rename abi_or_pref to abiOrPref
 - Make comments impersonal
 - Implement feature guard for ARM's CMSE secure call feature
 - Track volatile return times feature in CC lowering
 - Track missing features in the Itanium record builder
 - Remove incoherent fix me
 - Clarify comment regarding CIR record layout getter
 - Track missing cache for record layout getter
 - Remove unnecessary todo's
smeenai pushed a commit to smeenai/clangir that referenced this pull request Oct 9, 2024
This patch adds the necessary bits for unraveling struct arguments and
return values for the x86_64 calling convention.
smeenai pushed a commit to smeenai/clangir that referenced this pull request Oct 9, 2024
This patch fixes a bunch of pending review comments in llvm#784:

 - Remove data layout attribute from address space testing
 - Remove incoherent comment
 - Rename abi_or_pref to abiOrPref
 - Make comments impersonal
 - Implement feature guard for ARM's CMSE secure call feature
 - Track volatile return times feature in CC lowering
 - Track missing features in the Itanium record builder
 - Remove incoherent fix me
 - Clarify comment regarding CIR record layout getter
 - Track missing cache for record layout getter
 - Remove unnecessary todo's
keryell pushed a commit to keryell/clangir that referenced this pull request Oct 19, 2024
This patch adds the necessary bits for unraveling struct arguments and
return values for the x86_64 calling convention.
keryell pushed a commit to keryell/clangir that referenced this pull request Oct 19, 2024
This patch fixes a bunch of pending review comments in llvm#784:

 - Remove data layout attribute from address space testing
 - Remove incoherent comment
 - Rename abi_or_pref to abiOrPref
 - Make comments impersonal
 - Implement feature guard for ARM's CMSE secure call feature
 - Track volatile return times feature in CC lowering
 - Track missing features in the Itanium record builder
 - Remove incoherent fix me
 - Clarify comment regarding CIR record layout getter
 - Track missing cache for record layout getter
 - Remove unnecessary todo's
lanza pushed a commit that referenced this pull request Nov 5, 2024
This patch adds the necessary bits for unraveling struct arguments and
return values for the x86_64 calling convention.
lanza pushed a commit that referenced this pull request Nov 5, 2024
This patch fixes a bunch of pending review comments in #784:

 - Remove data layout attribute from address space testing
 - Remove incoherent comment
 - Rename abi_or_pref to abiOrPref
 - Make comments impersonal
 - Implement feature guard for ARM's CMSE secure call feature
 - Track volatile return times feature in CC lowering
 - Track missing features in the Itanium record builder
 - Remove incoherent fix me
 - Clarify comment regarding CIR record layout getter
 - Track missing cache for record layout getter
 - Remove unnecessary todo's
lanza pushed a commit that referenced this pull request Mar 18, 2025
This patch adds the necessary bits for unraveling struct arguments and
return values for the x86_64 calling convention.
lanza pushed a commit that referenced this pull request Mar 18, 2025
This patch fixes a bunch of pending review comments in #784:

 - Remove data layout attribute from address space testing
 - Remove incoherent comment
 - Rename abi_or_pref to abiOrPref
 - Make comments impersonal
 - Implement feature guard for ARM's CMSE secure call feature
 - Track volatile return times feature in CC lowering
 - Track missing features in the Itanium record builder
 - Remove incoherent fix me
 - Clarify comment regarding CIR record layout getter
 - Track missing cache for record layout getter
 - Remove unnecessary todo's
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