From bc81d231027c6540ed12305d7bf88aa2b647c188 Mon Sep 17 00:00:00 2001 From: Arnold Schwaighofer Date: Sat, 7 Oct 2023 07:26:38 -0700 Subject: [PATCH] IRGen: Mark async intrinsic helper functions as always inline github.com/apple/swift/issues/68708 rdar://115905828 --- lib/IRGen/GenFunc.cpp | 6 +++++- lib/IRGen/IRGen.cpp | 2 ++ test/DebugInfo/async-let.swift | 8 ++++---- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/IRGen/GenFunc.cpp b/lib/IRGen/GenFunc.cpp index 9a003eea85117..5c08a5a944a23 100644 --- a/lib/IRGen/GenFunc.cpp +++ b/lib/IRGen/GenFunc.cpp @@ -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()) @@ -2581,13 +2582,15 @@ void IRGenFunction::emitSuspensionPoint(Explosion &toExecutor, llvm::Function *IRGenFunction::getOrCreateResumeFromSuspensionFn() { auto name = "__swift_async_resume_get_context"; - return cast(IGM.getOrCreateHelperFunction( + auto fn = cast(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() { @@ -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, diff --git a/lib/IRGen/IRGen.cpp b/lib/IRGen/IRGen.cpp index 75ac1445794a6..0f5315ff42fff 100644 --- a/lib/IRGen/IRGen.cpp +++ b/lib/IRGen/IRGen.cpp @@ -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()); }); } diff --git a/test/DebugInfo/async-let.swift b/test/DebugInfo/async-let.swift index 627397b2d0259..835f3a23260c4 100644 --- a/test/DebugInfo/async-let.swift +++ b/test/DebugInfo/async-let.swift @@ -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