Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[CoroEarly] Hide promise alloca for later passes #139243

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 10 commits into from
May 16, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Make use of uniqueness of coro.promise
  • Loading branch information
NewSigma committed May 13, 2025
commit dc0bd0af7bf31eb6a4afe0b95a211a14b1f51b75
10 changes: 5 additions & 5 deletions 10 llvm/include/llvm/Transforms/Coroutines/CoroShape.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ struct Shape {
// Scan the function and collect the above intrinsics for later processing
void analyze(Function &F, SmallVectorImpl<CoroFrameInst *> &CoroFrames,
SmallVectorImpl<CoroSaveInst *> &UnusedCoroSaves,
SmallVectorImpl<CoroPromiseInst *> &CoroPromises);
CoroPromiseInst *&CoroPromise);
// If for some reason, we were not able to find coro.begin, bailout.
void invalidateCoroutine(Function &F,
SmallVectorImpl<CoroFrameInst *> &CoroFrames);
Expand All @@ -89,7 +89,7 @@ struct Shape {
// Remove orphaned and unnecessary intrinsics
void cleanCoroutine(SmallVectorImpl<CoroFrameInst *> &CoroFrames,
SmallVectorImpl<CoroSaveInst *> &UnusedCoroSaves,
SmallVectorImpl<CoroPromiseInst *> &CoroPromises);
CoroPromiseInst *CoroPromise);

// Field indexes for special fields in the switch lowering.
struct SwitchFieldIndex {
Expand Down Expand Up @@ -267,14 +267,14 @@ struct Shape {
explicit Shape(Function &F) {
SmallVector<CoroFrameInst *, 8> CoroFrames;
SmallVector<CoroSaveInst *, 2> UnusedCoroSaves;
SmallVector<CoroPromiseInst *, 2> CoroPromises;
CoroPromiseInst * CoroPromise = nullptr;

analyze(F, CoroFrames, UnusedCoroSaves, CoroPromises);
analyze(F, CoroFrames, UnusedCoroSaves, CoroPromise);
if (!CoroBegin) {
invalidateCoroutine(F, CoroFrames);
return;
}
cleanCoroutine(CoroFrames, UnusedCoroSaves, CoroPromises);
cleanCoroutine(CoroFrames, UnusedCoroSaves, CoroPromise);
}
};

Expand Down
15 changes: 7 additions & 8 deletions 15 llvm/lib/Transforms/Coroutines/Coroutines.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ static CoroSaveInst *createCoroSave(CoroBeginInst *CoroBegin,
void coro::Shape::analyze(Function &F,
SmallVectorImpl<CoroFrameInst *> &CoroFrames,
SmallVectorImpl<CoroSaveInst *> &UnusedCoroSaves,
SmallVectorImpl<CoroPromiseInst *> &CoroPromises) {
CoroPromiseInst *&CoroPromise) {
clear();

bool HasFinalSuspend = false;
Expand Down Expand Up @@ -288,7 +288,7 @@ void coro::Shape::analyze(Function &F,
}
break;
case Intrinsic::coro_promise:
CoroPromises.push_back(cast<CoroPromiseInst>(II));
CoroPromise = cast<CoroPromiseInst>(II);
NewSigma marked this conversation as resolved.
Show resolved Hide resolved
break;
}
}
Expand Down Expand Up @@ -481,8 +481,7 @@ void coro::AnyRetconABI::init() {

void coro::Shape::cleanCoroutine(
SmallVectorImpl<CoroFrameInst *> &CoroFrames,
SmallVectorImpl<CoroSaveInst *> &UnusedCoroSaves,
SmallVectorImpl<CoroPromiseInst *> &CoroPromises) {
SmallVectorImpl<CoroSaveInst *> &UnusedCoroSaves, CoroPromiseInst *PI) {
// The coro.frame intrinsic is always lowered to the result of coro.begin.
for (CoroFrameInst *CF : CoroFrames) {
CF->replaceAllUsesWith(CoroBegin);
Expand All @@ -495,10 +494,10 @@ void coro::Shape::cleanCoroutine(
CoroSave->eraseFromParent();
UnusedCoroSaves.clear();

auto *AI = getPromiseAlloca();
for (auto *PI : CoroPromises) {
PI->replaceAllUsesWith(PI->isFromPromise() ? cast<Value>(CoroBegin)
: cast<Value>(AI));
if (PI) {
PI->replaceAllUsesWith(PI->isFromPromise()
? cast<Value>(CoroBegin)
: cast<Value>(getPromiseAlloca()));
PI->eraseFromParent();
}
}
Expand Down
1 change: 0 additions & 1 deletion 1 llvm/test/Transforms/Coroutines/gh105595.ll
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ resume:
br label %suspend

suspend:
call i1 @llvm.coro.end(ptr null, i1 false, token none)
; load value when resume
; CHECK: %null = load ptr, ptr %promise.addr, align 8
%null = load ptr, ptr %__promise, align 8
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.