Skip to content

Commit d268feb

Browse files
committed
Improve the debug info for coro-split .resume functions
This patch updates the scope line to point to the suspend point. This makes the first address in the function point to the first source line in the resume function rather than the function declaration. Without this the line table "jumps" from the beginning of the function to the suspend point at the beginning. rdar://73386346 Differential Revision: https://reviews.llvm.org/D97345
1 parent a85eb11 commit d268feb

File tree

3 files changed

+37
-4
lines changed

3 files changed

+37
-4
lines changed

llvm/include/llvm/IR/DebugInfoMetadata.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1951,6 +1951,7 @@ class DISubprogram : public DILocalScope {
19511951
unsigned getVirtualIndex() const { return VirtualIndex; }
19521952
int getThisAdjustment() const { return ThisAdjustment; }
19531953
unsigned getScopeLine() const { return ScopeLine; }
1954+
void setScopeLine(unsigned L) { assert(isDistinct()); ScopeLine = L; }
19541955
DIFlags getFlags() const { return Flags; }
19551956
DISPFlags getSPFlags() const { return SPFlags; }
19561957
bool isLocalToUnit() const { return getSPFlags() & SPFlagLocalToUnit; }

llvm/lib/Transforms/Coroutines/CoroSplit.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -846,6 +846,16 @@ void CoroCloner::create() {
846846

847847
CloneFunctionInto(NewF, &OrigF, VMap,
848848
CloneFunctionChangeType::LocalChangesOnly, Returns);
849+
// For async functions / continuations, adjust the scope line of the
850+
// clone to the line number of the suspend point. The scope line is
851+
// associated with all pre-prologue instructions. This avoids a jump
852+
// in the linetable from the function declaration to the suspend point.
853+
if (DISubprogram *SP = NewF->getSubprogram()) {
854+
assert(SP != OrigF.getSubprogram() && SP->isDistinct());
855+
if (ActiveSuspend)
856+
if (auto DL = ActiveSuspend->getDebugLoc())
857+
SP->setScopeLine(DL->getLine());
858+
}
849859

850860
NewF->setLinkage(savedLinkage);
851861
NewF->setVisibility(savedVisibility);

llvm/test/Transforms/Coroutines/coro-async.ll

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ entry:
5555
}
5656

5757

58-
define swiftcc void @my_async_function(i8* %async.ctxt, %async.task* %task, %async.actor* %actor) {
58+
define swiftcc void @my_async_function(i8* %async.ctxt, %async.task* %task, %async.actor* %actor) !dbg !1 {
5959
entry:
6060
%tmp = alloca { i64, i64 }, align 8
6161
%proj.1 = getelementptr inbounds { i64, i64 }, { i64, i64 }* %tmp, i64 0, i32 0
@@ -93,7 +93,7 @@ entry:
9393
i8* %resume.func_ptr,
9494
i8* %resume_proj_fun,
9595
void (i8*, i8*, %async.task*, %async.actor*)* @my_async_function.my_other_async_function_fp.apply,
96-
i8* %callee, i8* %callee_context, %async.task* %task, %async.actor *%actor)
96+
i8* %callee, i8* %callee_context, %async.task* %task, %async.actor *%actor), !dbg !5
9797

9898
call void @llvm.coro.async.context.dealloc(i8* %callee_context)
9999
%continuation_task_arg = extractvalue {i8*, i8*, i8*} %res, 1
@@ -119,7 +119,8 @@ define void @my_async_function_pa(i8* %ctxt, %async.task* %task, %async.actor* %
119119
; CHECK: @my_async_function_pa_fp = constant <{ i32, i32 }> <{ {{.*}}, i32 176 }
120120
; CHECK: @my_async_function2_fp = constant <{ i32, i32 }> <{ {{.*}}, i32 176 }
121121

122-
; CHECK-LABEL: define swiftcc void @my_async_function(i8* %async.ctxt, %async.task* %task, %async.actor* %actor) {
122+
; CHECK-LABEL: define swiftcc void @my_async_function(i8* %async.ctxt, %async.task* %task, %async.actor* %actor)
123+
; CHECK-SAME: !dbg ![[SP1:[0-9]+]] {
123124
; CHECK: entry:
124125
; CHECK: [[FRAMEPTR:%.*]] = getelementptr inbounds i8, i8* %async.ctxt, i64 128
125126
; CHECK: [[ACTOR_SPILL_ADDR:%.*]] = getelementptr inbounds i8, i8* %async.ctxt, i64 152
@@ -148,7 +149,8 @@ define void @my_async_function_pa(i8* %ctxt, %async.task* %task, %async.actor* %
148149
; CHECK: ret void
149150
; CHECK: }
150151

151-
; CHECK-LABEL: define internal swiftcc void @my_async_function.resume.0(i8* nocapture readonly %0, i8* %1, i8* nocapture readnone %2) {
152+
; CHECK-LABEL: define internal swiftcc void @my_async_function.resume.0(i8* nocapture readonly %0, i8* %1, i8* nocapture readnone %2)
153+
; CHECK-SAME: !dbg ![[SP2:[0-9]+]] {
152154
; CHECK: entryresume.0:
153155
; CHECK: [[CALLER_CONTEXT_ADDR:%.*]] = bitcast i8* %0 to i8**
154156
; CHECK: [[CALLER_CONTEXT:%.*]] = load i8*, i8** [[CALLER_CONTEXT_ADDR]]
@@ -529,3 +531,23 @@ declare swiftcc void @asyncReturn(i8*, %async.task*, %async.actor*)
529531
declare swiftcc void @asyncSuspend(i8*, %async.task*, %async.actor*)
530532
declare i8* @llvm.coro.async.resume()
531533
declare void @llvm.coro.async.size.replace(i8*, i8*)
534+
535+
!llvm.dbg.cu = !{!2}
536+
!llvm.module.flags = !{!0}
537+
538+
!0 = !{i32 2, !"Debug Info Version", i32 3}
539+
; CHECK: ![[SP1]] = distinct !DISubprogram(name: "my_async_function",
540+
; CHECK-SAME: linkageName: "my_async_function",
541+
; CHECK-SAME: scopeLine: 1
542+
!1 = distinct !DISubprogram(name: "my_async_function",
543+
linkageName: "my_async_function",
544+
scope: !2, file: !3, line: 1, type: !4,
545+
scopeLine: 1, spFlags: DISPFlagDefinition, unit: !2)
546+
; CHECK: ![[SP2]] = distinct !DISubprogram(name: "my_async_function",
547+
; CHECK-SAME: linkageName: "my_async_function",
548+
; CHECK-SAME: scopeLine: 2
549+
!2 = distinct !DICompileUnit(language: DW_LANG_Swift, file: !3, emissionKind: FullDebug)
550+
!3 = !DIFile(filename: "/tmp/1.swift", directory: "/")
551+
!4 = !DISubroutineType(types: !{})
552+
!5 = !DILocation(line: 2, column: 0, scope: !1)
553+

0 commit comments

Comments
 (0)