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