Skip to content

Commit 8aa038a

Browse files
[CoroSplit][DebugInfo] Don't use entry_value in coroutine entry point
The entry point function is called as a regular function. Among other things, it can be inlined, which would violate the semantics of entry_value in the IR. Differential Revision: https://reviews.llvm.org/D158108
1 parent a342f98 commit 8aa038a

File tree

4 files changed

+14
-8
lines changed

4 files changed

+14
-8
lines changed

llvm/lib/Transforms/Coroutines/CoroFrame.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1882,7 +1882,8 @@ static void insertSpills(const FrameDataInfo &FrameData, coro::Shape &Shape) {
18821882
&*Builder.GetInsertPoint());
18831883
// This dbg.declare is for the main function entry point. It
18841884
// will be deleted in all coro-split functions.
1885-
coro::salvageDebugInfo(ArgToAllocaMap, DDI, Shape.OptimizeFrame);
1885+
coro::salvageDebugInfo(ArgToAllocaMap, DDI, Shape.OptimizeFrame,
1886+
true /*IsEntryPoint*/);
18861887
}
18871888
}
18881889

@@ -2818,7 +2819,7 @@ static void collectFrameAlloca(AllocaInst *AI, coro::Shape &Shape,
28182819

28192820
void coro::salvageDebugInfo(
28202821
SmallDenseMap<Argument *, AllocaInst *, 4> &ArgToAllocaMap,
2821-
DbgVariableIntrinsic *DVI, bool OptimizeFrame) {
2822+
DbgVariableIntrinsic *DVI, bool OptimizeFrame, bool IsEntryPoint) {
28222823
Function *F = DVI->getFunction();
28232824
IRBuilder<> Builder(F->getContext());
28242825
auto InsertPt = F->getEntryBlock().getFirstInsertionPt();
@@ -2870,7 +2871,10 @@ void coro::salvageDebugInfo(
28702871

28712872
// Swift async arguments are described by an entry value of the ABI-defined
28722873
// register containing the coroutine context.
2873-
if (IsSwiftAsyncArg && !Expr->isEntryValue())
2874+
// For the EntryPoint funclet, don't use EntryValues. This funclet can be
2875+
// inlined, which would remove the guarantee that this intrinsic targets an
2876+
// Argument.
2877+
if (IsSwiftAsyncArg && !IsEntryPoint && !Expr->isEntryValue())
28742878
Expr = DIExpression::prepend(Expr, DIExpression::EntryValue);
28752879

28762880
// If the coroutine frame is an Argument, store it in an alloca to improve

llvm/lib/Transforms/Coroutines/CoroInternal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ void replaceCoroFree(CoroIdInst *CoroId, bool Elide);
3232
/// OptimizeFrame is false.
3333
void salvageDebugInfo(
3434
SmallDenseMap<Argument *, AllocaInst *, 4> &ArgToAllocaMap,
35-
DbgVariableIntrinsic *DVI, bool OptimizeFrame);
35+
DbgVariableIntrinsic *DVI, bool OptimizeFrame, bool IsEntryPoint);
3636

3737
// Keeps data and helper functions for lowering coroutine intrinsics.
3838
struct LowererBase {

llvm/lib/Transforms/Coroutines/CoroSplit.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,8 @@ void CoroCloner::salvageDebugInfo() {
702702
collectDbgVariableIntrinsics(*NewF);
703703
SmallDenseMap<Argument *, AllocaInst *, 4> ArgToAllocaMap;
704704
for (DbgVariableIntrinsic *DVI : Worklist)
705-
coro::salvageDebugInfo(ArgToAllocaMap, DVI, Shape.OptimizeFrame);
705+
coro::salvageDebugInfo(ArgToAllocaMap, DVI, Shape.OptimizeFrame,
706+
false /*IsEntryPoint*/);
706707

707708
// Remove all salvaged dbg.declare intrinsics that became
708709
// either unreachable or stale due to the CoroSplit transformation.
@@ -1995,7 +1996,8 @@ splitCoroutine(Function &F, SmallVectorImpl<Function *> &Clones,
19951996
// coroutine funclets.
19961997
SmallDenseMap<Argument *, AllocaInst *, 4> ArgToAllocaMap;
19971998
for (auto *DDI : collectDbgVariableIntrinsics(F))
1998-
coro::salvageDebugInfo(ArgToAllocaMap, DDI, Shape.OptimizeFrame);
1999+
coro::salvageDebugInfo(ArgToAllocaMap, DDI, Shape.OptimizeFrame,
2000+
true /*IsEntryPoint*/);
19992001

20002002
return Shape;
20012003
}

llvm/test/Transforms/Coroutines/swift-async-dbg.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ define swifttailcc void @coroutineA(ptr swiftasync %arg) !dbg !48 {
1919
; CHECK-LABEL: define {{.*}} @coroutineA(
2020
; CHECK-SAME: ptr swiftasync %[[frame_ptr:.*]])
2121
; CHECK: @llvm.dbg.declare(metadata ptr %[[frame_ptr]], {{.*}} !DIExpression(
22-
; CHECK-SAME: DW_OP_LLVM_entry_value, 1, DW_OP_plus_uconst, 16, DW_OP_plus_uconst, 8)
22+
; CHECK-SAME: DW_OP_plus_uconst, 16, DW_OP_plus_uconst, 8)
2323
; CHECK: @llvm.dbg.value(metadata ptr %[[frame_ptr]], {{.*}} !DIExpression(
24-
; CHECK-SAME: DW_OP_LLVM_entry_value, 1, DW_OP_plus_uconst, 16, DW_OP_deref)
24+
; CHECK-SAME: DW_OP_plus_uconst, 16, DW_OP_deref)
2525
; CHECK: call {{.*}} @swift_task_switch
2626

2727
%i7 = call ptr @llvm.coro.async.resume(), !dbg !54

0 commit comments

Comments
 (0)