blob: 1af65c88abebe7024a790754d8876016548731ca [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"
Chandler Carruthd04a8d42012-12-03 16:50:05 +000028#include "llvm/Target/TargetSubtargetInfo.h"
29#include "llvm/Transforms/Scalar.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",
Benjamin Kramer74a45332013-03-29 17:14:24 +000042 cl::Hidden, cl::desc("Disable probability-driven block placement"));
Andrew Trickd5422652012-02-04 02:56:48 +000043static cl::opt<bool> EnableBlockPlacementStats("enable-block-placement-stats",
44 cl::Hidden, cl::desc("Collect probability-driven block placement stats"));
Andrew Trickd5422652012-02-04 02:56:48 +000045static cl::opt<bool> DisableSSC("disable-ssc", cl::Hidden,
46 cl::desc("Disable Stack Slot Coloring"));
47static cl::opt<bool> DisableMachineDCE("disable-machine-dce", cl::Hidden,
48 cl::desc("Disable Machine Dead Code Elimination"));
Jakob Stoklund Olesen0d141f82012-10-03 00:51:32 +000049static cl::opt<bool> DisableEarlyIfConversion("disable-early-ifcvt", cl::Hidden,
50 cl::desc("Disable Early If-conversion"));
Andrew Trickd5422652012-02-04 02:56:48 +000051static cl::opt<bool> DisableMachineLICM("disable-machine-licm", cl::Hidden,
52 cl::desc("Disable Machine LICM"));
53static cl::opt<bool> DisableMachineCSE("disable-machine-cse", cl::Hidden,
54 cl::desc("Disable Machine Common Subexpression Elimination"));
Andrew Trick8dd26252012-02-10 04:10:36 +000055static cl::opt<cl::boolOrDefault>
56OptimizeRegAlloc("optimize-regalloc", cl::Hidden,
57 cl::desc("Enable optimized register allocation compilation path."));
Andrew Trick746f24b2012-02-11 07:11:32 +000058static cl::opt<cl::boolOrDefault>
59EnableMachineSched("enable-misched", cl::Hidden,
Andrew Trick8dd26252012-02-10 04:10:36 +000060 cl::desc("Enable the machine instruction scheduling pass."));
61static cl::opt<bool> EnableStrongPHIElim("strong-phi-elim", cl::Hidden,
62 cl::desc("Use strong PHI elimination."));
Andrew Trickd5422652012-02-04 02:56:48 +000063static cl::opt<bool> DisablePostRAMachineLICM("disable-postra-machine-licm",
64 cl::Hidden,
65 cl::desc("Disable Machine LICM"));
66static cl::opt<bool> DisableMachineSink("disable-machine-sink", cl::Hidden,
67 cl::desc("Disable Machine Sinking"));
68static cl::opt<bool> DisableLSR("disable-lsr", cl::Hidden,
69 cl::desc("Disable Loop Strength Reduction Pass"));
70static cl::opt<bool> DisableCGP("disable-cgp", cl::Hidden,
71 cl::desc("Disable Codegen Prepare"));
72static cl::opt<bool> DisableCopyProp("disable-copyprop", cl::Hidden,
Evan Cheng01b623c2012-02-20 23:28:17 +000073 cl::desc("Disable Copy Propagation pass"));
Andrew Trickd5422652012-02-04 02:56:48 +000074static cl::opt<bool> PrintLSR("print-lsr-output", cl::Hidden,
75 cl::desc("Print LLVM IR produced by the loop-reduce pass"));
76static cl::opt<bool> PrintISelInput("print-isel-input", cl::Hidden,
77 cl::desc("Print LLVM IR input to isel pass"));
78static cl::opt<bool> PrintGCInfo("print-gc", cl::Hidden,
79 cl::desc("Dump garbage collector data"));
80static cl::opt<bool> VerifyMachineCode("verify-machineinstrs", cl::Hidden,
81 cl::desc("Verify generated machine code"),
82 cl::init(getenv("LLVM_VERIFY_MACHINEINSTRS")!=NULL));
Bob Wilson6e1b8122012-05-30 00:17:12 +000083static cl::opt<std::string>
84PrintMachineInstrs("print-machineinstrs", cl::ValueOptional,
85 cl::desc("Print machine instrs"),
86 cl::value_desc("pass-name"), cl::init("option-unspecified"));
Andrew Trickd5422652012-02-04 02:56:48 +000087
Cameron Zwarichd7c7a682013-02-10 06:42:34 +000088// Experimental option to run live interval analysis early.
Jakob Stoklund Olesendcc44362012-08-03 22:12:54 +000089static cl::opt<bool> EarlyLiveIntervals("early-live-intervals", cl::Hidden,
90 cl::desc("Run live interval analysis earlier in the pipeline"));
91
Andrew Trick79bf2882012-02-15 03:21:51 +000092/// Allow standard passes to be disabled by command line options. This supports
93/// simple binary flags that either suppress the pass or do nothing.
94/// i.e. -disable-mypass=false has no effect.
95/// These should be converted to boolOrDefault in order to use applyOverride.
Bob Wilson3fb99a72012-07-02 19:48:37 +000096static AnalysisID applyDisable(AnalysisID PassID, bool Override) {
Andrew Trick79bf2882012-02-15 03:21:51 +000097 if (Override)
Bob Wilson3fb99a72012-07-02 19:48:37 +000098 return 0;
99 return PassID;
Andrew Trick79bf2882012-02-15 03:21:51 +0000100}
101
102/// Allow Pass selection to be overriden by command line options. This supports
103/// flags with ternary conditions. TargetID is passed through by default. The
104/// pass is suppressed when the option is false. When the option is true, the
105/// StandardID is selected if the target provides no default.
106static AnalysisID applyOverride(AnalysisID TargetID, cl::boolOrDefault Override,
107 AnalysisID StandardID) {
Andrew Trick746f24b2012-02-11 07:11:32 +0000108 switch (Override) {
109 case cl::BOU_UNSET:
Andrew Trick79bf2882012-02-15 03:21:51 +0000110 return TargetID;
Andrew Trick746f24b2012-02-11 07:11:32 +0000111 case cl::BOU_TRUE:
Bob Wilson3fb99a72012-07-02 19:48:37 +0000112 if (TargetID)
Andrew Trick79bf2882012-02-15 03:21:51 +0000113 return TargetID;
Bob Wilson3fb99a72012-07-02 19:48:37 +0000114 if (StandardID == 0)
Andrew Trick746f24b2012-02-11 07:11:32 +0000115 report_fatal_error("Target cannot enable pass");
Andrew Trick79bf2882012-02-15 03:21:51 +0000116 return StandardID;
Andrew Trick746f24b2012-02-11 07:11:32 +0000117 case cl::BOU_FALSE:
Bob Wilson3fb99a72012-07-02 19:48:37 +0000118 return 0;
Andrew Trick746f24b2012-02-11 07:11:32 +0000119 }
120 llvm_unreachable("Invalid command line option state");
121}
122
Andrew Trick79bf2882012-02-15 03:21:51 +0000123/// Allow standard passes to be disabled by the command line, regardless of who
124/// is adding the pass.
125///
126/// StandardID is the pass identified in the standard pass pipeline and provided
127/// to addPass(). It may be a target-specific ID in the case that the target
128/// directly adds its own pass, but in that case we harmlessly fall through.
129///
130/// TargetID is the pass that the target has configured to override StandardID.
131///
132/// StandardID may be a pseudo ID. In that case TargetID is the name of the real
133/// pass to run. This allows multiple options to control a single pass depending
134/// on where in the pipeline that pass is added.
135static AnalysisID overridePass(AnalysisID StandardID, AnalysisID TargetID) {
136 if (StandardID == &PostRASchedulerID)
137 return applyDisable(TargetID, DisablePostRA);
138
139 if (StandardID == &BranchFolderPassID)
140 return applyDisable(TargetID, DisableBranchFold);
141
142 if (StandardID == &TailDuplicateID)
143 return applyDisable(TargetID, DisableTailDuplicate);
144
145 if (StandardID == &TargetPassConfig::EarlyTailDuplicateID)
146 return applyDisable(TargetID, DisableEarlyTailDup);
147
148 if (StandardID == &MachineBlockPlacementID)
Benjamin Kramer74a45332013-03-29 17:14:24 +0000149 return applyDisable(TargetID, DisableBlockPlacement);
Andrew Trick79bf2882012-02-15 03:21:51 +0000150
151 if (StandardID == &StackSlotColoringID)
152 return applyDisable(TargetID, DisableSSC);
153
154 if (StandardID == &DeadMachineInstructionElimID)
155 return applyDisable(TargetID, DisableMachineDCE);
156
Jakob Stoklund Olesen33242fd2012-07-04 00:09:54 +0000157 if (StandardID == &EarlyIfConverterID)
Jakob Stoklund Olesen0d141f82012-10-03 00:51:32 +0000158 return applyDisable(TargetID, DisableEarlyIfConversion);
Jakob Stoklund Olesen33242fd2012-07-04 00:09:54 +0000159
Andrew Trick79bf2882012-02-15 03:21:51 +0000160 if (StandardID == &MachineLICMID)
161 return applyDisable(TargetID, DisableMachineLICM);
162
163 if (StandardID == &MachineCSEID)
164 return applyDisable(TargetID, DisableMachineCSE);
165
166 if (StandardID == &MachineSchedulerID)
167 return applyOverride(TargetID, EnableMachineSched, StandardID);
168
169 if (StandardID == &TargetPassConfig::PostRAMachineLICMID)
170 return applyDisable(TargetID, DisablePostRAMachineLICM);
171
172 if (StandardID == &MachineSinkingID)
173 return applyDisable(TargetID, DisableMachineSink);
174
175 if (StandardID == &MachineCopyPropagationID)
176 return applyDisable(TargetID, DisableCopyProp);
177
178 return TargetID;
179}
180
Jim Laskeyeb577ba2006-08-02 12:30:23 +0000181//===---------------------------------------------------------------------===//
Andrew Trick74613342012-02-04 02:56:45 +0000182/// TargetPassConfig
183//===---------------------------------------------------------------------===//
184
185INITIALIZE_PASS(TargetPassConfig, "targetpassconfig",
186 "Target Pass Configuration", false, false)
187char TargetPassConfig::ID = 0;
188
Andrew Trick79bf2882012-02-15 03:21:51 +0000189// Pseudo Pass IDs.
190char TargetPassConfig::EarlyTailDuplicateID = 0;
191char TargetPassConfig::PostRAMachineLICMID = 0;
192
Andrew Trick5e108ee2012-02-15 03:21:47 +0000193namespace llvm {
194class PassConfigImpl {
195public:
196 // List of passes explicitly substituted by this target. Normally this is
197 // empty, but it is a convenient way to suppress or replace specific passes
198 // that are part of a standard pass pipeline without overridding the entire
199 // pipeline. This mechanism allows target options to inherit a standard pass's
200 // user interface. For example, a target may disable a standard pass by
Bob Wilson3fb99a72012-07-02 19:48:37 +0000201 // default by substituting a pass ID of zero, and the user may still enable
202 // that standard pass with an explicit command line option.
Andrew Trick5e108ee2012-02-15 03:21:47 +0000203 DenseMap<AnalysisID,AnalysisID> TargetPasses;
Bob Wilson6e1b8122012-05-30 00:17:12 +0000204
205 /// Store the pairs of <AnalysisID, AnalysisID> of which the second pass
206 /// is inserted after each instance of the first one.
207 SmallVector<std::pair<AnalysisID, AnalysisID>, 4> InsertedPasses;
Andrew Trick5e108ee2012-02-15 03:21:47 +0000208};
209} // namespace llvm
210
Andrew Trick74613342012-02-04 02:56:45 +0000211// Out of line virtual method.
Andrew Trick5e108ee2012-02-15 03:21:47 +0000212TargetPassConfig::~TargetPassConfig() {
213 delete Impl;
214}
Andrew Trick74613342012-02-04 02:56:45 +0000215
Andrew Trick61f1e3d2012-02-08 21:22:48 +0000216// Out of line constructor provides default values for pass options and
217// registers all common codegen passes.
Andrew Trick061efcf2012-02-04 02:56:59 +0000218TargetPassConfig::TargetPassConfig(TargetMachine *tm, PassManagerBase &pm)
Bob Wilson30a507a2012-07-02 19:48:45 +0000219 : ImmutablePass(ID), PM(&pm), StartAfter(0), StopAfter(0),
220 Started(true), Stopped(false), TM(tm), Impl(0), Initialized(false),
Andrew Trickffea03f2012-02-08 21:22:39 +0000221 DisableVerify(false),
222 EnableTailMerge(true) {
223
Andrew Trick5e108ee2012-02-15 03:21:47 +0000224 Impl = new PassConfigImpl();
225
Andrew Trick74613342012-02-04 02:56:45 +0000226 // Register all target independent codegen passes to activate their PassIDs,
227 // including this pass itself.
228 initializeCodeGen(*PassRegistry::getPassRegistry());
Andrew Trick79bf2882012-02-15 03:21:51 +0000229
230 // Substitute Pseudo Pass IDs for real ones.
Bob Wilson3fb99a72012-07-02 19:48:37 +0000231 substitutePass(&EarlyTailDuplicateID, &TailDuplicateID);
232 substitutePass(&PostRAMachineLICMID, &MachineLICMID);
Andrew Trick79bf2882012-02-15 03:21:51 +0000233
234 // Temporarily disable experimental passes.
Andrew Trickad1cc1d2012-11-13 08:47:29 +0000235 const TargetSubtargetInfo &ST = TM->getSubtarget<TargetSubtargetInfo>();
236 if (!ST.enableMachineScheduler())
237 disablePass(&MachineSchedulerID);
Andrew Trick74613342012-02-04 02:56:45 +0000238}
239
Bob Wilson6e1b8122012-05-30 00:17:12 +0000240/// Insert InsertedPassID pass after TargetPassID.
Bob Wilson3fb99a72012-07-02 19:48:37 +0000241void TargetPassConfig::insertPass(AnalysisID TargetPassID,
242 AnalysisID InsertedPassID) {
243 assert(TargetPassID != InsertedPassID && "Insert a pass after itself!");
244 std::pair<AnalysisID, AnalysisID> P(TargetPassID, InsertedPassID);
Bob Wilson6e1b8122012-05-30 00:17:12 +0000245 Impl->InsertedPasses.push_back(P);
246}
247
Andrew Trick74613342012-02-04 02:56:45 +0000248/// createPassConfig - Create a pass configuration object to be used by
249/// addPassToEmitX methods for generating a pipeline of CodeGen passes.
250///
251/// Targets may override this to extend TargetPassConfig.
Andrew Trick061efcf2012-02-04 02:56:59 +0000252TargetPassConfig *LLVMTargetMachine::createPassConfig(PassManagerBase &PM) {
253 return new TargetPassConfig(this, PM);
Andrew Trick74613342012-02-04 02:56:45 +0000254}
255
256TargetPassConfig::TargetPassConfig()
Bill Wendling7c4ce302012-05-01 08:27:43 +0000257 : ImmutablePass(ID), PM(0) {
Andrew Trick74613342012-02-04 02:56:45 +0000258 llvm_unreachable("TargetPassConfig should not be constructed on-the-fly");
259}
260
Andrew Trickffea03f2012-02-08 21:22:39 +0000261// Helper to verify the analysis is really immutable.
262void TargetPassConfig::setOpt(bool &Opt, bool Val) {
263 assert(!Initialized && "PassConfig is immutable");
264 Opt = Val;
265}
266
Bob Wilson3fb99a72012-07-02 19:48:37 +0000267void TargetPassConfig::substitutePass(AnalysisID StandardID,
268 AnalysisID TargetID) {
269 Impl->TargetPasses[StandardID] = TargetID;
Andrew Trick5e108ee2012-02-15 03:21:47 +0000270}
Andrew Trick746f24b2012-02-11 07:11:32 +0000271
Andrew Trick5e108ee2012-02-15 03:21:47 +0000272AnalysisID TargetPassConfig::getPassSubstitution(AnalysisID ID) const {
273 DenseMap<AnalysisID, AnalysisID>::const_iterator
274 I = Impl->TargetPasses.find(ID);
275 if (I == Impl->TargetPasses.end())
276 return ID;
277 return I->second;
278}
279
Bob Wilson30a507a2012-07-02 19:48:45 +0000280/// Add a pass to the PassManager if that pass is supposed to be run. If the
281/// Started/Stopped flags indicate either that the compilation should start at
282/// a later pass or that it should stop after an earlier pass, then do not add
283/// the pass. Finally, compare the current pass against the StartAfter
284/// and StopAfter options and change the Started/Stopped flags accordingly.
Bob Wilson564fbf62012-07-02 19:48:31 +0000285void TargetPassConfig::addPass(Pass *P) {
Bob Wilson6b2bb152012-07-02 19:48:39 +0000286 assert(!Initialized && "PassConfig is immutable");
287
Chandler Carruth6068c482012-07-02 22:56:41 +0000288 // Cache the Pass ID here in case the pass manager finds this pass is
289 // redundant with ones already scheduled / available, and deletes it.
290 // Fundamentally, once we add the pass to the manager, we no longer own it
291 // and shouldn't reference it.
292 AnalysisID PassID = P->getPassID();
293
Bob Wilson30a507a2012-07-02 19:48:45 +0000294 if (Started && !Stopped)
295 PM->add(P);
Chandler Carruth6068c482012-07-02 22:56:41 +0000296 if (StopAfter == PassID)
Bob Wilson30a507a2012-07-02 19:48:45 +0000297 Stopped = true;
Chandler Carruth6068c482012-07-02 22:56:41 +0000298 if (StartAfter == PassID)
Bob Wilson30a507a2012-07-02 19:48:45 +0000299 Started = true;
300 if (Stopped && !Started)
301 report_fatal_error("Cannot stop compilation after pass that is not run");
Bob Wilson564fbf62012-07-02 19:48:31 +0000302}
303
Andrew Trick5e108ee2012-02-15 03:21:47 +0000304/// Add a CodeGen pass at this point in the pipeline after checking for target
305/// and command line overrides.
Bob Wilson3fb99a72012-07-02 19:48:37 +0000306AnalysisID TargetPassConfig::addPass(AnalysisID PassID) {
Bob Wilson3fb99a72012-07-02 19:48:37 +0000307 AnalysisID TargetID = getPassSubstitution(PassID);
308 AnalysisID FinalID = overridePass(PassID, TargetID);
309 if (FinalID == 0)
Andrew Trick5e108ee2012-02-15 03:21:47 +0000310 return FinalID;
311
312 Pass *P = Pass::createPass(FinalID);
Andrew Trickebe18ef2012-02-08 21:22:34 +0000313 if (!P)
314 llvm_unreachable("Pass ID not registered");
Bob Wilson564fbf62012-07-02 19:48:31 +0000315 addPass(P);
Bob Wilson6e1b8122012-05-30 00:17:12 +0000316 // Add the passes after the pass P if there is any.
317 for (SmallVector<std::pair<AnalysisID, AnalysisID>, 4>::iterator
318 I = Impl->InsertedPasses.begin(), E = Impl->InsertedPasses.end();
319 I != E; ++I) {
Bob Wilson3fb99a72012-07-02 19:48:37 +0000320 if ((*I).first == PassID) {
Bob Wilson6e1b8122012-05-30 00:17:12 +0000321 assert((*I).second && "Illegal Pass ID!");
322 Pass *NP = Pass::createPass((*I).second);
323 assert(NP && "Pass ID not registered");
Bob Wilson564fbf62012-07-02 19:48:31 +0000324 addPass(NP);
Bob Wilson6e1b8122012-05-30 00:17:12 +0000325 }
326 }
Andrew Trick5e108ee2012-02-15 03:21:47 +0000327 return FinalID;
Andrew Trick061efcf2012-02-04 02:56:59 +0000328}
Andrew Trickd5422652012-02-04 02:56:48 +0000329
Bob Wilson564fbf62012-07-02 19:48:31 +0000330void TargetPassConfig::printAndVerify(const char *Banner) {
Andrew Trickd5422652012-02-04 02:56:48 +0000331 if (TM->shouldPrintMachineCode())
Bob Wilson564fbf62012-07-02 19:48:31 +0000332 addPass(createMachineFunctionPrinterPass(dbgs(), Banner));
Andrew Trickd5422652012-02-04 02:56:48 +0000333
334 if (VerifyMachineCode)
Bob Wilson564fbf62012-07-02 19:48:31 +0000335 addPass(createMachineVerifierPass(Banner));
Andrew Trickd5422652012-02-04 02:56:48 +0000336}
337
Andrew Trick061efcf2012-02-04 02:56:59 +0000338/// Add common target configurable passes that perform LLVM IR to IR transforms
339/// following machine independent optimization.
340void TargetPassConfig::addIRPasses() {
Andrew Trickd5422652012-02-04 02:56:48 +0000341 // Basic AliasAnalysis support.
342 // Add TypeBasedAliasAnalysis before BasicAliasAnalysis so that
343 // BasicAliasAnalysis wins if they disagree. This is intended to help
344 // support "obvious" type-punning idioms.
Bob Wilson564fbf62012-07-02 19:48:31 +0000345 addPass(createTypeBasedAliasAnalysisPass());
346 addPass(createBasicAliasAnalysisPass());
Andrew Trickd5422652012-02-04 02:56:48 +0000347
348 // Before running any passes, run the verifier to determine if the input
349 // coming from the front-end and/or optimizer is valid.
350 if (!DisableVerify)
Bob Wilson564fbf62012-07-02 19:48:31 +0000351 addPass(createVerifierPass());
Andrew Trickd5422652012-02-04 02:56:48 +0000352
353 // Run loop strength reduction before anything else.
354 if (getOptLevel() != CodeGenOpt::None && !DisableLSR) {
Chandler Carruthe4ba75f2013-01-07 14:41:08 +0000355 addPass(createLoopStrengthReducePass());
Andrew Trickd5422652012-02-04 02:56:48 +0000356 if (PrintLSR)
Bob Wilson564fbf62012-07-02 19:48:31 +0000357 addPass(createPrintFunctionPass("\n\n*** Code after LSR ***\n", &dbgs()));
Andrew Trickd5422652012-02-04 02:56:48 +0000358 }
359
Bob Wilson564fbf62012-07-02 19:48:31 +0000360 addPass(createGCLoweringPass());
Andrew Trickd5422652012-02-04 02:56:48 +0000361
362 // Make sure that no unreachable blocks are instruction selected.
Bob Wilson564fbf62012-07-02 19:48:31 +0000363 addPass(createUnreachableBlockEliminationPass());
364}
365
366/// Turn exception handling constructs into something the code generators can
367/// handle.
368void TargetPassConfig::addPassesToHandleExceptions() {
369 switch (TM->getMCAsmInfo()->getExceptionHandlingType()) {
370 case ExceptionHandling::SjLj:
371 // SjLj piggy-backs on dwarf for this bit. The cleanups done apply to both
372 // Dwarf EH prepare needs to be run after SjLj prepare. Otherwise,
373 // catch info can get misplaced when a selector ends up more than one block
374 // removed from the parent invoke(s). This could happen when a landing
375 // pad is shared by multiple invokes and is also a target of a normal
376 // edge from elsewhere.
377 addPass(createSjLjEHPreparePass(TM->getTargetLowering()));
378 // FALLTHROUGH
379 case ExceptionHandling::DwarfCFI:
380 case ExceptionHandling::ARM:
381 case ExceptionHandling::Win64:
382 addPass(createDwarfEHPass(TM));
383 break;
384 case ExceptionHandling::None:
Nadav Rotema04a4a72012-10-19 21:28:43 +0000385 addPass(createLowerInvokePass(TM->getTargetLowering()));
Bob Wilson564fbf62012-07-02 19:48:31 +0000386
387 // The lower invoke pass may create unreachable code. Remove it.
388 addPass(createUnreachableBlockEliminationPass());
389 break;
390 }
Andrew Trick061efcf2012-02-04 02:56:59 +0000391}
Andrew Trickd5422652012-02-04 02:56:48 +0000392
Bill Wendling08510b12012-11-30 22:08:55 +0000393/// Add pass to prepare the LLVM IR for code generation. This should be done
394/// before exception handling preparation passes.
395void TargetPassConfig::addCodeGenPrepare() {
396 if (getOptLevel() != CodeGenOpt::None && !DisableCGP)
397 addPass(createCodeGenPreparePass(getTargetLowering()));
398}
399
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() {
Bob Wilson564fbf62012-07-02 19:48:31 +0000403 addPass(createStackProtectorPass(getTargetLowering()));
Andrew Trickd5422652012-02-04 02:56:48 +0000404
405 addPreISel();
406
407 if (PrintISelInput)
Bob Wilson564fbf62012-07-02 19:48:31 +0000408 addPass(createPrintFunctionPass("\n\n"
Bill Wendling7c4ce302012-05-01 08:27:43 +0000409 "*** Final LLVM Code input to ISel ***\n",
410 &dbgs()));
Andrew Trickd5422652012-02-04 02:56:48 +0000411
412 // All passes which modify the LLVM IR are now complete; run the verifier
413 // to ensure that the IR is valid.
414 if (!DisableVerify)
Bob Wilson564fbf62012-07-02 19:48:31 +0000415 addPass(createVerifierPass());
Andrew Trick061efcf2012-02-04 02:56:59 +0000416}
Andrew Trickd5422652012-02-04 02:56:48 +0000417
Andrew Trickf7b96312012-02-09 00:40:55 +0000418/// Add the complete set of target-independent postISel code generator passes.
419///
420/// This can be read as the standard order of major LLVM CodeGen stages. Stages
421/// with nontrivial configuration or multiple passes are broken out below in
422/// add%Stage routines.
423///
424/// Any TargetPassConfig::addXX routine may be overriden by the Target. The
425/// addPre/Post methods with empty header implementations allow injecting
426/// target-specific fixups just before or after major stages. Additionally,
427/// targets have the flexibility to change pass order within a stage by
428/// overriding default implementation of add%Stage routines below. Each
429/// technique has maintainability tradeoffs because alternate pass orders are
430/// not well supported. addPre/Post works better if the target pass is easily
431/// tied to a common pass. But if it has subtle dependencies on multiple passes,
Andrew Trick06efdd22012-02-10 07:08:25 +0000432/// the target should override the stage instead.
Andrew Trickf7b96312012-02-09 00:40:55 +0000433///
434/// TODO: We could use a single addPre/Post(ID) hook to allow pass injection
435/// before/after any target-independent pass. But it's currently overkill.
Andrew Trick061efcf2012-02-04 02:56:59 +0000436void TargetPassConfig::addMachinePasses() {
Bob Wilson6e1b8122012-05-30 00:17:12 +0000437 // Insert a machine instr printer pass after the specified pass.
438 // If -print-machineinstrs specified, print machineinstrs after all passes.
439 if (StringRef(PrintMachineInstrs.getValue()).equals(""))
440 TM->Options.PrintMachineCode = true;
441 else if (!StringRef(PrintMachineInstrs.getValue())
442 .equals("option-unspecified")) {
443 const PassRegistry *PR = PassRegistry::getPassRegistry();
444 const PassInfo *TPI = PR->getPassInfo(PrintMachineInstrs.getValue());
445 const PassInfo *IPI = PR->getPassInfo(StringRef("print-machineinstrs"));
446 assert (TPI && IPI && "Pass ID not registered!");
Roman Divacky59324292012-09-05 22:26:57 +0000447 const char *TID = (const char *)(TPI->getTypeInfo());
448 const char *IID = (const char *)(IPI->getTypeInfo());
Bob Wilson3fb99a72012-07-02 19:48:37 +0000449 insertPass(TID, IID);
Bob Wilson6e1b8122012-05-30 00:17:12 +0000450 }
451
Jakob Stoklund Olesenf86c00f2012-07-04 19:28:27 +0000452 // Print the instruction selected machine code...
453 printAndVerify("After Instruction Selection");
454
Andrew Trickd5422652012-02-04 02:56:48 +0000455 // Expand pseudo-instructions emitted by ISel.
Jakob Stoklund Olesen228e3f52012-08-20 20:52:08 +0000456 if (addPass(&ExpandISelPseudosID))
457 printAndVerify("After ExpandISelPseudos");
Andrew Trickd5422652012-02-04 02:56:48 +0000458
Andrew Trickf7b96312012-02-09 00:40:55 +0000459 // Add passes that optimize machine instructions in SSA form.
Andrew Trickd5422652012-02-04 02:56:48 +0000460 if (getOptLevel() != CodeGenOpt::None) {
Andrew Trickf7b96312012-02-09 00:40:55 +0000461 addMachineSSAOptimization();
Craig Topper8f54a532012-11-19 00:11:50 +0000462 } else {
Andrew Trickf7b96312012-02-09 00:40:55 +0000463 // If the target requests it, assign local variables to stack slots relative
464 // to one another and simplify frame index references where possible.
Bob Wilson3fb99a72012-07-02 19:48:37 +0000465 addPass(&LocalStackSlotAllocationID);
Andrew Trickd5422652012-02-04 02:56:48 +0000466 }
467
468 // Run pre-ra passes.
469 if (addPreRegAlloc())
470 printAndVerify("After PreRegAlloc passes");
471
Andrew Trickf7b96312012-02-09 00:40:55 +0000472 // Run register allocation and passes that are tightly coupled with it,
473 // including phi elimination and scheduling.
Andrew Trick8dd26252012-02-10 04:10:36 +0000474 if (getOptimizeRegAlloc())
475 addOptimizedRegAlloc(createRegAllocPass(true));
476 else
477 addFastRegAlloc(createRegAllocPass(false));
Andrew Trickd5422652012-02-04 02:56:48 +0000478
479 // Run post-ra passes.
480 if (addPostRegAlloc())
481 printAndVerify("After PostRegAlloc passes");
482
483 // Insert prolog/epilog code. Eliminate abstract frame index references...
Bob Wilson3fb99a72012-07-02 19:48:37 +0000484 addPass(&PrologEpilogCodeInserterID);
Andrew Trickd5422652012-02-04 02:56:48 +0000485 printAndVerify("After PrologEpilogCodeInserter");
486
Andrew Trickf7b96312012-02-09 00:40:55 +0000487 /// Add passes that optimize machine instructions after register allocation.
488 if (getOptLevel() != CodeGenOpt::None)
489 addMachineLateOptimization();
Andrew Trickd5422652012-02-04 02:56:48 +0000490
491 // Expand pseudo instructions before second scheduling pass.
Bob Wilson3fb99a72012-07-02 19:48:37 +0000492 addPass(&ExpandPostRAPseudosID);
Jakob Stoklund Olesen2ef5bf62012-03-28 20:49:30 +0000493 printAndVerify("After ExpandPostRAPseudos");
Andrew Trickd5422652012-02-04 02:56:48 +0000494
495 // Run pre-sched2 passes.
496 if (addPreSched2())
Jakob Stoklund Olesen78811662012-03-28 23:31:15 +0000497 printAndVerify("After PreSched2 passes");
Andrew Trickd5422652012-02-04 02:56:48 +0000498
499 // Second pass scheduler.
Andrew Trick79bf2882012-02-15 03:21:51 +0000500 if (getOptLevel() != CodeGenOpt::None) {
Bob Wilson3fb99a72012-07-02 19:48:37 +0000501 addPass(&PostRASchedulerID);
Jakob Stoklund Olesen8b4c5022012-03-28 23:54:28 +0000502 printAndVerify("After PostRAScheduler");
Andrew Trickd5422652012-02-04 02:56:48 +0000503 }
504
Andrew Trickf7b96312012-02-09 00:40:55 +0000505 // GC
Evan Chengab37b2c2012-12-21 02:57:04 +0000506 if (addGCPasses()) {
507 if (PrintGCInfo)
508 addPass(createGCInfoPrinter(dbgs()));
509 }
Andrew Trickd5422652012-02-04 02:56:48 +0000510
Andrew Trickf7b96312012-02-09 00:40:55 +0000511 // Basic block placement.
Andrew Trick79bf2882012-02-15 03:21:51 +0000512 if (getOptLevel() != CodeGenOpt::None)
Andrew Trickf7b96312012-02-09 00:40:55 +0000513 addBlockPlacement();
Andrew Trickd5422652012-02-04 02:56:48 +0000514
515 if (addPreEmitPass())
Jakob Stoklund Olesen8b4c5022012-03-28 23:54:28 +0000516 printAndVerify("After PreEmit passes");
Andrew Trickd5422652012-02-04 02:56:48 +0000517}
518
Andrew Trickf7b96312012-02-09 00:40:55 +0000519/// Add passes that optimize machine instructions in SSA form.
520void TargetPassConfig::addMachineSSAOptimization() {
521 // Pre-ra tail duplication.
Bob Wilson3fb99a72012-07-02 19:48:37 +0000522 if (addPass(&EarlyTailDuplicateID))
Andrew Trickf7b96312012-02-09 00:40:55 +0000523 printAndVerify("After Pre-RegAlloc TailDuplicate");
Andrew Trickf7b96312012-02-09 00:40:55 +0000524
525 // Optimize PHIs before DCE: removing dead PHI cycles may make more
526 // instructions dead.
Bob Wilson3fb99a72012-07-02 19:48:37 +0000527 addPass(&OptimizePHIsID);
Andrew Trickf7b96312012-02-09 00:40:55 +0000528
Nadav Rotemc05d3062012-09-06 09:17:37 +0000529 // This pass merges large allocas. StackSlotColoring is a different pass
530 // which merges spill slots.
531 addPass(&StackColoringID);
532
Andrew Trickf7b96312012-02-09 00:40:55 +0000533 // If the target requests it, assign local variables to stack slots relative
534 // to one another and simplify frame index references where possible.
Bob Wilson3fb99a72012-07-02 19:48:37 +0000535 addPass(&LocalStackSlotAllocationID);
Andrew Trickf7b96312012-02-09 00:40:55 +0000536
537 // With optimization, dead code should already be eliminated. However
538 // there is one known exception: lowered code for arguments that are only
539 // used by tail calls, where the tail calls reuse the incoming stack
540 // arguments directly (see t11 in test/CodeGen/X86/sibcall.ll).
Bob Wilson3fb99a72012-07-02 19:48:37 +0000541 addPass(&DeadMachineInstructionElimID);
Andrew Trickf7b96312012-02-09 00:40:55 +0000542 printAndVerify("After codegen DCE pass");
543
Jakob Stoklund Olesen02c63252013-01-17 00:58:38 +0000544 // Allow targets to insert passes that improve instruction level parallelism,
545 // like if-conversion. Such passes will typically need dominator trees and
546 // loop info, just like LICM and CSE below.
547 if (addILPOpts())
548 printAndVerify("After ILP optimizations");
549
Bob Wilson3fb99a72012-07-02 19:48:37 +0000550 addPass(&MachineLICMID);
551 addPass(&MachineCSEID);
552 addPass(&MachineSinkingID);
Andrew Trickf7b96312012-02-09 00:40:55 +0000553 printAndVerify("After Machine LICM, CSE and Sinking passes");
554
Bob Wilson3fb99a72012-07-02 19:48:37 +0000555 addPass(&PeepholeOptimizerID);
Andrew Trickf7b96312012-02-09 00:40:55 +0000556 printAndVerify("After codegen peephole optimization pass");
557}
558
Andrew Trick74613342012-02-04 02:56:45 +0000559//===---------------------------------------------------------------------===//
Andrew Trickf7b96312012-02-09 00:40:55 +0000560/// Register Allocation Pass Configuration
Jim Laskeyeb577ba2006-08-02 12:30:23 +0000561//===---------------------------------------------------------------------===//
Andrew Trickf7b96312012-02-09 00:40:55 +0000562
Andrew Trick8dd26252012-02-10 04:10:36 +0000563bool TargetPassConfig::getOptimizeRegAlloc() const {
564 switch (OptimizeRegAlloc) {
565 case cl::BOU_UNSET: return getOptLevel() != CodeGenOpt::None;
566 case cl::BOU_TRUE: return true;
567 case cl::BOU_FALSE: return false;
568 }
569 llvm_unreachable("Invalid optimize-regalloc state");
570}
571
Andrew Trickf7b96312012-02-09 00:40:55 +0000572/// RegisterRegAlloc's global Registry tracks allocator registration.
Jim Laskeyeb577ba2006-08-02 12:30:23 +0000573MachinePassRegistry RegisterRegAlloc::Registry;
574
Andrew Trickf7b96312012-02-09 00:40:55 +0000575/// A dummy default pass factory indicates whether the register allocator is
576/// overridden on the command line.
Andrew Trick8dd26252012-02-10 04:10:36 +0000577static FunctionPass *useDefaultRegisterAllocator() { return 0; }
Jakob Stoklund Olesen700bfad2010-05-27 23:57:25 +0000578static RegisterRegAlloc
579defaultRegAlloc("default",
580 "pick register allocator based on -O option",
Andrew Trick8dd26252012-02-10 04:10:36 +0000581 useDefaultRegisterAllocator);
Jim Laskeyeb577ba2006-08-02 12:30:23 +0000582
Andrew Trickf7b96312012-02-09 00:40:55 +0000583/// -regalloc=... command line option.
Dan Gohman844731a2008-05-13 00:00:25 +0000584static cl::opt<RegisterRegAlloc::FunctionPassCtor, false,
585 RegisterPassParser<RegisterRegAlloc> >
586RegAlloc("regalloc",
Andrew Trick8dd26252012-02-10 04:10:36 +0000587 cl::init(&useDefaultRegisterAllocator),
Jakob Stoklund Olesen700bfad2010-05-27 23:57:25 +0000588 cl::desc("Register allocator to use"));
Alkis Evlogimenos7237ece2003-10-02 16:57:49 +0000589
Jim Laskeyeb577ba2006-08-02 12:30:23 +0000590
Andrew Trick8dd26252012-02-10 04:10:36 +0000591/// Instantiate the default register allocator pass for this target for either
592/// the optimized or unoptimized allocation path. This will be added to the pass
593/// manager by addFastRegAlloc in the unoptimized case or addOptimizedRegAlloc
594/// in the optimized case.
595///
596/// A target that uses the standard regalloc pass order for fast or optimized
597/// allocation may still override this for per-target regalloc
598/// selection. But -regalloc=... always takes precedence.
599FunctionPass *TargetPassConfig::createTargetRegisterAllocator(bool Optimized) {
600 if (Optimized)
601 return createGreedyRegisterAllocator();
602 else
603 return createFastRegisterAllocator();
604}
605
606/// Find and instantiate the register allocation pass requested by this target
607/// at the current optimization level. Different register allocators are
608/// defined as separate passes because they may require different analysis.
609///
610/// This helper ensures that the regalloc= option is always available,
611/// even for targets that override the default allocator.
612///
613/// FIXME: When MachinePassRegistry register pass IDs instead of function ptrs,
614/// this can be folded into addPass.
615FunctionPass *TargetPassConfig::createRegAllocPass(bool Optimized) {
Jim Laskey9ff542f2006-08-01 18:29:48 +0000616 RegisterRegAlloc::FunctionPassCtor Ctor = RegisterRegAlloc::getDefault();
Jakob Stoklund Olesen700bfad2010-05-27 23:57:25 +0000617
Andrew Trick8dd26252012-02-10 04:10:36 +0000618 // Initialize the global default.
Jim Laskey13ec7022006-08-01 14:21:23 +0000619 if (!Ctor) {
Jim Laskeyeb577ba2006-08-02 12:30:23 +0000620 Ctor = RegAlloc;
621 RegisterRegAlloc::setDefault(RegAlloc);
Jim Laskey13ec7022006-08-01 14:21:23 +0000622 }
Andrew Trick8dd26252012-02-10 04:10:36 +0000623 if (Ctor != useDefaultRegisterAllocator)
Jakob Stoklund Olesen700bfad2010-05-27 23:57:25 +0000624 return Ctor();
625
Andrew Trick8dd26252012-02-10 04:10:36 +0000626 // With no -regalloc= override, ask the target for a regalloc pass.
627 return createTargetRegisterAllocator(Optimized);
628}
629
630/// Add the minimum set of target-independent passes that are required for
631/// register allocation. No coalescing or scheduling.
632void TargetPassConfig::addFastRegAlloc(FunctionPass *RegAllocPass) {
Bob Wilson3fb99a72012-07-02 19:48:37 +0000633 addPass(&PHIEliminationID);
634 addPass(&TwoAddressInstructionPassID);
Andrew Trick8dd26252012-02-10 04:10:36 +0000635
Bob Wilson564fbf62012-07-02 19:48:31 +0000636 addPass(RegAllocPass);
Andrew Trick8dd26252012-02-10 04:10:36 +0000637 printAndVerify("After Register Allocation");
Jim Laskey33a0a6d2006-07-27 20:05:00 +0000638}
Andrew Trickf7b96312012-02-09 00:40:55 +0000639
640/// Add standard target-independent passes that are tightly coupled with
Andrew Trick8dd26252012-02-10 04:10:36 +0000641/// optimized register allocation, including coalescing, machine instruction
642/// scheduling, and register allocation itself.
643void TargetPassConfig::addOptimizedRegAlloc(FunctionPass *RegAllocPass) {
Bob Wilson3fb99a72012-07-02 19:48:37 +0000644 addPass(&ProcessImplicitDefsID);
Jakob Stoklund Olesen5984d2b2012-06-25 18:12:18 +0000645
Andrew Trick8dd26252012-02-10 04:10:36 +0000646 // LiveVariables currently requires pure SSA form.
647 //
648 // FIXME: Once TwoAddressInstruction pass no longer uses kill flags,
649 // LiveVariables can be removed completely, and LiveIntervals can be directly
650 // computed. (We still either need to regenerate kill flags after regalloc, or
651 // preferably fix the scavenger to not depend on them).
Bob Wilson3fb99a72012-07-02 19:48:37 +0000652 addPass(&LiveVariablesID);
Andrew Trick8dd26252012-02-10 04:10:36 +0000653
654 // Add passes that move from transformed SSA into conventional SSA. This is a
655 // "copy coalescing" problem.
656 //
657 if (!EnableStrongPHIElim) {
658 // Edge splitting is smarter with machine loop info.
Bob Wilson3fb99a72012-07-02 19:48:37 +0000659 addPass(&MachineLoopInfoID);
660 addPass(&PHIEliminationID);
Andrew Trick8dd26252012-02-10 04:10:36 +0000661 }
Jakob Stoklund Olesendcc44362012-08-03 22:12:54 +0000662
663 // Eventually, we want to run LiveIntervals before PHI elimination.
664 if (EarlyLiveIntervals)
665 addPass(&LiveIntervalsID);
666
Bob Wilson3fb99a72012-07-02 19:48:37 +0000667 addPass(&TwoAddressInstructionPassID);
Andrew Trick8dd26252012-02-10 04:10:36 +0000668
Andrew Trick8dd26252012-02-10 04:10:36 +0000669 if (EnableStrongPHIElim)
Bob Wilson3fb99a72012-07-02 19:48:37 +0000670 addPass(&StrongPHIEliminationID);
Andrew Trick8dd26252012-02-10 04:10:36 +0000671
Bob Wilson3fb99a72012-07-02 19:48:37 +0000672 addPass(&RegisterCoalescerID);
Andrew Trick8dd26252012-02-10 04:10:36 +0000673
674 // PreRA instruction scheduling.
Bob Wilson3fb99a72012-07-02 19:48:37 +0000675 if (addPass(&MachineSchedulerID))
Andrew Trick17d35e52012-03-14 04:00:41 +0000676 printAndVerify("After Machine Scheduling");
Andrew Trick8dd26252012-02-10 04:10:36 +0000677
678 // Add the selected register allocation pass.
Bob Wilson564fbf62012-07-02 19:48:31 +0000679 addPass(RegAllocPass);
Jakob Stoklund Olesen34f5a2b2012-06-26 17:09:29 +0000680 printAndVerify("After Register Allocation, before rewriter");
681
682 // Allow targets to change the register assignments before rewriting.
683 if (addPreRewrite())
684 printAndVerify("After pre-rewrite passes");
Andrew Trickf7b96312012-02-09 00:40:55 +0000685
Jakob Stoklund Olesen05ec7122012-06-08 23:44:45 +0000686 // Finally rewrite virtual registers.
Bob Wilson3fb99a72012-07-02 19:48:37 +0000687 addPass(&VirtRegRewriterID);
Jakob Stoklund Olesen05ec7122012-06-08 23:44:45 +0000688 printAndVerify("After Virtual Register Rewriter");
689
Andrew Trick746f24b2012-02-11 07:11:32 +0000690 // FinalizeRegAlloc is convenient until MachineInstrBundles is more mature,
691 // but eventually, all users of it should probably be moved to addPostRA and
692 // it can go away. Currently, it's the intended place for targets to run
693 // FinalizeMachineBundles, because passes other than MachineScheduling an
694 // RegAlloc itself may not be aware of bundles.
695 if (addFinalizeRegAlloc())
696 printAndVerify("After RegAlloc finalization");
697
Andrew Trickf7b96312012-02-09 00:40:55 +0000698 // Perform stack slot coloring and post-ra machine LICM.
Andrew Trick8dd26252012-02-10 04:10:36 +0000699 //
700 // FIXME: Re-enable coloring with register when it's capable of adding
701 // kill markers.
Bob Wilson3fb99a72012-07-02 19:48:37 +0000702 addPass(&StackSlotColoringID);
Andrew Trick900d7b72012-02-15 07:57:03 +0000703
704 // Run post-ra machine LICM to hoist reloads / remats.
705 //
706 // FIXME: can this move into MachineLateOptimization?
Bob Wilson3fb99a72012-07-02 19:48:37 +0000707 addPass(&PostRAMachineLICMID);
Andrew Trick900d7b72012-02-15 07:57:03 +0000708
709 printAndVerify("After StackSlotColoring and postra Machine LICM");
Andrew Trickf7b96312012-02-09 00:40:55 +0000710}
711
712//===---------------------------------------------------------------------===//
713/// Post RegAlloc Pass Configuration
714//===---------------------------------------------------------------------===//
715
716/// Add passes that optimize machine instructions after register allocation.
717void TargetPassConfig::addMachineLateOptimization() {
718 // Branch folding must be run after regalloc and prolog/epilog insertion.
Bob Wilson3fb99a72012-07-02 19:48:37 +0000719 if (addPass(&BranchFolderPassID))
Jakob Stoklund Olesen663ee202012-03-28 20:47:37 +0000720 printAndVerify("After BranchFolding");
Andrew Trickf7b96312012-02-09 00:40:55 +0000721
722 // Tail duplication.
Bob Wilson3fb99a72012-07-02 19:48:37 +0000723 if (addPass(&TailDuplicateID))
Jakob Stoklund Olesen663ee202012-03-28 20:47:37 +0000724 printAndVerify("After TailDuplicate");
Andrew Trickf7b96312012-02-09 00:40:55 +0000725
726 // Copy propagation.
Bob Wilson3fb99a72012-07-02 19:48:37 +0000727 if (addPass(&MachineCopyPropagationID))
Jakob Stoklund Olesen663ee202012-03-28 20:47:37 +0000728 printAndVerify("After copy propagation pass");
Andrew Trickf7b96312012-02-09 00:40:55 +0000729}
730
Evan Chengab37b2c2012-12-21 02:57:04 +0000731/// Add standard GC passes.
732bool TargetPassConfig::addGCPasses() {
733 addPass(&GCMachineCodeAnalysisID);
734 return true;
735}
736
Andrew Trickf7b96312012-02-09 00:40:55 +0000737/// Add standard basic block placement passes.
738void TargetPassConfig::addBlockPlacement() {
Benjamin Kramer74a45332013-03-29 17:14:24 +0000739 if (addPass(&MachineBlockPlacementID)) {
Andrew Trick79bf2882012-02-15 03:21:51 +0000740 // Run a separate pass to collect block placement statistics.
741 if (EnableBlockPlacementStats)
Bob Wilson3fb99a72012-07-02 19:48:37 +0000742 addPass(&MachineBlockPlacementStatsID);
Andrew Trickf7b96312012-02-09 00:40:55 +0000743
Jakob Stoklund Olesen8b4c5022012-03-28 23:54:28 +0000744 printAndVerify("After machine block placement.");
Andrew Trickf7b96312012-02-09 00:40:55 +0000745 }
746}