LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Passes.cpp
Go to the documentation of this file.
1 //===-- Passes.cpp - Target independent code generation passes ------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines interfaces to access the target independent code
11 // generation passes provided by the LLVM backend.
12 //
13 //===---------------------------------------------------------------------===//
14 
15 #include "llvm/CodeGen/Passes.h"
16 #include "llvm/Analysis/Passes.h"
17 #include "llvm/Analysis/Verifier.h"
22 #include "llvm/MC/MCAsmInfo.h"
23 #include "llvm/PassManager.h"
25 #include "llvm/Support/Debug.h"
29 #include "llvm/Transforms/Scalar.h"
30 
31 using namespace llvm;
32 
33 static cl::opt<bool> DisablePostRA("disable-post-ra", cl::Hidden,
34  cl::desc("Disable Post Regalloc"));
35 static cl::opt<bool> DisableBranchFold("disable-branch-fold", cl::Hidden,
36  cl::desc("Disable branch folding"));
37 static cl::opt<bool> DisableTailDuplicate("disable-tail-duplicate", cl::Hidden,
38  cl::desc("Disable tail duplication"));
39 static cl::opt<bool> DisableEarlyTailDup("disable-early-taildup", cl::Hidden,
40  cl::desc("Disable pre-register allocation tail duplication"));
41 static cl::opt<bool> DisableBlockPlacement("disable-block-placement",
42  cl::Hidden, cl::desc("Disable probability-driven block placement"));
43 static cl::opt<bool> EnableBlockPlacementStats("enable-block-placement-stats",
44  cl::Hidden, cl::desc("Collect probability-driven block placement stats"));
45 static cl::opt<bool> DisableSSC("disable-ssc", cl::Hidden,
46  cl::desc("Disable Stack Slot Coloring"));
47 static cl::opt<bool> DisableMachineDCE("disable-machine-dce", cl::Hidden,
48  cl::desc("Disable Machine Dead Code Elimination"));
49 static cl::opt<bool> DisableEarlyIfConversion("disable-early-ifcvt", cl::Hidden,
50  cl::desc("Disable Early If-conversion"));
51 static cl::opt<bool> DisableMachineLICM("disable-machine-licm", cl::Hidden,
52  cl::desc("Disable Machine LICM"));
53 static cl::opt<bool> DisableMachineCSE("disable-machine-cse", cl::Hidden,
54  cl::desc("Disable Machine Common Subexpression Elimination"));
56 OptimizeRegAlloc("optimize-regalloc", cl::Hidden,
57  cl::desc("Enable optimized register allocation compilation path."));
59 EnableMachineSched("enable-misched", cl::Hidden,
60  cl::desc("Enable the machine instruction scheduling pass."));
61 static cl::opt<bool> DisablePostRAMachineLICM("disable-postra-machine-licm",
62  cl::Hidden,
63  cl::desc("Disable Machine LICM"));
64 static cl::opt<bool> DisableMachineSink("disable-machine-sink", cl::Hidden,
65  cl::desc("Disable Machine Sinking"));
66 static cl::opt<bool> DisableLSR("disable-lsr", cl::Hidden,
67  cl::desc("Disable Loop Strength Reduction Pass"));
68 static cl::opt<bool> DisableCGP("disable-cgp", cl::Hidden,
69  cl::desc("Disable Codegen Prepare"));
70 static cl::opt<bool> DisableCopyProp("disable-copyprop", cl::Hidden,
71  cl::desc("Disable Copy Propagation pass"));
72 static cl::opt<bool> PrintLSR("print-lsr-output", cl::Hidden,
73  cl::desc("Print LLVM IR produced by the loop-reduce pass"));
74 static cl::opt<bool> PrintISelInput("print-isel-input", cl::Hidden,
75  cl::desc("Print LLVM IR input to isel pass"));
76 static cl::opt<bool> PrintGCInfo("print-gc", cl::Hidden,
77  cl::desc("Dump garbage collector data"));
78 static cl::opt<bool> VerifyMachineCode("verify-machineinstrs", cl::Hidden,
79  cl::desc("Verify generated machine code"),
80  cl::init(getenv("LLVM_VERIFY_MACHINEINSTRS")!=NULL));
82 PrintMachineInstrs("print-machineinstrs", cl::ValueOptional,
83  cl::desc("Print machine instrs"),
84  cl::value_desc("pass-name"), cl::init("option-unspecified"));
85 
86 // Experimental option to run live interval analysis early.
87 static cl::opt<bool> EarlyLiveIntervals("early-live-intervals", cl::Hidden,
88  cl::desc("Run live interval analysis earlier in the pipeline"));
89 
90 /// Allow standard passes to be disabled by command line options. This supports
91 /// simple binary flags that either suppress the pass or do nothing.
92 /// i.e. -disable-mypass=false has no effect.
93 /// These should be converted to boolOrDefault in order to use applyOverride.
95  bool Override) {
96  if (Override)
97  return IdentifyingPassPtr();
98  return PassID;
99 }
100 
101 /// Allow Pass selection to be overriden by command line options. This supports
102 /// flags with ternary conditions. TargetID is passed through by default. The
103 /// pass is suppressed when the option is false. When the option is true, the
104 /// StandardID is selected if the target provides no default.
106  cl::boolOrDefault Override,
107  AnalysisID StandardID) {
108  switch (Override) {
109  case cl::BOU_UNSET:
110  return TargetID;
111  case cl::BOU_TRUE:
112  if (TargetID.isValid())
113  return TargetID;
114  if (StandardID == 0)
115  report_fatal_error("Target cannot enable pass");
116  return StandardID;
117  case cl::BOU_FALSE:
118  return IdentifyingPassPtr();
119  }
120  llvm_unreachable("Invalid command line option state");
121 }
122 
123 /// Allow standard passes to be disabled by the command line, regardless of who
124 /// is adding the pass.
125 ///
126 /// StandardID is the pass identified in the standard pass pipeline and provided
127 /// to addPass(). It may be a target-specific ID in the case that the target
128 /// directly adds its own pass, but in that case we harmlessly fall through.
129 ///
130 /// TargetID is the pass that the target has configured to override StandardID.
131 ///
132 /// StandardID may be a pseudo ID. In that case TargetID is the name of the real
133 /// pass to run. This allows multiple options to control a single pass depending
134 /// on where in the pipeline that pass is added.
136  IdentifyingPassPtr TargetID) {
137  if (StandardID == &PostRASchedulerID)
138  return applyDisable(TargetID, DisablePostRA);
139 
140  if (StandardID == &BranchFolderPassID)
141  return applyDisable(TargetID, DisableBranchFold);
142 
143  if (StandardID == &TailDuplicateID)
144  return applyDisable(TargetID, DisableTailDuplicate);
145 
146  if (StandardID == &TargetPassConfig::EarlyTailDuplicateID)
147  return applyDisable(TargetID, DisableEarlyTailDup);
148 
149  if (StandardID == &MachineBlockPlacementID)
150  return applyDisable(TargetID, DisableBlockPlacement);
151 
152  if (StandardID == &StackSlotColoringID)
153  return applyDisable(TargetID, DisableSSC);
154 
155  if (StandardID == &DeadMachineInstructionElimID)
156  return applyDisable(TargetID, DisableMachineDCE);
157 
158  if (StandardID == &EarlyIfConverterID)
159  return applyDisable(TargetID, DisableEarlyIfConversion);
160 
161  if (StandardID == &MachineLICMID)
162  return applyDisable(TargetID, DisableMachineLICM);
163 
164  if (StandardID == &MachineCSEID)
165  return applyDisable(TargetID, DisableMachineCSE);
166 
167  if (StandardID == &MachineSchedulerID)
168  return applyOverride(TargetID, EnableMachineSched, StandardID);
169 
170  if (StandardID == &TargetPassConfig::PostRAMachineLICMID)
171  return applyDisable(TargetID, DisablePostRAMachineLICM);
172 
173  if (StandardID == &MachineSinkingID)
174  return applyDisable(TargetID, DisableMachineSink);
175 
176  if (StandardID == &MachineCopyPropagationID)
177  return applyDisable(TargetID, DisableCopyProp);
178 
179  return TargetID;
180 }
181 
182 //===---------------------------------------------------------------------===//
183 /// TargetPassConfig
184 //===---------------------------------------------------------------------===//
185 
186 INITIALIZE_PASS(TargetPassConfig, "targetpassconfig",
187  "Target Pass Configuration", false, false)
188 char TargetPassConfig::ID = 0;
189 
190 // Pseudo Pass IDs.
191 char TargetPassConfig::EarlyTailDuplicateID = 0;
192 char TargetPassConfig::PostRAMachineLICMID = 0;
193 
194 namespace llvm {
196 public:
197  // List of passes explicitly substituted by this target. Normally this is
198  // empty, but it is a convenient way to suppress or replace specific passes
199  // that are part of a standard pass pipeline without overridding the entire
200  // pipeline. This mechanism allows target options to inherit a standard pass's
201  // user interface. For example, a target may disable a standard pass by
202  // default by substituting a pass ID of zero, and the user may still enable
203  // that standard pass with an explicit command line option.
205 
206  /// Store the pairs of <AnalysisID, AnalysisID> of which the second pass
207  /// is inserted after each instance of the first one.
209 };
210 } // namespace llvm
211 
212 // Out of line virtual method.
214  delete Impl;
215 }
216 
217 // Out of line constructor provides default values for pass options and
218 // registers all common codegen passes.
220  : ImmutablePass(ID), PM(&pm), StartAfter(0), StopAfter(0),
221  Started(true), Stopped(false), TM(tm), Impl(0), Initialized(false),
222  DisableVerify(false),
223  EnableTailMerge(true) {
224 
225  Impl = new PassConfigImpl();
226 
227  // Register all target independent codegen passes to activate their PassIDs,
228  // including this pass itself.
230 
231  // Substitute Pseudo Pass IDs for real ones.
234 
235  // Temporarily disable experimental passes.
237  if (!ST.useMachineScheduler())
239 }
240 
241 /// Insert InsertedPassID pass after TargetPassID.
243  IdentifyingPassPtr InsertedPassID) {
244  assert(((!InsertedPassID.isInstance() &&
245  TargetPassID != InsertedPassID.getID()) ||
246  (InsertedPassID.isInstance() &&
247  TargetPassID != InsertedPassID.getInstance()->getPassID())) &&
248  "Insert a pass after itself!");
249  std::pair<AnalysisID, IdentifyingPassPtr> P(TargetPassID, InsertedPassID);
250  Impl->InsertedPasses.push_back(P);
251 }
252 
253 /// createPassConfig - Create a pass configuration object to be used by
254 /// addPassToEmitX methods for generating a pipeline of CodeGen passes.
255 ///
256 /// Targets may override this to extend TargetPassConfig.
258  return new TargetPassConfig(this, PM);
259 }
260 
262  : ImmutablePass(ID), PM(0) {
263  llvm_unreachable("TargetPassConfig should not be constructed on-the-fly");
264 }
265 
266 // Helper to verify the analysis is really immutable.
267 void TargetPassConfig::setOpt(bool &Opt, bool Val) {
268  assert(!Initialized && "PassConfig is immutable");
269  Opt = Val;
270 }
271 
273  IdentifyingPassPtr TargetID) {
274  Impl->TargetPasses[StandardID] = TargetID;
275 }
276 
279  I = Impl->TargetPasses.find(ID);
280  if (I == Impl->TargetPasses.end())
281  return ID;
282  return I->second;
283 }
284 
285 /// Add a pass to the PassManager if that pass is supposed to be run. If the
286 /// Started/Stopped flags indicate either that the compilation should start at
287 /// a later pass or that it should stop after an earlier pass, then do not add
288 /// the pass. Finally, compare the current pass against the StartAfter
289 /// and StopAfter options and change the Started/Stopped flags accordingly.
291  assert(!Initialized && "PassConfig is immutable");
292 
293  // Cache the Pass ID here in case the pass manager finds this pass is
294  // redundant with ones already scheduled / available, and deletes it.
295  // Fundamentally, once we add the pass to the manager, we no longer own it
296  // and shouldn't reference it.
297  AnalysisID PassID = P->getPassID();
298 
299  if (Started && !Stopped)
300  PM->add(P);
301  else
302  delete P;
303  if (StopAfter == PassID)
304  Stopped = true;
305  if (StartAfter == PassID)
306  Started = true;
307  if (Stopped && !Started)
308  report_fatal_error("Cannot stop compilation after pass that is not run");
309 }
310 
311 /// Add a CodeGen pass at this point in the pipeline after checking for target
312 /// and command line overrides.
313 ///
314 /// addPass cannot return a pointer to the pass instance because is internal the
315 /// PassManager and the instance we create here may already be freed.
317  IdentifyingPassPtr TargetID = getPassSubstitution(PassID);
318  IdentifyingPassPtr FinalPtr = overridePass(PassID, TargetID);
319  if (!FinalPtr.isValid())
320  return 0;
321 
322  Pass *P;
323  if (FinalPtr.isInstance())
324  P = FinalPtr.getInstance();
325  else {
326  P = Pass::createPass(FinalPtr.getID());
327  if (!P)
328  llvm_unreachable("Pass ID not registered");
329  }
330  AnalysisID FinalID = P->getPassID();
331  addPass(P); // Ends the lifetime of P.
332 
333  // Add the passes after the pass P if there is any.
334  for (SmallVectorImpl<std::pair<AnalysisID, IdentifyingPassPtr> >::iterator
335  I = Impl->InsertedPasses.begin(), E = Impl->InsertedPasses.end();
336  I != E; ++I) {
337  if ((*I).first == PassID) {
338  assert((*I).second.isValid() && "Illegal Pass ID!");
339  Pass *NP;
340  if ((*I).second.isInstance())
341  NP = (*I).second.getInstance();
342  else {
343  NP = Pass::createPass((*I).second.getID());
344  assert(NP && "Pass ID not registered");
345  }
346  addPass(NP);
347  }
348  }
349  return FinalID;
350 }
351 
352 void TargetPassConfig::printAndVerify(const char *Banner) {
353  if (TM->shouldPrintMachineCode())
355 
356  if (VerifyMachineCode)
358 }
359 
360 /// Add common target configurable passes that perform LLVM IR to IR transforms
361 /// following machine independent optimization.
363  // Basic AliasAnalysis support.
364  // Add TypeBasedAliasAnalysis before BasicAliasAnalysis so that
365  // BasicAliasAnalysis wins if they disagree. This is intended to help
366  // support "obvious" type-punning idioms.
369 
370  // Before running any passes, run the verifier to determine if the input
371  // coming from the front-end and/or optimizer is valid.
372  if (!DisableVerify)
374 
375  // Run loop strength reduction before anything else.
376  if (getOptLevel() != CodeGenOpt::None && !DisableLSR) {
378  if (PrintLSR)
379  addPass(createPrintFunctionPass("\n\n*** Code after LSR ***\n", &dbgs()));
380  }
381 
383 
384  // Make sure that no unreachable blocks are instruction selected.
386 }
387 
388 /// Turn exception handling constructs into something the code generators can
389 /// handle.
391  switch (TM->getMCAsmInfo()->getExceptionHandlingType()) {
393  // SjLj piggy-backs on dwarf for this bit. The cleanups done apply to both
394  // Dwarf EH prepare needs to be run after SjLj prepare. Otherwise,
395  // catch info can get misplaced when a selector ends up more than one block
396  // removed from the parent invoke(s). This could happen when a landing
397  // pad is shared by multiple invokes and is also a target of a normal
398  // edge from elsewhere.
400  // FALLTHROUGH
405  break;
408 
409  // The lower invoke pass may create unreachable code. Remove it.
411  break;
412  }
413 }
414 
415 /// Add pass to prepare the LLVM IR for code generation. This should be done
416 /// before exception handling preparation passes.
420 }
421 
422 /// Add common passes that perform LLVM IR to IR transforms in preparation for
423 /// instruction selection.
426 
427  addPreISel();
428 
429  if (PrintISelInput)
431  "*** Final LLVM Code input to ISel ***\n",
432  &dbgs()));
433 
434  // All passes which modify the LLVM IR are now complete; run the verifier
435  // to ensure that the IR is valid.
436  if (!DisableVerify)
438 }
439 
440 /// Add the complete set of target-independent postISel code generator passes.
441 ///
442 /// This can be read as the standard order of major LLVM CodeGen stages. Stages
443 /// with nontrivial configuration or multiple passes are broken out below in
444 /// add%Stage routines.
445 ///
446 /// Any TargetPassConfig::addXX routine may be overriden by the Target. The
447 /// addPre/Post methods with empty header implementations allow injecting
448 /// target-specific fixups just before or after major stages. Additionally,
449 /// targets have the flexibility to change pass order within a stage by
450 /// overriding default implementation of add%Stage routines below. Each
451 /// technique has maintainability tradeoffs because alternate pass orders are
452 /// not well supported. addPre/Post works better if the target pass is easily
453 /// tied to a common pass. But if it has subtle dependencies on multiple passes,
454 /// the target should override the stage instead.
455 ///
456 /// TODO: We could use a single addPre/Post(ID) hook to allow pass injection
457 /// before/after any target-independent pass. But it's currently overkill.
459  // Insert a machine instr printer pass after the specified pass.
460  // If -print-machineinstrs specified, print machineinstrs after all passes.
461  if (StringRef(PrintMachineInstrs.getValue()).equals(""))
462  TM->Options.PrintMachineCode = true;
463  else if (!StringRef(PrintMachineInstrs.getValue())
464  .equals("option-unspecified")) {
466  const PassInfo *TPI = PR->getPassInfo(PrintMachineInstrs.getValue());
467  const PassInfo *IPI = PR->getPassInfo(StringRef("print-machineinstrs"));
468  assert (TPI && IPI && "Pass ID not registered!");
469  const char *TID = (const char *)(TPI->getTypeInfo());
470  const char *IID = (const char *)(IPI->getTypeInfo());
471  insertPass(TID, IID);
472  }
473 
474  // Print the instruction selected machine code...
475  printAndVerify("After Instruction Selection");
476 
477  // Expand pseudo-instructions emitted by ISel.
479  printAndVerify("After ExpandISelPseudos");
480 
481  // Add passes that optimize machine instructions in SSA form.
482  if (getOptLevel() != CodeGenOpt::None) {
484  } else {
485  // If the target requests it, assign local variables to stack slots relative
486  // to one another and simplify frame index references where possible.
488  }
489 
490  // Run pre-ra passes.
491  if (addPreRegAlloc())
492  printAndVerify("After PreRegAlloc passes");
493 
494  // Run register allocation and passes that are tightly coupled with it,
495  // including phi elimination and scheduling.
496  if (getOptimizeRegAlloc())
498  else
500 
501  // Run post-ra passes.
502  if (addPostRegAlloc())
503  printAndVerify("After PostRegAlloc passes");
504 
505  // Insert prolog/epilog code. Eliminate abstract frame index references...
507  printAndVerify("After PrologEpilogCodeInserter");
508 
509  /// Add passes that optimize machine instructions after register allocation.
510  if (getOptLevel() != CodeGenOpt::None)
512 
513  // Expand pseudo instructions before second scheduling pass.
515  printAndVerify("After ExpandPostRAPseudos");
516 
517  // Run pre-sched2 passes.
518  if (addPreSched2())
519  printAndVerify("After PreSched2 passes");
520 
521  // Second pass scheduler.
522  if (getOptLevel() != CodeGenOpt::None) {
524  printAndVerify("After PostRAScheduler");
525  }
526 
527  // GC
528  if (addGCPasses()) {
529  if (PrintGCInfo)
531  }
532 
533  // Basic block placement.
534  if (getOptLevel() != CodeGenOpt::None)
536 
537  if (addPreEmitPass())
538  printAndVerify("After PreEmit passes");
539 }
540 
541 /// Add passes that optimize machine instructions in SSA form.
543  // Pre-ra tail duplication.
545  printAndVerify("After Pre-RegAlloc TailDuplicate");
546 
547  // Optimize PHIs before DCE: removing dead PHI cycles may make more
548  // instructions dead.
550 
551  // This pass merges large allocas. StackSlotColoring is a different pass
552  // which merges spill slots.
554 
555  // If the target requests it, assign local variables to stack slots relative
556  // to one another and simplify frame index references where possible.
558 
559  // With optimization, dead code should already be eliminated. However
560  // there is one known exception: lowered code for arguments that are only
561  // used by tail calls, where the tail calls reuse the incoming stack
562  // arguments directly (see t11 in test/CodeGen/X86/sibcall.ll).
564  printAndVerify("After codegen DCE pass");
565 
566  // Allow targets to insert passes that improve instruction level parallelism,
567  // like if-conversion. Such passes will typically need dominator trees and
568  // loop info, just like LICM and CSE below.
569  if (addILPOpts())
570  printAndVerify("After ILP optimizations");
571 
575  printAndVerify("After Machine LICM, CSE and Sinking passes");
576 
578  printAndVerify("After codegen peephole optimization pass");
579 }
580 
581 //===---------------------------------------------------------------------===//
582 /// Register Allocation Pass Configuration
583 //===---------------------------------------------------------------------===//
584 
586  switch (OptimizeRegAlloc) {
587  case cl::BOU_UNSET: return getOptLevel() != CodeGenOpt::None;
588  case cl::BOU_TRUE: return true;
589  case cl::BOU_FALSE: return false;
590  }
591  llvm_unreachable("Invalid optimize-regalloc state");
592 }
593 
594 /// RegisterRegAlloc's global Registry tracks allocator registration.
596 
597 /// A dummy default pass factory indicates whether the register allocator is
598 /// overridden on the command line.
600 static RegisterRegAlloc
601 defaultRegAlloc("default",
602  "pick register allocator based on -O option",
604 
605 /// -regalloc=... command line option.
608 RegAlloc("regalloc",
610  cl::desc("Register allocator to use"));
611 
612 
613 /// Instantiate the default register allocator pass for this target for either
614 /// the optimized or unoptimized allocation path. This will be added to the pass
615 /// manager by addFastRegAlloc in the unoptimized case or addOptimizedRegAlloc
616 /// in the optimized case.
617 ///
618 /// A target that uses the standard regalloc pass order for fast or optimized
619 /// allocation may still override this for per-target regalloc
620 /// selection. But -regalloc=... always takes precedence.
622  if (Optimized)
624  else
626 }
627 
628 /// Find and instantiate the register allocation pass requested by this target
629 /// at the current optimization level. Different register allocators are
630 /// defined as separate passes because they may require different analysis.
631 ///
632 /// This helper ensures that the regalloc= option is always available,
633 /// even for targets that override the default allocator.
634 ///
635 /// FIXME: When MachinePassRegistry register pass IDs instead of function ptrs,
636 /// this can be folded into addPass.
639 
640  // Initialize the global default.
641  if (!Ctor) {
642  Ctor = RegAlloc;
644  }
645  if (Ctor != useDefaultRegisterAllocator)
646  return Ctor();
647 
648  // With no -regalloc= override, ask the target for a regalloc pass.
649  return createTargetRegisterAllocator(Optimized);
650 }
651 
652 /// Add the minimum set of target-independent passes that are required for
653 /// register allocation. No coalescing or scheduling.
657 
658  addPass(RegAllocPass);
659  printAndVerify("After Register Allocation");
660 }
661 
662 /// Add standard target-independent passes that are tightly coupled with
663 /// optimized register allocation, including coalescing, machine instruction
664 /// scheduling, and register allocation itself.
667 
668  // LiveVariables currently requires pure SSA form.
669  //
670  // FIXME: Once TwoAddressInstruction pass no longer uses kill flags,
671  // LiveVariables can be removed completely, and LiveIntervals can be directly
672  // computed. (We still either need to regenerate kill flags after regalloc, or
673  // preferably fix the scavenger to not depend on them).
675 
676  // Edge splitting is smarter with machine loop info.
679 
680  // Eventually, we want to run LiveIntervals before PHI elimination.
681  if (EarlyLiveIntervals)
683 
686 
687  // PreRA instruction scheduling.
689  printAndVerify("After Machine Scheduling");
690 
691  // Add the selected register allocation pass.
692  addPass(RegAllocPass);
693  printAndVerify("After Register Allocation, before rewriter");
694 
695  // Allow targets to change the register assignments before rewriting.
696  if (addPreRewrite())
697  printAndVerify("After pre-rewrite passes");
698 
699  // Finally rewrite virtual registers.
701  printAndVerify("After Virtual Register Rewriter");
702 
703  // Perform stack slot coloring and post-ra machine LICM.
704  //
705  // FIXME: Re-enable coloring with register when it's capable of adding
706  // kill markers.
708 
709  // Run post-ra machine LICM to hoist reloads / remats.
710  //
711  // FIXME: can this move into MachineLateOptimization?
713 
714  printAndVerify("After StackSlotColoring and postra Machine LICM");
715 }
716 
717 //===---------------------------------------------------------------------===//
718 /// Post RegAlloc Pass Configuration
719 //===---------------------------------------------------------------------===//
720 
721 /// Add passes that optimize machine instructions after register allocation.
723  // Branch folding must be run after regalloc and prolog/epilog insertion.
725  printAndVerify("After BranchFolding");
726 
727  // Tail duplication.
728  if (addPass(&TailDuplicateID))
729  printAndVerify("After TailDuplicate");
730 
731  // Copy propagation.
733  printAndVerify("After copy propagation pass");
734 }
735 
736 /// Add standard GC passes.
739  return true;
740 }
741 
742 /// Add standard basic block placement passes.
745  // Run a separate pass to collect block placement statistics.
748 
749  printAndVerify("After machine block placement.");
750  }
751 }
static cl::opt< cl::boolOrDefault > OptimizeRegAlloc("optimize-regalloc", cl::Hidden, cl::desc("Enable optimized register allocation compilation path."))
unsigned PrintMachineCode
Definition: TargetOptions.h:60
static PassRegistry * getPassRegistry()
Pass * createLoopStrengthReducePass()
AnalysisID addPass(AnalysisID PassID)
Definition: Passes.cpp:316
virtual void addIRPasses()
Definition: Passes.cpp:362
AnalysisID getPassID() const
getPassID - Return the PassID number that corresponds to this pass.
Definition: Pass.h:103
char & MachineLICMID
MachineLICM - This pass performs LICM on machine instructions.
virtual bool addPreRewrite()
FunctionPass * createDwarfEHPass(const TargetMachine *TM)
static cl::opt< cl::boolOrDefault > EnableMachineSched("enable-misched", cl::Hidden, cl::desc("Enable the machine instruction scheduling pass."))
char & RegisterCoalescerID
RegisterCoalescer - This pass merges live ranges to eliminate copies.
char & EarlyIfConverterID
FunctionPass *(* FunctionPassCtor)()
static void setDefault(FunctionPassCtor C)
const void * getTypeInfo() const
Definition: PassSupport.h:82
ExceptionHandling::ExceptionsType getExceptionHandlingType() const
Definition: MCAsmInfo.h:519
char & MachineSchedulerID
MachineScheduler - This pass schedules machine instructions.
static MachinePassRegistry Registry
RegisterRegAlloc's global Registry tracks allocator registration.
static IdentifyingPassPtr applyOverride(IdentifyingPassPtr TargetID, cl::boolOrDefault Override, AnalysisID StandardID)
Definition: Passes.cpp:105
char & ProcessImplicitDefsID
ProcessImpicitDefs pass - This pass removes IMPLICIT_DEFs.
virtual void addMachineSSAOptimization()
Add passes that optimize machine instructions in SSA form.
Definition: Passes.cpp:542
char & MachineBlockPlacementStatsID
virtual bool addPostRegAlloc()
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(const char *reason, bool gen_crash_diag=true)
virtual TargetPassConfig * createPassConfig(PassManagerBase &PM)
Definition: Passes.cpp:257
static cl::opt< bool > DisableLSR("disable-lsr", cl::Hidden, cl::desc("Disable Loop Strength Reduction Pass"))
static cl::opt< bool > DisableEarlyTailDup("disable-early-taildup", cl::Hidden, cl::desc("Disable pre-register allocation tail duplication"))
Pass * getInstance() const
void insertPass(AnalysisID TargetPassID, IdentifyingPassPtr InsertedPassID)
Insert InsertedPassID pass after TargetPassID pass.
Definition: Passes.cpp:242
FunctionPass * createCodeGenPreparePass(const TargetMachine *TM=0)
char & MachineLoopInfoID
MachineLoopInfo - This pass is a loop analysis pass.
const MCAsmInfo * getMCAsmInfo() const
FunctionPass * createGCLoweringPass()
#define llvm_unreachable(msg)
bool getOptimizeRegAlloc() const
Return true if the optimized regalloc pipeline is enabled.
Definition: Passes.cpp:585
char & StackColoringID
static cl::opt< bool > DisableBlockPlacement("disable-block-placement", cl::Hidden, cl::desc("Disable probability-driven block placement"))
static RegisterRegAlloc defaultRegAlloc("default","pick register allocator based on -O option", useDefaultRegisterAllocator)
FunctionPass * createRegAllocPass(bool Optimized)
Definition: Passes.cpp:637
ID
LLVM Calling Convention Representation.
Definition: CallingConv.h:26
static IdentifyingPassPtr overridePass(AnalysisID StandardID, IdentifyingPassPtr TargetID)
Definition: Passes.cpp:135
#define false
Definition: ConvertUTF.c:64
CodeGenOpt::Level getOptLevel() const
virtual void addMachinePasses()
Definition: Passes.cpp:458
IdentifyingPassPtr getPassSubstitution(AnalysisID StandardID) const
Definition: Passes.cpp:277
char & MachineCSEID
MachineCSE - This pass performs global CSE on machine instructions.
Definition: MachineCSE.cpp:106
static cl::opt< bool > EnableBlockPlacementStats("enable-block-placement-stats", cl::Hidden, cl::desc("Collect probability-driven block placement stats"))
char & StackSlotColoringID
StackSlotColoring - This pass performs stack slot coloring.
char & ExpandPostRAPseudosID
ImmutablePass * createBasicAliasAnalysisPass()
char & ExpandISelPseudosID
ExpandISelPseudos - This pass expands pseudo-instructions.
char & DeadMachineInstructionElimID
DeadMachineInstructionElim - This pass removes dead machine instructions.
void substitutePass(AnalysisID StandardID, IdentifyingPassPtr TargetID)
Definition: Passes.cpp:272
FunctionPass * createUnreachableBlockEliminationPass()
char & LiveIntervalsID
virtual bool addILPOpts()
FunctionPass * createGCInfoPrinter(raw_ostream &OS)
Definition: GCMetadata.cpp:117
static cl::opt< bool > DisablePostRA("disable-post-ra", cl::Hidden, cl::desc("Disable Post Regalloc"))
DenseMap< AnalysisID, IdentifyingPassPtr > TargetPasses
Definition: Passes.cpp:204
char & PHIEliminationID
char & LiveVariablesID
virtual FunctionPass * createTargetRegisterAllocator(bool Optimized)
Definition: Passes.cpp:621
virtual bool addGCPasses()
Add standard GC passes.
Definition: Passes.cpp:737
#define P(N)
#define true
Definition: ConvertUTF.c:65
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:314
ImmutablePass * createTypeBasedAliasAnalysisPass()
* if(!EatIfPresent(lltok::kw_thread_local)) return false
static char PostRAMachineLICMID
void disablePass(AnalysisID PassID)
Allow the target to disable a specific standard pass by default.
virtual void addOptimizedRegAlloc(FunctionPass *RegAllocPass)
Definition: Passes.cpp:665
virtual void addMachineLateOptimization()
Add passes that optimize machine instructions after register allocation.
Definition: Passes.cpp:722
virtual bool addPreISel()
FunctionPass * createPrintFunctionPass(const std::string &Banner, raw_ostream *OS, bool DeleteStream=false)
FunctionPass * createLowerInvokePass(const TargetMachine *TM=0, bool useExpensiveEHSupport=false)
virtual void addISelPrepare()
Definition: Passes.cpp:424
virtual void addCodeGenPrepare()
Definition: Passes.cpp:417
static FunctionPass * useDefaultRegisterAllocator()
Definition: Passes.cpp:599
static cl::opt< RegisterRegAlloc::FunctionPassCtor, false, RegisterPassParser< RegisterRegAlloc > > RegAlloc("regalloc", cl::init(&useDefaultRegisterAllocator), cl::desc("Register allocator to use"))
-regalloc=... command line option.
static cl::opt< bool > DisableEarlyIfConversion("disable-early-ifcvt", cl::Hidden, cl::desc("Disable Early If-conversion"))
char & MachineCopyPropagationID
static cl::opt< bool > DisablePostRAMachineLICM("disable-postra-machine-licm", cl::Hidden, cl::desc("Disable Machine LICM"))
void addPassesToHandleExceptions()
Add passes to lower exception handling for the code generator.
Definition: Passes.cpp:390
FunctionPass * createSjLjEHPreparePass(const TargetMachine *TM)
static cl::opt< bool > PrintLSR("print-lsr-output", cl::Hidden, cl::desc("Print LLVM IR produced by the loop-reduce pass"))
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:153
char & PostRASchedulerID
static FunctionPassCtor getDefault()
FunctionPass * createStackProtectorPass(const TargetMachine *TM)
const STC & getSubtarget() const
static cl::opt< bool > DisableBranchFold("disable-branch-fold", cl::Hidden, cl::desc("Disable branch folding"))
char & TailDuplicateID
char & MachineSinkingID
MachineSinking - This pass performs sinking on machine instructions.
static cl::opt< bool > DisableSSC("disable-ssc", cl::Hidden, cl::desc("Disable Stack Slot Coloring"))
FunctionPass * createMachineVerifierPass(const char *Banner=0)
void printAndVerify(const char *Banner)
Definition: Passes.cpp:352
MachineFunctionPass * createMachineFunctionPrinterPass(raw_ostream &OS, const std::string &Banner="")
char & OptimizePHIsID
raw_ostream & dbgs()
dbgs - Return a circular-buffered debug stream.
Definition: Debug.cpp:101
virtual bool addPreSched2()
char & PeepholeOptimizerID
virtual void addFastRegAlloc(FunctionPass *RegAllocPass)
Definition: Passes.cpp:654
char & PrologEpilogCodeInserterID
char & GCMachineCodeAnalysisID
Definition: GCStrategy.cpp:338
virtual bool addPreRegAlloc()
static IdentifyingPassPtr applyDisable(IdentifyingPassPtr PassID, bool Override)
Definition: Passes.cpp:94
static cl::opt< bool > VerifyMachineCode("verify-machineinstrs", cl::Hidden, cl::desc("Verify generated machine code"), cl::init(getenv("LLVM_VERIFY_MACHINEINSTRS")!=NULL))
static cl::opt< bool > EarlyLiveIntervals("early-live-intervals", cl::Hidden, cl::desc("Run live interval analysis earlier in the pipeline"))
virtual void addBlockPlacement()
Add standard basic block placement passes.
Definition: Passes.cpp:743
static cl::opt< bool > DisableCopyProp("disable-copyprop", cl::Hidden, cl::desc("Disable Copy Propagation pass"))
FunctionPass * createGreedyRegisterAllocator()
AnalysisID getID() const
#define I(x, y, z)
Definition: MD5.cpp:54
char & MachineBlockPlacementID
static cl::opt< bool > DisableMachineSink("disable-machine-sink", cl::Hidden, cl::desc("Disable Machine Sinking"))
static cl::opt< bool > PrintISelInput("print-isel-input", cl::Hidden, cl::desc("Print LLVM IR input to isel pass"))
cl::opt< std::string > StopAfter("stop-after", cl::desc("Stop compilation after a specific pass"), cl::value_desc("pass-name"), cl::init(""))
virtual bool addPreEmitPass()
cl::opt< std::string > StartAfter("start-after", cl::desc("Resume compilation after a specific pass"), cl::value_desc("pass-name"), cl::init(""))
void setOpt(bool &Opt, bool Val)
Definition: Passes.cpp:267
static cl::opt< std::string > PrintMachineInstrs("print-machineinstrs", cl::ValueOptional, cl::desc("Print machine instrs"), cl::value_desc("pass-name"), cl::init("option-unspecified"))
static cl::opt< bool > PrintGCInfo("print-gc", cl::Hidden, cl::desc("Dump garbage collector data"))
const void * AnalysisID
Definition: Pass.h:47
bool shouldPrintMachineCode() const
static cl::opt< bool > DisableMachineCSE("disable-machine-cse", cl::Hidden, cl::desc("Disable Machine Common Subexpression Elimination"))
const PassInfo * getPassInfo(const void *TI) const
char & TwoAddressInstructionPassID
static cl::opt< bool > DisableMachineDCE("disable-machine-dce", cl::Hidden, cl::desc("Disable Machine Dead Code Elimination"))
SmallVector< std::pair< AnalysisID, IdentifyingPassPtr >, 4 > InsertedPasses
Definition: Passes.cpp:208
static char EarlyTailDuplicateID
static Pass * createPass(AnalysisID ID)
Definition: Pass.cpp:171
void initializeCodeGen(PassRegistry &)
initializeCodeGen - Initialize all passes linked into the CodeGen library.
Definition: CodeGen.cpp:22
FunctionPass * createFastRegisterAllocator()
virtual ~TargetPassConfig()
Definition: Passes.cpp:213
char & VirtRegRewriterID
Definition: VirtRegMap.cpp:176
char & BranchFolderPassID
static cl::opt< bool > DisableMachineLICM("disable-machine-licm", cl::Hidden, cl::desc("Disable Machine LICM"))
static cl::opt< bool > DisableTailDuplicate("disable-tail-duplicate", cl::Hidden, cl::desc("Disable tail duplication"))
static cl::opt< bool > DisableCGP("disable-cgp", cl::Hidden, cl::desc("Disable Codegen Prepare"))
bool useMachineScheduler() const
Temporary API to test migration to MI scheduler.
char & LocalStackSlotAllocationID
char *getenv(const char *name);
PassConfigImpl * Impl
FunctionPass * createVerifierPass(VerifierFailureAction action=AbortProcessAction)
Create a verifier pass.
Definition: Verifier.cpp:2409