blob: 526d994abbc71b7f255e7c2431fdee9ab3090707 [file] [log] [blame]
Chris Lattneraa4c91f2003-12-28 07:59:53 +00001//===-- Passes.cpp - Target independent code generation passes ------------===//
Misha Brukmanedf128a2005-04-21 22:36:52 +00002//
John Criswellb576c942003-10-20 19:43:21 +00003// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Misha Brukmanedf128a2005-04-21 22:36:52 +00007//
John Criswellb576c942003-10-20 19:43:21 +00008//===----------------------------------------------------------------------===//
Alkis Evlogimenos7237ece2003-10-02 16:57:49 +00009//
10// This file defines interfaces to access the target independent code
11// generation passes provided by the LLVM backend.
12//
13//===---------------------------------------------------------------------===//
14
Andrew Trickd5422652012-02-04 02:56:48 +000015#include "llvm/Analysis/Passes.h"
16#include "llvm/Analysis/Verifier.h"
17#include "llvm/Transforms/Scalar.h"
18#include "llvm/PassManager.h"
19#include "llvm/CodeGen/GCStrategy.h"
Andrew Trickd5422652012-02-04 02:56:48 +000020#include "llvm/CodeGen/MachineFunctionPass.h"
Alkis Evlogimenos7237ece2003-10-02 16:57:49 +000021#include "llvm/CodeGen/Passes.h"
Andrew Trickd5422652012-02-04 02:56:48 +000022#include "llvm/CodeGen/RegAllocRegistry.h"
23#include "llvm/Target/TargetLowering.h"
Andrew Trickd5422652012-02-04 02:56:48 +000024#include "llvm/Target/TargetOptions.h"
Andrew Trickad1cc1d2012-11-13 08:47:29 +000025#include "llvm/Target/TargetSubtargetInfo.h"
Bob Wilson564fbf62012-07-02 19:48:31 +000026#include "llvm/MC/MCAsmInfo.h"
Andrew Trickd5422652012-02-04 02:56:48 +000027#include "llvm/Assembly/PrintModulePass.h"
28#include "llvm/Support/CommandLine.h"
29#include "llvm/Support/Debug.h"
Andrew Trick74613342012-02-04 02:56:45 +000030#include "llvm/Support/ErrorHandling.h"
Jim Laskey13ec7022006-08-01 14:21:23 +000031
Chris Lattneraa4c91f2003-12-28 07:59:53 +000032using namespace llvm;
Brian Gaeked0fde302003-11-11 22:41:34 +000033
Andrew Trickd5422652012-02-04 02:56:48 +000034static cl::opt<bool> DisablePostRA("disable-post-ra", cl::Hidden,
35 cl::desc("Disable Post Regalloc"));
36static cl::opt<bool> DisableBranchFold("disable-branch-fold", cl::Hidden,
37 cl::desc("Disable branch folding"));
38static cl::opt<bool> DisableTailDuplicate("disable-tail-duplicate", cl::Hidden,
39 cl::desc("Disable tail duplication"));
40static cl::opt<bool> DisableEarlyTailDup("disable-early-taildup", cl::Hidden,
41 cl::desc("Disable pre-register allocation tail duplication"));
Chandler Carruth9e67db42012-04-16 13:49:17 +000042static cl::opt<bool> DisableBlockPlacement("disable-block-placement",
43 cl::Hidden, cl::desc("Disable the probability-driven block placement, and "
44 "re-enable the old code placement pass"));
Andrew Trickd5422652012-02-04 02:56:48 +000045static cl::opt<bool> EnableBlockPlacementStats("enable-block-placement-stats",
46 cl::Hidden, cl::desc("Collect probability-driven block placement stats"));
47static cl::opt<bool> DisableCodePlace("disable-code-place", cl::Hidden,
48 cl::desc("Disable code placement"));
49static cl::opt<bool> DisableSSC("disable-ssc", cl::Hidden,
50 cl::desc("Disable Stack Slot Coloring"));
51static cl::opt<bool> DisableMachineDCE("disable-machine-dce", cl::Hidden,
52 cl::desc("Disable Machine Dead Code Elimination"));
Jakob Stoklund Olesen0d141f82012-10-03 00:51:32 +000053static cl::opt<bool> DisableEarlyIfConversion("disable-early-ifcvt", cl::Hidden,
54 cl::desc("Disable Early If-conversion"));
Andrew Trickd5422652012-02-04 02:56:48 +000055static cl::opt<bool> DisableMachineLICM("disable-machine-licm", cl::Hidden,
56 cl::desc("Disable Machine LICM"));
57static cl::opt<bool> DisableMachineCSE("disable-machine-cse", cl::Hidden,
58 cl::desc("Disable Machine Common Subexpression Elimination"));
Andrew Trick8dd26252012-02-10 04:10:36 +000059static cl::opt<cl::boolOrDefault>
60OptimizeRegAlloc("optimize-regalloc", cl::Hidden,
61 cl::desc("Enable optimized register allocation compilation path."));
Andrew Trick746f24b2012-02-11 07:11:32 +000062static cl::opt<cl::boolOrDefault>
63EnableMachineSched("enable-misched", cl::Hidden,
Andrew Trick8dd26252012-02-10 04:10:36 +000064 cl::desc("Enable the machine instruction scheduling pass."));
65static cl::opt<bool> EnableStrongPHIElim("strong-phi-elim", cl::Hidden,
66 cl::desc("Use strong PHI elimination."));
Andrew Trickd5422652012-02-04 02:56:48 +000067static cl::opt<bool> DisablePostRAMachineLICM("disable-postra-machine-licm",
68 cl::Hidden,
69 cl::desc("Disable Machine LICM"));
70static cl::opt<bool> DisableMachineSink("disable-machine-sink", cl::Hidden,
71 cl::desc("Disable Machine Sinking"));
72static cl::opt<bool> DisableLSR("disable-lsr", cl::Hidden,
73 cl::desc("Disable Loop Strength Reduction Pass"));
74static cl::opt<bool> DisableCGP("disable-cgp", cl::Hidden,
75 cl::desc("Disable Codegen Prepare"));
76static cl::opt<bool> DisableCopyProp("disable-copyprop", cl::Hidden,
Evan Cheng01b623c2012-02-20 23:28:17 +000077 cl::desc("Disable Copy Propagation pass"));
Andrew Trickd5422652012-02-04 02:56:48 +000078static cl::opt<bool> PrintLSR("print-lsr-output", cl::Hidden,
79 cl::desc("Print LLVM IR produced by the loop-reduce pass"));
80static cl::opt<bool> PrintISelInput("print-isel-input", cl::Hidden,
81 cl::desc("Print LLVM IR input to isel pass"));
82static cl::opt<bool> PrintGCInfo("print-gc", cl::Hidden,
83 cl::desc("Dump garbage collector data"));
84static cl::opt<bool> VerifyMachineCode("verify-machineinstrs", cl::Hidden,
85 cl::desc("Verify generated machine code"),
86 cl::init(getenv("LLVM_VERIFY_MACHINEINSTRS")!=NULL));
Bob Wilson6e1b8122012-05-30 00:17:12 +000087static cl::opt<std::string>
88PrintMachineInstrs("print-machineinstrs", cl::ValueOptional,
89 cl::desc("Print machine instrs"),
90 cl::value_desc("pass-name"), cl::init("option-unspecified"));
Andrew Trickd5422652012-02-04 02:56:48 +000091
Jakob Stoklund Olesendcc44362012-08-03 22:12:54 +000092// Experimental option to run live inteerval analysis early.
93static cl::opt<bool> EarlyLiveIntervals("early-live-intervals", cl::Hidden,
94 cl::desc("Run live interval analysis earlier in the pipeline"));
95
Andrew Trick79bf2882012-02-15 03:21:51 +000096/// Allow standard passes to be disabled by command line options. This supports
97/// simple binary flags that either suppress the pass or do nothing.
98/// i.e. -disable-mypass=false has no effect.
99/// These should be converted to boolOrDefault in order to use applyOverride.
Bob Wilson3fb99a72012-07-02 19:48:37 +0000100static AnalysisID applyDisable(AnalysisID PassID, bool Override) {
Andrew Trick79bf2882012-02-15 03:21:51 +0000101 if (Override)
Bob Wilson3fb99a72012-07-02 19:48:37 +0000102 return 0;
103 return PassID;
Andrew Trick79bf2882012-02-15 03:21:51 +0000104}
105
106/// Allow Pass selection to be overriden by command line options. This supports
107/// flags with ternary conditions. TargetID is passed through by default. The
108/// pass is suppressed when the option is false. When the option is true, the
109/// StandardID is selected if the target provides no default.
110static AnalysisID applyOverride(AnalysisID TargetID, cl::boolOrDefault Override,
111 AnalysisID StandardID) {
Andrew Trick746f24b2012-02-11 07:11:32 +0000112 switch (Override) {
113 case cl::BOU_UNSET:
Andrew Trick79bf2882012-02-15 03:21:51 +0000114 return TargetID;
Andrew Trick746f24b2012-02-11 07:11:32 +0000115 case cl::BOU_TRUE:
Bob Wilson3fb99a72012-07-02 19:48:37 +0000116 if (TargetID)
Andrew Trick79bf2882012-02-15 03:21:51 +0000117 return TargetID;
Bob Wilson3fb99a72012-07-02 19:48:37 +0000118 if (StandardID == 0)
Andrew Trick746f24b2012-02-11 07:11:32 +0000119 report_fatal_error("Target cannot enable pass");
Andrew Trick79bf2882012-02-15 03:21:51 +0000120 return StandardID;
Andrew Trick746f24b2012-02-11 07:11:32 +0000121 case cl::BOU_FALSE:
Bob Wilson3fb99a72012-07-02 19:48:37 +0000122 return 0;
Andrew Trick746f24b2012-02-11 07:11:32 +0000123 }
124 llvm_unreachable("Invalid command line option state");
125}
126
Andrew Trick79bf2882012-02-15 03:21:51 +0000127/// Allow standard passes to be disabled by the command line, regardless of who
128/// is adding the pass.
129///
130/// StandardID is the pass identified in the standard pass pipeline and provided
131/// to addPass(). It may be a target-specific ID in the case that the target
132/// directly adds its own pass, but in that case we harmlessly fall through.
133///
134/// TargetID is the pass that the target has configured to override StandardID.
135///
136/// StandardID may be a pseudo ID. In that case TargetID is the name of the real
137/// pass to run. This allows multiple options to control a single pass depending
138/// on where in the pipeline that pass is added.
139static AnalysisID overridePass(AnalysisID StandardID, AnalysisID TargetID) {
140 if (StandardID == &PostRASchedulerID)
141 return applyDisable(TargetID, DisablePostRA);
142
143 if (StandardID == &BranchFolderPassID)
144 return applyDisable(TargetID, DisableBranchFold);
145
146 if (StandardID == &TailDuplicateID)
147 return applyDisable(TargetID, DisableTailDuplicate);
148
149 if (StandardID == &TargetPassConfig::EarlyTailDuplicateID)
150 return applyDisable(TargetID, DisableEarlyTailDup);
151
152 if (StandardID == &MachineBlockPlacementID)
153 return applyDisable(TargetID, DisableCodePlace);
154
155 if (StandardID == &CodePlacementOptID)
156 return applyDisable(TargetID, DisableCodePlace);
157
158 if (StandardID == &StackSlotColoringID)
159 return applyDisable(TargetID, DisableSSC);
160
161 if (StandardID == &DeadMachineInstructionElimID)
162 return applyDisable(TargetID, DisableMachineDCE);
163
Jakob Stoklund Olesen33242fd2012-07-04 00:09:54 +0000164 if (StandardID == &EarlyIfConverterID)
Jakob Stoklund Olesen0d141f82012-10-03 00:51:32 +0000165 return applyDisable(TargetID, DisableEarlyIfConversion);
Jakob Stoklund Olesen33242fd2012-07-04 00:09:54 +0000166
Andrew Trick79bf2882012-02-15 03:21:51 +0000167 if (StandardID == &MachineLICMID)
168 return applyDisable(TargetID, DisableMachineLICM);
169
170 if (StandardID == &MachineCSEID)
171 return applyDisable(TargetID, DisableMachineCSE);
172
173 if (StandardID == &MachineSchedulerID)
174 return applyOverride(TargetID, EnableMachineSched, StandardID);
175
176 if (StandardID == &TargetPassConfig::PostRAMachineLICMID)
177 return applyDisable(TargetID, DisablePostRAMachineLICM);
178
179 if (StandardID == &MachineSinkingID)
180 return applyDisable(TargetID, DisableMachineSink);
181
182 if (StandardID == &MachineCopyPropagationID)
183 return applyDisable(TargetID, DisableCopyProp);
184
185 return TargetID;
186}
187
Jim Laskeyeb577ba2006-08-02 12:30:23 +0000188//===---------------------------------------------------------------------===//
Andrew Trick74613342012-02-04 02:56:45 +0000189/// TargetPassConfig
190//===---------------------------------------------------------------------===//
191
192INITIALIZE_PASS(TargetPassConfig, "targetpassconfig",
193 "Target Pass Configuration", false, false)
194char TargetPassConfig::ID = 0;
195
Andrew Trick79bf2882012-02-15 03:21:51 +0000196// Pseudo Pass IDs.
197char TargetPassConfig::EarlyTailDuplicateID = 0;
198char TargetPassConfig::PostRAMachineLICMID = 0;
199
Andrew Trick5e108ee2012-02-15 03:21:47 +0000200namespace llvm {
201class PassConfigImpl {
202public:
203 // List of passes explicitly substituted by this target. Normally this is
204 // empty, but it is a convenient way to suppress or replace specific passes
205 // that are part of a standard pass pipeline without overridding the entire
206 // pipeline. This mechanism allows target options to inherit a standard pass's
207 // user interface. For example, a target may disable a standard pass by
Bob Wilson3fb99a72012-07-02 19:48:37 +0000208 // default by substituting a pass ID of zero, and the user may still enable
209 // that standard pass with an explicit command line option.
Andrew Trick5e108ee2012-02-15 03:21:47 +0000210 DenseMap<AnalysisID,AnalysisID> TargetPasses;
Bob Wilson6e1b8122012-05-30 00:17:12 +0000211
212 /// Store the pairs of <AnalysisID, AnalysisID> of which the second pass
213 /// is inserted after each instance of the first one.
214 SmallVector<std::pair<AnalysisID, AnalysisID>, 4> InsertedPasses;
Andrew Trick5e108ee2012-02-15 03:21:47 +0000215};
216} // namespace llvm
217
Andrew Trick74613342012-02-04 02:56:45 +0000218// Out of line virtual method.
Andrew Trick5e108ee2012-02-15 03:21:47 +0000219TargetPassConfig::~TargetPassConfig() {
220 delete Impl;
221}
Andrew Trick74613342012-02-04 02:56:45 +0000222
Andrew Trick61f1e3d2012-02-08 21:22:48 +0000223// Out of line constructor provides default values for pass options and
224// registers all common codegen passes.
Andrew Trick061efcf2012-02-04 02:56:59 +0000225TargetPassConfig::TargetPassConfig(TargetMachine *tm, PassManagerBase &pm)
Bob Wilson30a507a2012-07-02 19:48:45 +0000226 : ImmutablePass(ID), PM(&pm), StartAfter(0), StopAfter(0),
227 Started(true), Stopped(false), TM(tm), Impl(0), Initialized(false),
Andrew Trickffea03f2012-02-08 21:22:39 +0000228 DisableVerify(false),
229 EnableTailMerge(true) {
230
Andrew Trick5e108ee2012-02-15 03:21:47 +0000231 Impl = new PassConfigImpl();
232
Andrew Trick74613342012-02-04 02:56:45 +0000233 // Register all target independent codegen passes to activate their PassIDs,
234 // including this pass itself.
235 initializeCodeGen(*PassRegistry::getPassRegistry());
Andrew Trick79bf2882012-02-15 03:21:51 +0000236
237 // Substitute Pseudo Pass IDs for real ones.
Bob Wilson3fb99a72012-07-02 19:48:37 +0000238 substitutePass(&EarlyTailDuplicateID, &TailDuplicateID);
239 substitutePass(&PostRAMachineLICMID, &MachineLICMID);
Andrew Trick79bf2882012-02-15 03:21:51 +0000240
Jakob Stoklund Olesen33242fd2012-07-04 00:09:54 +0000241 // Disable early if-conversion. Targets that are ready can enable it.
242 disablePass(&EarlyIfConverterID);
243
Andrew Trick79bf2882012-02-15 03:21:51 +0000244 // Temporarily disable experimental passes.
Andrew Trickad1cc1d2012-11-13 08:47:29 +0000245 const TargetSubtargetInfo &ST = TM->getSubtarget<TargetSubtargetInfo>();
246 if (!ST.enableMachineScheduler())
247 disablePass(&MachineSchedulerID);
Andrew Trick74613342012-02-04 02:56:45 +0000248}
249
Bob Wilson6e1b8122012-05-30 00:17:12 +0000250/// Insert InsertedPassID pass after TargetPassID.
Bob Wilson3fb99a72012-07-02 19:48:37 +0000251void TargetPassConfig::insertPass(AnalysisID TargetPassID,
252 AnalysisID InsertedPassID) {
253 assert(TargetPassID != InsertedPassID && "Insert a pass after itself!");
254 std::pair<AnalysisID, AnalysisID> P(TargetPassID, InsertedPassID);
Bob Wilson6e1b8122012-05-30 00:17:12 +0000255 Impl->InsertedPasses.push_back(P);
256}
257
Andrew Trick74613342012-02-04 02:56:45 +0000258/// createPassConfig - Create a pass configuration object to be used by
259/// addPassToEmitX methods for generating a pipeline of CodeGen passes.
260///
261/// Targets may override this to extend TargetPassConfig.
Andrew Trick061efcf2012-02-04 02:56:59 +0000262TargetPassConfig *LLVMTargetMachine::createPassConfig(PassManagerBase &PM) {
263 return new TargetPassConfig(this, PM);
Andrew Trick74613342012-02-04 02:56:45 +0000264}
265
266TargetPassConfig::TargetPassConfig()
Bill Wendling7c4ce302012-05-01 08:27:43 +0000267 : ImmutablePass(ID), PM(0) {
Andrew Trick74613342012-02-04 02:56:45 +0000268 llvm_unreachable("TargetPassConfig should not be constructed on-the-fly");
269}
270
Andrew Trickffea03f2012-02-08 21:22:39 +0000271// Helper to verify the analysis is really immutable.
272void TargetPassConfig::setOpt(bool &Opt, bool Val) {
273 assert(!Initialized && "PassConfig is immutable");
274 Opt = Val;
275}
276
Bob Wilson3fb99a72012-07-02 19:48:37 +0000277void TargetPassConfig::substitutePass(AnalysisID StandardID,
278 AnalysisID TargetID) {
279 Impl->TargetPasses[StandardID] = TargetID;
Andrew Trick5e108ee2012-02-15 03:21:47 +0000280}
Andrew Trick746f24b2012-02-11 07:11:32 +0000281
Andrew Trick5e108ee2012-02-15 03:21:47 +0000282AnalysisID TargetPassConfig::getPassSubstitution(AnalysisID ID) const {
283 DenseMap<AnalysisID, AnalysisID>::const_iterator
284 I = Impl->TargetPasses.find(ID);
285 if (I == Impl->TargetPasses.end())
286 return ID;
287 return I->second;
288}
289
Bob Wilson30a507a2012-07-02 19:48:45 +0000290/// Add a pass to the PassManager if that pass is supposed to be run. If the
291/// Started/Stopped flags indicate either that the compilation should start at
292/// a later pass or that it should stop after an earlier pass, then do not add
293/// the pass. Finally, compare the current pass against the StartAfter
294/// and StopAfter options and change the Started/Stopped flags accordingly.
Bob Wilson564fbf62012-07-02 19:48:31 +0000295void TargetPassConfig::addPass(Pass *P) {
Bob Wilson6b2bb152012-07-02 19:48:39 +0000296 assert(!Initialized && "PassConfig is immutable");
297
Chandler Carruth6068c482012-07-02 22:56:41 +0000298 // Cache the Pass ID here in case the pass manager finds this pass is
299 // redundant with ones already scheduled / available, and deletes it.
300 // Fundamentally, once we add the pass to the manager, we no longer own it
301 // and shouldn't reference it.
302 AnalysisID PassID = P->getPassID();
303
Bob Wilson30a507a2012-07-02 19:48:45 +0000304 if (Started && !Stopped)
305 PM->add(P);
Chandler Carruth6068c482012-07-02 22:56:41 +0000306 if (StopAfter == PassID)
Bob Wilson30a507a2012-07-02 19:48:45 +0000307 Stopped = true;
Chandler Carruth6068c482012-07-02 22:56:41 +0000308 if (StartAfter == PassID)
Bob Wilson30a507a2012-07-02 19:48:45 +0000309 Started = true;
310 if (Stopped && !Started)
311 report_fatal_error("Cannot stop compilation after pass that is not run");
Bob Wilson564fbf62012-07-02 19:48:31 +0000312}
313
Andrew Trick5e108ee2012-02-15 03:21:47 +0000314/// Add a CodeGen pass at this point in the pipeline after checking for target
315/// and command line overrides.
Bob Wilson3fb99a72012-07-02 19:48:37 +0000316AnalysisID TargetPassConfig::addPass(AnalysisID PassID) {
Bob Wilson3fb99a72012-07-02 19:48:37 +0000317 AnalysisID TargetID = getPassSubstitution(PassID);
318 AnalysisID FinalID = overridePass(PassID, TargetID);
319 if (FinalID == 0)
Andrew Trick5e108ee2012-02-15 03:21:47 +0000320 return FinalID;
321
322 Pass *P = Pass::createPass(FinalID);
Andrew Trickebe18ef2012-02-08 21:22:34 +0000323 if (!P)
324 llvm_unreachable("Pass ID not registered");
Bob Wilson564fbf62012-07-02 19:48:31 +0000325 addPass(P);
Bob Wilson6e1b8122012-05-30 00:17:12 +0000326 // Add the passes after the pass P if there is any.
327 for (SmallVector<std::pair<AnalysisID, AnalysisID>, 4>::iterator
328 I = Impl->InsertedPasses.begin(), E = Impl->InsertedPasses.end();
329 I != E; ++I) {
Bob Wilson3fb99a72012-07-02 19:48:37 +0000330 if ((*I).first == PassID) {
Bob Wilson6e1b8122012-05-30 00:17:12 +0000331 assert((*I).second && "Illegal Pass ID!");
332 Pass *NP = Pass::createPass((*I).second);
333 assert(NP && "Pass ID not registered");
Bob Wilson564fbf62012-07-02 19:48:31 +0000334 addPass(NP);
Bob Wilson6e1b8122012-05-30 00:17:12 +0000335 }
336 }
Andrew Trick5e108ee2012-02-15 03:21:47 +0000337 return FinalID;
Andrew Trick061efcf2012-02-04 02:56:59 +0000338}
Andrew Trickd5422652012-02-04 02:56:48 +0000339
Bob Wilson564fbf62012-07-02 19:48:31 +0000340void TargetPassConfig::printAndVerify(const char *Banner) {
Andrew Trickd5422652012-02-04 02:56:48 +0000341 if (TM->shouldPrintMachineCode())
Bob Wilson564fbf62012-07-02 19:48:31 +0000342 addPass(createMachineFunctionPrinterPass(dbgs(), Banner));
Andrew Trickd5422652012-02-04 02:56:48 +0000343
344 if (VerifyMachineCode)
Bob Wilson564fbf62012-07-02 19:48:31 +0000345 addPass(createMachineVerifierPass(Banner));
Andrew Trickd5422652012-02-04 02:56:48 +0000346}
347
Andrew Trick061efcf2012-02-04 02:56:59 +0000348/// Add common target configurable passes that perform LLVM IR to IR transforms
349/// following machine independent optimization.
350void TargetPassConfig::addIRPasses() {
Andrew Trickd5422652012-02-04 02:56:48 +0000351 // Basic AliasAnalysis support.
352 // Add TypeBasedAliasAnalysis before BasicAliasAnalysis so that
353 // BasicAliasAnalysis wins if they disagree. This is intended to help
354 // support "obvious" type-punning idioms.
Bob Wilson564fbf62012-07-02 19:48:31 +0000355 addPass(createTypeBasedAliasAnalysisPass());
356 addPass(createBasicAliasAnalysisPass());
Andrew Trickd5422652012-02-04 02:56:48 +0000357
358 // Before running any passes, run the verifier to determine if the input
359 // coming from the front-end and/or optimizer is valid.
360 if (!DisableVerify)
Bob Wilson564fbf62012-07-02 19:48:31 +0000361 addPass(createVerifierPass());
Andrew Trickd5422652012-02-04 02:56:48 +0000362
363 // Run loop strength reduction before anything else.
364 if (getOptLevel() != CodeGenOpt::None && !DisableLSR) {
Nadav Rotema04a4a72012-10-19 21:28:43 +0000365 addPass(createLoopStrengthReducePass(getTargetLowering()));
Andrew Trickd5422652012-02-04 02:56:48 +0000366 if (PrintLSR)
Bob Wilson564fbf62012-07-02 19:48:31 +0000367 addPass(createPrintFunctionPass("\n\n*** Code after LSR ***\n", &dbgs()));
Andrew Trickd5422652012-02-04 02:56:48 +0000368 }
369
Bob Wilson564fbf62012-07-02 19:48:31 +0000370 addPass(createGCLoweringPass());
Andrew Trickd5422652012-02-04 02:56:48 +0000371
372 // Make sure that no unreachable blocks are instruction selected.
Bob Wilson564fbf62012-07-02 19:48:31 +0000373 addPass(createUnreachableBlockEliminationPass());
374}
375
376/// Turn exception handling constructs into something the code generators can
377/// handle.
378void TargetPassConfig::addPassesToHandleExceptions() {
379 switch (TM->getMCAsmInfo()->getExceptionHandlingType()) {
380 case ExceptionHandling::SjLj:
381 // SjLj piggy-backs on dwarf for this bit. The cleanups done apply to both
382 // Dwarf EH prepare needs to be run after SjLj prepare. Otherwise,
383 // catch info can get misplaced when a selector ends up more than one block
384 // removed from the parent invoke(s). This could happen when a landing
385 // pad is shared by multiple invokes and is also a target of a normal
386 // edge from elsewhere.
387 addPass(createSjLjEHPreparePass(TM->getTargetLowering()));
388 // FALLTHROUGH
389 case ExceptionHandling::DwarfCFI:
390 case ExceptionHandling::ARM:
391 case ExceptionHandling::Win64:
392 addPass(createDwarfEHPass(TM));
393 break;
394 case ExceptionHandling::None:
Nadav Rotema04a4a72012-10-19 21:28:43 +0000395 addPass(createLowerInvokePass(TM->getTargetLowering()));
Bob Wilson564fbf62012-07-02 19:48:31 +0000396
397 // The lower invoke pass may create unreachable code. Remove it.
398 addPass(createUnreachableBlockEliminationPass());
399 break;
400 }
Andrew Trick061efcf2012-02-04 02:56:59 +0000401}
Andrew Trickd5422652012-02-04 02:56:48 +0000402
Andrew Trick061efcf2012-02-04 02:56:59 +0000403/// Add common passes that perform LLVM IR to IR transforms in preparation for
404/// instruction selection.
405void TargetPassConfig::addISelPrepare() {
Andrew Trickd5422652012-02-04 02:56:48 +0000406 if (getOptLevel() != CodeGenOpt::None && !DisableCGP)
Bob Wilson564fbf62012-07-02 19:48:31 +0000407 addPass(createCodeGenPreparePass(getTargetLowering()));
Andrew Trickd5422652012-02-04 02:56:48 +0000408
Bob Wilson564fbf62012-07-02 19:48:31 +0000409 addPass(createStackProtectorPass(getTargetLowering()));
Andrew Trickd5422652012-02-04 02:56:48 +0000410
411 addPreISel();
412
413 if (PrintISelInput)
Bob Wilson564fbf62012-07-02 19:48:31 +0000414 addPass(createPrintFunctionPass("\n\n"
Bill Wendling7c4ce302012-05-01 08:27:43 +0000415 "*** Final LLVM Code input to ISel ***\n",
416 &dbgs()));
Andrew Trickd5422652012-02-04 02:56:48 +0000417
418 // All passes which modify the LLVM IR are now complete; run the verifier
419 // to ensure that the IR is valid.
420 if (!DisableVerify)
Bob Wilson564fbf62012-07-02 19:48:31 +0000421 addPass(createVerifierPass());
Andrew Trick061efcf2012-02-04 02:56:59 +0000422}
Andrew Trickd5422652012-02-04 02:56:48 +0000423
Andrew Trickf7b96312012-02-09 00:40:55 +0000424/// Add the complete set of target-independent postISel code generator passes.
425///
426/// This can be read as the standard order of major LLVM CodeGen stages. Stages
427/// with nontrivial configuration or multiple passes are broken out below in
428/// add%Stage routines.
429///
430/// Any TargetPassConfig::addXX routine may be overriden by the Target. The
431/// addPre/Post methods with empty header implementations allow injecting
432/// target-specific fixups just before or after major stages. Additionally,
433/// targets have the flexibility to change pass order within a stage by
434/// overriding default implementation of add%Stage routines below. Each
435/// technique has maintainability tradeoffs because alternate pass orders are
436/// not well supported. addPre/Post works better if the target pass is easily
437/// tied to a common pass. But if it has subtle dependencies on multiple passes,
Andrew Trick06efdd22012-02-10 07:08:25 +0000438/// the target should override the stage instead.
Andrew Trickf7b96312012-02-09 00:40:55 +0000439///
440/// TODO: We could use a single addPre/Post(ID) hook to allow pass injection
441/// before/after any target-independent pass. But it's currently overkill.
Andrew Trick061efcf2012-02-04 02:56:59 +0000442void TargetPassConfig::addMachinePasses() {
Bob Wilson6e1b8122012-05-30 00:17:12 +0000443 // Insert a machine instr printer pass after the specified pass.
444 // If -print-machineinstrs specified, print machineinstrs after all passes.
445 if (StringRef(PrintMachineInstrs.getValue()).equals(""))
446 TM->Options.PrintMachineCode = true;
447 else if (!StringRef(PrintMachineInstrs.getValue())
448 .equals("option-unspecified")) {
449 const PassRegistry *PR = PassRegistry::getPassRegistry();
450 const PassInfo *TPI = PR->getPassInfo(PrintMachineInstrs.getValue());
451 const PassInfo *IPI = PR->getPassInfo(StringRef("print-machineinstrs"));
452 assert (TPI && IPI && "Pass ID not registered!");
Roman Divacky59324292012-09-05 22:26:57 +0000453 const char *TID = (const char *)(TPI->getTypeInfo());
454 const char *IID = (const char *)(IPI->getTypeInfo());
Bob Wilson3fb99a72012-07-02 19:48:37 +0000455 insertPass(TID, IID);
Bob Wilson6e1b8122012-05-30 00:17:12 +0000456 }
457
Jakob Stoklund Olesenf86c00f2012-07-04 19:28:27 +0000458 // Print the instruction selected machine code...
459 printAndVerify("After Instruction Selection");
460
Andrew Trickd5422652012-02-04 02:56:48 +0000461 // Expand pseudo-instructions emitted by ISel.
Jakob Stoklund Olesen228e3f52012-08-20 20:52:08 +0000462 if (addPass(&ExpandISelPseudosID))
463 printAndVerify("After ExpandISelPseudos");
Andrew Trickd5422652012-02-04 02:56:48 +0000464
Andrew Trickf7b96312012-02-09 00:40:55 +0000465 // Add passes that optimize machine instructions in SSA form.
Andrew Trickd5422652012-02-04 02:56:48 +0000466 if (getOptLevel() != CodeGenOpt::None) {
Andrew Trickf7b96312012-02-09 00:40:55 +0000467 addMachineSSAOptimization();
Craig Topper8f54a532012-11-19 00:11:50 +0000468 } else {
Andrew Trickf7b96312012-02-09 00:40:55 +0000469 // If the target requests it, assign local variables to stack slots relative
470 // to one another and simplify frame index references where possible.
Bob Wilson3fb99a72012-07-02 19:48:37 +0000471 addPass(&LocalStackSlotAllocationID);
Andrew Trickd5422652012-02-04 02:56:48 +0000472 }
473
474 // Run pre-ra passes.
475 if (addPreRegAlloc())
476 printAndVerify("After PreRegAlloc passes");
477
Andrew Trickf7b96312012-02-09 00:40:55 +0000478 // Run register allocation and passes that are tightly coupled with it,
479 // including phi elimination and scheduling.
Andrew Trick8dd26252012-02-10 04:10:36 +0000480 if (getOptimizeRegAlloc())
481 addOptimizedRegAlloc(createRegAllocPass(true));
482 else
483 addFastRegAlloc(createRegAllocPass(false));
Andrew Trickd5422652012-02-04 02:56:48 +0000484
485 // Run post-ra passes.
486 if (addPostRegAlloc())
487 printAndVerify("After PostRegAlloc passes");
488
489 // Insert prolog/epilog code. Eliminate abstract frame index references...
Bob Wilson3fb99a72012-07-02 19:48:37 +0000490 addPass(&PrologEpilogCodeInserterID);
Andrew Trickd5422652012-02-04 02:56:48 +0000491 printAndVerify("After PrologEpilogCodeInserter");
492
Andrew Trickf7b96312012-02-09 00:40:55 +0000493 /// Add passes that optimize machine instructions after register allocation.
494 if (getOptLevel() != CodeGenOpt::None)
495 addMachineLateOptimization();
Andrew Trickd5422652012-02-04 02:56:48 +0000496
497 // Expand pseudo instructions before second scheduling pass.
Bob Wilson3fb99a72012-07-02 19:48:37 +0000498 addPass(&ExpandPostRAPseudosID);
Jakob Stoklund Olesen2ef5bf62012-03-28 20:49:30 +0000499 printAndVerify("After ExpandPostRAPseudos");
Andrew Trickd5422652012-02-04 02:56:48 +0000500
501 // Run pre-sched2 passes.
502 if (addPreSched2())
Jakob Stoklund Olesen78811662012-03-28 23:31:15 +0000503 printAndVerify("After PreSched2 passes");
Andrew Trickd5422652012-02-04 02:56:48 +0000504
505 // Second pass scheduler.
Andrew Trick79bf2882012-02-15 03:21:51 +0000506 if (getOptLevel() != CodeGenOpt::None) {
Bob Wilson3fb99a72012-07-02 19:48:37 +0000507 addPass(&PostRASchedulerID);
Jakob Stoklund Olesen8b4c5022012-03-28 23:54:28 +0000508 printAndVerify("After PostRAScheduler");
Andrew Trickd5422652012-02-04 02:56:48 +0000509 }
510
Andrew Trickf7b96312012-02-09 00:40:55 +0000511 // GC
Bob Wilson3fb99a72012-07-02 19:48:37 +0000512 addPass(&GCMachineCodeAnalysisID);
Andrew Trickd5422652012-02-04 02:56:48 +0000513 if (PrintGCInfo)
Bob Wilson564fbf62012-07-02 19:48:31 +0000514 addPass(createGCInfoPrinter(dbgs()));
Andrew Trickd5422652012-02-04 02:56:48 +0000515
Andrew Trickf7b96312012-02-09 00:40:55 +0000516 // Basic block placement.
Andrew Trick79bf2882012-02-15 03:21:51 +0000517 if (getOptLevel() != CodeGenOpt::None)
Andrew Trickf7b96312012-02-09 00:40:55 +0000518 addBlockPlacement();
Andrew Trickd5422652012-02-04 02:56:48 +0000519
520 if (addPreEmitPass())
Jakob Stoklund Olesen8b4c5022012-03-28 23:54:28 +0000521 printAndVerify("After PreEmit passes");
Andrew Trickd5422652012-02-04 02:56:48 +0000522}
523
Andrew Trickf7b96312012-02-09 00:40:55 +0000524/// Add passes that optimize machine instructions in SSA form.
525void TargetPassConfig::addMachineSSAOptimization() {
526 // Pre-ra tail duplication.
Bob Wilson3fb99a72012-07-02 19:48:37 +0000527 if (addPass(&EarlyTailDuplicateID))
Andrew Trickf7b96312012-02-09 00:40:55 +0000528 printAndVerify("After Pre-RegAlloc TailDuplicate");
Andrew Trickf7b96312012-02-09 00:40:55 +0000529
530 // Optimize PHIs before DCE: removing dead PHI cycles may make more
531 // instructions dead.
Bob Wilson3fb99a72012-07-02 19:48:37 +0000532 addPass(&OptimizePHIsID);
Andrew Trickf7b96312012-02-09 00:40:55 +0000533
Nadav Rotemc05d3062012-09-06 09:17:37 +0000534 // This pass merges large allocas. StackSlotColoring is a different pass
535 // which merges spill slots.
536 addPass(&StackColoringID);
537
Andrew Trickf7b96312012-02-09 00:40:55 +0000538 // If the target requests it, assign local variables to stack slots relative
539 // to one another and simplify frame index references where possible.
Bob Wilson3fb99a72012-07-02 19:48:37 +0000540 addPass(&LocalStackSlotAllocationID);
Andrew Trickf7b96312012-02-09 00:40:55 +0000541
542 // With optimization, dead code should already be eliminated. However
543 // there is one known exception: lowered code for arguments that are only
544 // used by tail calls, where the tail calls reuse the incoming stack
545 // arguments directly (see t11 in test/CodeGen/X86/sibcall.ll).
Bob Wilson3fb99a72012-07-02 19:48:37 +0000546 addPass(&DeadMachineInstructionElimID);
Andrew Trickf7b96312012-02-09 00:40:55 +0000547 printAndVerify("After codegen DCE pass");
548
Jakob Stoklund Olesen33242fd2012-07-04 00:09:54 +0000549 addPass(&EarlyIfConverterID);
Bob Wilson3fb99a72012-07-02 19:48:37 +0000550 addPass(&MachineLICMID);
551 addPass(&MachineCSEID);
552 addPass(&MachineSinkingID);
Andrew Trickf7b96312012-02-09 00:40:55 +0000553 printAndVerify("After Machine LICM, CSE and Sinking passes");
554
Bob Wilson3fb99a72012-07-02 19:48:37 +0000555 addPass(&PeepholeOptimizerID);
Andrew Trickf7b96312012-02-09 00:40:55 +0000556 printAndVerify("After codegen peephole optimization pass");
557}
558
Andrew Trick74613342012-02-04 02:56:45 +0000559//===---------------------------------------------------------------------===//
Andrew Trickf7b96312012-02-09 00:40:55 +0000560/// Register Allocation Pass Configuration
Jim Laskeyeb577ba2006-08-02 12:30:23 +0000561//===---------------------------------------------------------------------===//
Andrew Trickf7b96312012-02-09 00:40:55 +0000562
Andrew Trick8dd26252012-02-10 04:10:36 +0000563bool TargetPassConfig::getOptimizeRegAlloc() const {
564 switch (OptimizeRegAlloc) {
565 case cl::BOU_UNSET: return getOptLevel() != CodeGenOpt::None;
566 case cl::BOU_TRUE: return true;
567 case cl::BOU_FALSE: return false;
568 }
569 llvm_unreachable("Invalid optimize-regalloc state");
570}
571
Andrew Trickf7b96312012-02-09 00:40:55 +0000572/// RegisterRegAlloc's global Registry tracks allocator registration.
Jim Laskeyeb577ba2006-08-02 12:30:23 +0000573MachinePassRegistry RegisterRegAlloc::Registry;
574
Andrew Trickf7b96312012-02-09 00:40:55 +0000575/// A dummy default pass factory indicates whether the register allocator is
576/// overridden on the command line.
Andrew Trick8dd26252012-02-10 04:10:36 +0000577static FunctionPass *useDefaultRegisterAllocator() { return 0; }
Jakob Stoklund Olesen700bfad2010-05-27 23:57:25 +0000578static RegisterRegAlloc
579defaultRegAlloc("default",
580 "pick register allocator based on -O option",
Andrew Trick8dd26252012-02-10 04:10:36 +0000581 useDefaultRegisterAllocator);
Jim Laskeyeb577ba2006-08-02 12:30:23 +0000582
Andrew Trickf7b96312012-02-09 00:40:55 +0000583/// -regalloc=... command line option.
Dan Gohman844731a2008-05-13 00:00:25 +0000584static cl::opt<RegisterRegAlloc::FunctionPassCtor, false,
585 RegisterPassParser<RegisterRegAlloc> >
586RegAlloc("regalloc",
Andrew Trick8dd26252012-02-10 04:10:36 +0000587 cl::init(&useDefaultRegisterAllocator),
Jakob Stoklund Olesen700bfad2010-05-27 23:57:25 +0000588 cl::desc("Register allocator to use"));
Alkis Evlogimenos7237ece2003-10-02 16:57:49 +0000589
Jim Laskeyeb577ba2006-08-02 12:30:23 +0000590
Andrew Trick8dd26252012-02-10 04:10:36 +0000591/// Instantiate the default register allocator pass for this target for either
592/// the optimized or unoptimized allocation path. This will be added to the pass
593/// manager by addFastRegAlloc in the unoptimized case or addOptimizedRegAlloc
594/// in the optimized case.
595///
596/// A target that uses the standard regalloc pass order for fast or optimized
597/// allocation may still override this for per-target regalloc
598/// selection. But -regalloc=... always takes precedence.
599FunctionPass *TargetPassConfig::createTargetRegisterAllocator(bool Optimized) {
600 if (Optimized)
601 return createGreedyRegisterAllocator();
602 else
603 return createFastRegisterAllocator();
604}
605
606/// Find and instantiate the register allocation pass requested by this target
607/// at the current optimization level. Different register allocators are
608/// defined as separate passes because they may require different analysis.
609///
610/// This helper ensures that the regalloc= option is always available,
611/// even for targets that override the default allocator.
612///
613/// FIXME: When MachinePassRegistry register pass IDs instead of function ptrs,
614/// this can be folded into addPass.
615FunctionPass *TargetPassConfig::createRegAllocPass(bool Optimized) {
Jim Laskey9ff542f2006-08-01 18:29:48 +0000616 RegisterRegAlloc::FunctionPassCtor Ctor = RegisterRegAlloc::getDefault();
Jakob Stoklund Olesen700bfad2010-05-27 23:57:25 +0000617
Andrew Trick8dd26252012-02-10 04:10:36 +0000618 // Initialize the global default.
Jim Laskey13ec7022006-08-01 14:21:23 +0000619 if (!Ctor) {
Jim Laskeyeb577ba2006-08-02 12:30:23 +0000620 Ctor = RegAlloc;
621 RegisterRegAlloc::setDefault(RegAlloc);
Jim Laskey13ec7022006-08-01 14:21:23 +0000622 }
Andrew Trick8dd26252012-02-10 04:10:36 +0000623 if (Ctor != useDefaultRegisterAllocator)
Jakob Stoklund Olesen700bfad2010-05-27 23:57:25 +0000624 return Ctor();
625
Andrew Trick8dd26252012-02-10 04:10:36 +0000626 // With no -regalloc= override, ask the target for a regalloc pass.
627 return createTargetRegisterAllocator(Optimized);
628}
629
630/// Add the minimum set of target-independent passes that are required for
631/// register allocation. No coalescing or scheduling.
632void TargetPassConfig::addFastRegAlloc(FunctionPass *RegAllocPass) {
Bob Wilson3fb99a72012-07-02 19:48:37 +0000633 addPass(&PHIEliminationID);
634 addPass(&TwoAddressInstructionPassID);
Andrew Trick8dd26252012-02-10 04:10:36 +0000635
Bob Wilson564fbf62012-07-02 19:48:31 +0000636 addPass(RegAllocPass);
Andrew Trick8dd26252012-02-10 04:10:36 +0000637 printAndVerify("After Register Allocation");
Jim Laskey33a0a6d2006-07-27 20:05:00 +0000638}
Andrew Trickf7b96312012-02-09 00:40:55 +0000639
640/// Add standard target-independent passes that are tightly coupled with
Andrew Trick8dd26252012-02-10 04:10:36 +0000641/// optimized register allocation, including coalescing, machine instruction
642/// scheduling, and register allocation itself.
643void TargetPassConfig::addOptimizedRegAlloc(FunctionPass *RegAllocPass) {
Bob Wilson3fb99a72012-07-02 19:48:37 +0000644 addPass(&ProcessImplicitDefsID);
Jakob Stoklund Olesen5984d2b2012-06-25 18:12:18 +0000645
Andrew Trick8dd26252012-02-10 04:10:36 +0000646 // LiveVariables currently requires pure SSA form.
647 //
648 // FIXME: Once TwoAddressInstruction pass no longer uses kill flags,
649 // LiveVariables can be removed completely, and LiveIntervals can be directly
650 // computed. (We still either need to regenerate kill flags after regalloc, or
651 // preferably fix the scavenger to not depend on them).
Bob Wilson3fb99a72012-07-02 19:48:37 +0000652 addPass(&LiveVariablesID);
Andrew Trick8dd26252012-02-10 04:10:36 +0000653
654 // Add passes that move from transformed SSA into conventional SSA. This is a
655 // "copy coalescing" problem.
656 //
657 if (!EnableStrongPHIElim) {
658 // Edge splitting is smarter with machine loop info.
Bob Wilson3fb99a72012-07-02 19:48:37 +0000659 addPass(&MachineLoopInfoID);
660 addPass(&PHIEliminationID);
Andrew Trick8dd26252012-02-10 04:10:36 +0000661 }
Jakob Stoklund Olesendcc44362012-08-03 22:12:54 +0000662
663 // Eventually, we want to run LiveIntervals before PHI elimination.
664 if (EarlyLiveIntervals)
665 addPass(&LiveIntervalsID);
666
Bob Wilson3fb99a72012-07-02 19:48:37 +0000667 addPass(&TwoAddressInstructionPassID);
Andrew Trick8dd26252012-02-10 04:10:36 +0000668
Andrew Trick8dd26252012-02-10 04:10:36 +0000669 if (EnableStrongPHIElim)
Bob Wilson3fb99a72012-07-02 19:48:37 +0000670 addPass(&StrongPHIEliminationID);
Andrew Trick8dd26252012-02-10 04:10:36 +0000671
Bob Wilson3fb99a72012-07-02 19:48:37 +0000672 addPass(&RegisterCoalescerID);
Andrew Trick8dd26252012-02-10 04:10:36 +0000673
674 // PreRA instruction scheduling.
Bob Wilson3fb99a72012-07-02 19:48:37 +0000675 if (addPass(&MachineSchedulerID))
Andrew Trick17d35e52012-03-14 04:00:41 +0000676 printAndVerify("After Machine Scheduling");
Andrew Trick8dd26252012-02-10 04:10:36 +0000677
678 // Add the selected register allocation pass.
Bob Wilson564fbf62012-07-02 19:48:31 +0000679 addPass(RegAllocPass);
Jakob Stoklund Olesen34f5a2b2012-06-26 17:09:29 +0000680 printAndVerify("After Register Allocation, before rewriter");
681
682 // Allow targets to change the register assignments before rewriting.
683 if (addPreRewrite())
684 printAndVerify("After pre-rewrite passes");
Andrew Trickf7b96312012-02-09 00:40:55 +0000685
Jakob Stoklund Olesen05ec7122012-06-08 23:44:45 +0000686 // Finally rewrite virtual registers.
Bob Wilson3fb99a72012-07-02 19:48:37 +0000687 addPass(&VirtRegRewriterID);
Jakob Stoklund Olesen05ec7122012-06-08 23:44:45 +0000688 printAndVerify("After Virtual Register Rewriter");
689
Andrew Trick746f24b2012-02-11 07:11:32 +0000690 // FinalizeRegAlloc is convenient until MachineInstrBundles is more mature,
691 // but eventually, all users of it should probably be moved to addPostRA and
692 // it can go away. Currently, it's the intended place for targets to run
693 // FinalizeMachineBundles, because passes other than MachineScheduling an
694 // RegAlloc itself may not be aware of bundles.
695 if (addFinalizeRegAlloc())
696 printAndVerify("After RegAlloc finalization");
697
Andrew Trickf7b96312012-02-09 00:40:55 +0000698 // Perform stack slot coloring and post-ra machine LICM.
Andrew Trick8dd26252012-02-10 04:10:36 +0000699 //
700 // FIXME: Re-enable coloring with register when it's capable of adding
701 // kill markers.
Bob Wilson3fb99a72012-07-02 19:48:37 +0000702 addPass(&StackSlotColoringID);
Andrew Trick900d7b72012-02-15 07:57:03 +0000703
704 // Run post-ra machine LICM to hoist reloads / remats.
705 //
706 // FIXME: can this move into MachineLateOptimization?
Bob Wilson3fb99a72012-07-02 19:48:37 +0000707 addPass(&PostRAMachineLICMID);
Andrew Trick900d7b72012-02-15 07:57:03 +0000708
709 printAndVerify("After StackSlotColoring and postra Machine LICM");
Andrew Trickf7b96312012-02-09 00:40:55 +0000710}
711
712//===---------------------------------------------------------------------===//
713/// Post RegAlloc Pass Configuration
714//===---------------------------------------------------------------------===//
715
716/// Add passes that optimize machine instructions after register allocation.
717void TargetPassConfig::addMachineLateOptimization() {
718 // Branch folding must be run after regalloc and prolog/epilog insertion.
Bob Wilson3fb99a72012-07-02 19:48:37 +0000719 if (addPass(&BranchFolderPassID))
Jakob Stoklund Olesen663ee202012-03-28 20:47:37 +0000720 printAndVerify("After BranchFolding");
Andrew Trickf7b96312012-02-09 00:40:55 +0000721
722 // Tail duplication.
Bob Wilson3fb99a72012-07-02 19:48:37 +0000723 if (addPass(&TailDuplicateID))
Jakob Stoklund Olesen663ee202012-03-28 20:47:37 +0000724 printAndVerify("After TailDuplicate");
Andrew Trickf7b96312012-02-09 00:40:55 +0000725
726 // Copy propagation.
Bob Wilson3fb99a72012-07-02 19:48:37 +0000727 if (addPass(&MachineCopyPropagationID))
Jakob Stoklund Olesen663ee202012-03-28 20:47:37 +0000728 printAndVerify("After copy propagation pass");
Andrew Trickf7b96312012-02-09 00:40:55 +0000729}
730
731/// Add standard basic block placement passes.
732void TargetPassConfig::addBlockPlacement() {
Bob Wilson3fb99a72012-07-02 19:48:37 +0000733 AnalysisID PassID = 0;
Chandler Carruth9e67db42012-04-16 13:49:17 +0000734 if (!DisableBlockPlacement) {
735 // MachineBlockPlacement is a new pass which subsumes the functionality of
736 // CodPlacementOpt. The old code placement pass can be restored by
737 // disabling block placement, but eventually it will be removed.
Bob Wilson3fb99a72012-07-02 19:48:37 +0000738 PassID = addPass(&MachineBlockPlacementID);
Andrew Trickf7b96312012-02-09 00:40:55 +0000739 } else {
Bob Wilson3fb99a72012-07-02 19:48:37 +0000740 PassID = addPass(&CodePlacementOptID);
Andrew Trickf7b96312012-02-09 00:40:55 +0000741 }
Bob Wilson3fb99a72012-07-02 19:48:37 +0000742 if (PassID) {
Andrew Trick79bf2882012-02-15 03:21:51 +0000743 // Run a separate pass to collect block placement statistics.
744 if (EnableBlockPlacementStats)
Bob Wilson3fb99a72012-07-02 19:48:37 +0000745 addPass(&MachineBlockPlacementStatsID);
Andrew Trickf7b96312012-02-09 00:40:55 +0000746
Jakob Stoklund Olesen8b4c5022012-03-28 23:54:28 +0000747 printAndVerify("After machine block placement.");
Andrew Trickf7b96312012-02-09 00:40:55 +0000748 }
749}