blob: 5a7ec66e086561802de9d622123e6c8f86c4af1d [file] [log] [blame]
Chris Lattneraa4c91f2003-12-28 07:59:53 +00001//===-- Passes.cpp - Target independent code generation passes ------------===//
Misha Brukmanedf128a2005-04-21 22:36:52 +00002//
John Criswellb576c942003-10-20 19:43:21 +00003// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Misha Brukmanedf128a2005-04-21 22:36:52 +00007//
John Criswellb576c942003-10-20 19:43:21 +00008//===----------------------------------------------------------------------===//
Alkis Evlogimenos7237ece2003-10-02 16:57:49 +00009//
10// This file defines interfaces to access the target independent code
11// generation passes provided by the LLVM backend.
12//
13//===---------------------------------------------------------------------===//
14
Andrew Trickd5422652012-02-04 02:56:48 +000015#include "llvm/Analysis/Passes.h"
16#include "llvm/Analysis/Verifier.h"
17#include "llvm/Transforms/Scalar.h"
18#include "llvm/PassManager.h"
19#include "llvm/CodeGen/GCStrategy.h"
Andrew Trickd5422652012-02-04 02:56:48 +000020#include "llvm/CodeGen/MachineFunctionPass.h"
Alkis Evlogimenos7237ece2003-10-02 16:57:49 +000021#include "llvm/CodeGen/Passes.h"
Andrew Trickd5422652012-02-04 02:56:48 +000022#include "llvm/CodeGen/RegAllocRegistry.h"
23#include "llvm/Target/TargetLowering.h"
Andrew Trickd5422652012-02-04 02:56:48 +000024#include "llvm/Target/TargetOptions.h"
Andrew Trickd5422652012-02-04 02:56:48 +000025#include "llvm/Assembly/PrintModulePass.h"
26#include "llvm/Support/CommandLine.h"
27#include "llvm/Support/Debug.h"
Andrew Trick74613342012-02-04 02:56:45 +000028#include "llvm/Support/ErrorHandling.h"
Jim Laskey13ec7022006-08-01 14:21:23 +000029
Chris Lattneraa4c91f2003-12-28 07:59:53 +000030using namespace llvm;
Brian Gaeked0fde302003-11-11 22:41:34 +000031
Andrew Trickd5422652012-02-04 02:56:48 +000032static cl::opt<bool> DisablePostRA("disable-post-ra", cl::Hidden,
33 cl::desc("Disable Post Regalloc"));
34static cl::opt<bool> DisableBranchFold("disable-branch-fold", cl::Hidden,
35 cl::desc("Disable branch folding"));
36static cl::opt<bool> DisableTailDuplicate("disable-tail-duplicate", cl::Hidden,
37 cl::desc("Disable tail duplication"));
38static cl::opt<bool> DisableEarlyTailDup("disable-early-taildup", cl::Hidden,
39 cl::desc("Disable pre-register allocation tail duplication"));
40static cl::opt<bool> EnableBlockPlacement("enable-block-placement",
41 cl::Hidden, cl::desc("Enable probability-driven block placement"));
42static cl::opt<bool> EnableBlockPlacementStats("enable-block-placement-stats",
43 cl::Hidden, cl::desc("Collect probability-driven block placement stats"));
44static cl::opt<bool> DisableCodePlace("disable-code-place", cl::Hidden,
45 cl::desc("Disable code placement"));
46static cl::opt<bool> DisableSSC("disable-ssc", cl::Hidden,
47 cl::desc("Disable Stack Slot Coloring"));
48static cl::opt<bool> DisableMachineDCE("disable-machine-dce", cl::Hidden,
49 cl::desc("Disable Machine Dead Code Elimination"));
50static cl::opt<bool> DisableMachineLICM("disable-machine-licm", cl::Hidden,
51 cl::desc("Disable Machine LICM"));
52static cl::opt<bool> DisableMachineCSE("disable-machine-cse", cl::Hidden,
53 cl::desc("Disable Machine Common Subexpression Elimination"));
Andrew Trick8dd26252012-02-10 04:10:36 +000054static cl::opt<cl::boolOrDefault>
55OptimizeRegAlloc("optimize-regalloc", cl::Hidden,
56 cl::desc("Enable optimized register allocation compilation path."));
57static cl::opt<bool> EnableMachineSched("enable-misched", cl::Hidden,
58 cl::desc("Enable the machine instruction scheduling pass."));
59static cl::opt<bool> EnableStrongPHIElim("strong-phi-elim", cl::Hidden,
60 cl::desc("Use strong PHI elimination."));
Andrew Trickd5422652012-02-04 02:56:48 +000061static cl::opt<bool> DisablePostRAMachineLICM("disable-postra-machine-licm",
62 cl::Hidden,
63 cl::desc("Disable Machine LICM"));
64static cl::opt<bool> DisableMachineSink("disable-machine-sink", cl::Hidden,
65 cl::desc("Disable Machine Sinking"));
66static cl::opt<bool> DisableLSR("disable-lsr", cl::Hidden,
67 cl::desc("Disable Loop Strength Reduction Pass"));
68static cl::opt<bool> DisableCGP("disable-cgp", cl::Hidden,
69 cl::desc("Disable Codegen Prepare"));
70static cl::opt<bool> DisableCopyProp("disable-copyprop", cl::Hidden,
71 cl::desc("Disable Copy Propagation pass"));
72static cl::opt<bool> PrintLSR("print-lsr-output", cl::Hidden,
73 cl::desc("Print LLVM IR produced by the loop-reduce pass"));
74static cl::opt<bool> PrintISelInput("print-isel-input", cl::Hidden,
75 cl::desc("Print LLVM IR input to isel pass"));
76static cl::opt<bool> PrintGCInfo("print-gc", cl::Hidden,
77 cl::desc("Dump garbage collector data"));
78static cl::opt<bool> VerifyMachineCode("verify-machineinstrs", cl::Hidden,
79 cl::desc("Verify generated machine code"),
80 cl::init(getenv("LLVM_VERIFY_MACHINEINSTRS")!=NULL));
81
Jim Laskeyeb577ba2006-08-02 12:30:23 +000082//===---------------------------------------------------------------------===//
Andrew Trick74613342012-02-04 02:56:45 +000083/// TargetPassConfig
84//===---------------------------------------------------------------------===//
85
86INITIALIZE_PASS(TargetPassConfig, "targetpassconfig",
87 "Target Pass Configuration", false, false)
88char TargetPassConfig::ID = 0;
89
90// Out of line virtual method.
91TargetPassConfig::~TargetPassConfig() {}
92
Andrew Trick61f1e3d2012-02-08 21:22:48 +000093// Out of line constructor provides default values for pass options and
94// registers all common codegen passes.
Andrew Trick061efcf2012-02-04 02:56:59 +000095TargetPassConfig::TargetPassConfig(TargetMachine *tm, PassManagerBase &pm)
Andrew Trickffea03f2012-02-08 21:22:39 +000096 : ImmutablePass(ID), TM(tm), PM(pm), Initialized(false),
97 DisableVerify(false),
98 EnableTailMerge(true) {
99
Andrew Trick74613342012-02-04 02:56:45 +0000100 // Register all target independent codegen passes to activate their PassIDs,
101 // including this pass itself.
102 initializeCodeGen(*PassRegistry::getPassRegistry());
103}
104
105/// createPassConfig - Create a pass configuration object to be used by
106/// addPassToEmitX methods for generating a pipeline of CodeGen passes.
107///
108/// Targets may override this to extend TargetPassConfig.
Andrew Trick061efcf2012-02-04 02:56:59 +0000109TargetPassConfig *LLVMTargetMachine::createPassConfig(PassManagerBase &PM) {
110 return new TargetPassConfig(this, PM);
Andrew Trick74613342012-02-04 02:56:45 +0000111}
112
113TargetPassConfig::TargetPassConfig()
114 : ImmutablePass(ID), PM(*(PassManagerBase*)0) {
115 llvm_unreachable("TargetPassConfig should not be constructed on-the-fly");
116}
117
Andrew Trickffea03f2012-02-08 21:22:39 +0000118// Helper to verify the analysis is really immutable.
119void TargetPassConfig::setOpt(bool &Opt, bool Val) {
120 assert(!Initialized && "PassConfig is immutable");
121 Opt = Val;
122}
123
Andrew Trickebe18ef2012-02-08 21:22:34 +0000124void TargetPassConfig::addPass(char &ID) {
125 // FIXME: check user overrides
126 Pass *P = Pass::createPass(ID);
127 if (!P)
128 llvm_unreachable("Pass ID not registered");
129 PM.add(P);
Andrew Trick061efcf2012-02-04 02:56:59 +0000130}
Andrew Trickd5422652012-02-04 02:56:48 +0000131
132void TargetPassConfig::printNoVerify(const char *Banner) const {
133 if (TM->shouldPrintMachineCode())
134 PM.add(createMachineFunctionPrinterPass(dbgs(), Banner));
135}
136
137void TargetPassConfig::printAndVerify(const char *Banner) const {
138 if (TM->shouldPrintMachineCode())
139 PM.add(createMachineFunctionPrinterPass(dbgs(), Banner));
140
141 if (VerifyMachineCode)
142 PM.add(createMachineVerifierPass(Banner));
143}
144
Andrew Trick061efcf2012-02-04 02:56:59 +0000145/// Add common target configurable passes that perform LLVM IR to IR transforms
146/// following machine independent optimization.
147void TargetPassConfig::addIRPasses() {
Andrew Trickd5422652012-02-04 02:56:48 +0000148 // Basic AliasAnalysis support.
149 // Add TypeBasedAliasAnalysis before BasicAliasAnalysis so that
150 // BasicAliasAnalysis wins if they disagree. This is intended to help
151 // support "obvious" type-punning idioms.
152 PM.add(createTypeBasedAliasAnalysisPass());
153 PM.add(createBasicAliasAnalysisPass());
154
155 // Before running any passes, run the verifier to determine if the input
156 // coming from the front-end and/or optimizer is valid.
157 if (!DisableVerify)
158 PM.add(createVerifierPass());
159
160 // Run loop strength reduction before anything else.
161 if (getOptLevel() != CodeGenOpt::None && !DisableLSR) {
162 PM.add(createLoopStrengthReducePass(getTargetLowering()));
163 if (PrintLSR)
164 PM.add(createPrintFunctionPass("\n\n*** Code after LSR ***\n", &dbgs()));
165 }
166
167 PM.add(createGCLoweringPass());
168
169 // Make sure that no unreachable blocks are instruction selected.
170 PM.add(createUnreachableBlockEliminationPass());
Andrew Trick061efcf2012-02-04 02:56:59 +0000171}
Andrew Trickd5422652012-02-04 02:56:48 +0000172
Andrew Trick061efcf2012-02-04 02:56:59 +0000173/// Add common passes that perform LLVM IR to IR transforms in preparation for
174/// instruction selection.
175void TargetPassConfig::addISelPrepare() {
Andrew Trickd5422652012-02-04 02:56:48 +0000176 if (getOptLevel() != CodeGenOpt::None && !DisableCGP)
177 PM.add(createCodeGenPreparePass(getTargetLowering()));
178
179 PM.add(createStackProtectorPass(getTargetLowering()));
180
181 addPreISel();
182
183 if (PrintISelInput)
184 PM.add(createPrintFunctionPass("\n\n"
185 "*** Final LLVM Code input to ISel ***\n",
186 &dbgs()));
187
188 // All passes which modify the LLVM IR are now complete; run the verifier
189 // to ensure that the IR is valid.
190 if (!DisableVerify)
191 PM.add(createVerifierPass());
Andrew Trick061efcf2012-02-04 02:56:59 +0000192}
Andrew Trickd5422652012-02-04 02:56:48 +0000193
Andrew Trickf7b96312012-02-09 00:40:55 +0000194/// Add the complete set of target-independent postISel code generator passes.
195///
196/// This can be read as the standard order of major LLVM CodeGen stages. Stages
197/// with nontrivial configuration or multiple passes are broken out below in
198/// add%Stage routines.
199///
200/// Any TargetPassConfig::addXX routine may be overriden by the Target. The
201/// addPre/Post methods with empty header implementations allow injecting
202/// target-specific fixups just before or after major stages. Additionally,
203/// targets have the flexibility to change pass order within a stage by
204/// overriding default implementation of add%Stage routines below. Each
205/// technique has maintainability tradeoffs because alternate pass orders are
206/// not well supported. addPre/Post works better if the target pass is easily
207/// tied to a common pass. But if it has subtle dependencies on multiple passes,
208/// overriding the stage instead.
209///
210/// TODO: We could use a single addPre/Post(ID) hook to allow pass injection
211/// before/after any target-independent pass. But it's currently overkill.
Andrew Trick061efcf2012-02-04 02:56:59 +0000212void TargetPassConfig::addMachinePasses() {
Andrew Trickd5422652012-02-04 02:56:48 +0000213 // Print the instruction selected machine code...
214 printAndVerify("After Instruction Selection");
215
216 // Expand pseudo-instructions emitted by ISel.
Andrew Trick1dd8c852012-02-08 21:23:13 +0000217 addPass(ExpandISelPseudosID);
Andrew Trickd5422652012-02-04 02:56:48 +0000218
Andrew Trickf7b96312012-02-09 00:40:55 +0000219 // Add passes that optimize machine instructions in SSA form.
Andrew Trickd5422652012-02-04 02:56:48 +0000220 if (getOptLevel() != CodeGenOpt::None) {
Andrew Trickf7b96312012-02-09 00:40:55 +0000221 addMachineSSAOptimization();
222 }
223 else {
224 // If the target requests it, assign local variables to stack slots relative
225 // to one another and simplify frame index references where possible.
226 addPass(LocalStackSlotAllocationID);
Andrew Trickd5422652012-02-04 02:56:48 +0000227 }
228
229 // Run pre-ra passes.
230 if (addPreRegAlloc())
231 printAndVerify("After PreRegAlloc passes");
232
Andrew Trickf7b96312012-02-09 00:40:55 +0000233 // Run register allocation and passes that are tightly coupled with it,
234 // including phi elimination and scheduling.
Andrew Trick8dd26252012-02-10 04:10:36 +0000235 if (getOptimizeRegAlloc())
236 addOptimizedRegAlloc(createRegAllocPass(true));
237 else
238 addFastRegAlloc(createRegAllocPass(false));
Andrew Trickd5422652012-02-04 02:56:48 +0000239
240 // Run post-ra passes.
241 if (addPostRegAlloc())
242 printAndVerify("After PostRegAlloc passes");
243
244 // Insert prolog/epilog code. Eliminate abstract frame index references...
Andrew Trick1dd8c852012-02-08 21:23:13 +0000245 addPass(PrologEpilogCodeInserterID);
Andrew Trickd5422652012-02-04 02:56:48 +0000246 printAndVerify("After PrologEpilogCodeInserter");
247
Andrew Trickf7b96312012-02-09 00:40:55 +0000248 /// Add passes that optimize machine instructions after register allocation.
249 if (getOptLevel() != CodeGenOpt::None)
250 addMachineLateOptimization();
Andrew Trickd5422652012-02-04 02:56:48 +0000251
252 // Expand pseudo instructions before second scheduling pass.
Andrew Trick1dd8c852012-02-08 21:23:13 +0000253 addPass(ExpandPostRAPseudosID);
Andrew Trickd5422652012-02-04 02:56:48 +0000254 printNoVerify("After ExpandPostRAPseudos");
255
256 // Run pre-sched2 passes.
257 if (addPreSched2())
258 printNoVerify("After PreSched2 passes");
259
260 // Second pass scheduler.
261 if (getOptLevel() != CodeGenOpt::None && !DisablePostRA) {
Andrew Trick1dd8c852012-02-08 21:23:13 +0000262 addPass(PostRASchedulerID);
Andrew Trickd5422652012-02-04 02:56:48 +0000263 printNoVerify("After PostRAScheduler");
264 }
265
Andrew Trickf7b96312012-02-09 00:40:55 +0000266 // GC
Andrew Trick1dd8c852012-02-08 21:23:13 +0000267 addPass(GCMachineCodeAnalysisID);
Andrew Trickd5422652012-02-04 02:56:48 +0000268 if (PrintGCInfo)
269 PM.add(createGCInfoPrinter(dbgs()));
270
Andrew Trickf7b96312012-02-09 00:40:55 +0000271 // Basic block placement.
272 if (getOptLevel() != CodeGenOpt::None && !DisableCodePlace)
273 addBlockPlacement();
Andrew Trickd5422652012-02-04 02:56:48 +0000274
275 if (addPreEmitPass())
276 printNoVerify("After PreEmit passes");
Andrew Trickd5422652012-02-04 02:56:48 +0000277}
278
Andrew Trickf7b96312012-02-09 00:40:55 +0000279/// Add passes that optimize machine instructions in SSA form.
280void TargetPassConfig::addMachineSSAOptimization() {
281 // Pre-ra tail duplication.
282 if (!DisableEarlyTailDup) {
283 addPass(TailDuplicateID);
284 printAndVerify("After Pre-RegAlloc TailDuplicate");
285 }
286
287 // Optimize PHIs before DCE: removing dead PHI cycles may make more
288 // instructions dead.
289 addPass(OptimizePHIsID);
290
291 // If the target requests it, assign local variables to stack slots relative
292 // to one another and simplify frame index references where possible.
293 addPass(LocalStackSlotAllocationID);
294
295 // With optimization, dead code should already be eliminated. However
296 // there is one known exception: lowered code for arguments that are only
297 // used by tail calls, where the tail calls reuse the incoming stack
298 // arguments directly (see t11 in test/CodeGen/X86/sibcall.ll).
299 if (!DisableMachineDCE)
300 addPass(DeadMachineInstructionElimID);
301 printAndVerify("After codegen DCE pass");
302
303 if (!DisableMachineLICM)
304 addPass(MachineLICMID);
305 if (!DisableMachineCSE)
306 addPass(MachineCSEID);
307 if (!DisableMachineSink)
308 addPass(MachineSinkingID);
309 printAndVerify("After Machine LICM, CSE and Sinking passes");
310
311 addPass(PeepholeOptimizerID);
312 printAndVerify("After codegen peephole optimization pass");
313}
314
Andrew Trick74613342012-02-04 02:56:45 +0000315//===---------------------------------------------------------------------===//
Andrew Trickf7b96312012-02-09 00:40:55 +0000316/// Register Allocation Pass Configuration
Jim Laskeyeb577ba2006-08-02 12:30:23 +0000317//===---------------------------------------------------------------------===//
Andrew Trickf7b96312012-02-09 00:40:55 +0000318
Andrew Trick8dd26252012-02-10 04:10:36 +0000319bool TargetPassConfig::getOptimizeRegAlloc() const {
320 switch (OptimizeRegAlloc) {
321 case cl::BOU_UNSET: return getOptLevel() != CodeGenOpt::None;
322 case cl::BOU_TRUE: return true;
323 case cl::BOU_FALSE: return false;
324 }
325 llvm_unreachable("Invalid optimize-regalloc state");
326}
327
Andrew Trickf7b96312012-02-09 00:40:55 +0000328/// RegisterRegAlloc's global Registry tracks allocator registration.
Jim Laskeyeb577ba2006-08-02 12:30:23 +0000329MachinePassRegistry RegisterRegAlloc::Registry;
330
Andrew Trickf7b96312012-02-09 00:40:55 +0000331/// A dummy default pass factory indicates whether the register allocator is
332/// overridden on the command line.
Andrew Trick8dd26252012-02-10 04:10:36 +0000333static FunctionPass *useDefaultRegisterAllocator() { return 0; }
Jakob Stoklund Olesen700bfad2010-05-27 23:57:25 +0000334static RegisterRegAlloc
335defaultRegAlloc("default",
336 "pick register allocator based on -O option",
Andrew Trick8dd26252012-02-10 04:10:36 +0000337 useDefaultRegisterAllocator);
Jim Laskeyeb577ba2006-08-02 12:30:23 +0000338
Andrew Trickf7b96312012-02-09 00:40:55 +0000339/// -regalloc=... command line option.
Dan Gohman844731a2008-05-13 00:00:25 +0000340static cl::opt<RegisterRegAlloc::FunctionPassCtor, false,
341 RegisterPassParser<RegisterRegAlloc> >
342RegAlloc("regalloc",
Andrew Trick8dd26252012-02-10 04:10:36 +0000343 cl::init(&useDefaultRegisterAllocator),
Jakob Stoklund Olesen700bfad2010-05-27 23:57:25 +0000344 cl::desc("Register allocator to use"));
Alkis Evlogimenos7237ece2003-10-02 16:57:49 +0000345
Jim Laskeyeb577ba2006-08-02 12:30:23 +0000346
Andrew Trick8dd26252012-02-10 04:10:36 +0000347/// Instantiate the default register allocator pass for this target for either
348/// the optimized or unoptimized allocation path. This will be added to the pass
349/// manager by addFastRegAlloc in the unoptimized case or addOptimizedRegAlloc
350/// in the optimized case.
351///
352/// A target that uses the standard regalloc pass order for fast or optimized
353/// allocation may still override this for per-target regalloc
354/// selection. But -regalloc=... always takes precedence.
355FunctionPass *TargetPassConfig::createTargetRegisterAllocator(bool Optimized) {
356 if (Optimized)
357 return createGreedyRegisterAllocator();
358 else
359 return createFastRegisterAllocator();
360}
361
362/// Find and instantiate the register allocation pass requested by this target
363/// at the current optimization level. Different register allocators are
364/// defined as separate passes because they may require different analysis.
365///
366/// This helper ensures that the regalloc= option is always available,
367/// even for targets that override the default allocator.
368///
369/// FIXME: When MachinePassRegistry register pass IDs instead of function ptrs,
370/// this can be folded into addPass.
371FunctionPass *TargetPassConfig::createRegAllocPass(bool Optimized) {
Jim Laskey9ff542f2006-08-01 18:29:48 +0000372 RegisterRegAlloc::FunctionPassCtor Ctor = RegisterRegAlloc::getDefault();
Jakob Stoklund Olesen700bfad2010-05-27 23:57:25 +0000373
Andrew Trick8dd26252012-02-10 04:10:36 +0000374 // Initialize the global default.
Jim Laskey13ec7022006-08-01 14:21:23 +0000375 if (!Ctor) {
Jim Laskeyeb577ba2006-08-02 12:30:23 +0000376 Ctor = RegAlloc;
377 RegisterRegAlloc::setDefault(RegAlloc);
Jim Laskey13ec7022006-08-01 14:21:23 +0000378 }
Andrew Trick8dd26252012-02-10 04:10:36 +0000379 if (Ctor != useDefaultRegisterAllocator)
Jakob Stoklund Olesen700bfad2010-05-27 23:57:25 +0000380 return Ctor();
381
Andrew Trick8dd26252012-02-10 04:10:36 +0000382 // With no -regalloc= override, ask the target for a regalloc pass.
383 return createTargetRegisterAllocator(Optimized);
384}
385
386/// Add the minimum set of target-independent passes that are required for
387/// register allocation. No coalescing or scheduling.
388void TargetPassConfig::addFastRegAlloc(FunctionPass *RegAllocPass) {
389 addPass(PHIEliminationID);
390 addPass(TwoAddressInstructionPassID);
391
392 PM.add(RegAllocPass);
393 printAndVerify("After Register Allocation");
Jim Laskey33a0a6d2006-07-27 20:05:00 +0000394}
Andrew Trickf7b96312012-02-09 00:40:55 +0000395
396/// Add standard target-independent passes that are tightly coupled with
Andrew Trick8dd26252012-02-10 04:10:36 +0000397/// optimized register allocation, including coalescing, machine instruction
398/// scheduling, and register allocation itself.
399void TargetPassConfig::addOptimizedRegAlloc(FunctionPass *RegAllocPass) {
400 // LiveVariables currently requires pure SSA form.
401 //
402 // FIXME: Once TwoAddressInstruction pass no longer uses kill flags,
403 // LiveVariables can be removed completely, and LiveIntervals can be directly
404 // computed. (We still either need to regenerate kill flags after regalloc, or
405 // preferably fix the scavenger to not depend on them).
406 addPass(LiveVariablesID);
407
408 // Add passes that move from transformed SSA into conventional SSA. This is a
409 // "copy coalescing" problem.
410 //
411 if (!EnableStrongPHIElim) {
412 // Edge splitting is smarter with machine loop info.
413 addPass(MachineLoopInfoID);
414 addPass(PHIEliminationID);
415 }
416 addPass(TwoAddressInstructionPassID);
417
418 // FIXME: Either remove this pass completely, or fix it so that it works on
419 // SSA form. We could modify LiveIntervals to be independent of this pass, But
420 // it would be even better to simply eliminate *all* IMPLICIT_DEFs before
421 // leaving SSA.
422 addPass(ProcessImplicitDefsID);
423
424 if (EnableStrongPHIElim)
425 addPass(StrongPHIEliminationID);
426
427 addPass(RegisterCoalescerID);
428
429 // PreRA instruction scheduling.
430 if (EnableMachineSched)
431 addPass(MachineSchedulerID);
432
433 // Add the selected register allocation pass.
434 PM.add(RegAllocPass);
Andrew Trickf7b96312012-02-09 00:40:55 +0000435 printAndVerify("After Register Allocation");
436
437 // Perform stack slot coloring and post-ra machine LICM.
Andrew Trick8dd26252012-02-10 04:10:36 +0000438 //
439 // FIXME: Re-enable coloring with register when it's capable of adding
440 // kill markers.
441 if (!DisableSSC)
442 addPass(StackSlotColoringID);
Andrew Trickf7b96312012-02-09 00:40:55 +0000443
Andrew Trick8dd26252012-02-10 04:10:36 +0000444 // Run post-ra machine LICM to hoist reloads / remats.
445 //
446 // FIXME: can this move into MachineLateOptimization?
447 if (!DisablePostRAMachineLICM)
448 addPass(MachineLICMID);
Andrew Trickf7b96312012-02-09 00:40:55 +0000449
Andrew Trick8dd26252012-02-10 04:10:36 +0000450 printAndVerify("After StackSlotColoring and postra Machine LICM");
Andrew Trickf7b96312012-02-09 00:40:55 +0000451}
452
453//===---------------------------------------------------------------------===//
454/// Post RegAlloc Pass Configuration
455//===---------------------------------------------------------------------===//
456
457/// Add passes that optimize machine instructions after register allocation.
458void TargetPassConfig::addMachineLateOptimization() {
459 // Branch folding must be run after regalloc and prolog/epilog insertion.
460 if (!DisableBranchFold) {
461 addPass(BranchFolderPassID);
462 printNoVerify("After BranchFolding");
463 }
464
465 // Tail duplication.
466 if (!DisableTailDuplicate) {
467 addPass(TailDuplicateID);
468 printNoVerify("After TailDuplicate");
469 }
470
471 // Copy propagation.
472 if (!DisableCopyProp) {
473 addPass(MachineCopyPropagationID);
474 printNoVerify("After copy propagation pass");
475 }
476}
477
478/// Add standard basic block placement passes.
479void TargetPassConfig::addBlockPlacement() {
480 if (EnableBlockPlacement) {
481 // MachineBlockPlacement is an experimental pass which is disabled by
482 // default currently. Eventually it should subsume CodePlacementOpt, so
483 // when enabled, the other is disabled.
484 addPass(MachineBlockPlacementID);
485 printNoVerify("After MachineBlockPlacement");
486 } else {
487 addPass(CodePlacementOptID);
488 printNoVerify("After CodePlacementOpt");
489 }
490
491 // Run a separate pass to collect block placement statistics.
492 if (EnableBlockPlacementStats) {
493 addPass(MachineBlockPlacementStatsID);
494 printNoVerify("After MachineBlockPlacementStats");
495 }
496}