Skip to content

[Transforms] Add LifetimeMovePass #144319

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

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

NewSigma
Copy link
Contributor

As suggested by @ChuanqiXu9 in #143333 , I propose LifetimeMovePass, which was previously part of the CoroSplit pass, should now appear as a general pass. Lifetime markers determine whether we place alloca on the frame or on the stack. By moving these markers to optimized positions, we can reduce the coroutine frame size, leading to significant memory savings.
The LifetimeMovePass is positioned between SimplifyCFG and InstCombine. Currently, it only applies to pre-split coroutines, as I have not yet developed a concrete plan for its interaction with non-coroutine code. This patch is WIP, feel free to share your feedback or suggestions.

Close #49716

@NewSigma
Copy link
Contributor Author

cc @ChuanqiXu9 @nikic

Copy link
Contributor

@nikic nikic left a comment

Choose a reason for hiding this comment

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

Just some quick drive-by notes. Can this pass result in observable changes to allocation addresses?


def int_coro_await_suspend_handle : Intrinsic<[],
[llvm_ptr_ty, llvm_ptr_ty, llvm_ptr_ty],
[Throws]>;
[Throws, NoCapture<ArgIndex<0>>]>;
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be a separate change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK. I will separate it before landing this patch. Temporarily keep it so that CI looks good.

@nikic nikic requested a review from ChuanqiXu9 June 16, 2025 09:19
Co-authored-by: Nikita Popov <github@npopov.com>
@ChuanqiXu9
Copy link
Member

(I didn't take a real look yet)

We shouldn't put Coro in the title since this doesn't relate to coroutines. This is a generic optimization if it is valid.

@NewSigma NewSigma changed the title [LLVM][Coro] Add LifetimeMovePass [Transforms] Add LifetimeMovePass Jun 17, 2025
@NewSigma
Copy link
Contributor Author

Can this pass result in observable changes to allocation addresses?

No. This pass shall not introduce changes to allocation addresses.

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.

[Coroutine] Coroutine collect unneeded variables to coroutine frame.
3 participants