Skip to content

[CIR][CIRGen][Lowering] Get alignment from frontend and pass it to LLVM #810

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
merged 4 commits into from
Sep 9, 2024

Conversation

ghehg
Copy link
Collaborator

@ghehg ghehg commented Aug 29, 2024

As title.
Add setAlignmentAttr for GlobalOps created from AST.
LLVM Lowering should have LLVM GlobalOp's alignment attribute inherited from CIR::GlobalOp.

This PR is definitely needed to fix issue #801 (comment), but the issue doesn't have alignment and comdat attribute for CIR Ops to begin with, so I'll keep investigating and fix CIR problem in another PR.

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 starting to fix this issue, it's going to really improve our LLVM emission quality, yay!

Comments inline

@@ -2017,7 +2019,9 @@ class CIRGlobalOpLowering
// Rewrite op.
auto llvmGlobalOp = rewriter.replaceOpWithNewOp<mlir::LLVM::GlobalOp>(
op, llvmType, isConst, linkage, symbol, init.value(),
/*alignment*/ 0, /*addrSpace*/ getGlobalOpTargetAddrSpace(op),
/*alignment*/ op.getAlignment().has_value() ? op.getAlignment().value()
Copy link
Member

Choose a reason for hiding this comment

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

Same here!

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.

Marking as needing changes

@ghehg ghehg changed the title [CIR][Lowering] LLVM lowering to pass alignment attribute [CIR][CIRGen][Lowering] Add alignment attribute from front end and let LLVM lowering pass alignment attribute Sep 6, 2024
@ghehg ghehg changed the title [CIR][CIRGen][Lowering] Add alignment attribute from front end and let LLVM lowering pass alignment attribute [CIR][CIRGen][Lowering] Get alignment from front end and let LLVM lowering pass alignment attribute Sep 6, 2024
@ghehg ghehg changed the title [CIR][CIRGen][Lowering] Get alignment from front end and let LLVM lowering pass alignment attribute [CIR][CIRGen][Lowering] Get alignment from frontend and let LLVMLowering pass alignment attribute Sep 6, 2024
@ghehg ghehg changed the title [CIR][CIRGen][Lowering] Get alignment from frontend and let LLVMLowering pass alignment attribute [CIR][CIRGen][Lowering] Get alignment attribute from frontend and pass it to LLVM Sep 6, 2024
@ghehg ghehg changed the title [CIR][CIRGen][Lowering] Get alignment attribute from frontend and pass it to LLVM [CIR][CIRGen][Lowering] Get alignment from frontend and pass it to LLVM Sep 6, 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.

This have been missing for some time now, thanks for fixing this, yay!

@@ -5,11 +5,11 @@ extern int __attribute__((section(".shared"))) ext;
int getExt() {
return ext;
}
// CIR: cir.global "private" external @ext : !s32i {section = ".shared"}
// CIR: cir.global "private" external @ext : !s32i {alignment = 4 : i64, section = ".shared"}
Copy link
Member

Choose a reason for hiding this comment

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

Note: we usually try to make the attributes be first class in the operation, this is fine for alignment because it's already the case in many tests.

// TODO(cir):
// GV->setConstant(isTypeConstant(D->getType(), false));
// GV->setAlignment(getContext().getDeclAlign(D).getAsAlign());
// setLinkageForGV(GV, D);
Copy link
Member

Choose a reason for hiding this comment

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

We have some easy missing features here for next PRs, nice! Let me create an issue to track.

@bcardosolopes bcardosolopes merged commit 761ecf9 into llvm:main Sep 9, 2024
6 checks passed
Hugobros3 pushed a commit to shady-gang/clangir that referenced this pull request Oct 2, 2024
…VM (llvm#810)

As title.
Add setAlignmentAttr for GlobalOps created from AST.
LLVM Lowering should have LLVM GlobalOp's alignment attribute inherited
from CIR::GlobalOp.

This PR is definitely needed to fix issue
llvm#801 (comment), but
the issue doesn't have alignment and comdat attribute for CIR Ops to
begin with, so I'll keep investigating and fix CIR problem in another
PR.
smeenai pushed a commit to smeenai/clangir that referenced this pull request Oct 9, 2024
…VM (llvm#810)

As title.
Add setAlignmentAttr for GlobalOps created from AST.
LLVM Lowering should have LLVM GlobalOp's alignment attribute inherited
from CIR::GlobalOp.

This PR is definitely needed to fix issue
llvm#801 (comment), but
the issue doesn't have alignment and comdat attribute for CIR Ops to
begin with, so I'll keep investigating and fix CIR problem in another
PR.
smeenai pushed a commit to smeenai/clangir that referenced this pull request Oct 9, 2024
…VM (llvm#810)

As title.
Add setAlignmentAttr for GlobalOps created from AST.
LLVM Lowering should have LLVM GlobalOp's alignment attribute inherited
from CIR::GlobalOp.

This PR is definitely needed to fix issue
llvm#801 (comment), but
the issue doesn't have alignment and comdat attribute for CIR Ops to
begin with, so I'll keep investigating and fix CIR problem in another
PR.
keryell pushed a commit to keryell/clangir that referenced this pull request Oct 19, 2024
…VM (llvm#810)

As title.
Add setAlignmentAttr for GlobalOps created from AST.
LLVM Lowering should have LLVM GlobalOp's alignment attribute inherited
from CIR::GlobalOp.

This PR is definitely needed to fix issue
llvm#801 (comment), but
the issue doesn't have alignment and comdat attribute for CIR Ops to
begin with, so I'll keep investigating and fix CIR problem in another
PR.
lanza pushed a commit that referenced this pull request Nov 5, 2024
…VM (#810)

As title.
Add setAlignmentAttr for GlobalOps created from AST.
LLVM Lowering should have LLVM GlobalOp's alignment attribute inherited
from CIR::GlobalOp.

This PR is definitely needed to fix issue
#801 (comment), but
the issue doesn't have alignment and comdat attribute for CIR Ops to
begin with, so I'll keep investigating and fix CIR problem in another
PR.
lanza pushed a commit that referenced this pull request Mar 18, 2025
…VM (#810)

As title.
Add setAlignmentAttr for GlobalOps created from AST.
LLVM Lowering should have LLVM GlobalOp's alignment attribute inherited
from CIR::GlobalOp.

This PR is definitely needed to fix issue
#801 (comment), but
the issue doesn't have alignment and comdat attribute for CIR Ops to
begin with, so I'll keep investigating and fix CIR problem in another
PR.
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