LLVM  8.0.0svn
PassBuilder.cpp
Go to the documentation of this file.
1 //===- Parsing, selection, and construction of pass pipelines -------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 /// \file
10 ///
11 /// This file provides the implementation of the PassBuilder based on our
12 /// static pass registry as well as related functionality. It also provides
13 /// helpers to aid in analyzing, debugging, and testing passes and pass
14 /// pipelines.
15 ///
16 //===----------------------------------------------------------------------===//
17 
19 #include "llvm/ADT/StringSwitch.h"
35 #include "llvm/Analysis/IVUsers.h"
39 #include "llvm/Analysis/LoopInfo.h"
56 #include "llvm/IR/Dominators.h"
58 #include "llvm/IR/PassManager.h"
59 #include "llvm/IR/Verifier.h"
60 #include "llvm/Support/Debug.h"
61 #include "llvm/Support/Regex.h"
158 
159 using namespace llvm;
160 
161 static cl::opt<unsigned> MaxDevirtIterations("pm-max-devirt-iterations",
163 static cl::opt<bool>
164  RunPartialInlining("enable-npm-partial-inlining", cl::init(false),
166  cl::desc("Run Partial inlinining pass"));
167 
168 static cl::opt<bool>
169  RunNewGVN("enable-npm-newgvn", cl::init(false),
171  cl::desc("Run NewGVN instead of GVN"));
172 
174  "enable-npm-earlycse-memssa", cl::init(true), cl::Hidden,
175  cl::desc("Enable the EarlyCSE w/ MemorySSA pass for the new PM (default = on)"));
176 
178  "enable-npm-gvn-hoist", cl::init(true), cl::Hidden,
179  cl::desc("Enable the GVN hoisting pass for the new PM (default = on)"));
180 
182  "enable-npm-gvn-sink", cl::init(false), cl::Hidden,
183  cl::desc("Enable the GVN hoisting pass for the new PM (default = off)"));
184 
186  "enable-npm-unroll-and-jam", cl::init(false), cl::Hidden,
187  cl::desc("Enable the Unroll and Jam pass for the new PM (default = off)"));
188 
190  "enable-npm-synthetic-counts", cl::init(false), cl::Hidden, cl::ZeroOrMore,
191  cl::desc("Run synthetic function entry count generation "
192  "pass"));
193 
194 static Regex DefaultAliasRegex(
195  "^(default|thinlto-pre-link|thinlto|lto-pre-link|lto)<(O[0123sz])>$");
196 
197 static cl::opt<bool>
198  EnableCHR("enable-chr-npm", cl::init(true), cl::Hidden,
199  cl::desc("Enable control height reduction optimization (CHR)"));
200 
202  switch (Level) {
203  case PassBuilder::O0:
204  case PassBuilder::O1:
205  case PassBuilder::O2:
206  case PassBuilder::O3:
207  return false;
208 
209  case PassBuilder::Os:
210  case PassBuilder::Oz:
211  return true;
212  }
213  llvm_unreachable("Invalid optimization level!");
214 }
215 
216 namespace {
217 
218 /// No-op module pass which does nothing.
219 struct NoOpModulePass {
221  return PreservedAnalyses::all();
222  }
223  static StringRef name() { return "NoOpModulePass"; }
224 };
225 
226 /// No-op module analysis.
227 class NoOpModuleAnalysis : public AnalysisInfoMixin<NoOpModuleAnalysis> {
229  static AnalysisKey Key;
230 
231 public:
232  struct Result {};
233  Result run(Module &, ModuleAnalysisManager &) { return Result(); }
234  static StringRef name() { return "NoOpModuleAnalysis"; }
235 };
236 
237 /// No-op CGSCC pass which does nothing.
238 struct NoOpCGSCCPass {
241  return PreservedAnalyses::all();
242  }
243  static StringRef name() { return "NoOpCGSCCPass"; }
244 };
245 
246 /// No-op CGSCC analysis.
247 class NoOpCGSCCAnalysis : public AnalysisInfoMixin<NoOpCGSCCAnalysis> {
249  static AnalysisKey Key;
250 
251 public:
252  struct Result {};
254  return Result();
255  }
256  static StringRef name() { return "NoOpCGSCCAnalysis"; }
257 };
258 
259 /// No-op function pass which does nothing.
260 struct NoOpFunctionPass {
262  return PreservedAnalyses::all();
263  }
264  static StringRef name() { return "NoOpFunctionPass"; }
265 };
266 
267 /// No-op function analysis.
268 class NoOpFunctionAnalysis : public AnalysisInfoMixin<NoOpFunctionAnalysis> {
270  static AnalysisKey Key;
271 
272 public:
273  struct Result {};
274  Result run(Function &, FunctionAnalysisManager &) { return Result(); }
275  static StringRef name() { return "NoOpFunctionAnalysis"; }
276 };
277 
278 /// No-op loop pass which does nothing.
279 struct NoOpLoopPass {
282  return PreservedAnalyses::all();
283  }
284  static StringRef name() { return "NoOpLoopPass"; }
285 };
286 
287 /// No-op loop analysis.
288 class NoOpLoopAnalysis : public AnalysisInfoMixin<NoOpLoopAnalysis> {
290  static AnalysisKey Key;
291 
292 public:
293  struct Result {};
295  return Result();
296  }
297  static StringRef name() { return "NoOpLoopAnalysis"; }
298 };
299 
304 
305 } // End anonymous namespace.
306 
307 void PassBuilder::invokePeepholeEPCallbacks(
309  for (auto &C : PeepholeEPCallbacks)
310  C(FPM, Level);
311 }
312 
314 #define MODULE_ANALYSIS(NAME, CREATE_PASS) \
315  MAM.registerPass([&] { return CREATE_PASS; });
316 #include "PassRegistry.def"
317 
318  for (auto &C : ModuleAnalysisRegistrationCallbacks)
319  C(MAM);
320 }
321 
323 #define CGSCC_ANALYSIS(NAME, CREATE_PASS) \
324  CGAM.registerPass([&] { return CREATE_PASS; });
325 #include "PassRegistry.def"
326 
327  for (auto &C : CGSCCAnalysisRegistrationCallbacks)
328  C(CGAM);
329 }
330 
332 #define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
333  FAM.registerPass([&] { return CREATE_PASS; });
334 #include "PassRegistry.def"
335 
336  for (auto &C : FunctionAnalysisRegistrationCallbacks)
337  C(FAM);
338 }
339 
341 #define LOOP_ANALYSIS(NAME, CREATE_PASS) \
342  LAM.registerPass([&] { return CREATE_PASS; });
343 #include "PassRegistry.def"
344 
345  for (auto &C : LoopAnalysisRegistrationCallbacks)
346  C(LAM);
347 }
348 
352  bool DebugLogging) {
353  assert(Level != O0 && "Must request optimizations!");
354  FunctionPassManager FPM(DebugLogging);
355 
356  // Form SSA out of local memory accesses after breaking apart aggregates into
357  // scalars.
358  FPM.addPass(SROA());
359 
360  // Catch trivial redundancies
362 
363  // Hoisting of scalars and load expressions.
364  if (EnableGVNHoist)
365  FPM.addPass(GVNHoistPass());
366 
367  // Global value numbering based sinking.
368  if (EnableGVNSink) {
369  FPM.addPass(GVNSinkPass());
370  FPM.addPass(SimplifyCFGPass());
371  }
372 
373  // Speculative execution if the target has divergent branches; otherwise nop.
375 
376  // Optimize based on known information about branches, and cleanup afterward.
377  FPM.addPass(JumpThreadingPass());
379  FPM.addPass(SimplifyCFGPass());
380  if (Level == O3)
382  FPM.addPass(InstCombinePass());
383 
384  if (!isOptimizingForSize(Level))
386 
387  invokePeepholeEPCallbacks(FPM, Level);
388 
389  // For PGO use pipeline, try to optimize memory intrinsics such as memcpy
390  // using the size value profile. Don't perform this when optimizing for size.
391  if (PGOOpt && !PGOOpt->ProfileUseFile.empty() &&
392  !isOptimizingForSize(Level))
393  FPM.addPass(PGOMemOPSizeOpt());
394 
395  FPM.addPass(TailCallElimPass());
396  FPM.addPass(SimplifyCFGPass());
397 
398  // Form canonically associated expression trees, and simplify the trees using
399  // basic mathematical properties. For example, this will form (nearly)
400  // minimal multiplication trees.
401  FPM.addPass(ReassociatePass());
402 
403  // Add the primary loop simplification pipeline.
404  // FIXME: Currently this is split into two loop pass pipelines because we run
405  // some function passes in between them. These can and should be removed
406  // and/or replaced by scheduling the loop pass equivalents in the correct
407  // positions. But those equivalent passes aren't powerful enough yet.
408  // Specifically, `SimplifyCFGPass` and `InstCombinePass` are currently still
409  // used. We have `LoopSimplifyCFGPass` which isn't yet powerful enough yet to
410  // fully replace `SimplifyCFGPass`, and the closest to the other we have is
411  // `LoopInstSimplify`.
412  LoopPassManager LPM1(DebugLogging), LPM2(DebugLogging);
413 
414  // Simplify the loop body. We do this initially to clean up after other loop
415  // passes run, either when iterating on a loop or on inner loops with
416  // implications on the outer loop.
417  LPM1.addPass(LoopInstSimplifyPass());
418  LPM1.addPass(LoopSimplifyCFGPass());
419 
420  // Rotate Loop - disable header duplication at -Oz
421  LPM1.addPass(LoopRotatePass(Level != Oz));
422  LPM1.addPass(LICMPass());
423  LPM1.addPass(SimpleLoopUnswitchPass());
424  LPM2.addPass(IndVarSimplifyPass());
426 
427  for (auto &C : LateLoopOptimizationsEPCallbacks)
428  C(LPM2, Level);
429 
430  LPM2.addPass(LoopDeletionPass());
431  // Do not enable unrolling in PreLinkThinLTO phase during sample PGO
432  // because it changes IR to makes profile annotation in back compile
433  // inaccurate.
434  if (Phase != ThinLTOPhase::PreLink ||
435  !PGOOpt || PGOOpt->SampleProfileFile.empty())
436  LPM2.addPass(LoopFullUnrollPass(Level));
437 
438  for (auto &C : LoopOptimizerEndEPCallbacks)
439  C(LPM2, Level);
440 
441  // We provide the opt remark emitter pass for LICM to use. We only need to do
442  // this once as it is immutable.
444  FPM.addPass(createFunctionToLoopPassAdaptor(std::move(LPM1), DebugLogging));
445  FPM.addPass(SimplifyCFGPass());
446  FPM.addPass(InstCombinePass());
447  FPM.addPass(createFunctionToLoopPassAdaptor(std::move(LPM2), DebugLogging));
448 
449  // Eliminate redundancies.
450  if (Level != O1) {
451  // These passes add substantial compile time so skip them at O1.
453  if (RunNewGVN)
454  FPM.addPass(NewGVNPass());
455  else
456  FPM.addPass(GVN());
457  }
458 
459  // Specially optimize memory movement as it doesn't look like dataflow in SSA.
460  FPM.addPass(MemCpyOptPass());
461 
462  // Sparse conditional constant propagation.
463  // FIXME: It isn't clear why we do this *after* loop passes rather than
464  // before...
465  FPM.addPass(SCCPPass());
466 
467  // Delete dead bit computations (instcombine runs after to fold away the dead
468  // computations, and then ADCE will run later to exploit any new DCE
469  // opportunities that creates).
470  FPM.addPass(BDCEPass());
471 
472  // Run instcombine after redundancy and dead bit elimination to exploit
473  // opportunities opened up by them.
474  FPM.addPass(InstCombinePass());
475  invokePeepholeEPCallbacks(FPM, Level);
476 
477  // Re-consider control flow based optimizations after redundancy elimination,
478  // redo DCE, etc.
479  FPM.addPass(JumpThreadingPass());
481  FPM.addPass(DSEPass());
482  FPM.addPass(createFunctionToLoopPassAdaptor(LICMPass(), DebugLogging));
483 
484  for (auto &C : ScalarOptimizerLateEPCallbacks)
485  C(FPM, Level);
486 
487  // Finally, do an expensive DCE pass to catch all the dead code exposed by
488  // the simplifications and basic cleanup after all the simplifications.
489  FPM.addPass(ADCEPass());
490  FPM.addPass(SimplifyCFGPass());
491  FPM.addPass(InstCombinePass());
492  invokePeepholeEPCallbacks(FPM, Level);
493 
494  if (EnableCHR && Level == O3 && PGOOpt &&
495  (!PGOOpt->ProfileUseFile.empty() || !PGOOpt->SampleProfileFile.empty()))
497 
498  return FPM;
499 }
500 
501 void PassBuilder::addPGOInstrPasses(ModulePassManager &MPM, bool DebugLogging,
503  bool RunProfileGen,
504  std::string ProfileGenFile,
505  std::string ProfileUseFile) {
506  // Generally running simplification passes and the inliner with an high
507  // threshold results in smaller executables, but there may be cases where
508  // the size grows, so let's be conservative here and skip this simplification
509  // at -Os/Oz.
510  if (!isOptimizingForSize(Level)) {
511  InlineParams IP;
512 
513  // In the old pass manager, this is a cl::opt. Should still this be one?
514  IP.DefaultThreshold = 75;
515 
516  // FIXME: The hint threshold has the same value used by the regular inliner.
517  // This should probably be lowered after performance testing.
518  // FIXME: this comment is cargo culted from the old pass manager, revisit).
519  IP.HintThreshold = 325;
520 
521  CGSCCPassManager CGPipeline(DebugLogging);
522 
523  CGPipeline.addPass(InlinerPass(IP));
524 
526  FPM.addPass(SROA());
527  FPM.addPass(EarlyCSEPass()); // Catch trivial redundancies.
528  FPM.addPass(SimplifyCFGPass()); // Merge & remove basic blocks.
529  FPM.addPass(InstCombinePass()); // Combine silly sequences.
530  invokePeepholeEPCallbacks(FPM, Level);
531 
532  CGPipeline.addPass(createCGSCCToFunctionPassAdaptor(std::move(FPM)));
533 
534  MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(std::move(CGPipeline)));
535  }
536 
537  // Delete anything that is now dead to make sure that we don't instrument
538  // dead code. Instrumentation can end up keeping dead code around and
539  // dramatically increase code size.
540  MPM.addPass(GlobalDCEPass());
541 
542  if (RunProfileGen) {
544 
546  FPM.addPass(
548  MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
549 
550  // Add the profile lowering pass.
551  InstrProfOptions Options;
552  if (!ProfileGenFile.empty())
553  Options.InstrProfileOutput = ProfileGenFile;
554  Options.DoCounterPromotion = true;
555  MPM.addPass(InstrProfiling(Options));
556  }
557 
558  if (!ProfileUseFile.empty())
559  MPM.addPass(PGOInstrumentationUse(ProfileUseFile));
560 }
561 
562 static InlineParams
564  auto O3 = PassBuilder::O3;
565  unsigned OptLevel = Level > O3 ? 2 : Level;
566  unsigned SizeLevel = Level > O3 ? Level - O3 : 0;
567  return getInlineParams(OptLevel, SizeLevel);
568 }
569 
573  bool DebugLogging) {
574  ModulePassManager MPM(DebugLogging);
575 
576  // Do basic inference of function attributes from known properties of system
577  // libraries and other oracles.
579 
580  // Create an early function pass manager to cleanup the output of the
581  // frontend.
582  FunctionPassManager EarlyFPM(DebugLogging);
583  EarlyFPM.addPass(SimplifyCFGPass());
584  EarlyFPM.addPass(SROA());
585  EarlyFPM.addPass(EarlyCSEPass());
586  EarlyFPM.addPass(LowerExpectIntrinsicPass());
587  if (Level == O3)
588  EarlyFPM.addPass(CallSiteSplittingPass());
589 
590  // In SamplePGO ThinLTO backend, we need instcombine before profile annotation
591  // to convert bitcast to direct calls so that they can be inlined during the
592  // profile annotation prepration step.
593  // More details about SamplePGO design can be found in:
594  // https://research.google.com/pubs/pub45290.html
595  // FIXME: revisit how SampleProfileLoad/Inliner/ICP is structured.
596  if (PGOOpt && !PGOOpt->SampleProfileFile.empty() &&
597  Phase == ThinLTOPhase::PostLink)
598  EarlyFPM.addPass(InstCombinePass());
599  MPM.addPass(createModuleToFunctionPassAdaptor(std::move(EarlyFPM)));
600 
601  if (PGOOpt && !PGOOpt->SampleProfileFile.empty()) {
602  // Annotate sample profile right after early FPM to ensure freshness of
603  // the debug info.
604  MPM.addPass(SampleProfileLoaderPass(PGOOpt->SampleProfileFile,
605  Phase == ThinLTOPhase::PreLink));
606  // Do not invoke ICP in the ThinLTOPrelink phase as it makes it hard
607  // for the profile annotation to be accurate in the ThinLTO backend.
608  if (Phase != ThinLTOPhase::PreLink)
609  // We perform early indirect call promotion here, before globalopt.
610  // This is important for the ThinLTO backend phase because otherwise
611  // imported available_externally functions look unreferenced and are
612  // removed.
613  MPM.addPass(PGOIndirectCallPromotion(Phase == ThinLTOPhase::PostLink,
614  true));
615  }
616 
617  // Interprocedural constant propagation now that basic cleanup has occurred
618  // and prior to optimizing globals.
619  // FIXME: This position in the pipeline hasn't been carefully considered in
620  // years, it should be re-analyzed.
621  MPM.addPass(IPSCCPPass());
622 
623  // Attach metadata to indirect call sites indicating the set of functions
624  // they may target at run-time. This should follow IPSCCP.
626 
627  // Optimize globals to try and fold them into constants.
628  MPM.addPass(GlobalOptPass());
629 
630  // Promote any localized globals to SSA registers.
631  // FIXME: Should this instead by a run of SROA?
632  // FIXME: We should probably run instcombine and simplify-cfg afterward to
633  // delete control flows that are dead once globals have been folded to
634  // constants.
636 
637  // Remove any dead arguments exposed by cleanups and constand folding
638  // globals.
640 
641  // Create a small function pass pipeline to cleanup after all the global
642  // optimizations.
643  FunctionPassManager GlobalCleanupPM(DebugLogging);
644  GlobalCleanupPM.addPass(InstCombinePass());
645  invokePeepholeEPCallbacks(GlobalCleanupPM, Level);
646 
647  GlobalCleanupPM.addPass(SimplifyCFGPass());
648  MPM.addPass(createModuleToFunctionPassAdaptor(std::move(GlobalCleanupPM)));
649 
650  // Add all the requested passes for instrumentation PGO, if requested.
651  if (PGOOpt && Phase != ThinLTOPhase::PostLink &&
652  (!PGOOpt->ProfileGenFile.empty() || !PGOOpt->ProfileUseFile.empty())) {
653  addPGOInstrPasses(MPM, DebugLogging, Level, PGOOpt->RunProfileGen,
654  PGOOpt->ProfileGenFile, PGOOpt->ProfileUseFile);
655  MPM.addPass(PGOIndirectCallPromotion(false, false));
656  }
657 
658  // Synthesize function entry counts for non-PGO compilation.
659  if (EnableSyntheticCounts && !PGOOpt)
661 
662  // Require the GlobalsAA analysis for the module so we can query it within
663  // the CGSCC pipeline.
665 
666  // Require the ProfileSummaryAnalysis for the module so we can query it within
667  // the inliner pass.
669 
670  // Now begin the main postorder CGSCC pipeline.
671  // FIXME: The current CGSCC pipeline has its origins in the legacy pass
672  // manager and trying to emulate its precise behavior. Much of this doesn't
673  // make a lot of sense and we should revisit the core CGSCC structure.
674  CGSCCPassManager MainCGPipeline(DebugLogging);
675 
676  // Note: historically, the PruneEH pass was run first to deduce nounwind and
677  // generally clean up exception handling overhead. It isn't clear this is
678  // valuable as the inliner doesn't currently care whether it is inlining an
679  // invoke or a call.
680 
681  // Run the inliner first. The theory is that we are walking bottom-up and so
682  // the callees have already been fully optimized, and we want to inline them
683  // into the callers so that our optimizations can reflect that.
684  // For PreLinkThinLTO pass, we disable hot-caller heuristic for sample PGO
685  // because it makes profile annotation in the backend inaccurate.
687  if (Phase == ThinLTOPhase::PreLink &&
688  PGOOpt && !PGOOpt->SampleProfileFile.empty())
689  IP.HotCallSiteThreshold = 0;
690  MainCGPipeline.addPass(InlinerPass(IP));
691 
692  // Now deduce any function attributes based in the current code.
693  MainCGPipeline.addPass(PostOrderFunctionAttrsPass());
694 
695  // When at O3 add argument promotion to the pass pipeline.
696  // FIXME: It isn't at all clear why this should be limited to O3.
697  if (Level == O3)
698  MainCGPipeline.addPass(ArgumentPromotionPass());
699 
700  // Lastly, add the core function simplification pipeline nested inside the
701  // CGSCC walk.
703  buildFunctionSimplificationPipeline(Level, Phase, DebugLogging)));
704 
705  for (auto &C : CGSCCOptimizerLateEPCallbacks)
706  C(MainCGPipeline, Level);
707 
708  // We wrap the CGSCC pipeline in a devirtualization repeater. This will try
709  // to detect when we devirtualize indirect calls and iterate the SCC passes
710  // in that case to try and catch knock-on inlining or function attrs
711  // opportunities. Then we add it to the module pipeline by walking the SCCs
712  // in postorder (or bottom-up).
713  MPM.addPass(
715  std::move(MainCGPipeline), MaxDevirtIterations)));
716 
717  return MPM;
718 }
719 
722  bool DebugLogging) {
723  ModulePassManager MPM(DebugLogging);
724 
725  // Optimize globals now that the module is fully simplified.
726  MPM.addPass(GlobalOptPass());
727  MPM.addPass(GlobalDCEPass());
728 
729  // Run partial inlining pass to partially inline functions that have
730  // large bodies.
731  if (RunPartialInlining)
733 
734  // Remove avail extern fns and globals definitions since we aren't compiling
735  // an object file for later LTO. For LTO we want to preserve these so they
736  // are eligible for inlining at link-time. Note if they are unreferenced they
737  // will be removed by GlobalDCE later, so this only impacts referenced
738  // available externally globals. Eventually they will be suppressed during
739  // codegen, but eliminating here enables more opportunity for GlobalDCE as it
740  // may make globals referenced by available external functions dead and saves
741  // running remaining passes on the eliminated functions.
743 
744  // Do RPO function attribute inference across the module to forward-propagate
745  // attributes where applicable.
746  // FIXME: Is this really an optimization rather than a canonicalization?
748 
749  // Re-require GloblasAA here prior to function passes. This is particularly
750  // useful as the above will have inlined, DCE'ed, and function-attr
751  // propagated everything. We should at this point have a reasonably minimal
752  // and richly annotated call graph. By computing aliasing and mod/ref
753  // information for all local globals here, the late loop passes and notably
754  // the vectorizer will be able to use them to help recognize vectorizable
755  // memory operations.
757 
758  FunctionPassManager OptimizePM(DebugLogging);
759  OptimizePM.addPass(Float2IntPass());
760  // FIXME: We need to run some loop optimizations to re-rotate loops after
761  // simplify-cfg and others undo their rotation.
762 
763  // Optimize the loop execution. These passes operate on entire loop nests
764  // rather than on each loop in an inside-out manner, and so they are actually
765  // function passes.
766 
767  for (auto &C : VectorizerStartEPCallbacks)
768  C(OptimizePM, Level);
769 
770  // First rotate loops that may have been un-rotated by prior passes.
771  OptimizePM.addPass(
773 
774  // Distribute loops to allow partial vectorization. I.e. isolate dependences
775  // into separate loop that would otherwise inhibit vectorization. This is
776  // currently only performed for loops marked with the metadata
777  // llvm.loop.distribute=true or when -enable-loop-distribute is specified.
778  OptimizePM.addPass(LoopDistributePass());
779 
780  // Now run the core loop vectorizer.
781  OptimizePM.addPass(LoopVectorizePass());
782 
783  // Eliminate loads by forwarding stores from the previous iteration to loads
784  // of the current iteration.
785  OptimizePM.addPass(LoopLoadEliminationPass());
786 
787  // Cleanup after the loop optimization passes.
788  OptimizePM.addPass(InstCombinePass());
789 
790  // Now that we've formed fast to execute loop structures, we do further
791  // optimizations. These are run afterward as they might block doing complex
792  // analyses and transforms such as what are needed for loop vectorization.
793 
794  // Cleanup after loop vectorization, etc. Simplification passes like CVP and
795  // GVN, loop transforms, and others have already run, so it's now better to
796  // convert to more optimized IR using more aggressive simplify CFG options.
797  // The extra sinking transform can create larger basic blocks, so do this
798  // before SLP vectorization.
800  forwardSwitchCondToPhi(true).
801  convertSwitchToLookupTable(true).
802  needCanonicalLoops(false).
803  sinkCommonInsts(true)));
804 
805  // Optimize parallel scalar instruction chains into SIMD instructions.
806  OptimizePM.addPass(SLPVectorizerPass());
807 
808  OptimizePM.addPass(InstCombinePass());
809 
810  // Unroll small loops to hide loop backedge latency and saturate any parallel
811  // execution resources of an out-of-order processor. We also then need to
812  // clean up redundancies and loop invariant code.
813  // FIXME: It would be really good to use a loop-integrated instruction
814  // combiner for cleanup here so that the unrolling and LICM can be pipelined
815  // across the loop nests.
816  // We do UnrollAndJam in a separate LPM to ensure it happens before unroll
817  if (EnableUnrollAndJam) {
818  OptimizePM.addPass(
820  }
821  OptimizePM.addPass(LoopUnrollPass(Level));
822  OptimizePM.addPass(InstCombinePass());
824  OptimizePM.addPass(createFunctionToLoopPassAdaptor(LICMPass(), DebugLogging));
825 
826  // Now that we've vectorized and unrolled loops, we may have more refined
827  // alignment information, try to re-derive it here.
829 
830  // LoopSink pass sinks instructions hoisted by LICM, which serves as a
831  // canonicalization pass that enables other optimizations. As a result,
832  // LoopSink pass needs to be a very late IR pass to avoid undoing LICM
833  // result too early.
834  OptimizePM.addPass(LoopSinkPass());
835 
836  // And finally clean up LCSSA form before generating code.
837  OptimizePM.addPass(InstSimplifyPass());
838 
839  // This hoists/decomposes div/rem ops. It should run after other sink/hoist
840  // passes to avoid re-sinking, but before SimplifyCFG because it can allow
841  // flattening of blocks.
842  OptimizePM.addPass(DivRemPairsPass());
843 
844  // LoopSink (and other loop passes since the last simplifyCFG) might have
845  // resulted in single-entry-single-exit or empty blocks. Clean up the CFG.
846  OptimizePM.addPass(SimplifyCFGPass());
847 
848  // Optimize PHIs by speculating around them when profitable. Note that this
849  // pass needs to be run after any PRE or similar pass as it is essentially
850  // inserting redudnancies into the progrem. This even includes SimplifyCFG.
851  OptimizePM.addPass(SpeculateAroundPHIsPass());
852 
853  // Add the core optimizing pipeline.
854  MPM.addPass(createModuleToFunctionPassAdaptor(std::move(OptimizePM)));
855 
856  MPM.addPass(CGProfilePass());
857 
858  // Now we need to do some global optimization transforms.
859  // FIXME: It would seem like these should come first in the optimization
860  // pipeline and maybe be the bottom of the canonicalization pipeline? Weird
861  // ordering here.
862  MPM.addPass(GlobalDCEPass());
863  MPM.addPass(ConstantMergePass());
864 
865  return MPM;
866 }
867 
870  bool DebugLogging) {
871  assert(Level != O0 && "Must request optimizations for the default pipeline!");
872 
873  ModulePassManager MPM(DebugLogging);
874 
875  // Force any function attributes we want the rest of the pipeline to observe.
877 
878  // Apply module pipeline start EP callback.
879  for (auto &C : PipelineStartEPCallbacks)
880  C(MPM);
881 
882  if (PGOOpt && PGOOpt->SamplePGOSupport)
884 
885  // Add the core simplification pipeline.
886  MPM.addPass(buildModuleSimplificationPipeline(Level, ThinLTOPhase::None,
887  DebugLogging));
888 
889  // Now add the optimization pipeline.
890  MPM.addPass(buildModuleOptimizationPipeline(Level, DebugLogging));
891 
892  return MPM;
893 }
894 
897  bool DebugLogging) {
898  assert(Level != O0 && "Must request optimizations for the default pipeline!");
899 
900  ModulePassManager MPM(DebugLogging);
901 
902  // Force any function attributes we want the rest of the pipeline to observe.
904 
905  if (PGOOpt && PGOOpt->SamplePGOSupport)
907 
908  // Apply module pipeline start EP callback.
909  for (auto &C : PipelineStartEPCallbacks)
910  C(MPM);
911 
912  // If we are planning to perform ThinLTO later, we don't bloat the code with
913  // unrolling/vectorization/... now. Just simplify the module as much as we
914  // can.
915  MPM.addPass(buildModuleSimplificationPipeline(Level, ThinLTOPhase::PreLink,
916  DebugLogging));
917 
918  // Run partial inlining pass to partially inline functions that have
919  // large bodies.
920  // FIXME: It isn't clear whether this is really the right place to run this
921  // in ThinLTO. Because there is another canonicalization and simplification
922  // phase that will run after the thin link, running this here ends up with
923  // less information than will be available later and it may grow functions in
924  // ways that aren't beneficial.
925  if (RunPartialInlining)
927 
928  // Reduce the size of the IR as much as possible.
929  MPM.addPass(GlobalOptPass());
930 
931  return MPM;
932 }
933 
935  OptimizationLevel Level, bool DebugLogging,
936  const ModuleSummaryIndex *ImportSummary) {
937  ModulePassManager MPM(DebugLogging);
938 
939  if (ImportSummary) {
940  // These passes import type identifier resolutions for whole-program
941  // devirtualization and CFI. They must run early because other passes may
942  // disturb the specific instruction patterns that these passes look for,
943  // creating dependencies on resolutions that may not appear in the summary.
944  //
945  // For example, GVN may transform the pattern assume(type.test) appearing in
946  // two basic blocks into assume(phi(type.test, type.test)), which would
947  // transform a dependency on a WPD resolution into a dependency on a type
948  // identifier resolution for CFI.
949  //
950  // Also, WPD has access to more precise information than ICP and can
951  // devirtualize more effectively, so it should operate on the IR first.
952  MPM.addPass(WholeProgramDevirtPass(nullptr, ImportSummary));
953  MPM.addPass(LowerTypeTestsPass(nullptr, ImportSummary));
954  }
955 
956  // Force any function attributes we want the rest of the pipeline to observe.
958 
959  // During the ThinLTO backend phase we perform early indirect call promotion
960  // here, before globalopt. Otherwise imported available_externally functions
961  // look unreferenced and are removed.
962  // FIXME: move this into buildModuleSimplificationPipeline to merge the logic
963  // with SamplePGO.
964  if (!PGOOpt || PGOOpt->SampleProfileFile.empty())
965  MPM.addPass(PGOIndirectCallPromotion(true /* InLTO */,
966  false /* SamplePGO */));
967 
968  // Add the core simplification pipeline.
969  MPM.addPass(buildModuleSimplificationPipeline(Level, ThinLTOPhase::PostLink,
970  DebugLogging));
971 
972  // Now add the optimization pipeline.
973  MPM.addPass(buildModuleOptimizationPipeline(Level, DebugLogging));
974 
975  return MPM;
976 }
977 
980  bool DebugLogging) {
981  assert(Level != O0 && "Must request optimizations for the default pipeline!");
982  // FIXME: We should use a customized pre-link pipeline!
983  return buildPerModuleDefaultPipeline(Level, DebugLogging);
984 }
985 
988  ModuleSummaryIndex *ExportSummary) {
989  assert(Level != O0 && "Must request optimizations for the default pipeline!");
990  ModulePassManager MPM(DebugLogging);
991 
992  // Remove unused virtual tables to improve the quality of code generated by
993  // whole-program devirtualization and bitset lowering.
994  MPM.addPass(GlobalDCEPass());
995 
996  // Force any function attributes we want the rest of the pipeline to observe.
998 
999  // Do basic inference of function attributes from known properties of system
1000  // libraries and other oracles.
1002 
1003  if (Level > 1) {
1004  FunctionPassManager EarlyFPM(DebugLogging);
1005  EarlyFPM.addPass(CallSiteSplittingPass());
1006  MPM.addPass(createModuleToFunctionPassAdaptor(std::move(EarlyFPM)));
1007 
1008  // Indirect call promotion. This should promote all the targets that are
1009  // left by the earlier promotion pass that promotes intra-module targets.
1010  // This two-step promotion is to save the compile time. For LTO, it should
1011  // produce the same result as if we only do promotion here.
1013  true /* InLTO */, PGOOpt && !PGOOpt->SampleProfileFile.empty()));
1014  // Propagate constants at call sites into the functions they call. This
1015  // opens opportunities for globalopt (and inlining) by substituting function
1016  // pointers passed as arguments to direct uses of functions.
1017  MPM.addPass(IPSCCPPass());
1018 
1019  // Attach metadata to indirect call sites indicating the set of functions
1020  // they may target at run-time. This should follow IPSCCP.
1022  }
1023 
1024  // Now deduce any function attributes based in the current code.
1027 
1028  // Do RPO function attribute inference across the module to forward-propagate
1029  // attributes where applicable.
1030  // FIXME: Is this really an optimization rather than a canonicalization?
1032 
1033  // Use inragne annotations on GEP indices to split globals where beneficial.
1034  MPM.addPass(GlobalSplitPass());
1035 
1036  // Run whole program optimization of virtual call when the list of callees
1037  // is fixed.
1038  MPM.addPass(WholeProgramDevirtPass(ExportSummary, nullptr));
1039 
1040  // Stop here at -O1.
1041  if (Level == 1) {
1042  // The LowerTypeTestsPass needs to run to lower type metadata and the
1043  // type.test intrinsics. The pass does nothing if CFI is disabled.
1044  MPM.addPass(LowerTypeTestsPass(ExportSummary, nullptr));
1045  return MPM;
1046  }
1047 
1048  // Optimize globals to try and fold them into constants.
1049  MPM.addPass(GlobalOptPass());
1050 
1051  // Promote any localized globals to SSA registers.
1053 
1054  // Linking modules together can lead to duplicate global constant, only
1055  // keep one copy of each constant.
1056  MPM.addPass(ConstantMergePass());
1057 
1058  // Remove unused arguments from functions.
1060 
1061  // Reduce the code after globalopt and ipsccp. Both can open up significant
1062  // simplification opportunities, and both can propagate functions through
1063  // function pointers. When this happens, we often have to resolve varargs
1064  // calls, etc, so let instcombine do this.
1065  FunctionPassManager PeepholeFPM(DebugLogging);
1066  if (Level == O3)
1067  PeepholeFPM.addPass(AggressiveInstCombinePass());
1068  PeepholeFPM.addPass(InstCombinePass());
1069  invokePeepholeEPCallbacks(PeepholeFPM, Level);
1070 
1071  MPM.addPass(createModuleToFunctionPassAdaptor(std::move(PeepholeFPM)));
1072 
1073  // Note: historically, the PruneEH pass was run first to deduce nounwind and
1074  // generally clean up exception handling overhead. It isn't clear this is
1075  // valuable as the inliner doesn't currently care whether it is inlining an
1076  // invoke or a call.
1077  // Run the inliner now.
1080 
1081  // Optimize globals again after we ran the inliner.
1082  MPM.addPass(GlobalOptPass());
1083 
1084  // Garbage collect dead functions.
1085  // FIXME: Add ArgumentPromotion pass after once it's ported.
1086  MPM.addPass(GlobalDCEPass());
1087 
1088  FunctionPassManager FPM(DebugLogging);
1089  // The IPO Passes may leave cruft around. Clean up after them.
1090  FPM.addPass(InstCombinePass());
1091  invokePeepholeEPCallbacks(FPM, Level);
1092 
1093  FPM.addPass(JumpThreadingPass());
1094 
1095  // Break up allocas
1096  FPM.addPass(SROA());
1097 
1098  // Run a few AA driver optimizations here and now to cleanup the code.
1099  MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
1100 
1103  // FIXME: here we run IP alias analysis in the legacy PM.
1104 
1105  FunctionPassManager MainFPM;
1106 
1107  // FIXME: once we fix LoopPass Manager, add LICM here.
1108  // FIXME: once we provide support for enabling MLSM, add it here.
1109  // FIXME: once we provide support for enabling NewGVN, add it here.
1110  if (RunNewGVN)
1111  MainFPM.addPass(NewGVNPass());
1112  else
1113  MainFPM.addPass(GVN());
1114 
1115  // Remove dead memcpy()'s.
1116  MainFPM.addPass(MemCpyOptPass());
1117 
1118  // Nuke dead stores.
1119  MainFPM.addPass(DSEPass());
1120 
1121  // FIXME: at this point, we run a bunch of loop passes:
1122  // indVarSimplify, loopDeletion, loopInterchange, loopUnrool,
1123  // loopVectorize. Enable them once the remaining issue with LPM
1124  // are sorted out.
1125 
1126  MainFPM.addPass(InstCombinePass());
1127  MainFPM.addPass(SimplifyCFGPass());
1128  MainFPM.addPass(SCCPPass());
1129  MainFPM.addPass(InstCombinePass());
1130  MainFPM.addPass(BDCEPass());
1131 
1132  // FIXME: We may want to run SLPVectorizer here.
1133  // After vectorization, assume intrinsics may tell us more
1134  // about pointer alignments.
1135 #if 0
1136  MainFPM.add(AlignmentFromAssumptionsPass());
1137 #endif
1138 
1139  // FIXME: Conditionally run LoadCombine here, after it's ported
1140  // (in case we still have this pass, given its questionable usefulness).
1141 
1142  MainFPM.addPass(InstCombinePass());
1143  invokePeepholeEPCallbacks(MainFPM, Level);
1144  MainFPM.addPass(JumpThreadingPass());
1145  MPM.addPass(createModuleToFunctionPassAdaptor(std::move(MainFPM)));
1146 
1147  // Create a function that performs CFI checks for cross-DSO calls with
1148  // targets in the current module.
1149  MPM.addPass(CrossDSOCFIPass());
1150 
1151  // Lower type metadata and the type.test intrinsic. This pass supports
1152  // clang's control flow integrity mechanisms (-fsanitize=cfi*) and needs
1153  // to be run at link time if CFI is enabled. This pass does nothing if
1154  // CFI is disabled.
1155  MPM.addPass(LowerTypeTestsPass(ExportSummary, nullptr));
1156 
1157  // Add late LTO optimization passes.
1158  // Delete basic blocks, which optimization passes may have killed.
1160 
1161  // Drop bodies of available eternally objects to improve GlobalDCE.
1163 
1164  // Now that we have optimized the program, discard unreachable functions.
1165  MPM.addPass(GlobalDCEPass());
1166 
1167  // FIXME: Enable MergeFuncs, conditionally, after ported, maybe.
1168  return MPM;
1169 }
1170 
1172  AAManager AA;
1173 
1174  // The order in which these are registered determines their priority when
1175  // being queried.
1176 
1177  // First we register the basic alias analysis that provides the majority of
1178  // per-function local AA logic. This is a stateless, on-demand local set of
1179  // AA techniques.
1181 
1182  // Next we query fast, specialized alias analyses that wrap IR-embedded
1183  // information about aliasing.
1186 
1187  // Add support for querying global aliasing information when available.
1188  // Because the `AAManager` is a function analysis and `GlobalsAA` is a module
1189  // analysis, all that the `AAManager` can do is query for any *cached*
1190  // results from `GlobalsAA` through a readonly proxy.
1192 
1193  return AA;
1194 }
1195 
1197  if (!Name.consume_front("repeat<") || !Name.consume_back(">"))
1198  return None;
1199  int Count;
1200  if (Name.getAsInteger(0, Count) || Count <= 0)
1201  return None;
1202  return Count;
1203 }
1204 
1206  if (!Name.consume_front("devirt<") || !Name.consume_back(">"))
1207  return None;
1208  int Count;
1209  if (Name.getAsInteger(0, Count) || Count <= 0)
1210  return None;
1211  return Count;
1212 }
1213 
1214 /// Tests whether a pass name starts with a valid prefix for a default pipeline
1215 /// alias.
1217  return Name.startswith("default") || Name.startswith("thinlto") ||
1218  Name.startswith("lto");
1219 }
1220 
1221 /// Tests whether registered callbacks will accept a given pass name.
1222 ///
1223 /// When parsing a pipeline text, the type of the outermost pipeline may be
1224 /// omitted, in which case the type is automatically determined from the first
1225 /// pass name in the text. This may be a name that is handled through one of the
1226 /// callbacks. We check this through the oridinary parsing callbacks by setting
1227 /// up a dummy PassManager in order to not force the client to also handle this
1228 /// type of query.
1229 template <typename PassManagerT, typename CallbacksT>
1230 static bool callbacksAcceptPassName(StringRef Name, CallbacksT &Callbacks) {
1231  if (!Callbacks.empty()) {
1232  PassManagerT DummyPM;
1233  for (auto &CB : Callbacks)
1234  if (CB(Name, DummyPM, {}))
1235  return true;
1236  }
1237  return false;
1238 }
1239 
1240 template <typename CallbacksT>
1241 static bool isModulePassName(StringRef Name, CallbacksT &Callbacks) {
1242  // Manually handle aliases for pre-configured pipeline fragments.
1244  return DefaultAliasRegex.match(Name);
1245 
1246  // Explicitly handle pass manager names.
1247  if (Name == "module")
1248  return true;
1249  if (Name == "cgscc")
1250  return true;
1251  if (Name == "function")
1252  return true;
1253 
1254  // Explicitly handle custom-parsed pass names.
1255  if (parseRepeatPassName(Name))
1256  return true;
1257 
1258 #define MODULE_PASS(NAME, CREATE_PASS) \
1259  if (Name == NAME) \
1260  return true;
1261 #define MODULE_ANALYSIS(NAME, CREATE_PASS) \
1262  if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
1263  return true;
1264 #include "PassRegistry.def"
1265 
1266  return callbacksAcceptPassName<ModulePassManager>(Name, Callbacks);
1267 }
1268 
1269 template <typename CallbacksT>
1270 static bool isCGSCCPassName(StringRef Name, CallbacksT &Callbacks) {
1271  // Explicitly handle pass manager names.
1272  if (Name == "cgscc")
1273  return true;
1274  if (Name == "function")
1275  return true;
1276 
1277  // Explicitly handle custom-parsed pass names.
1278  if (parseRepeatPassName(Name))
1279  return true;
1280  if (parseDevirtPassName(Name))
1281  return true;
1282 
1283 #define CGSCC_PASS(NAME, CREATE_PASS) \
1284  if (Name == NAME) \
1285  return true;
1286 #define CGSCC_ANALYSIS(NAME, CREATE_PASS) \
1287  if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
1288  return true;
1289 #include "PassRegistry.def"
1290 
1291  return callbacksAcceptPassName<CGSCCPassManager>(Name, Callbacks);
1292 }
1293 
1294 template <typename CallbacksT>
1295 static bool isFunctionPassName(StringRef Name, CallbacksT &Callbacks) {
1296  // Explicitly handle pass manager names.
1297  if (Name == "function")
1298  return true;
1299  if (Name == "loop")
1300  return true;
1301 
1302  // Explicitly handle custom-parsed pass names.
1303  if (parseRepeatPassName(Name))
1304  return true;
1305 
1306 #define FUNCTION_PASS(NAME, CREATE_PASS) \
1307  if (Name == NAME) \
1308  return true;
1309 #define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
1310  if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
1311  return true;
1312 #include "PassRegistry.def"
1313 
1314  return callbacksAcceptPassName<FunctionPassManager>(Name, Callbacks);
1315 }
1316 
1317 template <typename CallbacksT>
1318 static bool isLoopPassName(StringRef Name, CallbacksT &Callbacks) {
1319  // Explicitly handle pass manager names.
1320  if (Name == "loop")
1321  return true;
1322 
1323  // Explicitly handle custom-parsed pass names.
1324  if (parseRepeatPassName(Name))
1325  return true;
1326 
1327 #define LOOP_PASS(NAME, CREATE_PASS) \
1328  if (Name == NAME) \
1329  return true;
1330 #define LOOP_ANALYSIS(NAME, CREATE_PASS) \
1331  if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
1332  return true;
1333 #include "PassRegistry.def"
1334 
1335  return callbacksAcceptPassName<LoopPassManager>(Name, Callbacks);
1336 }
1337 
1339 PassBuilder::parsePipelineText(StringRef Text) {
1340  std::vector<PipelineElement> ResultPipeline;
1341 
1342  SmallVector<std::vector<PipelineElement> *, 4> PipelineStack = {
1343  &ResultPipeline};
1344  for (;;) {
1345  std::vector<PipelineElement> &Pipeline = *PipelineStack.back();
1346  size_t Pos = Text.find_first_of(",()");
1347  Pipeline.push_back({Text.substr(0, Pos), {}});
1348 
1349  // If we have a single terminating name, we're done.
1350  if (Pos == Text.npos)
1351  break;
1352 
1353  char Sep = Text[Pos];
1354  Text = Text.substr(Pos + 1);
1355  if (Sep == ',')
1356  // Just a name ending in a comma, continue.
1357  continue;
1358 
1359  if (Sep == '(') {
1360  // Push the inner pipeline onto the stack to continue processing.
1361  PipelineStack.push_back(&Pipeline.back().InnerPipeline);
1362  continue;
1363  }
1364 
1365  assert(Sep == ')' && "Bogus separator!");
1366  // When handling the close parenthesis, we greedily consume them to avoid
1367  // empty strings in the pipeline.
1368  do {
1369  // If we try to pop the outer pipeline we have unbalanced parentheses.
1370  if (PipelineStack.size() == 1)
1371  return None;
1372 
1373  PipelineStack.pop_back();
1374  } while (Text.consume_front(")"));
1375 
1376  // Check if we've finished parsing.
1377  if (Text.empty())
1378  break;
1379 
1380  // Otherwise, the end of an inner pipeline always has to be followed by
1381  // a comma, and then we can continue.
1382  if (!Text.consume_front(","))
1383  return None;
1384  }
1385 
1386  if (PipelineStack.size() > 1)
1387  // Unbalanced paretheses.
1388  return None;
1389 
1390  assert(PipelineStack.back() == &ResultPipeline &&
1391  "Wrong pipeline at the bottom of the stack!");
1392  return {std::move(ResultPipeline)};
1393 }
1394 
1395 bool PassBuilder::parseModulePass(ModulePassManager &MPM,
1396  const PipelineElement &E, bool VerifyEachPass,
1397  bool DebugLogging) {
1398  auto &Name = E.Name;
1399  auto &InnerPipeline = E.InnerPipeline;
1400 
1401  // First handle complex passes like the pass managers which carry pipelines.
1402  if (!InnerPipeline.empty()) {
1403  if (Name == "module") {
1404  ModulePassManager NestedMPM(DebugLogging);
1405  if (!parseModulePassPipeline(NestedMPM, InnerPipeline, VerifyEachPass,
1406  DebugLogging))
1407  return false;
1408  MPM.addPass(std::move(NestedMPM));
1409  return true;
1410  }
1411  if (Name == "cgscc") {
1412  CGSCCPassManager CGPM(DebugLogging);
1413  if (!parseCGSCCPassPipeline(CGPM, InnerPipeline, VerifyEachPass,
1414  DebugLogging))
1415  return false;
1416  MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(std::move(CGPM)));
1417  return true;
1418  }
1419  if (Name == "function") {
1420  FunctionPassManager FPM(DebugLogging);
1421  if (!parseFunctionPassPipeline(FPM, InnerPipeline, VerifyEachPass,
1422  DebugLogging))
1423  return false;
1424  MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
1425  return true;
1426  }
1427  if (auto Count = parseRepeatPassName(Name)) {
1428  ModulePassManager NestedMPM(DebugLogging);
1429  if (!parseModulePassPipeline(NestedMPM, InnerPipeline, VerifyEachPass,
1430  DebugLogging))
1431  return false;
1432  MPM.addPass(createRepeatedPass(*Count, std::move(NestedMPM)));
1433  return true;
1434  }
1435 
1436  for (auto &C : ModulePipelineParsingCallbacks)
1437  if (C(Name, MPM, InnerPipeline))
1438  return true;
1439 
1440  // Normal passes can't have pipelines.
1441  return false;
1442  }
1443 
1444  // Manually handle aliases for pre-configured pipeline fragments.
1446  SmallVector<StringRef, 3> Matches;
1447  if (!DefaultAliasRegex.match(Name, &Matches))
1448  return false;
1449  assert(Matches.size() == 3 && "Must capture two matched strings!");
1450 
1451  OptimizationLevel L = StringSwitch<OptimizationLevel>(Matches[2])
1452  .Case("O0", O0)
1453  .Case("O1", O1)
1454  .Case("O2", O2)
1455  .Case("O3", O3)
1456  .Case("Os", Os)
1457  .Case("Oz", Oz);
1458  if (L == O0)
1459  // At O0 we do nothing at all!
1460  return true;
1461 
1462  if (Matches[1] == "default") {
1463  MPM.addPass(buildPerModuleDefaultPipeline(L, DebugLogging));
1464  } else if (Matches[1] == "thinlto-pre-link") {
1465  MPM.addPass(buildThinLTOPreLinkDefaultPipeline(L, DebugLogging));
1466  } else if (Matches[1] == "thinlto") {
1467  MPM.addPass(buildThinLTODefaultPipeline(L, DebugLogging, nullptr));
1468  } else if (Matches[1] == "lto-pre-link") {
1469  MPM.addPass(buildLTOPreLinkDefaultPipeline(L, DebugLogging));
1470  } else {
1471  assert(Matches[1] == "lto" && "Not one of the matched options!");
1472  MPM.addPass(buildLTODefaultPipeline(L, DebugLogging, nullptr));
1473  }
1474  return true;
1475  }
1476 
1477  // Finally expand the basic registered passes from the .inc file.
1478 #define MODULE_PASS(NAME, CREATE_PASS) \
1479  if (Name == NAME) { \
1480  MPM.addPass(CREATE_PASS); \
1481  return true; \
1482  }
1483 #define MODULE_ANALYSIS(NAME, CREATE_PASS) \
1484  if (Name == "require<" NAME ">") { \
1485  MPM.addPass( \
1486  RequireAnalysisPass< \
1487  std::remove_reference<decltype(CREATE_PASS)>::type, Module>()); \
1488  return true; \
1489  } \
1490  if (Name == "invalidate<" NAME ">") { \
1491  MPM.addPass(InvalidateAnalysisPass< \
1492  std::remove_reference<decltype(CREATE_PASS)>::type>()); \
1493  return true; \
1494  }
1495 #include "PassRegistry.def"
1496 
1497  for (auto &C : ModulePipelineParsingCallbacks)
1498  if (C(Name, MPM, InnerPipeline))
1499  return true;
1500  return false;
1501 }
1502 
1503 bool PassBuilder::parseCGSCCPass(CGSCCPassManager &CGPM,
1504  const PipelineElement &E, bool VerifyEachPass,
1505  bool DebugLogging) {
1506  auto &Name = E.Name;
1507  auto &InnerPipeline = E.InnerPipeline;
1508 
1509  // First handle complex passes like the pass managers which carry pipelines.
1510  if (!InnerPipeline.empty()) {
1511  if (Name == "cgscc") {
1512  CGSCCPassManager NestedCGPM(DebugLogging);
1513  if (!parseCGSCCPassPipeline(NestedCGPM, InnerPipeline, VerifyEachPass,
1514  DebugLogging))
1515  return false;
1516  // Add the nested pass manager with the appropriate adaptor.
1517  CGPM.addPass(std::move(NestedCGPM));
1518  return true;
1519  }
1520  if (Name == "function") {
1521  FunctionPassManager FPM(DebugLogging);
1522  if (!parseFunctionPassPipeline(FPM, InnerPipeline, VerifyEachPass,
1523  DebugLogging))
1524  return false;
1525  // Add the nested pass manager with the appropriate adaptor.
1526  CGPM.addPass(createCGSCCToFunctionPassAdaptor(std::move(FPM)));
1527  return true;
1528  }
1529  if (auto Count = parseRepeatPassName(Name)) {
1530  CGSCCPassManager NestedCGPM(DebugLogging);
1531  if (!parseCGSCCPassPipeline(NestedCGPM, InnerPipeline, VerifyEachPass,
1532  DebugLogging))
1533  return false;
1534  CGPM.addPass(createRepeatedPass(*Count, std::move(NestedCGPM)));
1535  return true;
1536  }
1537  if (auto MaxRepetitions = parseDevirtPassName(Name)) {
1538  CGSCCPassManager NestedCGPM(DebugLogging);
1539  if (!parseCGSCCPassPipeline(NestedCGPM, InnerPipeline, VerifyEachPass,
1540  DebugLogging))
1541  return false;
1542  CGPM.addPass(
1543  createDevirtSCCRepeatedPass(std::move(NestedCGPM), *MaxRepetitions));
1544  return true;
1545  }
1546 
1547  for (auto &C : CGSCCPipelineParsingCallbacks)
1548  if (C(Name, CGPM, InnerPipeline))
1549  return true;
1550 
1551  // Normal passes can't have pipelines.
1552  return false;
1553  }
1554 
1555 // Now expand the basic registered passes from the .inc file.
1556 #define CGSCC_PASS(NAME, CREATE_PASS) \
1557  if (Name == NAME) { \
1558  CGPM.addPass(CREATE_PASS); \
1559  return true; \
1560  }
1561 #define CGSCC_ANALYSIS(NAME, CREATE_PASS) \
1562  if (Name == "require<" NAME ">") { \
1563  CGPM.addPass(RequireAnalysisPass< \
1564  std::remove_reference<decltype(CREATE_PASS)>::type, \
1565  LazyCallGraph::SCC, CGSCCAnalysisManager, LazyCallGraph &, \
1566  CGSCCUpdateResult &>()); \
1567  return true; \
1568  } \
1569  if (Name == "invalidate<" NAME ">") { \
1570  CGPM.addPass(InvalidateAnalysisPass< \
1571  std::remove_reference<decltype(CREATE_PASS)>::type>()); \
1572  return true; \
1573  }
1574 #include "PassRegistry.def"
1575 
1576  for (auto &C : CGSCCPipelineParsingCallbacks)
1577  if (C(Name, CGPM, InnerPipeline))
1578  return true;
1579  return false;
1580 }
1581 
1582 bool PassBuilder::parseFunctionPass(FunctionPassManager &FPM,
1583  const PipelineElement &E,
1584  bool VerifyEachPass, bool DebugLogging) {
1585  auto &Name = E.Name;
1586  auto &InnerPipeline = E.InnerPipeline;
1587 
1588  // First handle complex passes like the pass managers which carry pipelines.
1589  if (!InnerPipeline.empty()) {
1590  if (Name == "function") {
1591  FunctionPassManager NestedFPM(DebugLogging);
1592  if (!parseFunctionPassPipeline(NestedFPM, InnerPipeline, VerifyEachPass,
1593  DebugLogging))
1594  return false;
1595  // Add the nested pass manager with the appropriate adaptor.
1596  FPM.addPass(std::move(NestedFPM));
1597  return true;
1598  }
1599  if (Name == "loop") {
1600  LoopPassManager LPM(DebugLogging);
1601  if (!parseLoopPassPipeline(LPM, InnerPipeline, VerifyEachPass,
1602  DebugLogging))
1603  return false;
1604  // Add the nested pass manager with the appropriate adaptor.
1605  FPM.addPass(
1606  createFunctionToLoopPassAdaptor(std::move(LPM), DebugLogging));
1607  return true;
1608  }
1609  if (auto Count = parseRepeatPassName(Name)) {
1610  FunctionPassManager NestedFPM(DebugLogging);
1611  if (!parseFunctionPassPipeline(NestedFPM, InnerPipeline, VerifyEachPass,
1612  DebugLogging))
1613  return false;
1614  FPM.addPass(createRepeatedPass(*Count, std::move(NestedFPM)));
1615  return true;
1616  }
1617 
1618  for (auto &C : FunctionPipelineParsingCallbacks)
1619  if (C(Name, FPM, InnerPipeline))
1620  return true;
1621 
1622  // Normal passes can't have pipelines.
1623  return false;
1624  }
1625 
1626 // Now expand the basic registered passes from the .inc file.
1627 #define FUNCTION_PASS(NAME, CREATE_PASS) \
1628  if (Name == NAME) { \
1629  FPM.addPass(CREATE_PASS); \
1630  return true; \
1631  }
1632 #define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
1633  if (Name == "require<" NAME ">") { \
1634  FPM.addPass( \
1635  RequireAnalysisPass< \
1636  std::remove_reference<decltype(CREATE_PASS)>::type, Function>()); \
1637  return true; \
1638  } \
1639  if (Name == "invalidate<" NAME ">") { \
1640  FPM.addPass(InvalidateAnalysisPass< \
1641  std::remove_reference<decltype(CREATE_PASS)>::type>()); \
1642  return true; \
1643  }
1644 #include "PassRegistry.def"
1645 
1646  for (auto &C : FunctionPipelineParsingCallbacks)
1647  if (C(Name, FPM, InnerPipeline))
1648  return true;
1649  return false;
1650 }
1651 
1652 bool PassBuilder::parseLoopPass(LoopPassManager &LPM, const PipelineElement &E,
1653  bool VerifyEachPass, bool DebugLogging) {
1654  StringRef Name = E.Name;
1655  auto &InnerPipeline = E.InnerPipeline;
1656 
1657  // First handle complex passes like the pass managers which carry pipelines.
1658  if (!InnerPipeline.empty()) {
1659  if (Name == "loop") {
1660  LoopPassManager NestedLPM(DebugLogging);
1661  if (!parseLoopPassPipeline(NestedLPM, InnerPipeline, VerifyEachPass,
1662  DebugLogging))
1663  return false;
1664  // Add the nested pass manager with the appropriate adaptor.
1665  LPM.addPass(std::move(NestedLPM));
1666  return true;
1667  }
1668  if (auto Count = parseRepeatPassName(Name)) {
1669  LoopPassManager NestedLPM(DebugLogging);
1670  if (!parseLoopPassPipeline(NestedLPM, InnerPipeline, VerifyEachPass,
1671  DebugLogging))
1672  return false;
1673  LPM.addPass(createRepeatedPass(*Count, std::move(NestedLPM)));
1674  return true;
1675  }
1676 
1677  for (auto &C : LoopPipelineParsingCallbacks)
1678  if (C(Name, LPM, InnerPipeline))
1679  return true;
1680 
1681  // Normal passes can't have pipelines.
1682  return false;
1683  }
1684 
1685 // Now expand the basic registered passes from the .inc file.
1686 #define LOOP_PASS(NAME, CREATE_PASS) \
1687  if (Name == NAME) { \
1688  LPM.addPass(CREATE_PASS); \
1689  return true; \
1690  }
1691 #define LOOP_ANALYSIS(NAME, CREATE_PASS) \
1692  if (Name == "require<" NAME ">") { \
1693  LPM.addPass(RequireAnalysisPass< \
1694  std::remove_reference<decltype(CREATE_PASS)>::type, Loop, \
1695  LoopAnalysisManager, LoopStandardAnalysisResults &, \
1696  LPMUpdater &>()); \
1697  return true; \
1698  } \
1699  if (Name == "invalidate<" NAME ">") { \
1700  LPM.addPass(InvalidateAnalysisPass< \
1701  std::remove_reference<decltype(CREATE_PASS)>::type>()); \
1702  return true; \
1703  }
1704 #include "PassRegistry.def"
1705 
1706  for (auto &C : LoopPipelineParsingCallbacks)
1707  if (C(Name, LPM, InnerPipeline))
1708  return true;
1709  return false;
1710 }
1711 
1712 bool PassBuilder::parseAAPassName(AAManager &AA, StringRef Name) {
1713 #define MODULE_ALIAS_ANALYSIS(NAME, CREATE_PASS) \
1714  if (Name == NAME) { \
1715  AA.registerModuleAnalysis< \
1716  std::remove_reference<decltype(CREATE_PASS)>::type>(); \
1717  return true; \
1718  }
1719 #define FUNCTION_ALIAS_ANALYSIS(NAME, CREATE_PASS) \
1720  if (Name == NAME) { \
1721  AA.registerFunctionAnalysis< \
1722  std::remove_reference<decltype(CREATE_PASS)>::type>(); \
1723  return true; \
1724  }
1725 #include "PassRegistry.def"
1726 
1727  for (auto &C : AAParsingCallbacks)
1728  if (C(Name, AA))
1729  return true;
1730  return false;
1731 }
1732 
1733 bool PassBuilder::parseLoopPassPipeline(LoopPassManager &LPM,
1734  ArrayRef<PipelineElement> Pipeline,
1735  bool VerifyEachPass,
1736  bool DebugLogging) {
1737  for (const auto &Element : Pipeline) {
1738  if (!parseLoopPass(LPM, Element, VerifyEachPass, DebugLogging))
1739  return false;
1740  // FIXME: No verifier support for Loop passes!
1741  }
1742  return true;
1743 }
1744 
1745 bool PassBuilder::parseFunctionPassPipeline(FunctionPassManager &FPM,
1746  ArrayRef<PipelineElement> Pipeline,
1747  bool VerifyEachPass,
1748  bool DebugLogging) {
1749  for (const auto &Element : Pipeline) {
1750  if (!parseFunctionPass(FPM, Element, VerifyEachPass, DebugLogging))
1751  return false;
1752  if (VerifyEachPass)
1753  FPM.addPass(VerifierPass());
1754  }
1755  return true;
1756 }
1757 
1758 bool PassBuilder::parseCGSCCPassPipeline(CGSCCPassManager &CGPM,
1759  ArrayRef<PipelineElement> Pipeline,
1760  bool VerifyEachPass,
1761  bool DebugLogging) {
1762  for (const auto &Element : Pipeline) {
1763  if (!parseCGSCCPass(CGPM, Element, VerifyEachPass, DebugLogging))
1764  return false;
1765  // FIXME: No verifier support for CGSCC passes!
1766  }
1767  return true;
1768 }
1769 
1772  CGSCCAnalysisManager &CGAM,
1773  ModuleAnalysisManager &MAM) {
1774  MAM.registerPass([&] { return FunctionAnalysisManagerModuleProxy(FAM); });
1775  MAM.registerPass([&] { return CGSCCAnalysisManagerModuleProxy(CGAM); });
1776  CGAM.registerPass([&] { return ModuleAnalysisManagerCGSCCProxy(MAM); });
1777  FAM.registerPass([&] { return CGSCCAnalysisManagerFunctionProxy(CGAM); });
1778  FAM.registerPass([&] { return ModuleAnalysisManagerFunctionProxy(MAM); });
1779  FAM.registerPass([&] { return LoopAnalysisManagerFunctionProxy(LAM); });
1780  LAM.registerPass([&] { return FunctionAnalysisManagerLoopProxy(FAM); });
1781 }
1782 
1783 bool PassBuilder::parseModulePassPipeline(ModulePassManager &MPM,
1784  ArrayRef<PipelineElement> Pipeline,
1785  bool VerifyEachPass,
1786  bool DebugLogging) {
1787  for (const auto &Element : Pipeline) {
1788  if (!parseModulePass(MPM, Element, VerifyEachPass, DebugLogging))
1789  return false;
1790  if (VerifyEachPass)
1791  MPM.addPass(VerifierPass());
1792  }
1793  return true;
1794 }
1795 
1796 // Primary pass pipeline description parsing routine for a \c ModulePassManager
1797 // FIXME: Should this routine accept a TargetMachine or require the caller to
1798 // pre-populate the analysis managers with target-specific stuff?
1800  StringRef PipelineText, bool VerifyEachPass,
1801  bool DebugLogging) {
1802  auto Pipeline = parsePipelineText(PipelineText);
1803  if (!Pipeline || Pipeline->empty())
1804  return false;
1805 
1806  // If the first name isn't at the module layer, wrap the pipeline up
1807  // automatically.
1808  StringRef FirstName = Pipeline->front().Name;
1809 
1810  if (!isModulePassName(FirstName, ModulePipelineParsingCallbacks)) {
1811  if (isCGSCCPassName(FirstName, CGSCCPipelineParsingCallbacks)) {
1812  Pipeline = {{"cgscc", std::move(*Pipeline)}};
1813  } else if (isFunctionPassName(FirstName,
1814  FunctionPipelineParsingCallbacks)) {
1815  Pipeline = {{"function", std::move(*Pipeline)}};
1816  } else if (isLoopPassName(FirstName, LoopPipelineParsingCallbacks)) {
1817  Pipeline = {{"function", {{"loop", std::move(*Pipeline)}}}};
1818  } else {
1819  for (auto &C : TopLevelPipelineParsingCallbacks)
1820  if (C(MPM, *Pipeline, VerifyEachPass, DebugLogging))
1821  return true;
1822 
1823  // Unknown pass name!
1824  return false;
1825  }
1826  }
1827 
1828  return parseModulePassPipeline(MPM, *Pipeline, VerifyEachPass, DebugLogging);
1829 }
1830 
1831 // Primary pass pipeline description parsing routine for a \c CGSCCPassManager
1833  StringRef PipelineText, bool VerifyEachPass,
1834  bool DebugLogging) {
1835  auto Pipeline = parsePipelineText(PipelineText);
1836  if (!Pipeline || Pipeline->empty())
1837  return false;
1838 
1839  StringRef FirstName = Pipeline->front().Name;
1840  if (!isCGSCCPassName(FirstName, CGSCCPipelineParsingCallbacks))
1841  return false;
1842 
1843  return parseCGSCCPassPipeline(CGPM, *Pipeline, VerifyEachPass, DebugLogging);
1844 }
1845 
1846 // Primary pass pipeline description parsing routine for a \c
1847 // FunctionPassManager
1849  StringRef PipelineText, bool VerifyEachPass,
1850  bool DebugLogging) {
1851  auto Pipeline = parsePipelineText(PipelineText);
1852  if (!Pipeline || Pipeline->empty())
1853  return false;
1854 
1855  StringRef FirstName = Pipeline->front().Name;
1856  if (!isFunctionPassName(FirstName, FunctionPipelineParsingCallbacks))
1857  return false;
1858 
1859  return parseFunctionPassPipeline(FPM, *Pipeline, VerifyEachPass,
1860  DebugLogging);
1861 }
1862 
1863 // Primary pass pipeline description parsing routine for a \c LoopPassManager
1865  StringRef PipelineText, bool VerifyEachPass,
1866  bool DebugLogging) {
1867  auto Pipeline = parsePipelineText(PipelineText);
1868  if (!Pipeline || Pipeline->empty())
1869  return false;
1870 
1871  return parseLoopPassPipeline(CGPM, *Pipeline, VerifyEachPass, DebugLogging);
1872 }
1873 
1875  // If the pipeline just consists of the word 'default' just replace the AA
1876  // manager with our default one.
1877  if (PipelineText == "default") {
1878  AA = buildDefaultAAPipeline();
1879  return true;
1880  }
1881 
1882  while (!PipelineText.empty()) {
1883  StringRef Name;
1884  std::tie(Name, PipelineText) = PipelineText.split(',');
1885  if (!parseAAPassName(AA, Name))
1886  return false;
1887  }
1888 
1889  return true;
1890 }
Super simple passes to force specific function attrs from the commandline into the IR for debugging p...
Defines passes for running instruction simplification across chunks of IR.
This file provides the interface for the pass responsible for both simplifying and canonicalizing the...
const T & front() const
front - Get the first element.
Definition: ArrayRef.h:152
Analysis pass providing a never-invalidated alias analysis result.
uint64_t CallInst * C
Computes function attributes in post-order over the call graph.
Definition: FunctionAttrs.h:51
A simple loop rotation transformation.
Definition: LoopRotation.h:24
A simple and fast domtree-based CSE pass.
Definition: EarlyCSE.h:31
The profile annotation (profile-instr-use) pass for IR based PGO.
Thresholds to tune inline cost analysis.
Definition: InlineCost.h:155
Interfaces for registering analysis passes, producing common pass manager configurations, and parsing of pass pipelines.
AAManager buildDefaultAAPipeline()
Build the default AAManager with the default alias analysis pipeline registered.
Eliminate dead arguments (and return values) from functions.
This is the interface for LLVM&#39;s inclusion-based alias analysis implemented with CFL graph reachabili...
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
static Optional< int > parseRepeatPassName(StringRef Name)
This header provides classes for managing a pipeline of passes over loops in LLVM IR...
This is the interface for a simple mod/ref and alias analysis over globals.
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:64
This is the interface to build a ModuleSummaryIndex for a module.
Uses an "inverted" value numbering to decide the similarity of expressions and sinks similar expressi...
Definition: GVN.h:300
InnerAnalysisManagerProxy< LoopAnalysisManager, Function > LoopAnalysisManagerFunctionProxy
A proxy from a LoopAnalysisManager to a Function.
Performs basic CFG simplifications to assist other loop passes.
This file provides the interface for LLVM&#39;s Scalar Replacement of Aggregates pass.
This file implements a simple N^2 alias analysis accuracy evaluator.
InnerAnalysisManagerProxy< CGSCCAnalysisManager, Module > CGSCCAnalysisManagerModuleProxy
A proxy from a CGSCCAnalysisManager to a Module.
Implements a lazy call graph analysis and related passes for the new pass manager.
RepeatedPass< PassT > createRepeatedPass(int Count, PassT P)
Definition: PassManager.h:1437
void registerModuleAnalyses(ModuleAnalysisManager &MAM)
Registers all available module analysis passes.
This is the interface for a metadata-based scoped no-alias analysis.
void registerModuleAnalysis()
Register a specific AA result.
ModuleToPostOrderCGSCCPassAdaptor< CGSCCPassT > createModuleToPostOrderCGSCCPassAdaptor(CGSCCPassT Pass)
A function to deduce a function pass type and wrap it in the templated adaptor.
CGSCCToFunctionPassAdaptor< FunctionPassT > createCGSCCToFunctionPassAdaptor(FunctionPassT Pass)
A function to deduce a function pass type and wrap it in the templated adaptor.
Pass to remove unused function declarations.
OptimizationLevel
LLVM-provided high-level optimization levels.
Definition: PassBuilder.h:93
ModulePassManager buildThinLTOPreLinkDefaultPipeline(OptimizationLevel Level, bool DebugLogging=false)
Build a pre-link, ThinLTO-targeting default optimization pipeline to a pass manager.
This file provides the interface for LLVM&#39;s PGO Instrumentation lowering pass.
OuterAnalysisManagerProxy< FunctionAnalysisManager, Loop, LoopStandardAnalysisResults & > FunctionAnalysisManagerLoopProxy
A proxy from a FunctionAnalysisManager to a Loop.
static cl::opt< bool > EnableEarlyCSEMemSSA("enable-npm-earlycse-memssa", cl::init(true), cl::Hidden, cl::desc("Enable the EarlyCSE w/ MemorySSA pass for the new PM (default = on)"))
The adaptor from a function pass to a loop pass computes these analyses and makes them available to t...
F(f)
Loop unroll pass that only does full loop unrolling.
Loop unroll pass that will support both full and partial unrolling.
Pass to perform split of global variables.
Definition: GlobalSplit.h:27
This pass transforms loops that contain branches or switches on loop- invariant conditions to have mu...
A DCE pass that assumes instructions are dead until proven otherwise.
Definition: ADCE.h:32
static cl::opt< bool > EnableSyntheticCounts("enable-npm-synthetic-counts", cl::init(false), cl::Hidden, cl::ZeroOrMore, cl::desc("Run synthetic function entry count generation " "pass"))
A utility pass template to force an analysis result to be available.
Definition: PassManager.h:1349
Reassociate commutative expressions.
Definition: Reassociate.h:72
Support structure for SCC passes to communicate updates the call graph back to the CGSCC pass manager...
Run instruction simplification across each instruction in the function.
Pass to forward loads in a loop around the backedge to subsequent iterations.
A pass that transforms external global definitions into declarations.
This pass handles simple speculating of instructions around PHIs when doing so is profitable for a pa...
A simple and fast domtree-based GVN pass to hoist common expressions from sibling branches...
Definition: GVN.h:293
This is the interface for a SCEV-based alias analysis.
ModulePassManager buildModuleSimplificationPipeline(OptimizationLevel Level, ThinLTOPhase Phase, bool DebugLogging=false)
Construct the core LLVM module canonicalization and simplification pipeline.
A pass to do RPO deduction and propagation of function attributes.
Definition: FunctionAttrs.h:70
Optional< int > HintThreshold
Threshold to use for callees with inline hint.
Definition: InlineCost.h:160
bool parseAAPipeline(AAManager &AA, StringRef PipelineText)
Parse a textual alias analysis pipeline into the provided AA manager.
LLVM_ATTRIBUTE_ALWAYS_INLINE bool consume_back(StringRef Suffix)
Returns true if this StringRef has the given suffix and removes that suffix.
Definition: StringRef.h:689
Similar to O2 but tries to optimize for small code size instead of fast execution without triggering ...
Definition: PassBuilder.h:163
Instrumentation based profiling lowering pass.
bool registerPass(PassBuilderT &&PassBuilder)
Register an analysis pass with the manager.
Definition: PassManager.h:822
static cl::opt< bool > EnableGVNSink("enable-npm-gvn-sink", cl::init(false), cl::Hidden, cl::desc("Enable the GVN hoisting pass for the new PM (default = off)"))
InnerAnalysisManagerProxy< FunctionAnalysisManager, Module > FunctionAnalysisManagerModuleProxy
Provide the FunctionAnalysisManager to Module proxy.
Definition: PassManager.h:1121
Hoist/decompose integer division and remainder instructions to enable CFG improvements and better cod...
Definition: DivRemPairs.h:24
OuterAnalysisManagerProxy< CGSCCAnalysisManager, Function > CGSCCAnalysisManagerFunctionProxy
A proxy from a CGSCCAnalysisManager to a Function.
void registerLoopAnalyses(LoopAnalysisManager &LAM)
Registers all available loop analysis passes.
Key
PAL metadata keys.
A very specialized mode that will optimize for code size at any and all costs.
Definition: PassBuilder.h:172
This file provides interfaces used to build and manipulate a call graph, which is a very useful tool ...
The sample profiler data loader pass.
Definition: SampleProfile.h:26
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
Definition: StringRef.h:267
FunctionToLoopPassAdaptor< LoopPassT > createFunctionToLoopPassAdaptor(LoopPassT Pass, bool DebugLogging=false)
A function to deduce a loop pass type and wrap it in the templated adaptor.
This file provides the interface for IR based instrumentation passes ( (profile-gen, and profile-use).
LLVM_ATTRIBUTE_ALWAYS_INLINE bool consume_front(StringRef Prefix)
Returns true if this StringRef has the given prefix and removes that prefix.
Definition: StringRef.h:678
static bool isModulePassName(StringRef Name, CallbacksT &Callbacks)
falkor hwpf fix Falkor HW Prefetch Fix Late Phase
This file provides the interface for a simple, fast CSE pass.
This file provides the interface for the GCOV style profiler pass.
Performs Loop Invariant Code Motion Pass.
Definition: LICM.h:43
The core GVN pass object.
Definition: GVN.h:68
void crossRegisterProxies(LoopAnalysisManager &LAM, FunctionAnalysisManager &FAM, CGSCCAnalysisManager &CGAM, ModuleAnalysisManager &MAM)
Cross register the analysis managers through their proxies.
Pass to remove unused function declarations.
Definition: GlobalDCE.h:30
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:133
A lazily constructed view of the call graph of a module.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:33
A pass that does profile-guided sinking of instructions into loops.
Definition: LoopSink.h:34
void registerFunctionAnalysis()
Register a specific AA result.
This class implements a trivial dead store elimination.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
Definition: StringRef.h:598
Class to hold module path string table and global value map, and encapsulate methods for operating on...
Argument promotion pass.
OuterAnalysisManagerProxy< ModuleAnalysisManager, LazyCallGraph::SCC, LazyCallGraph & > ModuleAnalysisManagerCGSCCProxy
A proxy from a ModuleAnalysisManager to an SCC.
Pass to perform interprocedural constant propagation.
Definition: SCCP.h:31
A pass which infers function attributes from the names and signatures of function declarations in a m...
static cl::opt< unsigned > MaxDevirtIterations("pm-max-devirt-iterations", cl::ReallyHidden, cl::init(4))
A switch()-like statement whose cases are string literals.
Definition: StringSwitch.h:43
This is the interface for LLVM&#39;s unification-based alias analysis implemented with CFL graph reachabi...
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:410
static bool isOptimizingForSize(PassBuilder::OptimizationLevel Level)
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:154
This is the interface for a metadata-based TBAA.
static Regex DefaultAliasRegex("^(default|thinlto-pre-link|thinlto|lto-pre-link|lto)<(O[0123sz])>$")
ModuleToFunctionPassAdaptor< FunctionPassT > createModuleToFunctionPassAdaptor(FunctionPassT Pass)
A function to deduce a function pass type and wrap it in the templated adaptor.
Definition: PassManager.h:1333
This file provides the interface for LLVM&#39;s Global Value Numbering pass which eliminates fully redund...
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file provides the primary interface to the instcombine pass.
Disable as many optimizations as possible.
Definition: PassBuilder.h:97
FunctionPassManager buildFunctionSimplificationPipeline(OptimizationLevel Level, ThinLTOPhase Phase, bool DebugLogging=false)
Construct the core LLVM function canonicalization and simplification pipeline.
A manager for alias analyses.
ModulePassManager buildLTOPreLinkDefaultPipeline(OptimizationLevel Level, bool DebugLogging=false)
Build a pre-link, LTO-targeting default optimization pipeline to a pass manager.
A CRTP mix-in that provides informational APIs needed for analysis passes.
Definition: PassManager.h:383
static bool isFunctionPassName(StringRef Name, CallbacksT &Callbacks)
The inliner pass for the new pass manager.
Definition: Inliner.h:95
void registerFunctionAnalyses(FunctionAnalysisManager &FAM)
Registers all available function analysis passes.
Analysis pass providing a never-invalidated alias analysis result.
This file provides the interface for LLVM&#39;s Global Value Numbering pass.
ThinLTOPhase
ThinLTO phase.
Definition: PassBuilder.h:80
Optimize for fast execution as much as possible.
Definition: PassBuilder.h:151
ModulePassManager buildModuleOptimizationPipeline(OptimizationLevel Level, bool DebugLogging=false)
Construct the core LLVM module optimization pipeline.
static cl::opt< bool > EnableCHR("enable-chr-npm", cl::init(true), cl::Hidden, cl::desc("Enable control height reduction optimization (CHR)"))
DevirtSCCRepeatedPass< PassT > createDevirtSCCRepeatedPass(PassT Pass, int MaxIterations)
A function to deduce a function pass type and wrap it in the templated adaptor.
A simple loop rotation transformation.
static bool callbacksAcceptPassName(StringRef Name, CallbacksT &Callbacks)
Tests whether registered callbacks will accept a given pass name.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition: PassManager.h:160
std::string InstrProfileOutput
size_t size() const
Definition: SmallVector.h:53
Create a verifier pass.
Definition: Verifier.h:137
ModulePassManager buildThinLTODefaultPipeline(OptimizationLevel Level, bool DebugLogging, const ModuleSummaryIndex *ImportSummary)
Build an ThinLTO default optimization pipeline to a pass manager.
static cl::opt< bool > EnableUnrollAndJam("enable-npm-unroll-and-jam", cl::init(false), cl::Hidden, cl::desc("Enable the Unroll and Jam pass for the new PM (default = off)"))
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
std::enable_if< std::numeric_limits< T >::is_signed, bool >::type getAsInteger(unsigned Radix, T &Result) const
Parse the current string as an integer of the specified radix.
Definition: StringRef.h:497
This file provides the interface for LLVM&#39;s Loop Data Prefetching Pass.
Provides passes to inlining "always_inline" functions.
This file provides the primary interface to the aggressive instcombine pass.
This class provides an interface for updating the loop pass manager based on mutations to the loop ne...
This header defines the LoopLoadEliminationPass object.
InlineParams getInlineParams()
Generate the parameters to tune the inline cost analysis based only on the commandline options...
static cl::opt< bool > EnableGVNHoist("enable-npm-gvn-hoist", cl::init(true), cl::Hidden, cl::desc("Enable the GVN hoisting pass for the new PM (default = on)"))
static Optional< int > parseDevirtPassName(StringRef Name)
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:847
Optimize for fast execution as much as possible without triggering significant incremental compile ti...
Definition: PassBuilder.h:135
LLVM_NODISCARD std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
Definition: StringRef.h:727
This pass performs &#39;jump threading&#39;, which looks at blocks that have multiple predecessors and multip...
Definition: JumpThreading.h:78
bool parsePassPipeline(ModulePassManager &MPM, StringRef PipelineText, bool VerifyEachPass=true, bool DebugLogging=false)
Parse a textual pass pipeline description into a ModulePassManager.
A pass to simplify and canonicalize the CFG of a function.
Definition: SimplifyCFG.h:30
const DataFlowGraph & G
Definition: RDFGraph.cpp:211
static InlineParams getInlineParamsFromOptLevel(PassBuilder::OptimizationLevel Level)
The instrumentation (profile-instr-gen) pass for IR based PGO.
A pass that merges duplicate global constants into a single constant.
Definition: ConstantMerge.h:30
Analysis pass providing a never-invalidated alias analysis result.
Options for the frontend instrumentation based profiling pass.
LLVM_ATTRIBUTE_ALWAYS_INLINE StringSwitch & Case(StringLiteral S, T Value)
Definition: StringSwitch.h:70
This pass performs merges of loads and stores on both sides of a.
The indirect function call promotion pass.
Interfaces for passes which infer implicit function attributes from the name and signature of functio...
Analysis pass providing a never-invalidated alias analysis result.
static const size_t npos
Definition: StringRef.h:51
Represents a single loop in the control flow graph.
Definition: LoopInfo.h:459
Pass which forces specific function attributes into the IR, primarily as a debugging tool...
LLVM_NODISCARD size_t find_first_of(char C, size_t From=0) const
Find the first character in the string that is C, or npos if not found.
Definition: StringRef.h:395
The header file for the LowerExpectIntrinsic pass as used by the new pass manager.
Provides passes for computing function attributes based on interprocedural analyses.
OuterAnalysisManagerProxy< ModuleAnalysisManager, Function > ModuleAnalysisManagerFunctionProxy
Provide the ModuleAnalysisManager to Function proxy.
Definition: PassManager.h:1250
This header provides classes for managing passes over SCCs of the call graph.
This file defines passes to print out IR in various granularities.
void registerCGSCCAnalyses(CGSCCAnalysisManager &CGAM)
Registers all available CGSCC analysis passes.
ModulePassManager buildLTODefaultPipeline(OptimizationLevel Level, bool DebugLogging, ModuleSummaryIndex *ExportSummary)
Build an LTO default optimization pipeline to a pass manager.
static bool startsWithDefaultPipelineAliasPrefix(StringRef Name)
Tests whether a pass name starts with a valid prefix for a default pipeline alias.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file provides the interface for LLVM&#39;s Call Graph Profile pass.
Optimize quickly without destroying debuggability.
Definition: PassBuilder.h:117
The profile size based optimization pass for memory intrinsics.
See the comments on JumpThreadingPass.
An SCC of the call graph.
static const char * name
Performs Loop Inst Simplify Pass.
The LoopVectorize Pass.
Definition: LoopVectorize.h:80
static bool isCGSCCPassName(StringRef Name, CallbacksT &Callbacks)
bool match(StringRef String, SmallVectorImpl< StringRef > *Matches=nullptr)
matches - Match the regex against a given String.
Definition: Regex.cpp:73
An optimization pass providing Scalar Replacement of Aggregates.
Definition: SROA.h:66
This file exposes an interface to building/using memory SSA to walk memory instructions using a use/d...
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
This is the interface for LLVM&#39;s primary stateless and local alias analysis.
ModulePassManager buildPerModuleDefaultPipeline(OptimizationLevel Level, bool DebugLogging=false)
Build a per-module default optimization pipeline.
A container for analyses that lazily runs them and caches their results.
static cl::opt< bool > RunPartialInlining("enable-npm-partial-inlining", cl::init(false), cl::Hidden, cl::ZeroOrMore, cl::desc("Run Partial inlinining pass"))
A set of parameters used to control the transforms in the SimplifyCFG pass.
Definition: Local.h:65
void addPass(PassT Pass)
Definition: PassManager.h:542
This pass exposes codegen information to IR-level passes.
This pass performs function-level constant propagation and merging.
Definition: SCCP.h:37
This header defines various interfaces for pass management in LLVM.
static cl::opt< bool > RunNewGVN("enable-npm-newgvn", cl::init(false), cl::Hidden, cl::ZeroOrMore, cl::desc("Run NewGVN instead of GVN"))
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition: PassManager.h:71
This file provides the interface for the sampled PGO loader pass.
Optional< int > HotCallSiteThreshold
Threshold to use when the callsite is considered hot.
Definition: InlineCost.h:172
int DefaultThreshold
The default threshold to start with for a callee.
Definition: InlineCost.h:157
Optimize globals that never have their address taken.
Definition: GlobalOpt.h:26
bool empty() const
empty - Check if the array is empty.
Definition: ArrayRef.h:144
Performs Loop Idiom Recognize Pass.
static bool isLoopPassName(StringRef Name, CallbacksT &Callbacks)