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> EnableLoopFlatten("enable-loop-flatten", cl::init(false),
96  cl::Hidden,
97  cl::desc("Enable the LoopFlatten Pass"));
98 
99 static cl::opt<bool>
100  EnablePrepareForThinLTO("prepare-for-thinlto", cl::init(false), cl::Hidden,
101  cl::desc("Enable preparation for ThinLTO."));
102 
103 static cl::opt<bool>
104  EnablePerformThinLTO("perform-thinlto", cl::init(false), cl::Hidden,
105  cl::desc("Enable performing ThinLTO."));
106 
107 cl::opt<bool> EnableHotColdSplit("hot-cold-split", cl::init(false),
108  cl::ZeroOrMore, cl::desc("Enable hot-cold splitting pass"));
109 
111  "enable-loop-versioning-licm", cl::init(false), cl::Hidden,
112  cl::desc("Enable the experimental Loop Versioning LICM pass"));
113 
115  DisablePreInliner("disable-preinline", cl::init(false), cl::Hidden,
116  cl::desc("Disable pre-instrumentation inliner"));
117 
119  "preinline-threshold", cl::Hidden, cl::init(75), cl::ZeroOrMore,
120  cl::desc("Control the amount of inlining in pre-instrumentation inliner "
121  "(default = 75)"));
122 
124  "enable-gvn-hoist", cl::init(false), cl::ZeroOrMore,
125  cl::desc("Enable the GVN hoisting pass (default = off)"));
126 
127 static cl::opt<bool>
128  DisableLibCallsShrinkWrap("disable-libcalls-shrinkwrap", cl::init(false),
129  cl::Hidden,
130  cl::desc("Disable shrink-wrap library calls"));
131 
133  "enable-simple-loop-unswitch", cl::init(false), cl::Hidden,
134  cl::desc("Enable the simple loop unswitch pass. Also enables independent "
135  "cleanup passes integrated into the loop pass manager pipeline."));
136 
138  "enable-gvn-sink", cl::init(false), cl::ZeroOrMore,
139  cl::desc("Enable the GVN sinking pass (default = off)"));
140 
141 // This option is used in simplifying testing SampleFDO optimizations for
142 // profile loading.
143 static cl::opt<bool>
144  EnableCHR("enable-chr", cl::init(true), cl::Hidden,
145  cl::desc("Enable control height reduction optimization (CHR)"));
146 
148  "flattened-profile-used", cl::init(false), cl::Hidden,
149  cl::desc("Indicate the sample profile being used is flattened, i.e., "
150  "no inline hierachy exists in the profile. "));
151 
153  "enable-order-file-instrumentation", cl::init(false), cl::Hidden,
154  cl::desc("Enable order file instrumentation (default = off)"));
155 
157  "enable-matrix", cl::init(false), cl::Hidden,
158  cl::desc("Enable lowering of the matrix intrinsics"));
159 
161  "enable-constraint-elimination", cl::init(false), cl::Hidden,
162  cl::desc(
163  "Enable pass to eliminate conditions based on linear constraints."));
164 
166  "attributor-enable", cl::Hidden, cl::init(AttributorRunOption::NONE),
167  cl::desc("Enable the attributor inter-procedural deduction pass."),
169  "enable all attributor runs"),
171  "enable module-wide attributor runs"),
173  "enable call graph SCC attributor runs"),
175  "disable attributor runs")));
176 
178 
180  OptLevel = 2;
181  SizeLevel = 0;
182  LibraryInfo = nullptr;
183  Inliner = nullptr;
184  DisableUnrollLoops = false;
185  SLPVectorize = false;
186  LoopVectorize = true;
187  LoopsInterleaved = true;
188  RerollLoops = RunLoopRerolling;
189  NewGVN = RunNewGVN;
190  LicmMssaOptCap = SetLicmMssaOptCap;
191  LicmMssaNoAccForPromotionCap = SetLicmMssaNoAccForPromotionCap;
192  DisableGVNLoadPRE = false;
193  ForgetAllSCEVInLoopUnroll = ForgetSCEVInLoopUnroll;
194  VerifyInput = false;
195  VerifyOutput = false;
196  MergeFunctions = false;
197  PrepareForLTO = false;
198  EnablePGOInstrGen = false;
199  EnablePGOCSInstrGen = false;
200  EnablePGOCSInstrUse = false;
201  PGOInstrGen = "";
202  PGOInstrUse = "";
203  PGOSampleUse = "";
204  PrepareForThinLTO = EnablePrepareForThinLTO;
205  PerformThinLTO = EnablePerformThinLTO;
206  DivergentTarget = false;
207  CallGraphProfile = true;
208 }
209 
211  delete LibraryInfo;
212  delete Inliner;
213 }
214 
215 /// Set of global extensions, automatically added as part of the standard set.
216 static ManagedStatic<
220  8>>
222 static PassManagerBuilder::GlobalExtensionID GlobalExtensionsCounter;
223 
224 /// Check if GlobalExtensions is constructed and not empty.
225 /// Since GlobalExtensions is a managed static, calling 'empty()' will trigger
226 /// the construction of the object.
228  return GlobalExtensions.isConstructed() && !GlobalExtensions->empty();
229 }
230 
231 PassManagerBuilder::GlobalExtensionID
232 PassManagerBuilder::addGlobalExtension(PassManagerBuilder::ExtensionPointTy Ty,
233  PassManagerBuilder::ExtensionFn Fn) {
234  auto ExtensionID = GlobalExtensionsCounter++;
235  GlobalExtensions->push_back(std::make_tuple(Ty, std::move(Fn), ExtensionID));
236  return ExtensionID;
237 }
238 
240  PassManagerBuilder::GlobalExtensionID ExtensionID) {
241  // RegisterStandardPasses may try to call this function after GlobalExtensions
242  // has already been destroyed; doing so should not generate an error.
243  if (!GlobalExtensions.isConstructed())
244  return;
245 
246  auto GlobalExtension =
247  llvm::find_if(*GlobalExtensions, [ExtensionID](const auto &elem) {
248  return std::get<2>(elem) == ExtensionID;
249  });
250  assert(GlobalExtension != GlobalExtensions->end() &&
251  "The extension ID to be removed should always be valid.");
252 
253  GlobalExtensions->erase(GlobalExtension);
254 }
255 
257  Extensions.push_back(std::make_pair(Ty, std::move(Fn)));
258 }
259 
260 void PassManagerBuilder::addExtensionsToPM(ExtensionPointTy ETy,
261  legacy::PassManagerBase &PM) const {
262  if (GlobalExtensionsNotEmpty()) {
263  for (auto &Ext : *GlobalExtensions) {
264  if (std::get<0>(Ext) == ETy)
265  std::get<1>(Ext)(*this, PM);
266  }
267  }
268  for (unsigned i = 0, e = Extensions.size(); i != e; ++i)
269  if (Extensions[i].first == ETy)
270  Extensions[i].second(*this, PM);
271 }
272 
273 void PassManagerBuilder::addInitialAliasAnalysisPasses(
274  legacy::PassManagerBase &PM) const {
275  switch (UseCFLAA) {
278  break;
279  case CFLAAType::Andersen:
281  break;
282  case CFLAAType::Both:
285  break;
286  default:
287  break;
288  }
289 
290  // Add TypeBasedAliasAnalysis before BasicAliasAnalysis so that
291  // BasicAliasAnalysis wins if they disagree. This is intended to help
292  // support "obvious" type-punning idioms.
295 }
296 
299  addExtensionsToPM(EP_EarlyAsPossible, FPM);
301 
302  // Add LibraryInfo if we have some.
303  if (LibraryInfo)
304  FPM.add(new TargetLibraryInfoWrapperPass(*LibraryInfo));
305 
306  // The backends do not handle matrix intrinsics currently.
307  // Make sure they are also lowered in O0.
308  // FIXME: A lightweight version of the pass should run in the backend
309  // pipeline on demand.
310  if (EnableMatrix && OptLevel == 0)
312 
313  if (OptLevel == 0) return;
314 
315  addInitialAliasAnalysisPasses(FPM);
316 
318  FPM.add(createSROAPass());
319  FPM.add(createEarlyCSEPass());
321 }
322 
323 // Do PGO instrumentation generation or use pass as the option specified.
324 void PassManagerBuilder::addPGOInstrPasses(legacy::PassManagerBase &MPM,
325  bool IsCS = false) {
326  if (IsCS) {
327  if (!EnablePGOCSInstrGen && !EnablePGOCSInstrUse)
328  return;
329  } else if (!EnablePGOInstrGen && PGOInstrUse.empty() && PGOSampleUse.empty())
330  return;
331 
332  // Perform the preinline and cleanup passes for O1 and above.
333  // And avoid doing them if optimizing for size.
334  // We will not do this inline for context sensitive PGO (when IsCS is true).
335  if (OptLevel > 0 && SizeLevel == 0 && !DisablePreInliner &&
336  PGOSampleUse.empty() && !IsCS) {
337  // Create preinline pass. We construct an InlineParams object and specify
338  // the threshold here to avoid the command line options of the regular
339  // inliner to influence pre-inlining. The only fields of InlineParams we
340  // care about are DefaultThreshold and HintThreshold.
341  InlineParams IP;
343  // FIXME: The hint threshold has the same value used by the regular inliner.
344  // This should probably be lowered after performance testing.
345  IP.HintThreshold = 325;
346 
348  MPM.add(createSROAPass());
349  MPM.add(createEarlyCSEPass()); // Catch trivial redundancies
350  MPM.add(createCFGSimplificationPass()); // Merge & remove BBs
351  MPM.add(createInstructionCombiningPass()); // Combine silly seq's
352  addExtensionsToPM(EP_Peephole, MPM);
353  }
354  if ((EnablePGOInstrGen && !IsCS) || (EnablePGOCSInstrGen && IsCS)) {
356  // Add the profile lowering pass.
357  InstrProfOptions Options;
358  if (!PGOInstrGen.empty())
359  Options.InstrProfileOutput = PGOInstrGen;
360  Options.DoCounterPromotion = true;
361  Options.UseBFIInPromotion = IsCS;
362  MPM.add(createLoopRotatePass());
363  MPM.add(createInstrProfilingLegacyPass(Options, IsCS));
364  }
365  if (!PGOInstrUse.empty())
366  MPM.add(createPGOInstrumentationUseLegacyPass(PGOInstrUse, IsCS));
367  // Indirect call promotion that promotes intra-module targets only.
368  // For ThinLTO this is done earlier due to interactions with globalopt
369  // for imported functions. We don't run this at -O0.
370  if (OptLevel > 0 && !IsCS)
371  MPM.add(
372  createPGOIndirectCallPromotionLegacyPass(false, !PGOSampleUse.empty()));
373 }
374 void PassManagerBuilder::addFunctionSimplificationPasses(
376  // Start of function pass.
377  // Break up aggregate allocas, using SSAUpdater.
378  assert(OptLevel >= 1 && "Calling function optimizer with no optimization level!");
379  MPM.add(createSROAPass());
380  MPM.add(createEarlyCSEPass(true /* Enable mem-ssa. */)); // Catch trivial redundancies
381  if (EnableKnowledgeRetention)
383 
384  if (OptLevel > 1) {
385  if (EnableGVNHoist)
386  MPM.add(createGVNHoistPass());
387  if (EnableGVNSink) {
388  MPM.add(createGVNSinkPass());
390  }
391  }
392 
393  if (EnableConstraintElimination)
395 
396  if (OptLevel > 1) {
397  // Speculative execution if the target has divergent branches; otherwise nop.
399 
400  MPM.add(createJumpThreadingPass()); // Thread jumps.
401  MPM.add(createCorrelatedValuePropagationPass()); // Propagate conditionals
402  }
403  MPM.add(createCFGSimplificationPass()); // Merge & remove BBs
404  // Combine silly seq's
405  if (OptLevel > 2)
408  if (SizeLevel == 0 && !DisableLibCallsShrinkWrap)
410  addExtensionsToPM(EP_Peephole, MPM);
411 
412  // Optimize memory intrinsic calls based on the profiled size information.
413  if (SizeLevel == 0)
415 
416  // TODO: Investigate the cost/benefit of tail call elimination on debugging.
417  if (OptLevel > 1)
418  MPM.add(createTailCallEliminationPass()); // Eliminate tail calls
419  MPM.add(createCFGSimplificationPass()); // Merge & remove BBs
420  MPM.add(createReassociatePass()); // Reassociate expressions
421 
422  // Begin the loop pass pipeline.
423  if (EnableSimpleLoopUnswitch) {
424  // The simple loop unswitch pass relies on separate cleanup passes. Schedule
425  // them first so when we re-process a loop they run before other loop
426  // passes.
429  }
430  // Rotate Loop - disable header duplication at -Oz
431  MPM.add(createLoopRotatePass(SizeLevel == 2 ? 0 : -1));
432  // TODO: Investigate promotion cap for O1.
433  MPM.add(createLICMPass(LicmMssaOptCap, LicmMssaNoAccForPromotionCap));
434  if (EnableSimpleLoopUnswitch)
436  else
437  MPM.add(createLoopUnswitchPass(SizeLevel || OptLevel < 3, DivergentTarget));
438  // FIXME: We break the loop pass pipeline here in order to do full
439  // simplify-cfg. Eventually loop-simplifycfg should be enhanced to replace the
440  // need for this.
443  // We resume loop passes creating a second loop pipeline here.
444  if (EnableLoopFlatten) {
445  MPM.add(createLoopFlattenPass()); // Flatten loops
447  }
448  MPM.add(createIndVarSimplifyPass()); // Canonicalize indvars
449  MPM.add(createLoopIdiomPass()); // Recognize idioms like memset.
450  addExtensionsToPM(EP_LateLoopOptimizations, MPM);
451  MPM.add(createLoopDeletionPass()); // Delete dead loops
452 
453  if (EnableLoopInterchange)
454  MPM.add(createLoopInterchangePass()); // Interchange loops
455 
456  // Unroll small loops
457  MPM.add(createSimpleLoopUnrollPass(OptLevel, DisableUnrollLoops,
458  ForgetAllSCEVInLoopUnroll));
459  addExtensionsToPM(EP_LoopOptimizerEnd, MPM);
460  // This ends the loop pass pipelines.
461 
462  // Break up allocas that may now be splittable after loop unrolling.
463  MPM.add(createSROAPass());
464 
465  if (OptLevel > 1) {
466  MPM.add(createMergedLoadStoreMotionPass()); // Merge ld/st in diamonds
467  MPM.add(NewGVN ? createNewGVNPass()
468  : createGVNPass(DisableGVNLoadPRE)); // Remove redundancies
469  }
470  MPM.add(createMemCpyOptPass()); // Remove memcpy / form memset
471  MPM.add(createSCCPPass()); // Constant prop with SCCP
472 
473  // Delete dead bit computations (instcombine runs after to fold away the dead
474  // computations, and then ADCE will run later to exploit any new DCE
475  // opportunities that creates).
476  MPM.add(createBitTrackingDCEPass()); // Delete dead bit computations
477 
478  // Run instcombine after redundancy elimination to exploit opportunities
479  // opened up by them.
481  addExtensionsToPM(EP_Peephole, MPM);
482  if (OptLevel > 1) {
483  MPM.add(createJumpThreadingPass()); // Thread jumps
485  }
486  MPM.add(createAggressiveDCEPass()); // Delete dead instructions
487 
488  // TODO: Investigate if this is too expensive at O1.
489  if (OptLevel > 1) {
490  MPM.add(createDeadStoreEliminationPass()); // Delete dead stores
491  MPM.add(createLICMPass(LicmMssaOptCap, LicmMssaNoAccForPromotionCap));
492  }
493 
494  addExtensionsToPM(EP_ScalarOptimizerLate, MPM);
495 
496  if (RerollLoops)
497  MPM.add(createLoopRerollPass());
498 
499  MPM.add(createCFGSimplificationPass()); // Merge & remove BBs
500  // Clean up after everything.
502  addExtensionsToPM(EP_Peephole, MPM);
503 
504  if (EnableCHR && OptLevel >= 3 &&
505  (!PGOInstrUse.empty() || !PGOSampleUse.empty() || EnablePGOCSInstrGen))
507 }
508 
511  // Whether this is a default or *LTO pre-link pipeline. The FullLTO post-link
512  // is handled separately, so just check this is not the ThinLTO post-link.
513  bool DefaultOrPreLinkPipeline = !PerformThinLTO;
514 
516 
517  if (!PGOSampleUse.empty()) {
518  MPM.add(createPruneEHPass());
519  // In ThinLTO mode, when flattened profile is used, all the available
520  // profile information will be annotated in PreLink phase so there is
521  // no need to load the profile again in PostLink.
522  if (!(FlattenedProfileUsed && PerformThinLTO))
523  MPM.add(createSampleProfileLoaderPass(PGOSampleUse));
524  }
525 
526  // Allow forcing function attributes as a debugging and tuning aid.
528 
529  // If all optimizations are disabled, just run the always-inline pass and,
530  // if enabled, the function merging pass.
531  if (OptLevel == 0) {
532  addPGOInstrPasses(MPM);
533  if (Inliner) {
534  MPM.add(Inliner);
535  Inliner = nullptr;
536  }
537 
538  // FIXME: The BarrierNoopPass is a HACK! The inliner pass above implicitly
539  // creates a CGSCC pass manager, but we don't want to add extensions into
540  // that pass manager. To prevent this we insert a no-op module pass to reset
541  // the pass manager to get the same behavior as EP_OptimizerLast in non-O0
542  // builds. The function merging pass is
543  if (MergeFunctions)
545  else if (GlobalExtensionsNotEmpty() || !Extensions.empty())
546  MPM.add(createBarrierNoopPass());
547 
548  if (PerformThinLTO) {
549  MPM.add(createLowerTypeTestsPass(nullptr, nullptr, true));
550  // Drop available_externally and unreferenced globals. This is necessary
551  // with ThinLTO in order to avoid leaving undefined references to dead
552  // globals in the object file.
554  MPM.add(createGlobalDCEPass());
555  }
556 
557  addExtensionsToPM(EP_EnabledOnOptLevel0, MPM);
558 
559  if (PrepareForLTO || PrepareForThinLTO) {
561  // Rename anon globals to be able to export them in the summary.
562  // This has to be done after we add the extensions to the pass manager
563  // as there could be passes (e.g. Adddress sanitizer) which introduce
564  // new unnamed globals.
566  }
567  return;
568  }
569 
570  // Add LibraryInfo if we have some.
571  if (LibraryInfo)
572  MPM.add(new TargetLibraryInfoWrapperPass(*LibraryInfo));
573 
574  addInitialAliasAnalysisPasses(MPM);
575 
576  // For ThinLTO there are two passes of indirect call promotion. The
577  // first is during the compile phase when PerformThinLTO=false and
578  // intra-module indirect call targets are promoted. The second is during
579  // the ThinLTO backend when PerformThinLTO=true, when we promote imported
580  // inter-module indirect calls. For that we perform indirect call promotion
581  // earlier in the pass pipeline, here before globalopt. Otherwise imported
582  // available_externally functions look unreferenced and are removed.
583  if (PerformThinLTO) {
584  MPM.add(createPGOIndirectCallPromotionLegacyPass(/*InLTO = */ true,
585  !PGOSampleUse.empty()));
586  MPM.add(createLowerTypeTestsPass(nullptr, nullptr, true));
587  }
588 
589  // For SamplePGO in ThinLTO compile phase, we do not want to unroll loops
590  // as it will change the CFG too much to make the 2nd profile annotation
591  // in backend more difficult.
592  bool PrepareForThinLTOUsingPGOSampleProfile =
593  PrepareForThinLTO && !PGOSampleUse.empty();
594  if (PrepareForThinLTOUsingPGOSampleProfile)
595  DisableUnrollLoops = true;
596 
597  // Infer attributes about declarations if possible.
599 
600  // Infer attributes on declarations, call sites, arguments, etc.
601  if (AttributorRun & AttributorRunOption::MODULE)
603 
604  addExtensionsToPM(EP_ModuleOptimizerEarly, MPM);
605 
606  if (OptLevel > 2)
608 
609  MPM.add(createIPSCCPPass()); // IP SCCP
611 
612  MPM.add(createGlobalOptimizerPass()); // Optimize out global vars
613  // Promote any localized global vars.
615 
616  MPM.add(createDeadArgEliminationPass()); // Dead argument elimination
617 
618  MPM.add(createInstructionCombiningPass()); // Clean up after IPCP & DAE
619  addExtensionsToPM(EP_Peephole, MPM);
620  MPM.add(createCFGSimplificationPass()); // Clean up after IPCP & DAE
621 
622  // For SamplePGO in ThinLTO compile phase, we do not want to do indirect
623  // call promotion as it will change the CFG too much to make the 2nd
624  // profile annotation in backend more difficult.
625  // PGO instrumentation is added during the compile phase for ThinLTO, do
626  // not run it a second time
627  if (DefaultOrPreLinkPipeline && !PrepareForThinLTOUsingPGOSampleProfile)
628  addPGOInstrPasses(MPM);
629 
630  // Create profile COMDAT variables. Lld linker wants to see all variables
631  // before the LTO/ThinLTO link since it needs to resolve symbols/comdats.
632  if (!PerformThinLTO && EnablePGOCSInstrGen)
634 
635  // We add a module alias analysis pass here. In part due to bugs in the
636  // analysis infrastructure this "works" in that the analysis stays alive
637  // for the entire SCC pass run below.
639 
640  // Start of CallGraph SCC passes.
641  MPM.add(createPruneEHPass()); // Remove dead EH info
642  bool RunInliner = false;
643  if (Inliner) {
644  MPM.add(Inliner);
645  Inliner = nullptr;
646  RunInliner = true;
647  }
648 
649  // Infer attributes on declarations, call sites, arguments, etc. for an SCC.
650  if (AttributorRun & AttributorRunOption::CGSCC)
652 
653  // Try to perform OpenMP specific optimizations. This is a (quick!) no-op if
654  // there are no OpenMP runtime calls present in the module.
655  if (OptLevel > 1)
657 
659  if (OptLevel > 2)
660  MPM.add(createArgumentPromotionPass()); // Scalarize uninlined fn args
661 
662  addExtensionsToPM(EP_CGSCCOptimizerLate, MPM);
663  addFunctionSimplificationPasses(MPM);
664 
665  // FIXME: This is a HACK! The inliner pass above implicitly creates a CGSCC
666  // pass manager that we are specifically trying to avoid. To prevent this
667  // we must insert a no-op module pass to reset the pass manager.
668  MPM.add(createBarrierNoopPass());
669 
670  if (RunPartialInlining)
672 
673  if (OptLevel > 1 && !PrepareForLTO && !PrepareForThinLTO)
674  // Remove avail extern fns and globals definitions if we aren't
675  // compiling an object file for later LTO. For LTO we want to preserve
676  // these so they are eligible for inlining at link-time. Note if they
677  // are unreferenced they will be removed by GlobalDCE later, so
678  // this only impacts referenced available externally globals.
679  // Eventually they will be suppressed during codegen, but eliminating
680  // here enables more opportunity for GlobalDCE as it may make
681  // globals referenced by available external functions dead
682  // and saves running remaining passes on the eliminated functions.
684 
685  // CSFDO instrumentation and use pass. Don't invoke this for Prepare pass
686  // for LTO and ThinLTO -- The actual pass will be called after all inlines
687  // are performed.
688  // Need to do this after COMDAT variables have been eliminated,
689  // (i.e. after EliminateAvailableExternallyPass).
690  if (!(PrepareForLTO || PrepareForThinLTO))
691  addPGOInstrPasses(MPM, /* IsCS */ true);
692 
693  if (EnableOrderFileInstrumentation)
695 
697 
698  // The inliner performs some kind of dead code elimination as it goes,
699  // but there are cases that are not really caught by it. We might
700  // at some point consider teaching the inliner about them, but it
701  // is OK for now to run GlobalOpt + GlobalDCE in tandem as their
702  // benefits generally outweight the cost, making the whole pipeline
703  // faster.
704  if (RunInliner) {
706  MPM.add(createGlobalDCEPass());
707  }
708 
709  // If we are planning to perform ThinLTO later, let's not bloat the code with
710  // unrolling/vectorization/... now. We'll first run the inliner + CGSCC passes
711  // during ThinLTO and perform the rest of the optimizations afterward.
712  if (PrepareForThinLTO) {
713  // Ensure we perform any last passes, but do so before renaming anonymous
714  // globals in case the passes add any.
715  addExtensionsToPM(EP_OptimizerLast, MPM);
717  // Rename anon globals to be able to export them in the summary.
719  return;
720  }
721 
722  if (PerformThinLTO)
723  // Optimize globals now when performing ThinLTO, this enables more
724  // optimizations later.
726 
727  // Scheduling LoopVersioningLICM when inlining is over, because after that
728  // we may see more accurate aliasing. Reason to run this late is that too
729  // early versioning may prevent further inlining due to increase of code
730  // size. By placing it just after inlining other optimizations which runs
731  // later might get benefit of no-alias assumption in clone loop.
732  if (UseLoopVersioningLICM) {
733  MPM.add(createLoopVersioningLICMPass()); // Do LoopVersioningLICM
734  MPM.add(createLICMPass(LicmMssaOptCap, LicmMssaNoAccForPromotionCap));
735  }
736 
737  // We add a fresh GlobalsModRef run at this point. This is particularly
738  // useful as the above will have inlined, DCE'ed, and function-attr
739  // propagated everything. We should at this point have a reasonably minimal
740  // and richly annotated call graph. By computing aliasing and mod/ref
741  // information for all local globals here, the late loop passes and notably
742  // the vectorizer will be able to use them to help recognize vectorizable
743  // memory operations.
744  //
745  // Note that this relies on a bug in the pass manager which preserves
746  // a module analysis into a function pass pipeline (and throughout it) so
747  // long as the first function pass doesn't invalidate the module analysis.
748  // Thus both Float2Int and LoopRotate have to preserve AliasAnalysis for
749  // this to work. Fortunately, it is trivial to preserve AliasAnalysis
750  // (doing nothing preserves it as it is required to be conservatively
751  // correct in the face of IR changes).
753 
754  MPM.add(createFloat2IntPass());
756 
757  if (EnableMatrix) {
759  // CSE the pointer arithmetic of the column vectors. This allows alias
760  // analysis to establish no-aliasing between loads and stores of different
761  // columns of the same matrix.
762  MPM.add(createEarlyCSEPass(false));
763  }
764 
765  addExtensionsToPM(EP_VectorizerStart, MPM);
766 
767  // Re-rotate loops in all our loop nests. These may have fallout out of
768  // rotated form due to GVN or other transformations, and the vectorizer relies
769  // on the rotated form. Disable header duplication at -Oz.
770  MPM.add(createLoopRotatePass(SizeLevel == 2 ? 0 : -1));
771 
772  // Distribute loops to allow partial vectorization. I.e. isolate dependences
773  // into separate loop that would otherwise inhibit vectorization. This is
774  // currently only performed for loops marked with the metadata
775  // llvm.loop.distribute=true or when -enable-loop-distribute is specified.
777 
778  MPM.add(createLoopVectorizePass(!LoopsInterleaved, !LoopVectorize));
779 
780  // Eliminate loads by forwarding stores from the previous iteration to loads
781  // of the current iteration.
783 
784  // FIXME: Because of #pragma vectorize enable, the passes below are always
785  // inserted in the pipeline, even when the vectorizer doesn't run (ex. when
786  // on -O1 and no #pragma is found). Would be good to have these two passes
787  // as function calls, so that we can only pass them when the vectorizer
788  // changed the code.
790  if (OptLevel > 1 && ExtraVectorizerPasses) {
791  // At higher optimization levels, try to clean up any runtime overlap and
792  // alignment checks inserted by the vectorizer. We want to track correllated
793  // runtime checks for two inner loops in the same outer loop, fold any
794  // common computations, hoist loop-invariant aspects out of any outer loop,
795  // and unswitch the runtime checks if possible. Once hoisted, we may have
796  // dead (or speculatable) control flows or more combining opportunities.
797  MPM.add(createEarlyCSEPass());
800  MPM.add(createLICMPass(LicmMssaOptCap, LicmMssaNoAccForPromotionCap));
801  MPM.add(createLoopUnswitchPass(SizeLevel || OptLevel < 3, DivergentTarget));
804  }
805 
806  // Cleanup after loop vectorization, etc. Simplification passes like CVP and
807  // GVN, loop transforms, and others have already run, so it's now better to
808  // convert to more optimized IR using more aggressive simplify CFG options.
809  // The extra sinking transform can create larger basic blocks, so do this
810  // before SLP vectorization.
811  // FIXME: study whether hoisting and/or sinking of common instructions should
812  // be delayed until after SLP vectorizer.
814  .forwardSwitchCondToPhi(true)
815  .convertSwitchToLookupTable(true)
816  .needCanonicalLoops(false)
817  .hoistCommonInsts(true)
818  .sinkCommonInsts(true)));
819 
820  if (SLPVectorize) {
821  MPM.add(createSLPVectorizerPass()); // Vectorize parallel scalar chains.
822  if (OptLevel > 1 && ExtraVectorizerPasses) {
823  MPM.add(createEarlyCSEPass());
824  }
825  }
826 
827  // Enhance/cleanup vector code.
829 
830  addExtensionsToPM(EP_Peephole, MPM);
832 
833  if (EnableUnrollAndJam && !DisableUnrollLoops) {
834  // Unroll and Jam. We do this before unroll but need to be in a separate
835  // loop pass manager in order for the outer loop to be processed by
836  // unroll and jam before the inner loop is unrolled.
837  MPM.add(createLoopUnrollAndJamPass(OptLevel));
838  }
839 
840  // Unroll small loops
841  MPM.add(createLoopUnrollPass(OptLevel, DisableUnrollLoops,
842  ForgetAllSCEVInLoopUnroll));
843 
844  if (!DisableUnrollLoops) {
845  // LoopUnroll may generate some redundency to cleanup.
847 
848  // Runtime unrolling will introduce runtime check in loop prologue. If the
849  // unrolled loop is a inner loop, then the prologue will be inside the
850  // outer loop. LICM pass can help to promote the runtime check out if the
851  // checked value is loop invariant.
852  MPM.add(createLICMPass(LicmMssaOptCap, LicmMssaNoAccForPromotionCap));
853  }
854 
856 
857  // After vectorization and unrolling, assume intrinsics may tell us more
858  // about pointer alignments.
860 
861  // FIXME: We shouldn't bother with this anymore.
862  MPM.add(createStripDeadPrototypesPass()); // Get rid of dead prototypes
863 
864  // GlobalOpt already deletes dead functions and globals, at -O2 try a
865  // late pass of GlobalDCE. It is capable of deleting dead cycles.
866  if (OptLevel > 1) {
867  MPM.add(createGlobalDCEPass()); // Remove dead fns and globals.
868  MPM.add(createConstantMergePass()); // Merge dup global constants
869  }
870 
871  // See comment in the new PM for justification of scheduling splitting at
872  // this stage (\ref buildModuleSimplificationPipeline).
873  if (EnableHotColdSplit && !(PrepareForLTO || PrepareForThinLTO))
875 
876  if (MergeFunctions)
878 
879  // Add Module flag "CG Profile" based on Branch Frequency Information.
880  if (CallGraphProfile)
882 
883  // LoopSink pass sinks instructions hoisted by LICM, which serves as a
884  // canonicalization pass that enables other optimizations. As a result,
885  // LoopSink pass needs to be a very late IR pass to avoid undoing LICM
886  // result too early.
887  MPM.add(createLoopSinkPass());
888  // Get rid of LCSSA nodes.
890 
891  // This hoists/decomposes div/rem ops. It should run after other sink/hoist
892  // passes to avoid re-sinking, but before SimplifyCFG because it can allow
893  // flattening of blocks.
894  MPM.add(createDivRemPairsPass());
895 
896  // LoopSink (and other loop passes since the last simplifyCFG) might have
897  // resulted in single-entry-single-exit or empty blocks. Clean up the CFG.
899 
900  addExtensionsToPM(EP_OptimizerLast, MPM);
901 
902  if (PrepareForLTO) {
904  // Rename anon globals to be able to handle them in the summary
906  }
907 
909 }
910 
911 void PassManagerBuilder::addLTOOptimizationPasses(legacy::PassManagerBase &PM) {
912  // Load sample profile before running the LTO optimization pipeline.
913  if (!PGOSampleUse.empty()) {
914  PM.add(createPruneEHPass());
915  PM.add(createSampleProfileLoaderPass(PGOSampleUse));
916  }
917 
918  // Remove unused virtual tables to improve the quality of code generated by
919  // whole-program devirtualization and bitset lowering.
920  PM.add(createGlobalDCEPass());
921 
922  // Provide AliasAnalysis services for optimizations.
923  addInitialAliasAnalysisPasses(PM);
924 
925  // Allow forcing function attributes as a debugging and tuning aid.
927 
928  // Infer attributes about declarations if possible.
930 
931  if (OptLevel > 1) {
932  // Split call-site with more constrained arguments.
934 
935  // Indirect call promotion. This should promote all the targets that are
936  // left by the earlier promotion pass that promotes intra-module targets.
937  // This two-step promotion is to save the compile time. For LTO, it should
938  // produce the same result as if we only do promotion here.
939  PM.add(
940  createPGOIndirectCallPromotionLegacyPass(true, !PGOSampleUse.empty()));
941 
942  // Propagate constants at call sites into the functions they call. This
943  // opens opportunities for globalopt (and inlining) by substituting function
944  // pointers passed as arguments to direct uses of functions.
945  PM.add(createIPSCCPPass());
946 
947  // Attach metadata to indirect call sites indicating the set of functions
948  // they may target at run-time. This should follow IPSCCP.
950 
951  // Infer attributes on declarations, call sites, arguments, etc.
952  if (AttributorRun & AttributorRunOption::MODULE)
954  }
955 
956  // Infer attributes about definitions. The readnone attribute in particular is
957  // required for virtual constant propagation.
960 
961  // Split globals using inrange annotations on GEP indices. This can help
962  // improve the quality of generated code when virtual constant propagation or
963  // control flow integrity are enabled.
965 
966  // Apply whole-program devirtualization and virtual constant propagation.
967  PM.add(createWholeProgramDevirtPass(ExportSummary, nullptr));
968 
969  // That's all we need at opt level 1.
970  if (OptLevel == 1)
971  return;
972 
973  // Now that we internalized some globals, see if we can hack on them!
975  // Promote any localized global vars.
977 
978  // Linking modules together can lead to duplicated global constants, only
979  // keep one copy of each constant.
981 
982  // Remove unused arguments from functions.
984 
985  // Reduce the code after globalopt and ipsccp. Both can open up significant
986  // simplification opportunities, and both can propagate functions through
987  // function pointers. When this happens, we often have to resolve varargs
988  // calls, etc, so let instcombine do this.
989  if (OptLevel > 2)
992  addExtensionsToPM(EP_Peephole, PM);
993 
994  // Inline small functions
995  bool RunInliner = Inliner;
996  if (RunInliner) {
997  PM.add(Inliner);
998  Inliner = nullptr;
999  }
1000 
1001  PM.add(createPruneEHPass()); // Remove dead EH info.
1002 
1003  // CSFDO instrumentation and use pass.
1004  addPGOInstrPasses(PM, /* IsCS */ true);
1005 
1006  // Infer attributes on declarations, call sites, arguments, etc. for an SCC.
1007  if (AttributorRun & AttributorRunOption::CGSCC)
1009 
1010  // Try to perform OpenMP specific optimizations. This is a (quick!) no-op if
1011  // there are no OpenMP runtime calls present in the module.
1012  if (OptLevel > 1)
1014 
1015  // Optimize globals again if we ran the inliner.
1016  if (RunInliner)
1018  PM.add(createGlobalDCEPass()); // Remove dead functions.
1019 
1020  // If we didn't decide to inline a function, check to see if we can
1021  // transform it to pass arguments by value instead of by reference.
1023 
1024  // The IPO passes may leave cruft around. Clean up after them.
1026  addExtensionsToPM(EP_Peephole, PM);
1027  PM.add(createJumpThreadingPass(/*FreezeSelectCond*/ true));
1028 
1029  // Break up allocas
1030  PM.add(createSROAPass());
1031 
1032  // LTO provides additional opportunities for tailcall elimination due to
1033  // link-time inlining, and visibility of nocapture attribute.
1034  if (OptLevel > 1)
1036 
1037  // Infer attributes on declarations, call sites, arguments, etc.
1038  PM.add(createPostOrderFunctionAttrsLegacyPass()); // Add nocapture.
1039  // Run a few AA driven optimizations here and now, to cleanup the code.
1040  PM.add(createGlobalsAAWrapperPass()); // IP alias analysis.
1041 
1042  PM.add(createLICMPass(LicmMssaOptCap, LicmMssaNoAccForPromotionCap));
1043  PM.add(NewGVN ? createNewGVNPass()
1044  : createGVNPass(DisableGVNLoadPRE)); // Remove redundancies.
1045  PM.add(createMemCpyOptPass()); // Remove dead memcpys.
1046 
1047  // Nuke dead stores.
1049  PM.add(createMergedLoadStoreMotionPass()); // Merge ld/st in diamonds.
1050 
1051  // More loops are countable; try to optimize them.
1052  if (EnableLoopFlatten)
1053  PM.add(createLoopFlattenPass());
1056  if (EnableLoopInterchange)
1058 
1059  // Unroll small loops
1060  PM.add(createSimpleLoopUnrollPass(OptLevel, DisableUnrollLoops,
1061  ForgetAllSCEVInLoopUnroll));
1063  PM.add(createLoopVectorizePass(true, !LoopVectorize));
1064  // The vectorizer may have significantly shortened a loop body; unroll again.
1065  PM.add(createLoopUnrollPass(OptLevel, DisableUnrollLoops,
1066  ForgetAllSCEVInLoopUnroll));
1067 
1069 
1070  // Now that we've optimized loops (in particular loop induction variables),
1071  // we may have exposed more scalar opportunities. Run parts of the scalar
1072  // optimizer again at this point.
1073  PM.add(createInstructionCombiningPass()); // Initial cleanup
1074  PM.add(createCFGSimplificationPass()); // if-convert
1075  PM.add(createSCCPPass()); // Propagate exposed constants
1076  PM.add(createInstructionCombiningPass()); // Clean up again
1078 
1079  // More scalar chains could be vectorized due to more alias information
1080  if (SLPVectorize)
1081  PM.add(createSLPVectorizerPass()); // Vectorize parallel scalar chains.
1082 
1083  PM.add(createVectorCombinePass()); // Clean up partial vectorization.
1084 
1085  // After vectorization, assume intrinsics may tell us more about pointer
1086  // alignments.
1088 
1089  // Cleanup and simplify the code after the scalar optimizations.
1091  addExtensionsToPM(EP_Peephole, PM);
1092 
1093  PM.add(createJumpThreadingPass(/*FreezeSelectCond*/ true));
1094 }
1095 
1096 void PassManagerBuilder::addLateLTOOptimizationPasses(
1098  // See comment in the new PM for justification of scheduling splitting at
1099  // this stage (\ref buildLTODefaultPipeline).
1100  if (EnableHotColdSplit)
1102 
1103  // Delete basic blocks, which optimization passes may have killed.
1105 
1106  // Drop bodies of available externally objects to improve GlobalDCE.
1108 
1109  // Now that we have optimized the program, discard unreachable functions.
1110  PM.add(createGlobalDCEPass());
1111 
1112  // FIXME: this is profitable (for compiler time) to do at -O0 too, but
1113  // currently it damages debug info.
1114  if (MergeFunctions)
1116 }
1117 
1120  PerformThinLTO = true;
1121  if (LibraryInfo)
1122  PM.add(new TargetLibraryInfoWrapperPass(*LibraryInfo));
1123 
1124  if (VerifyInput)
1125  PM.add(createVerifierPass());
1126 
1127  if (ImportSummary) {
1128  // This pass imports type identifier resolutions for whole-program
1129  // devirtualization and CFI. It must run early because other passes may
1130  // disturb the specific instruction patterns that these passes look for,
1131  // creating dependencies on resolutions that may not appear in the summary.
1132  //
1133  // For example, GVN may transform the pattern assume(type.test) appearing in
1134  // two basic blocks into assume(phi(type.test, type.test)), which would
1135  // transform a dependency on a WPD resolution into a dependency on a type
1136  // identifier resolution for CFI.
1137  //
1138  // Also, WPD has access to more precise information than ICP and can
1139  // devirtualize more effectively, so it should operate on the IR first.
1140  PM.add(createWholeProgramDevirtPass(nullptr, ImportSummary));
1141  PM.add(createLowerTypeTestsPass(nullptr, ImportSummary));
1142  }
1143 
1144  populateModulePassManager(PM);
1145 
1146  if (VerifyOutput)
1147  PM.add(createVerifierPass());
1148  PerformThinLTO = false;
1149 }
1150 
1152  if (LibraryInfo)
1153  PM.add(new TargetLibraryInfoWrapperPass(*LibraryInfo));
1154 
1155  if (VerifyInput)
1156  PM.add(createVerifierPass());
1157 
1158  addExtensionsToPM(EP_FullLinkTimeOptimizationEarly, PM);
1159 
1160  if (OptLevel != 0)
1161  addLTOOptimizationPasses(PM);
1162  else {
1163  // The whole-program-devirt pass needs to run at -O0 because only it knows
1164  // about the llvm.type.checked.load intrinsic: it needs to both lower the
1165  // intrinsic itself and handle it in the summary.
1166  PM.add(createWholeProgramDevirtPass(ExportSummary, nullptr));
1167  }
1168 
1169  // Create a function that performs CFI checks for cross-DSO calls with targets
1170  // in the current module.
1171  PM.add(createCrossDSOCFIPass());
1172 
1173  // Lower type metadata and the type.test intrinsic. This pass supports Clang's
1174  // control flow integrity mechanisms (-fsanitize=cfi*) and needs to run at
1175  // link time if CFI is enabled. The pass does nothing if CFI is disabled.
1176  PM.add(createLowerTypeTestsPass(ExportSummary, nullptr));
1177  // Run a second time to clean up any type tests left behind by WPD for use
1178  // in ICP (which is performed earlier than this in the regular LTO pipeline).
1179  PM.add(createLowerTypeTestsPass(nullptr, nullptr, true));
1180 
1181  if (OptLevel != 0)
1182  addLateLTOOptimizationPasses(PM);
1183 
1184  addExtensionsToPM(EP_FullLinkTimeOptimizationLast, PM);
1185 
1187 
1188  if (VerifyOutput)
1189  PM.add(createVerifierPass());
1190 }
1191 
1194  return wrap(PMB);
1195 }
1196 
1199  delete Builder;
1200 }
1201 
1202 void
1204  unsigned OptLevel) {
1206  Builder->OptLevel = OptLevel;
1207 }
1208 
1209 void
1211  unsigned SizeLevel) {
1213  Builder->SizeLevel = SizeLevel;
1214 }
1215 
1216 void
1218  LLVMBool Value) {
1219  // NOTE: The DisableUnitAtATime switch has been removed.
1220 }
1221 
1222 void
1224  LLVMBool Value) {
1226  Builder->DisableUnrollLoops = Value;
1227 }
1228 
1229 void
1231  LLVMBool Value) {
1232  // NOTE: The simplify-libcalls pass has been removed.
1233 }
1234 
1235 void
1237  unsigned Threshold) {
1239  Builder->Inliner = createFunctionInliningPass(Threshold);
1240 }
1241 
1242 void
1244  LLVMPassManagerRef PM) {
1246  legacy::FunctionPassManager *FPM = unwrap<legacy::FunctionPassManager>(PM);
1247  Builder->populateFunctionPassManager(*FPM);
1248 }
1249 
1250 void
1252  LLVMPassManagerRef PM) {
1254  legacy::PassManagerBase *MPM = unwrap(PM);
1255  Builder->populateModulePassManager(*MPM);
1256 }
1257 
1259  LLVMPassManagerRef PM,
1260  LLVMBool Internalize,
1261  LLVMBool RunInliner) {
1263  legacy::PassManagerBase *LPM = unwrap(PM);
1264 
1265  // A small backwards compatibility hack. populateLTOPassManager used to take
1266  // an RunInliner option.
1267  if (RunInliner && !Builder->Inliner)
1268  Builder->Inliner = createFunctionInliningPass();
1269 
1270  Builder->populateLTOPassManager(*LPM);
1271 }
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)
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()
Pass * createReversePostOrderFunctionAttrsPass()
createReversePostOrderFunctionAttrsPass - This pass walks SCCs of the call graph in RPO to deduce and...
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.
FunctionPass * createLoopFlattenPass()
Pass * createLoopVectorizePass()
This is the interface for a metadata-based scoped no-alias analysis.
FunctionPass * createVerifierPass(bool FatalErrors=true)
Definition: Verifier.cpp:5927
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.
Pass * createLoopRerollPass()
Pass * createLowerMatrixIntrinsicsMinimalPass()
ModulePass * createEliminateAvailableExternallyPass()
This transform is designed to eliminate available external globals (functions or global variables) ...
FunctionPass * createGVNHoistPass()
Definition: GVNHoist.cpp:1273
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.
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. "))
FunctionPass * createJumpThreadingPass(bool FreezeSelectCond=false, int Threshold=-1)
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:229
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()
cl::opt< bool > EnableConstraintElimination("enable-constraint-elimination", cl::init(false), cl::Hidden, cl::desc("Enable pass to eliminate conditions based on linear constraints."))
static cl::opt< bool > EnablePrepareForThinLTO("prepare-for-thinlto", cl::init(false), cl::Hidden, cl::desc("Enable preparation for ThinLTO."))
FunctionPass * createSCCPPass()
Definition: SCCP.cpp:1816
ModulePass * createInstrOrderFilePass()
void add(Pass *P) override
Add a pass to the queue of passes to run.
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.
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()
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:427
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:683
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:296
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:3203
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
std::string InstrProfileOutput
static cl::opt< bool > EnableLoopFlatten("enable-loop-flatten", cl::init(false), cl::Hidden, cl::desc("Enable the LoopFlatten Pass"))
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:2298
Pass * createLoopInterchangePass()
PassManagerBase - An abstract interface to allow code to add passes to a pass manager without having ...
ModulePass * createAnnotation2MetadataLegacyPass()
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:960
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()
Pass * createPostOrderFunctionAttrsLegacyPass()
Create a legacy pass manager instance of a pass to compute function attrs in post-order.
FunctionPass * createLibCallsShrinkWrapPass()
FunctionPass * createConstraintEliminationPass()
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:658
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:224
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:933
ModulePass * createGlobalsAAWrapperPass()
FunctionPass * createSROAPass()
Definition: SROA.cpp:4834
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:63
LLVM Value Representation.
Definition: Value.h:75
Pass * createLowerMatrixIntrinsicsPass()
FunctionPass * createEarlyCSEPass(bool UseMemorySSA=false)
Definition: EarlyCSE.cpp:1687
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:4179
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly...
Definition: STLExtras.h:1556
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:1525
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:2939
FunctionPass * createAnnotationRemarksLegacyPass()
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()