Skip to content

[DebugInfo] Remove debug info from outlined async helper functions #75881

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/IRGen/GenDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3114,7 +3114,7 @@ void IRGenModule::createReplaceableProlog(IRGenFunction &IGF, SILFunction *f) {
// Index of swiftasync context | ((index of swiftself) << 8).
arguments.push_back(IGM.getInt32(paramAttributeFlags));
arguments.push_back(currentResumeFn);
auto resumeProjFn = IGF.getOrCreateResumePrjFn(true /*forProlog*/);
auto resumeProjFn = IGF.getOrCreateResumePrjFn();
arguments.push_back(
Builder.CreateBitOrPointerCast(resumeProjFn, IGM.Int8PtrTy));
auto dispatchFn = IGF.createAsyncDispatchFn(
Expand Down
21 changes: 8 additions & 13 deletions lib/IRGen/GenFunc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2846,11 +2846,12 @@ IRGenFunction::emitAsyncResumeProjectContext(llvm::Value *calleeContext) {
return callerContext;
}

llvm::Function *IRGenFunction::getOrCreateResumePrjFn(bool forPrologue) {
// The prologue version lacks artificial debug info as this would cause
// verification errors when it gets inlined.
auto name = forPrologue ? "__swift_async_resume_project_context_prologue"
: "__swift_async_resume_project_context";
llvm::Function *IRGenFunction::getOrCreateResumePrjFn() {
auto name = "__swift_async_resume_project_context";
// This is effectively an outlined function with `alwaysinline`. Don't emit
// debug locations for those to avoid creating unnecessary inlined frames.
// Instead, rely on the inliner to propagate the call site debug location.
const bool skipDebugInfo = true;
auto Fn = cast<llvm::Function>(IGM.getOrCreateHelperFunction(
name, IGM.Int8PtrTy, {IGM.Int8PtrTy},
[&](IRGenFunction &IGF) {
Expand All @@ -2860,7 +2861,7 @@ llvm::Function *IRGenFunction::getOrCreateResumePrjFn(bool forPrologue) {
auto callerContext = IGF.emitAsyncResumeProjectContext(addr);
Builder.CreateRet(callerContext);
},
false /*isNoInline*/, forPrologue));
false /*isNoInline*/, skipDebugInfo));
Fn->addFnAttr(llvm::Attribute::AlwaysInline);
return Fn;
}
Expand Down Expand Up @@ -2899,9 +2900,6 @@ IRGenFunction::createAsyncDispatchFn(const FunctionPointer &fnPtr,
dispatch->setDoesNotThrow();
dispatch->addFnAttr(llvm::Attribute::AlwaysInline);
IRGenFunction dispatchIGF(IGM, dispatch);
// Don't emit debug info if we are generating a function for the prologue.
if (IGM.DebugInfo && Builder.getCurrentDebugLocation())
IGM.DebugInfo->emitOutlinedFunction(dispatchIGF, dispatch, CurFn->getName());
auto &Builder = dispatchIGF.Builder;
auto it = dispatchIGF.CurFn->arg_begin(), end = dispatchIGF.CurFn->arg_end();
llvm::Value *fnPtrArg = &*(it++);
Expand Down Expand Up @@ -2958,7 +2956,7 @@ llvm::Function *IRGenFunction::getOrCreateResumeFromSuspensionFn() {
auto &Builder = IGF.Builder;
Builder.CreateRet(&*IGF.CurFn->arg_begin());
},
false /*isNoInline*/));
false /*isNoInline*/, true /*forPrologue*/));
fn->addFnAttr(llvm::Attribute::AlwaysInline);
return fn;
}
Expand Down Expand Up @@ -2987,9 +2985,6 @@ llvm::Function *IRGenFunction::createAsyncSuspendFn() {
suspendFn->setDoesNotThrow();
suspendFn->addFnAttr(llvm::Attribute::AlwaysInline);
IRGenFunction suspendIGF(IGM, suspendFn);
if (IGM.DebugInfo)
IGM.DebugInfo->emitOutlinedFunction(suspendIGF, suspendFn,
CurFn->getName());
auto &Builder = suspendIGF.Builder;

llvm::Value *resumeFunction = suspendFn->getArg(0);
Expand Down
2 changes: 1 addition & 1 deletion lib/IRGen/IRGenFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ class IRGenFunction {
bool restoreCurrentContext = true);

llvm::Value *emitAsyncResumeProjectContext(llvm::Value *callerContextAddr);
llvm::Function *getOrCreateResumePrjFn(bool forPrologue = false);
llvm::Function *getOrCreateResumePrjFn();
llvm::Function *createAsyncDispatchFn(const FunctionPointer &fnPtr,
ArrayRef<llvm::Value *> args);
llvm::Function *createAsyncDispatchFn(const FunctionPointer &fnPtr,
Expand Down
53 changes: 53 additions & 0 deletions test/DebugInfo/async-await-no-debug-info-outlined-funcs.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// RUN: %target-swift-frontend %s -emit-irgen -g -o - \
// RUN: -module-name M -disable-availability-checking \
// RUN: -parse-as-library | %FileCheck %s --check-prefix=CHECK

// REQUIRES: concurrency

// Check that all the helper "outlined" functions do not have debug information.

func ASYNC___1___() async -> Int {
return 42
}

func ASYNC___2___() async -> Int {
print("hello")
var x = await ASYNC___1___()
x += await ASYNC___1___()
return x
}

// CHECK-LABEL: define {{.*}} @"$s1M12ASYNC___1___SiyYaF.0"
// CHECK-NOT: !dbg
// CHECK: ret void
// CHECK-NEXT: }

// CHECK-LABEL: define {{.*}} @__swift_async_resume_get_context
// CHECK-NOT: !dbg
// CHECK: ret ptr
// CHECK-NEXT: }

// CHECK-LABEL: define {{.*}} @"$s1M12ASYNC___2___SiyYaF.1"
// CHECK-NOT: !dbg
// CHECK: ret void
// CHECK-NEXT: }

// CHECK-LABEL: define {{.*}} @__swift_async_resume_project_context
// CHECK-NOT: !dbg
// CHECK: ret ptr
// CHECK-NEXT: }

// CHECK-LABEL: define {{.*}} @"$s1M12ASYNC___2___SiyYaF.0"
// CHECK-NOT: !dbg
// CHECK: ret void
// CHECK-NEXT: }

// CHECK-LABEL: define {{.*}} @"$s1M12ASYNC___2___SiyYaF.0.1"
// CHECK-NOT: !dbg
// CHECK: ret void
// CHECK-NEXT: }

// CHECK-LABEL: define {{.*}} @"$s1M12ASYNC___2___SiyYaF.0.2"
// CHECK-NOT: !dbg
// CHECK: ret void
// CHECK-NEXT: }
3 changes: 1 addition & 2 deletions test/IRGen/async/get_async_continuation.sil
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,10 @@ bb0:
// CHECK: {{musttail call swifttailcc|tail call swiftcc}} void @swift_continuation_await(ptr %0)
// CHECK-NEXT: ret void

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

sil @async_continuation : $@async () -> () {
entry:
Expand Down