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