Skip to content

Commit b45f016

Browse files
committed
[Coro] RetconOnceDynamic: Pass frame to de/alloc.
Doing so enables allocator implementation to use the frame to store contextual info.
1 parent 69ecaf6 commit b45f016

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

llvm/lib/Transforms/Coroutines/Coroutines.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -534,18 +534,21 @@ Value *coro::Shape::emitAlloc(IRBuilder<> &Builder, Value *Size,
534534
case coro::ABI::RetconOnce:
535535
case coro::ABI::RetconOnceDynamic: {
536536
unsigned sizeParamIndex = 0;
537-
SmallVector<Value *, 2> Args;
538-
if (ABI == coro::ABI::RetconOnceDynamic) {
539-
sizeParamIndex = 1;
540-
Args.push_back(RetconLowering.Allocator);
541-
}
542537
Function *Alloc = nullptr;
543538
if (isa_and_nonnull<CoroAllocaAllocFrameInst>(AI)) {
544539
assert(ABI == coro::ABI::RetconOnceDynamic);
545540
Alloc = RetconLowering.AllocFrame;
546541
} else {
547542
Alloc = RetconLowering.Alloc;
548543
}
544+
SmallVector<Value *, 2> Args;
545+
if (ABI == coro::ABI::RetconOnceDynamic) {
546+
Args.push_back(RetconLowering.Storage);
547+
Args.push_back(RetconLowering.Allocator);
548+
sizeParamIndex = 2;
549+
} else {
550+
Alloc = RetconLowering.Alloc;
551+
}
549552
Size = Builder.CreateIntCast(
550553
Size, Alloc->getFunctionType()->getParamType(sizeParamIndex),
551554
/*is signed*/ false);
@@ -582,11 +585,14 @@ void coro::Shape::emitDealloc(IRBuilder<> &Builder, Value *Ptr,
582585
} else {
583586
Dealloc = RetconLowering.Dealloc;
584587
}
585-
SmallVector<Value *, 2> Args;
586588
unsigned allocationParamIndex = 0;
589+
SmallVector<Value *, 2> Args;
587590
if (ABI == coro::ABI::RetconOnceDynamic) {
588-
allocationParamIndex = 1;
591+
allocationParamIndex = 2;
592+
Args.push_back(RetconLowering.Storage);
589593
Args.push_back(RetconLowering.Allocator);
594+
} else {
595+
Dealloc = RetconLowering.Dealloc;
590596
}
591597
Ptr = Builder.CreateBitCast(
592598
Ptr, Dealloc->getFunctionType()->getParamType(allocationParamIndex));

llvm/test/Transforms/Coroutines/coro-retcon-once-dynamic.ll

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,10 @@ cleanup:
114114

115115
declare void @continuation_prototype(ptr, ptr)
116116

117-
declare swiftcorocc noalias ptr @allocate(ptr swiftcoro %cator, i32 %size)
118-
declare void @deallocate(ptr swiftcoro %cator, ptr %ptr)
119-
declare swiftcorocc noalias ptr @allocate_frame(ptr swiftcoro %cator, i32 %size)
120-
declare void @deallocate_frame(ptr swiftcoro %cator, ptr %ptr)
117+
declare swiftcorocc noalias ptr @allocate(ptr %frame, ptr swiftcoro %cator, i32 %size)
118+
declare void @deallocate(ptr %frame, ptr swiftcoro %cator, ptr %ptr)
119+
declare swiftcorocc noalias ptr @allocate_frame(ptr %frame, ptr swiftcoro %cator, i32 %size)
120+
declare void @deallocate_frame(ptr %frame, ptr swiftcoro %cator, ptr %ptr)
121121

122122
declare void @use(ptr %ptr)
123123

@@ -186,10 +186,12 @@ declare { ptr, ptr } @allocating_something_else(ptr noalias %frame, ptr swiftcor
186186
; CHECK-SAME: {
187187
; CHECK: %size = call i32 @getSize()
188188
; CHECK: call swiftcorocc ptr @allocate(
189+
; CHECK-SAME: ptr %frame,
189190
; CHECK-SAME: ptr %allocator,
190191
; CHECK-SAME: i32 %size
191192
; CHECK-SAME: )
192193
; CHECK: call swiftcorocc ptr @allocate_frame(
194+
; CHECK-SAME: ptr %frame,
193195
; CHECK-SAME: ptr %allocator,
194196
; CHECK-SAME: i32
195197
; CHECK-SAME: )
@@ -199,10 +201,12 @@ declare { ptr, ptr } @allocating_something_else(ptr noalias %frame, ptr swiftcor
199201
; CHECK-SAME: )
200202
; CHECK-SAME: {
201203
; CHECK: call void @deallocate_frame(
204+
; CHECK-SAME: ptr %0,
202205
; CHECK-SAME: ptr %1,
203206
; CHECK-SAME: ptr
204207
; CHECK-SAME: )
205208
; CHECK: call void @deallocate(
209+
; CHECK-SAME: ptr %0,
206210
; CHECK-SAME: ptr %1,
207211
; CHECK-SAME: ptr
208212
; CHECK-SAME: )

0 commit comments

Comments
 (0)