Skip to content

Commit

Permalink
IRGen: Mark async intrinsic helper functions as always inline
Browse files Browse the repository at this point in the history
github.com/swiftlang/issues/68708
rdar://115905828
  • Loading branch information
aschwaighofer committed Feb 6, 2024
1 parent f98b211 commit bc81d23
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
6 changes: 5 additions & 1 deletion lib/IRGen/GenFunc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2529,6 +2529,7 @@ IRGenFunction::createAsyncDispatchFn(const FunctionPointer &fnPtr,
llvm::StringRef(name), &IGM.Module);
dispatch->setCallingConv(IGM.SwiftAsyncCC);
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())
Expand Down Expand Up @@ -2581,13 +2582,15 @@ void IRGenFunction::emitSuspensionPoint(Explosion &toExecutor,

llvm::Function *IRGenFunction::getOrCreateResumeFromSuspensionFn() {
auto name = "__swift_async_resume_get_context";
return cast<llvm::Function>(IGM.getOrCreateHelperFunction(
auto fn = cast<llvm::Function>(IGM.getOrCreateHelperFunction(
name, IGM.Int8PtrTy, {IGM.Int8PtrTy},
[&](IRGenFunction &IGF) {
auto &Builder = IGF.Builder;
Builder.CreateRet(&*IGF.CurFn->arg_begin());
},
false /*isNoInline*/));
fn->addFnAttr(llvm::Attribute::AlwaysInline);
return fn;
}

llvm::Function *IRGenFunction::createAsyncSuspendFn() {
Expand All @@ -2612,6 +2615,7 @@ llvm::Function *IRGenFunction::createAsyncSuspendFn() {
name, &IGM.Module);
suspendFn->setCallingConv(IGM.SwiftAsyncCC);
suspendFn->setDoesNotThrow();
suspendFn->addFnAttr(llvm::Attribute::AlwaysInline);
IRGenFunction suspendIGF(IGM, suspendFn);
if (IGM.DebugInfo)
IGM.DebugInfo->emitOutlinedFunction(suspendIGF, suspendFn,
Expand Down
2 changes: 2 additions & 0 deletions lib/IRGen/IRGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@ void swift::performLLVMOptimizations(const IRGenOptions &Opts,
OptimizationLevel Level) {
if (Level != OptimizationLevel::O0)
MPM.addPass(createModuleToFunctionPassAdaptor(SwiftARCContractPass()));
if (Level == OptimizationLevel::O0)
MPM.addPass(AlwaysInlinerPass());
});
}

Expand Down
8 changes: 4 additions & 4 deletions test/DebugInfo/async-let.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ public actor Alice {
let bob = Bob()

// CHECK: define {{.*}}$s1M5AliceC4callyyYaFTY0_{{.*}} !dbg ![[SCOPE0:[0-9]+]]
// CHECK: call ptr @__swift_async_resume_get_context{{.*}}!dbg ![[HOP0:[0-9]+]]
// CHECK: load ptr, ptr {{.*}} !dbg ![[HOP0:[0-9]+]]

// CHECK: define {{.*}}$s1M5AliceC4callyyYaFTY1_{{.*}} !dbg ![[SCOPE1:[0-9]+]]
// CHECK: call ptr @__swift_async_resume_get_context{{.*}}!dbg ![[HOP1:[0-9]+]]
// CHECK: load ptr, ptr {{.*}} !dbg ![[HOP1:[0-9]+]]

// CHECK: define {{.*}}$s1M5AliceC4callyyYaFSiyYaYbcfu_TY0_{{.*}} !dbg ![[LET_SCOPE0:[0-9]+]]
// CHECK: call ptr @__swift_async_resume_get_context{{.*}}!dbg ![[LET_HOP0:[0-9]+]]
// CHECK: load ptr, ptr {{.*}} !dbg ![[LET_HOP0:[0-9]+]]

// CHECK: define {{.*}}$s1M5AliceC4callyyYaFSiyYaYbcfu_TY2_{{.*}} !dbg ![[LET_SCOPE1:[0-9]+]]
// CHECK: call ptr @__swift_async_resume_get_context{{.*}}!dbg ![[LET_HOP1:[0-9]+]]
// CHECK: load ptr, ptr {{.*}} !dbg ![[LET_HOP1:[0-9]+]]
public func call() async {
// CHECK: ![[SCOPE0]] = distinct !DISubprogram({{.*}}line: [[@LINE-1]]
// CHECK: ![[HOP0]] = !DILocation(line: [[@LINE-2]], column: 15
Expand Down

0 comments on commit bc81d23

Please sign in to comment.