LLVM  12.0.0git
PassManagerBuilder.cpp
Go to the documentation of this file.
1 //===- PassManagerBuilder.cpp - Build Standard Pass -----------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines the PassManagerBuilder class, which is used to set up a
10 // "standard" optimization sequence suitable for languages like C and C++.
11 //
12 //===----------------------------------------------------------------------===//
13 
16 #include "llvm/ADT/STLExtras.h"
17 #include "llvm/ADT/SmallVector.h"
23 #include "llvm/Analysis/Passes.h"
27 #include "llvm/IR/DataLayout.h"
29 #include "llvm/IR/Verifier.h"
33 #include "llvm/Transforms/IPO.h"
40 #include "llvm/Transforms/Scalar.h"
46 #include "llvm/Transforms/Utils.h"
51 
52 using namespace llvm;
53 
54 static cl::opt<bool>
55  RunPartialInlining("enable-partial-inlining", cl::init(false), cl::Hidden,
56  cl::ZeroOrMore, cl::desc("Run Partial inlinining pass"));
57 
58 static cl::opt<bool>
59 UseGVNAfterVectorization("use-gvn-after-vectorization",
60  cl::init(false), cl::Hidden,
61  cl::desc("Run GVN instead of Early CSE after vectorization passes"));
62 
64  "extra-vectorizer-passes", cl::init(false), cl::Hidden,
65  cl::desc("Run cleanup optimization passes after vectorization."));
66 
67 static cl::opt<bool>
68 RunLoopRerolling("reroll-loops", cl::Hidden,
69  cl::desc("Run the loop rerolling pass"));
70 
71 static cl::opt<bool> RunNewGVN("enable-newgvn", cl::init(false), cl::Hidden,
72  cl::desc("Run the NewGVN pass"));
73 
74 // Experimental option to use CFL-AA
76 static cl::opt<CFLAAType>
78  cl::desc("Enable the new, experimental CFL alias analysis"),
79  cl::values(clEnumValN(CFLAAType::None, "none", "Disable CFL-AA"),
81  "Enable unification-based CFL-AA"),
83  "Enable inclusion-based CFL-AA"),
85  "Enable both variants of CFL-AA")));
86 
88  "enable-loopinterchange", cl::init(false), cl::Hidden,
89  cl::desc("Enable the new, experimental LoopInterchange Pass"));
90 
91 static cl::opt<bool> EnableUnrollAndJam("enable-unroll-and-jam",
92  cl::init(false), cl::Hidden,
93  cl::desc("Enable Unroll And Jam Pass"));
94 
95 static cl::opt<bool>
96  EnablePrepareForThinLTO("prepare-for-thinlto", cl::init(false), cl::Hidden,
97  cl::desc("Enable preparation for ThinLTO."));
98 
99 static cl::opt<bool>
100  EnablePerformThinLTO("perform-thinlto", cl::init(false), cl::Hidden,
101  cl::desc("Enable performing ThinLTO."));
102 
103 cl::opt<bool> EnableHotColdSplit("hot-cold-split", cl::init(false),
104  cl::ZeroOrMore, cl::desc("Enable hot-cold splitting pass"));
105 
107  "enable-loop-versioning-licm", cl::init(false), cl::Hidden,
108  cl::desc("Enable the experimental Loop Versioning LICM pass"));
109 
110 static cl::opt<bool>
111  DisablePreInliner("disable-preinline", cl::init(false), cl::Hidden,
112  cl::desc("Disable pre-instrumentation inliner"));
113 
115  "preinline-threshold", cl::Hidden, cl::init(75), cl::ZeroOrMore,
116  cl::desc("Control the amount of inlining in pre-instrumentation inliner "
117  "(default = 75)"));
118 
120  "enable-gvn-hoist", cl::init(false), cl::ZeroOrMore,
121  cl::desc("Enable the GVN hoisting pass (default = off)"));
122 
123 static cl::opt<bool>
124  DisableLibCallsShrinkWrap("disable-libcalls-shrinkwrap", cl::init(false),
125  cl::Hidden,
126  cl::desc("Disable shrink-wrap library calls"));
127 
129  "enable-simple-loop-unswitch", cl::init(false), cl::Hidden,
130  cl::desc("Enable the simple loop unswitch pass. Also enables independent "
131  "cleanup passes integrated into the loop pass manager pipeline."));
132 
134  "enable-gvn-sink", cl::init(false), cl::ZeroOrMore,
135  cl::desc("Enable the GVN sinking pass (default = off)"));
136 
137 // This option is used in simplifying testing SampleFDO optimizations for
138 // profile loading.
139 static cl::opt<bool>
140  EnableCHR("enable-chr", cl::init(true), cl::Hidden,
141  cl::desc("Enable control height reduction optimization (CHR)"));
142 
144  "flattened-profile-used", cl::init(false), cl::Hidden,
145  cl::desc("Indicate the sample profile being used is flattened, i.e., "
146  "no inline hierachy exists in the profile. "));
147 
149  "enable-order-file-instrumentation", cl::init(false), cl::Hidden,
150  cl::desc("Enable order file instrumentation (default = off)"));
151 
152 static cl::opt<bool>
153  EnableMatrix("enable-matrix", cl::init(false), cl::Hidden,
154  cl::desc("Enable lowering of the matrix intrinsics"));
155 
157  "attributor-enable", cl::Hidden, cl::init(AttributorRunOption::NONE),
158  cl::desc("Enable the attributor inter-procedural deduction pass."),
160  "enable all attributor runs"),
162  "enable module-wide attributor runs"),
164  "enable call graph SCC attributor runs"),
166  "disable attributor runs")));
167 
169 
171  OptLevel = 2;
172  SizeLevel = 0;
173  LibraryInfo = nullptr;
174  Inliner = nullptr;
175  DisableUnrollLoops = false;
176  SLPVectorize = false;
177  LoopVectorize = true;
178  LoopsInterleaved = true;
179  RerollLoops = RunLoopRerolling;
180  NewGVN = RunNewGVN;
181  LicmMssaOptCap = SetLicmMssaOptCap;
182  LicmMssaNoAccForPromotionCap = SetLicmMssaNoAccForPromotionCap;
183  DisableGVNLoadPRE = false;
184  ForgetAllSCEVInLoopUnroll = ForgetSCEVInLoopUnroll;
185  VerifyInput = false;
186  VerifyOutput = false;
187  MergeFunctions = false;
188  PrepareForLTO = false;
189  EnablePGOInstrGen = false;
190  EnablePGOCSInstrGen = false;
191  EnablePGOCSInstrUse = false;
192  PGOInstrGen = "";
193  PGOInstrUse = "";
194  PGOSampleUse = "";
195  PrepareForThinLTO = EnablePrepareForThinLTO;
196  PerformThinLTO = EnablePerformThinLTO;
197  DivergentTarget = false;
198  CallGraphProfile = true;
199 }
200 
202  delete LibraryInfo;
203  delete Inliner;
204 }
205 
206 /// Set of global extensions, automatically added as part of the standard set.
207 static ManagedStatic<
211  8>>
213 static PassManagerBuilder::GlobalExtensionID GlobalExtensionsCounter;
214 
215 /// Check if GlobalExtensions is constructed and not empty.
216 /// Since GlobalExtensions is a managed static, calling 'empty()' will trigger
217 /// the construction of the object.
219  return GlobalExtensions.isConstructed() && !GlobalExtensions->empty();
220 }
221 
222 PassManagerBuilder::GlobalExtensionID
223 PassManagerBuilder::addGlobalExtension(PassManagerBuilder::ExtensionPointTy Ty,
224  PassManagerBuilder::ExtensionFn Fn) {
225  auto ExtensionID = GlobalExtensionsCounter++;
226  GlobalExtensions->push_back(std::make_tuple(Ty, std::move(Fn), ExtensionID));
227  return ExtensionID;
228 }
229 
231  PassManagerBuilder::GlobalExtensionID ExtensionID) {
232  // RegisterStandardPasses may try to call this function after GlobalExtensions
233  // has already been destroyed; doing so should not generate an error.
234  if (!GlobalExtensions.isConstructed())
235  return;
236 
237  auto GlobalExtension =
238  llvm::find_if(*GlobalExtensions, [ExtensionID](const auto &elem) {
239  return std::get<2>(elem) == ExtensionID;
240  });
241  assert(GlobalExtension != GlobalExtensions->end() &&
242  "The extension ID to be removed should always be valid.");
243 
244  GlobalExtensions->erase(GlobalExtension);
245 }
246 
248  Extensions.push_back(std::make_pair(Ty, std::move(Fn)));
249 }
250 
251 void PassManagerBuilder::addExtensionsToPM(ExtensionPointTy ETy,
252  legacy::PassManagerBase &PM) const {
253  if (GlobalExtensionsNotEmpty()) {
254  for (auto &Ext : *GlobalExtensions) {
255  if (std::get<0>(Ext) == ETy)
256  std::get<1>(Ext)(*this, PM);
257  }
258  }
259  for (unsigned i = 0, e = Extensions.size(); i != e; ++i)
260  if (Extensions[i].first == ETy)
261  Extensions[i].second(*this, PM);
262 }
263 
264 void PassManagerBuilder::addInitialAliasAnalysisPasses(
265  legacy::PassManagerBase &PM) const {
266  switch (UseCFLAA) {
269  break;
270  case CFLAAType::Andersen:
272  break;
273  case CFLAAType::Both:
276  break;
277  default:
278  break;
279  }
280 
281  // Add TypeBasedAliasAnalysis before BasicAliasAnalysis so that
282  // BasicAliasAnalysis wins if they disagree. This is intended to help
283  // support "obvious" type-punning idioms.
286 }
287 
290  addExtensionsToPM(EP_EarlyAsPossible, FPM);
292 
293  // Add LibraryInfo if we have some.
294  if (LibraryInfo)
295  FPM.add(new TargetLibraryInfoWrapperPass(*LibraryInfo));
296 
297  if (OptLevel == 0) return;
298 
299  addInitialAliasAnalysisPasses(FPM);
300 
302  FPM.add(createSROAPass());
303  FPM.add(createEarlyCSEPass());
305 }
306 
307 // Do PGO instrumentation generation or use pass as the option specified.
308 void PassManagerBuilder::addPGOInstrPasses(legacy::PassManagerBase &MPM,
309  bool IsCS = false) {
310  if (IsCS) {
311  if (!EnablePGOCSInstrGen && !EnablePGOCSInstrUse)
312  return;
313  } else if (!EnablePGOInstrGen && PGOInstrUse.empty() && PGOSampleUse.empty())
314  return;
315 
316  // Perform the preinline and cleanup passes for O1 and above.
317  // And avoid doing them if optimizing for size.
318  // We will not do this inline for context sensitive PGO (when IsCS is true).
319  if (OptLevel > 0 && SizeLevel == 0 && !DisablePreInliner &&
320  PGOSampleUse.empty() && !IsCS) {
321  // Create preinline pass. We construct an InlineParams object and specify
322  // the threshold here to avoid the command line options of the regular
323  // inliner to influence pre-inlining. The only fields of InlineParams we
324  // care about are DefaultThreshold and HintThreshold.
325  InlineParams IP;
327  // FIXME: The hint threshold has the same value used by the regular inliner.
328  // This should probably be lowered after performance testing.
329  IP.HintThreshold = 325;
330 
332  MPM.add(createSROAPass());
333  MPM.add(createEarlyCSEPass()); // Catch trivial redundancies
334  MPM.add(createCFGSimplificationPass()); // Merge & remove BBs
335  MPM.add(createInstructionCombiningPass()); // Combine silly seq's
336  addExtensionsToPM(EP_Peephole, MPM);
337  }
338  if ((EnablePGOInstrGen && !IsCS) || (EnablePGOCSInstrGen && IsCS)) {
340  // Add the profile lowering pass.
341  InstrProfOptions Options;
342  if (!PGOInstrGen.empty())
343  Options.InstrProfileOutput = PGOInstrGen;
344  Options.DoCounterPromotion = true;
345  Options.UseBFIInPromotion = IsCS;
346  MPM.add(createLoopRotatePass());
347  MPM.add(createInstrProfilingLegacyPass(Options, IsCS));
348  }
349  if (!PGOInstrUse.empty())
350  MPM.add(createPGOInstrumentationUseLegacyPass(PGOInstrUse, IsCS));
351  // Indirect call promotion that promotes intra-module targets only.
352  // For ThinLTO this is done earlier due to interactions with globalopt
353  // for imported functions. We don't run this at -O0.
354  if (OptLevel > 0 && !IsCS)
355  MPM.add(
356  createPGOIndirectCallPromotionLegacyPass(false, !PGOSampleUse.empty()));
357 }
358 void PassManagerBuilder::addFunctionSimplificationPasses(
360  // Start of function pass.
361  // Break up aggregate allocas, using SSAUpdater.
362  assert(OptLevel >= 1 && "Calling function optimizer with no optimization level!");
363  MPM.add(createSROAPass());
364  MPM.add(createEarlyCSEPass(true /* Enable mem-ssa. */)); // Catch trivial redundancies
365  if (EnableKnowledgeRetention)
367 
368  if (OptLevel > 1) {
369  if (EnableGVNHoist)
370  MPM.add(createGVNHoistPass());
371  if (EnableGVNSink) {
372  MPM.add(createGVNSinkPass());
374  }
375  }
376 
377  if (OptLevel > 1) {
378  // Speculative execution if the target has divergent branches; otherwise nop.
380 
381  MPM.add(createJumpThreadingPass()); // Thread jumps.
382  MPM.add(createCorrelatedValuePropagationPass()); // Propagate conditionals
383  }
384  MPM.add(createCFGSimplificationPass()); // Merge & remove BBs
385  // Combine silly seq's
386  if (OptLevel > 2)
389  if (SizeLevel == 0 && !DisableLibCallsShrinkWrap)
391  addExtensionsToPM(EP_Peephole, MPM);
392 
393  // Optimize memory intrinsic calls based on the profiled size information.
394  if (SizeLevel == 0)
396 
397  // TODO: Investigate the cost/benefit of tail call elimination on debugging.
398  if (OptLevel > 1)
399  MPM.add(createTailCallEliminationPass()); // Eliminate tail calls
400  MPM.add(createCFGSimplificationPass()); // Merge & remove BBs
401  MPM.add(createReassociatePass()); // Reassociate expressions
402 
403  // Begin the loop pass pipeline.
404  if (EnableSimpleLoopUnswitch) {
405  // The simple loop unswitch pass relies on separate cleanup passes. Schedule
406  // them first so when we re-process a loop they run before other loop
407  // passes.
410  }
411  // Rotate Loop - disable header duplication at -Oz
412  MPM.add(createLoopRotatePass(SizeLevel == 2 ? 0 : -1));
413  // TODO: Investigate promotion cap for O1.
414  MPM.add(createLICMPass(LicmMssaOptCap, LicmMssaNoAccForPromotionCap));
415  if (EnableSimpleLoopUnswitch)
417  else
418  MPM.add(createLoopUnswitchPass(SizeLevel || OptLevel < 3, DivergentTarget));
419  // FIXME: We break the loop pass pipeline here in order to do full
420  // simplify-cfg. Eventually loop-simplifycfg should be enhanced to replace the
421  // need for this.
424  // We resume loop passes creating a second loop pipeline here.
425  MPM.add(createIndVarSimplifyPass()); // Canonicalize indvars
426  MPM.add(createLoopIdiomPass()); // Recognize idioms like memset.
427  addExtensionsToPM(EP_LateLoopOptimizations, MPM);
428  MPM.add(createLoopDeletionPass()); // Delete dead loops
429 
430  if (EnableLoopInterchange)
431  MPM.add(createLoopInterchangePass()); // Interchange loops
432 
433  // Unroll small loops
434  MPM.add(createSimpleLoopUnrollPass(OptLevel, DisableUnrollLoops,
435  ForgetAllSCEVInLoopUnroll));
436  addExtensionsToPM(EP_LoopOptimizerEnd, MPM);
437  // This ends the loop pass pipelines.
438 
439  if (OptLevel > 1) {
440  MPM.add(createMergedLoadStoreMotionPass()); // Merge ld/st in diamonds
441  MPM.add(NewGVN ? createNewGVNPass()
442  : createGVNPass(DisableGVNLoadPRE)); // Remove redundancies
443  }
444  MPM.add(createMemCpyOptPass()); // Remove memcpy / form memset
445  MPM.add(createSCCPPass()); // Constant prop with SCCP
446 
447  // Delete dead bit computations (instcombine runs after to fold away the dead
448  // computations, and then ADCE will run later to exploit any new DCE
449  // opportunities that creates).
450  MPM.add(createBitTrackingDCEPass()); // Delete dead bit computations
451 
452  // Run instcombine after redundancy elimination to exploit opportunities
453  // opened up by them.
455  addExtensionsToPM(EP_Peephole, MPM);
456  if (OptLevel > 1) {
457  MPM.add(createJumpThreadingPass()); // Thread jumps
459  MPM.add(createDeadStoreEliminationPass()); // Delete dead stores
460  MPM.add(createLICMPass(LicmMssaOptCap, LicmMssaNoAccForPromotionCap));
461  }
462 
463  addExtensionsToPM(EP_ScalarOptimizerLate, MPM);
464 
465  if (RerollLoops)
466  MPM.add(createLoopRerollPass());
467 
468  // TODO: Investigate if this is too expensive at O1.
469  MPM.add(createAggressiveDCEPass()); // Delete dead instructions
470  MPM.add(createCFGSimplificationPass()); // Merge & remove BBs
471  // Clean up after everything.
473  addExtensionsToPM(EP_Peephole, MPM);
474 
475  if (EnableCHR && OptLevel >= 3 &&
476  (!PGOInstrUse.empty() || !PGOSampleUse.empty() || EnablePGOCSInstrGen))
478 }
479 
482  // Whether this is a default or *LTO pre-link pipeline. The FullLTO post-link
483  // is handled separately, so just check this is not the ThinLTO post-link.
484  bool DefaultOrPreLinkPipeline = !PerformThinLTO;
485 
486  if (!PGOSampleUse.empty()) {
487  MPM.add(createPruneEHPass());
488  // In ThinLTO mode, when flattened profile is used, all the available
489  // profile information will be annotated in PreLink phase so there is
490  // no need to load the profile again in PostLink.
491  if (!(FlattenedProfileUsed && PerformThinLTO))
492  MPM.add(createSampleProfileLoaderPass(PGOSampleUse));
493  }
494 
495  // Allow forcing function attributes as a debugging and tuning aid.
497 
498  // If all optimizations are disabled, just run the always-inline pass and,
499  // if enabled, the function merging pass.
500  if (OptLevel == 0) {
501  addPGOInstrPasses(MPM);
502  if (Inliner) {
503  MPM.add(Inliner);
504  Inliner = nullptr;
505  }
506 
507  // FIXME: The BarrierNoopPass is a HACK! The inliner pass above implicitly
508  // creates a CGSCC pass manager, but we don't want to add extensions into
509  // that pass manager. To prevent this we insert a no-op module pass to reset
510  // the pass manager to get the same behavior as EP_OptimizerLast in non-O0
511  // builds. The function merging pass is
512  if (MergeFunctions)
514  else if (GlobalExtensionsNotEmpty() || !Extensions.empty())
515  MPM.add(createBarrierNoopPass());
516 
517  if (PerformThinLTO) {
518  MPM.add(createLowerTypeTestsPass(nullptr, nullptr, true));
519  // Drop available_externally and unreferenced globals. This is necessary
520  // with ThinLTO in order to avoid leaving undefined references to dead
521  // globals in the object file.
523  MPM.add(createGlobalDCEPass());
524  }
525 
526  addExtensionsToPM(EP_EnabledOnOptLevel0, MPM);
527 
528  if (PrepareForLTO || PrepareForThinLTO) {
530  // Rename anon globals to be able to export them in the summary.
531  // This has to be done after we add the extensions to the pass manager
532  // as there could be passes (e.g. Adddress sanitizer) which introduce
533  // new unnamed globals.
535  }
536  return;
537  }
538 
539  // Add LibraryInfo if we have some.
540  if (LibraryInfo)
541  MPM.add(new TargetLibraryInfoWrapperPass(*LibraryInfo));
542 
543  addInitialAliasAnalysisPasses(MPM);
544 
545  // For ThinLTO there are two passes of indirect call promotion. The
546  // first is during the compile phase when PerformThinLTO=false and
547  // intra-module indirect call targets are promoted. The second is during
548  // the ThinLTO backend when PerformThinLTO=true, when we promote imported
549  // inter-module indirect calls. For that we perform indirect call promotion
550  // earlier in the pass pipeline, here before globalopt. Otherwise imported
551  // available_externally functions look unreferenced and are removed.
552  if (PerformThinLTO) {
553  MPM.add(createPGOIndirectCallPromotionLegacyPass(/*InLTO = */ true,
554  !PGOSampleUse.empty()));
555  MPM.add(createLowerTypeTestsPass(nullptr, nullptr, true));
556  }
557 
558  // For SamplePGO in ThinLTO compile phase, we do not want to unroll loops
559  // as it will change the CFG too much to make the 2nd profile annotation
560  // in backend more difficult.
561  bool PrepareForThinLTOUsingPGOSampleProfile =
562  PrepareForThinLTO && !PGOSampleUse.empty();
563  if (PrepareForThinLTOUsingPGOSampleProfile)
564  DisableUnrollLoops = true;
565 
566  // Infer attributes about declarations if possible.
568 
569  // Infer attributes on declarations, call sites, arguments, etc.
570  if (AttributorRun & AttributorRunOption::MODULE)
572 
573  addExtensionsToPM(EP_ModuleOptimizerEarly, MPM);
574 
575  if (OptLevel > 2)
577 
578  MPM.add(createIPSCCPPass()); // IP SCCP
580 
581  MPM.add(createGlobalOptimizerPass()); // Optimize out global vars
582  // Promote any localized global vars.
584 
585  MPM.add(createDeadArgEliminationPass()); // Dead argument elimination
586 
587  MPM.add(createInstructionCombiningPass()); // Clean up after IPCP & DAE
588  addExtensionsToPM(EP_Peephole, MPM);
589  MPM.add(createCFGSimplificationPass()); // Clean up after IPCP & DAE
590 
591  // For SamplePGO in ThinLTO compile phase, we do not want to do indirect
592  // call promotion as it will change the CFG too much to make the 2nd
593  // profile annotation in backend more difficult.
594  // PGO instrumentation is added during the compile phase for ThinLTO, do
595  // not run it a second time
596  if (DefaultOrPreLinkPipeline && !PrepareForThinLTOUsingPGOSampleProfile)
597  addPGOInstrPasses(MPM);
598 
599  // Create profile COMDAT variables. Lld linker wants to see all variables
600  // before the LTO/ThinLTO link since it needs to resolve symbols/comdats.
601  if (!PerformThinLTO && EnablePGOCSInstrGen)
603 
604  // We add a module alias analysis pass here. In part due to bugs in the
605  // analysis infrastructure this "works" in that the analysis stays alive
606  // for the entire SCC pass run below.
608 
609  // Start of CallGraph SCC passes.
610  MPM.add(createPruneEHPass()); // Remove dead EH info
611  bool RunInliner = false;
612  if (Inliner) {
613  MPM.add(Inliner);
614  Inliner = nullptr;
615  RunInliner = true;
616  }
617 
618  // Infer attributes on declarations, call sites, arguments, etc. for an SCC.
619  if (AttributorRun & AttributorRunOption::CGSCC)
621 
622  // Try to perform OpenMP specific optimizations. This is a (quick!) no-op if
623  // there are no OpenMP runtime calls present in the module.
624  if (OptLevel > 1)
626 
628  if (OptLevel > 2)
629  MPM.add(createArgumentPromotionPass()); // Scalarize uninlined fn args
630 
631  addExtensionsToPM(EP_CGSCCOptimizerLate, MPM);
632  addFunctionSimplificationPasses(MPM);
633 
634  // FIXME: This is a HACK! The inliner pass above implicitly creates a CGSCC
635  // pass manager that we are specifically trying to avoid. To prevent this
636  // we must insert a no-op module pass to reset the pass manager.
637  MPM.add(createBarrierNoopPass());
638 
639  if (RunPartialInlining)
641 
642  if (OptLevel > 1 && !PrepareForLTO && !PrepareForThinLTO)
643  // Remove avail extern fns and globals definitions if we aren't
644  // compiling an object file for later LTO. For LTO we want to preserve
645  // these so they are eligible for inlining at link-time. Note if they
646  // are unreferenced they will be removed by GlobalDCE later, so
647  // this only impacts referenced available externally globals.
648  // Eventually they will be suppressed during codegen, but eliminating
649  // here enables more opportunity for GlobalDCE as it may make
650  // globals referenced by available external functions dead
651  // and saves running remaining passes on the eliminated functions.
653 
654  // CSFDO instrumentation and use pass. Don't invoke this for Prepare pass
655  // for LTO and ThinLTO -- The actual pass will be called after all inlines
656  // are performed.
657  // Need to do this after COMDAT variables have been eliminated,
658  // (i.e. after EliminateAvailableExternallyPass).
659  if (!(PrepareForLTO || PrepareForThinLTO))
660  addPGOInstrPasses(MPM, /* IsCS */ true);
661 
662  if (EnableOrderFileInstrumentation)
664 
666 
667  // The inliner performs some kind of dead code elimination as it goes,
668  // but there are cases that are not really caught by it. We might
669  // at some point consider teaching the inliner about them, but it
670  // is OK for now to run GlobalOpt + GlobalDCE in tandem as their
671  // benefits generally outweight the cost, making the whole pipeline
672  // faster.
673  if (RunInliner) {
675  MPM.add(createGlobalDCEPass());
676  }
677 
678  // If we are planning to perform ThinLTO later, let's not bloat the code with
679  // unrolling/vectorization/... now. We'll first run the inliner + CGSCC passes
680  // during ThinLTO and perform the rest of the optimizations afterward.
681  if (PrepareForThinLTO) {
682  // Ensure we perform any last passes, but do so before renaming anonymous
683  // globals in case the passes add any.
684  addExtensionsToPM(EP_OptimizerLast, MPM);
686  // Rename anon globals to be able to export them in the summary.
688  return;
689  }
690 
691  if (PerformThinLTO)
692  // Optimize globals now when performing ThinLTO, this enables more
693  // optimizations later.
695 
696  // Scheduling LoopVersioningLICM when inlining is over, because after that
697  // we may see more accurate aliasing. Reason to run this late is that too
698  // early versioning may prevent further inlining due to increase of code
699  // size. By placing it just after inlining other optimizations which runs
700  // later might get benefit of no-alias assumption in clone loop.
701  if (UseLoopVersioningLICM) {
702  MPM.add(createLoopVersioningLICMPass()); // Do LoopVersioningLICM
703  MPM.add(createLICMPass(LicmMssaOptCap, LicmMssaNoAccForPromotionCap));
704  }
705 
706  // We add a fresh GlobalsModRef run at this point. This is particularly
707  // useful as the above will have inlined, DCE'ed, and function-attr
708  // propagated everything. We should at this point have a reasonably minimal
709  // and richly annotated call graph. By computing aliasing and mod/ref
710  // information for all local globals here, the late loop passes and notably
711  // the vectorizer will be able to use them to help recognize vectorizable
712  // memory operations.
713  //
714  // Note that this relies on a bug in the pass manager which preserves
715  // a module analysis into a function pass pipeline (and throughout it) so
716  // long as the first function pass doesn't invalidate the module analysis.
717  // Thus both Float2Int and LoopRotate have to preserve AliasAnalysis for
718  // this to work. Fortunately, it is trivial to preserve AliasAnalysis
719  // (doing nothing preserves it as it is required to be conservatively
720  // correct in the face of IR changes).
722 
723  MPM.add(createFloat2IntPass());
725 
726  if (EnableMatrix) {
728  // CSE the pointer arithmetic of the column vectors. This allows alias
729  // analysis to establish no-aliasing between loads and stores of different
730  // columns of the same matrix.
731  MPM.add(createEarlyCSEPass(false));
732  }
733 
734  addExtensionsToPM(EP_VectorizerStart, MPM);
735 
736  // Re-rotate loops in all our loop nests. These may have fallout out of
737  // rotated form due to GVN or other transformations, and the vectorizer relies
738  // on the rotated form. Disable header duplication at -Oz.
739  MPM.add(createLoopRotatePass(SizeLevel == 2 ? 0 : -1));
740 
741  // Distribute loops to allow partial vectorization. I.e. isolate dependences
742  // into separate loop that would otherwise inhibit vectorization. This is
743  // currently only performed for loops marked with the metadata
744  // llvm.loop.distribute=true or when -enable-loop-distribute is specified.
746 
747  MPM.add(createLoopVectorizePass(!LoopsInterleaved, !LoopVectorize));
748 
749  // Eliminate loads by forwarding stores from the previous iteration to loads
750  // of the current iteration.
752 
753  // FIXME: Because of #pragma vectorize enable, the passes below are always
754  // inserted in the pipeline, even when the vectorizer doesn't run (ex. when
755  // on -O1 and no #pragma is found). Would be good to have these two passes
756  // as function calls, so that we can only pass them when the vectorizer
757  // changed the code.
759  if (OptLevel > 1 && ExtraVectorizerPasses) {
760  // At higher optimization levels, try to clean up any runtime overlap and
761  // alignment checks inserted by the vectorizer. We want to track correllated
762  // runtime checks for two inner loops in the same outer loop, fold any
763  // common computations, hoist loop-invariant aspects out of any outer loop,
764  // and unswitch the runtime checks if possible. Once hoisted, we may have
765  // dead (or speculatable) control flows or more combining opportunities.
766  MPM.add(createEarlyCSEPass());
769  MPM.add(createLICMPass(LicmMssaOptCap, LicmMssaNoAccForPromotionCap));
770  MPM.add(createLoopUnswitchPass(SizeLevel || OptLevel < 3, DivergentTarget));
773  }
774 
775  // Cleanup after loop vectorization, etc. Simplification passes like CVP and
776  // GVN, loop transforms, and others have already run, so it's now better to
777  // convert to more optimized IR using more aggressive simplify CFG options.
778  // The extra sinking transform can create larger basic blocks, so do this
779  // before SLP vectorization.
781  .forwardSwitchCondToPhi(true)
782  .convertSwitchToLookupTable(true)
783  .needCanonicalLoops(false)
784  .sinkCommonInsts(true)));
785 
786  if (SLPVectorize) {
787  MPM.add(createSLPVectorizerPass()); // Vectorize parallel scalar chains.
788  if (OptLevel > 1 && ExtraVectorizerPasses) {
789  MPM.add(createEarlyCSEPass());
790  }
791  }
792 
793  // Enhance/cleanup vector code.
795 
796  addExtensionsToPM(EP_Peephole, MPM);
798 
799  if (EnableUnrollAndJam && !DisableUnrollLoops) {
800  // Unroll and Jam. We do this before unroll but need to be in a separate
801  // loop pass manager in order for the outer loop to be processed by
802  // unroll and jam before the inner loop is unrolled.
803  MPM.add(createLoopUnrollAndJamPass(OptLevel));
804  }
805 
806  // Unroll small loops
807  MPM.add(createLoopUnrollPass(OptLevel, DisableUnrollLoops,
808  ForgetAllSCEVInLoopUnroll));
809 
810  if (!DisableUnrollLoops) {
811  // LoopUnroll may generate some redundency to cleanup.
813 
814  // Runtime unrolling will introduce runtime check in loop prologue. If the
815  // unrolled loop is a inner loop, then the prologue will be inside the
816  // outer loop. LICM pass can help to promote the runtime check out if the
817  // checked value is loop invariant.
818  MPM.add(createLICMPass(LicmMssaOptCap, LicmMssaNoAccForPromotionCap));
819  }
820 
822 
823  // After vectorization and unrolling, assume intrinsics may tell us more
824  // about pointer alignments.
826 
827  // FIXME: We shouldn't bother with this anymore.
828  MPM.add(createStripDeadPrototypesPass()); // Get rid of dead prototypes
829 
830  // GlobalOpt already deletes dead functions and globals, at -O2 try a
831  // late pass of GlobalDCE. It is capable of deleting dead cycles.
832  if (OptLevel > 1) {
833  MPM.add(createGlobalDCEPass()); // Remove dead fns and globals.
834  MPM.add(createConstantMergePass()); // Merge dup global constants
835  }
836 
837  // See comment in the new PM for justification of scheduling splitting at
838  // this stage (\ref buildModuleSimplificationPipeline).
839  if (EnableHotColdSplit && !(PrepareForLTO || PrepareForThinLTO))
841 
842  if (MergeFunctions)
844 
845  // Add Module flag "CG Profile" based on Branch Frequency Information.
846  if (CallGraphProfile)
848 
849  // LoopSink pass sinks instructions hoisted by LICM, which serves as a
850  // canonicalization pass that enables other optimizations. As a result,
851  // LoopSink pass needs to be a very late IR pass to avoid undoing LICM
852  // result too early.
853  MPM.add(createLoopSinkPass());
854  // Get rid of LCSSA nodes.
856 
857  // This hoists/decomposes div/rem ops. It should run after other sink/hoist
858  // passes to avoid re-sinking, but before SimplifyCFG because it can allow
859  // flattening of blocks.
860  MPM.add(createDivRemPairsPass());
861 
862  // LoopSink (and other loop passes since the last simplifyCFG) might have
863  // resulted in single-entry-single-exit or empty blocks. Clean up the CFG.
865 
866  addExtensionsToPM(EP_OptimizerLast, MPM);
867 
868  if (PrepareForLTO) {
870  // Rename anon globals to be able to handle them in the summary
872  }
873 }
874 
875 void PassManagerBuilder::addLTOOptimizationPasses(legacy::PassManagerBase &PM) {
876  // Load sample profile before running the LTO optimization pipeline.
877  if (!PGOSampleUse.empty()) {
878  PM.add(createPruneEHPass());
879  PM.add(createSampleProfileLoaderPass(PGOSampleUse));
880  }
881 
882  // Remove unused virtual tables to improve the quality of code generated by
883  // whole-program devirtualization and bitset lowering.
884  PM.add(createGlobalDCEPass());
885 
886  // Provide AliasAnalysis services for optimizations.
887  addInitialAliasAnalysisPasses(PM);
888 
889  // Allow forcing function attributes as a debugging and tuning aid.
891 
892  // Infer attributes about declarations if possible.
894 
895  if (OptLevel > 1) {
896  // Split call-site with more constrained arguments.
898 
899  // Indirect call promotion. This should promote all the targets that are
900  // left by the earlier promotion pass that promotes intra-module targets.
901  // This two-step promotion is to save the compile time. For LTO, it should
902  // produce the same result as if we only do promotion here.
903  PM.add(
904  createPGOIndirectCallPromotionLegacyPass(true, !PGOSampleUse.empty()));
905 
906  // Propagate constants at call sites into the functions they call. This
907  // opens opportunities for globalopt (and inlining) by substituting function
908  // pointers passed as arguments to direct uses of functions.
909  PM.add(createIPSCCPPass());
910 
911  // Attach metadata to indirect call sites indicating the set of functions
912  // they may target at run-time. This should follow IPSCCP.
914 
915  // Infer attributes on declarations, call sites, arguments, etc.
916  if (AttributorRun & AttributorRunOption::MODULE)
918  }
919 
920  // Infer attributes about definitions. The readnone attribute in particular is
921  // required for virtual constant propagation.
924 
925  // Split globals using inrange annotations on GEP indices. This can help
926  // improve the quality of generated code when virtual constant propagation or
927  // control flow integrity are enabled.
929 
930  // Apply whole-program devirtualization and virtual constant propagation.
931  PM.add(createWholeProgramDevirtPass(ExportSummary, nullptr));
932 
933  // That's all we need at opt level 1.
934  if (OptLevel == 1)
935  return;
936 
937  // Now that we internalized some globals, see if we can hack on them!
939  // Promote any localized global vars.
941 
942  // Linking modules together can lead to duplicated global constants, only
943  // keep one copy of each constant.
945 
946  // Remove unused arguments from functions.
948 
949  // Reduce the code after globalopt and ipsccp. Both can open up significant
950  // simplification opportunities, and both can propagate functions through
951  // function pointers. When this happens, we often have to resolve varargs
952  // calls, etc, so let instcombine do this.
953  if (OptLevel > 2)
956  addExtensionsToPM(EP_Peephole, PM);
957 
958  // Inline small functions
959  bool RunInliner = Inliner;
960  if (RunInliner) {
961  PM.add(Inliner);
962  Inliner = nullptr;
963  }
964 
965  PM.add(createPruneEHPass()); // Remove dead EH info.
966 
967  // CSFDO instrumentation and use pass.
968  addPGOInstrPasses(PM, /* IsCS */ true);
969 
970  // Infer attributes on declarations, call sites, arguments, etc. for an SCC.
971  if (AttributorRun & AttributorRunOption::CGSCC)
973 
974  // Try to perform OpenMP specific optimizations. This is a (quick!) no-op if
975  // there are no OpenMP runtime calls present in the module.
976  if (OptLevel > 1)
978 
979  // Optimize globals again if we ran the inliner.
980  if (RunInliner)
982  PM.add(createGlobalDCEPass()); // Remove dead functions.
983 
984  // If we didn't decide to inline a function, check to see if we can
985  // transform it to pass arguments by value instead of by reference.
987 
988  // The IPO passes may leave cruft around. Clean up after them.
990  addExtensionsToPM(EP_Peephole, PM);
992 
993  // Break up allocas
994  PM.add(createSROAPass());
995 
996  // LTO provides additional opportunities for tailcall elimination due to
997  // link-time inlining, and visibility of nocapture attribute.
998  if (OptLevel > 1)
1000 
1001  // Infer attributes on declarations, call sites, arguments, etc.
1002  PM.add(createPostOrderFunctionAttrsLegacyPass()); // Add nocapture.
1003  // Run a few AA driven optimizations here and now, to cleanup the code.
1004  PM.add(createGlobalsAAWrapperPass()); // IP alias analysis.
1005 
1006  PM.add(createLICMPass(LicmMssaOptCap, LicmMssaNoAccForPromotionCap));
1007  PM.add(createMergedLoadStoreMotionPass()); // Merge ld/st in diamonds.
1008  PM.add(NewGVN ? createNewGVNPass()
1009  : createGVNPass(DisableGVNLoadPRE)); // Remove redundancies.
1010  PM.add(createMemCpyOptPass()); // Remove dead memcpys.
1011 
1012  // Nuke dead stores.
1014 
1015  // More loops are countable; try to optimize them.
1018  if (EnableLoopInterchange)
1020 
1021  // Unroll small loops
1022  PM.add(createSimpleLoopUnrollPass(OptLevel, DisableUnrollLoops,
1023  ForgetAllSCEVInLoopUnroll));
1024  PM.add(createLoopVectorizePass(true, !LoopVectorize));
1025  // The vectorizer may have significantly shortened a loop body; unroll again.
1026  PM.add(createLoopUnrollPass(OptLevel, DisableUnrollLoops,
1027  ForgetAllSCEVInLoopUnroll));
1028 
1030 
1031  // Now that we've optimized loops (in particular loop induction variables),
1032  // we may have exposed more scalar opportunities. Run parts of the scalar
1033  // optimizer again at this point.
1034  PM.add(createInstructionCombiningPass()); // Initial cleanup
1035  PM.add(createCFGSimplificationPass()); // if-convert
1036  PM.add(createSCCPPass()); // Propagate exposed constants
1037  PM.add(createInstructionCombiningPass()); // Clean up again
1039 
1040  // More scalar chains could be vectorized due to more alias information
1041  if (SLPVectorize)
1042  PM.add(createSLPVectorizerPass()); // Vectorize parallel scalar chains.
1043 
1044  PM.add(createVectorCombinePass()); // Clean up partial vectorization.
1045 
1046  // After vectorization, assume intrinsics may tell us more about pointer
1047  // alignments.
1049 
1050  // Cleanup and simplify the code after the scalar optimizations.
1052  addExtensionsToPM(EP_Peephole, PM);
1053 
1055 }
1056 
1057 void PassManagerBuilder::addLateLTOOptimizationPasses(
1059  // See comment in the new PM for justification of scheduling splitting at
1060  // this stage (\ref buildLTODefaultPipeline).
1061  if (EnableHotColdSplit)
1063 
1064  // Delete basic blocks, which optimization passes may have killed.
1066 
1067  // Drop bodies of available externally objects to improve GlobalDCE.
1069 
1070  // Now that we have optimized the program, discard unreachable functions.
1071  PM.add(createGlobalDCEPass());
1072 
1073  // FIXME: this is profitable (for compiler time) to do at -O0 too, but
1074  // currently it damages debug info.
1075  if (MergeFunctions)
1077 }
1078 
1081  PerformThinLTO = true;
1082  if (LibraryInfo)
1083  PM.add(new TargetLibraryInfoWrapperPass(*LibraryInfo));
1084 
1085  if (VerifyInput)
1086  PM.add(createVerifierPass());
1087 
1088  if (ImportSummary) {
1089  // This pass imports type identifier resolutions for whole-program
1090  // devirtualization and CFI. It must run early because other passes may
1091  // disturb the specific instruction patterns that these passes look for,
1092  // creating dependencies on resolutions that may not appear in the summary.
1093  //
1094  // For example, GVN may transform the pattern assume(type.test) appearing in
1095  // two basic blocks into assume(phi(type.test, type.test)), which would
1096  // transform a dependency on a WPD resolution into a dependency on a type
1097  // identifier resolution for CFI.
1098  //
1099  // Also, WPD has access to more precise information than ICP and can
1100  // devirtualize more effectively, so it should operate on the IR first.
1101  PM.add(createWholeProgramDevirtPass(nullptr, ImportSummary));
1102  PM.add(createLowerTypeTestsPass(nullptr, ImportSummary));
1103  }
1104 
1105  populateModulePassManager(PM);
1106 
1107  if (VerifyOutput)
1108  PM.add(createVerifierPass());
1109  PerformThinLTO = false;
1110 }
1111 
1113  if (LibraryInfo)
1114  PM.add(new TargetLibraryInfoWrapperPass(*LibraryInfo));
1115 
1116  if (VerifyInput)
1117  PM.add(createVerifierPass());
1118 
1119  addExtensionsToPM(EP_FullLinkTimeOptimizationEarly, PM);
1120 
1121  if (OptLevel != 0)
1122  addLTOOptimizationPasses(PM);
1123  else {
1124  // The whole-program-devirt pass needs to run at -O0 because only it knows
1125  // about the llvm.type.checked.load intrinsic: it needs to both lower the
1126  // intrinsic itself and handle it in the summary.
1127  PM.add(createWholeProgramDevirtPass(ExportSummary, nullptr));
1128  }
1129 
1130  // Create a function that performs CFI checks for cross-DSO calls with targets
1131  // in the current module.
1132  PM.add(createCrossDSOCFIPass());
1133 
1134  // Lower type metadata and the type.test intrinsic. This pass supports Clang's
1135  // control flow integrity mechanisms (-fsanitize=cfi*) and needs to run at
1136  // link time if CFI is enabled. The pass does nothing if CFI is disabled.
1137  PM.add(createLowerTypeTestsPass(ExportSummary, nullptr));
1138  // Run a second time to clean up any type tests left behind by WPD for use
1139  // in ICP (which is performed earlier than this in the regular LTO pipeline).
1140  PM.add(createLowerTypeTestsPass(nullptr, nullptr, true));
1141 
1142  if (OptLevel != 0)
1143  addLateLTOOptimizationPasses(PM);
1144 
1145  addExtensionsToPM(EP_FullLinkTimeOptimizationLast, PM);
1146 
1147  if (VerifyOutput)
1148  PM.add(createVerifierPass());
1149 }
1150 
1153  return wrap(PMB);
1154 }
1155 
1158  delete Builder;
1159 }
1160 
1161 void
1163  unsigned OptLevel) {
1165  Builder->OptLevel = OptLevel;
1166 }
1167 
1168 void
1170  unsigned SizeLevel) {
1172  Builder->SizeLevel = SizeLevel;
1173 }
1174 
1175 void
1177  LLVMBool Value) {
1178  // NOTE: The DisableUnitAtATime switch has been removed.
1179 }
1180 
1181 void
1183  LLVMBool Value) {
1185  Builder->DisableUnrollLoops = Value;
1186 }
1187 
1188 void
1190  LLVMBool Value) {
1191  // NOTE: The simplify-libcalls pass has been removed.
1192 }
1193 
1194 void
1196  unsigned Threshold) {
1198  Builder->Inliner = createFunctionInliningPass(Threshold);
1199 }
1200 
1201 void
1203  LLVMPassManagerRef PM) {
1205  legacy::FunctionPassManager *FPM = unwrap<legacy::FunctionPassManager>(PM);
1206  Builder->populateFunctionPassManager(*FPM);
1207 }
1208 
1209 void
1211  LLVMPassManagerRef PM) {
1213  legacy::PassManagerBase *MPM = unwrap(PM);
1214  Builder->populateModulePassManager(*MPM);
1215 }
1216 
1218  LLVMPassManagerRef PM,
1219  LLVMBool Internalize,
1220  LLVMBool RunInliner) {
1222  legacy::PassManagerBase *LPM = unwrap(PM);
1223 
1224  // A small backwards compatibility hack. populateLTOPassManager used to take
1225  // an RunInliner option.
1226  if (RunInliner && !Builder->Inliner)
1227  Builder->Inliner = createFunctionInliningPass();
1228 
1229  Builder->populateLTOPassManager(*LPM);
1230 }
Super simple passes to force specific function attrs from the commandline into the IR for debugging p...
Defines passes for running instruction simplification across chunks of IR.
cl::opt< bool > EnableOrderFileInstrumentation("enable-order-file-instrumentation", cl::init(false), cl::Hidden, cl::desc("Enable order file instrumentation (default = off)"))
ModulePass * createPGOInstrumentationGenLegacyPass(bool IsCS=false)
ModulePass * createNameAnonGlobalPass()
===------------------------------------------------------------------—===//
Pass * createSimpleLoopUnrollPass(int OptLevel=2, bool OnlyWhenForced=false, bool ForgetAllSCEV=false)
Pass * createLoopRerollPass()
Thresholds to tune inline cost analysis.
Definition: InlineCost.h:160
Pass * createVectorCombinePass()
void LLVMPassManagerBuilderSetOptLevel(LLVMPassManagerBuilderRef PMB, unsigned OptLevel)
See llvm::PassManagerBuilder::OptLevel.
ModulePass * createStripDeadPrototypesPass()
createStripDeadPrototypesPass - This pass removes any function declarations (prototypes) that are not...
static cl::opt< bool > UseLoopVersioningLICM("enable-loop-versioning-licm", cl::init(false), cl::Hidden, cl::desc("Enable the experimental Loop Versioning LICM pass"))
PassManagerBuilder - This class is used to set up a standard optimization sequence for languages like...
partial Partial Inliner
This is the interface for LLVM&#39;s inclusion-based alias analysis implemented with CFL graph reachabili...
This class represents lattice values for constants.
Definition: AllocatorList.h:23
ModulePass * createMergeFunctionsPass()
createMergeFunctionsPass - This pass discovers identical functions and collapses them.
cl::opt< bool > ForgetSCEVInLoopUnroll
This is the interface for a simple mod/ref and alias analysis over globals.
FunctionPass * createPGOMemOPSizeOptLegacyPass()
void populateThinLTOPassManager(legacy::PassManagerBase &PM)
static GlobalExtensionID addGlobalExtension(ExtensionPointTy Ty, ExtensionFn Fn)
Adds an extension that will be used by all PassManagerBuilder instances.
void LLVMPassManagerBuilderSetDisableSimplifyLibCalls(LLVMPassManagerBuilderRef PMB, LLVMBool Value)
See llvm::PassManagerBuilder::DisableSimplifyLibCalls.
Pass * createLoopVectorizePass()
This is the interface for a metadata-based scoped no-alias analysis.
FunctionPass * createVerifierPass(bool FatalErrors=true)
Definition: Verifier.cpp:5871
ModulePass * createIPSCCPPass()
createIPSCCPPass - This pass propagates constants from call sites into the bodies of functions...
Definition: SCCP.cpp:93
FunctionPass * createFloat2IntPass()
Definition: Float2Int.cpp:539
FunctionPass * createAssumeSimplifyPass()
virtual void add(Pass *P)=0
Add a pass to the queue of passes to run.
static cl::opt< bool > EnableGVNSink("enable-gvn-sink", cl::init(false), cl::ZeroOrMore, cl::desc("Enable the GVN sinking pass (default = off)"))
void LLVMPassManagerBuilderSetDisableUnrollLoops(LLVMPassManagerBuilderRef PMB, LLVMBool Value)
See llvm::PassManagerBuilder::DisableUnrollLoops.
ModulePass * createEliminateAvailableExternallyPass()
This transform is designed to eliminate available external globals (functions or global variables) ...
FunctionPass * createGVNHoistPass()
Definition: GVNHoist.cpp:1209
ModulePass * createCanonicalizeAliasesPass()
ImmutablePass * createScopedNoAliasAAWrapperPass()
FunctionPass * createAlignmentFromAssumptionsPass()
void LLVMPassManagerBuilderPopulateLTOPassManager(LLVMPassManagerBuilderRef PMB, LLVMPassManagerRef PM, LLVMBool Internalize, LLVMBool RunInliner)
See llvm::PassManagerBuilder::populateLTOPassManager.
Pass * Inliner
Inliner - Specifies the inliner to use.
FunctionPass * createJumpThreadingPass(int Threshold=-1)
cl::opt< bool > FlattenedProfileUsed("flattened-profile-used", cl::init(false), cl::Hidden, cl::desc("Indicate the sample profile being used is flattened, i.e., " "no inline hierachy exists in the profile. "))
ModulePass * createPGOInstrumentationGenCreateVarLegacyPass(StringRef CSInstrName=StringRef(""))
ModulePass * createInstrProfilingLegacyPass(const InstrProfOptions &Options=InstrProfOptions(), bool IsCS=false)
Insert frontend instrumentation based profiling. Parameter IsCS indicates if.
ModulePass * createPartialInliningPass()
createPartialInliningPass - This pass inlines parts of functions.
FunctionPass * createMergedLoadStoreMotionPass(bool SplitFooterBB=false)
createMergedLoadStoreMotionPass - The public interface to this file.
Attribute unwrap(LLVMAttributeRef Attr)
Definition: Attributes.h:217
Optional< int > HintThreshold
Threshold to use for callees with inline hint.
Definition: InlineCost.h:165
void populateLTOPassManager(legacy::PassManagerBase &PM)
ModulePass * createCrossDSOCFIPass()
This pass export CFI checks for use by external modules.
static cl::opt< bool > ExtraVectorizerPasses("extra-vectorizer-passes", cl::init(false), cl::Hidden, cl::desc("Run cleanup optimization passes after vectorization."))
FunctionPass * createReassociatePass()
Pass * createArgumentPromotionPass(unsigned maxElements=3)
createArgumentPromotionPass - This pass promotes "by reference" arguments to be passed by value if th...
FunctionPass * createAggressiveInstCombinerPass()
static cl::opt< bool > EnablePrepareForThinLTO("prepare-for-thinlto", cl::init(false), cl::Hidden, cl::desc("Enable preparation for ThinLTO."))
FunctionPass * createSCCPPass()
Definition: SCCP.cpp:1789
ModulePass * createInstrOrderFilePass()
void add(Pass *P) override
Add a pass to the queue of passes to run.
static cl::opt< bool > EnableMatrix("enable-matrix", cl::init(false), cl::Hidden, cl::desc("Enable lowering of the matrix intrinsics"))
FunctionPass * createCFGSimplificationPass(SimplifyCFGOptions Options=SimplifyCFGOptions(), std::function< bool(const Function &)> Ftor=nullptr)
std::function< void(const PassManagerBuilder &Builder, legacy::PassManagerBase &PM)> ExtensionFn
Extensions are passed to the builder itself (so they can see how it is configured) as well as the pas...
unsigned OptLevel
The Optimization Level - Specify the basic optimization level.
cl::opt< bool > EnableKnowledgeRetention
static cl::opt< bool > UseGVNAfterVectorization("use-gvn-after-vectorization", cl::init(false), cl::Hidden, cl::desc("Run GVN instead of Early CSE after vectorization passes"))
void populateModulePassManager(legacy::PassManagerBase &MPM)
populateModulePassManager - This sets up the primary pass manager.
static cl::opt< bool > DisablePreInliner("disable-preinline", cl::init(false), cl::Hidden, cl::desc("Disable pre-instrumentation inliner"))
ModulePass * createCalledValuePropagationPass()
createCalledValuePropagationPass - Attach metadata to indirct call sites indicating the set of functi...
FunctionPass * createInstSimplifyLegacyPass()
Create a legacy pass that does instruction simplification on each instruction in a function...
Pass * createLoopInstSimplifyPass()
void LLVMPassManagerBuilderSetSizeLevel(LLVMPassManagerBuilderRef PMB, unsigned SizeLevel)
See llvm::PassManagerBuilder::SizeLevel.
FunctionPass * createInstructionCombiningPass()
ModulePass * createSampleProfileLoaderPass()
ModulePass * createGlobalDCEPass()
createGlobalDCEPass - This transform is designed to eliminate unreachable internal globals (functions...
static cl::opt< bool > EnableUnrollAndJam("enable-unroll-and-jam", cl::init(false), cl::Hidden, cl::desc("Enable Unroll And Jam Pass"))
Pass * createLoopUnrollAndJamPass(int OptLevel=2)
Pass * createAttributorCGSCCLegacyPass()
Pass * createCorrelatedValuePropagationPass()
struct LLVMOpaquePassManagerBuilder * LLVMPassManagerBuilderRef
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:434
This is the interface for a metadata-based TBAA.
FunctionPass * createTailCallEliminationPass()
This file provides the interface for LLVM&#39;s Global Value Numbering pass which eliminates fully redund...
ValuesClass values(OptsTy... Options)
Helper to build a ValuesClass by forwarding a variable number of arguments as an initializer list to ...
Definition: CommandLine.h:690
FunctionPass * createPromoteMemoryToRegisterPass()
Definition: Mem2Reg.cpp:114
static cl::opt< bool > EnableGVNHoist("enable-gvn-hoist", cl::init(false), cl::ZeroOrMore, cl::desc("Enable the GVN hoisting pass (default = off)"))
This file provides the primary interface to the instcombine pass.
ModulePass * createDeadArgEliminationPass()
createDeadArgEliminationPass - This pass removes arguments from functions which are not used by the b...
cl::opt< bool > EnableHotColdSplit("hot-cold-split", cl::init(false), cl::ZeroOrMore, cl::desc("Enable hot-cold splitting pass"))
void LLVMPassManagerBuilderDispose(LLVMPassManagerBuilderRef PMB)
Pass * createLICMPass()
Definition: LICM.cpp:278
ModulePass * createLowerTypeTestsPass(ModuleSummaryIndex *ExportSummary, const ModuleSummaryIndex *ImportSummary, bool DropTypeTests=false)
This pass lowers type metadata and the llvm.type.test intrinsic to bitsets.
FunctionPass * createDivRemPairsPass()
FunctionPass * createDeadStoreEliminationPass()
cl::opt< unsigned > SetLicmMssaOptCap
constexpr double e
Definition: MathExtras.h:58
ModulePass * createBarrierNoopPass()
createBarrierNoopPass - This pass is purely a module pass barrier in a pass manager.
FunctionPass * createMemCpyOptPass()
The public interface to this file...
FunctionPass * createBitTrackingDCEPass()
Definition: BDCE.cpp:206
ModulePass * createConstantMergePass()
createConstantMergePass - This function returns a new pass that merges duplicate global constants tog...
Pass * createLoopSinkPass()
ModulePass * createGlobalOptimizerPass()
createGlobalOptimizerPass - This function returns a new pass that optimizes non-address taken interna...
Definition: GlobalOpt.cpp:3200
Pass * createReversePostOrderFunctionAttrsPass()
createReversePostOrderFunctionAttrsPass - This pass walks SCCs of the call graph in RPO to deduce and...
assume Assume Builder
void populateFunctionPassManager(legacy::FunctionPassManager &FPM)
populateFunctionPassManager - This fills in the function pass manager, which is expected to be run on...
Pass * createWarnMissedTransformationsPass()
FunctionPassManager manages FunctionPasses.
int LLVMBool
Definition: Types.h:28
Pass * createPostOrderFunctionAttrsLegacyPass()
Create a legacy pass manager instance of a pass to compute function attrs in post-order.
std::string InstrProfileOutput
Pass * createLoopVersioningLICMPass()
ModulePass * createGlobalSplitPass()
This pass splits globals into pieces for the benefit of whole-program devirtualization and control-fl...
static cl::opt< bool > EnableLoopInterchange("enable-loopinterchange", cl::init(false), cl::Hidden, cl::desc("Enable the new, experimental LoopInterchange Pass"))
This file provides the primary interface to the aggressive instcombine pass.
Pass * createOpenMPOptLegacyPass()
createOpenMPOptLegacyPass - OpenMP specific optimizations.
Definition: OpenMPOpt.cpp:1501
Pass * createLoopInterchangePass()
PassManagerBase - An abstract interface to allow code to add passes to a pass manager without having ...
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:883
FunctionPass * createLoopLoadEliminationPass()
FunctionPass * createLowerConstantIntrinsicsPass()
Pass * createSimpleLoopUnswitchLegacyPass(bool NonTrivial=false)
Create the legacy pass object for the simple loop unswitcher.
static cl::opt< CFLAAType > UseCFLAA("use-cfl-aa", cl::init(CFLAAType::None), cl::Hidden, cl::desc("Enable the new, experimental CFL alias analysis"), cl::values(clEnumValN(CFLAAType::None, "none", "Disable CFL-AA"), clEnumValN(CFLAAType::Steensgaard, "steens", "Enable unification-based CFL-AA"), clEnumValN(CFLAAType::Andersen, "anders", "Enable inclusion-based CFL-AA"), clEnumValN(CFLAAType::Both, "both", "Enable both variants of CFL-AA")))
Pass * createLoopSimplifyCFGPass()
FunctionPass * createSpeculativeExecutionIfHasBranchDivergencePass()
FunctionPass * createLibCallsShrinkWrapPass()
struct LLVMOpaquePassManager * LLVMPassManagerRef
Definition: Types.h:127
ModulePass * createPGOInstrumentationUseLegacyPass(StringRef Filename=StringRef(""), bool IsCS=false)
Pass * createLoopDeletionPass()
Pass * createLoopUnswitchPass(bool OptimizeForSize=false, bool hasBranchDivergence=false)
Options for the frontend instrumentation based profiling pass.
static cl::opt< unsigned > Threshold("loop-unswitch-threshold", cl::desc("Max loop size to unswitch"), cl::init(100), cl::Hidden)
Pass * createLoopIdiomPass()
#define clEnumValN(ENUMVAL, FLAGNAME, DESC)
Definition: CommandLine.h:665
ModulePass * createWholeProgramDevirtPass(ModuleSummaryIndex *ExportSummary, const ModuleSummaryIndex *ImportSummary)
This pass implements whole-program devirtualization using type metadata.
Interfaces for passes which infer implicit function attributes from the name and signature of functio...
LLVMPassManagerBuilderRef LLVMPassManagerBuilderCreate()
See llvm::PassManagerBuilder.
static ManagedStatic< SmallVector< std::tuple< PassManagerBuilder::ExtensionPointTy, PassManagerBuilder::ExtensionFn, PassManagerBuilder::GlobalExtensionID >, 8 > > GlobalExtensions
Set of global extensions, automatically added as part of the standard set.
cl::opt< unsigned > SetLicmMssaNoAccForPromotionCap
void LLVMPassManagerBuilderPopulateModulePassManager(LLVMPassManagerBuilderRef PMB, LLVMPassManagerRef PM)
See llvm::PassManagerBuilder::populateModulePassManager.
LLVMAttributeRef wrap(Attribute Attr)
Definition: Attributes.h:212
ModulePass * createHotColdSplittingPass()
createHotColdSplittingPass - This pass outlines cold blocks into a separate function(s).
Pass * createAttributorLegacyPass()
unsigned SizeLevel
SizeLevel - How much we&#39;re optimizing for size.
static cl::opt< bool > DisableLibCallsShrinkWrap("disable-libcalls-shrinkwrap", cl::init(false), cl::Hidden, cl::desc("Disable shrink-wrap library calls"))
static void removeGlobalExtension(GlobalExtensionID ExtensionID)
Removes an extension that was previously added using addGlobalExtension.
FunctionPass * createGVNSinkPass()
Definition: GVNSink.cpp:935
ModulePass * createGlobalsAAWrapperPass()
FunctionPass * createSROAPass()
Definition: SROA.cpp:4773
Pass * createInferFunctionAttrsLegacyPass()
Create a legacy pass manager instance of a pass to infer function attributes.
static bool GlobalExtensionsNotEmpty()
Check if GlobalExtensions is constructed and not empty.
Provides passes for computing function attributes based on interprocedural analyses.
ImmutablePass * createCFLSteensAAWrapperPass()
ImmutablePass * createTypeBasedAAWrapperPass()
static PassManagerBuilder::GlobalExtensionID GlobalExtensionsCounter
Pass * createLoopUnrollPass(int OptLevel=2, bool OnlyWhenForced=false, bool ForgetAllSCEV=false, int Threshold=-1, int Count=-1, int AllowPartial=-1, int Runtime=-1, int UpperBound=-1, int AllowPeeling=-1)
Pass * createSLPVectorizerPass()
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
void LLVMPassManagerBuilderSetDisableUnitAtATime(LLVMPassManagerBuilderRef PMB, LLVMBool Value)
See llvm::PassManagerBuilder::DisableUnitAtATime.
static cl::opt< bool > EnableCHR("enable-chr", cl::init(true), cl::Hidden, cl::desc("Enable control height reduction optimization (CHR)"))
Pass * createFunctionInliningPass()
createFunctionInliningPass - Return a new pass object that uses a heuristic to inline direct function...
Pass * createPruneEHPass()
createPruneEHPass - Return a new pass object which transforms invoke instructions into calls...
Definition: PruneEH.cpp:61
LLVM Value Representation.
Definition: Value.h:74
Pass * createLowerMatrixIntrinsicsPass()
FunctionPass * createEarlyCSEPass(bool UseMemorySSA=false)
Definition: EarlyCSE.cpp:1476
static cl::opt< int > PreInlineThreshold("preinline-threshold", cl::Hidden, cl::init(75), cl::ZeroOrMore, cl::desc("Control the amount of inlining in pre-instrumentation inliner " "(default = 75)"))
FunctionPass * createNewGVNPass()
Definition: NewGVN.cpp:4228
This is the interface for LLVM&#39;s primary stateless and local alias analysis.
static cl::opt< bool > RunPartialInlining("enable-partial-inlining", cl::init(false), cl::Hidden, cl::ZeroOrMore, cl::desc("Run Partial inlinining pass"))
ManagedStatic - This transparently changes the behavior of global statics to be lazily constructed on...
Definition: ManagedStatic.h:83
FunctionPass * createControlHeightReductionLegacyPass()
static cl::opt< bool > EnablePerformThinLTO("perform-thinlto", cl::init(false), cl::Hidden, cl::desc("Enable performing ThinLTO."))
static cl::opt< bool > EnableSimpleLoopUnswitch("enable-simple-loop-unswitch", cl::init(false), cl::Hidden, cl::desc("Enable the simple loop unswitch pass. Also enables independent " "cleanup passes integrated into the loop pass manager pipeline."))
void LLVMPassManagerBuilderPopulateFunctionPassManager(LLVMPassManagerBuilderRef PMB, LLVMPassManagerRef PM)
See llvm::PassManagerBuilder::populateFunctionPassManager.
ImmutablePass * createCFLAndersAAWrapperPass()
void addExtension(ExtensionPointTy Ty, ExtensionFn Fn)
FunctionPass * createEntryExitInstrumenterPass()
cl::opt< AttributorRunOption > AttributorRun("attributor-enable", cl::Hidden, cl::init(AttributorRunOption::NONE), cl::desc("Enable the attributor inter-procedural deduction pass."), cl::values(clEnumValN(AttributorRunOption::ALL, "all", "enable all attributor runs"), clEnumValN(AttributorRunOption::MODULE, "module", "enable module-wide attributor runs"), clEnumValN(AttributorRunOption::CGSCC, "cgscc", "enable call graph SCC attributor runs"), clEnumValN(AttributorRunOption::NONE, "none", "disable attributor runs")))
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly...
Definition: STLExtras.h:1518
ModulePass * createPGOIndirectCallPromotionLegacyPass(bool InLTO=false, bool SamplePGO=false)
Pass * createForceFunctionAttrsLegacyPass()
Create a legacy pass manager instance of a pass to force function attrs.
Pass * createLoopRotatePass(int MaxHeaderSize=-1)
Pass * createIndVarSimplifyPass()
FunctionPass * createGVNPass(bool NoMemDepAnalysis=false)
Create a legacy GVN pass.
Definition: GVN.cpp:2772
FunctionPass * createAggressiveDCEPass()
Definition: ADCE.cpp:747
int DefaultThreshold
The default threshold to start with for a callee.
Definition: InlineCost.h:162
FunctionPass * createLoopDistributePass()
FunctionPass * createLowerExpectIntrinsicPass()
ModulePass * createCGProfileLegacyPass()
static cl::opt< bool > RunLoopRerolling("reroll-loops", cl::Hidden, cl::desc("Run the loop rerolling pass"))
static cl::opt< bool > RunNewGVN("enable-newgvn", cl::init(false), cl::Hidden, cl::desc("Run the NewGVN pass"))
void LLVMPassManagerBuilderUseInlinerWithThreshold(LLVMPassManagerBuilderRef PMB, unsigned Threshold)
See llvm::PassManagerBuilder::Inliner.
FunctionPass * createCallSiteSplittingPass()