Skip to content
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

IRGen: Mark async intrinsic helper functions as always inline #71414

Merged
merged 1 commit into from
Feb 8, 2024
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
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());
Copy link
Contributor

@felipepiovezan felipepiovezan Feb 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure this (the instance added by this PR) is the only place the alwaysinline attribute is used? Because by adding an optimization pass at O0 we might be changing more than what we intended to change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default O0 llvm pass pipeline runs the AlwaysInlinerPass. Unfortunately just to early for our purposes i.e before Coro splitting.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, thanks for the clarification!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, at least as far as debugging is concerned, inlining is a 100% "reversible" operation, i.e., it should be transparent in the debugger.

});
}

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