LLVM 22.0.0git
PassBuilderPipelines.cpp
Go to the documentation of this file.
1//===- Construction of pass pipelines -------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8/// \file
9///
10/// This file provides the implementation of the PassBuilder based on our
11/// static pass registry as well as related functionality. It also provides
12/// helpers to aid in analyzing, debugging, and testing passes and pass
13/// pipelines.
14///
15//===----------------------------------------------------------------------===//
16
17#include "llvm/ADT/Statistic.h"
27#include "llvm/IR/PassManager.h"
28#include "llvm/Pass.h"
150
151using namespace llvm;
152
153namespace llvm {
154
156 "enable-ml-inliner", cl::init(InliningAdvisorMode::Default), cl::Hidden,
157 cl::desc("Enable ML policy for inliner. Currently trained for -Oz only"),
159 "Heuristics-based inliner version"),
161 "Use development mode (runtime-loadable model)"),
163 "Use release mode (AOT-compiled model)")));
164
165/// Flag to enable inline deferral during PGO.
166static cl::opt<bool>
167 EnablePGOInlineDeferral("enable-npm-pgo-inline-deferral", cl::init(true),
169 cl::desc("Enable inline deferral during PGO"));
170
171static cl::opt<bool> EnableModuleInliner("enable-module-inliner",
172 cl::init(false), cl::Hidden,
173 cl::desc("Enable module inliner"));
174
176 "mandatory-inlining-first", cl::init(false), cl::Hidden,
177 cl::desc("Perform mandatory inlinings module-wide, before performing "
178 "inlining"));
179
181 "eagerly-invalidate-analyses", cl::init(true), cl::Hidden,
182 cl::desc("Eagerly invalidate more analyses in default pipelines"));
183
185 "enable-merge-functions", cl::init(false), cl::Hidden,
186 cl::desc("Enable function merging as part of the optimization pipeline"));
187
189 "enable-post-pgo-loop-rotation", cl::init(true), cl::Hidden,
190 cl::desc("Run the loop rotation transformation after PGO instrumentation"));
191
193 "enable-global-analyses", cl::init(true), cl::Hidden,
194 cl::desc("Enable inter-procedural analyses"));
195
196static cl::opt<bool> RunPartialInlining("enable-partial-inlining",
197 cl::init(false), cl::Hidden,
198 cl::desc("Run Partial inlining pass"));
199
201 "extra-vectorizer-passes", cl::init(false), cl::Hidden,
202 cl::desc("Run cleanup optimization passes after vectorization"));
203
204static cl::opt<bool> RunNewGVN("enable-newgvn", cl::init(false), cl::Hidden,
205 cl::desc("Run the NewGVN pass"));
206
207static cl::opt<bool>
208 EnableLoopInterchange("enable-loopinterchange", cl::init(false), cl::Hidden,
209 cl::desc("Enable the LoopInterchange Pass"));
210
211static cl::opt<bool> EnableUnrollAndJam("enable-unroll-and-jam",
212 cl::init(false), cl::Hidden,
213 cl::desc("Enable Unroll And Jam Pass"));
214
215static cl::opt<bool> EnableLoopFlatten("enable-loop-flatten", cl::init(false),
217 cl::desc("Enable the LoopFlatten Pass"));
218
219// Experimentally allow loop header duplication. This should allow for better
220// optimization at Oz, since loop-idiom recognition can then recognize things
221// like memcpy. If this ends up being useful for many targets, we should drop
222// this flag and make a code generation option that can be controlled
223// independent of the opt level and exposed through the frontend.
225 "enable-loop-header-duplication", cl::init(false), cl::Hidden,
226 cl::desc("Enable loop header duplication at any optimization level"));
227
228static cl::opt<bool>
229 EnableDFAJumpThreading("enable-dfa-jump-thread",
230 cl::desc("Enable DFA jump threading"),
231 cl::init(false), cl::Hidden);
232
233static cl::opt<bool>
234 EnableHotColdSplit("hot-cold-split",
235 cl::desc("Enable hot-cold splitting pass"));
236
237static cl::opt<bool> EnableIROutliner("ir-outliner", cl::init(false),
239 cl::desc("Enable ir outliner pass"));
240
241static cl::opt<bool>
242 DisablePreInliner("disable-preinline", cl::init(false), cl::Hidden,
243 cl::desc("Disable pre-instrumentation inliner"));
244
246 "preinline-threshold", cl::Hidden, cl::init(75),
247 cl::desc("Control the amount of inlining in pre-instrumentation inliner "
248 "(default = 75)"));
249
250static cl::opt<bool>
251 EnableGVNHoist("enable-gvn-hoist",
252 cl::desc("Enable the GVN hoisting pass (default = off)"));
253
254static cl::opt<bool>
255 EnableGVNSink("enable-gvn-sink",
256 cl::desc("Enable the GVN sinking pass (default = off)"));
257
259 "enable-jump-table-to-switch",
260 cl::desc("Enable JumpTableToSwitch pass (default = off)"));
261
262// This option is used in simplifying testing SampleFDO optimizations for
263// profile loading.
264static cl::opt<bool>
265 EnableCHR("enable-chr", cl::init(true), cl::Hidden,
266 cl::desc("Enable control height reduction optimization (CHR)"));
267
269 "flattened-profile-used", cl::init(false), cl::Hidden,
270 cl::desc("Indicate the sample profile being used is flattened, i.e., "
271 "no inline hierarchy exists in the profile"));
272
273static cl::opt<bool>
274 EnableMatrix("enable-matrix", cl::init(false), cl::Hidden,
275 cl::desc("Enable lowering of the matrix intrinsics"));
276
278 "enable-constraint-elimination", cl::init(true), cl::Hidden,
279 cl::desc(
280 "Enable pass to eliminate conditions based on linear constraints"));
281
283 "attributor-enable", cl::Hidden, cl::init(AttributorRunOption::NONE),
284 cl::desc("Enable the attributor inter-procedural deduction pass"),
286 "enable all attributor runs"),
288 "enable module-wide attributor runs"),
290 "enable call graph SCC attributor runs"),
291 clEnumValN(AttributorRunOption::NONE, "none",
292 "disable attributor runs")));
293
295 "enable-sampled-instrumentation", cl::init(false), cl::Hidden,
296 cl::desc("Enable profile instrumentation sampling (default = off)"));
298 "enable-loop-versioning-licm", cl::init(false), cl::Hidden,
299 cl::desc("Enable the experimental Loop Versioning LICM pass"));
300
302 "instrument-cold-function-only-path", cl::init(""),
303 cl::desc("File path for cold function only instrumentation(requires use "
304 "with --pgo-instrument-cold-function-only)"),
305 cl::Hidden);
306
309
311} // namespace llvm
312
329
330namespace llvm {
332} // namespace llvm
333
335 OptimizationLevel Level) {
336 for (auto &C : PeepholeEPCallbacks)
337 C(FPM, Level);
338}
341 for (auto &C : LateLoopOptimizationsEPCallbacks)
342 C(LPM, Level);
343}
345 OptimizationLevel Level) {
346 for (auto &C : LoopOptimizerEndEPCallbacks)
347 C(LPM, Level);
348}
351 for (auto &C : ScalarOptimizerLateEPCallbacks)
352 C(FPM, Level);
353}
355 OptimizationLevel Level) {
356 for (auto &C : CGSCCOptimizerLateEPCallbacks)
357 C(CGPM, Level);
358}
360 OptimizationLevel Level) {
361 for (auto &C : VectorizerStartEPCallbacks)
362 C(FPM, Level);
363}
365 OptimizationLevel Level) {
366 for (auto &C : VectorizerEndEPCallbacks)
367 C(FPM, Level);
368}
370 OptimizationLevel Level,
372 for (auto &C : OptimizerEarlyEPCallbacks)
373 C(MPM, Level, Phase);
374}
376 OptimizationLevel Level,
378 for (auto &C : OptimizerLastEPCallbacks)
379 C(MPM, Level, Phase);
380}
383 for (auto &C : FullLinkTimeOptimizationEarlyEPCallbacks)
384 C(MPM, Level);
385}
388 for (auto &C : FullLinkTimeOptimizationLastEPCallbacks)
389 C(MPM, Level);
390}
392 OptimizationLevel Level) {
393 for (auto &C : PipelineStartEPCallbacks)
394 C(MPM, Level);
395}
398 for (auto &C : PipelineEarlySimplificationEPCallbacks)
399 C(MPM, Level, Phase);
400}
401
402// Helper to add AnnotationRemarksPass.
406
407// Helper to check if the current compilation phase is preparing for LTO
412
413// Helper to check if the current compilation phase is LTO backend
418
419// Helper to wrap conditionally Coro passes.
421 // TODO: Skip passes according to Phase.
422 ModulePassManager CoroPM;
423 CoroPM.addPass(CoroEarlyPass());
424 CGSCCPassManager CGPM;
425 CGPM.addPass(CoroSplitPass());
426 CoroPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(std::move(CGPM)));
427 CoroPM.addPass(CoroCleanupPass());
428 CoroPM.addPass(GlobalDCEPass());
429 return CoroConditionalWrapper(std::move(CoroPM));
430}
431
432// TODO: Investigate the cost/benefit of tail call elimination on debugging.
434PassBuilder::buildO1FunctionSimplificationPipeline(OptimizationLevel Level,
436
438
440 FPM.addPass(CountVisitsPass());
441
442 // Form SSA out of local memory accesses after breaking apart aggregates into
443 // scalars.
444 FPM.addPass(SROAPass(SROAOptions::ModifyCFG));
445
446 // Catch trivial redundancies
447 FPM.addPass(EarlyCSEPass(true /* Enable mem-ssa. */));
448
449 // Hoisting of scalars and load expressions.
450 FPM.addPass(
451 SimplifyCFGPass(SimplifyCFGOptions().convertSwitchRangeToICmp(true)));
452 FPM.addPass(InstCombinePass());
453
454 FPM.addPass(LibCallsShrinkWrapPass());
455
456 invokePeepholeEPCallbacks(FPM, Level);
457
458 FPM.addPass(
459 SimplifyCFGPass(SimplifyCFGOptions().convertSwitchRangeToICmp(true)));
460
461 // Form canonically associated expression trees, and simplify the trees using
462 // basic mathematical properties. For example, this will form (nearly)
463 // minimal multiplication trees.
464 FPM.addPass(ReassociatePass());
465
466 // Add the primary loop simplification pipeline.
467 // FIXME: Currently this is split into two loop pass pipelines because we run
468 // some function passes in between them. These can and should be removed
469 // and/or replaced by scheduling the loop pass equivalents in the correct
470 // positions. But those equivalent passes aren't powerful enough yet.
471 // Specifically, `SimplifyCFGPass` and `InstCombinePass` are currently still
472 // used. We have `LoopSimplifyCFGPass` which isn't yet powerful enough yet to
473 // fully replace `SimplifyCFGPass`, and the closest to the other we have is
474 // `LoopInstSimplify`.
475 LoopPassManager LPM1, LPM2;
476
477 // Simplify the loop body. We do this initially to clean up after other loop
478 // passes run, either when iterating on a loop or on inner loops with
479 // implications on the outer loop.
480 LPM1.addPass(LoopInstSimplifyPass());
481 LPM1.addPass(LoopSimplifyCFGPass());
482
483 // Try to remove as much code from the loop header as possible,
484 // to reduce amount of IR that will have to be duplicated. However,
485 // do not perform speculative hoisting the first time as LICM
486 // will destroy metadata that may not need to be destroyed if run
487 // after loop rotation.
488 // TODO: Investigate promotion cap for O1.
489 LPM1.addPass(LICMPass(PTO.LicmMssaOptCap, PTO.LicmMssaNoAccForPromotionCap,
490 /*AllowSpeculation=*/false));
491
492 LPM1.addPass(LoopRotatePass(/* Disable header duplication */ true,
494 // TODO: Investigate promotion cap for O1.
495 LPM1.addPass(LICMPass(PTO.LicmMssaOptCap, PTO.LicmMssaNoAccForPromotionCap,
496 /*AllowSpeculation=*/true));
497 LPM1.addPass(SimpleLoopUnswitchPass());
499 LPM1.addPass(LoopFlattenPass());
500
501 LPM2.addPass(LoopIdiomRecognizePass());
502 LPM2.addPass(IndVarSimplifyPass());
503
505
506 LPM2.addPass(LoopDeletionPass());
507
508 // Do not enable unrolling in PreLinkThinLTO phase during sample PGO
509 // because it changes IR to makes profile annotation in back compile
510 // inaccurate. The normal unroller doesn't pay attention to forced full unroll
511 // attributes so we need to make sure and allow the full unroll pass to pay
512 // attention to it.
513 if (Phase != ThinOrFullLTOPhase::ThinLTOPreLink || !PGOOpt ||
514 PGOOpt->Action != PGOOptions::SampleUse)
515 LPM2.addPass(LoopFullUnrollPass(Level.getSpeedupLevel(),
516 /* OnlyWhenForced= */ !PTO.LoopUnrolling,
517 PTO.ForgetAllSCEVInLoopUnroll));
518
520
521 FPM.addPass(createFunctionToLoopPassAdaptor(std::move(LPM1),
522 /*UseMemorySSA=*/true));
523 FPM.addPass(
524 SimplifyCFGPass(SimplifyCFGOptions().convertSwitchRangeToICmp(true)));
525 FPM.addPass(InstCombinePass());
526 // The loop passes in LPM2 (LoopFullUnrollPass) do not preserve MemorySSA.
527 // *All* loop passes must preserve it, in order to be able to use it.
528 FPM.addPass(createFunctionToLoopPassAdaptor(std::move(LPM2),
529 /*UseMemorySSA=*/false));
530
531 // Delete small array after loop unroll.
532 FPM.addPass(SROAPass(SROAOptions::ModifyCFG));
533
534 // Specially optimize memory movement as it doesn't look like dataflow in SSA.
535 FPM.addPass(MemCpyOptPass());
536
537 // Sparse conditional constant propagation.
538 // FIXME: It isn't clear why we do this *after* loop passes rather than
539 // before...
540 FPM.addPass(SCCPPass());
541
542 // Delete dead bit computations (instcombine runs after to fold away the dead
543 // computations, and then ADCE will run later to exploit any new DCE
544 // opportunities that creates).
545 FPM.addPass(BDCEPass());
546
547 // Run instcombine after redundancy and dead bit elimination to exploit
548 // opportunities opened up by them.
549 FPM.addPass(InstCombinePass());
550 invokePeepholeEPCallbacks(FPM, Level);
551
552 FPM.addPass(CoroElidePass());
553
555
556 // Finally, do an expensive DCE pass to catch all the dead code exposed by
557 // the simplifications and basic cleanup after all the simplifications.
558 // TODO: Investigate if this is too expensive.
559 FPM.addPass(ADCEPass());
560 FPM.addPass(
561 SimplifyCFGPass(SimplifyCFGOptions().convertSwitchRangeToICmp(true)));
562 FPM.addPass(InstCombinePass());
563 invokePeepholeEPCallbacks(FPM, Level);
564
565 return FPM;
566}
567
571 assert(Level != OptimizationLevel::O0 && "Must request optimizations!");
572
573 // The O1 pipeline has a separate pipeline creation function to simplify
574 // construction readability.
575 if (Level.getSpeedupLevel() == 1)
576 return buildO1FunctionSimplificationPipeline(Level, Phase);
577
579
582
583 // Form SSA out of local memory accesses after breaking apart aggregates into
584 // scalars.
586
587 // Catch trivial redundancies
588 FPM.addPass(EarlyCSEPass(true /* Enable mem-ssa. */));
591
592 // Hoisting of scalars and load expressions.
593 if (EnableGVNHoist)
594 FPM.addPass(GVNHoistPass());
595
596 // Global value numbering based sinking.
597 if (EnableGVNSink) {
598 FPM.addPass(GVNSinkPass());
599 FPM.addPass(
600 SimplifyCFGPass(SimplifyCFGOptions().convertSwitchRangeToICmp(true)));
601 }
602
603 // Speculative execution if the target has divergent branches; otherwise nop.
604 FPM.addPass(SpeculativeExecutionPass(/* OnlyIfDivergentTarget =*/true));
605
606 // Optimize based on known information about branches, and cleanup afterward.
609
610 // Jump table to switch conversion.
615
616 FPM.addPass(
617 SimplifyCFGPass(SimplifyCFGOptions().convertSwitchRangeToICmp(true)));
620
621 if (!Level.isOptimizingForSize())
623
624 invokePeepholeEPCallbacks(FPM, Level);
625
626 // For PGO use pipeline, try to optimize memory intrinsics such as memcpy
627 // using the size value profile. Don't perform this when optimizing for size.
628 if (PGOOpt && PGOOpt->Action == PGOOptions::IRUse &&
629 !Level.isOptimizingForSize())
631
632 FPM.addPass(TailCallElimPass(/*UpdateFunctionEntryCount=*/
633 isInstrumentedPGOUse()));
634 FPM.addPass(
635 SimplifyCFGPass(SimplifyCFGOptions().convertSwitchRangeToICmp(true)));
636
637 // Form canonically associated expression trees, and simplify the trees using
638 // basic mathematical properties. For example, this will form (nearly)
639 // minimal multiplication trees.
641
644
645 // Add the primary loop simplification pipeline.
646 // FIXME: Currently this is split into two loop pass pipelines because we run
647 // some function passes in between them. These can and should be removed
648 // and/or replaced by scheduling the loop pass equivalents in the correct
649 // positions. But those equivalent passes aren't powerful enough yet.
650 // Specifically, `SimplifyCFGPass` and `InstCombinePass` are currently still
651 // used. We have `LoopSimplifyCFGPass` which isn't yet powerful enough yet to
652 // fully replace `SimplifyCFGPass`, and the closest to the other we have is
653 // `LoopInstSimplify`.
654 LoopPassManager LPM1, LPM2;
655
656 // Simplify the loop body. We do this initially to clean up after other loop
657 // passes run, either when iterating on a loop or on inner loops with
658 // implications on the outer loop.
659 LPM1.addPass(LoopInstSimplifyPass());
660 LPM1.addPass(LoopSimplifyCFGPass());
661
662 // Try to remove as much code from the loop header as possible,
663 // to reduce amount of IR that will have to be duplicated. However,
664 // do not perform speculative hoisting the first time as LICM
665 // will destroy metadata that may not need to be destroyed if run
666 // after loop rotation.
667 // TODO: Investigate promotion cap for O1.
668 LPM1.addPass(LICMPass(PTO.LicmMssaOptCap, PTO.LicmMssaNoAccForPromotionCap,
669 /*AllowSpeculation=*/false));
670
671 // Disable header duplication in loop rotation at -Oz.
673 Level != OptimizationLevel::Oz,
675 // TODO: Investigate promotion cap for O1.
676 LPM1.addPass(LICMPass(PTO.LicmMssaOptCap, PTO.LicmMssaNoAccForPromotionCap,
677 /*AllowSpeculation=*/true));
678 LPM1.addPass(
679 SimpleLoopUnswitchPass(/* NonTrivial */ Level == OptimizationLevel::O3));
681 LPM1.addPass(LoopFlattenPass());
682
683 LPM2.addPass(LoopIdiomRecognizePass());
684 LPM2.addPass(IndVarSimplifyPass());
685
686 {
688 ExtraPasses.addPass(SimpleLoopUnswitchPass(/* NonTrivial */ Level ==
690 LPM2.addPass(std::move(ExtraPasses));
691 }
692
694
695 LPM2.addPass(LoopDeletionPass());
696
697 // Do not enable unrolling in PreLinkThinLTO phase during sample PGO
698 // because it changes IR to makes profile annotation in back compile
699 // inaccurate. The normal unroller doesn't pay attention to forced full unroll
700 // attributes so we need to make sure and allow the full unroll pass to pay
701 // attention to it.
702 if (Phase != ThinOrFullLTOPhase::ThinLTOPreLink || !PGOOpt ||
703 PGOOpt->Action != PGOOptions::SampleUse)
704 LPM2.addPass(LoopFullUnrollPass(Level.getSpeedupLevel(),
705 /* OnlyWhenForced= */ !PTO.LoopUnrolling,
706 PTO.ForgetAllSCEVInLoopUnroll));
707
709
710 FPM.addPass(createFunctionToLoopPassAdaptor(std::move(LPM1),
711 /*UseMemorySSA=*/true));
712 FPM.addPass(
713 SimplifyCFGPass(SimplifyCFGOptions().convertSwitchRangeToICmp(true)));
715 // The loop passes in LPM2 (LoopIdiomRecognizePass, IndVarSimplifyPass,
716 // LoopDeletionPass and LoopFullUnrollPass) do not preserve MemorySSA.
717 // *All* loop passes must preserve it, in order to be able to use it.
718 FPM.addPass(createFunctionToLoopPassAdaptor(std::move(LPM2),
719 /*UseMemorySSA=*/false));
720
721 // Delete small array after loop unroll.
723
724 // Try vectorization/scalarization transforms that are both improvements
725 // themselves and can allow further folds with GVN and InstCombine.
726 FPM.addPass(VectorCombinePass(/*TryEarlyFoldsOnly=*/true));
727
728 // Eliminate redundancies.
730 if (RunNewGVN)
731 FPM.addPass(NewGVNPass());
732 else
733 FPM.addPass(GVNPass());
734
735 // Sparse conditional constant propagation.
736 // FIXME: It isn't clear why we do this *after* loop passes rather than
737 // before...
738 FPM.addPass(SCCPPass());
739
740 // Delete dead bit computations (instcombine runs after to fold away the dead
741 // computations, and then ADCE will run later to exploit any new DCE
742 // opportunities that creates).
743 FPM.addPass(BDCEPass());
744
745 // Run instcombine after redundancy and dead bit elimination to exploit
746 // opportunities opened up by them.
748 invokePeepholeEPCallbacks(FPM, Level);
749
750 // Re-consider control flow based optimizations after redundancy elimination,
751 // redo DCE, etc.
754
757
758 // Finally, do an expensive DCE pass to catch all the dead code exposed by
759 // the simplifications and basic cleanup after all the simplifications.
760 // TODO: Investigate if this is too expensive.
761 FPM.addPass(ADCEPass());
762
763 // Specially optimize memory movement as it doesn't look like dataflow in SSA.
764 FPM.addPass(MemCpyOptPass());
765
766 FPM.addPass(DSEPass());
768
770 LICMPass(PTO.LicmMssaOptCap, PTO.LicmMssaNoAccForPromotionCap,
771 /*AllowSpeculation=*/true),
772 /*UseMemorySSA=*/true));
773
774 FPM.addPass(CoroElidePass());
775
777
779 .convertSwitchRangeToICmp(true)
780 .convertSwitchToArithmetic(true)
781 .hoistCommonInsts(true)
782 .sinkCommonInsts(true)));
784 invokePeepholeEPCallbacks(FPM, Level);
785
786 return FPM;
787}
788
789void PassBuilder::addRequiredLTOPreLinkPasses(ModulePassManager &MPM) {
792}
793
794void PassBuilder::addPreInlinerPasses(ModulePassManager &MPM,
795 OptimizationLevel Level,
796 ThinOrFullLTOPhase LTOPhase) {
797 assert(Level != OptimizationLevel::O0 && "Not expecting O0 here!");
799 return;
800 InlineParams IP;
801
803
804 // FIXME: The hint threshold has the same value used by the regular inliner
805 // when not optimzing for size. This should probably be lowered after
806 // performance testing.
807 // FIXME: this comment is cargo culted from the old pass manager, revisit).
808 IP.HintThreshold = Level.isOptimizingForSize() ? PreInlineThreshold : 325;
810 IP, /* MandatoryFirst */ true,
812 CGSCCPassManager &CGPipeline = MIWP.getPM();
813
815 FPM.addPass(SROAPass(SROAOptions::ModifyCFG));
816 FPM.addPass(EarlyCSEPass()); // Catch trivial redundancies.
817 FPM.addPass(SimplifyCFGPass(SimplifyCFGOptions().convertSwitchRangeToICmp(
818 true))); // Merge & remove basic blocks.
819 FPM.addPass(InstCombinePass()); // Combine silly sequences.
820 invokePeepholeEPCallbacks(FPM, Level);
821
822 CGPipeline.addPass(createCGSCCToFunctionPassAdaptor(
823 std::move(FPM), PTO.EagerlyInvalidateAnalyses));
824
825 MPM.addPass(std::move(MIWP));
826
827 // Delete anything that is now dead to make sure that we don't instrument
828 // dead code. Instrumentation can end up keeping dead code around and
829 // dramatically increase code size.
830 MPM.addPass(GlobalDCEPass());
831}
832
833void PassBuilder::addPostPGOLoopRotation(ModulePassManager &MPM,
834 OptimizationLevel Level) {
836 // Disable header duplication in loop rotation at -Oz.
839 LoopRotatePass(EnableLoopHeaderDuplication ||
840 Level != OptimizationLevel::Oz),
841 /*UseMemorySSA=*/false),
842 PTO.EagerlyInvalidateAnalyses));
843 }
844}
845
846void PassBuilder::addPGOInstrPasses(ModulePassManager &MPM,
847 OptimizationLevel Level, bool RunProfileGen,
848 bool IsCS, bool AtomicCounterUpdate,
849 std::string ProfileFile,
850 std::string ProfileRemappingFile) {
851 assert(Level != OptimizationLevel::O0 && "Not expecting O0 here!");
852
853 if (!RunProfileGen) {
854 assert(!ProfileFile.empty() && "Profile use expecting a profile file!");
855 MPM.addPass(
856 PGOInstrumentationUse(ProfileFile, ProfileRemappingFile, IsCS, FS));
857 // Cache ProfileSummaryAnalysis once to avoid the potential need to insert
858 // RequireAnalysisPass for PSI before subsequent non-module passes.
859 MPM.addPass(RequireAnalysisPass<ProfileSummaryAnalysis, Module>());
860 return;
861 }
862
863 // Perform PGO instrumentation.
864 MPM.addPass(PGOInstrumentationGen(IsCS ? PGOInstrumentationType::CSFDO
866
867 addPostPGOLoopRotation(MPM, Level);
868 // Add the profile lowering pass.
869 InstrProfOptions Options;
870 if (!ProfileFile.empty())
871 Options.InstrProfileOutput = ProfileFile;
872 // Do counter promotion at Level greater than O0.
873 Options.DoCounterPromotion = true;
874 Options.UseBFIInPromotion = IsCS;
875 if (EnableSampledInstr) {
876 Options.Sampling = true;
877 // With sampling, there is little beneifit to enable counter promotion.
878 // But note that sampling does work with counter promotion.
879 Options.DoCounterPromotion = false;
880 }
881 Options.Atomic = AtomicCounterUpdate;
882 MPM.addPass(InstrProfilingLoweringPass(Options, IsCS));
883}
884
886 bool RunProfileGen, bool IsCS,
887 bool AtomicCounterUpdate,
888 std::string ProfileFile,
889 std::string ProfileRemappingFile) {
890 if (!RunProfileGen) {
891 assert(!ProfileFile.empty() && "Profile use expecting a profile file!");
892 MPM.addPass(
893 PGOInstrumentationUse(ProfileFile, ProfileRemappingFile, IsCS, FS));
894 // Cache ProfileSummaryAnalysis once to avoid the potential need to insert
895 // RequireAnalysisPass for PSI before subsequent non-module passes.
897 return;
898 }
899
900 // Perform PGO instrumentation.
903 // Add the profile lowering pass.
905 if (!ProfileFile.empty())
906 Options.InstrProfileOutput = ProfileFile;
907 // Do not do counter promotion at O0.
908 Options.DoCounterPromotion = false;
909 Options.UseBFIInPromotion = IsCS;
910 Options.Atomic = AtomicCounterUpdate;
912}
913
915 return getInlineParams(Level.getSpeedupLevel(), Level.getSizeLevel());
916}
917
921 InlineParams IP;
922 if (PTO.InlinerThreshold == -1)
923 IP = getInlineParamsFromOptLevel(Level);
924 else
925 IP = getInlineParams(PTO.InlinerThreshold);
926 // For PreLinkThinLTO + SamplePGO or PreLinkFullLTO + SamplePGO,
927 // set hot-caller threshold to 0 to disable hot
928 // callsite inline (as much as possible [1]) because it makes
929 // profile annotation in the backend inaccurate.
930 //
931 // [1] Note the cost of a function could be below zero due to erased
932 // prologue / epilogue.
933 if (isLTOPreLink(Phase) && PGOOpt && PGOOpt->Action == PGOOptions::SampleUse)
935
936 if (PGOOpt)
938
942
943 // Require the GlobalsAA analysis for the module so we can query it within
944 // the CGSCC pipeline.
946 MIWP.addModulePass(RequireAnalysisPass<GlobalsAA, Module>());
947 // Invalidate AAManager so it can be recreated and pick up the newly
948 // available GlobalsAA.
949 MIWP.addModulePass(
951 }
952
953 // Require the ProfileSummaryAnalysis for the module so we can query it within
954 // the inliner pass.
956
957 // Now begin the main postorder CGSCC pipeline.
958 // FIXME: The current CGSCC pipeline has its origins in the legacy pass
959 // manager and trying to emulate its precise behavior. Much of this doesn't
960 // make a lot of sense and we should revisit the core CGSCC structure.
961 CGSCCPassManager &MainCGPipeline = MIWP.getPM();
962
963 // Note: historically, the PruneEH pass was run first to deduce nounwind and
964 // generally clean up exception handling overhead. It isn't clear this is
965 // valuable as the inliner doesn't currently care whether it is inlining an
966 // invoke or a call.
967
969 MainCGPipeline.addPass(AttributorCGSCCPass());
970
971 // Deduce function attributes. We do another run of this after the function
972 // simplification pipeline, so this only needs to run when it could affect the
973 // function simplification pipeline, which is only the case with recursive
974 // functions.
975 MainCGPipeline.addPass(PostOrderFunctionAttrsPass(/*SkipNonRecursive*/ true));
976
977 // When at O3 add argument promotion to the pass pipeline.
978 // FIXME: It isn't at all clear why this should be limited to O3.
979 if (Level == OptimizationLevel::O3)
980 MainCGPipeline.addPass(ArgumentPromotionPass());
981
982 // Try to perform OpenMP specific optimizations. This is a (quick!) no-op if
983 // there are no OpenMP runtime calls present in the module.
984 if (Level == OptimizationLevel::O2 || Level == OptimizationLevel::O3)
985 MainCGPipeline.addPass(OpenMPOptCGSCCPass(Phase));
986
987 invokeCGSCCOptimizerLateEPCallbacks(MainCGPipeline, Level);
988
989 // Add the core function simplification pipeline nested inside the
990 // CGSCC walk.
993 PTO.EagerlyInvalidateAnalyses, /*NoRerun=*/true));
994
995 // Finally, deduce any function attributes based on the fully simplified
996 // function.
997 MainCGPipeline.addPass(PostOrderFunctionAttrsPass());
998
999 // Mark that the function is fully simplified and that it shouldn't be
1000 // simplified again if we somehow revisit it due to CGSCC mutations unless
1001 // it's been modified since.
1004
1006 MainCGPipeline.addPass(CoroSplitPass(Level != OptimizationLevel::O0));
1007 MainCGPipeline.addPass(CoroAnnotationElidePass());
1008 }
1009
1010 // Make sure we don't affect potential future NoRerun CGSCC adaptors.
1011 MIWP.addLateModulePass(createModuleToFunctionPassAdaptor(
1013
1014 return MIWP;
1015}
1016
1021
1023 // For PreLinkThinLTO + SamplePGO or PreLinkFullLTO + SamplePGO,
1024 // set hot-caller threshold to 0 to disable hot
1025 // callsite inline (as much as possible [1]) because it makes
1026 // profile annotation in the backend inaccurate.
1027 //
1028 // [1] Note the cost of a function could be below zero due to erased
1029 // prologue / epilogue.
1030 if (isLTOPreLink(Phase) && PGOOpt && PGOOpt->Action == PGOOptions::SampleUse)
1031 IP.HotCallSiteThreshold = 0;
1032
1033 if (PGOOpt)
1035
1036 // The inline deferral logic is used to avoid losing some
1037 // inlining chance in future. It is helpful in SCC inliner, in which
1038 // inlining is processed in bottom-up order.
1039 // While in module inliner, the inlining order is a priority-based order
1040 // by default. The inline deferral is unnecessary there. So we disable the
1041 // inline deferral logic in module inliner.
1042 IP.EnableDeferral = false;
1043
1046 MPM.addPass(GlobalOptPass());
1047 MPM.addPass(GlobalDCEPass());
1048 MPM.addPass(PGOCtxProfFlatteningPass(/*IsPreThinlink=*/false));
1049 }
1050
1053 PTO.EagerlyInvalidateAnalyses));
1054
1058 MPM.addPass(
1060 }
1061
1062 return MPM;
1063}
1064
1068 assert(Level != OptimizationLevel::O0 &&
1069 "Should not be used for O0 pipeline");
1070
1072 "FullLTOPostLink shouldn't call buildModuleSimplificationPipeline!");
1073
1075
1076 // Place pseudo probe instrumentation as the first pass of the pipeline to
1077 // minimize the impact of optimization changes.
1078 if (PGOOpt && PGOOpt->PseudoProbeForProfiling &&
1081
1082 bool HasSampleProfile = PGOOpt && (PGOOpt->Action == PGOOptions::SampleUse);
1083
1084 // In ThinLTO mode, when flattened profile is used, all the available
1085 // profile information will be annotated in PreLink phase so there is
1086 // no need to load the profile again in PostLink.
1087 bool LoadSampleProfile =
1088 HasSampleProfile &&
1090
1091 // During the ThinLTO backend phase we perform early indirect call promotion
1092 // here, before globalopt. Otherwise imported available_externally functions
1093 // look unreferenced and are removed. If we are going to load the sample
1094 // profile then defer until later.
1095 // TODO: See if we can move later and consolidate with the location where
1096 // we perform ICP when we are loading a sample profile.
1097 // TODO: We pass HasSampleProfile (whether there was a sample profile file
1098 // passed to the compile) to the SamplePGO flag of ICP. This is used to
1099 // determine whether the new direct calls are annotated with prof metadata.
1100 // Ideally this should be determined from whether the IR is annotated with
1101 // sample profile, and not whether the a sample profile was provided on the
1102 // command line. E.g. for flattened profiles where we will not be reloading
1103 // the sample profile in the ThinLTO backend, we ideally shouldn't have to
1104 // provide the sample profile file.
1105 if (Phase == ThinOrFullLTOPhase::ThinLTOPostLink && !LoadSampleProfile)
1106 MPM.addPass(PGOIndirectCallPromotion(true /* InLTO */, HasSampleProfile));
1107
1108 // Create an early function pass manager to cleanup the output of the
1109 // frontend. Not necessary with LTO post link pipelines since the pre link
1110 // pipeline already cleaned up the frontend output.
1112 // Do basic inference of function attributes from known properties of system
1113 // libraries and other oracles.
1115 MPM.addPass(CoroEarlyPass());
1116
1117 FunctionPassManager EarlyFPM;
1118 EarlyFPM.addPass(EntryExitInstrumenterPass(/*PostInlining=*/false));
1119 // Lower llvm.expect to metadata before attempting transforms.
1120 // Compare/branch metadata may alter the behavior of passes like
1121 // SimplifyCFG.
1123 EarlyFPM.addPass(SimplifyCFGPass());
1125 EarlyFPM.addPass(EarlyCSEPass());
1126 if (Level == OptimizationLevel::O3)
1127 EarlyFPM.addPass(CallSiteSplittingPass());
1129 std::move(EarlyFPM), PTO.EagerlyInvalidateAnalyses));
1130 }
1131
1132 if (LoadSampleProfile) {
1133 // Annotate sample profile right after early FPM to ensure freshness of
1134 // the debug info.
1136 PGOOpt->ProfileFile, PGOOpt->ProfileRemappingFile, Phase, FS));
1137 // Cache ProfileSummaryAnalysis once to avoid the potential need to insert
1138 // RequireAnalysisPass for PSI before subsequent non-module passes.
1140 // Do not invoke ICP in the LTOPrelink phase as it makes it hard
1141 // for the profile annotation to be accurate in the LTO backend.
1142 if (!isLTOPreLink(Phase))
1143 // We perform early indirect call promotion here, before globalopt.
1144 // This is important for the ThinLTO backend phase because otherwise
1145 // imported available_externally functions look unreferenced and are
1146 // removed.
1147 MPM.addPass(
1148 PGOIndirectCallPromotion(true /* IsInLTO */, true /* SamplePGO */));
1149 }
1150
1151 // Try to perform OpenMP specific optimizations on the module. This is a
1152 // (quick!) no-op if there are no OpenMP runtime calls present in the module.
1154
1156 MPM.addPass(AttributorPass());
1157
1158 // Lower type metadata and the type.test intrinsic in the ThinLTO
1159 // post link pipeline after ICP. This is to enable usage of the type
1160 // tests in ICP sequences.
1162 MPM.addPass(LowerTypeTestsPass(nullptr, nullptr,
1164
1166
1167 // Interprocedural constant propagation now that basic cleanup has occurred
1168 // and prior to optimizing globals.
1169 // FIXME: This position in the pipeline hasn't been carefully considered in
1170 // years, it should be re-analyzed.
1171 MPM.addPass(IPSCCPPass(
1172 IPSCCPOptions(/*AllowFuncSpec=*/
1173 Level != OptimizationLevel::Os &&
1174 Level != OptimizationLevel::Oz &&
1175 !isLTOPreLink(Phase))));
1176
1177 // Attach metadata to indirect call sites indicating the set of functions
1178 // they may target at run-time. This should follow IPSCCP.
1180
1181 // Optimize globals to try and fold them into constants.
1182 MPM.addPass(GlobalOptPass());
1183
1184 // Create a small function pass pipeline to cleanup after all the global
1185 // optimizations.
1186 FunctionPassManager GlobalCleanupPM;
1187 // FIXME: Should this instead by a run of SROA?
1188 GlobalCleanupPM.addPass(PromotePass());
1189 GlobalCleanupPM.addPass(InstCombinePass());
1190 invokePeepholeEPCallbacks(GlobalCleanupPM, Level);
1191 GlobalCleanupPM.addPass(
1192 SimplifyCFGPass(SimplifyCFGOptions().convertSwitchRangeToICmp(true)));
1193 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(GlobalCleanupPM),
1194 PTO.EagerlyInvalidateAnalyses));
1195
1196 // We already asserted this happens in non-FullLTOPostLink earlier.
1197 const bool IsPreLink = Phase != ThinOrFullLTOPhase::ThinLTOPostLink;
1198 // Enable contextual profiling instrumentation.
1199 const bool IsCtxProfGen =
1201 const bool IsPGOPreLink = !IsCtxProfGen && PGOOpt && IsPreLink;
1202 const bool IsPGOInstrGen =
1203 IsPGOPreLink && PGOOpt->Action == PGOOptions::IRInstr;
1204 const bool IsPGOInstrUse =
1205 IsPGOPreLink && PGOOpt->Action == PGOOptions::IRUse;
1206 const bool IsMemprofUse = IsPGOPreLink && !PGOOpt->MemoryProfile.empty();
1207 // We don't want to mix pgo ctx gen and pgo gen; we also don't currently
1208 // enable ctx profiling from the frontend.
1210 "Enabling both instrumented PGO and contextual instrumentation is not "
1211 "supported.");
1212 const bool IsCtxProfUse =
1214
1215 assert(
1217 "--instrument-cold-function-only-path is provided but "
1218 "--pgo-instrument-cold-function-only is not enabled");
1219 const bool IsColdFuncOnlyInstrGen = PGOInstrumentColdFunctionOnly &&
1220 IsPGOPreLink &&
1222
1223 if (IsPGOInstrGen || IsPGOInstrUse || IsMemprofUse || IsCtxProfGen ||
1224 IsCtxProfUse || IsColdFuncOnlyInstrGen)
1225 addPreInlinerPasses(MPM, Level, Phase);
1226
1227 // Add all the requested passes for instrumentation PGO, if requested.
1228 if (IsPGOInstrGen || IsPGOInstrUse) {
1229 addPGOInstrPasses(MPM, Level,
1230 /*RunProfileGen=*/IsPGOInstrGen,
1231 /*IsCS=*/false, PGOOpt->AtomicCounterUpdate,
1232 PGOOpt->ProfileFile, PGOOpt->ProfileRemappingFile);
1233 } else if (IsCtxProfGen || IsCtxProfUse) {
1235 // In pre-link, we just want the instrumented IR. We use the contextual
1236 // profile in the post-thinlink phase.
1237 // The instrumentation will be removed in post-thinlink after IPO.
1238 // FIXME(mtrofin): move AssignGUIDPass if there is agreement to use this
1239 // mechanism for GUIDs.
1240 MPM.addPass(AssignGUIDPass());
1241 if (IsCtxProfUse) {
1242 MPM.addPass(PGOCtxProfFlatteningPass(/*IsPreThinlink=*/true));
1243 return MPM;
1244 }
1245 // Block further inlining in the instrumented ctxprof case. This avoids
1246 // confusingly collecting profiles for the same GUID corresponding to
1247 // different variants of the function. We could do like PGO and identify
1248 // functions by a (GUID, Hash) tuple, but since the ctxprof "use" waits for
1249 // thinlto to happen before performing any further optimizations, it's
1250 // unnecessary to collect profiles for non-prevailing copies.
1252 addPostPGOLoopRotation(MPM, Level);
1254 } else if (IsColdFuncOnlyInstrGen) {
1255 addPGOInstrPasses(MPM, Level, /* RunProfileGen */ true, /* IsCS */ false,
1256 /* AtomicCounterUpdate */ false,
1258 /* ProfileRemappingFile */ "");
1259 }
1260
1261 if (IsPGOInstrGen || IsPGOInstrUse || IsCtxProfGen)
1262 MPM.addPass(PGOIndirectCallPromotion(false, false));
1263
1264 if (IsPGOPreLink && PGOOpt->CSAction == PGOOptions::CSIRInstr)
1265 MPM.addPass(PGOInstrumentationGenCreateVar(PGOOpt->CSProfileGenFile,
1267
1268 if (IsMemprofUse)
1269 MPM.addPass(MemProfUsePass(PGOOpt->MemoryProfile, FS));
1270
1271 if (PGOOpt && (PGOOpt->Action == PGOOptions::IRUse ||
1272 PGOOpt->Action == PGOOptions::SampleUse))
1273 MPM.addPass(PGOForceFunctionAttrsPass(PGOOpt->ColdOptType));
1274
1275 MPM.addPass(AlwaysInlinerPass(/*InsertLifetimeIntrinsics=*/true));
1276
1279 else
1280 MPM.addPass(buildInlinerPipeline(Level, Phase));
1281
1282 // Remove any dead arguments exposed by cleanups, constant folding globals,
1283 // and argument promotion.
1285
1288
1290 MPM.addPass(CoroCleanupPass());
1291
1292 // Optimize globals now that functions are fully simplified.
1293 MPM.addPass(GlobalOptPass());
1294 MPM.addPass(GlobalDCEPass());
1295
1296 return MPM;
1297}
1298
1299/// TODO: Should LTO cause any differences to this set of passes?
1300void PassBuilder::addVectorPasses(OptimizationLevel Level,
1301 FunctionPassManager &FPM, bool IsFullLTO) {
1304
1306 if (IsFullLTO) {
1307 // The vectorizer may have significantly shortened a loop body; unroll
1308 // again. Unroll small loops to hide loop backedge latency and saturate any
1309 // parallel execution resources of an out-of-order processor. We also then
1310 // need to clean up redundancies and loop invariant code.
1311 // FIXME: It would be really good to use a loop-integrated instruction
1312 // combiner for cleanup here so that the unrolling and LICM can be pipelined
1313 // across the loop nests.
1314 // We do UnrollAndJam in a separate LPM to ensure it happens before unroll
1317 LoopUnrollAndJamPass(Level.getSpeedupLevel())));
1319 Level.getSpeedupLevel(), /*OnlyWhenForced=*/!PTO.LoopUnrolling,
1322 // Now that we are done with loop unrolling, be it either by LoopVectorizer,
1323 // or LoopUnroll passes, some variable-offset GEP's into alloca's could have
1324 // become constant-offset, thus enabling SROA and alloca promotion. Do so.
1325 // NOTE: we are very late in the pipeline, and we don't have any LICM
1326 // or SimplifyCFG passes scheduled after us, that would cleanup
1327 // the CFG mess this may created if allowed to modify CFG, so forbid that.
1329 }
1330
1331 if (!IsFullLTO) {
1332 // Eliminate loads by forwarding stores from the previous iteration to loads
1333 // of the current iteration.
1335 }
1336 // Cleanup after the loop optimization passes.
1337 FPM.addPass(InstCombinePass());
1338
1339 if (Level.getSpeedupLevel() > 1 && ExtraVectorizerPasses) {
1340 ExtraFunctionPassManager<ShouldRunExtraVectorPasses> ExtraPasses;
1341 // At higher optimization levels, try to clean up any runtime overlap and
1342 // alignment checks inserted by the vectorizer. We want to track correlated
1343 // runtime checks for two inner loops in the same outer loop, fold any
1344 // common computations, hoist loop-invariant aspects out of any outer loop,
1345 // and unswitch the runtime checks if possible. Once hoisted, we may have
1346 // dead (or speculatable) control flows or more combining opportunities.
1347 ExtraPasses.addPass(EarlyCSEPass());
1348 ExtraPasses.addPass(CorrelatedValuePropagationPass());
1349 ExtraPasses.addPass(InstCombinePass());
1350 LoopPassManager LPM;
1351 LPM.addPass(LICMPass(PTO.LicmMssaOptCap, PTO.LicmMssaNoAccForPromotionCap,
1352 /*AllowSpeculation=*/true));
1353 LPM.addPass(SimpleLoopUnswitchPass(/* NonTrivial */ Level ==
1355 ExtraPasses.addPass(
1356 createFunctionToLoopPassAdaptor(std::move(LPM), /*UseMemorySSA=*/true));
1357 ExtraPasses.addPass(
1358 SimplifyCFGPass(SimplifyCFGOptions().convertSwitchRangeToICmp(true)));
1359 ExtraPasses.addPass(InstCombinePass());
1360 FPM.addPass(std::move(ExtraPasses));
1361 }
1362
1363 // Now that we've formed fast to execute loop structures, we do further
1364 // optimizations. These are run afterward as they might block doing complex
1365 // analyses and transforms such as what are needed for loop vectorization.
1366
1367 // Cleanup after loop vectorization, etc. Simplification passes like CVP and
1368 // GVN, loop transforms, and others have already run, so it's now better to
1369 // convert to more optimized IR using more aggressive simplify CFG options.
1370 // The extra sinking transform can create larger basic blocks, so do this
1371 // before SLP vectorization.
1372 FPM.addPass(SimplifyCFGPass(SimplifyCFGOptions()
1373 .forwardSwitchCondToPhi(true)
1374 .convertSwitchRangeToICmp(true)
1375 .convertSwitchToArithmetic(true)
1376 .convertSwitchToLookupTable(true)
1377 .needCanonicalLoops(false)
1378 .hoistCommonInsts(true)
1379 .sinkCommonInsts(true)));
1380
1381 if (IsFullLTO) {
1382 FPM.addPass(SCCPPass());
1383 FPM.addPass(InstCombinePass());
1384 FPM.addPass(BDCEPass());
1385 }
1386
1387 // Optimize parallel scalar instruction chains into SIMD instructions.
1388 if (PTO.SLPVectorization) {
1389 FPM.addPass(SLPVectorizerPass());
1390 if (Level.getSpeedupLevel() > 1 && ExtraVectorizerPasses) {
1391 FPM.addPass(EarlyCSEPass());
1392 }
1393 }
1394 // Enhance/cleanup vector code.
1395 FPM.addPass(VectorCombinePass());
1396
1397 if (!IsFullLTO) {
1398 FPM.addPass(InstCombinePass());
1399 // Unroll small loops to hide loop backedge latency and saturate any
1400 // parallel execution resources of an out-of-order processor. We also then
1401 // need to clean up redundancies and loop invariant code.
1402 // FIXME: It would be really good to use a loop-integrated instruction
1403 // combiner for cleanup here so that the unrolling and LICM can be pipelined
1404 // across the loop nests.
1405 // We do UnrollAndJam in a separate LPM to ensure it happens before unroll
1406 if (EnableUnrollAndJam && PTO.LoopUnrolling) {
1408 LoopUnrollAndJamPass(Level.getSpeedupLevel())));
1409 }
1410 FPM.addPass(LoopUnrollPass(LoopUnrollOptions(
1411 Level.getSpeedupLevel(), /*OnlyWhenForced=*/!PTO.LoopUnrolling,
1412 PTO.ForgetAllSCEVInLoopUnroll)));
1413 FPM.addPass(WarnMissedTransformationsPass());
1414 // Now that we are done with loop unrolling, be it either by LoopVectorizer,
1415 // or LoopUnroll passes, some variable-offset GEP's into alloca's could have
1416 // become constant-offset, thus enabling SROA and alloca promotion. Do so.
1417 // NOTE: we are very late in the pipeline, and we don't have any LICM
1418 // or SimplifyCFG passes scheduled after us, that would cleanup
1419 // the CFG mess this may created if allowed to modify CFG, so forbid that.
1420 FPM.addPass(SROAPass(SROAOptions::PreserveCFG));
1421 }
1422
1423 FPM.addPass(InferAlignmentPass());
1424 FPM.addPass(InstCombinePass());
1425
1426 // This is needed for two reasons:
1427 // 1. It works around problems that instcombine introduces, such as sinking
1428 // expensive FP divides into loops containing multiplications using the
1429 // divide result.
1430 // 2. It helps to clean up some loop-invariant code created by the loop
1431 // unroll pass when IsFullLTO=false.
1433 LICMPass(PTO.LicmMssaOptCap, PTO.LicmMssaNoAccForPromotionCap,
1434 /*AllowSpeculation=*/true),
1435 /*UseMemorySSA=*/true));
1436
1437 // Now that we've vectorized and unrolled loops, we may have more refined
1438 // alignment information, try to re-derive it here.
1439 FPM.addPass(AlignmentFromAssumptionsPass());
1440}
1441
1444 ThinOrFullLTOPhase LTOPhase) {
1445 const bool LTOPreLink = isLTOPreLink(LTOPhase);
1447
1448 // Run partial inlining pass to partially inline functions that have
1449 // large bodies.
1452
1453 // Remove avail extern fns and globals definitions since we aren't compiling
1454 // an object file for later LTO. For LTO we want to preserve these so they
1455 // are eligible for inlining at link-time. Note if they are unreferenced they
1456 // will be removed by GlobalDCE later, so this only impacts referenced
1457 // available externally globals. Eventually they will be suppressed during
1458 // codegen, but eliminating here enables more opportunity for GlobalDCE as it
1459 // may make globals referenced by available external functions dead and saves
1460 // running remaining passes on the eliminated functions. These should be
1461 // preserved during prelinking for link-time inlining decisions.
1462 if (!LTOPreLink)
1464
1465 // Do RPO function attribute inference across the module to forward-propagate
1466 // attributes where applicable.
1467 // FIXME: Is this really an optimization rather than a canonicalization?
1469
1470 // Do a post inline PGO instrumentation and use pass. This is a context
1471 // sensitive PGO pass. We don't want to do this in LTOPreLink phrase as
1472 // cross-module inline has not been done yet. The context sensitive
1473 // instrumentation is after all the inlines are done.
1474 if (!LTOPreLink && PGOOpt) {
1475 if (PGOOpt->CSAction == PGOOptions::CSIRInstr)
1476 addPGOInstrPasses(MPM, Level, /*RunProfileGen=*/true,
1477 /*IsCS=*/true, PGOOpt->AtomicCounterUpdate,
1478 PGOOpt->CSProfileGenFile, PGOOpt->ProfileRemappingFile);
1479 else if (PGOOpt->CSAction == PGOOptions::CSIRUse)
1480 addPGOInstrPasses(MPM, Level, /*RunProfileGen=*/false,
1481 /*IsCS=*/true, PGOOpt->AtomicCounterUpdate,
1482 PGOOpt->ProfileFile, PGOOpt->ProfileRemappingFile);
1483 }
1484
1485 // Re-compute GlobalsAA here prior to function passes. This is particularly
1486 // useful as the above will have inlined, DCE'ed, and function-attr
1487 // propagated everything. We should at this point have a reasonably minimal
1488 // and richly annotated call graph. By computing aliasing and mod/ref
1489 // information for all local globals here, the late loop passes and notably
1490 // the vectorizer will be able to use them to help recognize vectorizable
1491 // memory operations.
1494
1495 invokeOptimizerEarlyEPCallbacks(MPM, Level, LTOPhase);
1496
1497 FunctionPassManager OptimizePM;
1498
1499 // Only drop unnecessary assumes post-inline and post-link, as otherwise
1500 // additional uses of the affected value may be introduced through inlining
1501 // and CSE.
1502 if (!isLTOPreLink(LTOPhase))
1503 OptimizePM.addPass(DropUnnecessaryAssumesPass());
1504
1505 // Scheduling LoopVersioningLICM when inlining is over, because after that
1506 // we may see more accurate aliasing. Reason to run this late is that too
1507 // early versioning may prevent further inlining due to increase of code
1508 // size. Other optimizations which runs later might get benefit of no-alias
1509 // assumption in clone loop.
1511 OptimizePM.addPass(
1513 // LoopVersioningLICM pass might increase new LICM opportunities.
1515 LICMPass(PTO.LicmMssaOptCap, PTO.LicmMssaNoAccForPromotionCap,
1516 /*AllowSpeculation=*/true),
1517 /*USeMemorySSA=*/true));
1518 }
1519
1520 OptimizePM.addPass(Float2IntPass());
1522
1523 if (EnableMatrix) {
1524 OptimizePM.addPass(LowerMatrixIntrinsicsPass());
1525 OptimizePM.addPass(EarlyCSEPass());
1526 }
1527
1528 // CHR pass should only be applied with the profile information.
1529 // The check is to check the profile summary information in CHR.
1530 if (EnableCHR && Level == OptimizationLevel::O3)
1531 OptimizePM.addPass(ControlHeightReductionPass());
1532
1533 // FIXME: We need to run some loop optimizations to re-rotate loops after
1534 // simplifycfg and others undo their rotation.
1535
1536 // Optimize the loop execution. These passes operate on entire loop nests
1537 // rather than on each loop in an inside-out manner, and so they are actually
1538 // function passes.
1539
1540 invokeVectorizerStartEPCallbacks(OptimizePM, Level);
1541
1542 LoopPassManager LPM;
1543 // First rotate loops that may have been un-rotated by prior passes.
1544 // Disable header duplication at -Oz.
1546 Level != OptimizationLevel::Oz,
1547 LTOPreLink));
1548 // Some loops may have become dead by now. Try to delete them.
1549 // FIXME: see discussion in https://reviews.llvm.org/D112851,
1550 // this may need to be revisited once we run GVN before loop deletion
1551 // in the simplification pipeline.
1552 LPM.addPass(LoopDeletionPass());
1553
1554 if (PTO.LoopInterchange)
1555 LPM.addPass(LoopInterchangePass());
1556
1557 OptimizePM.addPass(
1558 createFunctionToLoopPassAdaptor(std::move(LPM), /*UseMemorySSA=*/false));
1559
1560 // FIXME: This may not be the right place in the pipeline.
1561 // We need to have the data to support the right place.
1562 if (PTO.LoopFusion)
1563 OptimizePM.addPass(LoopFusePass());
1564
1565 // Distribute loops to allow partial vectorization. I.e. isolate dependences
1566 // into separate loop that would otherwise inhibit vectorization. This is
1567 // currently only performed for loops marked with the metadata
1568 // llvm.loop.distribute=true or when -enable-loop-distribute is specified.
1569 OptimizePM.addPass(LoopDistributePass());
1570
1571 // Populates the VFABI attribute with the scalar-to-vector mappings
1572 // from the TargetLibraryInfo.
1573 OptimizePM.addPass(InjectTLIMappings());
1574
1575 addVectorPasses(Level, OptimizePM, /* IsFullLTO */ false);
1576
1577 invokeVectorizerEndEPCallbacks(OptimizePM, Level);
1578
1579 // LoopSink pass sinks instructions hoisted by LICM, which serves as a
1580 // canonicalization pass that enables other optimizations. As a result,
1581 // LoopSink pass needs to be a very late IR pass to avoid undoing LICM
1582 // result too early.
1583 OptimizePM.addPass(LoopSinkPass());
1584
1585 // And finally clean up LCSSA form before generating code.
1586 OptimizePM.addPass(InstSimplifyPass());
1587
1588 // This hoists/decomposes div/rem ops. It should run after other sink/hoist
1589 // passes to avoid re-sinking, but before SimplifyCFG because it can allow
1590 // flattening of blocks.
1591 OptimizePM.addPass(DivRemPairsPass());
1592
1593 // Try to annotate calls that were created during optimization.
1594 OptimizePM.addPass(
1595 TailCallElimPass(/*UpdateFunctionEntryCount=*/isInstrumentedPGOUse()));
1596
1597 // LoopSink (and other loop passes since the last simplifyCFG) might have
1598 // resulted in single-entry-single-exit or empty blocks. Clean up the CFG.
1599 OptimizePM.addPass(
1601 .convertSwitchRangeToICmp(true)
1602 .convertSwitchToArithmetic(true)
1603 .speculateUnpredictables(true)
1604 .hoistLoadsStoresWithCondFaulting(true)));
1605
1606 // Add the core optimizing pipeline.
1607 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(OptimizePM),
1608 PTO.EagerlyInvalidateAnalyses));
1609
1610 invokeOptimizerLastEPCallbacks(MPM, Level, LTOPhase);
1611
1612 // Split out cold code. Splitting is done late to avoid hiding context from
1613 // other optimizations and inadvertently regressing performance. The tradeoff
1614 // is that this has a higher code size cost than splitting early.
1615 if (EnableHotColdSplit && !LTOPreLink)
1617
1618 // Search the code for similar regions of code. If enough similar regions can
1619 // be found where extracting the regions into their own function will decrease
1620 // the size of the program, we extract the regions, a deduplicate the
1621 // structurally similar regions.
1622 if (EnableIROutliner)
1623 MPM.addPass(IROutlinerPass());
1624
1625 // Now we need to do some global optimization transforms.
1626 // FIXME: It would seem like these should come first in the optimization
1627 // pipeline and maybe be the bottom of the canonicalization pipeline? Weird
1628 // ordering here.
1629 MPM.addPass(GlobalDCEPass());
1631
1632 // Merge functions if requested. It has a better chance to merge functions
1633 // after ConstantMerge folded jump tables.
1634 if (PTO.MergeFunctions)
1636
1637 if (PTO.CallGraphProfile && !LTOPreLink)
1638 MPM.addPass(CGProfilePass(isLTOPostLink(LTOPhase)));
1639
1640 // RelLookupTableConverterPass runs later in LTO post-link pipeline.
1641 if (!LTOPreLink)
1643
1644 return MPM;
1645}
1646
1650 if (Level == OptimizationLevel::O0)
1651 return buildO0DefaultPipeline(Level, Phase);
1652
1654
1655 // Currently this pipeline is only invoked in an LTO pre link pass or when we
1656 // are not running LTO. If that changes the below checks may need updating.
1658
1659 // If we are invoking this in non-LTO mode, remove any MemProf related
1660 // attributes and metadata, as we don't know whether we are linking with
1661 // a library containing the necessary interfaces.
1664
1665 // Convert @llvm.global.annotations to !annotation metadata.
1667
1668 // Force any function attributes we want the rest of the pipeline to observe.
1670
1671 if (PGOOpt && PGOOpt->DebugInfoForProfiling)
1673
1674 // Apply module pipeline start EP callback.
1676
1677 // Add the core simplification pipeline.
1679
1680 // Now add the optimization pipeline.
1682
1683 if (PGOOpt && PGOOpt->PseudoProbeForProfiling &&
1684 PGOOpt->Action == PGOOptions::SampleUse)
1686
1687 // Emit annotation remarks.
1689
1690 if (isLTOPreLink(Phase))
1691 addRequiredLTOPreLinkPasses(MPM);
1692 return MPM;
1693}
1694
1697 bool EmitSummary) {
1699 if (ThinLTO)
1701 else
1703 MPM.addPass(EmbedBitcodePass(ThinLTO, EmitSummary));
1704
1705 // Perform any cleanups to the IR that aren't suitable for per TU compilation,
1706 // like removing CFI/WPD related instructions. Note, we reuse
1707 // LowerTypeTestsPass to clean up type tests rather than duplicate that logic
1708 // in FatLtoCleanup.
1709 MPM.addPass(FatLtoCleanup());
1710
1711 // If we're doing FatLTO w/ CFI enabled, we don't want the type tests in the
1712 // object code, only in the bitcode section, so drop it before we run
1713 // module optimization and generate machine code. If llvm.type.test() isn't in
1714 // the IR, this won't do anything.
1715 MPM.addPass(
1717
1718 // Use the ThinLTO post-link pipeline with sample profiling
1719 if (ThinLTO && PGOOpt && PGOOpt->Action == PGOOptions::SampleUse)
1720 MPM.addPass(buildThinLTODefaultPipeline(Level, /*ImportSummary=*/nullptr));
1721 else {
1722 // ModuleSimplification does not run the coroutine passes for
1723 // ThinLTOPreLink, so we need the coroutine passes to run for ThinLTO
1724 // builds, otherwise they will miscompile.
1725 if (ThinLTO) {
1726 // TODO: replace w/ buildCoroWrapper() when it takes phase and level into
1727 // consideration.
1728 CGSCCPassManager CGPM;
1732 MPM.addPass(CoroCleanupPass());
1733 }
1734
1735 // otherwise, just use module optimization
1736 MPM.addPass(
1738 // Emit annotation remarks.
1740 }
1741 return MPM;
1742}
1743
1746 if (Level == OptimizationLevel::O0)
1748
1750
1751 // Convert @llvm.global.annotations to !annotation metadata.
1753
1754 // Force any function attributes we want the rest of the pipeline to observe.
1756
1757 if (PGOOpt && PGOOpt->DebugInfoForProfiling)
1759
1760 // Apply module pipeline start EP callback.
1762
1763 // If we are planning to perform ThinLTO later, we don't bloat the code with
1764 // unrolling/vectorization/... now. Just simplify the module as much as we
1765 // can.
1768 // In pre-link, for ctx prof use, we stop here with an instrumented IR. We let
1769 // thinlto use the contextual info to perform imports; then use the contextual
1770 // profile in the post-thinlink phase.
1771 if (!UseCtxProfile.empty()) {
1772 addRequiredLTOPreLinkPasses(MPM);
1773 return MPM;
1774 }
1775
1776 // Run partial inlining pass to partially inline functions that have
1777 // large bodies.
1778 // FIXME: It isn't clear whether this is really the right place to run this
1779 // in ThinLTO. Because there is another canonicalization and simplification
1780 // phase that will run after the thin link, running this here ends up with
1781 // less information than will be available later and it may grow functions in
1782 // ways that aren't beneficial.
1785
1786 if (PGOOpt && PGOOpt->PseudoProbeForProfiling &&
1787 PGOOpt->Action == PGOOptions::SampleUse)
1789
1790 // Handle Optimizer{Early,Last}EPCallbacks added by clang on PreLink. Actual
1791 // optimization is going to be done in PostLink stage, but clang can't add
1792 // callbacks there in case of in-process ThinLTO called by linker.
1797
1798 // Emit annotation remarks.
1800
1801 addRequiredLTOPreLinkPasses(MPM);
1802
1803 return MPM;
1804}
1805
1807 OptimizationLevel Level, const ModuleSummaryIndex *ImportSummary) {
1809
1810 // If we are invoking this without a summary index noting that we are linking
1811 // with a library containing the necessary APIs, remove any MemProf related
1812 // attributes and metadata.
1813 if (!ImportSummary || !ImportSummary->withSupportsHotColdNew())
1815
1816 if (ImportSummary) {
1817 // For ThinLTO we must apply the context disambiguation decisions early, to
1818 // ensure we can correctly match the callsites to summary data.
1821 ImportSummary, PGOOpt && PGOOpt->Action == PGOOptions::SampleUse));
1822
1823 // These passes import type identifier resolutions for whole-program
1824 // devirtualization and CFI. They must run early because other passes may
1825 // disturb the specific instruction patterns that these passes look for,
1826 // creating dependencies on resolutions that may not appear in the summary.
1827 //
1828 // For example, GVN may transform the pattern assume(type.test) appearing in
1829 // two basic blocks into assume(phi(type.test, type.test)), which would
1830 // transform a dependency on a WPD resolution into a dependency on a type
1831 // identifier resolution for CFI.
1832 //
1833 // Also, WPD has access to more precise information than ICP and can
1834 // devirtualize more effectively, so it should operate on the IR first.
1835 //
1836 // The WPD and LowerTypeTest passes need to run at -O0 to lower type
1837 // metadata and intrinsics.
1838 MPM.addPass(WholeProgramDevirtPass(nullptr, ImportSummary));
1839 MPM.addPass(LowerTypeTestsPass(nullptr, ImportSummary));
1840 }
1841
1842 if (Level == OptimizationLevel::O0) {
1843 // Run a second time to clean up any type tests left behind by WPD for use
1844 // in ICP.
1845 MPM.addPass(LowerTypeTestsPass(nullptr, nullptr,
1848 // Drop available_externally and unreferenced globals. This is necessary
1849 // with ThinLTO in order to avoid leaving undefined references to dead
1850 // globals in the object file.
1852 MPM.addPass(GlobalDCEPass());
1853 return MPM;
1854 }
1855 if (!UseCtxProfile.empty()) {
1856 MPM.addPass(
1858 } else {
1859 // Add the core simplification pipeline.
1862 }
1863 // Now add the optimization pipeline.
1866
1867 // Emit annotation remarks.
1869
1870 return MPM;
1871}
1872
1875 // FIXME: We should use a customized pre-link pipeline!
1876 return buildPerModuleDefaultPipeline(Level,
1878}
1879
1882 ModuleSummaryIndex *ExportSummary) {
1884
1886
1887 // If we are invoking this without a summary index noting that we are linking
1888 // with a library containing the necessary APIs, remove any MemProf related
1889 // attributes and metadata.
1890 if (!ExportSummary || !ExportSummary->withSupportsHotColdNew())
1892
1893 // Create a function that performs CFI checks for cross-DSO calls with targets
1894 // in the current module.
1895 MPM.addPass(CrossDSOCFIPass());
1896
1897 if (Level == OptimizationLevel::O0) {
1898 // The WPD and LowerTypeTest passes need to run at -O0 to lower type
1899 // metadata and intrinsics.
1900 MPM.addPass(WholeProgramDevirtPass(ExportSummary, nullptr));
1901 MPM.addPass(LowerTypeTestsPass(ExportSummary, nullptr));
1902 // Run a second time to clean up any type tests left behind by WPD for use
1903 // in ICP.
1904 MPM.addPass(LowerTypeTestsPass(nullptr, nullptr,
1906
1908
1910
1911 // Emit annotation remarks.
1913
1914 return MPM;
1915 }
1916
1917 if (PGOOpt && PGOOpt->Action == PGOOptions::SampleUse) {
1918 // Load sample profile before running the LTO optimization pipeline.
1919 MPM.addPass(SampleProfileLoaderPass(PGOOpt->ProfileFile,
1920 PGOOpt->ProfileRemappingFile,
1922 // Cache ProfileSummaryAnalysis once to avoid the potential need to insert
1923 // RequireAnalysisPass for PSI before subsequent non-module passes.
1925 }
1926
1927 // Try to run OpenMP optimizations, quick no-op if no OpenMP metadata present.
1929
1930 // Remove unused virtual tables to improve the quality of code generated by
1931 // whole-program devirtualization and bitset lowering.
1932 MPM.addPass(GlobalDCEPass(/*InLTOPostLink=*/true));
1933
1934 // Do basic inference of function attributes from known properties of system
1935 // libraries and other oracles.
1937
1938 if (Level.getSpeedupLevel() > 1) {
1940 CallSiteSplittingPass(), PTO.EagerlyInvalidateAnalyses));
1941
1942 // Indirect call promotion. This should promote all the targets that are
1943 // left by the earlier promotion pass that promotes intra-module targets.
1944 // This two-step promotion is to save the compile time. For LTO, it should
1945 // produce the same result as if we only do promotion here.
1947 true /* InLTO */, PGOOpt && PGOOpt->Action == PGOOptions::SampleUse));
1948
1949 // Promoting by-reference arguments to by-value exposes more constants to
1950 // IPSCCP.
1951 CGSCCPassManager CGPM;
1954 CGPM.addPass(
1957
1958 // Propagate constants at call sites into the functions they call. This
1959 // opens opportunities for globalopt (and inlining) by substituting function
1960 // pointers passed as arguments to direct uses of functions.
1961 MPM.addPass(IPSCCPPass(IPSCCPOptions(/*AllowFuncSpec=*/
1962 Level != OptimizationLevel::Os &&
1963 Level != OptimizationLevel::Oz)));
1964
1965 // Attach metadata to indirect call sites indicating the set of functions
1966 // they may target at run-time. This should follow IPSCCP.
1968 }
1969
1970 // Do RPO function attribute inference across the module to forward-propagate
1971 // attributes where applicable.
1972 // FIXME: Is this really an optimization rather than a canonicalization?
1974
1975 // Use in-range annotations on GEP indices to split globals where beneficial.
1976 MPM.addPass(GlobalSplitPass());
1977
1978 // Run whole program optimization of virtual call when the list of callees
1979 // is fixed.
1980 MPM.addPass(WholeProgramDevirtPass(ExportSummary, nullptr));
1981
1983 // Stop here at -O1.
1984 if (Level == OptimizationLevel::O1) {
1985 // The LowerTypeTestsPass needs to run to lower type metadata and the
1986 // type.test intrinsics. The pass does nothing if CFI is disabled.
1987 MPM.addPass(LowerTypeTestsPass(ExportSummary, nullptr));
1988 // Run a second time to clean up any type tests left behind by WPD for use
1989 // in ICP (which is performed earlier than this in the regular LTO
1990 // pipeline).
1991 MPM.addPass(LowerTypeTestsPass(nullptr, nullptr,
1993
1995
1997
1998 // Emit annotation remarks.
2000
2001 return MPM;
2002 }
2003
2004 // TODO: Skip to match buildCoroWrapper.
2005 MPM.addPass(CoroEarlyPass());
2006
2007 // Optimize globals to try and fold them into constants.
2008 MPM.addPass(GlobalOptPass());
2009
2010 // Promote any localized globals to SSA registers.
2012
2013 // Linking modules together can lead to duplicate global constant, only
2014 // keep one copy of each constant.
2016
2017 // Remove unused arguments from functions.
2019
2020 // Reduce the code after globalopt and ipsccp. Both can open up significant
2021 // simplification opportunities, and both can propagate functions through
2022 // function pointers. When this happens, we often have to resolve varargs
2023 // calls, etc, so let instcombine do this.
2024 FunctionPassManager PeepholeFPM;
2025 PeepholeFPM.addPass(InstCombinePass());
2026 if (Level.getSpeedupLevel() > 1)
2027 PeepholeFPM.addPass(AggressiveInstCombinePass());
2028 invokePeepholeEPCallbacks(PeepholeFPM, Level);
2029
2030 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(PeepholeFPM),
2031 PTO.EagerlyInvalidateAnalyses));
2032
2033 // Lower variadic functions for supported targets prior to inlining.
2035
2036 // Note: historically, the PruneEH pass was run first to deduce nounwind and
2037 // generally clean up exception handling overhead. It isn't clear this is
2038 // valuable as the inliner doesn't currently care whether it is inlining an
2039 // invoke or a call.
2040 // Run the inliner now.
2041 if (EnableModuleInliner) {
2045 } else {
2048 /* MandatoryFirst */ true,
2051 }
2052
2053 // Perform context disambiguation after inlining, since that would reduce the
2054 // amount of additional cloning required to distinguish the allocation
2055 // contexts.
2058 /*Summary=*/nullptr,
2059 PGOOpt && PGOOpt->Action == PGOOptions::SampleUse));
2060
2061 // Optimize globals again after we ran the inliner.
2062 MPM.addPass(GlobalOptPass());
2063
2064 // Run the OpenMPOpt pass again after global optimizations.
2066
2067 // Garbage collect dead functions.
2068 MPM.addPass(GlobalDCEPass(/*InLTOPostLink=*/true));
2069
2070 // If we didn't decide to inline a function, check to see if we can
2071 // transform it to pass arguments by value instead of by reference.
2072 CGSCCPassManager CGPM;
2077
2079 // The IPO Passes may leave cruft around. Clean up after them.
2080 FPM.addPass(InstCombinePass());
2081 invokePeepholeEPCallbacks(FPM, Level);
2082
2085
2087
2088 // Do a post inline PGO instrumentation and use pass. This is a context
2089 // sensitive PGO pass.
2090 if (PGOOpt) {
2091 if (PGOOpt->CSAction == PGOOptions::CSIRInstr)
2092 addPGOInstrPasses(MPM, Level, /*RunProfileGen=*/true,
2093 /*IsCS=*/true, PGOOpt->AtomicCounterUpdate,
2094 PGOOpt->CSProfileGenFile, PGOOpt->ProfileRemappingFile);
2095 else if (PGOOpt->CSAction == PGOOptions::CSIRUse)
2096 addPGOInstrPasses(MPM, Level, /*RunProfileGen=*/false,
2097 /*IsCS=*/true, PGOOpt->AtomicCounterUpdate,
2098 PGOOpt->ProfileFile, PGOOpt->ProfileRemappingFile);
2099 }
2100
2101 // Break up allocas
2103
2104 // LTO provides additional opportunities for tailcall elimination due to
2105 // link-time inlining, and visibility of nocapture attribute.
2106 FPM.addPass(
2107 TailCallElimPass(/*UpdateFunctionEntryCount=*/isInstrumentedPGOUse()));
2108
2109 // Run a few AA driver optimizations here and now to cleanup the code.
2110 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM),
2111 PTO.EagerlyInvalidateAnalyses));
2112
2113 MPM.addPass(
2115
2116 // Require the GlobalsAA analysis for the module so we can query it within
2117 // MainFPM.
2120 // Invalidate AAManager so it can be recreated and pick up the newly
2121 // available GlobalsAA.
2122 MPM.addPass(
2124 }
2125
2126 FunctionPassManager MainFPM;
2128 LICMPass(PTO.LicmMssaOptCap, PTO.LicmMssaNoAccForPromotionCap,
2129 /*AllowSpeculation=*/true),
2130 /*USeMemorySSA=*/true));
2131
2132 if (RunNewGVN)
2133 MainFPM.addPass(NewGVNPass());
2134 else
2135 MainFPM.addPass(GVNPass());
2136
2137 // Remove dead memcpy()'s.
2138 MainFPM.addPass(MemCpyOptPass());
2139
2140 // Nuke dead stores.
2141 MainFPM.addPass(DSEPass());
2142 MainFPM.addPass(MoveAutoInitPass());
2144
2145 invokeVectorizerStartEPCallbacks(MainFPM, Level);
2146
2147 LoopPassManager LPM;
2148 if (EnableLoopFlatten && Level.getSpeedupLevel() > 1)
2149 LPM.addPass(LoopFlattenPass());
2150 LPM.addPass(IndVarSimplifyPass());
2151 LPM.addPass(LoopDeletionPass());
2152 // FIXME: Add loop interchange.
2153
2154 // Unroll small loops and perform peeling.
2155 LPM.addPass(LoopFullUnrollPass(Level.getSpeedupLevel(),
2156 /* OnlyWhenForced= */ !PTO.LoopUnrolling,
2157 PTO.ForgetAllSCEVInLoopUnroll));
2158 // The loop passes in LPM (LoopFullUnrollPass) do not preserve MemorySSA.
2159 // *All* loop passes must preserve it, in order to be able to use it.
2160 MainFPM.addPass(
2161 createFunctionToLoopPassAdaptor(std::move(LPM), /*UseMemorySSA=*/false));
2162
2163 MainFPM.addPass(LoopDistributePass());
2164
2165 addVectorPasses(Level, MainFPM, /* IsFullLTO */ true);
2166
2167 invokeVectorizerEndEPCallbacks(MainFPM, Level);
2168
2169 // Run the OpenMPOpt CGSCC pass again late.
2172
2173 invokePeepholeEPCallbacks(MainFPM, Level);
2174 MainFPM.addPass(JumpThreadingPass());
2175 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(MainFPM),
2176 PTO.EagerlyInvalidateAnalyses));
2177
2178 // Lower type metadata and the type.test intrinsic. This pass supports
2179 // clang's control flow integrity mechanisms (-fsanitize=cfi*) and needs
2180 // to be run at link time if CFI is enabled. This pass does nothing if
2181 // CFI is disabled.
2182 MPM.addPass(LowerTypeTestsPass(ExportSummary, nullptr));
2183 // Run a second time to clean up any type tests left behind by WPD for use
2184 // in ICP (which is performed earlier than this in the regular LTO pipeline).
2185 MPM.addPass(LowerTypeTestsPass(nullptr, nullptr,
2187
2188 // Enable splitting late in the FullLTO post-link pipeline.
2191
2192 // Add late LTO optimization passes.
2193 FunctionPassManager LateFPM;
2194
2195 // LoopSink pass sinks instructions hoisted by LICM, which serves as a
2196 // canonicalization pass that enables other optimizations. As a result,
2197 // LoopSink pass needs to be a very late IR pass to avoid undoing LICM
2198 // result too early.
2199 LateFPM.addPass(LoopSinkPass());
2200
2201 // This hoists/decomposes div/rem ops. It should run after other sink/hoist
2202 // passes to avoid re-sinking, but before SimplifyCFG because it can allow
2203 // flattening of blocks.
2204 LateFPM.addPass(DivRemPairsPass());
2205
2206 // Delete basic blocks, which optimization passes may have killed.
2208 .convertSwitchRangeToICmp(true)
2209 .convertSwitchToArithmetic(true)
2210 .hoistCommonInsts(true)
2211 .speculateUnpredictables(true)));
2212 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(LateFPM)));
2213
2214 // Drop bodies of available eternally objects to improve GlobalDCE.
2216
2217 // Now that we have optimized the program, discard unreachable functions.
2218 MPM.addPass(GlobalDCEPass(/*InLTOPostLink=*/true));
2219
2220 if (PTO.MergeFunctions)
2222
2224
2225 if (PTO.CallGraphProfile)
2226 MPM.addPass(CGProfilePass(/*InLTOPostLink=*/true));
2227
2228 MPM.addPass(CoroCleanupPass());
2229
2231
2232 // Emit annotation remarks.
2234
2235 return MPM;
2236}
2237
2241 assert(Level == OptimizationLevel::O0 &&
2242 "buildO0DefaultPipeline should only be used with O0");
2243
2245
2246 // Perform pseudo probe instrumentation in O0 mode. This is for the
2247 // consistency between different build modes. For example, a LTO build can be
2248 // mixed with an O0 prelink and an O2 postlink. Loading a sample profile in
2249 // the postlink will require pseudo probe instrumentation in the prelink.
2250 if (PGOOpt && PGOOpt->PseudoProbeForProfiling)
2252
2253 if (PGOOpt && (PGOOpt->Action == PGOOptions::IRInstr ||
2254 PGOOpt->Action == PGOOptions::IRUse))
2256 MPM,
2257 /*RunProfileGen=*/(PGOOpt->Action == PGOOptions::IRInstr),
2258 /*IsCS=*/false, PGOOpt->AtomicCounterUpdate, PGOOpt->ProfileFile,
2259 PGOOpt->ProfileRemappingFile);
2260
2261 // Instrument function entry and exit before all inlining.
2263 EntryExitInstrumenterPass(/*PostInlining=*/false)));
2264
2266
2267 if (PGOOpt && PGOOpt->DebugInfoForProfiling)
2269
2270 if (PGOOpt && PGOOpt->Action == PGOOptions::SampleUse) {
2271 // Explicitly disable sample loader inlining and use flattened profile in O0
2272 // pipeline.
2273 MPM.addPass(SampleProfileLoaderPass(PGOOpt->ProfileFile,
2274 PGOOpt->ProfileRemappingFile,
2275 ThinOrFullLTOPhase::None, nullptr,
2276 /*DisableSampleProfileInlining=*/true,
2277 /*UseFlattenedProfile=*/true));
2278 // Cache ProfileSummaryAnalysis once to avoid the potential need to insert
2279 // RequireAnalysisPass for PSI before subsequent non-module passes.
2281 }
2282
2284
2285 // Build a minimal pipeline based on the semantics required by LLVM,
2286 // which is just that always inlining occurs. Further, disable generating
2287 // lifetime intrinsics to avoid enabling further optimizations during
2288 // code generation.
2290 /*InsertLifetimeIntrinsics=*/false));
2291
2292 if (PTO.MergeFunctions)
2294
2295 if (EnableMatrix)
2296 MPM.addPass(
2298
2299 if (!CGSCCOptimizerLateEPCallbacks.empty()) {
2300 CGSCCPassManager CGPM;
2302 if (!CGPM.isEmpty())
2304 }
2305 if (!LateLoopOptimizationsEPCallbacks.empty()) {
2306 LoopPassManager LPM;
2308 if (!LPM.isEmpty()) {
2310 createFunctionToLoopPassAdaptor(std::move(LPM))));
2311 }
2312 }
2313 if (!LoopOptimizerEndEPCallbacks.empty()) {
2314 LoopPassManager LPM;
2316 if (!LPM.isEmpty()) {
2318 createFunctionToLoopPassAdaptor(std::move(LPM))));
2319 }
2320 }
2321 if (!ScalarOptimizerLateEPCallbacks.empty()) {
2324 if (!FPM.isEmpty())
2325 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
2326 }
2327
2329
2330 if (!VectorizerStartEPCallbacks.empty()) {
2333 if (!FPM.isEmpty())
2334 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
2335 }
2336
2337 if (!VectorizerEndEPCallbacks.empty()) {
2340 if (!FPM.isEmpty())
2341 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
2342 }
2343
2345
2347
2348 if (isLTOPreLink(Phase))
2349 addRequiredLTOPreLinkPasses(MPM);
2350
2352
2353 return MPM;
2354}
2355
2357 AAManager AA;
2358
2359 // The order in which these are registered determines their priority when
2360 // being queried.
2361
2362 // Add any target-specific alias analyses that should be run early.
2363 if (TM)
2364 TM->registerEarlyDefaultAliasAnalyses(AA);
2365
2366 // First we register the basic alias analysis that provides the majority of
2367 // per-function local AA logic. This is a stateless, on-demand local set of
2368 // AA techniques.
2369 AA.registerFunctionAnalysis<BasicAA>();
2370
2371 // Next we query fast, specialized alias analyses that wrap IR-embedded
2372 // information about aliasing.
2373 AA.registerFunctionAnalysis<ScopedNoAliasAA>();
2374 AA.registerFunctionAnalysis<TypeBasedAA>();
2375
2376 // Add support for querying global aliasing information when available.
2377 // Because the `AAManager` is a function analysis and `GlobalsAA` is a module
2378 // analysis, all that the `AAManager` can do is query for any *cached*
2379 // results from `GlobalsAA` through a readonly proxy.
2381 AA.registerModuleAnalysis<GlobalsAA>();
2382
2383 // Add target-specific alias analyses.
2384 if (TM)
2385 TM->registerDefaultAliasAnalyses(AA);
2386
2387 return AA;
2388}
2389
2390bool PassBuilder::isInstrumentedPGOUse() const {
2391 return (PGOOpt && PGOOpt->Action == PGOOptions::IRUse) ||
2392 !UseCtxProfile.empty();
2393}
aarch64 falkor hwpf fix Falkor HW Prefetch Fix Late Phase
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
AggressiveInstCombiner - Combine expression patterns to form expressions with fewer,...
Provides passes to inlining "always_inline" functions.
This is the interface for LLVM's primary stateless and local alias analysis.
This file provides the interface for LLVM's Call Graph Profile pass.
This header provides classes for managing passes over SCCs of the call graph.
#define clEnumValN(ENUMVAL, FLAGNAME, DESC)
This file provides the interface for a simple, fast CSE pass.
This file provides a pass which clones the current module and runs the provided pass pipeline on the ...
This file provides a pass manager that only runs its passes if the provided marker analysis has been ...
Super simple passes to force specific function attrs from the commandline into the IR for debugging p...
Provides passes for computing function attributes based on interprocedural analyses.
This file provides the interface for LLVM's Global Value Numbering pass which eliminates fully redund...
This is the interface for a simple mod/ref and alias analysis over globals.
AcceleratorCodeSelection - Identify all functions reachable from a kernel, removing those that are un...
This header defines various interfaces for pass management in LLVM.
Interfaces for passes which infer implicit function attributes from the name and signature of functio...
This file provides the primary interface to the instcombine pass.
Defines passes for running instruction simplification across chunks of IR.
This file provides the interface for LLVM's PGO Instrumentation lowering pass.
See the comments on JumpThreadingPass.
static LVOptions Options
Definition LVOptions.cpp:25
This file implements the Loop Fusion pass.
This header defines the LoopLoadEliminationPass object.
This header provides classes for managing a pipeline of passes over loops in LLVM IR.
The header file for the LowerConstantIntrinsics pass as used by the new pass manager.
The header file for the LowerExpectIntrinsic pass as used by the new pass manager.
This pass performs merges of loads and stores on both sides of a.
This file provides the interface for LLVM's Global Value Numbering pass.
This header enumerates the LLVM-provided high-level optimization levels.
This file provides the interface for IR based instrumentation passes ( (profile-gen,...
Define option tunables for PGO.
static void addAnnotationRemarksPass(ModulePassManager &MPM)
static InlineParams getInlineParamsFromOptLevel(OptimizationLevel Level)
static CoroConditionalWrapper buildCoroWrapper(ThinOrFullLTOPhase Phase)
static bool isLTOPreLink(ThinOrFullLTOPhase Phase)
static bool isLTOPostLink(ThinOrFullLTOPhase Phase)
This file implements relative lookup table converter that converts lookup tables to relative lookup t...
This file provides the interface for LLVM's Scalar Replacement of Aggregates pass.
This file provides the interface for the pseudo probe implementation for AutoFDO.
This file provides the interface for the sampled PGO loader pass.
This is the interface for a metadata-based scoped no-alias analysis.
This file provides the interface for the pass responsible for both simplifying and canonicalizing the...
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
This is the interface for a metadata-based TBAA.
Defines the virtual file system interface vfs::FileSystem.
A manager for alias analyses.
Inlines functions marked as "always_inline".
Argument promotion pass.
Assign a GUID to functions as metadata.
Analysis pass providing a never-invalidated alias analysis result.
Simple pass that canonicalizes aliases.
A pass that merges duplicate global constants into a single constant.
This class implements a trivial dead store elimination.
Eliminate dead arguments (and return values) from functions.
A pass that transforms external global definitions into declarations.
Pass embeds a copy of the module optimized with the provided pass pipeline into a global variable.
A pass manager to run a set of extra loop passes if the MarkerTy analysis is present.
The core GVN pass object.
Definition GVN.h:128
Pass to remove unused function declarations.
Definition GlobalDCE.h:38
Optimize globals that never have their address taken.
Definition GlobalOpt.h:25
Pass to perform split of global variables.
Definition GlobalSplit.h:26
Analysis pass providing a never-invalidated alias analysis result.
Pass to outline cold regions.
Pass to perform interprocedural constant propagation.
Definition SCCP.h:48
Pass to outline similar regions.
Definition IROutliner.h:444
Run instruction simplification across each instruction in the function.
Instrumentation based profiling lowering pass.
This pass performs 'jump threading', which looks at blocks that have multiple predecessors and multip...
Performs Loop Invariant Code Motion Pass.
Definition LICM.h:66
Loop unroll pass that only does full loop unrolling and peeling.
Performs Loop Idiom Recognize Pass.
Performs Loop Inst Simplify Pass.
A simple loop rotation transformation.
Performs basic CFG simplifications to assist other loop passes.
A pass that does profile-guided sinking of instructions into loops.
Definition LoopSink.h:33
A simple loop rotation transformation.
Loop unroll pass that will support both full and partial unrolling.
Strips MemProf attributes and metadata.
Merge identical functions.
The module inliner pass for the new pass manager.
Module pass, wrapping the inliner pass.
Definition Inliner.h:65
void addModulePass(T Pass)
Add a module pass that runs before the CGSCC passes.
Definition Inliner.h:81
Class to hold module path string table and global value map, and encapsulate methods for operating on...
Simple pass that provides a name to every anonymous globals.
Additional 'norecurse' attribute deduction during postlink LTO phase.
OpenMP optimizations pass.
Definition OpenMPOpt.h:42
static LLVM_ABI const OptimizationLevel O3
Optimize for fast execution as much as possible.
static LLVM_ABI const OptimizationLevel Oz
A very specialized mode that will optimize for code size at any and all costs.
static LLVM_ABI const OptimizationLevel O0
Disable as many optimizations as possible.
static LLVM_ABI const OptimizationLevel Os
Similar to O2 but tries to optimize for small code size instead of fast execution without triggering ...
static LLVM_ABI const OptimizationLevel O2
Optimize for fast execution as much as possible without triggering significant incremental compile ti...
static LLVM_ABI const OptimizationLevel O1
Optimize quickly without destroying debuggability.
The indirect function call promotion pass.
The instrumentation (profile-instr-gen) pass for IR based PGO.
The instrumentation (profile-instr-gen) pass for IR based PGO.
The profile annotation (profile-instr-use) pass for IR based PGO.
The profile size based optimization pass for memory intrinsics.
Pass to remove unused function declarations.
LLVM_ABI void invokeFullLinkTimeOptimizationLastEPCallbacks(ModulePassManager &MPM, OptimizationLevel Level)
LLVM_ABI ModuleInlinerWrapperPass buildInlinerPipeline(OptimizationLevel Level, ThinOrFullLTOPhase Phase)
Construct the module pipeline that performs inlining as well as the inlining-driven cleanups.
LLVM_ABI void invokeOptimizerEarlyEPCallbacks(ModulePassManager &MPM, OptimizationLevel Level, ThinOrFullLTOPhase Phase)
LLVM_ABI void invokeVectorizerStartEPCallbacks(FunctionPassManager &FPM, OptimizationLevel Level)
LLVM_ABI AAManager buildDefaultAAPipeline()
Build the default AAManager with the default alias analysis pipeline registered.
LLVM_ABI void invokeCGSCCOptimizerLateEPCallbacks(CGSCCPassManager &CGPM, OptimizationLevel Level)
LLVM_ABI ModulePassManager buildThinLTOPreLinkDefaultPipeline(OptimizationLevel Level)
Build a pre-link, ThinLTO-targeting default optimization pipeline to a pass manager.
LLVM_ABI void addPGOInstrPassesForO0(ModulePassManager &MPM, bool RunProfileGen, bool IsCS, bool AtomicCounterUpdate, std::string ProfileFile, std::string ProfileRemappingFile)
Add PGOInstrumenation passes for O0 only.
LLVM_ABI void invokeScalarOptimizerLateEPCallbacks(FunctionPassManager &FPM, OptimizationLevel Level)
LLVM_ABI ModulePassManager buildPerModuleDefaultPipeline(OptimizationLevel Level, ThinOrFullLTOPhase Phase=ThinOrFullLTOPhase::None)
Build a per-module default optimization pipeline.
LLVM_ABI void invokePipelineStartEPCallbacks(ModulePassManager &MPM, OptimizationLevel Level)
LLVM_ABI void invokeVectorizerEndEPCallbacks(FunctionPassManager &FPM, OptimizationLevel Level)
LLVM_ABI ModulePassManager buildO0DefaultPipeline(OptimizationLevel Level, ThinOrFullLTOPhase Phase=ThinOrFullLTOPhase::None)
Build an O0 pipeline with the minimal semantically required passes.
LLVM_ABI FunctionPassManager buildFunctionSimplificationPipeline(OptimizationLevel Level, ThinOrFullLTOPhase Phase)
Construct the core LLVM function canonicalization and simplification pipeline.
LLVM_ABI void invokePeepholeEPCallbacks(FunctionPassManager &FPM, OptimizationLevel Level)
LLVM_ABI void invokePipelineEarlySimplificationEPCallbacks(ModulePassManager &MPM, OptimizationLevel Level, ThinOrFullLTOPhase Phase)
LLVM_ABI void invokeLoopOptimizerEndEPCallbacks(LoopPassManager &LPM, OptimizationLevel Level)
LLVM_ABI ModulePassManager buildLTODefaultPipeline(OptimizationLevel Level, ModuleSummaryIndex *ExportSummary)
Build an LTO default optimization pipeline to a pass manager.
LLVM_ABI ModulePassManager buildModuleInlinerPipeline(OptimizationLevel Level, ThinOrFullLTOPhase Phase)
Construct the module pipeline that performs inlining with module inliner pass.
LLVM_ABI ModulePassManager buildThinLTODefaultPipeline(OptimizationLevel Level, const ModuleSummaryIndex *ImportSummary)
Build a ThinLTO default optimization pipeline to a pass manager.
LLVM_ABI void invokeLateLoopOptimizationsEPCallbacks(LoopPassManager &LPM, OptimizationLevel Level)
LLVM_ABI void invokeFullLinkTimeOptimizationEarlyEPCallbacks(ModulePassManager &MPM, OptimizationLevel Level)
LLVM_ABI ModulePassManager buildFatLTODefaultPipeline(OptimizationLevel Level, bool ThinLTO, bool EmitSummary)
Build a fat object default optimization pipeline.
LLVM_ABI ModulePassManager buildModuleSimplificationPipeline(OptimizationLevel Level, ThinOrFullLTOPhase Phase)
Construct the core LLVM module canonicalization and simplification pipeline.
LLVM_ABI ModulePassManager buildModuleOptimizationPipeline(OptimizationLevel Level, ThinOrFullLTOPhase LTOPhase)
Construct the core LLVM module optimization pipeline.
LLVM_ABI void invokeOptimizerLastEPCallbacks(ModulePassManager &MPM, OptimizationLevel Level, ThinOrFullLTOPhase Phase)
LLVM_ABI ModulePassManager buildLTOPreLinkDefaultPipeline(OptimizationLevel Level)
Build a pre-link, LTO-targeting default optimization pipeline to a pass manager.
LLVM_ATTRIBUTE_MINSIZE std::enable_if_t<!std::is_same_v< PassT, PassManager > > addPass(PassT &&Pass)
bool isEmpty() const
Returns if the pass manager contains any passes.
unsigned LicmMssaNoAccForPromotionCap
Tuning option to disable promotion to scalars in LICM with MemorySSA, if the number of access is too ...
Definition PassBuilder.h:78
bool SLPVectorization
Tuning option to enable/disable slp loop vectorization, set based on opt level.
Definition PassBuilder.h:56
int InlinerThreshold
Tuning option to override the default inliner threshold.
Definition PassBuilder.h:92
bool LoopFusion
Tuning option to enable/disable loop fusion. Its default value is false.
Definition PassBuilder.h:66
bool CallGraphProfile
Tuning option to enable/disable call graph profile.
Definition PassBuilder.h:82
bool MergeFunctions
Tuning option to enable/disable function merging.
Definition PassBuilder.h:89
bool ForgetAllSCEVInLoopUnroll
Tuning option to forget all SCEV loops in LoopUnroll.
Definition PassBuilder.h:70
unsigned LicmMssaOptCap
Tuning option to cap the number of calls to retrive clobbering accesses in MemorySSA,...
Definition PassBuilder.h:74
bool LoopInterleaving
Tuning option to set loop interleaving on/off, set based on opt level.
Definition PassBuilder.h:48
LLVM_ABI PipelineTuningOptions()
Constructor sets pipeline tuning defaults based on cl::opts.
bool LoopUnrolling
Tuning option to enable/disable loop unrolling. Its default value is true.
Definition PassBuilder.h:59
bool LoopInterchange
Tuning option to enable/disable loop interchange.
Definition PassBuilder.h:63
bool LoopVectorization
Tuning option to enable/disable loop vectorization, set based on opt level.
Definition PassBuilder.h:52
Reassociate commutative expressions.
Definition Reassociate.h:74
A pass to do RPO deduction and propagation of function attributes.
This pass performs function-level constant propagation and merging.
Definition SCCP.h:30
The sample profiler data loader pass.
Analysis pass providing a never-invalidated alias analysis result.
This pass transforms loops that contain branches or switches on loop- invariant conditions to have mu...
A pass to simplify and canonicalize the CFG of a function.
Definition SimplifyCFG.h:30
Analysis pass providing a never-invalidated alias analysis result.
Optimize scalar/vector interactions in IR using target cost models.
Interfaces for registering analysis passes, producing common pass manager configurations,...
Abstract Attribute helper functions.
Definition Attributor.h:165
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
ValuesClass values(OptsTy... Options)
Helper to build a ValuesClass by forwarding a variable number of arguments as an initializer list to ...
initializer< Ty > init(const Ty &Val)
@ Assume
Do not drop type tests (default).
@ All
Drop only llvm.assumes using type test value.
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI cl::opt< bool > EnableKnowledgeRetention
static cl::opt< bool > RunNewGVN("enable-newgvn", cl::init(false), cl::Hidden, cl::desc("Run the NewGVN pass"))
static cl::opt< bool > DisablePreInliner("disable-preinline", cl::init(false), cl::Hidden, cl::desc("Disable pre-instrumentation inliner"))
static cl::opt< bool > EnableJumpTableToSwitch("enable-jump-table-to-switch", cl::desc("Enable JumpTableToSwitch pass (default = off)"))
static cl::opt< bool > PerformMandatoryInliningsFirst("mandatory-inlining-first", cl::init(false), cl::Hidden, cl::desc("Perform mandatory inlinings module-wide, before performing " "inlining"))
static cl::opt< bool > RunPartialInlining("enable-partial-inlining", cl::init(false), cl::Hidden, cl::desc("Run Partial inlining pass"))
static cl::opt< bool > EnableGVNSink("enable-gvn-sink", cl::desc("Enable the GVN sinking pass (default = off)"))
static cl::opt< bool > EnableLoopHeaderDuplication("enable-loop-header-duplication", cl::init(false), cl::Hidden, cl::desc("Enable loop header duplication at any optimization level"))
static cl::opt< bool > EnableModuleInliner("enable-module-inliner", cl::init(false), cl::Hidden, cl::desc("Enable module inliner"))
static cl::opt< bool > EnableEagerlyInvalidateAnalyses("eagerly-invalidate-analyses", cl::init(true), cl::Hidden, cl::desc("Eagerly invalidate more analyses in default pipelines"))
static cl::opt< bool > EnableMatrix("enable-matrix", cl::init(false), cl::Hidden, cl::desc("Enable lowering of the matrix intrinsics"))
ModuleToFunctionPassAdaptor createModuleToFunctionPassAdaptor(FunctionPassT &&Pass, bool EagerlyInvalidate=false)
A function to deduce a function pass type and wrap it in the templated adaptor.
cl::opt< std::string > UseCtxProfile("use-ctx-profile", cl::init(""), cl::Hidden, cl::desc("Use the specified contextual profile file"))
static cl::opt< bool > EnableSampledInstr("enable-sampled-instrumentation", cl::init(false), cl::Hidden, cl::desc("Enable profile instrumentation sampling (default = off)"))
static cl::opt< bool > EnableLoopFlatten("enable-loop-flatten", cl::init(false), cl::Hidden, cl::desc("Enable the LoopFlatten Pass"))
static cl::opt< InliningAdvisorMode > UseInlineAdvisor("enable-ml-inliner", cl::init(InliningAdvisorMode::Default), cl::Hidden, cl::desc("Enable ML policy for inliner. Currently trained for -Oz only"), cl::values(clEnumValN(InliningAdvisorMode::Default, "default", "Heuristics-based inliner version"), clEnumValN(InliningAdvisorMode::Development, "development", "Use development mode (runtime-loadable model)"), clEnumValN(InliningAdvisorMode::Release, "release", "Use release mode (AOT-compiled model)")))
PassManager< LazyCallGraph::SCC, CGSCCAnalysisManager, LazyCallGraph &, CGSCCUpdateResult & > CGSCCPassManager
The CGSCC pass manager.
static cl::opt< bool > EnableUnrollAndJam("enable-unroll-and-jam", cl::init(false), cl::Hidden, cl::desc("Enable Unroll And Jam Pass"))
ThinOrFullLTOPhase
This enumerates the LLVM full LTO or ThinLTO optimization phases.
Definition Pass.h:77
@ FullLTOPreLink
Full LTO prelink phase.
Definition Pass.h:85
@ ThinLTOPostLink
ThinLTO postlink (backend compile) phase.
Definition Pass.h:83
@ None
No LTO/ThinLTO behavior needed.
Definition Pass.h:79
@ FullLTOPostLink
Full LTO postlink (backend compile) phase.
Definition Pass.h:87
@ ThinLTOPreLink
ThinLTO prelink (summary) phase.
Definition Pass.h:81
PassManager< Loop, LoopAnalysisManager, LoopStandardAnalysisResults &, LPMUpdater & > LoopPassManager
The Loop pass manager.
static cl::opt< bool > EnableConstraintElimination("enable-constraint-elimination", cl::init(true), cl::Hidden, cl::desc("Enable pass to eliminate conditions based on linear constraints"))
ModuleToPostOrderCGSCCPassAdaptor createModuleToPostOrderCGSCCPassAdaptor(CGSCCPassT &&Pass)
A function to deduce a function pass type and wrap it in the templated adaptor.
static cl::opt< bool > EnablePGOInlineDeferral("enable-npm-pgo-inline-deferral", cl::init(true), cl::Hidden, cl::desc("Enable inline deferral during PGO"))
Flag to enable inline deferral during PGO.
FunctionToLoopPassAdaptor createFunctionToLoopPassAdaptor(LoopPassT &&Pass, bool UseMemorySSA=false)
A function to deduce a loop pass type and wrap it in the templated adaptor.
CGSCCToFunctionPassAdaptor createCGSCCToFunctionPassAdaptor(FunctionPassT &&Pass, bool EagerlyInvalidate=false, bool NoRerun=false)
A function to deduce a function pass type and wrap it in the templated adaptor.
cl::opt< bool > ForgetSCEVInLoopUnroll
PassManager< Module > ModulePassManager
Convenience typedef for a pass manager over modules.
static cl::opt< bool > EnablePostPGOLoopRotation("enable-post-pgo-loop-rotation", cl::init(true), cl::Hidden, cl::desc("Run the loop rotation transformation after PGO instrumentation"))
LLVM_ABI bool AreStatisticsEnabled()
Check if statistics are enabled.
static cl::opt< std::string > InstrumentColdFuncOnlyPath("instrument-cold-function-only-path", cl::init(""), cl::desc("File path for cold function only instrumentation(requires use " "with --pgo-instrument-cold-function-only)"), cl::Hidden)
static cl::opt< bool > EnableGlobalAnalyses("enable-global-analyses", cl::init(true), cl::Hidden, cl::desc("Enable inter-procedural analyses"))
static cl::opt< bool > EnableDFAJumpThreading("enable-dfa-jump-thread", cl::desc("Enable DFA jump threading"), cl::init(false), cl::Hidden)
static cl::opt< bool > FlattenedProfileUsed("flattened-profile-used", cl::init(false), cl::Hidden, cl::desc("Indicate the sample profile being used is flattened, i.e., " "no inline hierarchy exists in the profile"))
static cl::opt< bool > ExtraVectorizerPasses("extra-vectorizer-passes", cl::init(false), cl::Hidden, cl::desc("Run cleanup optimization passes after vectorization"))
static cl::opt< bool > EnableHotColdSplit("hot-cold-split", cl::desc("Enable hot-cold splitting pass"))
cl::opt< bool > EnableMemProfContextDisambiguation
Enable MemProf context disambiguation for thin link.
PassManager< Function > FunctionPassManager
Convenience typedef for a pass manager over functions.
LLVM_ABI InlineParams getInlineParams()
Generate the parameters to tune the inline cost analysis based only on the commandline options.
cl::opt< bool > PGOInstrumentColdFunctionOnly
static cl::opt< bool > EnableLoopInterchange("enable-loopinterchange", cl::init(false), cl::Hidden, cl::desc("Enable the LoopInterchange Pass"))
static cl::opt< bool > EnableCHR("enable-chr", cl::init(true), cl::Hidden, cl::desc("Enable control height reduction optimization (CHR)"))
static cl::opt< bool > EnableMergeFunctions("enable-merge-functions", cl::init(false), cl::Hidden, cl::desc("Enable function merging as part of the optimization pipeline"))
static cl::opt< bool > EnableGVNHoist("enable-gvn-hoist", cl::desc("Enable the GVN hoisting pass (default = off)"))
cl::opt< unsigned > SetLicmMssaNoAccForPromotionCap
static cl::opt< bool > EnableIROutliner("ir-outliner", cl::init(false), cl::Hidden, cl::desc("Enable ir outliner pass"))
static cl::opt< AttributorRunOption > AttributorRun("attributor-enable", cl::Hidden, cl::init(AttributorRunOption::NONE), cl::desc("Enable the attributor inter-procedural deduction pass"), cl::values(clEnumValN(AttributorRunOption::ALL, "all", "enable all attributor runs"), clEnumValN(AttributorRunOption::MODULE, "module", "enable module-wide attributor runs"), clEnumValN(AttributorRunOption::CGSCC, "cgscc", "enable call graph SCC attributor runs"), clEnumValN(AttributorRunOption::NONE, "none", "disable attributor runs")))
static cl::opt< int > PreInlineThreshold("preinline-threshold", cl::Hidden, cl::init(75), cl::desc("Control the amount of inlining in pre-instrumentation inliner " "(default = 75)"))
static cl::opt< bool > UseLoopVersioningLICM("enable-loop-versioning-licm", cl::init(false), cl::Hidden, cl::desc("Enable the experimental Loop Versioning LICM pass"))
cl::opt< unsigned > MaxDevirtIterations("max-devirt-iterations", cl::ReallyHidden, cl::init(4))
cl::opt< unsigned > SetLicmMssaOptCap
A DCE pass that assumes instructions are dead until proven otherwise.
Definition ADCE.h:31
Pass to convert @llvm.global.annotations to !annotation metadata.
This pass attempts to minimize the number of assume without loosing any information.
Hoist/decompose integer division and remainder instructions to enable CFG improvements and better cod...
Definition DivRemPairs.h:23
A simple and fast domtree-based CSE pass.
Definition EarlyCSE.h:31
Pass which forces specific function attributes into the IR, primarily as a debugging tool.
A simple and fast domtree-based GVN pass to hoist common expressions from sibling branches.
Definition GVN.h:415
Uses an "inverted" value numbering to decide the similarity of expressions and sinks similar expressi...
Definition GVN.h:422
A set of parameters to control various transforms performed by IPSCCP pass.
Definition SCCP.h:35
A pass which infers function attributes from the names and signatures of function declarations in a m...
Provides context on when an inline advisor is constructed in the pipeline (e.g., link phase,...
Thresholds to tune inline cost analysis.
Definition InlineCost.h:207
std::optional< int > HotCallSiteThreshold
Threshold to use when the callsite is considered hot.
Definition InlineCost.h:224
int DefaultThreshold
The default threshold to start with for a callee.
Definition InlineCost.h:209
std::optional< bool > EnableDeferral
Indicate whether we should allow inline deferral.
Definition InlineCost.h:237
std::optional< int > HintThreshold
Threshold to use for callees with inline hint.
Definition InlineCost.h:212
Options for the frontend instrumentation based profiling pass.
A no-op pass template which simply forces a specific analysis result to be invalidated.
Pass to forward loads in a loop around the backedge to subsequent iterations.
A set of parameters used to control various transforms performed by the LoopUnroll pass.
The LoopVectorize Pass.
Computes function attributes in post-order over the call graph.
A utility pass template to force an analysis result to be available.