blob: 69d6d00091adb225b45be12d5f56e6c7e73fd558 [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 Olesen33242fd2012-07-04 00:09:54 +000052static cl::opt<bool> EnableEarlyIfConversion("enable-early-ifcvt", cl::Hidden,
53 cl::desc("Enable 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
Andrew Trick79bf2882012-02-15 03:21:51 +000091/// Allow standard passes to be disabled by command line options. This supports
92/// simple binary flags that either suppress the pass or do nothing.
93/// i.e. -disable-mypass=false has no effect.
94/// These should be converted to boolOrDefault in order to use applyOverride.
Bob Wilson3fb99a72012-07-02 19:48:37 +000095static AnalysisID applyDisable(AnalysisID PassID, bool Override) {
Andrew Trick79bf2882012-02-15 03:21:51 +000096 if (Override)
Bob Wilson3fb99a72012-07-02 19:48:37 +000097 return 0;
98 return PassID;
Andrew Trick79bf2882012-02-15 03:21:51 +000099}
100
101/// Allow Pass selection to be overriden by command line options. This supports
102/// flags with ternary conditions. TargetID is passed through by default. The
103/// pass is suppressed when the option is false. When the option is true, the
104/// StandardID is selected if the target provides no default.
105static AnalysisID applyOverride(AnalysisID TargetID, cl::boolOrDefault Override,
106 AnalysisID StandardID) {
Andrew Trick746f24b2012-02-11 07:11:32 +0000107 switch (Override) {
108 case cl::BOU_UNSET:
Andrew Trick79bf2882012-02-15 03:21:51 +0000109 return TargetID;
Andrew Trick746f24b2012-02-11 07:11:32 +0000110 case cl::BOU_TRUE:
Bob Wilson3fb99a72012-07-02 19:48:37 +0000111 if (TargetID)
Andrew Trick79bf2882012-02-15 03:21:51 +0000112 return TargetID;
Bob Wilson3fb99a72012-07-02 19:48:37 +0000113 if (StandardID == 0)
Andrew Trick746f24b2012-02-11 07:11:32 +0000114 report_fatal_error("Target cannot enable pass");
Andrew Trick79bf2882012-02-15 03:21:51 +0000115 return StandardID;
Andrew Trick746f24b2012-02-11 07:11:32 +0000116 case cl::BOU_FALSE:
Bob Wilson3fb99a72012-07-02 19:48:37 +0000117 return 0;
Andrew Trick746f24b2012-02-11 07:11:32 +0000118 }
119 llvm_unreachable("Invalid command line option state");
120}
121
Andrew Trick79bf2882012-02-15 03:21:51 +0000122/// Allow standard passes to be disabled by the command line, regardless of who
123/// is adding the pass.
124///
125/// StandardID is the pass identified in the standard pass pipeline and provided
126/// to addPass(). It may be a target-specific ID in the case that the target
127/// directly adds its own pass, but in that case we harmlessly fall through.
128///
129/// TargetID is the pass that the target has configured to override StandardID.
130///
131/// StandardID may be a pseudo ID. In that case TargetID is the name of the real
132/// pass to run. This allows multiple options to control a single pass depending
133/// on where in the pipeline that pass is added.
134static AnalysisID overridePass(AnalysisID StandardID, AnalysisID TargetID) {
135 if (StandardID == &PostRASchedulerID)
136 return applyDisable(TargetID, DisablePostRA);
137
138 if (StandardID == &BranchFolderPassID)
139 return applyDisable(TargetID, DisableBranchFold);
140
141 if (StandardID == &TailDuplicateID)
142 return applyDisable(TargetID, DisableTailDuplicate);
143
144 if (StandardID == &TargetPassConfig::EarlyTailDuplicateID)
145 return applyDisable(TargetID, DisableEarlyTailDup);
146
147 if (StandardID == &MachineBlockPlacementID)
148 return applyDisable(TargetID, DisableCodePlace);
149
150 if (StandardID == &CodePlacementOptID)
151 return applyDisable(TargetID, DisableCodePlace);
152
153 if (StandardID == &StackSlotColoringID)
154 return applyDisable(TargetID, DisableSSC);
155
156 if (StandardID == &DeadMachineInstructionElimID)
157 return applyDisable(TargetID, DisableMachineDCE);
158
Jakob Stoklund Olesen33242fd2012-07-04 00:09:54 +0000159 if (StandardID == &EarlyIfConverterID)
160 return applyDisable(TargetID, !EnableEarlyIfConversion);
161
Andrew Trick79bf2882012-02-15 03:21:51 +0000162 if (StandardID == &MachineLICMID)
163 return applyDisable(TargetID, DisableMachineLICM);
164
165 if (StandardID == &MachineCSEID)
166 return applyDisable(TargetID, DisableMachineCSE);
167
168 if (StandardID == &MachineSchedulerID)
169 return applyOverride(TargetID, EnableMachineSched, StandardID);
170
171 if (StandardID == &TargetPassConfig::PostRAMachineLICMID)
172 return applyDisable(TargetID, DisablePostRAMachineLICM);
173
174 if (StandardID == &MachineSinkingID)
175 return applyDisable(TargetID, DisableMachineSink);
176
177 if (StandardID == &MachineCopyPropagationID)
178 return applyDisable(TargetID, DisableCopyProp);
179
180 return TargetID;
181}
182
Jim Laskeyeb577ba2006-08-02 12:30:23 +0000183//===---------------------------------------------------------------------===//
Andrew Trick74613342012-02-04 02:56:45 +0000184/// TargetPassConfig
185//===---------------------------------------------------------------------===//
186
187INITIALIZE_PASS(TargetPassConfig, "targetpassconfig",
188 "Target Pass Configuration", false, false)
189char TargetPassConfig::ID = 0;
190
Andrew Trick79bf2882012-02-15 03:21:51 +0000191// Pseudo Pass IDs.
192char TargetPassConfig::EarlyTailDuplicateID = 0;
193char TargetPassConfig::PostRAMachineLICMID = 0;
194
Andrew Trick5e108ee2012-02-15 03:21:47 +0000195namespace llvm {
196class PassConfigImpl {
197public:
198 // List of passes explicitly substituted by this target. Normally this is
199 // empty, but it is a convenient way to suppress or replace specific passes
200 // that are part of a standard pass pipeline without overridding the entire
201 // pipeline. This mechanism allows target options to inherit a standard pass's
202 // user interface. For example, a target may disable a standard pass by
Bob Wilson3fb99a72012-07-02 19:48:37 +0000203 // default by substituting a pass ID of zero, and the user may still enable
204 // that standard pass with an explicit command line option.
Andrew Trick5e108ee2012-02-15 03:21:47 +0000205 DenseMap<AnalysisID,AnalysisID> TargetPasses;
Bob Wilson6e1b8122012-05-30 00:17:12 +0000206
207 /// Store the pairs of <AnalysisID, AnalysisID> of which the second pass
208 /// is inserted after each instance of the first one.
209 SmallVector<std::pair<AnalysisID, AnalysisID>, 4> InsertedPasses;
Andrew Trick5e108ee2012-02-15 03:21:47 +0000210};
211} // namespace llvm
212
Andrew Trick74613342012-02-04 02:56:45 +0000213// Out of line virtual method.
Andrew Trick5e108ee2012-02-15 03:21:47 +0000214TargetPassConfig::~TargetPassConfig() {
215 delete Impl;
216}
Andrew Trick74613342012-02-04 02:56:45 +0000217
Andrew Trick61f1e3d2012-02-08 21:22:48 +0000218// Out of line constructor provides default values for pass options and
219// registers all common codegen passes.
Andrew Trick061efcf2012-02-04 02:56:59 +0000220TargetPassConfig::TargetPassConfig(TargetMachine *tm, PassManagerBase &pm)
Bob Wilson30a507a2012-07-02 19:48:45 +0000221 : ImmutablePass(ID), PM(&pm), StartAfter(0), StopAfter(0),
222 Started(true), Stopped(false), TM(tm), Impl(0), Initialized(false),
Andrew Trickffea03f2012-02-08 21:22:39 +0000223 DisableVerify(false),
224 EnableTailMerge(true) {
225
Andrew Trick5e108ee2012-02-15 03:21:47 +0000226 Impl = new PassConfigImpl();
227
Andrew Trick74613342012-02-04 02:56:45 +0000228 // Register all target independent codegen passes to activate their PassIDs,
229 // including this pass itself.
230 initializeCodeGen(*PassRegistry::getPassRegistry());
Andrew Trick79bf2882012-02-15 03:21:51 +0000231
232 // Substitute Pseudo Pass IDs for real ones.
Bob Wilson3fb99a72012-07-02 19:48:37 +0000233 substitutePass(&EarlyTailDuplicateID, &TailDuplicateID);
234 substitutePass(&PostRAMachineLICMID, &MachineLICMID);
Andrew Trick79bf2882012-02-15 03:21:51 +0000235
Jakob Stoklund Olesen33242fd2012-07-04 00:09:54 +0000236 // Disable early if-conversion. Targets that are ready can enable it.
237 disablePass(&EarlyIfConverterID);
238
Andrew Trick79bf2882012-02-15 03:21:51 +0000239 // Temporarily disable experimental passes.
Bob Wilson3fb99a72012-07-02 19:48:37 +0000240 substitutePass(&MachineSchedulerID, 0);
Andrew Trick74613342012-02-04 02:56:45 +0000241}
242
Bob Wilson6e1b8122012-05-30 00:17:12 +0000243/// Insert InsertedPassID pass after TargetPassID.
Bob Wilson3fb99a72012-07-02 19:48:37 +0000244void TargetPassConfig::insertPass(AnalysisID TargetPassID,
245 AnalysisID InsertedPassID) {
246 assert(TargetPassID != InsertedPassID && "Insert a pass after itself!");
247 std::pair<AnalysisID, AnalysisID> P(TargetPassID, InsertedPassID);
Bob Wilson6e1b8122012-05-30 00:17:12 +0000248 Impl->InsertedPasses.push_back(P);
249}
250
Andrew Trick74613342012-02-04 02:56:45 +0000251/// createPassConfig - Create a pass configuration object to be used by
252/// addPassToEmitX methods for generating a pipeline of CodeGen passes.
253///
254/// Targets may override this to extend TargetPassConfig.
Andrew Trick061efcf2012-02-04 02:56:59 +0000255TargetPassConfig *LLVMTargetMachine::createPassConfig(PassManagerBase &PM) {
256 return new TargetPassConfig(this, PM);
Andrew Trick74613342012-02-04 02:56:45 +0000257}
258
259TargetPassConfig::TargetPassConfig()
Bill Wendling7c4ce302012-05-01 08:27:43 +0000260 : ImmutablePass(ID), PM(0) {
Andrew Trick74613342012-02-04 02:56:45 +0000261 llvm_unreachable("TargetPassConfig should not be constructed on-the-fly");
262}
263
Andrew Trickffea03f2012-02-08 21:22:39 +0000264// Helper to verify the analysis is really immutable.
265void TargetPassConfig::setOpt(bool &Opt, bool Val) {
266 assert(!Initialized && "PassConfig is immutable");
267 Opt = Val;
268}
269
Bob Wilson3fb99a72012-07-02 19:48:37 +0000270void TargetPassConfig::substitutePass(AnalysisID StandardID,
271 AnalysisID TargetID) {
272 Impl->TargetPasses[StandardID] = TargetID;
Andrew Trick5e108ee2012-02-15 03:21:47 +0000273}
Andrew Trick746f24b2012-02-11 07:11:32 +0000274
Andrew Trick5e108ee2012-02-15 03:21:47 +0000275AnalysisID TargetPassConfig::getPassSubstitution(AnalysisID ID) const {
276 DenseMap<AnalysisID, AnalysisID>::const_iterator
277 I = Impl->TargetPasses.find(ID);
278 if (I == Impl->TargetPasses.end())
279 return ID;
280 return I->second;
281}
282
Bob Wilson30a507a2012-07-02 19:48:45 +0000283/// Add a pass to the PassManager if that pass is supposed to be run. If the
284/// Started/Stopped flags indicate either that the compilation should start at
285/// a later pass or that it should stop after an earlier pass, then do not add
286/// the pass. Finally, compare the current pass against the StartAfter
287/// and StopAfter options and change the Started/Stopped flags accordingly.
Bob Wilson564fbf62012-07-02 19:48:31 +0000288void TargetPassConfig::addPass(Pass *P) {
Bob Wilson6b2bb152012-07-02 19:48:39 +0000289 assert(!Initialized && "PassConfig is immutable");
290
Chandler Carruth6068c482012-07-02 22:56:41 +0000291 // Cache the Pass ID here in case the pass manager finds this pass is
292 // redundant with ones already scheduled / available, and deletes it.
293 // Fundamentally, once we add the pass to the manager, we no longer own it
294 // and shouldn't reference it.
295 AnalysisID PassID = P->getPassID();
296
Bob Wilson30a507a2012-07-02 19:48:45 +0000297 if (Started && !Stopped)
298 PM->add(P);
Chandler Carruth6068c482012-07-02 22:56:41 +0000299 if (StopAfter == PassID)
Bob Wilson30a507a2012-07-02 19:48:45 +0000300 Stopped = true;
Chandler Carruth6068c482012-07-02 22:56:41 +0000301 if (StartAfter == PassID)
Bob Wilson30a507a2012-07-02 19:48:45 +0000302 Started = true;
303 if (Stopped && !Started)
304 report_fatal_error("Cannot stop compilation after pass that is not run");
Bob Wilson564fbf62012-07-02 19:48:31 +0000305}
306
Andrew Trick5e108ee2012-02-15 03:21:47 +0000307/// Add a CodeGen pass at this point in the pipeline after checking for target
308/// and command line overrides.
Bob Wilson3fb99a72012-07-02 19:48:37 +0000309AnalysisID TargetPassConfig::addPass(AnalysisID PassID) {
Bob Wilson3fb99a72012-07-02 19:48:37 +0000310 AnalysisID TargetID = getPassSubstitution(PassID);
311 AnalysisID FinalID = overridePass(PassID, TargetID);
312 if (FinalID == 0)
Andrew Trick5e108ee2012-02-15 03:21:47 +0000313 return FinalID;
314
315 Pass *P = Pass::createPass(FinalID);
Andrew Trickebe18ef2012-02-08 21:22:34 +0000316 if (!P)
317 llvm_unreachable("Pass ID not registered");
Bob Wilson564fbf62012-07-02 19:48:31 +0000318 addPass(P);
Bob Wilson6e1b8122012-05-30 00:17:12 +0000319 // Add the passes after the pass P if there is any.
320 for (SmallVector<std::pair<AnalysisID, AnalysisID>, 4>::iterator
321 I = Impl->InsertedPasses.begin(), E = Impl->InsertedPasses.end();
322 I != E; ++I) {
Bob Wilson3fb99a72012-07-02 19:48:37 +0000323 if ((*I).first == PassID) {
Bob Wilson6e1b8122012-05-30 00:17:12 +0000324 assert((*I).second && "Illegal Pass ID!");
325 Pass *NP = Pass::createPass((*I).second);
326 assert(NP && "Pass ID not registered");
Bob Wilson564fbf62012-07-02 19:48:31 +0000327 addPass(NP);
Bob Wilson6e1b8122012-05-30 00:17:12 +0000328 }
329 }
Andrew Trick5e108ee2012-02-15 03:21:47 +0000330 return FinalID;
Andrew Trick061efcf2012-02-04 02:56:59 +0000331}
Andrew Trickd5422652012-02-04 02:56:48 +0000332
Bob Wilson564fbf62012-07-02 19:48:31 +0000333void TargetPassConfig::printAndVerify(const char *Banner) {
Andrew Trickd5422652012-02-04 02:56:48 +0000334 if (TM->shouldPrintMachineCode())
Bob Wilson564fbf62012-07-02 19:48:31 +0000335 addPass(createMachineFunctionPrinterPass(dbgs(), Banner));
Andrew Trickd5422652012-02-04 02:56:48 +0000336
337 if (VerifyMachineCode)
Bob Wilson564fbf62012-07-02 19:48:31 +0000338 addPass(createMachineVerifierPass(Banner));
Andrew Trickd5422652012-02-04 02:56:48 +0000339}
340
Andrew Trick061efcf2012-02-04 02:56:59 +0000341/// Add common target configurable passes that perform LLVM IR to IR transforms
342/// following machine independent optimization.
343void TargetPassConfig::addIRPasses() {
Andrew Trickd5422652012-02-04 02:56:48 +0000344 // Basic AliasAnalysis support.
345 // Add TypeBasedAliasAnalysis before BasicAliasAnalysis so that
346 // BasicAliasAnalysis wins if they disagree. This is intended to help
347 // support "obvious" type-punning idioms.
Bob Wilson564fbf62012-07-02 19:48:31 +0000348 addPass(createTypeBasedAliasAnalysisPass());
349 addPass(createBasicAliasAnalysisPass());
Andrew Trickd5422652012-02-04 02:56:48 +0000350
351 // Before running any passes, run the verifier to determine if the input
352 // coming from the front-end and/or optimizer is valid.
353 if (!DisableVerify)
Bob Wilson564fbf62012-07-02 19:48:31 +0000354 addPass(createVerifierPass());
Andrew Trickd5422652012-02-04 02:56:48 +0000355
356 // Run loop strength reduction before anything else.
357 if (getOptLevel() != CodeGenOpt::None && !DisableLSR) {
Bob Wilson564fbf62012-07-02 19:48:31 +0000358 addPass(createLoopStrengthReducePass(getTargetLowering()));
Andrew Trickd5422652012-02-04 02:56:48 +0000359 if (PrintLSR)
Bob Wilson564fbf62012-07-02 19:48:31 +0000360 addPass(createPrintFunctionPass("\n\n*** Code after LSR ***\n", &dbgs()));
Andrew Trickd5422652012-02-04 02:56:48 +0000361 }
362
Bob Wilson564fbf62012-07-02 19:48:31 +0000363 addPass(createGCLoweringPass());
Andrew Trickd5422652012-02-04 02:56:48 +0000364
365 // Make sure that no unreachable blocks are instruction selected.
Bob Wilson564fbf62012-07-02 19:48:31 +0000366 addPass(createUnreachableBlockEliminationPass());
367}
368
369/// Turn exception handling constructs into something the code generators can
370/// handle.
371void TargetPassConfig::addPassesToHandleExceptions() {
372 switch (TM->getMCAsmInfo()->getExceptionHandlingType()) {
373 case ExceptionHandling::SjLj:
374 // SjLj piggy-backs on dwarf for this bit. The cleanups done apply to both
375 // Dwarf EH prepare needs to be run after SjLj prepare. Otherwise,
376 // catch info can get misplaced when a selector ends up more than one block
377 // removed from the parent invoke(s). This could happen when a landing
378 // pad is shared by multiple invokes and is also a target of a normal
379 // edge from elsewhere.
380 addPass(createSjLjEHPreparePass(TM->getTargetLowering()));
381 // FALLTHROUGH
382 case ExceptionHandling::DwarfCFI:
383 case ExceptionHandling::ARM:
384 case ExceptionHandling::Win64:
385 addPass(createDwarfEHPass(TM));
386 break;
387 case ExceptionHandling::None:
388 addPass(createLowerInvokePass(TM->getTargetLowering()));
389
390 // The lower invoke pass may create unreachable code. Remove it.
391 addPass(createUnreachableBlockEliminationPass());
392 break;
393 }
Andrew Trick061efcf2012-02-04 02:56:59 +0000394}
Andrew Trickd5422652012-02-04 02:56:48 +0000395
Andrew Trick061efcf2012-02-04 02:56:59 +0000396/// Add common passes that perform LLVM IR to IR transforms in preparation for
397/// instruction selection.
398void TargetPassConfig::addISelPrepare() {
Andrew Trickd5422652012-02-04 02:56:48 +0000399 if (getOptLevel() != CodeGenOpt::None && !DisableCGP)
Bob Wilson564fbf62012-07-02 19:48:31 +0000400 addPass(createCodeGenPreparePass(getTargetLowering()));
Andrew Trickd5422652012-02-04 02:56:48 +0000401
Bob Wilson564fbf62012-07-02 19:48:31 +0000402 addPass(createStackProtectorPass(getTargetLowering()));
Andrew Trickd5422652012-02-04 02:56:48 +0000403
404 addPreISel();
405
406 if (PrintISelInput)
Bob Wilson564fbf62012-07-02 19:48:31 +0000407 addPass(createPrintFunctionPass("\n\n"
Bill Wendling7c4ce302012-05-01 08:27:43 +0000408 "*** Final LLVM Code input to ISel ***\n",
409 &dbgs()));
Andrew Trickd5422652012-02-04 02:56:48 +0000410
411 // All passes which modify the LLVM IR are now complete; run the verifier
412 // to ensure that the IR is valid.
413 if (!DisableVerify)
Bob Wilson564fbf62012-07-02 19:48:31 +0000414 addPass(createVerifierPass());
Andrew Trick061efcf2012-02-04 02:56:59 +0000415}
Andrew Trickd5422652012-02-04 02:56:48 +0000416
Andrew Trickf7b96312012-02-09 00:40:55 +0000417/// Add the complete set of target-independent postISel code generator passes.
418///
419/// This can be read as the standard order of major LLVM CodeGen stages. Stages
420/// with nontrivial configuration or multiple passes are broken out below in
421/// add%Stage routines.
422///
423/// Any TargetPassConfig::addXX routine may be overriden by the Target. The
424/// addPre/Post methods with empty header implementations allow injecting
425/// target-specific fixups just before or after major stages. Additionally,
426/// targets have the flexibility to change pass order within a stage by
427/// overriding default implementation of add%Stage routines below. Each
428/// technique has maintainability tradeoffs because alternate pass orders are
429/// not well supported. addPre/Post works better if the target pass is easily
430/// tied to a common pass. But if it has subtle dependencies on multiple passes,
Andrew Trick06efdd22012-02-10 07:08:25 +0000431/// the target should override the stage instead.
Andrew Trickf7b96312012-02-09 00:40:55 +0000432///
433/// TODO: We could use a single addPre/Post(ID) hook to allow pass injection
434/// before/after any target-independent pass. But it's currently overkill.
Andrew Trick061efcf2012-02-04 02:56:59 +0000435void TargetPassConfig::addMachinePasses() {
Bob Wilson6e1b8122012-05-30 00:17:12 +0000436 // Insert a machine instr printer pass after the specified pass.
437 // If -print-machineinstrs specified, print machineinstrs after all passes.
438 if (StringRef(PrintMachineInstrs.getValue()).equals(""))
439 TM->Options.PrintMachineCode = true;
440 else if (!StringRef(PrintMachineInstrs.getValue())
441 .equals("option-unspecified")) {
442 const PassRegistry *PR = PassRegistry::getPassRegistry();
443 const PassInfo *TPI = PR->getPassInfo(PrintMachineInstrs.getValue());
444 const PassInfo *IPI = PR->getPassInfo(StringRef("print-machineinstrs"));
445 assert (TPI && IPI && "Pass ID not registered!");
446 const char *TID = (char *)(TPI->getTypeInfo());
447 const char *IID = (char *)(IPI->getTypeInfo());
Bob Wilson3fb99a72012-07-02 19:48:37 +0000448 insertPass(TID, IID);
Bob Wilson6e1b8122012-05-30 00:17:12 +0000449 }
450
Jakob Stoklund Olesenf86c00f2012-07-04 19:28:27 +0000451 // Print the instruction selected machine code...
452 printAndVerify("After Instruction Selection");
453
Andrew Trickd5422652012-02-04 02:56:48 +0000454 // Expand pseudo-instructions emitted by ISel.
Bob Wilson3fb99a72012-07-02 19:48:37 +0000455 addPass(&ExpandISelPseudosID);
Andrew Trickd5422652012-02-04 02:56:48 +0000456
Andrew Trickf7b96312012-02-09 00:40:55 +0000457 // Add passes that optimize machine instructions in SSA form.
Andrew Trickd5422652012-02-04 02:56:48 +0000458 if (getOptLevel() != CodeGenOpt::None) {
Andrew Trickf7b96312012-02-09 00:40:55 +0000459 addMachineSSAOptimization();
460 }
461 else {
462 // If the target requests it, assign local variables to stack slots relative
463 // to one another and simplify frame index references where possible.
Bob Wilson3fb99a72012-07-02 19:48:37 +0000464 addPass(&LocalStackSlotAllocationID);
Andrew Trickd5422652012-02-04 02:56:48 +0000465 }
466
467 // Run pre-ra passes.
468 if (addPreRegAlloc())
469 printAndVerify("After PreRegAlloc passes");
470
Andrew Trickf7b96312012-02-09 00:40:55 +0000471 // Run register allocation and passes that are tightly coupled with it,
472 // including phi elimination and scheduling.
Andrew Trick8dd26252012-02-10 04:10:36 +0000473 if (getOptimizeRegAlloc())
474 addOptimizedRegAlloc(createRegAllocPass(true));
475 else
476 addFastRegAlloc(createRegAllocPass(false));
Andrew Trickd5422652012-02-04 02:56:48 +0000477
478 // Run post-ra passes.
479 if (addPostRegAlloc())
480 printAndVerify("After PostRegAlloc passes");
481
482 // Insert prolog/epilog code. Eliminate abstract frame index references...
Bob Wilson3fb99a72012-07-02 19:48:37 +0000483 addPass(&PrologEpilogCodeInserterID);
Andrew Trickd5422652012-02-04 02:56:48 +0000484 printAndVerify("After PrologEpilogCodeInserter");
485
Andrew Trickf7b96312012-02-09 00:40:55 +0000486 /// Add passes that optimize machine instructions after register allocation.
487 if (getOptLevel() != CodeGenOpt::None)
488 addMachineLateOptimization();
Andrew Trickd5422652012-02-04 02:56:48 +0000489
490 // Expand pseudo instructions before second scheduling pass.
Bob Wilson3fb99a72012-07-02 19:48:37 +0000491 addPass(&ExpandPostRAPseudosID);
Jakob Stoklund Olesen2ef5bf62012-03-28 20:49:30 +0000492 printAndVerify("After ExpandPostRAPseudos");
Andrew Trickd5422652012-02-04 02:56:48 +0000493
494 // Run pre-sched2 passes.
495 if (addPreSched2())
Jakob Stoklund Olesen78811662012-03-28 23:31:15 +0000496 printAndVerify("After PreSched2 passes");
Andrew Trickd5422652012-02-04 02:56:48 +0000497
498 // Second pass scheduler.
Andrew Trick79bf2882012-02-15 03:21:51 +0000499 if (getOptLevel() != CodeGenOpt::None) {
Bob Wilson3fb99a72012-07-02 19:48:37 +0000500 addPass(&PostRASchedulerID);
Jakob Stoklund Olesen8b4c5022012-03-28 23:54:28 +0000501 printAndVerify("After PostRAScheduler");
Andrew Trickd5422652012-02-04 02:56:48 +0000502 }
503
Andrew Trickf7b96312012-02-09 00:40:55 +0000504 // GC
Bob Wilson3fb99a72012-07-02 19:48:37 +0000505 addPass(&GCMachineCodeAnalysisID);
Andrew Trickd5422652012-02-04 02:56:48 +0000506 if (PrintGCInfo)
Bob Wilson564fbf62012-07-02 19:48:31 +0000507 addPass(createGCInfoPrinter(dbgs()));
Andrew Trickd5422652012-02-04 02:56:48 +0000508
Andrew Trickf7b96312012-02-09 00:40:55 +0000509 // Basic block placement.
Andrew Trick79bf2882012-02-15 03:21:51 +0000510 if (getOptLevel() != CodeGenOpt::None)
Andrew Trickf7b96312012-02-09 00:40:55 +0000511 addBlockPlacement();
Andrew Trickd5422652012-02-04 02:56:48 +0000512
513 if (addPreEmitPass())
Jakob Stoklund Olesen8b4c5022012-03-28 23:54:28 +0000514 printAndVerify("After PreEmit passes");
Andrew Trickd5422652012-02-04 02:56:48 +0000515}
516
Andrew Trickf7b96312012-02-09 00:40:55 +0000517/// Add passes that optimize machine instructions in SSA form.
518void TargetPassConfig::addMachineSSAOptimization() {
519 // Pre-ra tail duplication.
Bob Wilson3fb99a72012-07-02 19:48:37 +0000520 if (addPass(&EarlyTailDuplicateID))
Andrew Trickf7b96312012-02-09 00:40:55 +0000521 printAndVerify("After Pre-RegAlloc TailDuplicate");
Andrew Trickf7b96312012-02-09 00:40:55 +0000522
523 // Optimize PHIs before DCE: removing dead PHI cycles may make more
524 // instructions dead.
Bob Wilson3fb99a72012-07-02 19:48:37 +0000525 addPass(&OptimizePHIsID);
Andrew Trickf7b96312012-02-09 00:40:55 +0000526
527 // If the target requests it, assign local variables to stack slots relative
528 // to one another and simplify frame index references where possible.
Bob Wilson3fb99a72012-07-02 19:48:37 +0000529 addPass(&LocalStackSlotAllocationID);
Andrew Trickf7b96312012-02-09 00:40:55 +0000530
531 // With optimization, dead code should already be eliminated. However
532 // there is one known exception: lowered code for arguments that are only
533 // used by tail calls, where the tail calls reuse the incoming stack
534 // arguments directly (see t11 in test/CodeGen/X86/sibcall.ll).
Bob Wilson3fb99a72012-07-02 19:48:37 +0000535 addPass(&DeadMachineInstructionElimID);
Andrew Trickf7b96312012-02-09 00:40:55 +0000536 printAndVerify("After codegen DCE pass");
537
Jakob Stoklund Olesen33242fd2012-07-04 00:09:54 +0000538 addPass(&EarlyIfConverterID);
Bob Wilson3fb99a72012-07-02 19:48:37 +0000539 addPass(&MachineLICMID);
540 addPass(&MachineCSEID);
541 addPass(&MachineSinkingID);
Andrew Trickf7b96312012-02-09 00:40:55 +0000542 printAndVerify("After Machine LICM, CSE and Sinking passes");
543
Bob Wilson3fb99a72012-07-02 19:48:37 +0000544 addPass(&PeepholeOptimizerID);
Andrew Trickf7b96312012-02-09 00:40:55 +0000545 printAndVerify("After codegen peephole optimization pass");
546}
547
Andrew Trick74613342012-02-04 02:56:45 +0000548//===---------------------------------------------------------------------===//
Andrew Trickf7b96312012-02-09 00:40:55 +0000549/// Register Allocation Pass Configuration
Jim Laskeyeb577ba2006-08-02 12:30:23 +0000550//===---------------------------------------------------------------------===//
Andrew Trickf7b96312012-02-09 00:40:55 +0000551
Andrew Trick8dd26252012-02-10 04:10:36 +0000552bool TargetPassConfig::getOptimizeRegAlloc() const {
553 switch (OptimizeRegAlloc) {
554 case cl::BOU_UNSET: return getOptLevel() != CodeGenOpt::None;
555 case cl::BOU_TRUE: return true;
556 case cl::BOU_FALSE: return false;
557 }
558 llvm_unreachable("Invalid optimize-regalloc state");
559}
560
Andrew Trickf7b96312012-02-09 00:40:55 +0000561/// RegisterRegAlloc's global Registry tracks allocator registration.
Jim Laskeyeb577ba2006-08-02 12:30:23 +0000562MachinePassRegistry RegisterRegAlloc::Registry;
563
Andrew Trickf7b96312012-02-09 00:40:55 +0000564/// A dummy default pass factory indicates whether the register allocator is
565/// overridden on the command line.
Andrew Trick8dd26252012-02-10 04:10:36 +0000566static FunctionPass *useDefaultRegisterAllocator() { return 0; }
Jakob Stoklund Olesen700bfad2010-05-27 23:57:25 +0000567static RegisterRegAlloc
568defaultRegAlloc("default",
569 "pick register allocator based on -O option",
Andrew Trick8dd26252012-02-10 04:10:36 +0000570 useDefaultRegisterAllocator);
Jim Laskeyeb577ba2006-08-02 12:30:23 +0000571
Andrew Trickf7b96312012-02-09 00:40:55 +0000572/// -regalloc=... command line option.
Dan Gohman844731a2008-05-13 00:00:25 +0000573static cl::opt<RegisterRegAlloc::FunctionPassCtor, false,
574 RegisterPassParser<RegisterRegAlloc> >
575RegAlloc("regalloc",
Andrew Trick8dd26252012-02-10 04:10:36 +0000576 cl::init(&useDefaultRegisterAllocator),
Jakob Stoklund Olesen700bfad2010-05-27 23:57:25 +0000577 cl::desc("Register allocator to use"));
Alkis Evlogimenos7237ece2003-10-02 16:57:49 +0000578
Jim Laskeyeb577ba2006-08-02 12:30:23 +0000579
Andrew Trick8dd26252012-02-10 04:10:36 +0000580/// Instantiate the default register allocator pass for this target for either
581/// the optimized or unoptimized allocation path. This will be added to the pass
582/// manager by addFastRegAlloc in the unoptimized case or addOptimizedRegAlloc
583/// in the optimized case.
584///
585/// A target that uses the standard regalloc pass order for fast or optimized
586/// allocation may still override this for per-target regalloc
587/// selection. But -regalloc=... always takes precedence.
588FunctionPass *TargetPassConfig::createTargetRegisterAllocator(bool Optimized) {
589 if (Optimized)
590 return createGreedyRegisterAllocator();
591 else
592 return createFastRegisterAllocator();
593}
594
595/// Find and instantiate the register allocation pass requested by this target
596/// at the current optimization level. Different register allocators are
597/// defined as separate passes because they may require different analysis.
598///
599/// This helper ensures that the regalloc= option is always available,
600/// even for targets that override the default allocator.
601///
602/// FIXME: When MachinePassRegistry register pass IDs instead of function ptrs,
603/// this can be folded into addPass.
604FunctionPass *TargetPassConfig::createRegAllocPass(bool Optimized) {
Jim Laskey9ff542f2006-08-01 18:29:48 +0000605 RegisterRegAlloc::FunctionPassCtor Ctor = RegisterRegAlloc::getDefault();
Jakob Stoklund Olesen700bfad2010-05-27 23:57:25 +0000606
Andrew Trick8dd26252012-02-10 04:10:36 +0000607 // Initialize the global default.
Jim Laskey13ec7022006-08-01 14:21:23 +0000608 if (!Ctor) {
Jim Laskeyeb577ba2006-08-02 12:30:23 +0000609 Ctor = RegAlloc;
610 RegisterRegAlloc::setDefault(RegAlloc);
Jim Laskey13ec7022006-08-01 14:21:23 +0000611 }
Andrew Trick8dd26252012-02-10 04:10:36 +0000612 if (Ctor != useDefaultRegisterAllocator)
Jakob Stoklund Olesen700bfad2010-05-27 23:57:25 +0000613 return Ctor();
614
Andrew Trick8dd26252012-02-10 04:10:36 +0000615 // With no -regalloc= override, ask the target for a regalloc pass.
616 return createTargetRegisterAllocator(Optimized);
617}
618
619/// Add the minimum set of target-independent passes that are required for
620/// register allocation. No coalescing or scheduling.
621void TargetPassConfig::addFastRegAlloc(FunctionPass *RegAllocPass) {
Bob Wilson3fb99a72012-07-02 19:48:37 +0000622 addPass(&PHIEliminationID);
623 addPass(&TwoAddressInstructionPassID);
Andrew Trick8dd26252012-02-10 04:10:36 +0000624
Bob Wilson564fbf62012-07-02 19:48:31 +0000625 addPass(RegAllocPass);
Andrew Trick8dd26252012-02-10 04:10:36 +0000626 printAndVerify("After Register Allocation");
Jim Laskey33a0a6d2006-07-27 20:05:00 +0000627}
Andrew Trickf7b96312012-02-09 00:40:55 +0000628
629/// Add standard target-independent passes that are tightly coupled with
Andrew Trick8dd26252012-02-10 04:10:36 +0000630/// optimized register allocation, including coalescing, machine instruction
631/// scheduling, and register allocation itself.
632void TargetPassConfig::addOptimizedRegAlloc(FunctionPass *RegAllocPass) {
Bob Wilson3fb99a72012-07-02 19:48:37 +0000633 addPass(&ProcessImplicitDefsID);
Jakob Stoklund Olesen5984d2b2012-06-25 18:12:18 +0000634
Andrew Trick8dd26252012-02-10 04:10:36 +0000635 // LiveVariables currently requires pure SSA form.
636 //
637 // FIXME: Once TwoAddressInstruction pass no longer uses kill flags,
638 // LiveVariables can be removed completely, and LiveIntervals can be directly
639 // computed. (We still either need to regenerate kill flags after regalloc, or
640 // preferably fix the scavenger to not depend on them).
Bob Wilson3fb99a72012-07-02 19:48:37 +0000641 addPass(&LiveVariablesID);
Andrew Trick8dd26252012-02-10 04:10:36 +0000642
643 // Add passes that move from transformed SSA into conventional SSA. This is a
644 // "copy coalescing" problem.
645 //
646 if (!EnableStrongPHIElim) {
647 // Edge splitting is smarter with machine loop info.
Bob Wilson3fb99a72012-07-02 19:48:37 +0000648 addPass(&MachineLoopInfoID);
649 addPass(&PHIEliminationID);
Andrew Trick8dd26252012-02-10 04:10:36 +0000650 }
Bob Wilson3fb99a72012-07-02 19:48:37 +0000651 addPass(&TwoAddressInstructionPassID);
Andrew Trick8dd26252012-02-10 04:10:36 +0000652
Andrew Trick8dd26252012-02-10 04:10:36 +0000653 if (EnableStrongPHIElim)
Bob Wilson3fb99a72012-07-02 19:48:37 +0000654 addPass(&StrongPHIEliminationID);
Andrew Trick8dd26252012-02-10 04:10:36 +0000655
Bob Wilson3fb99a72012-07-02 19:48:37 +0000656 addPass(&RegisterCoalescerID);
Andrew Trick8dd26252012-02-10 04:10:36 +0000657
658 // PreRA instruction scheduling.
Bob Wilson3fb99a72012-07-02 19:48:37 +0000659 if (addPass(&MachineSchedulerID))
Andrew Trick17d35e52012-03-14 04:00:41 +0000660 printAndVerify("After Machine Scheduling");
Andrew Trick8dd26252012-02-10 04:10:36 +0000661
662 // Add the selected register allocation pass.
Bob Wilson564fbf62012-07-02 19:48:31 +0000663 addPass(RegAllocPass);
Jakob Stoklund Olesen34f5a2b2012-06-26 17:09:29 +0000664 printAndVerify("After Register Allocation, before rewriter");
665
666 // Allow targets to change the register assignments before rewriting.
667 if (addPreRewrite())
668 printAndVerify("After pre-rewrite passes");
Andrew Trickf7b96312012-02-09 00:40:55 +0000669
Jakob Stoklund Olesen05ec7122012-06-08 23:44:45 +0000670 // Finally rewrite virtual registers.
Bob Wilson3fb99a72012-07-02 19:48:37 +0000671 addPass(&VirtRegRewriterID);
Jakob Stoklund Olesen05ec7122012-06-08 23:44:45 +0000672 printAndVerify("After Virtual Register Rewriter");
673
Andrew Trick746f24b2012-02-11 07:11:32 +0000674 // FinalizeRegAlloc is convenient until MachineInstrBundles is more mature,
675 // but eventually, all users of it should probably be moved to addPostRA and
676 // it can go away. Currently, it's the intended place for targets to run
677 // FinalizeMachineBundles, because passes other than MachineScheduling an
678 // RegAlloc itself may not be aware of bundles.
679 if (addFinalizeRegAlloc())
680 printAndVerify("After RegAlloc finalization");
681
Andrew Trickf7b96312012-02-09 00:40:55 +0000682 // Perform stack slot coloring and post-ra machine LICM.
Andrew Trick8dd26252012-02-10 04:10:36 +0000683 //
684 // FIXME: Re-enable coloring with register when it's capable of adding
685 // kill markers.
Bob Wilson3fb99a72012-07-02 19:48:37 +0000686 addPass(&StackSlotColoringID);
Andrew Trick900d7b72012-02-15 07:57:03 +0000687
688 // Run post-ra machine LICM to hoist reloads / remats.
689 //
690 // FIXME: can this move into MachineLateOptimization?
Bob Wilson3fb99a72012-07-02 19:48:37 +0000691 addPass(&PostRAMachineLICMID);
Andrew Trick900d7b72012-02-15 07:57:03 +0000692
693 printAndVerify("After StackSlotColoring and postra Machine LICM");
Andrew Trickf7b96312012-02-09 00:40:55 +0000694}
695
696//===---------------------------------------------------------------------===//
697/// Post RegAlloc Pass Configuration
698//===---------------------------------------------------------------------===//
699
700/// Add passes that optimize machine instructions after register allocation.
701void TargetPassConfig::addMachineLateOptimization() {
702 // Branch folding must be run after regalloc and prolog/epilog insertion.
Bob Wilson3fb99a72012-07-02 19:48:37 +0000703 if (addPass(&BranchFolderPassID))
Jakob Stoklund Olesen663ee202012-03-28 20:47:37 +0000704 printAndVerify("After BranchFolding");
Andrew Trickf7b96312012-02-09 00:40:55 +0000705
706 // Tail duplication.
Bob Wilson3fb99a72012-07-02 19:48:37 +0000707 if (addPass(&TailDuplicateID))
Jakob Stoklund Olesen663ee202012-03-28 20:47:37 +0000708 printAndVerify("After TailDuplicate");
Andrew Trickf7b96312012-02-09 00:40:55 +0000709
710 // Copy propagation.
Bob Wilson3fb99a72012-07-02 19:48:37 +0000711 if (addPass(&MachineCopyPropagationID))
Jakob Stoklund Olesen663ee202012-03-28 20:47:37 +0000712 printAndVerify("After copy propagation pass");
Andrew Trickf7b96312012-02-09 00:40:55 +0000713}
714
715/// Add standard basic block placement passes.
716void TargetPassConfig::addBlockPlacement() {
Bob Wilson3fb99a72012-07-02 19:48:37 +0000717 AnalysisID PassID = 0;
Chandler Carruth9e67db42012-04-16 13:49:17 +0000718 if (!DisableBlockPlacement) {
719 // MachineBlockPlacement is a new pass which subsumes the functionality of
720 // CodPlacementOpt. The old code placement pass can be restored by
721 // disabling block placement, but eventually it will be removed.
Bob Wilson3fb99a72012-07-02 19:48:37 +0000722 PassID = addPass(&MachineBlockPlacementID);
Andrew Trickf7b96312012-02-09 00:40:55 +0000723 } else {
Bob Wilson3fb99a72012-07-02 19:48:37 +0000724 PassID = addPass(&CodePlacementOptID);
Andrew Trickf7b96312012-02-09 00:40:55 +0000725 }
Bob Wilson3fb99a72012-07-02 19:48:37 +0000726 if (PassID) {
Andrew Trick79bf2882012-02-15 03:21:51 +0000727 // Run a separate pass to collect block placement statistics.
728 if (EnableBlockPlacementStats)
Bob Wilson3fb99a72012-07-02 19:48:37 +0000729 addPass(&MachineBlockPlacementStatsID);
Andrew Trickf7b96312012-02-09 00:40:55 +0000730
Jakob Stoklund Olesen8b4c5022012-03-28 23:54:28 +0000731 printAndVerify("After machine block placement.");
Andrew Trickf7b96312012-02-09 00:40:55 +0000732 }
733}