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