Skip to content

Commit 60f20a8

Browse files
Merge pull request #75881 from felipepiovezan/felipe/remove_outlined_debug_info_rebranch
[DebugInfo] Remove debug info from outlined async helper functions
2 parents ce455db + 35297b3 commit 60f20a8

File tree

5 files changed

+64
-17
lines changed

5 files changed

+64
-17
lines changed

lib/IRGen/GenDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3114,7 +3114,7 @@ void IRGenModule::createReplaceableProlog(IRGenFunction &IGF, SILFunction *f) {
31143114
// Index of swiftasync context | ((index of swiftself) << 8).
31153115
arguments.push_back(IGM.getInt32(paramAttributeFlags));
31163116
arguments.push_back(currentResumeFn);
3117-
auto resumeProjFn = IGF.getOrCreateResumePrjFn(true /*forProlog*/);
3117+
auto resumeProjFn = IGF.getOrCreateResumePrjFn();
31183118
arguments.push_back(
31193119
Builder.CreateBitOrPointerCast(resumeProjFn, IGM.Int8PtrTy));
31203120
auto dispatchFn = IGF.createAsyncDispatchFn(

lib/IRGen/GenFunc.cpp

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2846,11 +2846,12 @@ IRGenFunction::emitAsyncResumeProjectContext(llvm::Value *calleeContext) {
28462846
return callerContext;
28472847
}
28482848

2849-
llvm::Function *IRGenFunction::getOrCreateResumePrjFn(bool forPrologue) {
2850-
// The prologue version lacks artificial debug info as this would cause
2851-
// verification errors when it gets inlined.
2852-
auto name = forPrologue ? "__swift_async_resume_project_context_prologue"
2853-
: "__swift_async_resume_project_context";
2849+
llvm::Function *IRGenFunction::getOrCreateResumePrjFn() {
2850+
auto name = "__swift_async_resume_project_context";
2851+
// This is effectively an outlined function with `alwaysinline`. Don't emit
2852+
// debug locations for those to avoid creating unnecessary inlined frames.
2853+
// Instead, rely on the inliner to propagate the call site debug location.
2854+
const bool skipDebugInfo = true;
28542855
auto Fn = cast<llvm::Function>(IGM.getOrCreateHelperFunction(
28552856
name, IGM.Int8PtrTy, {IGM.Int8PtrTy},
28562857
[&](IRGenFunction &IGF) {
@@ -2860,7 +2861,7 @@ llvm::Function *IRGenFunction::getOrCreateResumePrjFn(bool forPrologue) {
28602861
auto callerContext = IGF.emitAsyncResumeProjectContext(addr);
28612862
Builder.CreateRet(callerContext);
28622863
},
2863-
false /*isNoInline*/, forPrologue));
2864+
false /*isNoInline*/, skipDebugInfo));
28642865
Fn->addFnAttr(llvm::Attribute::AlwaysInline);
28652866
return Fn;
28662867
}
@@ -2899,9 +2900,6 @@ IRGenFunction::createAsyncDispatchFn(const FunctionPointer &fnPtr,
28992900
dispatch->setDoesNotThrow();
29002901
dispatch->addFnAttr(llvm::Attribute::AlwaysInline);
29012902
IRGenFunction dispatchIGF(IGM, dispatch);
2902-
// Don't emit debug info if we are generating a function for the prologue.
2903-
if (IGM.DebugInfo && Builder.getCurrentDebugLocation())
2904-
IGM.DebugInfo->emitOutlinedFunction(dispatchIGF, dispatch, CurFn->getName());
29052903
auto &Builder = dispatchIGF.Builder;
29062904
auto it = dispatchIGF.CurFn->arg_begin(), end = dispatchIGF.CurFn->arg_end();
29072905
llvm::Value *fnPtrArg = &*(it++);
@@ -2958,7 +2956,7 @@ llvm::Function *IRGenFunction::getOrCreateResumeFromSuspensionFn() {
29582956
auto &Builder = IGF.Builder;
29592957
Builder.CreateRet(&*IGF.CurFn->arg_begin());
29602958
},
2961-
false /*isNoInline*/));
2959+
false /*isNoInline*/, true /*forPrologue*/));
29622960
fn->addFnAttr(llvm::Attribute::AlwaysInline);
29632961
return fn;
29642962
}
@@ -2987,9 +2985,6 @@ llvm::Function *IRGenFunction::createAsyncSuspendFn() {
29872985
suspendFn->setDoesNotThrow();
29882986
suspendFn->addFnAttr(llvm::Attribute::AlwaysInline);
29892987
IRGenFunction suspendIGF(IGM, suspendFn);
2990-
if (IGM.DebugInfo)
2991-
IGM.DebugInfo->emitOutlinedFunction(suspendIGF, suspendFn,
2992-
CurFn->getName());
29932988
auto &Builder = suspendIGF.Builder;
29942989

29952990
llvm::Value *resumeFunction = suspendFn->getArg(0);

lib/IRGen/IRGenFunction.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ class IRGenFunction {
178178
bool restoreCurrentContext = true);
179179

180180
llvm::Value *emitAsyncResumeProjectContext(llvm::Value *callerContextAddr);
181-
llvm::Function *getOrCreateResumePrjFn(bool forPrologue = false);
181+
llvm::Function *getOrCreateResumePrjFn();
182182
llvm::Function *createAsyncDispatchFn(const FunctionPointer &fnPtr,
183183
ArrayRef<llvm::Value *> args);
184184
llvm::Function *createAsyncDispatchFn(const FunctionPointer &fnPtr,
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// RUN: %target-swift-frontend %s -emit-irgen -g -o - \
2+
// RUN: -module-name M -disable-availability-checking \
3+
// RUN: -parse-as-library | %FileCheck %s --check-prefix=CHECK
4+
5+
// REQUIRES: concurrency
6+
7+
// Check that all the helper "outlined" functions do not have debug information.
8+
9+
func ASYNC___1___() async -> Int {
10+
return 42
11+
}
12+
13+
func ASYNC___2___() async -> Int {
14+
print("hello")
15+
var x = await ASYNC___1___()
16+
x += await ASYNC___1___()
17+
return x
18+
}
19+
20+
// CHECK-LABEL: define {{.*}} @"$s1M12ASYNC___1___SiyYaF.0"
21+
// CHECK-NOT: !dbg
22+
// CHECK: ret void
23+
// CHECK-NEXT: }
24+
25+
// CHECK-LABEL: define {{.*}} @__swift_async_resume_get_context
26+
// CHECK-NOT: !dbg
27+
// CHECK: ret ptr
28+
// CHECK-NEXT: }
29+
30+
// CHECK-LABEL: define {{.*}} @"$s1M12ASYNC___2___SiyYaF.1"
31+
// CHECK-NOT: !dbg
32+
// CHECK: ret void
33+
// CHECK-NEXT: }
34+
35+
// CHECK-LABEL: define {{.*}} @__swift_async_resume_project_context
36+
// CHECK-NOT: !dbg
37+
// CHECK: ret ptr
38+
// CHECK-NEXT: }
39+
40+
// CHECK-LABEL: define {{.*}} @"$s1M12ASYNC___2___SiyYaF.0"
41+
// CHECK-NOT: !dbg
42+
// CHECK: ret void
43+
// CHECK-NEXT: }
44+
45+
// CHECK-LABEL: define {{.*}} @"$s1M12ASYNC___2___SiyYaF.0.1"
46+
// CHECK-NOT: !dbg
47+
// CHECK: ret void
48+
// CHECK-NEXT: }
49+
50+
// CHECK-LABEL: define {{.*}} @"$s1M12ASYNC___2___SiyYaF.0.2"
51+
// CHECK-NOT: !dbg
52+
// CHECK: ret void
53+
// CHECK-NEXT: }

test/IRGen/async/get_async_continuation.sil

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,10 @@ bb0:
6969
// CHECK: {{musttail call swifttailcc|tail call swiftcc}} void @swift_continuation_await(ptr %0)
7070
// CHECK-NEXT: ret void
7171

72-
// CHECK: define {{.*}} void @async_continuation.0(ptr %0, ptr %1){{.*}}!dbg ![[DBG:[0-9]+]]
72+
// CHECK: define {{.*}} void @async_continuation.0(ptr %0, ptr %1)
7373
// CHECK-NOT: define
7474
// CHECK: tail call swift{{(tail)?}}cc void %{{.*}}(ptr swiftasync %1)
7575
// CHECK-NEXT: ret void
76-
// CHECK: ![[DBG]] = distinct !DISubprogram(linkageName: "async_continuation"
7776

7877
sil @async_continuation : $@async () -> () {
7978
entry:

0 commit comments

Comments
 (0)