Skip to content

Commit 61326af

Browse files
Merge pull request #71414 from aschwaighofer/coro_noinline
IRGen: Mark async intrinsic helper functions as always inline
2 parents 8621508 + bc81d23 commit 61326af

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

lib/IRGen/GenFunc.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2529,6 +2529,7 @@ IRGenFunction::createAsyncDispatchFn(const FunctionPointer &fnPtr,
25292529
llvm::StringRef(name), &IGM.Module);
25302530
dispatch->setCallingConv(IGM.SwiftAsyncCC);
25312531
dispatch->setDoesNotThrow();
2532+
dispatch->addFnAttr(llvm::Attribute::AlwaysInline);
25322533
IRGenFunction dispatchIGF(IGM, dispatch);
25332534
// Don't emit debug info if we are generating a function for the prologue.
25342535
if (IGM.DebugInfo && Builder.getCurrentDebugLocation())
@@ -2581,13 +2582,15 @@ void IRGenFunction::emitSuspensionPoint(Explosion &toExecutor,
25812582

25822583
llvm::Function *IRGenFunction::getOrCreateResumeFromSuspensionFn() {
25832584
auto name = "__swift_async_resume_get_context";
2584-
return cast<llvm::Function>(IGM.getOrCreateHelperFunction(
2585+
auto fn = cast<llvm::Function>(IGM.getOrCreateHelperFunction(
25852586
name, IGM.Int8PtrTy, {IGM.Int8PtrTy},
25862587
[&](IRGenFunction &IGF) {
25872588
auto &Builder = IGF.Builder;
25882589
Builder.CreateRet(&*IGF.CurFn->arg_begin());
25892590
},
25902591
false /*isNoInline*/));
2592+
fn->addFnAttr(llvm::Attribute::AlwaysInline);
2593+
return fn;
25912594
}
25922595

25932596
llvm::Function *IRGenFunction::createAsyncSuspendFn() {
@@ -2612,6 +2615,7 @@ llvm::Function *IRGenFunction::createAsyncSuspendFn() {
26122615
name, &IGM.Module);
26132616
suspendFn->setCallingConv(IGM.SwiftAsyncCC);
26142617
suspendFn->setDoesNotThrow();
2618+
suspendFn->addFnAttr(llvm::Attribute::AlwaysInline);
26152619
IRGenFunction suspendIGF(IGM, suspendFn);
26162620
if (IGM.DebugInfo)
26172621
IGM.DebugInfo->emitOutlinedFunction(suspendIGF, suspendFn,

lib/IRGen/IRGen.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,8 @@ void swift::performLLVMOptimizations(const IRGenOptions &Opts,
263263
OptimizationLevel Level) {
264264
if (Level != OptimizationLevel::O0)
265265
MPM.addPass(createModuleToFunctionPassAdaptor(SwiftARCContractPass()));
266+
if (Level == OptimizationLevel::O0)
267+
MPM.addPass(AlwaysInlinerPass());
266268
});
267269
}
268270

test/DebugInfo/async-let.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ public actor Alice {
88
let bob = Bob()
99

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

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

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

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

0 commit comments

Comments
 (0)