blob: 4ea21d4ff7bd40b3a5c4ab4f08dfe9f9c380b806 [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"
Bob Wilson564fbf62012-07-02 19:48:31 +000025#include "llvm/MC/MCAsmInfo.h"
Andrew Trickd5422652012-02-04 02:56:48 +000026#include "llvm/Assembly/PrintModulePass.h"
27#include "llvm/Support/CommandLine.h"
28#include "llvm/Support/Debug.h"
Andrew Trick74613342012-02-04 02:56:45 +000029#include "llvm/Support/ErrorHandling.h"
Jim Laskey13ec7022006-08-01 14:21:23 +000030
Chris Lattneraa4c91f2003-12-28 07:59:53 +000031using namespace llvm;
Brian Gaeked0fde302003-11-11 22:41:34 +000032
Andrew Trickd5422652012-02-04 02:56:48 +000033static cl::opt<bool> DisablePostRA("disable-post-ra", cl::Hidden,
34 cl::desc("Disable Post Regalloc"));
35static cl::opt<bool> DisableBranchFold("disable-branch-fold", cl::Hidden,
36 cl::desc("Disable branch folding"));
37static cl::opt<bool> DisableTailDuplicate("disable-tail-duplicate", cl::Hidden,
38 cl::desc("Disable tail duplication"));
39static cl::opt<bool> DisableEarlyTailDup("disable-early-taildup", cl::Hidden,
40 cl::desc("Disable pre-register allocation tail duplication"));
Chandler Carruth9e67db42012-04-16 13:49:17 +000041static cl::opt<bool> DisableBlockPlacement("disable-block-placement",
42 cl::Hidden, cl::desc("Disable the probability-driven block placement, and "
43 "re-enable the old code placement pass"));
Andrew Trickd5422652012-02-04 02:56:48 +000044static cl::opt<bool> EnableBlockPlacementStats("enable-block-placement-stats",
45 cl::Hidden, cl::desc("Collect probability-driven block placement stats"));
46static cl::opt<bool> DisableCodePlace("disable-code-place", cl::Hidden,
47 cl::desc("Disable code placement"));
48static cl::opt<bool> DisableSSC("disable-ssc", cl::Hidden,
49 cl::desc("Disable Stack Slot Coloring"));
50static cl::opt<bool> DisableMachineDCE("disable-machine-dce", cl::Hidden,
51 cl::desc("Disable Machine Dead Code Elimination"));
Jakob Stoklund Olesen0d141f82012-10-03 00:51:32 +000052static cl::opt<bool> DisableEarlyIfConversion("disable-early-ifcvt", cl::Hidden,
53 cl::desc("Disable Early If-conversion"));
Andrew Trickd5422652012-02-04 02:56:48 +000054static cl::opt<bool> DisableMachineLICM("disable-machine-licm", cl::Hidden,
55 cl::desc("Disable Machine LICM"));
56static cl::opt<bool> DisableMachineCSE("disable-machine-cse", cl::Hidden,
57 cl::desc("Disable Machine Common Subexpression Elimination"));
Andrew Trick8dd26252012-02-10 04:10:36 +000058static cl::opt<cl::boolOrDefault>
59OptimizeRegAlloc("optimize-regalloc", cl::Hidden,
60 cl::desc("Enable optimized register allocation compilation path."));
Andrew Trick746f24b2012-02-11 07:11:32 +000061static cl::opt<cl::boolOrDefault>
62EnableMachineSched("enable-misched", cl::Hidden,
Andrew Trick8dd26252012-02-10 04:10:36 +000063 cl::desc("Enable the machine instruction scheduling pass."));
64static cl::opt<bool> EnableStrongPHIElim("strong-phi-elim", cl::Hidden,
65 cl::desc("Use strong PHI elimination."));
Andrew Trickd5422652012-02-04 02:56:48 +000066static cl::opt<bool> DisablePostRAMachineLICM("disable-postra-machine-licm",
67 cl::Hidden,
68 cl::desc("Disable Machine LICM"));
69static cl::opt<bool> DisableMachineSink("disable-machine-sink", cl::Hidden,
70 cl::desc("Disable Machine Sinking"));
71static cl::opt<bool> DisableLSR("disable-lsr", cl::Hidden,
72 cl::desc("Disable Loop Strength Reduction Pass"));
73static cl::opt<bool> DisableCGP("disable-cgp", cl::Hidden,
74 cl::desc("Disable Codegen Prepare"));
75static cl::opt<bool> DisableCopyProp("disable-copyprop", cl::Hidden,
Evan Cheng01b623c2012-02-20 23:28:17 +000076 cl::desc("Disable Copy Propagation pass"));
Andrew Trickd5422652012-02-04 02:56:48 +000077static cl::opt<bool> PrintLSR("print-lsr-output", cl::Hidden,
78 cl::desc("Print LLVM IR produced by the loop-reduce pass"));
79static cl::opt<bool> PrintISelInput("print-isel-input", cl::Hidden,
80 cl::desc("Print LLVM IR input to isel pass"));
81static cl::opt<bool> PrintGCInfo("print-gc", cl::Hidden,
82 cl::desc("Dump garbage collector data"));
83static cl::opt<bool> VerifyMachineCode("verify-machineinstrs", cl::Hidden,
84 cl::desc("Verify generated machine code"),
85 cl::init(getenv("LLVM_VERIFY_MACHINEINSTRS")!=NULL));
Bob Wilson6e1b8122012-05-30 00:17:12 +000086static cl::opt<std::string>
87PrintMachineInstrs("print-machineinstrs", cl::ValueOptional,
88 cl::desc("Print machine instrs"),
89 cl::value_desc("pass-name"), cl::init("option-unspecified"));
Andrew Trickd5422652012-02-04 02:56:48 +000090
Jakob Stoklund Olesendcc44362012-08-03 22:12:54 +000091// Experimental option to run live inteerval analysis early.
92static cl::opt<bool> EarlyLiveIntervals("early-live-intervals", cl::Hidden,
93 cl::desc("Run live interval analysis earlier in the pipeline"));
94
Andrew Trick79bf2882012-02-15 03:21:51 +000095/// Allow standard passes to be disabled by command line options. This supports
96/// simple binary flags that either suppress the pass or do nothing.
97/// i.e. -disable-mypass=false has no effect.
98/// These should be converted to boolOrDefault in order to use applyOverride.
Bob Wilson3fb99a72012-07-02 19:48:37 +000099static AnalysisID applyDisable(AnalysisID PassID, bool Override) {
Andrew Trick79bf2882012-02-15 03:21:51 +0000100 if (Override)
Bob Wilson3fb99a72012-07-02 19:48:37 +0000101 return 0;
102 return PassID;
Andrew Trick79bf2882012-02-15 03:21:51 +0000103}
104
105/// Allow Pass selection to be overriden by command line options. This supports
106/// flags with ternary conditions. TargetID is passed through by default. The
107/// pass is suppressed when the option is false. When the option is true, the
108/// StandardID is selected if the target provides no default.
109static AnalysisID applyOverride(AnalysisID TargetID, cl::boolOrDefault Override,
110 AnalysisID StandardID) {
Andrew Trick746f24b2012-02-11 07:11:32 +0000111 switch (Override) {
112 case cl::BOU_UNSET:
Andrew Trick79bf2882012-02-15 03:21:51 +0000113 return TargetID;
Andrew Trick746f24b2012-02-11 07:11:32 +0000114 case cl::BOU_TRUE:
Bob Wilson3fb99a72012-07-02 19:48:37 +0000115 if (TargetID)
Andrew Trick79bf2882012-02-15 03:21:51 +0000116 return TargetID;
Bob Wilson3fb99a72012-07-02 19:48:37 +0000117 if (StandardID == 0)
Andrew Trick746f24b2012-02-11 07:11:32 +0000118 report_fatal_error("Target cannot enable pass");
Andrew Trick79bf2882012-02-15 03:21:51 +0000119 return StandardID;
Andrew Trick746f24b2012-02-11 07:11:32 +0000120 case cl::BOU_FALSE:
Bob Wilson3fb99a72012-07-02 19:48:37 +0000121 return 0;
Andrew Trick746f24b2012-02-11 07:11:32 +0000122 }
123 llvm_unreachable("Invalid command line option state");
124}
125
Andrew Trick79bf2882012-02-15 03:21:51 +0000126/// Allow standard passes to be disabled by the command line, regardless of who
127/// is adding the pass.
128///
129/// StandardID is the pass identified in the standard pass pipeline and provided
130/// to addPass(). It may be a target-specific ID in the case that the target
131/// directly adds its own pass, but in that case we harmlessly fall through.
132///
133/// TargetID is the pass that the target has configured to override StandardID.
134///
135/// StandardID may be a pseudo ID. In that case TargetID is the name of the real
136/// pass to run. This allows multiple options to control a single pass depending
137/// on where in the pipeline that pass is added.
138static AnalysisID overridePass(AnalysisID StandardID, AnalysisID TargetID) {
139 if (StandardID == &PostRASchedulerID)
140 return applyDisable(TargetID, DisablePostRA);
141
142 if (StandardID == &BranchFolderPassID)
143 return applyDisable(TargetID, DisableBranchFold);
144
145 if (StandardID == &TailDuplicateID)
146 return applyDisable(TargetID, DisableTailDuplicate);
147
148 if (StandardID == &TargetPassConfig::EarlyTailDuplicateID)
149 return applyDisable(TargetID, DisableEarlyTailDup);
150
151 if (StandardID == &MachineBlockPlacementID)
152 return applyDisable(TargetID, DisableCodePlace);
153
154 if (StandardID == &CodePlacementOptID)
155 return applyDisable(TargetID, DisableCodePlace);
156
157 if (StandardID == &StackSlotColoringID)
158 return applyDisable(TargetID, DisableSSC);
159
160 if (StandardID == &DeadMachineInstructionElimID)
161 return applyDisable(TargetID, DisableMachineDCE);
162
Jakob Stoklund Olesen33242fd2012-07-04 00:09:54 +0000163 if (StandardID == &EarlyIfConverterID)
Jakob Stoklund Olesen0d141f82012-10-03 00:51:32 +0000164 return applyDisable(TargetID, DisableEarlyIfConversion);
Jakob Stoklund Olesen33242fd2012-07-04 00:09:54 +0000165
Andrew Trick79bf2882012-02-15 03:21:51 +0000166 if (StandardID == &MachineLICMID)
167 return applyDisable(TargetID, DisableMachineLICM);
168
169 if (StandardID == &MachineCSEID)
170 return applyDisable(TargetID, DisableMachineCSE);
171
172 if (StandardID == &MachineSchedulerID)
173 return applyOverride(TargetID, EnableMachineSched, StandardID);
174
175 if (StandardID == &TargetPassConfig::PostRAMachineLICMID)
176 return applyDisable(TargetID, DisablePostRAMachineLICM);
177
178 if (StandardID == &MachineSinkingID)
179 return applyDisable(TargetID, DisableMachineSink);
180
181 if (StandardID == &MachineCopyPropagationID)
182 return applyDisable(TargetID, DisableCopyProp);
183
184 return TargetID;
185}
186
Jim Laskeyeb577ba2006-08-02 12:30:23 +0000187//===---------------------------------------------------------------------===//
Andrew Trick74613342012-02-04 02:56:45 +0000188/// TargetPassConfig
189//===---------------------------------------------------------------------===//
190
191INITIALIZE_PASS(TargetPassConfig, "targetpassconfig",
192 "Target Pass Configuration", false, false)
193char TargetPassConfig::ID = 0;
194
Andrew Trick79bf2882012-02-15 03:21:51 +0000195// Pseudo Pass IDs.
196char TargetPassConfig::EarlyTailDuplicateID = 0;
197char TargetPassConfig::PostRAMachineLICMID = 0;
198
Andrew Trick5e108ee2012-02-15 03:21:47 +0000199namespace llvm {
200class PassConfigImpl {
201public:
202 // List of passes explicitly substituted by this target. Normally this is
203 // empty, but it is a convenient way to suppress or replace specific passes
204 // that are part of a standard pass pipeline without overridding the entire
205 // pipeline. This mechanism allows target options to inherit a standard pass's
206 // user interface. For example, a target may disable a standard pass by
Bob Wilson3fb99a72012-07-02 19:48:37 +0000207 // default by substituting a pass ID of zero, and the user may still enable
208 // that standard pass with an explicit command line option.
Andrew Trick5e108ee2012-02-15 03:21:47 +0000209 DenseMap<AnalysisID,AnalysisID> TargetPasses;
Bob Wilson6e1b8122012-05-30 00:17:12 +0000210
211 /// Store the pairs of <AnalysisID, AnalysisID> of which the second pass
212 /// is inserted after each instance of the first one.
213 SmallVector<std::pair<AnalysisID, AnalysisID>, 4> InsertedPasses;
Andrew Trick5e108ee2012-02-15 03:21:47 +0000214};
215} // namespace llvm
216
Andrew Trick74613342012-02-04 02:56:45 +0000217// Out of line virtual method.
Andrew Trick5e108ee2012-02-15 03:21:47 +0000218TargetPassConfig::~TargetPassConfig() {
219 delete Impl;
220}
Andrew Trick74613342012-02-04 02:56:45 +0000221
Andrew Trick61f1e3d2012-02-08 21:22:48 +0000222// Out of line constructor provides default values for pass options and
223// registers all common codegen passes.
Andrew Trick061efcf2012-02-04 02:56:59 +0000224TargetPassConfig::TargetPassConfig(TargetMachine *tm, PassManagerBase &pm)
Bob Wilson30a507a2012-07-02 19:48:45 +0000225 : ImmutablePass(ID), PM(&pm), StartAfter(0), StopAfter(0),
226 Started(true), Stopped(false), TM(tm), Impl(0), Initialized(false),
Andrew Trickffea03f2012-02-08 21:22:39 +0000227 DisableVerify(false),
228 EnableTailMerge(true) {
229
Andrew Trick5e108ee2012-02-15 03:21:47 +0000230 Impl = new PassConfigImpl();
231
Andrew Trick74613342012-02-04 02:56:45 +0000232 // Register all target independent codegen passes to activate their PassIDs,
233 // including this pass itself.
234 initializeCodeGen(*PassRegistry::getPassRegistry());
Andrew Trick79bf2882012-02-15 03:21:51 +0000235
236 // Substitute Pseudo Pass IDs for real ones.
Bob Wilson3fb99a72012-07-02 19:48:37 +0000237 substitutePass(&EarlyTailDuplicateID, &TailDuplicateID);
238 substitutePass(&PostRAMachineLICMID, &MachineLICMID);
Andrew Trick79bf2882012-02-15 03:21:51 +0000239
Jakob Stoklund Olesen33242fd2012-07-04 00:09:54 +0000240 // Disable early if-conversion. Targets that are ready can enable it.
241 disablePass(&EarlyIfConverterID);
242
Andrew Trick79bf2882012-02-15 03:21:51 +0000243 // Temporarily disable experimental passes.
Bob Wilson3fb99a72012-07-02 19:48:37 +0000244 substitutePass(&MachineSchedulerID, 0);
Andrew Trick74613342012-02-04 02:56:45 +0000245}
246
Bob Wilson6e1b8122012-05-30 00:17:12 +0000247/// Insert InsertedPassID pass after TargetPassID.
Bob Wilson3fb99a72012-07-02 19:48:37 +0000248void TargetPassConfig::insertPass(AnalysisID TargetPassID,
249 AnalysisID InsertedPassID) {
250 assert(TargetPassID != InsertedPassID && "Insert a pass after itself!");
251 std::pair<AnalysisID, AnalysisID> P(TargetPassID, InsertedPassID);
Bob Wilson6e1b8122012-05-30 00:17:12 +0000252 Impl->InsertedPasses.push_back(P);
253}
254
Andrew Trick74613342012-02-04 02:56:45 +0000255/// createPassConfig - Create a pass configuration object to be used by
256/// addPassToEmitX methods for generating a pipeline of CodeGen passes.
257///
258/// Targets may override this to extend TargetPassConfig.
Andrew Trick061efcf2012-02-04 02:56:59 +0000259TargetPassConfig *LLVMTargetMachine::createPassConfig(PassManagerBase &PM) {
260 return new TargetPassConfig(this, PM);
Andrew Trick74613342012-02-04 02:56:45 +0000261}
262
263TargetPassConfig::TargetPassConfig()
Bill Wendling7c4ce302012-05-01 08:27:43 +0000264 : ImmutablePass(ID), PM(0) {
Andrew Trick74613342012-02-04 02:56:45 +0000265 llvm_unreachable("TargetPassConfig should not be constructed on-the-fly");
266}
267
Andrew Trickffea03f2012-02-08 21:22:39 +0000268// Helper to verify the analysis is really immutable.
269void TargetPassConfig::setOpt(bool &Opt, bool Val) {
270 assert(!Initialized && "PassConfig is immutable");
271 Opt = Val;
272}
273
Bob Wilson3fb99a72012-07-02 19:48:37 +0000274void TargetPassConfig::substitutePass(AnalysisID StandardID,
275 AnalysisID TargetID) {
276 Impl->TargetPasses[StandardID] = TargetID;
Andrew Trick5e108ee2012-02-15 03:21:47 +0000277}
Andrew Trick746f24b2012-02-11 07:11:32 +0000278
Andrew Trick5e108ee2012-02-15 03:21:47 +0000279AnalysisID TargetPassConfig::getPassSubstitution(AnalysisID ID) const {
280 DenseMap<AnalysisID, AnalysisID>::const_iterator
281 I = Impl->TargetPasses.find(ID);
282 if (I == Impl->TargetPasses.end())
283 return ID;
284 return I->second;
285}
286
Bob Wilson30a507a2012-07-02 19:48:45 +0000287/// Add a pass to the PassManager if that pass is supposed to be run. If the
288/// Started/Stopped flags indicate either that the compilation should start at
289/// a later pass or that it should stop after an earlier pass, then do not add
290/// the pass. Finally, compare the current pass against the StartAfter
291/// and StopAfter options and change the Started/Stopped flags accordingly.
Bob Wilson564fbf62012-07-02 19:48:31 +0000292void TargetPassConfig::addPass(Pass *P) {
Bob Wilson6b2bb152012-07-02 19:48:39 +0000293 assert(!Initialized && "PassConfig is immutable");
294
Chandler Carruth6068c482012-07-02 22:56:41 +0000295 // Cache the Pass ID here in case the pass manager finds this pass is
296 // redundant with ones already scheduled / available, and deletes it.
297 // Fundamentally, once we add the pass to the manager, we no longer own it
298 // and shouldn't reference it.
299 AnalysisID PassID = P->getPassID();
300
Bob Wilson30a507a2012-07-02 19:48:45 +0000301 if (Started && !Stopped)
302 PM->add(P);
Chandler Carruth6068c482012-07-02 22:56:41 +0000303 if (StopAfter == PassID)
Bob Wilson30a507a2012-07-02 19:48:45 +0000304 Stopped = true;
Chandler Carruth6068c482012-07-02 22:56:41 +0000305 if (StartAfter == PassID)
Bob Wilson30a507a2012-07-02 19:48:45 +0000306 Started = true;
307 if (Stopped && !Started)
308 report_fatal_error("Cannot stop compilation after pass that is not run");
Bob Wilson564fbf62012-07-02 19:48:31 +0000309}
310
Andrew Trick5e108ee2012-02-15 03:21:47 +0000311/// Add a CodeGen pass at this point in the pipeline after checking for target
312/// and command line overrides.
Bob Wilson3fb99a72012-07-02 19:48:37 +0000313AnalysisID TargetPassConfig::addPass(AnalysisID PassID) {
Bob Wilson3fb99a72012-07-02 19:48:37 +0000314 AnalysisID TargetID = getPassSubstitution(PassID);
315 AnalysisID FinalID = overridePass(PassID, TargetID);
316 if (FinalID == 0)
Andrew Trick5e108ee2012-02-15 03:21:47 +0000317 return FinalID;
318
319 Pass *P = Pass::createPass(FinalID);
Andrew Trickebe18ef2012-02-08 21:22:34 +0000320 if (!P)
321 llvm_unreachable("Pass ID not registered");
Bob Wilson564fbf62012-07-02 19:48:31 +0000322 addPass(P);
Bob Wilson6e1b8122012-05-30 00:17:12 +0000323 // Add the passes after the pass P if there is any.
324 for (SmallVector<std::pair<AnalysisID, AnalysisID>, 4>::iterator
325 I = Impl->InsertedPasses.begin(), E = Impl->InsertedPasses.end();
326 I != E; ++I) {
Bob Wilson3fb99a72012-07-02 19:48:37 +0000327 if ((*I).first == PassID) {
Bob Wilson6e1b8122012-05-30 00:17:12 +0000328 assert((*I).second && "Illegal Pass ID!");
329 Pass *NP = Pass::createPass((*I).second);
330 assert(NP && "Pass ID not registered");
Bob Wilson564fbf62012-07-02 19:48:31 +0000331 addPass(NP);
Bob Wilson6e1b8122012-05-30 00:17:12 +0000332 }
333 }
Andrew Trick5e108ee2012-02-15 03:21:47 +0000334 return FinalID;
Andrew Trick061efcf2012-02-04 02:56:59 +0000335}
Andrew Trickd5422652012-02-04 02:56:48 +0000336
Bob Wilson564fbf62012-07-02 19:48:31 +0000337void TargetPassConfig::printAndVerify(const char *Banner) {
Andrew Trickd5422652012-02-04 02:56:48 +0000338 if (TM->shouldPrintMachineCode())
Bob Wilson564fbf62012-07-02 19:48:31 +0000339 addPass(createMachineFunctionPrinterPass(dbgs(), Banner));
Andrew Trickd5422652012-02-04 02:56:48 +0000340
341 if (VerifyMachineCode)
Bob Wilson564fbf62012-07-02 19:48:31 +0000342 addPass(createMachineVerifierPass(Banner));
Andrew Trickd5422652012-02-04 02:56:48 +0000343}
344
Andrew Trick061efcf2012-02-04 02:56:59 +0000345/// Add common target configurable passes that perform LLVM IR to IR transforms
346/// following machine independent optimization.
347void TargetPassConfig::addIRPasses() {
Andrew Trickd5422652012-02-04 02:56:48 +0000348 // Basic AliasAnalysis support.
349 // Add TypeBasedAliasAnalysis before BasicAliasAnalysis so that
350 // BasicAliasAnalysis wins if they disagree. This is intended to help
351 // support "obvious" type-punning idioms.
Bob Wilson564fbf62012-07-02 19:48:31 +0000352 addPass(createTypeBasedAliasAnalysisPass());
353 addPass(createBasicAliasAnalysisPass());
Andrew Trickd5422652012-02-04 02:56:48 +0000354
355 // Before running any passes, run the verifier to determine if the input
356 // coming from the front-end and/or optimizer is valid.
357 if (!DisableVerify)
Bob Wilson564fbf62012-07-02 19:48:31 +0000358 addPass(createVerifierPass());
Andrew Trickd5422652012-02-04 02:56:48 +0000359
360 // Run loop strength reduction before anything else.
361 if (getOptLevel() != CodeGenOpt::None && !DisableLSR) {
Bob Wilson564fbf62012-07-02 19:48:31 +0000362 addPass(createLoopStrengthReducePass(getTargetLowering()));
Andrew Trickd5422652012-02-04 02:56:48 +0000363 if (PrintLSR)
Bob Wilson564fbf62012-07-02 19:48:31 +0000364 addPass(createPrintFunctionPass("\n\n*** Code after LSR ***\n", &dbgs()));
Andrew Trickd5422652012-02-04 02:56:48 +0000365 }
366
Bob Wilson564fbf62012-07-02 19:48:31 +0000367 addPass(createGCLoweringPass());
Andrew Trickd5422652012-02-04 02:56:48 +0000368
369 // Make sure that no unreachable blocks are instruction selected.
Bob Wilson564fbf62012-07-02 19:48:31 +0000370 addPass(createUnreachableBlockEliminationPass());
371}
372
373/// Turn exception handling constructs into something the code generators can
374/// handle.
375void TargetPassConfig::addPassesToHandleExceptions() {
376 switch (TM->getMCAsmInfo()->getExceptionHandlingType()) {
377 case ExceptionHandling::SjLj:
378 // SjLj piggy-backs on dwarf for this bit. The cleanups done apply to both
379 // Dwarf EH prepare needs to be run after SjLj prepare. Otherwise,
380 // catch info can get misplaced when a selector ends up more than one block
381 // removed from the parent invoke(s). This could happen when a landing
382 // pad is shared by multiple invokes and is also a target of a normal
383 // edge from elsewhere.
384 addPass(createSjLjEHPreparePass(TM->getTargetLowering()));
385 // FALLTHROUGH
386 case ExceptionHandling::DwarfCFI:
387 case ExceptionHandling::ARM:
388 case ExceptionHandling::Win64:
389 addPass(createDwarfEHPass(TM));
390 break;
391 case ExceptionHandling::None:
392 addPass(createLowerInvokePass(TM->getTargetLowering()));
393
394 // The lower invoke pass may create unreachable code. Remove it.
395 addPass(createUnreachableBlockEliminationPass());
396 break;
397 }
Andrew Trick061efcf2012-02-04 02:56:59 +0000398}
Andrew Trickd5422652012-02-04 02:56:48 +0000399
Andrew Trick061efcf2012-02-04 02:56:59 +0000400/// Add common passes that perform LLVM IR to IR transforms in preparation for
401/// instruction selection.
402void TargetPassConfig::addISelPrepare() {
Andrew Trickd5422652012-02-04 02:56:48 +0000403 if (getOptLevel() != CodeGenOpt::None && !DisableCGP)
Bob Wilson564fbf62012-07-02 19:48:31 +0000404 addPass(createCodeGenPreparePass(getTargetLowering()));
Andrew Trickd5422652012-02-04 02:56:48 +0000405
Bob Wilson564fbf62012-07-02 19:48:31 +0000406 addPass(createStackProtectorPass(getTargetLowering()));
Andrew Trickd5422652012-02-04 02:56:48 +0000407
408 addPreISel();
409
410 if (PrintISelInput)
Bob Wilson564fbf62012-07-02 19:48:31 +0000411 addPass(createPrintFunctionPass("\n\n"
Bill Wendling7c4ce302012-05-01 08:27:43 +0000412 "*** Final LLVM Code input to ISel ***\n",
413 &dbgs()));
Andrew Trickd5422652012-02-04 02:56:48 +0000414
415 // All passes which modify the LLVM IR are now complete; run the verifier
416 // to ensure that the IR is valid.
417 if (!DisableVerify)
Bob Wilson564fbf62012-07-02 19:48:31 +0000418 addPass(createVerifierPass());
Andrew Trick061efcf2012-02-04 02:56:59 +0000419}
Andrew Trickd5422652012-02-04 02:56:48 +0000420
Andrew Trickf7b96312012-02-09 00:40:55 +0000421/// Add the complete set of target-independent postISel code generator passes.
422///
423/// This can be read as the standard order of major LLVM CodeGen stages. Stages
424/// with nontrivial configuration or multiple passes are broken out below in
425/// add%Stage routines.
426///
427/// Any TargetPassConfig::addXX routine may be overriden by the Target. The
428/// addPre/Post methods with empty header implementations allow injecting
429/// target-specific fixups just before or after major stages. Additionally,
430/// targets have the flexibility to change pass order within a stage by
431/// overriding default implementation of add%Stage routines below. Each
432/// technique has maintainability tradeoffs because alternate pass orders are
433/// not well supported. addPre/Post works better if the target pass is easily
434/// tied to a common pass. But if it has subtle dependencies on multiple passes,
Andrew Trick06efdd22012-02-10 07:08:25 +0000435/// the target should override the stage instead.
Andrew Trickf7b96312012-02-09 00:40:55 +0000436///
437/// TODO: We could use a single addPre/Post(ID) hook to allow pass injection
438/// before/after any target-independent pass. But it's currently overkill.
Andrew Trick061efcf2012-02-04 02:56:59 +0000439void TargetPassConfig::addMachinePasses() {
Bob Wilson6e1b8122012-05-30 00:17:12 +0000440 // Insert a machine instr printer pass after the specified pass.
441 // If -print-machineinstrs specified, print machineinstrs after all passes.
442 if (StringRef(PrintMachineInstrs.getValue()).equals(""))
443 TM->Options.PrintMachineCode = true;
444 else if (!StringRef(PrintMachineInstrs.getValue())
445 .equals("option-unspecified")) {
446 const PassRegistry *PR = PassRegistry::getPassRegistry();
447 const PassInfo *TPI = PR->getPassInfo(PrintMachineInstrs.getValue());
448 const PassInfo *IPI = PR->getPassInfo(StringRef("print-machineinstrs"));
449 assert (TPI && IPI && "Pass ID not registered!");
Roman Divacky59324292012-09-05 22:26:57 +0000450 const char *TID = (const char *)(TPI->getTypeInfo());
451 const char *IID = (const char *)(IPI->getTypeInfo());
Bob Wilson3fb99a72012-07-02 19:48:37 +0000452 insertPass(TID, IID);
Bob Wilson6e1b8122012-05-30 00:17:12 +0000453 }
454
Jakob Stoklund Olesenf86c00f2012-07-04 19:28:27 +0000455 // Print the instruction selected machine code...
456 printAndVerify("After Instruction Selection");
457
Andrew Trickd5422652012-02-04 02:56:48 +0000458 // Expand pseudo-instructions emitted by ISel.
Jakob Stoklund Olesen228e3f52012-08-20 20:52:08 +0000459 if (addPass(&ExpandISelPseudosID))
460 printAndVerify("After ExpandISelPseudos");
Andrew Trickd5422652012-02-04 02:56:48 +0000461
Andrew Trickf7b96312012-02-09 00:40:55 +0000462 // Add passes that optimize machine instructions in SSA form.
Andrew Trickd5422652012-02-04 02:56:48 +0000463 if (getOptLevel() != CodeGenOpt::None) {
Andrew Trickf7b96312012-02-09 00:40:55 +0000464 addMachineSSAOptimization();
465 }
466 else {
467 // If the target requests it, assign local variables to stack slots relative
468 // to one another and simplify frame index references where possible.
Bob Wilson3fb99a72012-07-02 19:48:37 +0000469 addPass(&LocalStackSlotAllocationID);
Andrew Trickd5422652012-02-04 02:56:48 +0000470 }
471
472 // Run pre-ra passes.
473 if (addPreRegAlloc())
474 printAndVerify("After PreRegAlloc passes");
475
Andrew Trickf7b96312012-02-09 00:40:55 +0000476 // Run register allocation and passes that are tightly coupled with it,
477 // including phi elimination and scheduling.
Andrew Trick8dd26252012-02-10 04:10:36 +0000478 if (getOptimizeRegAlloc())
479 addOptimizedRegAlloc(createRegAllocPass(true));
480 else
481 addFastRegAlloc(createRegAllocPass(false));
Andrew Trickd5422652012-02-04 02:56:48 +0000482
483 // Run post-ra passes.
484 if (addPostRegAlloc())
485 printAndVerify("After PostRegAlloc passes");
486
487 // Insert prolog/epilog code. Eliminate abstract frame index references...
Bob Wilson3fb99a72012-07-02 19:48:37 +0000488 addPass(&PrologEpilogCodeInserterID);
Andrew Trickd5422652012-02-04 02:56:48 +0000489 printAndVerify("After PrologEpilogCodeInserter");
490
Andrew Trickf7b96312012-02-09 00:40:55 +0000491 /// Add passes that optimize machine instructions after register allocation.
492 if (getOptLevel() != CodeGenOpt::None)
493 addMachineLateOptimization();
Andrew Trickd5422652012-02-04 02:56:48 +0000494
495 // Expand pseudo instructions before second scheduling pass.
Bob Wilson3fb99a72012-07-02 19:48:37 +0000496 addPass(&ExpandPostRAPseudosID);
Jakob Stoklund Olesen2ef5bf62012-03-28 20:49:30 +0000497 printAndVerify("After ExpandPostRAPseudos");
Andrew Trickd5422652012-02-04 02:56:48 +0000498
499 // Run pre-sched2 passes.
500 if (addPreSched2())
Jakob Stoklund Olesen78811662012-03-28 23:31:15 +0000501 printAndVerify("After PreSched2 passes");
Andrew Trickd5422652012-02-04 02:56:48 +0000502
503 // Second pass scheduler.
Andrew Trick79bf2882012-02-15 03:21:51 +0000504 if (getOptLevel() != CodeGenOpt::None) {
Bob Wilson3fb99a72012-07-02 19:48:37 +0000505 addPass(&PostRASchedulerID);
Jakob Stoklund Olesen8b4c5022012-03-28 23:54:28 +0000506 printAndVerify("After PostRAScheduler");
Andrew Trickd5422652012-02-04 02:56:48 +0000507 }
508
Andrew Trickf7b96312012-02-09 00:40:55 +0000509 // GC
Bob Wilson3fb99a72012-07-02 19:48:37 +0000510 addPass(&GCMachineCodeAnalysisID);
Andrew Trickd5422652012-02-04 02:56:48 +0000511 if (PrintGCInfo)
Bob Wilson564fbf62012-07-02 19:48:31 +0000512 addPass(createGCInfoPrinter(dbgs()));
Andrew Trickd5422652012-02-04 02:56:48 +0000513
Andrew Trickf7b96312012-02-09 00:40:55 +0000514 // Basic block placement.
Andrew Trick79bf2882012-02-15 03:21:51 +0000515 if (getOptLevel() != CodeGenOpt::None)
Andrew Trickf7b96312012-02-09 00:40:55 +0000516 addBlockPlacement();
Andrew Trickd5422652012-02-04 02:56:48 +0000517
518 if (addPreEmitPass())
Jakob Stoklund Olesen8b4c5022012-03-28 23:54:28 +0000519 printAndVerify("After PreEmit passes");
Andrew Trickd5422652012-02-04 02:56:48 +0000520}
521
Andrew Trickf7b96312012-02-09 00:40:55 +0000522/// Add passes that optimize machine instructions in SSA form.
523void TargetPassConfig::addMachineSSAOptimization() {
524 // Pre-ra tail duplication.
Bob Wilson3fb99a72012-07-02 19:48:37 +0000525 if (addPass(&EarlyTailDuplicateID))
Andrew Trickf7b96312012-02-09 00:40:55 +0000526 printAndVerify("After Pre-RegAlloc TailDuplicate");
Andrew Trickf7b96312012-02-09 00:40:55 +0000527
528 // Optimize PHIs before DCE: removing dead PHI cycles may make more
529 // instructions dead.
Bob Wilson3fb99a72012-07-02 19:48:37 +0000530 addPass(&OptimizePHIsID);
Andrew Trickf7b96312012-02-09 00:40:55 +0000531
Nadav Rotemc05d3062012-09-06 09:17:37 +0000532 // This pass merges large allocas. StackSlotColoring is a different pass
533 // which merges spill slots.
534 addPass(&StackColoringID);
535
Andrew Trickf7b96312012-02-09 00:40:55 +0000536 // If the target requests it, assign local variables to stack slots relative
537 // to one another and simplify frame index references where possible.
Bob Wilson3fb99a72012-07-02 19:48:37 +0000538 addPass(&LocalStackSlotAllocationID);
Andrew Trickf7b96312012-02-09 00:40:55 +0000539
540 // With optimization, dead code should already be eliminated. However
541 // there is one known exception: lowered code for arguments that are only
542 // used by tail calls, where the tail calls reuse the incoming stack
543 // arguments directly (see t11 in test/CodeGen/X86/sibcall.ll).
Bob Wilson3fb99a72012-07-02 19:48:37 +0000544 addPass(&DeadMachineInstructionElimID);
Andrew Trickf7b96312012-02-09 00:40:55 +0000545 printAndVerify("After codegen DCE pass");
546
Jakob Stoklund Olesen33242fd2012-07-04 00:09:54 +0000547 addPass(&EarlyIfConverterID);
Bob Wilson3fb99a72012-07-02 19:48:37 +0000548 addPass(&MachineLICMID);
549 addPass(&MachineCSEID);
550 addPass(&MachineSinkingID);
Andrew Trickf7b96312012-02-09 00:40:55 +0000551 printAndVerify("After Machine LICM, CSE and Sinking passes");
552
Bob Wilson3fb99a72012-07-02 19:48:37 +0000553 addPass(&PeepholeOptimizerID);
Andrew Trickf7b96312012-02-09 00:40:55 +0000554 printAndVerify("After codegen peephole optimization pass");
555}
556
Andrew Trick74613342012-02-04 02:56:45 +0000557//===---------------------------------------------------------------------===//
Andrew Trickf7b96312012-02-09 00:40:55 +0000558/// Register Allocation Pass Configuration
Jim Laskeyeb577ba2006-08-02 12:30:23 +0000559//===---------------------------------------------------------------------===//
Andrew Trickf7b96312012-02-09 00:40:55 +0000560
Andrew Trick8dd26252012-02-10 04:10:36 +0000561bool TargetPassConfig::getOptimizeRegAlloc() const {
562 switch (OptimizeRegAlloc) {
563 case cl::BOU_UNSET: return getOptLevel() != CodeGenOpt::None;
564 case cl::BOU_TRUE: return true;
565 case cl::BOU_FALSE: return false;
566 }
567 llvm_unreachable("Invalid optimize-regalloc state");
568}
569
Andrew Trickf7b96312012-02-09 00:40:55 +0000570/// RegisterRegAlloc's global Registry tracks allocator registration.
Jim Laskeyeb577ba2006-08-02 12:30:23 +0000571MachinePassRegistry RegisterRegAlloc::Registry;
572
Andrew Trickf7b96312012-02-09 00:40:55 +0000573/// A dummy default pass factory indicates whether the register allocator is
574/// overridden on the command line.
Andrew Trick8dd26252012-02-10 04:10:36 +0000575static FunctionPass *useDefaultRegisterAllocator() { return 0; }
Jakob Stoklund Olesen700bfad2010-05-27 23:57:25 +0000576static RegisterRegAlloc
577defaultRegAlloc("default",
578 "pick register allocator based on -O option",
Andrew Trick8dd26252012-02-10 04:10:36 +0000579 useDefaultRegisterAllocator);
Jim Laskeyeb577ba2006-08-02 12:30:23 +0000580
Andrew Trickf7b96312012-02-09 00:40:55 +0000581/// -regalloc=... command line option.
Dan Gohman844731a2008-05-13 00:00:25 +0000582static cl::opt<RegisterRegAlloc::FunctionPassCtor, false,
583 RegisterPassParser<RegisterRegAlloc> >
584RegAlloc("regalloc",
Andrew Trick8dd26252012-02-10 04:10:36 +0000585 cl::init(&useDefaultRegisterAllocator),
Jakob Stoklund Olesen700bfad2010-05-27 23:57:25 +0000586 cl::desc("Register allocator to use"));
Alkis Evlogimenos7237ece2003-10-02 16:57:49 +0000587
Jim Laskeyeb577ba2006-08-02 12:30:23 +0000588
Andrew Trick8dd26252012-02-10 04:10:36 +0000589/// Instantiate the default register allocator pass for this target for either
590/// the optimized or unoptimized allocation path. This will be added to the pass
591/// manager by addFastRegAlloc in the unoptimized case or addOptimizedRegAlloc
592/// in the optimized case.
593///
594/// A target that uses the standard regalloc pass order for fast or optimized
595/// allocation may still override this for per-target regalloc
596/// selection. But -regalloc=... always takes precedence.
597FunctionPass *TargetPassConfig::createTargetRegisterAllocator(bool Optimized) {
598 if (Optimized)
599 return createGreedyRegisterAllocator();
600 else
601 return createFastRegisterAllocator();
602}
603
604/// Find and instantiate the register allocation pass requested by this target
605/// at the current optimization level. Different register allocators are
606/// defined as separate passes because they may require different analysis.
607///
608/// This helper ensures that the regalloc= option is always available,
609/// even for targets that override the default allocator.
610///
611/// FIXME: When MachinePassRegistry register pass IDs instead of function ptrs,
612/// this can be folded into addPass.
613FunctionPass *TargetPassConfig::createRegAllocPass(bool Optimized) {
Jim Laskey9ff542f2006-08-01 18:29:48 +0000614 RegisterRegAlloc::FunctionPassCtor Ctor = RegisterRegAlloc::getDefault();
Jakob Stoklund Olesen700bfad2010-05-27 23:57:25 +0000615
Andrew Trick8dd26252012-02-10 04:10:36 +0000616 // Initialize the global default.
Jim Laskey13ec7022006-08-01 14:21:23 +0000617 if (!Ctor) {
Jim Laskeyeb577ba2006-08-02 12:30:23 +0000618 Ctor = RegAlloc;
619 RegisterRegAlloc::setDefault(RegAlloc);
Jim Laskey13ec7022006-08-01 14:21:23 +0000620 }
Andrew Trick8dd26252012-02-10 04:10:36 +0000621 if (Ctor != useDefaultRegisterAllocator)
Jakob Stoklund Olesen700bfad2010-05-27 23:57:25 +0000622 return Ctor();
623
Andrew Trick8dd26252012-02-10 04:10:36 +0000624 // With no -regalloc= override, ask the target for a regalloc pass.
625 return createTargetRegisterAllocator(Optimized);
626}
627
628/// Add the minimum set of target-independent passes that are required for
629/// register allocation. No coalescing or scheduling.
630void TargetPassConfig::addFastRegAlloc(FunctionPass *RegAllocPass) {
Bob Wilson3fb99a72012-07-02 19:48:37 +0000631 addPass(&PHIEliminationID);
632 addPass(&TwoAddressInstructionPassID);
Andrew Trick8dd26252012-02-10 04:10:36 +0000633
Bob Wilson564fbf62012-07-02 19:48:31 +0000634 addPass(RegAllocPass);
Andrew Trick8dd26252012-02-10 04:10:36 +0000635 printAndVerify("After Register Allocation");
Jim Laskey33a0a6d2006-07-27 20:05:00 +0000636}
Andrew Trickf7b96312012-02-09 00:40:55 +0000637
638/// Add standard target-independent passes that are tightly coupled with
Andrew Trick8dd26252012-02-10 04:10:36 +0000639/// optimized register allocation, including coalescing, machine instruction
640/// scheduling, and register allocation itself.
641void TargetPassConfig::addOptimizedRegAlloc(FunctionPass *RegAllocPass) {
Bob Wilson3fb99a72012-07-02 19:48:37 +0000642 addPass(&ProcessImplicitDefsID);
Jakob Stoklund Olesen5984d2b2012-06-25 18:12:18 +0000643
Andrew Trick8dd26252012-02-10 04:10:36 +0000644 // LiveVariables currently requires pure SSA form.
645 //
646 // FIXME: Once TwoAddressInstruction pass no longer uses kill flags,
647 // LiveVariables can be removed completely, and LiveIntervals can be directly
648 // computed. (We still either need to regenerate kill flags after regalloc, or
649 // preferably fix the scavenger to not depend on them).
Bob Wilson3fb99a72012-07-02 19:48:37 +0000650 addPass(&LiveVariablesID);
Andrew Trick8dd26252012-02-10 04:10:36 +0000651
652 // Add passes that move from transformed SSA into conventional SSA. This is a
653 // "copy coalescing" problem.
654 //
655 if (!EnableStrongPHIElim) {
656 // Edge splitting is smarter with machine loop info.
Bob Wilson3fb99a72012-07-02 19:48:37 +0000657 addPass(&MachineLoopInfoID);
658 addPass(&PHIEliminationID);
Andrew Trick8dd26252012-02-10 04:10:36 +0000659 }
Jakob Stoklund Olesendcc44362012-08-03 22:12:54 +0000660
661 // Eventually, we want to run LiveIntervals before PHI elimination.
662 if (EarlyLiveIntervals)
663 addPass(&LiveIntervalsID);
664
Bob Wilson3fb99a72012-07-02 19:48:37 +0000665 addPass(&TwoAddressInstructionPassID);
Andrew Trick8dd26252012-02-10 04:10:36 +0000666
Andrew Trick8dd26252012-02-10 04:10:36 +0000667 if (EnableStrongPHIElim)
Bob Wilson3fb99a72012-07-02 19:48:37 +0000668 addPass(&StrongPHIEliminationID);
Andrew Trick8dd26252012-02-10 04:10:36 +0000669
Bob Wilson3fb99a72012-07-02 19:48:37 +0000670 addPass(&RegisterCoalescerID);
Andrew Trick8dd26252012-02-10 04:10:36 +0000671
672 // PreRA instruction scheduling.
Bob Wilson3fb99a72012-07-02 19:48:37 +0000673 if (addPass(&MachineSchedulerID))
Andrew Trick17d35e52012-03-14 04:00:41 +0000674 printAndVerify("After Machine Scheduling");
Andrew Trick8dd26252012-02-10 04:10:36 +0000675
676 // Add the selected register allocation pass.
Bob Wilson564fbf62012-07-02 19:48:31 +0000677 addPass(RegAllocPass);
Jakob Stoklund Olesen34f5a2b2012-06-26 17:09:29 +0000678 printAndVerify("After Register Allocation, before rewriter");
679
680 // Allow targets to change the register assignments before rewriting.
681 if (addPreRewrite())
682 printAndVerify("After pre-rewrite passes");
Andrew Trickf7b96312012-02-09 00:40:55 +0000683
Jakob Stoklund Olesen05ec7122012-06-08 23:44:45 +0000684 // Finally rewrite virtual registers.
Bob Wilson3fb99a72012-07-02 19:48:37 +0000685 addPass(&VirtRegRewriterID);
Jakob Stoklund Olesen05ec7122012-06-08 23:44:45 +0000686 printAndVerify("After Virtual Register Rewriter");
687
Andrew Trick746f24b2012-02-11 07:11:32 +0000688 // FinalizeRegAlloc is convenient until MachineInstrBundles is more mature,
689 // but eventually, all users of it should probably be moved to addPostRA and
690 // it can go away. Currently, it's the intended place for targets to run
691 // FinalizeMachineBundles, because passes other than MachineScheduling an
692 // RegAlloc itself may not be aware of bundles.
693 if (addFinalizeRegAlloc())
694 printAndVerify("After RegAlloc finalization");
695
Andrew Trickf7b96312012-02-09 00:40:55 +0000696 // Perform stack slot coloring and post-ra machine LICM.
Andrew Trick8dd26252012-02-10 04:10:36 +0000697 //
698 // FIXME: Re-enable coloring with register when it's capable of adding
699 // kill markers.
Bob Wilson3fb99a72012-07-02 19:48:37 +0000700 addPass(&StackSlotColoringID);
Andrew Trick900d7b72012-02-15 07:57:03 +0000701
702 // Run post-ra machine LICM to hoist reloads / remats.
703 //
704 // FIXME: can this move into MachineLateOptimization?
Bob Wilson3fb99a72012-07-02 19:48:37 +0000705 addPass(&PostRAMachineLICMID);
Andrew Trick900d7b72012-02-15 07:57:03 +0000706
707 printAndVerify("After StackSlotColoring and postra Machine LICM");
Andrew Trickf7b96312012-02-09 00:40:55 +0000708}
709
710//===---------------------------------------------------------------------===//
711/// Post RegAlloc Pass Configuration
712//===---------------------------------------------------------------------===//
713
714/// Add passes that optimize machine instructions after register allocation.
715void TargetPassConfig::addMachineLateOptimization() {
716 // Branch folding must be run after regalloc and prolog/epilog insertion.
Bob Wilson3fb99a72012-07-02 19:48:37 +0000717 if (addPass(&BranchFolderPassID))
Jakob Stoklund Olesen663ee202012-03-28 20:47:37 +0000718 printAndVerify("After BranchFolding");
Andrew Trickf7b96312012-02-09 00:40:55 +0000719
720 // Tail duplication.
Bob Wilson3fb99a72012-07-02 19:48:37 +0000721 if (addPass(&TailDuplicateID))
Jakob Stoklund Olesen663ee202012-03-28 20:47:37 +0000722 printAndVerify("After TailDuplicate");
Andrew Trickf7b96312012-02-09 00:40:55 +0000723
724 // Copy propagation.
Bob Wilson3fb99a72012-07-02 19:48:37 +0000725 if (addPass(&MachineCopyPropagationID))
Jakob Stoklund Olesen663ee202012-03-28 20:47:37 +0000726 printAndVerify("After copy propagation pass");
Andrew Trickf7b96312012-02-09 00:40:55 +0000727}
728
729/// Add standard basic block placement passes.
730void TargetPassConfig::addBlockPlacement() {
Bob Wilson3fb99a72012-07-02 19:48:37 +0000731 AnalysisID PassID = 0;
Chandler Carruth9e67db42012-04-16 13:49:17 +0000732 if (!DisableBlockPlacement) {
733 // MachineBlockPlacement is a new pass which subsumes the functionality of
734 // CodPlacementOpt. The old code placement pass can be restored by
735 // disabling block placement, but eventually it will be removed.
Bob Wilson3fb99a72012-07-02 19:48:37 +0000736 PassID = addPass(&MachineBlockPlacementID);
Andrew Trickf7b96312012-02-09 00:40:55 +0000737 } else {
Bob Wilson3fb99a72012-07-02 19:48:37 +0000738 PassID = addPass(&CodePlacementOptID);
Andrew Trickf7b96312012-02-09 00:40:55 +0000739 }
Bob Wilson3fb99a72012-07-02 19:48:37 +0000740 if (PassID) {
Andrew Trick79bf2882012-02-15 03:21:51 +0000741 // Run a separate pass to collect block placement statistics.
742 if (EnableBlockPlacementStats)
Bob Wilson3fb99a72012-07-02 19:48:37 +0000743 addPass(&MachineBlockPlacementStatsID);
Andrew Trickf7b96312012-02-09 00:40:55 +0000744
Jakob Stoklund Olesen8b4c5022012-03-28 23:54:28 +0000745 printAndVerify("After machine block placement.");
Andrew Trickf7b96312012-02-09 00:40:55 +0000746 }
747}