llvm.org GIT mirror llvm / 6fe089f
[PM] Flesh out the new pass manager LTO pipeline. Differential Revision: https://reviews.llvm.org/D28996 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292863 91177308-0d34-0410-b5e6-96231b3b80d8 Davide Italiano 2 years ago
3 changed file(s) with 265 addition(s) and 14 deletion(s). Raw diff Collapse all Expand all
546546 assert(Level != O0 && "Must request optimizations for the default pipeline!");
547547 ModulePassManager MPM(DebugLogging);
548548
549 // FIXME: Finish fleshing this out to match the legacy LTO pipelines.
550 FunctionPassManager LateFPM(DebugLogging);
551 LateFPM.addPass(InstCombinePass());
552 LateFPM.addPass(SimplifyCFGPass());
553
554 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(LateFPM)));
555
549 // Remove unused virtual tables to improve the quality of code generated by
550 // whole-program devirtualization and bitset lowering.
551 MPM.addPass(GlobalDCEPass());
552
553 // Force any function attributes we want the rest of the pipeline to observe.
554 MPM.addPass(ForceFunctionAttrsPass());
555
556 // Do basic inference of function attributes from known properties of system
557 // libraries and other oracles.
558 MPM.addPass(InferFunctionAttrsPass());
559
560 if (Level > 1) {
561 // Indirect call promotion. This should promote all the targets that are
562 // left by the earlier promotion pass that promotes intra-module targets.
563 // This two-step promotion is to save the compile time. For LTO, it should
564 // produce the same result as if we only do promotion here.
565 MPM.addPass(PGOIndirectCallPromotion(true /* InLTO */));
566
567 // Propagate constants at call sites into the functions they call. This
568 // opens opportunities for globalopt (and inlining) by substituting function
569 // pointers passed as arguments to direct uses of functions.
570 MPM.addPass(IPSCCPPass());
571 }
572
573 // Now deduce any function attributes based in the current code.
574 MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(
575 PostOrderFunctionAttrsPass()));
576
577 // Do RPO function attribute inference across the module to forward-propagate
578 // attributes where applicable.
579 // FIXME: Is this really an optimization rather than a canonicalization?
580 MPM.addPass(ReversePostOrderFunctionAttrsPass());
581
582 // Use inragne annotations on GEP indices to split globals where beneficial.
583 MPM.addPass(GlobalSplitPass());
584
585 // Run whole program optimization of virtual call when the list of callees
586 // is fixed.
587 MPM.addPass(WholeProgramDevirtPass());
588
589 // Stop here at -O1.
590 if (Level == 1)
591 return MPM;
592
593 // Optimize globals to try and fold them into constants.
594 MPM.addPass(GlobalOptPass());
595
596 // Promote any localized globals to SSA registers.
597 MPM.addPass(createModuleToFunctionPassAdaptor(PromotePass()));
598
599 // Linking modules together can lead to duplicate global constant, only
600 // keep one copy of each constant.
601 MPM.addPass(ConstantMergePass());
602
603 // Remove unused arguments from functions.
604 MPM.addPass(DeadArgumentEliminationPass());
605
606 // Reduce the code after globalopt and ipsccp. Both can open up significant
607 // simplification opportunities, and both can propagate functions through
608 // function pointers. When this happens, we often have to resolve varargs
609 // calls, etc, so let instcombine do this.
610 // FIXME: add peephole extensions here as the legacy PM does.
611 MPM.addPass(createModuleToFunctionPassAdaptor(InstCombinePass()));
612
613 // Note: historically, the PruneEH pass was run first to deduce nounwind and
614 // generally clean up exception handling overhead. It isn't clear this is
615 // valuable as the inliner doesn't currently care whether it is inlining an
616 // invoke or a call.
617 // Run the inliner now.
618 MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(InlinerPass()));
619
620 // Optimize globals again after we ran the inliner.
621 MPM.addPass(GlobalOptPass());
622
623 // Garbage collect dead functions.
624 // FIXME: Add ArgumentPromotion pass after once it's ported.
625 MPM.addPass(GlobalDCEPass());
626
627 FunctionPassManager FPM(DebugLogging);
628
629 // The IPO Passes may leave cruft around. Clean up after them.
630 // FIXME: add peephole extensions here as the legacy PM does.
631 FPM.addPass(InstCombinePass());
632 FPM.addPass(JumpThreadingPass());
633
634 // Break up allocas
635 FPM.addPass(SROA());
636
637 // Run a few AA driver optimizations here and now to cleanup the code.
638 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
639
640 MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(
641 PostOrderFunctionAttrsPass()));
642 // FIXME: here we run IP alias analysis in the legacy PM.
643
644 FunctionPassManager MainFPM;
645
646 // FIXME: once we fix LoopPass Manager, add LICM here.
647 // FIXME: once we provide support for enabling MLSM, add it here.
648 // FIXME: once we provide support for enabling NewGVN, add it here.
649 MainFPM.addPass(GVN());
650
651 // Remove dead memcpy()'s.
652 MainFPM.addPass(MemCpyOptPass());
653
654 // Nuke dead stores.
655 MainFPM.addPass(DSEPass());
656
657 // FIXME: at this point, we run a bunch of loop passes:
658 // indVarSimplify, loopDeletion, loopInterchange, loopUnrool,
659 // loopVectorize. Enable them once the remaining issue with LPM
660 // are sorted out.
661
662 MainFPM.addPass(InstCombinePass());
663 MainFPM.addPass(SimplifyCFGPass());
664 MainFPM.addPass(SCCPPass());
665 MainFPM.addPass(InstCombinePass());
666 MainFPM.addPass(BDCEPass());
667
668 // FIXME: We may want to run SLPVectorizer here.
669 // After vectorization, assume intrinsics may tell us more
670 // about pointer alignments.
671 #if 0
672 MainFPM.add(AlignmentFromAssumptionsPass());
673 #endif
674
675 // FIXME: Conditionally run LoadCombine here, after it's ported
676 // (in case we still have this pass, given its questionable usefulness).
677
678 // FIXME: add peephole extensions to the PM here.
679 MainFPM.addPass(InstCombinePass());
680 MainFPM.addPass(JumpThreadingPass());
681 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(MainFPM)));
682
683 // Create a function that performs CFI checks for cross-DSO calls with
684 // targets in the current module.
685 MPM.addPass(CrossDSOCFIPass());
686
687 // Lower type metadata and the type.test intrinsic. This pass supports
688 // clang's control flow integrity mechanisms (-fsanitize=cfi*) and needs
689 // to be run at link time if CFI is enabled. This pass does nothing if
690 // CFI is disabled.
691 // Enable once we add support for the summary in the new PM.
692 #if 0
693 MPM.addPass(LowerTypeTestsPass(Summary ? LowerTypeTestsSummaryAction::Export :
694 LowerTypeTestsSummaryAction::None,
695 Summary));
696 #endif
697
698 // Add late LTO optimization passes.
699 // Delete basic blocks, which optimization passes may have killed.
700 MPM.addPass(createModuleToFunctionPassAdaptor(SimplifyCFGPass()));
701
702 // Drop bodies of available eternally objects to improve GlobalDCE.
703 MPM.addPass(EliminateAvailableExternallyPass());
704
705 // Now that we have optimized the program, discard unreachable functions.
706 MPM.addPass(GlobalDCEPass());
707
708 // FIXME: Enable MergeFuncs, conditionally, after ported, maybe.
556709 return MPM;
557710 }
558711
381381 ; RUN: | FileCheck %s --check-prefix=CHECK-O0
382382 ; CHECK-O0: Starting llvm::Module pass manager run
383383 ; CHECK-O0-NEXT: Finished llvm::Module pass manager run
384
385 ; RUN: opt -disable-output -disable-verify -debug-pass-manager \
386 ; RUN: -passes='lto' %s 2>&1 \
387 ; RUN: | FileCheck %s --check-prefix=CHECK-LTO-O2
388 ; CHECK-LTO-O2: Starting llvm::Module pass manager run
389 ; CHECK-LTO-O2: Running pass: InstCombinePass
390 ; CHECK-LTO-O2: Running pass: SimplifyCFGPass
391384
392385 ; RUN: opt -disable-output -disable-verify -debug-pass-manager \
393386 ; RUN: -passes='repeat<3>(no-op-module)' %s 2>&1 \
0 ; Basic test for the new LTO pipeline.
1 ; For now the only difference is between -O1 and everything else, so
2 ; -O2, -O3, -Os, -Oz are the same.
3
4 ; RUN: opt -disable-verify -debug-pass-manager \
5 ; RUN: -passes='lto' -S %s 2>&1 \
6 ; RUN: | FileCheck %s --check-prefix=CHECK-O
7 ; RUN: opt -disable-verify -debug-pass-manager \
8 ; RUN: -passes='lto' -S %s 2>&1 \
9 ; RUN: | FileCheck %s --check-prefix=CHECK-O --check-prefix=CHECK-O2
10 ; RUN: opt -disable-verify -debug-pass-manager \
11 ; RUN: -passes='lto' -S %s 2>&1 \
12 ; RUN: | FileCheck %s --check-prefix=CHECK-O --check-prefix=CHECK-O2
13 ; RUN: opt -disable-verify -debug-pass-manager \
14 ; RUN: -passes='lto' -S %s 2>&1 \
15 ; RUN: | FileCheck %s --check-prefix=CHECK-O --check-prefix=CHECK-O2
16 ; RUN: opt -disable-verify -debug-pass-manager \
17 ; RUN: -passes='lto' -S %s 2>&1 \
18 ; RUN: | FileCheck %s --check-prefix=CHECK-O --check-prefix=CHECK-O2
19
20 ; CHECK-O: Starting llvm::Module pass manager run.
21 ; CHECK-O-NEXT: Running pass: PassManager
22 ; CHECK-O-NEXT: Starting llvm::Module pass manager run.
23 ; CHECK-O-NEXT: Running pass: GlobalDCEPass
24 ; CHECK-O-NEXT: Running pass: ForceFunctionAttrsPass
25 ; CHECK-O-NEXT: Running pass: InferFunctionAttrsPass
26 ; CHECK-O-NEXT: Running analysis: TargetLibraryAnalysis
27 ; CHECK-O2-NEXT: PGOIndirectCallPromotion
28 ; CHECK-O2-NEXT: Running pass: IPSCCPPass
29 ; CHECK-O-NEXT: Running pass: ModuleToPostOrderCGSCCPassAdaptor
30 ; CHECK-O-NEXT: Running analysis: InnerAnalysisManagerProxy, llvm::Module>
31 ; CHECK-O-NEXT: Running analysis: InnerAnalysisManagerProxy, llvm::Module>
32 ; CHECK-O-NEXT: Running analysis: LazyCallGraphAnalysis
33 ; CHECK-O-NEXT: Running analysis: FunctionAnalysisManagerCGSCCProxy
34 ; CHECK-O-NEXT: Running analysis: OuterAnalysisManagerProxy, llvm::LazyCallGraph::SCC>
35 ; CHECK-O-NEXT: Running analysis: AAManager
36 ; CHECK-O-NEXT: Running analysis: TargetLibraryAnalysis
37 ; CHECK-O-NEXT: Running pass: ReversePostOrderFunctionAttrsPass
38 ; CHECK-O-NEXT: Running analysis: CallGraphAnalysis
39 ; CHECK-O-NEXT: Invalidating analysis: CallGraphAnalysis
40 ; CHECK-O-NEXT: Running pass: GlobalSplitPass
41 ; CHECK-O-NEXT: Running pass: WholeProgramDevirtPass
42 ; CHECK-O2-NEXT: Running pass: GlobalOptPass
43 ; CHECK-O2-NEXT: Running pass: ModuleToFunctionPassAdaptor
44 ; CHECK-O2-NEXT: Running analysis: DominatorTreeAnalysis
45 ; CHECK-O2-NEXT: Running analysis: AssumptionAnalysis
46 ; CHECK-O2-NEXT: Running pass: ConstantMergePass
47 ; CHECK-O2-NEXT: Running pass: DeadArgumentEliminationPass
48 ; CHECK-O2-NEXT: Running pass: ModuleToFunctionPassAdaptor
49 ; CHECK-O2-NEXT: Running pass: ModuleToPostOrderCGSCCPassAdaptor
50 ; CHECK-O2-NEXT: Running analysis: OptimizationRemarkEmitterAnalysis
51 ; CHECK-O2-NEXT: Running pass: GlobalOptPass
52 ; CHECK-O2-NEXT: Running pass: GlobalDCEPass
53 ; CHECK-O2-NEXT: Running pass: ModuleToFunctionPassAdaptor >
54 ; CHECK-O2-NEXT: Starting llvm::Function pass manager run.
55 ; CHECK-O2-NEXT: Running pass: InstCombinePass
56 ; CHECK-O2-NEXT: Running pass: JumpThreadingPass
57 ; CHECK-O2-NEXT: Running analysis: LazyValueAnalysis
58 ; CHECK-O2-NEXT: Invalidating analysis: LazyValueAnalysis
59 ; CHECK-O2-NEXT: Running pass: SROA on foo
60 ; CHECK-O2-NEXT: Finished llvm::Function pass manager run.
61 ; CHECK-O2-NEXT: Running pass: ModuleToPostOrderCGSCCPassAdaptor
62 ; CHECK-O2-NEXT: Running pass: ModuleToFunctionPassAdaptor >
63 ; CHECK-O2-NEXT: Running analysis: MemoryDependenceAnalysis
64 ; CHECK-O2-NEXT: Running analysis: TargetIRAnalysis
65 ; CHECK-O2-NEXT: Running analysis: DemandedBitsAnalysis
66 ; CHECK-O2-NEXT: Running analysis: LazyValueAnalysis
67 ; CHECK-O2-NEXT: Invalidating analysis: LazyValueAnalysis
68 ; CHECK-O2-NEXT: Running pass: CrossDSOCFIPass
69 ; CHECK-O2-NEXT: Running pass: ModuleToFunctionPassAdaptor
70 ; CHECK-O2-NEXT: Running pass: EliminateAvailableExternallyPass
71 ; CHECK-O2-NEXT: Running pass: GlobalDCEPass
72 ; CHECK-O-NEXT: Finished llvm::Module pass manager run.
73 ; CHECK-O-NEXT: Running pass: PrintModulePass
74
75 ; Make sure we get the IR back out without changes when we print the module.
76 ; CHECK-O-LABEL: define void @foo(i32 %n) local_unnamed_addr {
77 ; CHECK-O-NEXT: entry:
78 ; CHECK-O-NEXT: br label %loop
79 ; CHECK-O: loop:
80 ; CHECK-O-NEXT: %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop ]
81 ; CHECK-O-NEXT: %iv.next = add i32 %iv, 1
82 ; CHECK-O-NEXT: tail call void @bar()
83 ; CHECK-O-NEXT: %cmp = icmp eq i32 %iv, %n
84 ; CHECK-O-NEXT: br i1 %cmp, label %exit, label %loop
85 ; CHECK-O: exit:
86 ; CHECK-O-NEXT: ret void
87 ; CHECK-O-NEXT: }
88 ;
89 ; CHECK-O-NEXT: Finished llvm::Module pass manager run.
90
91 declare void @bar() local_unnamed_addr
92
93 define void @foo(i32 %n) local_unnamed_addr {
94 entry:
95 br label %loop
96 loop:
97 %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop ]
98 %iv.next = add i32 %iv, 1
99 tail call void @bar()
100 %cmp = icmp eq i32 %iv, %n
101 br i1 %cmp, label %exit, label %loop
102 exit:
103 ret void
104 }