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