-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Reapply "[coro][CoroSplit] Use llvm.lifetime.end
to compute putting objects on the frame vs the stack (#90265)
#91372
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
Changes from 3 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
e4c029f
Reapply "[coro][CoroSplit] Use `llvm.lifetime.end` to compute putting…
alanzhao1 703081b
fix clang format issue
alanzhao1 0bfa097
Use SmallPtrSet instead of DenseMap
alanzhao1 025f236
remove extra change
alanzhao1 7e9695f
use SmallPtrSet for loops
alanzhao1 edbcf9f
deduplicate code by using templates
alanzhao1 6dcb05c
remove unnecessary change..again
alanzhao1 ca09dd0
reduce size of StopBBReachable to align with size of CoroSuspendBBs
alanzhao1 cbb5c8b
ditto with StopLoops
alanzhao1 3f47dd4
Improve template parameter names
alanzhao1 6a8909c
fix build failure
alanzhao1 a487d32
create and use SingleEntrySet
alanzhao1 34617b3
remove template bool param and non const iterator methods
alanzhao1 46bd7d9
Drop StopBBReachable set
alanzhao1 7bb84a7
fix conditional
alanzhao1 d983f8e
remove extra line
alanzhao1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4 | ||
; RUN: opt < %s -passes='cgscc(coro-split),simplifycfg,early-cse' -S | FileCheck %s | ||
|
||
declare ptr @malloc(i64) | ||
|
||
%i8.array = type { [100 x i8] } | ||
declare void @consume.i8.array(ptr) | ||
|
||
@testbool = external local_unnamed_addr global i8, align 1 | ||
|
||
; testval does not contain an explicit lifetime end. We must assume that it may | ||
; live across suspension. | ||
define void @HasNoLifetimeEnd() presplitcoroutine { | ||
; CHECK-LABEL: define void @HasNoLifetimeEnd() { | ||
; CHECK-NEXT: entry: | ||
; CHECK-NEXT: [[ID:%.*]] = call token @llvm.coro.id(i32 0, ptr null, ptr null, ptr @HasNoLifetimeEnd.resumers) | ||
; CHECK-NEXT: [[ALLOC:%.*]] = call ptr @malloc(i64 16) | ||
; CHECK-NEXT: [[VFRAME:%.*]] = call noalias nonnull ptr @llvm.coro.begin(token [[ID]], ptr [[ALLOC]]) | ||
; CHECK-NEXT: store ptr @HasNoLifetimeEnd.resume, ptr [[VFRAME]], align 8 | ||
; CHECK-NEXT: [[DESTROY_ADDR:%.*]] = getelementptr inbounds [[HASNOLIFETIMEEND_FRAME:%.*]], ptr [[VFRAME]], i32 0, i32 1 | ||
; CHECK-NEXT: store ptr @HasNoLifetimeEnd.destroy, ptr [[DESTROY_ADDR]], align 8 | ||
; CHECK-NEXT: [[INDEX_ADDR1:%.*]] = getelementptr inbounds [[HASNOLIFETIMEEND_FRAME]], ptr [[VFRAME]], i32 0, i32 2 | ||
; CHECK-NEXT: call void @consume.i8.array(ptr [[INDEX_ADDR1]]) | ||
; CHECK-NEXT: [[INDEX_ADDR2:%.*]] = getelementptr inbounds [[HASNOLIFETIMEEND_FRAME]], ptr [[VFRAME]], i32 0, i32 3 | ||
; CHECK-NEXT: store i1 false, ptr [[INDEX_ADDR2]], align 1 | ||
; CHECK-NEXT: ret void | ||
; | ||
entry: | ||
%testval = alloca %i8.array | ||
%id = call token @llvm.coro.id(i32 0, ptr null, ptr null, ptr null) | ||
%alloc = call ptr @malloc(i64 16) #3 | ||
%vFrame = call noalias nonnull ptr @llvm.coro.begin(token %id, ptr %alloc) | ||
|
||
call void @llvm.lifetime.start.p0(i64 100, ptr %testval) | ||
call void @consume.i8.array(ptr %testval) | ||
|
||
%save = call token @llvm.coro.save(ptr null) | ||
%suspend = call i8 @llvm.coro.suspend(token %save, i1 false) | ||
switch i8 %suspend, label %exit [ | ||
i8 0, label %await.ready | ||
i8 1, label %exit | ||
] | ||
await.ready: | ||
br label %exit | ||
exit: | ||
call i1 @llvm.coro.end(ptr null, i1 false, token none) | ||
ret void | ||
} | ||
|
||
define void @LifetimeEndAfterCoroEnd() presplitcoroutine { | ||
; CHECK-LABEL: define void @LifetimeEndAfterCoroEnd() { | ||
; CHECK-NEXT: entry: | ||
; CHECK-NEXT: [[ID:%.*]] = call token @llvm.coro.id(i32 0, ptr null, ptr null, ptr @LifetimeEndAfterCoroEnd.resumers) | ||
; CHECK-NEXT: [[ALLOC:%.*]] = call ptr @malloc(i64 16) | ||
; CHECK-NEXT: [[VFRAME:%.*]] = call noalias nonnull ptr @llvm.coro.begin(token [[ID]], ptr [[ALLOC]]) | ||
; CHECK-NEXT: store ptr @LifetimeEndAfterCoroEnd.resume, ptr [[VFRAME]], align 8 | ||
; CHECK-NEXT: [[DESTROY_ADDR:%.*]] = getelementptr inbounds [[LIFETIMEENDAFTERCOROEND_FRAME:%.*]], ptr [[VFRAME]], i32 0, i32 1 | ||
; CHECK-NEXT: store ptr @LifetimeEndAfterCoroEnd.destroy, ptr [[DESTROY_ADDR]], align 8 | ||
; CHECK-NEXT: [[INDEX_ADDR1:%.*]] = getelementptr inbounds [[LIFETIMEENDAFTERCOROEND_FRAME]], ptr [[VFRAME]], i32 0, i32 2 | ||
; CHECK-NEXT: call void @consume.i8.array(ptr [[INDEX_ADDR1]]) | ||
; CHECK-NEXT: [[INDEX_ADDR2:%.*]] = getelementptr inbounds [[LIFETIMEENDAFTERCOROEND_FRAME]], ptr [[VFRAME]], i32 0, i32 3 | ||
; CHECK-NEXT: store i1 false, ptr [[INDEX_ADDR2]], align 1 | ||
; CHECK-NEXT: ret void | ||
; | ||
entry: | ||
%testval = alloca %i8.array | ||
%id = call token @llvm.coro.id(i32 0, ptr null, ptr null, ptr null) | ||
%alloc = call ptr @malloc(i64 16) #3 | ||
%vFrame = call noalias nonnull ptr @llvm.coro.begin(token %id, ptr %alloc) | ||
|
||
call void @llvm.lifetime.start.p0(i64 100, ptr %testval) | ||
call void @consume.i8.array(ptr %testval) | ||
|
||
%save = call token @llvm.coro.save(ptr null) | ||
%suspend = call i8 @llvm.coro.suspend(token %save, i1 false) | ||
switch i8 %suspend, label %exit [ | ||
i8 0, label %await.ready | ||
i8 1, label %exit | ||
] | ||
await.ready: | ||
br label %exit | ||
exit: | ||
call i1 @llvm.coro.end(ptr null, i1 false, token none) | ||
call void @llvm.lifetime.end.p0(i64 100, ptr %testval) | ||
ret void | ||
} | ||
|
||
define void @BranchWithoutLifetimeEnd() presplitcoroutine { | ||
; CHECK-LABEL: define void @BranchWithoutLifetimeEnd() { | ||
; CHECK-NEXT: entry: | ||
; CHECK-NEXT: [[ID:%.*]] = call token @llvm.coro.id(i32 0, ptr null, ptr null, ptr @BranchWithoutLifetimeEnd.resumers) | ||
; CHECK-NEXT: [[ALLOC:%.*]] = call ptr @malloc(i64 16) | ||
; CHECK-NEXT: [[VFRAME:%.*]] = call noalias nonnull ptr @llvm.coro.begin(token [[ID]], ptr [[ALLOC]]) | ||
; CHECK-NEXT: store ptr @BranchWithoutLifetimeEnd.resume, ptr [[VFRAME]], align 8 | ||
; CHECK-NEXT: [[DESTROY_ADDR:%.*]] = getelementptr inbounds [[BRANCHWITHOUTLIFETIMEEND_FRAME:%.*]], ptr [[VFRAME]], i32 0, i32 1 | ||
; CHECK-NEXT: store ptr @BranchWithoutLifetimeEnd.destroy, ptr [[DESTROY_ADDR]], align 8 | ||
; CHECK-NEXT: [[TESTVAL:%.*]] = getelementptr inbounds [[BRANCHWITHOUTLIFETIMEEND_FRAME]], ptr [[VFRAME]], i32 0, i32 2 | ||
; CHECK-NEXT: call void @consume.i8.array(ptr [[TESTVAL]]) | ||
; CHECK-NEXT: [[TMP0:%.*]] = load i8, ptr @testbool, align 1 | ||
; CHECK-NEXT: [[INDEX_ADDR1:%.*]] = getelementptr inbounds [[BRANCHWITHOUTLIFETIMEEND_FRAME]], ptr [[VFRAME]], i32 0, i32 3 | ||
; CHECK-NEXT: store i1 false, ptr [[INDEX_ADDR1]], align 1 | ||
; CHECK-NEXT: ret void | ||
; | ||
entry: | ||
%testval = alloca %i8.array | ||
%id = call token @llvm.coro.id(i32 0, ptr null, ptr null, ptr null) | ||
%alloc = call ptr @malloc(i64 16) #3 | ||
%vFrame = call noalias nonnull ptr @llvm.coro.begin(token %id, ptr %alloc) | ||
|
||
call void @llvm.lifetime.start.p0(i64 100, ptr %testval) | ||
call void @consume.i8.array(ptr %testval) | ||
|
||
%0 = load i8, ptr @testbool, align 1 | ||
%tobool = trunc nuw i8 %0 to i1 | ||
br i1 %tobool, label %if.then, label %if.end | ||
|
||
if.then: | ||
call void @llvm.lifetime.end.p0(i64 100, ptr %testval) | ||
br label %if.end | ||
|
||
if.end: | ||
%save = call token @llvm.coro.save(ptr null) | ||
%suspend = call i8 @llvm.coro.suspend(token %save, i1 false) | ||
switch i8 %suspend, label %exit [ | ||
i8 0, label %await.ready | ||
i8 1, label %exit | ||
] | ||
await.ready: | ||
br label %exit | ||
exit: | ||
call i1 @llvm.coro.end(ptr null, i1 false, token none) | ||
ret void | ||
} | ||
|
||
|
||
declare token @llvm.coro.id(i32, ptr readnone, ptr nocapture readonly, ptr) | ||
declare ptr @llvm.coro.begin(token, ptr writeonly) #3 | ||
declare ptr @llvm.coro.frame() #5 | ||
declare i8 @llvm.coro.suspend(token, i1) #3 | ||
declare i1 @llvm.coro.end(ptr, i1, token) #3 | ||
declare void @llvm.lifetime.start.p0(i64, ptr nocapture) #4 | ||
declare void @llvm.lifetime.end.p0(i64, ptr nocapture) #4 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.