Chris Lattner | aa4c91f | 2003-12-28 07:59:53 +0000 | [diff] [blame] | 1 | //===-- Passes.cpp - Target independent code generation passes ------------===// |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 2 | // |
John Criswell | b576c94 | 2003-10-20 19:43:21 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 4ee451d | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 7 | // |
John Criswell | b576c94 | 2003-10-20 19:43:21 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
Alkis Evlogimenos | 7237ece | 2003-10-02 16:57:49 +0000 | [diff] [blame] | 9 | // |
| 10 | // This file defines interfaces to access the target independent code |
| 11 | // generation passes provided by the LLVM backend. |
| 12 | // |
| 13 | //===---------------------------------------------------------------------===// |
| 14 | |
Andrew Trick | d542265 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 15 | #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 Trick | d542265 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 20 | #include "llvm/CodeGen/MachineFunctionPass.h" |
Alkis Evlogimenos | 7237ece | 2003-10-02 16:57:49 +0000 | [diff] [blame] | 21 | #include "llvm/CodeGen/Passes.h" |
Andrew Trick | d542265 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 22 | #include "llvm/CodeGen/RegAllocRegistry.h" |
| 23 | #include "llvm/Target/TargetLowering.h" |
Andrew Trick | d542265 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 24 | #include "llvm/Target/TargetOptions.h" |
Andrew Trick | d542265 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 25 | #include "llvm/Assembly/PrintModulePass.h" |
| 26 | #include "llvm/Support/CommandLine.h" |
| 27 | #include "llvm/Support/Debug.h" |
Andrew Trick | 7461334 | 2012-02-04 02:56:45 +0000 | [diff] [blame] | 28 | #include "llvm/Support/ErrorHandling.h" |
Jim Laskey | 13ec702 | 2006-08-01 14:21:23 +0000 | [diff] [blame] | 29 | |
Chris Lattner | aa4c91f | 2003-12-28 07:59:53 +0000 | [diff] [blame] | 30 | using namespace llvm; |
Brian Gaeke | d0fde30 | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 31 | |
Andrew Trick | d542265 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 32 | static cl::opt<bool> DisablePostRA("disable-post-ra", cl::Hidden, |
| 33 | cl::desc("Disable Post Regalloc")); |
| 34 | static cl::opt<bool> DisableBranchFold("disable-branch-fold", cl::Hidden, |
| 35 | cl::desc("Disable branch folding")); |
| 36 | static cl::opt<bool> DisableTailDuplicate("disable-tail-duplicate", cl::Hidden, |
| 37 | cl::desc("Disable tail duplication")); |
| 38 | static cl::opt<bool> DisableEarlyTailDup("disable-early-taildup", cl::Hidden, |
| 39 | cl::desc("Disable pre-register allocation tail duplication")); |
Chandler Carruth | 9e67db4 | 2012-04-16 13:49:17 +0000 | [diff] [blame^] | 40 | static cl::opt<bool> DisableBlockPlacement("disable-block-placement", |
| 41 | cl::Hidden, cl::desc("Disable the probability-driven block placement, and " |
| 42 | "re-enable the old code placement pass")); |
Andrew Trick | d542265 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 43 | static cl::opt<bool> EnableBlockPlacementStats("enable-block-placement-stats", |
| 44 | cl::Hidden, cl::desc("Collect probability-driven block placement stats")); |
| 45 | static cl::opt<bool> DisableCodePlace("disable-code-place", cl::Hidden, |
| 46 | cl::desc("Disable code placement")); |
| 47 | static cl::opt<bool> DisableSSC("disable-ssc", cl::Hidden, |
| 48 | cl::desc("Disable Stack Slot Coloring")); |
| 49 | static cl::opt<bool> DisableMachineDCE("disable-machine-dce", cl::Hidden, |
| 50 | cl::desc("Disable Machine Dead Code Elimination")); |
| 51 | static cl::opt<bool> DisableMachineLICM("disable-machine-licm", cl::Hidden, |
| 52 | cl::desc("Disable Machine LICM")); |
| 53 | static cl::opt<bool> DisableMachineCSE("disable-machine-cse", cl::Hidden, |
| 54 | cl::desc("Disable Machine Common Subexpression Elimination")); |
Andrew Trick | 8dd2625 | 2012-02-10 04:10:36 +0000 | [diff] [blame] | 55 | static cl::opt<cl::boolOrDefault> |
| 56 | OptimizeRegAlloc("optimize-regalloc", cl::Hidden, |
| 57 | cl::desc("Enable optimized register allocation compilation path.")); |
Andrew Trick | 746f24b | 2012-02-11 07:11:32 +0000 | [diff] [blame] | 58 | static cl::opt<cl::boolOrDefault> |
| 59 | EnableMachineSched("enable-misched", cl::Hidden, |
Andrew Trick | 8dd2625 | 2012-02-10 04:10:36 +0000 | [diff] [blame] | 60 | cl::desc("Enable the machine instruction scheduling pass.")); |
| 61 | static cl::opt<bool> EnableStrongPHIElim("strong-phi-elim", cl::Hidden, |
| 62 | cl::desc("Use strong PHI elimination.")); |
Andrew Trick | d542265 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 63 | static cl::opt<bool> DisablePostRAMachineLICM("disable-postra-machine-licm", |
| 64 | cl::Hidden, |
| 65 | cl::desc("Disable Machine LICM")); |
| 66 | static cl::opt<bool> DisableMachineSink("disable-machine-sink", cl::Hidden, |
| 67 | cl::desc("Disable Machine Sinking")); |
| 68 | static cl::opt<bool> DisableLSR("disable-lsr", cl::Hidden, |
| 69 | cl::desc("Disable Loop Strength Reduction Pass")); |
| 70 | static cl::opt<bool> DisableCGP("disable-cgp", cl::Hidden, |
| 71 | cl::desc("Disable Codegen Prepare")); |
| 72 | static cl::opt<bool> DisableCopyProp("disable-copyprop", cl::Hidden, |
Evan Cheng | 01b623c | 2012-02-20 23:28:17 +0000 | [diff] [blame] | 73 | cl::desc("Disable Copy Propagation pass")); |
Andrew Trick | d542265 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 74 | static cl::opt<bool> PrintLSR("print-lsr-output", cl::Hidden, |
| 75 | cl::desc("Print LLVM IR produced by the loop-reduce pass")); |
| 76 | static cl::opt<bool> PrintISelInput("print-isel-input", cl::Hidden, |
| 77 | cl::desc("Print LLVM IR input to isel pass")); |
| 78 | static cl::opt<bool> PrintGCInfo("print-gc", cl::Hidden, |
| 79 | cl::desc("Dump garbage collector data")); |
| 80 | static cl::opt<bool> VerifyMachineCode("verify-machineinstrs", cl::Hidden, |
| 81 | cl::desc("Verify generated machine code"), |
| 82 | cl::init(getenv("LLVM_VERIFY_MACHINEINSTRS")!=NULL)); |
| 83 | |
Andrew Trick | 79bf288 | 2012-02-15 03:21:51 +0000 | [diff] [blame] | 84 | /// Allow standard passes to be disabled by command line options. This supports |
| 85 | /// simple binary flags that either suppress the pass or do nothing. |
| 86 | /// i.e. -disable-mypass=false has no effect. |
| 87 | /// These should be converted to boolOrDefault in order to use applyOverride. |
| 88 | static AnalysisID applyDisable(AnalysisID ID, bool Override) { |
| 89 | if (Override) |
| 90 | return &NoPassID; |
| 91 | return ID; |
| 92 | } |
| 93 | |
| 94 | /// Allow Pass selection to be overriden by command line options. This supports |
| 95 | /// flags with ternary conditions. TargetID is passed through by default. The |
| 96 | /// pass is suppressed when the option is false. When the option is true, the |
| 97 | /// StandardID is selected if the target provides no default. |
| 98 | static AnalysisID applyOverride(AnalysisID TargetID, cl::boolOrDefault Override, |
| 99 | AnalysisID StandardID) { |
Andrew Trick | 746f24b | 2012-02-11 07:11:32 +0000 | [diff] [blame] | 100 | switch (Override) { |
| 101 | case cl::BOU_UNSET: |
Andrew Trick | 79bf288 | 2012-02-15 03:21:51 +0000 | [diff] [blame] | 102 | return TargetID; |
Andrew Trick | 746f24b | 2012-02-11 07:11:32 +0000 | [diff] [blame] | 103 | case cl::BOU_TRUE: |
Andrew Trick | 79bf288 | 2012-02-15 03:21:51 +0000 | [diff] [blame] | 104 | if (TargetID != &NoPassID) |
| 105 | return TargetID; |
| 106 | if (StandardID == &NoPassID) |
Andrew Trick | 746f24b | 2012-02-11 07:11:32 +0000 | [diff] [blame] | 107 | report_fatal_error("Target cannot enable pass"); |
Andrew Trick | 79bf288 | 2012-02-15 03:21:51 +0000 | [diff] [blame] | 108 | return StandardID; |
Andrew Trick | 746f24b | 2012-02-11 07:11:32 +0000 | [diff] [blame] | 109 | case cl::BOU_FALSE: |
Andrew Trick | 79bf288 | 2012-02-15 03:21:51 +0000 | [diff] [blame] | 110 | return &NoPassID; |
Andrew Trick | 746f24b | 2012-02-11 07:11:32 +0000 | [diff] [blame] | 111 | } |
| 112 | llvm_unreachable("Invalid command line option state"); |
| 113 | } |
| 114 | |
Andrew Trick | 79bf288 | 2012-02-15 03:21:51 +0000 | [diff] [blame] | 115 | /// Allow standard passes to be disabled by the command line, regardless of who |
| 116 | /// is adding the pass. |
| 117 | /// |
| 118 | /// StandardID is the pass identified in the standard pass pipeline and provided |
| 119 | /// to addPass(). It may be a target-specific ID in the case that the target |
| 120 | /// directly adds its own pass, but in that case we harmlessly fall through. |
| 121 | /// |
| 122 | /// TargetID is the pass that the target has configured to override StandardID. |
| 123 | /// |
| 124 | /// StandardID may be a pseudo ID. In that case TargetID is the name of the real |
| 125 | /// pass to run. This allows multiple options to control a single pass depending |
| 126 | /// on where in the pipeline that pass is added. |
| 127 | static AnalysisID overridePass(AnalysisID StandardID, AnalysisID TargetID) { |
| 128 | if (StandardID == &PostRASchedulerID) |
| 129 | return applyDisable(TargetID, DisablePostRA); |
| 130 | |
| 131 | if (StandardID == &BranchFolderPassID) |
| 132 | return applyDisable(TargetID, DisableBranchFold); |
| 133 | |
| 134 | if (StandardID == &TailDuplicateID) |
| 135 | return applyDisable(TargetID, DisableTailDuplicate); |
| 136 | |
| 137 | if (StandardID == &TargetPassConfig::EarlyTailDuplicateID) |
| 138 | return applyDisable(TargetID, DisableEarlyTailDup); |
| 139 | |
| 140 | if (StandardID == &MachineBlockPlacementID) |
| 141 | return applyDisable(TargetID, DisableCodePlace); |
| 142 | |
| 143 | if (StandardID == &CodePlacementOptID) |
| 144 | return applyDisable(TargetID, DisableCodePlace); |
| 145 | |
| 146 | if (StandardID == &StackSlotColoringID) |
| 147 | return applyDisable(TargetID, DisableSSC); |
| 148 | |
| 149 | if (StandardID == &DeadMachineInstructionElimID) |
| 150 | return applyDisable(TargetID, DisableMachineDCE); |
| 151 | |
| 152 | if (StandardID == &MachineLICMID) |
| 153 | return applyDisable(TargetID, DisableMachineLICM); |
| 154 | |
| 155 | if (StandardID == &MachineCSEID) |
| 156 | return applyDisable(TargetID, DisableMachineCSE); |
| 157 | |
| 158 | if (StandardID == &MachineSchedulerID) |
| 159 | return applyOverride(TargetID, EnableMachineSched, StandardID); |
| 160 | |
| 161 | if (StandardID == &TargetPassConfig::PostRAMachineLICMID) |
| 162 | return applyDisable(TargetID, DisablePostRAMachineLICM); |
| 163 | |
| 164 | if (StandardID == &MachineSinkingID) |
| 165 | return applyDisable(TargetID, DisableMachineSink); |
| 166 | |
| 167 | if (StandardID == &MachineCopyPropagationID) |
| 168 | return applyDisable(TargetID, DisableCopyProp); |
| 169 | |
| 170 | return TargetID; |
| 171 | } |
| 172 | |
Jim Laskey | eb577ba | 2006-08-02 12:30:23 +0000 | [diff] [blame] | 173 | //===---------------------------------------------------------------------===// |
Andrew Trick | 7461334 | 2012-02-04 02:56:45 +0000 | [diff] [blame] | 174 | /// TargetPassConfig |
| 175 | //===---------------------------------------------------------------------===// |
| 176 | |
| 177 | INITIALIZE_PASS(TargetPassConfig, "targetpassconfig", |
| 178 | "Target Pass Configuration", false, false) |
| 179 | char TargetPassConfig::ID = 0; |
| 180 | |
Andrew Trick | 746f24b | 2012-02-11 07:11:32 +0000 | [diff] [blame] | 181 | static char NoPassIDAnchor = 0; |
| 182 | char &llvm::NoPassID = NoPassIDAnchor; |
| 183 | |
Andrew Trick | 79bf288 | 2012-02-15 03:21:51 +0000 | [diff] [blame] | 184 | // Pseudo Pass IDs. |
| 185 | char TargetPassConfig::EarlyTailDuplicateID = 0; |
| 186 | char TargetPassConfig::PostRAMachineLICMID = 0; |
| 187 | |
Andrew Trick | 5e108ee | 2012-02-15 03:21:47 +0000 | [diff] [blame] | 188 | namespace llvm { |
| 189 | class PassConfigImpl { |
| 190 | public: |
| 191 | // List of passes explicitly substituted by this target. Normally this is |
| 192 | // empty, but it is a convenient way to suppress or replace specific passes |
| 193 | // that are part of a standard pass pipeline without overridding the entire |
| 194 | // pipeline. This mechanism allows target options to inherit a standard pass's |
| 195 | // user interface. For example, a target may disable a standard pass by |
| 196 | // default by substituting NoPass, and the user may still enable that standard |
| 197 | // pass with an explicit command line option. |
| 198 | DenseMap<AnalysisID,AnalysisID> TargetPasses; |
| 199 | }; |
| 200 | } // namespace llvm |
| 201 | |
Andrew Trick | 7461334 | 2012-02-04 02:56:45 +0000 | [diff] [blame] | 202 | // Out of line virtual method. |
Andrew Trick | 5e108ee | 2012-02-15 03:21:47 +0000 | [diff] [blame] | 203 | TargetPassConfig::~TargetPassConfig() { |
| 204 | delete Impl; |
| 205 | } |
Andrew Trick | 7461334 | 2012-02-04 02:56:45 +0000 | [diff] [blame] | 206 | |
Andrew Trick | 61f1e3d | 2012-02-08 21:22:48 +0000 | [diff] [blame] | 207 | // Out of line constructor provides default values for pass options and |
| 208 | // registers all common codegen passes. |
Andrew Trick | 061efcf | 2012-02-04 02:56:59 +0000 | [diff] [blame] | 209 | TargetPassConfig::TargetPassConfig(TargetMachine *tm, PassManagerBase &pm) |
Andrew Trick | 5e108ee | 2012-02-15 03:21:47 +0000 | [diff] [blame] | 210 | : ImmutablePass(ID), TM(tm), PM(pm), Impl(0), Initialized(false), |
Andrew Trick | ffea03f | 2012-02-08 21:22:39 +0000 | [diff] [blame] | 211 | DisableVerify(false), |
| 212 | EnableTailMerge(true) { |
| 213 | |
Andrew Trick | 5e108ee | 2012-02-15 03:21:47 +0000 | [diff] [blame] | 214 | Impl = new PassConfigImpl(); |
| 215 | |
Andrew Trick | 7461334 | 2012-02-04 02:56:45 +0000 | [diff] [blame] | 216 | // Register all target independent codegen passes to activate their PassIDs, |
| 217 | // including this pass itself. |
| 218 | initializeCodeGen(*PassRegistry::getPassRegistry()); |
Andrew Trick | 79bf288 | 2012-02-15 03:21:51 +0000 | [diff] [blame] | 219 | |
| 220 | // Substitute Pseudo Pass IDs for real ones. |
| 221 | substitutePass(EarlyTailDuplicateID, TailDuplicateID); |
| 222 | substitutePass(PostRAMachineLICMID, MachineLICMID); |
| 223 | |
| 224 | // Temporarily disable experimental passes. |
| 225 | substitutePass(MachineSchedulerID, NoPassID); |
Andrew Trick | 7461334 | 2012-02-04 02:56:45 +0000 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | /// createPassConfig - Create a pass configuration object to be used by |
| 229 | /// addPassToEmitX methods for generating a pipeline of CodeGen passes. |
| 230 | /// |
| 231 | /// Targets may override this to extend TargetPassConfig. |
Andrew Trick | 061efcf | 2012-02-04 02:56:59 +0000 | [diff] [blame] | 232 | TargetPassConfig *LLVMTargetMachine::createPassConfig(PassManagerBase &PM) { |
| 233 | return new TargetPassConfig(this, PM); |
Andrew Trick | 7461334 | 2012-02-04 02:56:45 +0000 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | TargetPassConfig::TargetPassConfig() |
| 237 | : ImmutablePass(ID), PM(*(PassManagerBase*)0) { |
| 238 | llvm_unreachable("TargetPassConfig should not be constructed on-the-fly"); |
| 239 | } |
| 240 | |
Andrew Trick | ffea03f | 2012-02-08 21:22:39 +0000 | [diff] [blame] | 241 | // Helper to verify the analysis is really immutable. |
| 242 | void TargetPassConfig::setOpt(bool &Opt, bool Val) { |
| 243 | assert(!Initialized && "PassConfig is immutable"); |
| 244 | Opt = Val; |
| 245 | } |
| 246 | |
Andrew Trick | 5e108ee | 2012-02-15 03:21:47 +0000 | [diff] [blame] | 247 | void TargetPassConfig::substitutePass(char &StandardID, char &TargetID) { |
| 248 | Impl->TargetPasses[&StandardID] = &TargetID; |
| 249 | } |
Andrew Trick | 746f24b | 2012-02-11 07:11:32 +0000 | [diff] [blame] | 250 | |
Andrew Trick | 5e108ee | 2012-02-15 03:21:47 +0000 | [diff] [blame] | 251 | AnalysisID TargetPassConfig::getPassSubstitution(AnalysisID ID) const { |
| 252 | DenseMap<AnalysisID, AnalysisID>::const_iterator |
| 253 | I = Impl->TargetPasses.find(ID); |
| 254 | if (I == Impl->TargetPasses.end()) |
| 255 | return ID; |
| 256 | return I->second; |
| 257 | } |
| 258 | |
| 259 | /// Add a CodeGen pass at this point in the pipeline after checking for target |
| 260 | /// and command line overrides. |
| 261 | AnalysisID TargetPassConfig::addPass(char &ID) { |
| 262 | assert(!Initialized && "PassConfig is immutable"); |
| 263 | |
Andrew Trick | 79bf288 | 2012-02-15 03:21:51 +0000 | [diff] [blame] | 264 | AnalysisID TargetID = getPassSubstitution(&ID); |
| 265 | AnalysisID FinalID = overridePass(&ID, TargetID); |
Andrew Trick | 5e108ee | 2012-02-15 03:21:47 +0000 | [diff] [blame] | 266 | if (FinalID == &NoPassID) |
| 267 | return FinalID; |
| 268 | |
| 269 | Pass *P = Pass::createPass(FinalID); |
Andrew Trick | ebe18ef | 2012-02-08 21:22:34 +0000 | [diff] [blame] | 270 | if (!P) |
| 271 | llvm_unreachable("Pass ID not registered"); |
| 272 | PM.add(P); |
Andrew Trick | 5e108ee | 2012-02-15 03:21:47 +0000 | [diff] [blame] | 273 | return FinalID; |
Andrew Trick | 061efcf | 2012-02-04 02:56:59 +0000 | [diff] [blame] | 274 | } |
Andrew Trick | d542265 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 275 | |
Andrew Trick | d542265 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 276 | void TargetPassConfig::printAndVerify(const char *Banner) const { |
| 277 | if (TM->shouldPrintMachineCode()) |
| 278 | PM.add(createMachineFunctionPrinterPass(dbgs(), Banner)); |
| 279 | |
| 280 | if (VerifyMachineCode) |
| 281 | PM.add(createMachineVerifierPass(Banner)); |
| 282 | } |
| 283 | |
Andrew Trick | 061efcf | 2012-02-04 02:56:59 +0000 | [diff] [blame] | 284 | /// Add common target configurable passes that perform LLVM IR to IR transforms |
| 285 | /// following machine independent optimization. |
| 286 | void TargetPassConfig::addIRPasses() { |
Andrew Trick | d542265 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 287 | // Basic AliasAnalysis support. |
| 288 | // Add TypeBasedAliasAnalysis before BasicAliasAnalysis so that |
| 289 | // BasicAliasAnalysis wins if they disagree. This is intended to help |
| 290 | // support "obvious" type-punning idioms. |
| 291 | PM.add(createTypeBasedAliasAnalysisPass()); |
| 292 | PM.add(createBasicAliasAnalysisPass()); |
| 293 | |
| 294 | // Before running any passes, run the verifier to determine if the input |
| 295 | // coming from the front-end and/or optimizer is valid. |
| 296 | if (!DisableVerify) |
| 297 | PM.add(createVerifierPass()); |
| 298 | |
| 299 | // Run loop strength reduction before anything else. |
| 300 | if (getOptLevel() != CodeGenOpt::None && !DisableLSR) { |
| 301 | PM.add(createLoopStrengthReducePass(getTargetLowering())); |
| 302 | if (PrintLSR) |
| 303 | PM.add(createPrintFunctionPass("\n\n*** Code after LSR ***\n", &dbgs())); |
| 304 | } |
| 305 | |
| 306 | PM.add(createGCLoweringPass()); |
| 307 | |
| 308 | // Make sure that no unreachable blocks are instruction selected. |
| 309 | PM.add(createUnreachableBlockEliminationPass()); |
Andrew Trick | 061efcf | 2012-02-04 02:56:59 +0000 | [diff] [blame] | 310 | } |
Andrew Trick | d542265 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 311 | |
Andrew Trick | 061efcf | 2012-02-04 02:56:59 +0000 | [diff] [blame] | 312 | /// Add common passes that perform LLVM IR to IR transforms in preparation for |
| 313 | /// instruction selection. |
| 314 | void TargetPassConfig::addISelPrepare() { |
Andrew Trick | d542265 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 315 | if (getOptLevel() != CodeGenOpt::None && !DisableCGP) |
| 316 | PM.add(createCodeGenPreparePass(getTargetLowering())); |
| 317 | |
| 318 | PM.add(createStackProtectorPass(getTargetLowering())); |
| 319 | |
| 320 | addPreISel(); |
| 321 | |
| 322 | if (PrintISelInput) |
| 323 | PM.add(createPrintFunctionPass("\n\n" |
| 324 | "*** Final LLVM Code input to ISel ***\n", |
| 325 | &dbgs())); |
| 326 | |
| 327 | // All passes which modify the LLVM IR are now complete; run the verifier |
| 328 | // to ensure that the IR is valid. |
| 329 | if (!DisableVerify) |
| 330 | PM.add(createVerifierPass()); |
Andrew Trick | 061efcf | 2012-02-04 02:56:59 +0000 | [diff] [blame] | 331 | } |
Andrew Trick | d542265 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 332 | |
Andrew Trick | f7b9631 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 333 | /// Add the complete set of target-independent postISel code generator passes. |
| 334 | /// |
| 335 | /// This can be read as the standard order of major LLVM CodeGen stages. Stages |
| 336 | /// with nontrivial configuration or multiple passes are broken out below in |
| 337 | /// add%Stage routines. |
| 338 | /// |
| 339 | /// Any TargetPassConfig::addXX routine may be overriden by the Target. The |
| 340 | /// addPre/Post methods with empty header implementations allow injecting |
| 341 | /// target-specific fixups just before or after major stages. Additionally, |
| 342 | /// targets have the flexibility to change pass order within a stage by |
| 343 | /// overriding default implementation of add%Stage routines below. Each |
| 344 | /// technique has maintainability tradeoffs because alternate pass orders are |
| 345 | /// not well supported. addPre/Post works better if the target pass is easily |
| 346 | /// tied to a common pass. But if it has subtle dependencies on multiple passes, |
Andrew Trick | 06efdd2 | 2012-02-10 07:08:25 +0000 | [diff] [blame] | 347 | /// the target should override the stage instead. |
Andrew Trick | f7b9631 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 348 | /// |
| 349 | /// TODO: We could use a single addPre/Post(ID) hook to allow pass injection |
| 350 | /// before/after any target-independent pass. But it's currently overkill. |
Andrew Trick | 061efcf | 2012-02-04 02:56:59 +0000 | [diff] [blame] | 351 | void TargetPassConfig::addMachinePasses() { |
Andrew Trick | d542265 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 352 | // Print the instruction selected machine code... |
| 353 | printAndVerify("After Instruction Selection"); |
| 354 | |
| 355 | // Expand pseudo-instructions emitted by ISel. |
Andrew Trick | 1dd8c85 | 2012-02-08 21:23:13 +0000 | [diff] [blame] | 356 | addPass(ExpandISelPseudosID); |
Andrew Trick | d542265 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 357 | |
Andrew Trick | f7b9631 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 358 | // Add passes that optimize machine instructions in SSA form. |
Andrew Trick | d542265 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 359 | if (getOptLevel() != CodeGenOpt::None) { |
Andrew Trick | f7b9631 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 360 | addMachineSSAOptimization(); |
| 361 | } |
| 362 | else { |
| 363 | // If the target requests it, assign local variables to stack slots relative |
| 364 | // to one another and simplify frame index references where possible. |
| 365 | addPass(LocalStackSlotAllocationID); |
Andrew Trick | d542265 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 366 | } |
| 367 | |
| 368 | // Run pre-ra passes. |
| 369 | if (addPreRegAlloc()) |
| 370 | printAndVerify("After PreRegAlloc passes"); |
| 371 | |
Andrew Trick | f7b9631 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 372 | // Run register allocation and passes that are tightly coupled with it, |
| 373 | // including phi elimination and scheduling. |
Andrew Trick | 8dd2625 | 2012-02-10 04:10:36 +0000 | [diff] [blame] | 374 | if (getOptimizeRegAlloc()) |
| 375 | addOptimizedRegAlloc(createRegAllocPass(true)); |
| 376 | else |
| 377 | addFastRegAlloc(createRegAllocPass(false)); |
Andrew Trick | d542265 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 378 | |
| 379 | // Run post-ra passes. |
| 380 | if (addPostRegAlloc()) |
| 381 | printAndVerify("After PostRegAlloc passes"); |
| 382 | |
| 383 | // Insert prolog/epilog code. Eliminate abstract frame index references... |
Andrew Trick | 1dd8c85 | 2012-02-08 21:23:13 +0000 | [diff] [blame] | 384 | addPass(PrologEpilogCodeInserterID); |
Andrew Trick | d542265 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 385 | printAndVerify("After PrologEpilogCodeInserter"); |
| 386 | |
Andrew Trick | f7b9631 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 387 | /// Add passes that optimize machine instructions after register allocation. |
| 388 | if (getOptLevel() != CodeGenOpt::None) |
| 389 | addMachineLateOptimization(); |
Andrew Trick | d542265 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 390 | |
| 391 | // Expand pseudo instructions before second scheduling pass. |
Andrew Trick | 1dd8c85 | 2012-02-08 21:23:13 +0000 | [diff] [blame] | 392 | addPass(ExpandPostRAPseudosID); |
Jakob Stoklund Olesen | 2ef5bf6 | 2012-03-28 20:49:30 +0000 | [diff] [blame] | 393 | printAndVerify("After ExpandPostRAPseudos"); |
Andrew Trick | d542265 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 394 | |
| 395 | // Run pre-sched2 passes. |
| 396 | if (addPreSched2()) |
Jakob Stoklund Olesen | 7881166 | 2012-03-28 23:31:15 +0000 | [diff] [blame] | 397 | printAndVerify("After PreSched2 passes"); |
Andrew Trick | d542265 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 398 | |
| 399 | // Second pass scheduler. |
Andrew Trick | 79bf288 | 2012-02-15 03:21:51 +0000 | [diff] [blame] | 400 | if (getOptLevel() != CodeGenOpt::None) { |
Andrew Trick | 1dd8c85 | 2012-02-08 21:23:13 +0000 | [diff] [blame] | 401 | addPass(PostRASchedulerID); |
Jakob Stoklund Olesen | 8b4c502 | 2012-03-28 23:54:28 +0000 | [diff] [blame] | 402 | printAndVerify("After PostRAScheduler"); |
Andrew Trick | d542265 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 403 | } |
| 404 | |
Andrew Trick | f7b9631 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 405 | // GC |
Andrew Trick | 1dd8c85 | 2012-02-08 21:23:13 +0000 | [diff] [blame] | 406 | addPass(GCMachineCodeAnalysisID); |
Andrew Trick | d542265 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 407 | if (PrintGCInfo) |
| 408 | PM.add(createGCInfoPrinter(dbgs())); |
| 409 | |
Andrew Trick | f7b9631 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 410 | // Basic block placement. |
Andrew Trick | 79bf288 | 2012-02-15 03:21:51 +0000 | [diff] [blame] | 411 | if (getOptLevel() != CodeGenOpt::None) |
Andrew Trick | f7b9631 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 412 | addBlockPlacement(); |
Andrew Trick | d542265 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 413 | |
| 414 | if (addPreEmitPass()) |
Jakob Stoklund Olesen | 8b4c502 | 2012-03-28 23:54:28 +0000 | [diff] [blame] | 415 | printAndVerify("After PreEmit passes"); |
Andrew Trick | d542265 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 416 | } |
| 417 | |
Andrew Trick | f7b9631 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 418 | /// Add passes that optimize machine instructions in SSA form. |
| 419 | void TargetPassConfig::addMachineSSAOptimization() { |
| 420 | // Pre-ra tail duplication. |
Andrew Trick | 79bf288 | 2012-02-15 03:21:51 +0000 | [diff] [blame] | 421 | if (addPass(EarlyTailDuplicateID) != &NoPassID) |
Andrew Trick | f7b9631 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 422 | printAndVerify("After Pre-RegAlloc TailDuplicate"); |
Andrew Trick | f7b9631 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 423 | |
| 424 | // Optimize PHIs before DCE: removing dead PHI cycles may make more |
| 425 | // instructions dead. |
| 426 | addPass(OptimizePHIsID); |
| 427 | |
| 428 | // If the target requests it, assign local variables to stack slots relative |
| 429 | // to one another and simplify frame index references where possible. |
| 430 | addPass(LocalStackSlotAllocationID); |
| 431 | |
| 432 | // With optimization, dead code should already be eliminated. However |
| 433 | // there is one known exception: lowered code for arguments that are only |
| 434 | // used by tail calls, where the tail calls reuse the incoming stack |
| 435 | // arguments directly (see t11 in test/CodeGen/X86/sibcall.ll). |
Andrew Trick | 79bf288 | 2012-02-15 03:21:51 +0000 | [diff] [blame] | 436 | addPass(DeadMachineInstructionElimID); |
Andrew Trick | f7b9631 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 437 | printAndVerify("After codegen DCE pass"); |
| 438 | |
Andrew Trick | 79bf288 | 2012-02-15 03:21:51 +0000 | [diff] [blame] | 439 | addPass(MachineLICMID); |
| 440 | addPass(MachineCSEID); |
| 441 | addPass(MachineSinkingID); |
Andrew Trick | f7b9631 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 442 | printAndVerify("After Machine LICM, CSE and Sinking passes"); |
| 443 | |
| 444 | addPass(PeepholeOptimizerID); |
| 445 | printAndVerify("After codegen peephole optimization pass"); |
| 446 | } |
| 447 | |
Andrew Trick | 7461334 | 2012-02-04 02:56:45 +0000 | [diff] [blame] | 448 | //===---------------------------------------------------------------------===// |
Andrew Trick | f7b9631 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 449 | /// Register Allocation Pass Configuration |
Jim Laskey | eb577ba | 2006-08-02 12:30:23 +0000 | [diff] [blame] | 450 | //===---------------------------------------------------------------------===// |
Andrew Trick | f7b9631 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 451 | |
Andrew Trick | 8dd2625 | 2012-02-10 04:10:36 +0000 | [diff] [blame] | 452 | bool TargetPassConfig::getOptimizeRegAlloc() const { |
| 453 | switch (OptimizeRegAlloc) { |
| 454 | case cl::BOU_UNSET: return getOptLevel() != CodeGenOpt::None; |
| 455 | case cl::BOU_TRUE: return true; |
| 456 | case cl::BOU_FALSE: return false; |
| 457 | } |
| 458 | llvm_unreachable("Invalid optimize-regalloc state"); |
| 459 | } |
| 460 | |
Andrew Trick | f7b9631 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 461 | /// RegisterRegAlloc's global Registry tracks allocator registration. |
Jim Laskey | eb577ba | 2006-08-02 12:30:23 +0000 | [diff] [blame] | 462 | MachinePassRegistry RegisterRegAlloc::Registry; |
| 463 | |
Andrew Trick | f7b9631 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 464 | /// A dummy default pass factory indicates whether the register allocator is |
| 465 | /// overridden on the command line. |
Andrew Trick | 8dd2625 | 2012-02-10 04:10:36 +0000 | [diff] [blame] | 466 | static FunctionPass *useDefaultRegisterAllocator() { return 0; } |
Jakob Stoklund Olesen | 700bfad | 2010-05-27 23:57:25 +0000 | [diff] [blame] | 467 | static RegisterRegAlloc |
| 468 | defaultRegAlloc("default", |
| 469 | "pick register allocator based on -O option", |
Andrew Trick | 8dd2625 | 2012-02-10 04:10:36 +0000 | [diff] [blame] | 470 | useDefaultRegisterAllocator); |
Jim Laskey | eb577ba | 2006-08-02 12:30:23 +0000 | [diff] [blame] | 471 | |
Andrew Trick | f7b9631 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 472 | /// -regalloc=... command line option. |
Dan Gohman | 844731a | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 473 | static cl::opt<RegisterRegAlloc::FunctionPassCtor, false, |
| 474 | RegisterPassParser<RegisterRegAlloc> > |
| 475 | RegAlloc("regalloc", |
Andrew Trick | 8dd2625 | 2012-02-10 04:10:36 +0000 | [diff] [blame] | 476 | cl::init(&useDefaultRegisterAllocator), |
Jakob Stoklund Olesen | 700bfad | 2010-05-27 23:57:25 +0000 | [diff] [blame] | 477 | cl::desc("Register allocator to use")); |
Alkis Evlogimenos | 7237ece | 2003-10-02 16:57:49 +0000 | [diff] [blame] | 478 | |
Jim Laskey | eb577ba | 2006-08-02 12:30:23 +0000 | [diff] [blame] | 479 | |
Andrew Trick | 8dd2625 | 2012-02-10 04:10:36 +0000 | [diff] [blame] | 480 | /// Instantiate the default register allocator pass for this target for either |
| 481 | /// the optimized or unoptimized allocation path. This will be added to the pass |
| 482 | /// manager by addFastRegAlloc in the unoptimized case or addOptimizedRegAlloc |
| 483 | /// in the optimized case. |
| 484 | /// |
| 485 | /// A target that uses the standard regalloc pass order for fast or optimized |
| 486 | /// allocation may still override this for per-target regalloc |
| 487 | /// selection. But -regalloc=... always takes precedence. |
| 488 | FunctionPass *TargetPassConfig::createTargetRegisterAllocator(bool Optimized) { |
| 489 | if (Optimized) |
| 490 | return createGreedyRegisterAllocator(); |
| 491 | else |
| 492 | return createFastRegisterAllocator(); |
| 493 | } |
| 494 | |
| 495 | /// Find and instantiate the register allocation pass requested by this target |
| 496 | /// at the current optimization level. Different register allocators are |
| 497 | /// defined as separate passes because they may require different analysis. |
| 498 | /// |
| 499 | /// This helper ensures that the regalloc= option is always available, |
| 500 | /// even for targets that override the default allocator. |
| 501 | /// |
| 502 | /// FIXME: When MachinePassRegistry register pass IDs instead of function ptrs, |
| 503 | /// this can be folded into addPass. |
| 504 | FunctionPass *TargetPassConfig::createRegAllocPass(bool Optimized) { |
Jim Laskey | 9ff542f | 2006-08-01 18:29:48 +0000 | [diff] [blame] | 505 | RegisterRegAlloc::FunctionPassCtor Ctor = RegisterRegAlloc::getDefault(); |
Jakob Stoklund Olesen | 700bfad | 2010-05-27 23:57:25 +0000 | [diff] [blame] | 506 | |
Andrew Trick | 8dd2625 | 2012-02-10 04:10:36 +0000 | [diff] [blame] | 507 | // Initialize the global default. |
Jim Laskey | 13ec702 | 2006-08-01 14:21:23 +0000 | [diff] [blame] | 508 | if (!Ctor) { |
Jim Laskey | eb577ba | 2006-08-02 12:30:23 +0000 | [diff] [blame] | 509 | Ctor = RegAlloc; |
| 510 | RegisterRegAlloc::setDefault(RegAlloc); |
Jim Laskey | 13ec702 | 2006-08-01 14:21:23 +0000 | [diff] [blame] | 511 | } |
Andrew Trick | 8dd2625 | 2012-02-10 04:10:36 +0000 | [diff] [blame] | 512 | if (Ctor != useDefaultRegisterAllocator) |
Jakob Stoklund Olesen | 700bfad | 2010-05-27 23:57:25 +0000 | [diff] [blame] | 513 | return Ctor(); |
| 514 | |
Andrew Trick | 8dd2625 | 2012-02-10 04:10:36 +0000 | [diff] [blame] | 515 | // With no -regalloc= override, ask the target for a regalloc pass. |
| 516 | return createTargetRegisterAllocator(Optimized); |
| 517 | } |
| 518 | |
| 519 | /// Add the minimum set of target-independent passes that are required for |
| 520 | /// register allocation. No coalescing or scheduling. |
| 521 | void TargetPassConfig::addFastRegAlloc(FunctionPass *RegAllocPass) { |
| 522 | addPass(PHIEliminationID); |
| 523 | addPass(TwoAddressInstructionPassID); |
| 524 | |
| 525 | PM.add(RegAllocPass); |
| 526 | printAndVerify("After Register Allocation"); |
Jim Laskey | 33a0a6d | 2006-07-27 20:05:00 +0000 | [diff] [blame] | 527 | } |
Andrew Trick | f7b9631 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 528 | |
| 529 | /// Add standard target-independent passes that are tightly coupled with |
Andrew Trick | 8dd2625 | 2012-02-10 04:10:36 +0000 | [diff] [blame] | 530 | /// optimized register allocation, including coalescing, machine instruction |
| 531 | /// scheduling, and register allocation itself. |
| 532 | void TargetPassConfig::addOptimizedRegAlloc(FunctionPass *RegAllocPass) { |
| 533 | // LiveVariables currently requires pure SSA form. |
| 534 | // |
| 535 | // FIXME: Once TwoAddressInstruction pass no longer uses kill flags, |
| 536 | // LiveVariables can be removed completely, and LiveIntervals can be directly |
| 537 | // computed. (We still either need to regenerate kill flags after regalloc, or |
| 538 | // preferably fix the scavenger to not depend on them). |
| 539 | addPass(LiveVariablesID); |
| 540 | |
| 541 | // Add passes that move from transformed SSA into conventional SSA. This is a |
| 542 | // "copy coalescing" problem. |
| 543 | // |
| 544 | if (!EnableStrongPHIElim) { |
| 545 | // Edge splitting is smarter with machine loop info. |
| 546 | addPass(MachineLoopInfoID); |
| 547 | addPass(PHIEliminationID); |
| 548 | } |
| 549 | addPass(TwoAddressInstructionPassID); |
| 550 | |
| 551 | // FIXME: Either remove this pass completely, or fix it so that it works on |
| 552 | // SSA form. We could modify LiveIntervals to be independent of this pass, But |
| 553 | // it would be even better to simply eliminate *all* IMPLICIT_DEFs before |
| 554 | // leaving SSA. |
| 555 | addPass(ProcessImplicitDefsID); |
| 556 | |
| 557 | if (EnableStrongPHIElim) |
| 558 | addPass(StrongPHIEliminationID); |
| 559 | |
| 560 | addPass(RegisterCoalescerID); |
| 561 | |
| 562 | // PreRA instruction scheduling. |
Andrew Trick | 17d35e5 | 2012-03-14 04:00:41 +0000 | [diff] [blame] | 563 | if (addPass(MachineSchedulerID) != &NoPassID) |
| 564 | printAndVerify("After Machine Scheduling"); |
Andrew Trick | 8dd2625 | 2012-02-10 04:10:36 +0000 | [diff] [blame] | 565 | |
| 566 | // Add the selected register allocation pass. |
| 567 | PM.add(RegAllocPass); |
Andrew Trick | f7b9631 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 568 | printAndVerify("After Register Allocation"); |
| 569 | |
Andrew Trick | 746f24b | 2012-02-11 07:11:32 +0000 | [diff] [blame] | 570 | // FinalizeRegAlloc is convenient until MachineInstrBundles is more mature, |
| 571 | // but eventually, all users of it should probably be moved to addPostRA and |
| 572 | // it can go away. Currently, it's the intended place for targets to run |
| 573 | // FinalizeMachineBundles, because passes other than MachineScheduling an |
| 574 | // RegAlloc itself may not be aware of bundles. |
| 575 | if (addFinalizeRegAlloc()) |
| 576 | printAndVerify("After RegAlloc finalization"); |
| 577 | |
Andrew Trick | f7b9631 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 578 | // Perform stack slot coloring and post-ra machine LICM. |
Andrew Trick | 8dd2625 | 2012-02-10 04:10:36 +0000 | [diff] [blame] | 579 | // |
| 580 | // FIXME: Re-enable coloring with register when it's capable of adding |
| 581 | // kill markers. |
Andrew Trick | 900d7b7 | 2012-02-15 07:57:03 +0000 | [diff] [blame] | 582 | addPass(StackSlotColoringID); |
| 583 | |
| 584 | // Run post-ra machine LICM to hoist reloads / remats. |
| 585 | // |
| 586 | // FIXME: can this move into MachineLateOptimization? |
| 587 | addPass(PostRAMachineLICMID); |
| 588 | |
| 589 | printAndVerify("After StackSlotColoring and postra Machine LICM"); |
Andrew Trick | f7b9631 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 590 | } |
| 591 | |
| 592 | //===---------------------------------------------------------------------===// |
| 593 | /// Post RegAlloc Pass Configuration |
| 594 | //===---------------------------------------------------------------------===// |
| 595 | |
| 596 | /// Add passes that optimize machine instructions after register allocation. |
| 597 | void TargetPassConfig::addMachineLateOptimization() { |
| 598 | // Branch folding must be run after regalloc and prolog/epilog insertion. |
Andrew Trick | 79bf288 | 2012-02-15 03:21:51 +0000 | [diff] [blame] | 599 | if (addPass(BranchFolderPassID) != &NoPassID) |
Jakob Stoklund Olesen | 663ee20 | 2012-03-28 20:47:37 +0000 | [diff] [blame] | 600 | printAndVerify("After BranchFolding"); |
Andrew Trick | f7b9631 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 601 | |
| 602 | // Tail duplication. |
Andrew Trick | 79bf288 | 2012-02-15 03:21:51 +0000 | [diff] [blame] | 603 | if (addPass(TailDuplicateID) != &NoPassID) |
Jakob Stoklund Olesen | 663ee20 | 2012-03-28 20:47:37 +0000 | [diff] [blame] | 604 | printAndVerify("After TailDuplicate"); |
Andrew Trick | f7b9631 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 605 | |
| 606 | // Copy propagation. |
Andrew Trick | 79bf288 | 2012-02-15 03:21:51 +0000 | [diff] [blame] | 607 | if (addPass(MachineCopyPropagationID) != &NoPassID) |
Jakob Stoklund Olesen | 663ee20 | 2012-03-28 20:47:37 +0000 | [diff] [blame] | 608 | printAndVerify("After copy propagation pass"); |
Andrew Trick | f7b9631 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 609 | } |
| 610 | |
| 611 | /// Add standard basic block placement passes. |
| 612 | void TargetPassConfig::addBlockPlacement() { |
Andrew Trick | 79bf288 | 2012-02-15 03:21:51 +0000 | [diff] [blame] | 613 | AnalysisID ID = &NoPassID; |
Chandler Carruth | 9e67db4 | 2012-04-16 13:49:17 +0000 | [diff] [blame^] | 614 | if (!DisableBlockPlacement) { |
| 615 | // MachineBlockPlacement is a new pass which subsumes the functionality of |
| 616 | // CodPlacementOpt. The old code placement pass can be restored by |
| 617 | // disabling block placement, but eventually it will be removed. |
Andrew Trick | 79bf288 | 2012-02-15 03:21:51 +0000 | [diff] [blame] | 618 | ID = addPass(MachineBlockPlacementID); |
Andrew Trick | f7b9631 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 619 | } else { |
Andrew Trick | 79bf288 | 2012-02-15 03:21:51 +0000 | [diff] [blame] | 620 | ID = addPass(CodePlacementOptID); |
Andrew Trick | f7b9631 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 621 | } |
Andrew Trick | 79bf288 | 2012-02-15 03:21:51 +0000 | [diff] [blame] | 622 | if (ID != &NoPassID) { |
| 623 | // Run a separate pass to collect block placement statistics. |
| 624 | if (EnableBlockPlacementStats) |
| 625 | addPass(MachineBlockPlacementStatsID); |
Andrew Trick | f7b9631 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 626 | |
Jakob Stoklund Olesen | 8b4c502 | 2012-03-28 23:54:28 +0000 | [diff] [blame] | 627 | printAndVerify("After machine block placement."); |
Andrew Trick | f7b9631 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 628 | } |
| 629 | } |