Skip to content

Commit 98637c9

Browse files
nate-chandlerbnbarham
authored andcommitted
[Coro] Retcon.Dynamic: Cap spill alignment.
Apply to dynamic retcon coroutines the machinery added in 2937f8d for async coroutines. And test aligning of allocas with large alignments. rdar://148782254 (cherry picked from commit 9281ab2)
1 parent 361a06d commit 98637c9

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

llvm/lib/Transforms/Coroutines/CoroFrame.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,8 @@ static StructType *buildFrameType(Function &F, coro::Shape &Shape,
874874
std::optional<Align> MaxFrameAlignment;
875875
if (Shape.ABI == coro::ABI::Async)
876876
MaxFrameAlignment = Shape.AsyncLowering.getContextAlignment();
877+
if (Shape.ABI == coro::ABI::RetconOnceDynamic)
878+
MaxFrameAlignment = Shape.RetconLowering.getStorageAlignment();
877879
FrameTypeBuilder B(C, DL, MaxFrameAlignment);
878880

879881
AllocaInst *PromiseAlloca = Shape.getPromiseAlloca();

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

+56
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
44
target triple = "arm64-apple-macos99.99"
55

66
; CHECK-LABEL: %func.Frame = type { ptr }
7+
; CHECK-LABEL: %big_types.Frame = type { <32 x i8>, [16 x i8], i64, ptr, %Integer8 }
78

89
; CHECK-LABEL: @func_cfp = constant <{ i32, i32 }>
910
; CHECK-SAME: <{
@@ -20,6 +21,16 @@ target triple = "arm64-apple-macos99.99"
2021
i32 64 ; frame size
2122
}>
2223

24+
@big_types_cfp = constant <{ i32, i32 }>
25+
<{ i32 trunc ( ; offset to @func from @big_types_cfp
26+
i64 sub (
27+
i64 ptrtoint (ptr @big_types to i64),
28+
i64 ptrtoint (ptr getelementptr inbounds (<{ i32, i32 }>, ptr @big_types_cfp, i32 0, i32 1) to i64)
29+
)
30+
to i32),
31+
i32 64 ; frame size
32+
}>
33+
2334

2435
; CHECK-LABEL: @func(
2536
; CHECK-SAME: ptr %buffer,
@@ -101,3 +112,48 @@ declare void @continuation_prototype(ptr, ptr)
101112

102113
declare swiftcorocc noalias ptr @allocate(i32 %size)
103114
declare void @deallocate(ptr %ptr)
115+
116+
%Integer8 = type { i8 }
117+
118+
; CHECK-LABEL: @big_types(
119+
; CHECK-SAME: ptr noalias %frame,
120+
; CHECK-SAME: ptr swiftcoro %allocator,
121+
; CHECK-SAME: i64 %index,
122+
; CHECK-SAME: ptr swiftself dereferenceable(32) %vec_addr
123+
; CHECK-SAME: ) {
124+
; CHECK: [[VEC_STK_BASE_PTR:%.*]] = getelementptr inbounds %big_types.Frame, ptr %frame, i32 0, i32 0
125+
; CHECK: [[VEC_STK_BASE_INT:%.*]] = ptrtoint ptr [[VEC_STK_BASE_PTR]] to i64
126+
; CHECK: [[VEC_STK_BIASED_INT:%.*]] = add i64 [[VEC_STK_BASE_INT]], 31
127+
; CHECK: [[VEC_STK_ALIGNED_INT:%.*]] = and i64 [[VEC_STK_BIASED_INT]], -32
128+
; CHECK: %vec_stk = inttoptr i64 [[VEC_STK_ALIGNED_INT]] to ptr
129+
define swiftcorocc { ptr, ptr } @big_types(ptr noalias %frame, ptr swiftcoro %allocator, i64 %index, ptr nocapture swiftself dereferenceable(32) %vec_addr) {
130+
%element_addr = alloca %Integer8, align 1
131+
%id = tail call token @llvm.coro.id.retcon.once.dynamic(
132+
i32 -1,
133+
i32 16,
134+
ptr nonnull @big_types_cfp,
135+
ptr %allocator,
136+
ptr %frame,
137+
ptr @continuation_prototype,
138+
ptr nonnull @allocate,
139+
ptr nonnull @deallocate
140+
)
141+
%handle = tail call ptr @llvm.coro.begin(token %id, ptr null)
142+
call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %element_addr)
143+
%vec_original = load <32 x i8>, ptr %vec_addr, align 32
144+
%vec_stk = alloca <32 x i8>, align 32
145+
store <32 x i8> %vec_original, ptr %vec_stk, align 32
146+
%vec_original_2 = load <32 x i8>, ptr %vec_stk, align 32
147+
%index32 = trunc i64 %index to i32
148+
%element_original = extractelement <32 x i8> %vec_original_2, i32 %index32
149+
store i8 %element_original, ptr %element_addr, align 1
150+
call ptr (...) @llvm.coro.suspend.retcon.p0(ptr nonnull %element_addr)
151+
%element_modified = load i8, ptr %element_addr, align 1
152+
%vec_original_3 = load <32 x i8>, ptr %vec_stk, align 32
153+
%vec_modified = insertelement <32 x i8> %vec_original_3, i8 %element_modified, i32 %index32
154+
store <32 x i8> %vec_modified, ptr %vec_addr, align 32
155+
call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %element_addr)
156+
call i1 @llvm.coro.end(ptr %handle, i1 false, token none)
157+
unreachable
158+
}
159+

0 commit comments

Comments
 (0)