blob: 02ac836337aa9ebbf07b34ebfd7e134487af49c8 [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
Chandler Carruthd04a8d42012-12-03 16:50:05 +000015#include "llvm/CodeGen/Passes.h"
Andrew Trickd5422652012-02-04 02:56:48 +000016#include "llvm/Analysis/Passes.h"
17#include "llvm/Analysis/Verifier.h"
Chandler Carruthd04a8d42012-12-03 16:50:05 +000018#include "llvm/Assembly/PrintModulePass.h"
Andrew Trickd5422652012-02-04 02:56:48 +000019#include "llvm/CodeGen/GCStrategy.h"
Andrew Trickd5422652012-02-04 02:56:48 +000020#include "llvm/CodeGen/MachineFunctionPass.h"
Andrew Trickd5422652012-02-04 02:56:48 +000021#include "llvm/CodeGen/RegAllocRegistry.h"
Bob Wilson564fbf62012-07-02 19:48:31 +000022#include "llvm/MC/MCAsmInfo.h"
Chandler Carruthd04a8d42012-12-03 16:50:05 +000023#include "llvm/PassManager.h"
Andrew Trickd5422652012-02-04 02:56:48 +000024#include "llvm/Support/CommandLine.h"
25#include "llvm/Support/Debug.h"
Andrew Trick74613342012-02-04 02:56:45 +000026#include "llvm/Support/ErrorHandling.h"
Chandler Carruthd04a8d42012-12-03 16:50:05 +000027#include "llvm/Target/TargetLowering.h"
28#include "llvm/Target/TargetOptions.h"
29#include "llvm/Target/TargetSubtargetInfo.h"
30#include "llvm/Transforms/Scalar.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
Bill Wendling08510b12012-11-30 22:08:55 +0000403/// Add pass to prepare the LLVM IR for code generation. This should be done
404/// before exception handling preparation passes.
405void TargetPassConfig::addCodeGenPrepare() {
406 if (getOptLevel() != CodeGenOpt::None && !DisableCGP)
407 addPass(createCodeGenPreparePass(getTargetLowering()));
408}
409
Andrew Trick061efcf2012-02-04 02:56:59 +0000410/// Add common passes that perform LLVM IR to IR transforms in preparation for
411/// instruction selection.
412void TargetPassConfig::addISelPrepare() {
Bob Wilson564fbf62012-07-02 19:48:31 +0000413 addPass(createStackProtectorPass(getTargetLowering()));
Andrew Trickd5422652012-02-04 02:56:48 +0000414
415 addPreISel();
416
417 if (PrintISelInput)
Bob Wilson564fbf62012-07-02 19:48:31 +0000418 addPass(createPrintFunctionPass("\n\n"
Bill Wendling7c4ce302012-05-01 08:27:43 +0000419 "*** Final LLVM Code input to ISel ***\n",
420 &dbgs()));
Andrew Trickd5422652012-02-04 02:56:48 +0000421
422 // All passes which modify the LLVM IR are now complete; run the verifier
423 // to ensure that the IR is valid.
424 if (!DisableVerify)
Bob Wilson564fbf62012-07-02 19:48:31 +0000425 addPass(createVerifierPass());
Andrew Trick061efcf2012-02-04 02:56:59 +0000426}
Andrew Trickd5422652012-02-04 02:56:48 +0000427
Andrew Trickf7b96312012-02-09 00:40:55 +0000428/// Add the complete set of target-independent postISel code generator passes.
429///
430/// This can be read as the standard order of major LLVM CodeGen stages. Stages
431/// with nontrivial configuration or multiple passes are broken out below in
432/// add%Stage routines.
433///
434/// Any TargetPassConfig::addXX routine may be overriden by the Target. The
435/// addPre/Post methods with empty header implementations allow injecting
436/// target-specific fixups just before or after major stages. Additionally,
437/// targets have the flexibility to change pass order within a stage by
438/// overriding default implementation of add%Stage routines below. Each
439/// technique has maintainability tradeoffs because alternate pass orders are
440/// not well supported. addPre/Post works better if the target pass is easily
441/// tied to a common pass. But if it has subtle dependencies on multiple passes,
Andrew Trick06efdd22012-02-10 07:08:25 +0000442/// the target should override the stage instead.
Andrew Trickf7b96312012-02-09 00:40:55 +0000443///
444/// TODO: We could use a single addPre/Post(ID) hook to allow pass injection
445/// before/after any target-independent pass. But it's currently overkill.
Andrew Trick061efcf2012-02-04 02:56:59 +0000446void TargetPassConfig::addMachinePasses() {
Bob Wilson6e1b8122012-05-30 00:17:12 +0000447 // Insert a machine instr printer pass after the specified pass.
448 // If -print-machineinstrs specified, print machineinstrs after all passes.
449 if (StringRef(PrintMachineInstrs.getValue()).equals(""))
450 TM->Options.PrintMachineCode = true;
451 else if (!StringRef(PrintMachineInstrs.getValue())
452 .equals("option-unspecified")) {
453 const PassRegistry *PR = PassRegistry::getPassRegistry();
454 const PassInfo *TPI = PR->getPassInfo(PrintMachineInstrs.getValue());
455 const PassInfo *IPI = PR->getPassInfo(StringRef("print-machineinstrs"));
456 assert (TPI && IPI && "Pass ID not registered!");
Roman Divacky59324292012-09-05 22:26:57 +0000457 const char *TID = (const char *)(TPI->getTypeInfo());
458 const char *IID = (const char *)(IPI->getTypeInfo());
Bob Wilson3fb99a72012-07-02 19:48:37 +0000459 insertPass(TID, IID);
Bob Wilson6e1b8122012-05-30 00:17:12 +0000460 }
461
Jakob Stoklund Olesenf86c00f2012-07-04 19:28:27 +0000462 // Print the instruction selected machine code...
463 printAndVerify("After Instruction Selection");
464
Andrew Trickd5422652012-02-04 02:56:48 +0000465 // Expand pseudo-instructions emitted by ISel.
Jakob Stoklund Olesen228e3f52012-08-20 20:52:08 +0000466 if (addPass(&ExpandISelPseudosID))
467 printAndVerify("After ExpandISelPseudos");
Andrew Trickd5422652012-02-04 02:56:48 +0000468
Andrew Trickf7b96312012-02-09 00:40:55 +0000469 // Add passes that optimize machine instructions in SSA form.
Andrew Trickd5422652012-02-04 02:56:48 +0000470 if (getOptLevel() != CodeGenOpt::None) {
Andrew Trickf7b96312012-02-09 00:40:55 +0000471 addMachineSSAOptimization();
Craig Topper8f54a532012-11-19 00:11:50 +0000472 } else {
Andrew Trickf7b96312012-02-09 00:40:55 +0000473 // If the target requests it, assign local variables to stack slots relative
474 // to one another and simplify frame index references where possible.
Bob Wilson3fb99a72012-07-02 19:48:37 +0000475 addPass(&LocalStackSlotAllocationID);
Andrew Trickd5422652012-02-04 02:56:48 +0000476 }
477
478 // Run pre-ra passes.
479 if (addPreRegAlloc())
480 printAndVerify("After PreRegAlloc passes");
481
Andrew Trickf7b96312012-02-09 00:40:55 +0000482 // Run register allocation and passes that are tightly coupled with it,
483 // including phi elimination and scheduling.
Andrew Trick8dd26252012-02-10 04:10:36 +0000484 if (getOptimizeRegAlloc())
485 addOptimizedRegAlloc(createRegAllocPass(true));
486 else
487 addFastRegAlloc(createRegAllocPass(false));
Andrew Trickd5422652012-02-04 02:56:48 +0000488
489 // Run post-ra passes.
490 if (addPostRegAlloc())
491 printAndVerify("After PostRegAlloc passes");
492
493 // Insert prolog/epilog code. Eliminate abstract frame index references...
Bob Wilson3fb99a72012-07-02 19:48:37 +0000494 addPass(&PrologEpilogCodeInserterID);
Andrew Trickd5422652012-02-04 02:56:48 +0000495 printAndVerify("After PrologEpilogCodeInserter");
496
Andrew Trickf7b96312012-02-09 00:40:55 +0000497 /// Add passes that optimize machine instructions after register allocation.
498 if (getOptLevel() != CodeGenOpt::None)
499 addMachineLateOptimization();
Andrew Trickd5422652012-02-04 02:56:48 +0000500
501 // Expand pseudo instructions before second scheduling pass.
Bob Wilson3fb99a72012-07-02 19:48:37 +0000502 addPass(&ExpandPostRAPseudosID);
Jakob Stoklund Olesen2ef5bf62012-03-28 20:49:30 +0000503 printAndVerify("After ExpandPostRAPseudos");
Andrew Trickd5422652012-02-04 02:56:48 +0000504
505 // Run pre-sched2 passes.
506 if (addPreSched2())
Jakob Stoklund Olesen78811662012-03-28 23:31:15 +0000507 printAndVerify("After PreSched2 passes");
Andrew Trickd5422652012-02-04 02:56:48 +0000508
509 // Second pass scheduler.
Andrew Trick79bf2882012-02-15 03:21:51 +0000510 if (getOptLevel() != CodeGenOpt::None) {
Bob Wilson3fb99a72012-07-02 19:48:37 +0000511 addPass(&PostRASchedulerID);
Jakob Stoklund Olesen8b4c5022012-03-28 23:54:28 +0000512 printAndVerify("After PostRAScheduler");
Andrew Trickd5422652012-02-04 02:56:48 +0000513 }
514
Andrew Trickf7b96312012-02-09 00:40:55 +0000515 // GC
Evan Chengab37b2c2012-12-21 02:57:04 +0000516 if (addGCPasses()) {
517 if (PrintGCInfo)
518 addPass(createGCInfoPrinter(dbgs()));
519 }
Andrew Trickd5422652012-02-04 02:56:48 +0000520
Andrew Trickf7b96312012-02-09 00:40:55 +0000521 // Basic block placement.
Andrew Trick79bf2882012-02-15 03:21:51 +0000522 if (getOptLevel() != CodeGenOpt::None)
Andrew Trickf7b96312012-02-09 00:40:55 +0000523 addBlockPlacement();
Andrew Trickd5422652012-02-04 02:56:48 +0000524
525 if (addPreEmitPass())
Jakob Stoklund Olesen8b4c5022012-03-28 23:54:28 +0000526 printAndVerify("After PreEmit passes");
Andrew Trickd5422652012-02-04 02:56:48 +0000527}
528
Andrew Trickf7b96312012-02-09 00:40:55 +0000529/// Add passes that optimize machine instructions in SSA form.
530void TargetPassConfig::addMachineSSAOptimization() {
531 // Pre-ra tail duplication.
Bob Wilson3fb99a72012-07-02 19:48:37 +0000532 if (addPass(&EarlyTailDuplicateID))
Andrew Trickf7b96312012-02-09 00:40:55 +0000533 printAndVerify("After Pre-RegAlloc TailDuplicate");
Andrew Trickf7b96312012-02-09 00:40:55 +0000534
535 // Optimize PHIs before DCE: removing dead PHI cycles may make more
536 // instructions dead.
Bob Wilson3fb99a72012-07-02 19:48:37 +0000537 addPass(&OptimizePHIsID);
Andrew Trickf7b96312012-02-09 00:40:55 +0000538
Nadav Rotemc05d3062012-09-06 09:17:37 +0000539 // This pass merges large allocas. StackSlotColoring is a different pass
540 // which merges spill slots.
541 addPass(&StackColoringID);
542
Andrew Trickf7b96312012-02-09 00:40:55 +0000543 // If the target requests it, assign local variables to stack slots relative
544 // to one another and simplify frame index references where possible.
Bob Wilson3fb99a72012-07-02 19:48:37 +0000545 addPass(&LocalStackSlotAllocationID);
Andrew Trickf7b96312012-02-09 00:40:55 +0000546
547 // With optimization, dead code should already be eliminated. However
548 // there is one known exception: lowered code for arguments that are only
549 // used by tail calls, where the tail calls reuse the incoming stack
550 // arguments directly (see t11 in test/CodeGen/X86/sibcall.ll).
Bob Wilson3fb99a72012-07-02 19:48:37 +0000551 addPass(&DeadMachineInstructionElimID);
Andrew Trickf7b96312012-02-09 00:40:55 +0000552 printAndVerify("After codegen DCE pass");
553
Jakob Stoklund Olesen33242fd2012-07-04 00:09:54 +0000554 addPass(&EarlyIfConverterID);
Bob Wilson3fb99a72012-07-02 19:48:37 +0000555 addPass(&MachineLICMID);
556 addPass(&MachineCSEID);
557 addPass(&MachineSinkingID);
Andrew Trickf7b96312012-02-09 00:40:55 +0000558 printAndVerify("After Machine LICM, CSE and Sinking passes");
559
Bob Wilson3fb99a72012-07-02 19:48:37 +0000560 addPass(&PeepholeOptimizerID);
Andrew Trickf7b96312012-02-09 00:40:55 +0000561 printAndVerify("After codegen peephole optimization pass");
562}
563
Andrew Trick74613342012-02-04 02:56:45 +0000564//===---------------------------------------------------------------------===//
Andrew Trickf7b96312012-02-09 00:40:55 +0000565/// Register Allocation Pass Configuration
Jim Laskeyeb577ba2006-08-02 12:30:23 +0000566//===---------------------------------------------------------------------===//
Andrew Trickf7b96312012-02-09 00:40:55 +0000567
Andrew Trick8dd26252012-02-10 04:10:36 +0000568bool TargetPassConfig::getOptimizeRegAlloc() const {
569 switch (OptimizeRegAlloc) {
570 case cl::BOU_UNSET: return getOptLevel() != CodeGenOpt::None;
571 case cl::BOU_TRUE: return true;
572 case cl::BOU_FALSE: return false;
573 }
574 llvm_unreachable("Invalid optimize-regalloc state");
575}
576
Andrew Trickf7b96312012-02-09 00:40:55 +0000577/// RegisterRegAlloc's global Registry tracks allocator registration.
Jim Laskeyeb577ba2006-08-02 12:30:23 +0000578MachinePassRegistry RegisterRegAlloc::Registry;
579
Andrew Trickf7b96312012-02-09 00:40:55 +0000580/// A dummy default pass factory indicates whether the register allocator is
581/// overridden on the command line.
Andrew Trick8dd26252012-02-10 04:10:36 +0000582static FunctionPass *useDefaultRegisterAllocator() { return 0; }
Jakob Stoklund Olesen700bfad2010-05-27 23:57:25 +0000583static RegisterRegAlloc
584defaultRegAlloc("default",
585 "pick register allocator based on -O option",
Andrew Trick8dd26252012-02-10 04:10:36 +0000586 useDefaultRegisterAllocator);
Jim Laskeyeb577ba2006-08-02 12:30:23 +0000587
Andrew Trickf7b96312012-02-09 00:40:55 +0000588/// -regalloc=... command line option.
Dan Gohman844731a2008-05-13 00:00:25 +0000589static cl::opt<RegisterRegAlloc::FunctionPassCtor, false,
590 RegisterPassParser<RegisterRegAlloc> >
591RegAlloc("regalloc",
Andrew Trick8dd26252012-02-10 04:10:36 +0000592 cl::init(&useDefaultRegisterAllocator),
Jakob Stoklund Olesen700bfad2010-05-27 23:57:25 +0000593 cl::desc("Register allocator to use"));
Alkis Evlogimenos7237ece2003-10-02 16:57:49 +0000594
Jim Laskeyeb577ba2006-08-02 12:30:23 +0000595
Andrew Trick8dd26252012-02-10 04:10:36 +0000596/// Instantiate the default register allocator pass for this target for either
597/// the optimized or unoptimized allocation path. This will be added to the pass
598/// manager by addFastRegAlloc in the unoptimized case or addOptimizedRegAlloc
599/// in the optimized case.
600///
601/// A target that uses the standard regalloc pass order for fast or optimized
602/// allocation may still override this for per-target regalloc
603/// selection. But -regalloc=... always takes precedence.
604FunctionPass *TargetPassConfig::createTargetRegisterAllocator(bool Optimized) {
605 if (Optimized)
606 return createGreedyRegisterAllocator();
607 else
608 return createFastRegisterAllocator();
609}
610
611/// Find and instantiate the register allocation pass requested by this target
612/// at the current optimization level. Different register allocators are
613/// defined as separate passes because they may require different analysis.
614///
615/// This helper ensures that the regalloc= option is always available,
616/// even for targets that override the default allocator.
617///
618/// FIXME: When MachinePassRegistry register pass IDs instead of function ptrs,
619/// this can be folded into addPass.
620FunctionPass *TargetPassConfig::createRegAllocPass(bool Optimized) {
Jim Laskey9ff542f2006-08-01 18:29:48 +0000621 RegisterRegAlloc::FunctionPassCtor Ctor = RegisterRegAlloc::getDefault();
Jakob Stoklund Olesen700bfad2010-05-27 23:57:25 +0000622
Andrew Trick8dd26252012-02-10 04:10:36 +0000623 // Initialize the global default.
Jim Laskey13ec7022006-08-01 14:21:23 +0000624 if (!Ctor) {
Jim Laskeyeb577ba2006-08-02 12:30:23 +0000625 Ctor = RegAlloc;
626 RegisterRegAlloc::setDefault(RegAlloc);
Jim Laskey13ec7022006-08-01 14:21:23 +0000627 }
Andrew Trick8dd26252012-02-10 04:10:36 +0000628 if (Ctor != useDefaultRegisterAllocator)
Jakob Stoklund Olesen700bfad2010-05-27 23:57:25 +0000629 return Ctor();
630
Andrew Trick8dd26252012-02-10 04:10:36 +0000631 // With no -regalloc= override, ask the target for a regalloc pass.
632 return createTargetRegisterAllocator(Optimized);
633}
634
635/// Add the minimum set of target-independent passes that are required for
636/// register allocation. No coalescing or scheduling.
637void TargetPassConfig::addFastRegAlloc(FunctionPass *RegAllocPass) {
Bob Wilson3fb99a72012-07-02 19:48:37 +0000638 addPass(&PHIEliminationID);
639 addPass(&TwoAddressInstructionPassID);
Andrew Trick8dd26252012-02-10 04:10:36 +0000640
Bob Wilson564fbf62012-07-02 19:48:31 +0000641 addPass(RegAllocPass);
Andrew Trick8dd26252012-02-10 04:10:36 +0000642 printAndVerify("After Register Allocation");
Jim Laskey33a0a6d2006-07-27 20:05:00 +0000643}
Andrew Trickf7b96312012-02-09 00:40:55 +0000644
645/// Add standard target-independent passes that are tightly coupled with
Andrew Trick8dd26252012-02-10 04:10:36 +0000646/// optimized register allocation, including coalescing, machine instruction
647/// scheduling, and register allocation itself.
648void TargetPassConfig::addOptimizedRegAlloc(FunctionPass *RegAllocPass) {
Bob Wilson3fb99a72012-07-02 19:48:37 +0000649 addPass(&ProcessImplicitDefsID);
Jakob Stoklund Olesen5984d2b2012-06-25 18:12:18 +0000650
Andrew Trick8dd26252012-02-10 04:10:36 +0000651 // LiveVariables currently requires pure SSA form.
652 //
653 // FIXME: Once TwoAddressInstruction pass no longer uses kill flags,
654 // LiveVariables can be removed completely, and LiveIntervals can be directly
655 // computed. (We still either need to regenerate kill flags after regalloc, or
656 // preferably fix the scavenger to not depend on them).
Bob Wilson3fb99a72012-07-02 19:48:37 +0000657 addPass(&LiveVariablesID);
Andrew Trick8dd26252012-02-10 04:10:36 +0000658
659 // Add passes that move from transformed SSA into conventional SSA. This is a
660 // "copy coalescing" problem.
661 //
662 if (!EnableStrongPHIElim) {
663 // Edge splitting is smarter with machine loop info.
Bob Wilson3fb99a72012-07-02 19:48:37 +0000664 addPass(&MachineLoopInfoID);
665 addPass(&PHIEliminationID);
Andrew Trick8dd26252012-02-10 04:10:36 +0000666 }
Jakob Stoklund Olesendcc44362012-08-03 22:12:54 +0000667
668 // Eventually, we want to run LiveIntervals before PHI elimination.
669 if (EarlyLiveIntervals)
670 addPass(&LiveIntervalsID);
671
Bob Wilson3fb99a72012-07-02 19:48:37 +0000672 addPass(&TwoAddressInstructionPassID);
Andrew Trick8dd26252012-02-10 04:10:36 +0000673
Andrew Trick8dd26252012-02-10 04:10:36 +0000674 if (EnableStrongPHIElim)
Bob Wilson3fb99a72012-07-02 19:48:37 +0000675 addPass(&StrongPHIEliminationID);
Andrew Trick8dd26252012-02-10 04:10:36 +0000676
Bob Wilson3fb99a72012-07-02 19:48:37 +0000677 addPass(&RegisterCoalescerID);
Andrew Trick8dd26252012-02-10 04:10:36 +0000678
679 // PreRA instruction scheduling.
Bob Wilson3fb99a72012-07-02 19:48:37 +0000680 if (addPass(&MachineSchedulerID))
Andrew Trick17d35e52012-03-14 04:00:41 +0000681 printAndVerify("After Machine Scheduling");
Andrew Trick8dd26252012-02-10 04:10:36 +0000682
683 // Add the selected register allocation pass.
Bob Wilson564fbf62012-07-02 19:48:31 +0000684 addPass(RegAllocPass);
Jakob Stoklund Olesen34f5a2b2012-06-26 17:09:29 +0000685 printAndVerify("After Register Allocation, before rewriter");
686
687 // Allow targets to change the register assignments before rewriting.
688 if (addPreRewrite())
689 printAndVerify("After pre-rewrite passes");
Andrew Trickf7b96312012-02-09 00:40:55 +0000690
Jakob Stoklund Olesen05ec7122012-06-08 23:44:45 +0000691 // Finally rewrite virtual registers.
Bob Wilson3fb99a72012-07-02 19:48:37 +0000692 addPass(&VirtRegRewriterID);
Jakob Stoklund Olesen05ec7122012-06-08 23:44:45 +0000693 printAndVerify("After Virtual Register Rewriter");
694
Andrew Trick746f24b2012-02-11 07:11:32 +0000695 // FinalizeRegAlloc is convenient until MachineInstrBundles is more mature,
696 // but eventually, all users of it should probably be moved to addPostRA and
697 // it can go away. Currently, it's the intended place for targets to run
698 // FinalizeMachineBundles, because passes other than MachineScheduling an
699 // RegAlloc itself may not be aware of bundles.
700 if (addFinalizeRegAlloc())
701 printAndVerify("After RegAlloc finalization");
702
Andrew Trickf7b96312012-02-09 00:40:55 +0000703 // Perform stack slot coloring and post-ra machine LICM.
Andrew Trick8dd26252012-02-10 04:10:36 +0000704 //
705 // FIXME: Re-enable coloring with register when it's capable of adding
706 // kill markers.
Bob Wilson3fb99a72012-07-02 19:48:37 +0000707 addPass(&StackSlotColoringID);
Andrew Trick900d7b72012-02-15 07:57:03 +0000708
709 // Run post-ra machine LICM to hoist reloads / remats.
710 //
711 // FIXME: can this move into MachineLateOptimization?
Bob Wilson3fb99a72012-07-02 19:48:37 +0000712 addPass(&PostRAMachineLICMID);
Andrew Trick900d7b72012-02-15 07:57:03 +0000713
714 printAndVerify("After StackSlotColoring and postra Machine LICM");
Andrew Trickf7b96312012-02-09 00:40:55 +0000715}
716
717//===---------------------------------------------------------------------===//
718/// Post RegAlloc Pass Configuration
719//===---------------------------------------------------------------------===//
720
721/// Add passes that optimize machine instructions after register allocation.
722void TargetPassConfig::addMachineLateOptimization() {
723 // Branch folding must be run after regalloc and prolog/epilog insertion.
Bob Wilson3fb99a72012-07-02 19:48:37 +0000724 if (addPass(&BranchFolderPassID))
Jakob Stoklund Olesen663ee202012-03-28 20:47:37 +0000725 printAndVerify("After BranchFolding");
Andrew Trickf7b96312012-02-09 00:40:55 +0000726
727 // Tail duplication.
Bob Wilson3fb99a72012-07-02 19:48:37 +0000728 if (addPass(&TailDuplicateID))
Jakob Stoklund Olesen663ee202012-03-28 20:47:37 +0000729 printAndVerify("After TailDuplicate");
Andrew Trickf7b96312012-02-09 00:40:55 +0000730
731 // Copy propagation.
Bob Wilson3fb99a72012-07-02 19:48:37 +0000732 if (addPass(&MachineCopyPropagationID))
Jakob Stoklund Olesen663ee202012-03-28 20:47:37 +0000733 printAndVerify("After copy propagation pass");
Andrew Trickf7b96312012-02-09 00:40:55 +0000734}
735
Evan Chengab37b2c2012-12-21 02:57:04 +0000736/// Add standard GC passes.
737bool TargetPassConfig::addGCPasses() {
738 addPass(&GCMachineCodeAnalysisID);
739 return true;
740}
741
Andrew Trickf7b96312012-02-09 00:40:55 +0000742/// Add standard basic block placement passes.
743void TargetPassConfig::addBlockPlacement() {
Bob Wilson3fb99a72012-07-02 19:48:37 +0000744 AnalysisID PassID = 0;
Chandler Carruth9e67db42012-04-16 13:49:17 +0000745 if (!DisableBlockPlacement) {
746 // MachineBlockPlacement is a new pass which subsumes the functionality of
747 // CodPlacementOpt. The old code placement pass can be restored by
748 // disabling block placement, but eventually it will be removed.
Bob Wilson3fb99a72012-07-02 19:48:37 +0000749 PassID = addPass(&MachineBlockPlacementID);
Andrew Trickf7b96312012-02-09 00:40:55 +0000750 } else {
Bob Wilson3fb99a72012-07-02 19:48:37 +0000751 PassID = addPass(&CodePlacementOptID);
Andrew Trickf7b96312012-02-09 00:40:55 +0000752 }
Bob Wilson3fb99a72012-07-02 19:48:37 +0000753 if (PassID) {
Andrew Trick79bf2882012-02-15 03:21:51 +0000754 // Run a separate pass to collect block placement statistics.
755 if (EnableBlockPlacementStats)
Bob Wilson3fb99a72012-07-02 19:48:37 +0000756 addPass(&MachineBlockPlacementStatsID);
Andrew Trickf7b96312012-02-09 00:40:55 +0000757
Jakob Stoklund Olesen8b4c5022012-03-28 23:54:28 +0000758 printAndVerify("After machine block placement.");
Andrew Trickf7b96312012-02-09 00:40:55 +0000759 }
760}