Skip to content

[LTO][Pipelines][Coro] Handle coroutines in LTO pipeline #126168

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 8 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
13 changes: 12 additions & 1 deletion llvm/lib/Passes/PassBuilderPipelines.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1816,6 +1816,8 @@ PassBuilder::buildLTODefaultPipeline(OptimizationLevel Level,
// in the current module.
MPM.addPass(CrossDSOCFIPass());

MPM.addPass(CoroEarlyPass());

if (Level == OptimizationLevel::O0) {
// The WPD and LowerTypeTest passes need to run at -O0 to lower type
// metadata and intrinsics.
Expand All @@ -1825,6 +1827,7 @@ PassBuilder::buildLTODefaultPipeline(OptimizationLevel Level,
// in ICP.
MPM.addPass(LowerTypeTestsPass(nullptr, nullptr,
lowertypetests::DropTestKind::Assume));
MPM.addPass(CoroCleanupPass());

invokeFullLinkTimeOptimizationLastEPCallbacks(MPM, Level);

Expand Down Expand Up @@ -1910,6 +1913,8 @@ PassBuilder::buildLTODefaultPipeline(OptimizationLevel Level,
MPM.addPass(LowerTypeTestsPass(nullptr, nullptr,
lowertypetests::DropTestKind::Assume));

MPM.addPass(CoroCleanupPass());

invokeFullLinkTimeOptimizationLastEPCallbacks(MPM, Level);

// Emit annotation remarks.
Expand Down Expand Up @@ -1983,7 +1988,11 @@ PassBuilder::buildLTODefaultPipeline(OptimizationLevel Level,

// If we didn't decide to inline a function, check to see if we can
// transform it to pass arguments by value instead of by reference.
MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(ArgumentPromotionPass()));
CGSCCPassManager CGPM;
CGPM.addPass(ArgumentPromotionPass());
CGPM.addPass(CoroSplitPass(Level != OptimizationLevel::O0));
CGPM.addPass(CoroAnnotationElidePass());
MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(std::move(CGPM)));

FunctionPassManager FPM;
// The IPO Passes may leave cruft around. Clean up after them.
Expand Down Expand Up @@ -2135,6 +2144,8 @@ PassBuilder::buildLTODefaultPipeline(OptimizationLevel Level,
if (PTO.CallGraphProfile)
MPM.addPass(CGProfilePass(/*InLTOPostLink=*/true));

MPM.addPass(CoroCleanupPass());

invokeFullLinkTimeOptimizationLastEPCallbacks(MPM, Level);

// Emit annotation remarks.
Expand Down
21 changes: 21 additions & 0 deletions llvm/test/LTO/X86/coro.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
; RUN: llvm-as %s -o %t1.bc
; RUN: llvm-lto2 run %t1.bc -o %t2.o -r=%t1.bc,test,plx -r=%t1.bc,extern_func,plx -save-temps
; RUN: llvm-dis %t2.o.0.5.precodegen.bc -o - | FileCheck %s --implicit-check-not="call void @llvm.coro"

target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-fuchsia"

declare void @extern_func()

; CHECK: define {{.*}} void @test(
define void @test(ptr %hdl) {
call void @llvm.coro.resume(ptr %hdl)
call void @llvm.coro.destroy(ptr %hdl)
call i1 @llvm.coro.done(ptr %hdl)
ret void
}

declare void @llvm.coro.resume(ptr)
declare void @llvm.coro.destroy(ptr)
declare i1 @llvm.coro.done(ptr)

2 changes: 2 additions & 0 deletions llvm/test/Other/new-pm-O0-defaults.ll
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,14 @@
; CHECK-THINLTO-NEXT: Running pass: EliminateAvailableExternallyPass
; CHECK-THINLTO-NEXT: Running pass: GlobalDCEPass
; CHECK-LTO: Running pass: CrossDSOCFIPass on [module]
; CHECK-LTO-NEXT: CoroEarlyPass
; CHECK-LTO-NEXT: Running pass: WholeProgramDevirtPass
; CHECK-LTO-NEXT: Running analysis: InnerAnalysisManagerProxy
; CHECK-LTO-NEXT: Running pass: LowerTypeTestsPass
; CHECK-LTO-NEXT: Running pass: LowerTypeTestsPass
; CHECK-CORO-NEXT: Running pass: AnnotationRemarksPass
; CHECK-CORO-NEXT: Running analysis: TargetLibraryAnalysis
; CHECK-LTO-NEXT: CoroCleanupPass
; CHECK-LTO-NEXT: Running pass: AnnotationRemarksPass
; CHECK-LTO-NEXT: Running analysis: TargetLibraryAnalysis
; CHECK-NEXT: Running pass: PrintModulePass
Expand Down
4 changes: 4 additions & 0 deletions llvm/test/Other/new-pm-lto-defaults.ll
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

; CHECK-EP: Running pass: NoOpModulePass
; CHECK-O: Running pass: CrossDSOCFIPass
; CHECK-O-NEXT: CoroEarlyPass
; CHECK-O-NEXT: Running pass: OpenMPOptPass
; CHECK-O-NEXT: Running pass: GlobalDCEPass
; CHECK-O-NEXT: Running pass: InferFunctionAttrsPass
Expand Down Expand Up @@ -86,6 +87,8 @@
; CHECK-O23SZ-NEXT: Running pass: OpenMPOptPass
; CHECK-O23SZ-NEXT: Running pass: GlobalDCEPass
; CHECK-O23SZ-NEXT: Running pass: ArgumentPromotionPass
; CHECK-O23SZ-NEXT: CoroSplitPass on (foo)
; CHECK-O23SZ-NEXT: CoroAnnotationElidePass on (foo)
; CHECK-O23SZ-NEXT: Running pass: InstCombinePass
; CHECK-EP-PEEPHOLE-NEXT: Running pass: NoOpFunctionPass
; CHECK-O23SZ-NEXT: Running pass: ConstraintEliminationPass
Expand Down Expand Up @@ -156,6 +159,7 @@
; CHECK-O23SZ-NEXT: Running pass: GlobalDCEPass
; CHECK-O23SZ-NEXT: Running pass: RelLookupTableConverterPass
; CHECK-O23SZ-NEXT: Running pass: CGProfilePass
; CHECK-O-NEXT: CoroCleanupPass
; CHECK-EP-NEXT: Running pass: NoOpModulePass
; CHECK-O-NEXT: Running pass: AnnotationRemarksPass on foo
; CHECK-O-NEXT: Running pass: PrintModulePass
Expand Down