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] Lower nested local constant alloca #1261

Merged
merged 1 commit into from
Feb 17, 2025

Conversation

Lancern
Copy link
Member

@Lancern Lancern commented Dec 29, 2024

This PR adds support for lowering local constants in nested scopes, including those in nested loops.

For those constant allocas in non-loop inner scopes, this PR keeps their constant flags during alloca hoisting. LLVM lowering would correctly emit necessary invariant metadata for those allocas.

For those constant allocas in a loop, this PR introduces a new operation cir.invariant_group that marks the beginning of the lifetime of the constant objects. This operation is put at the location of the alloca operation before hoisting them. This PR updates LLVM lowering to emit the necessary invariant metadata when loading and storing through such pointers.

This PR takes care of the special case where the constant alloca represents a variable declared in the condition part of a while loop. In such a case, this PR removes the constant flag on the alloca operation when hositing them.

@Lancern Lancern force-pushed the nested-local-const-lowering branch from 0a13412 to 7a7d9cf Compare January 24, 2025 08:02
@Lancern
Copy link
Member Author

Lancern commented Jan 24, 2025

Rebased onto the latest main.

@bcardosolopes
Copy link
Member

Sorry I missed this, taking a closer look next week!

@Lancern
Copy link
Member Author

Lancern commented Feb 4, 2025

Rebased onto the latest main.

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 your patience, comments inline

@Lancern Lancern force-pushed the nested-local-const-lowering branch from 4e7443d to 691c91b Compare February 10, 2025 15:44
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.

LGTM pending few comment additions and function rename

@Lancern Lancern force-pushed the nested-local-const-lowering branch 3 times, most recently from 0c723b0 to 008a24a Compare February 13, 2025 13:47
@Lancern
Copy link
Member Author

Lancern commented Feb 13, 2025

Rebased onto the latest main.

@bcardosolopes
Copy link
Member

LGTM, maybe rebase and land once the test passes (just to make sure)

This patch adds support for lowering local constants in nested scopes, including
those in nested loops.

For those constant allocas in non-loop inner scopes, this patch keeps their
constant flags during alloca hoisting. LLVM lowering would correctly emit
necessary invariant metadata for those allocas.

For those constant allocas in a loop, this patch introduces a new operation
`cir.invariant_group` that marks the beginning of the lifetime of the constant
objects. This operation is put at the location of the alloca operation before
hoisting them. This patch updates LLVM lowering to emit the necessary invariant
metadata when loading and storing through such pointers.

This patch takes care of the special case where the constant alloca represents
a variable declared in the condition part of a while loop. In such a case, this
patch removes the constant flag on the alloca operation when hositing them.
@Lancern Lancern force-pushed the nested-local-const-lowering branch from 008a24a to c6ac622 Compare February 15, 2025 15:53
@Lancern
Copy link
Member Author

Lancern commented Feb 15, 2025

Rebased onto the latest main.

@Lancern
Copy link
Member Author

Lancern commented Feb 17, 2025

All tests are green, landing this.

@Lancern Lancern merged commit c69469e into llvm:main Feb 17, 2025
6 checks passed
@Lancern Lancern deleted the nested-local-const-lowering branch February 17, 2025 03:13
lanza pushed a commit that referenced this pull request Mar 18, 2025
This PR adds support for lowering local constants in nested scopes,
including those in nested loops.

For those constant allocas in non-loop inner scopes, this PR keeps their
constant flags during alloca hoisting. LLVM lowering would correctly
emit necessary invariant metadata for those allocas.

For those constant allocas in a loop, this PR introduces a new operation
`cir.invariant_group` that marks the beginning of the lifetime of the
constant objects. This operation is put at the location of the alloca
operation before hoisting them. This PR updates LLVM lowering to emit
the necessary invariant metadata when loading and storing through such
pointers.

This PR takes care of the special case where the constant alloca
represents a variable declared in the condition part of a while loop. In
such a case, this PR removes the constant flag on the alloca operation
when hositing them.
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