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 | |
Chandler Carruth | d04a8d4 | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 15 | #include "llvm/CodeGen/Passes.h" |
Andrew Trick | d542265 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 16 | #include "llvm/Analysis/Passes.h" |
Andrew Trick | d542265 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 17 | #include "llvm/CodeGen/GCStrategy.h" |
Andrew Trick | d542265 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 18 | #include "llvm/CodeGen/MachineFunctionPass.h" |
Andrew Trick | d542265 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 19 | #include "llvm/CodeGen/RegAllocRegistry.h" |
Stephen Hines | 36b5688 | 2014-04-23 16:57:46 -0700 | [diff] [blame] | 20 | #include "llvm/IR/IRPrintingPasses.h" |
| 21 | #include "llvm/IR/Verifier.h" |
Bob Wilson | 564fbf6 | 2012-07-02 19:48:31 +0000 | [diff] [blame] | 22 | #include "llvm/MC/MCAsmInfo.h" |
Chandler Carruth | d04a8d4 | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 23 | #include "llvm/PassManager.h" |
Andrew Trick | d542265 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 24 | #include "llvm/Support/CommandLine.h" |
| 25 | #include "llvm/Support/Debug.h" |
Andrew Trick | 7461334 | 2012-02-04 02:56:45 +0000 | [diff] [blame] | 26 | #include "llvm/Support/ErrorHandling.h" |
Chandler Carruth | d04a8d4 | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 27 | #include "llvm/Target/TargetLowering.h" |
Chandler Carruth | d04a8d4 | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 28 | #include "llvm/Target/TargetSubtargetInfo.h" |
| 29 | #include "llvm/Transforms/Scalar.h" |
Jim Laskey | 13ec702 | 2006-08-01 14:21:23 +0000 | [diff] [blame] | 30 | |
Chris Lattner | aa4c91f | 2003-12-28 07:59:53 +0000 | [diff] [blame] | 31 | using namespace llvm; |
Brian Gaeke | d0fde30 | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 32 | |
Stephen Hines | 36b5688 | 2014-04-23 16:57:46 -0700 | [diff] [blame] | 33 | namespace llvm { |
| 34 | extern cl::opt<bool> EnableStackMapLiveness; |
| 35 | extern cl::opt<bool> EnablePatchPointLiveness; |
| 36 | } |
| 37 | |
Andrew Trick | d542265 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 38 | static cl::opt<bool> DisablePostRA("disable-post-ra", cl::Hidden, |
| 39 | cl::desc("Disable Post Regalloc")); |
| 40 | static cl::opt<bool> DisableBranchFold("disable-branch-fold", cl::Hidden, |
| 41 | cl::desc("Disable branch folding")); |
| 42 | static cl::opt<bool> DisableTailDuplicate("disable-tail-duplicate", cl::Hidden, |
| 43 | cl::desc("Disable tail duplication")); |
| 44 | static cl::opt<bool> DisableEarlyTailDup("disable-early-taildup", cl::Hidden, |
| 45 | cl::desc("Disable pre-register allocation tail duplication")); |
Chandler Carruth | 9e67db4 | 2012-04-16 13:49:17 +0000 | [diff] [blame] | 46 | static cl::opt<bool> DisableBlockPlacement("disable-block-placement", |
Benjamin Kramer | 74a4533 | 2013-03-29 17:14:24 +0000 | [diff] [blame] | 47 | cl::Hidden, cl::desc("Disable probability-driven block placement")); |
Andrew Trick | d542265 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 48 | static cl::opt<bool> EnableBlockPlacementStats("enable-block-placement-stats", |
| 49 | cl::Hidden, cl::desc("Collect probability-driven block placement stats")); |
Andrew Trick | d542265 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 50 | static cl::opt<bool> DisableSSC("disable-ssc", cl::Hidden, |
| 51 | cl::desc("Disable Stack Slot Coloring")); |
| 52 | static cl::opt<bool> DisableMachineDCE("disable-machine-dce", cl::Hidden, |
| 53 | cl::desc("Disable Machine Dead Code Elimination")); |
Jakob Stoklund Olesen | 0d141f8 | 2012-10-03 00:51:32 +0000 | [diff] [blame] | 54 | static cl::opt<bool> DisableEarlyIfConversion("disable-early-ifcvt", cl::Hidden, |
| 55 | cl::desc("Disable Early If-conversion")); |
Andrew Trick | d542265 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 56 | static cl::opt<bool> DisableMachineLICM("disable-machine-licm", cl::Hidden, |
| 57 | cl::desc("Disable Machine LICM")); |
| 58 | static cl::opt<bool> DisableMachineCSE("disable-machine-cse", cl::Hidden, |
| 59 | cl::desc("Disable Machine Common Subexpression Elimination")); |
Andrew Trick | 8dd2625 | 2012-02-10 04:10:36 +0000 | [diff] [blame] | 60 | static cl::opt<cl::boolOrDefault> |
| 61 | OptimizeRegAlloc("optimize-regalloc", cl::Hidden, |
| 62 | cl::desc("Enable optimized register allocation compilation path.")); |
Andrew Trick | 746f24b | 2012-02-11 07:11:32 +0000 | [diff] [blame] | 63 | static cl::opt<cl::boolOrDefault> |
Stephen Hines | 36b5688 | 2014-04-23 16:57:46 -0700 | [diff] [blame] | 64 | EnableMachineSched("enable-misched", |
Andrew Trick | 8dd2625 | 2012-02-10 04:10:36 +0000 | [diff] [blame] | 65 | cl::desc("Enable the machine instruction scheduling pass.")); |
Andrew Trick | d542265 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 66 | static cl::opt<bool> DisablePostRAMachineLICM("disable-postra-machine-licm", |
| 67 | cl::Hidden, |
| 68 | cl::desc("Disable Machine LICM")); |
| 69 | static cl::opt<bool> DisableMachineSink("disable-machine-sink", cl::Hidden, |
| 70 | cl::desc("Disable Machine Sinking")); |
| 71 | static cl::opt<bool> DisableLSR("disable-lsr", cl::Hidden, |
| 72 | cl::desc("Disable Loop Strength Reduction Pass")); |
Stephen Hines | 36b5688 | 2014-04-23 16:57:46 -0700 | [diff] [blame] | 73 | static cl::opt<bool> DisableConstantHoisting("disable-constant-hoisting", |
| 74 | cl::Hidden, cl::desc("Disable ConstantHoisting")); |
Andrew Trick | d542265 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 75 | static cl::opt<bool> DisableCGP("disable-cgp", cl::Hidden, |
| 76 | cl::desc("Disable Codegen Prepare")); |
| 77 | static cl::opt<bool> DisableCopyProp("disable-copyprop", cl::Hidden, |
Evan Cheng | 01b623c | 2012-02-20 23:28:17 +0000 | [diff] [blame] | 78 | cl::desc("Disable Copy Propagation pass")); |
Andrew Trick | d542265 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 79 | static cl::opt<bool> PrintLSR("print-lsr-output", cl::Hidden, |
| 80 | cl::desc("Print LLVM IR produced by the loop-reduce pass")); |
| 81 | static cl::opt<bool> PrintISelInput("print-isel-input", cl::Hidden, |
| 82 | cl::desc("Print LLVM IR input to isel pass")); |
| 83 | static cl::opt<bool> PrintGCInfo("print-gc", cl::Hidden, |
| 84 | cl::desc("Dump garbage collector data")); |
| 85 | static cl::opt<bool> VerifyMachineCode("verify-machineinstrs", cl::Hidden, |
| 86 | cl::desc("Verify generated machine code"), |
Stephen Hines | dce4a40 | 2014-05-29 02:49:00 -0700 | [diff] [blame^] | 87 | cl::init(getenv("LLVM_VERIFY_MACHINEINSTRS")!=nullptr)); |
Bob Wilson | 6e1b812 | 2012-05-30 00:17:12 +0000 | [diff] [blame] | 88 | static cl::opt<std::string> |
| 89 | PrintMachineInstrs("print-machineinstrs", cl::ValueOptional, |
| 90 | cl::desc("Print machine instrs"), |
| 91 | cl::value_desc("pass-name"), cl::init("option-unspecified")); |
Andrew Trick | d542265 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 92 | |
Stephen Hines | 36b5688 | 2014-04-23 16:57:46 -0700 | [diff] [blame] | 93 | // Temporary option to allow experimenting with MachineScheduler as a post-RA |
| 94 | // scheduler. Targets can "properly" enable this with |
| 95 | // substitutePass(&PostRASchedulerID, &MachineSchedulerID); Ideally it wouldn't |
| 96 | // be part of the standard pass pipeline, and the target would just add a PostRA |
| 97 | // scheduling pass wherever it wants. |
| 98 | static cl::opt<bool> MISchedPostRA("misched-postra", cl::Hidden, |
| 99 | cl::desc("Run MachineScheduler post regalloc (independent of preRA sched)")); |
| 100 | |
Cameron Zwarich | d7c7a68 | 2013-02-10 06:42:34 +0000 | [diff] [blame] | 101 | // Experimental option to run live interval analysis early. |
Jakob Stoklund Olesen | dcc4436 | 2012-08-03 22:12:54 +0000 | [diff] [blame] | 102 | static cl::opt<bool> EarlyLiveIntervals("early-live-intervals", cl::Hidden, |
| 103 | cl::desc("Run live interval analysis earlier in the pipeline")); |
| 104 | |
Andrew Trick | 79bf288 | 2012-02-15 03:21:51 +0000 | [diff] [blame] | 105 | /// Allow standard passes to be disabled by command line options. This supports |
| 106 | /// simple binary flags that either suppress the pass or do nothing. |
| 107 | /// i.e. -disable-mypass=false has no effect. |
| 108 | /// These should be converted to boolOrDefault in order to use applyOverride. |
Andrew Trick | 5ed0283 | 2013-04-10 01:06:56 +0000 | [diff] [blame] | 109 | static IdentifyingPassPtr applyDisable(IdentifyingPassPtr PassID, |
| 110 | bool Override) { |
Andrew Trick | 79bf288 | 2012-02-15 03:21:51 +0000 | [diff] [blame] | 111 | if (Override) |
Andrew Trick | 5ed0283 | 2013-04-10 01:06:56 +0000 | [diff] [blame] | 112 | return IdentifyingPassPtr(); |
Bob Wilson | 3fb99a7 | 2012-07-02 19:48:37 +0000 | [diff] [blame] | 113 | return PassID; |
Andrew Trick | 79bf288 | 2012-02-15 03:21:51 +0000 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | /// Allow Pass selection to be overriden by command line options. This supports |
| 117 | /// flags with ternary conditions. TargetID is passed through by default. The |
| 118 | /// pass is suppressed when the option is false. When the option is true, the |
| 119 | /// StandardID is selected if the target provides no default. |
Andrew Trick | 5ed0283 | 2013-04-10 01:06:56 +0000 | [diff] [blame] | 120 | static IdentifyingPassPtr applyOverride(IdentifyingPassPtr TargetID, |
| 121 | cl::boolOrDefault Override, |
| 122 | AnalysisID StandardID) { |
Andrew Trick | 746f24b | 2012-02-11 07:11:32 +0000 | [diff] [blame] | 123 | switch (Override) { |
| 124 | case cl::BOU_UNSET: |
Andrew Trick | 79bf288 | 2012-02-15 03:21:51 +0000 | [diff] [blame] | 125 | return TargetID; |
Andrew Trick | 746f24b | 2012-02-11 07:11:32 +0000 | [diff] [blame] | 126 | case cl::BOU_TRUE: |
Andrew Trick | 5ed0283 | 2013-04-10 01:06:56 +0000 | [diff] [blame] | 127 | if (TargetID.isValid()) |
Andrew Trick | 79bf288 | 2012-02-15 03:21:51 +0000 | [diff] [blame] | 128 | return TargetID; |
Stephen Hines | dce4a40 | 2014-05-29 02:49:00 -0700 | [diff] [blame^] | 129 | if (StandardID == nullptr) |
Andrew Trick | 746f24b | 2012-02-11 07:11:32 +0000 | [diff] [blame] | 130 | report_fatal_error("Target cannot enable pass"); |
Andrew Trick | 79bf288 | 2012-02-15 03:21:51 +0000 | [diff] [blame] | 131 | return StandardID; |
Andrew Trick | 746f24b | 2012-02-11 07:11:32 +0000 | [diff] [blame] | 132 | case cl::BOU_FALSE: |
Andrew Trick | 5ed0283 | 2013-04-10 01:06:56 +0000 | [diff] [blame] | 133 | return IdentifyingPassPtr(); |
Andrew Trick | 746f24b | 2012-02-11 07:11:32 +0000 | [diff] [blame] | 134 | } |
| 135 | llvm_unreachable("Invalid command line option state"); |
| 136 | } |
| 137 | |
Andrew Trick | 79bf288 | 2012-02-15 03:21:51 +0000 | [diff] [blame] | 138 | /// Allow standard passes to be disabled by the command line, regardless of who |
| 139 | /// is adding the pass. |
| 140 | /// |
| 141 | /// StandardID is the pass identified in the standard pass pipeline and provided |
| 142 | /// to addPass(). It may be a target-specific ID in the case that the target |
| 143 | /// directly adds its own pass, but in that case we harmlessly fall through. |
| 144 | /// |
| 145 | /// TargetID is the pass that the target has configured to override StandardID. |
| 146 | /// |
| 147 | /// StandardID may be a pseudo ID. In that case TargetID is the name of the real |
| 148 | /// pass to run. This allows multiple options to control a single pass depending |
| 149 | /// on where in the pipeline that pass is added. |
Andrew Trick | 5ed0283 | 2013-04-10 01:06:56 +0000 | [diff] [blame] | 150 | static IdentifyingPassPtr overridePass(AnalysisID StandardID, |
| 151 | IdentifyingPassPtr TargetID) { |
Andrew Trick | 79bf288 | 2012-02-15 03:21:51 +0000 | [diff] [blame] | 152 | if (StandardID == &PostRASchedulerID) |
| 153 | return applyDisable(TargetID, DisablePostRA); |
| 154 | |
| 155 | if (StandardID == &BranchFolderPassID) |
| 156 | return applyDisable(TargetID, DisableBranchFold); |
| 157 | |
| 158 | if (StandardID == &TailDuplicateID) |
| 159 | return applyDisable(TargetID, DisableTailDuplicate); |
| 160 | |
| 161 | if (StandardID == &TargetPassConfig::EarlyTailDuplicateID) |
| 162 | return applyDisable(TargetID, DisableEarlyTailDup); |
| 163 | |
| 164 | if (StandardID == &MachineBlockPlacementID) |
Benjamin Kramer | 74a4533 | 2013-03-29 17:14:24 +0000 | [diff] [blame] | 165 | return applyDisable(TargetID, DisableBlockPlacement); |
Andrew Trick | 79bf288 | 2012-02-15 03:21:51 +0000 | [diff] [blame] | 166 | |
| 167 | if (StandardID == &StackSlotColoringID) |
| 168 | return applyDisable(TargetID, DisableSSC); |
| 169 | |
| 170 | if (StandardID == &DeadMachineInstructionElimID) |
| 171 | return applyDisable(TargetID, DisableMachineDCE); |
| 172 | |
Jakob Stoklund Olesen | 33242fd | 2012-07-04 00:09:54 +0000 | [diff] [blame] | 173 | if (StandardID == &EarlyIfConverterID) |
Jakob Stoklund Olesen | 0d141f8 | 2012-10-03 00:51:32 +0000 | [diff] [blame] | 174 | return applyDisable(TargetID, DisableEarlyIfConversion); |
Jakob Stoklund Olesen | 33242fd | 2012-07-04 00:09:54 +0000 | [diff] [blame] | 175 | |
Andrew Trick | 79bf288 | 2012-02-15 03:21:51 +0000 | [diff] [blame] | 176 | if (StandardID == &MachineLICMID) |
| 177 | return applyDisable(TargetID, DisableMachineLICM); |
| 178 | |
| 179 | if (StandardID == &MachineCSEID) |
| 180 | return applyDisable(TargetID, DisableMachineCSE); |
| 181 | |
| 182 | if (StandardID == &MachineSchedulerID) |
| 183 | return applyOverride(TargetID, EnableMachineSched, StandardID); |
| 184 | |
| 185 | if (StandardID == &TargetPassConfig::PostRAMachineLICMID) |
| 186 | return applyDisable(TargetID, DisablePostRAMachineLICM); |
| 187 | |
| 188 | if (StandardID == &MachineSinkingID) |
| 189 | return applyDisable(TargetID, DisableMachineSink); |
| 190 | |
| 191 | if (StandardID == &MachineCopyPropagationID) |
| 192 | return applyDisable(TargetID, DisableCopyProp); |
| 193 | |
| 194 | return TargetID; |
| 195 | } |
| 196 | |
Jim Laskey | eb577ba | 2006-08-02 12:30:23 +0000 | [diff] [blame] | 197 | //===---------------------------------------------------------------------===// |
Andrew Trick | 7461334 | 2012-02-04 02:56:45 +0000 | [diff] [blame] | 198 | /// TargetPassConfig |
| 199 | //===---------------------------------------------------------------------===// |
| 200 | |
| 201 | INITIALIZE_PASS(TargetPassConfig, "targetpassconfig", |
| 202 | "Target Pass Configuration", false, false) |
| 203 | char TargetPassConfig::ID = 0; |
| 204 | |
Andrew Trick | 79bf288 | 2012-02-15 03:21:51 +0000 | [diff] [blame] | 205 | // Pseudo Pass IDs. |
| 206 | char TargetPassConfig::EarlyTailDuplicateID = 0; |
| 207 | char TargetPassConfig::PostRAMachineLICMID = 0; |
| 208 | |
Andrew Trick | 5e108ee | 2012-02-15 03:21:47 +0000 | [diff] [blame] | 209 | namespace llvm { |
| 210 | class PassConfigImpl { |
| 211 | public: |
| 212 | // List of passes explicitly substituted by this target. Normally this is |
| 213 | // empty, but it is a convenient way to suppress or replace specific passes |
| 214 | // that are part of a standard pass pipeline without overridding the entire |
| 215 | // pipeline. This mechanism allows target options to inherit a standard pass's |
| 216 | // user interface. For example, a target may disable a standard pass by |
Bob Wilson | 3fb99a7 | 2012-07-02 19:48:37 +0000 | [diff] [blame] | 217 | // default by substituting a pass ID of zero, and the user may still enable |
| 218 | // that standard pass with an explicit command line option. |
Andrew Trick | 5ed0283 | 2013-04-10 01:06:56 +0000 | [diff] [blame] | 219 | DenseMap<AnalysisID,IdentifyingPassPtr> TargetPasses; |
Bob Wilson | 6e1b812 | 2012-05-30 00:17:12 +0000 | [diff] [blame] | 220 | |
| 221 | /// Store the pairs of <AnalysisID, AnalysisID> of which the second pass |
| 222 | /// is inserted after each instance of the first one. |
Andrew Trick | 5ed0283 | 2013-04-10 01:06:56 +0000 | [diff] [blame] | 223 | SmallVector<std::pair<AnalysisID, IdentifyingPassPtr>, 4> InsertedPasses; |
Andrew Trick | 5e108ee | 2012-02-15 03:21:47 +0000 | [diff] [blame] | 224 | }; |
| 225 | } // namespace llvm |
| 226 | |
Andrew Trick | 7461334 | 2012-02-04 02:56:45 +0000 | [diff] [blame] | 227 | // Out of line virtual method. |
Andrew Trick | 5e108ee | 2012-02-15 03:21:47 +0000 | [diff] [blame] | 228 | TargetPassConfig::~TargetPassConfig() { |
| 229 | delete Impl; |
| 230 | } |
Andrew Trick | 7461334 | 2012-02-04 02:56:45 +0000 | [diff] [blame] | 231 | |
Andrew Trick | 61f1e3d | 2012-02-08 21:22:48 +0000 | [diff] [blame] | 232 | // Out of line constructor provides default values for pass options and |
| 233 | // registers all common codegen passes. |
Andrew Trick | 061efcf | 2012-02-04 02:56:59 +0000 | [diff] [blame] | 234 | TargetPassConfig::TargetPassConfig(TargetMachine *tm, PassManagerBase &pm) |
Stephen Hines | dce4a40 | 2014-05-29 02:49:00 -0700 | [diff] [blame^] | 235 | : ImmutablePass(ID), PM(&pm), StartAfter(nullptr), StopAfter(nullptr), |
| 236 | Started(true), Stopped(false), TM(tm), Impl(nullptr), Initialized(false), |
Andrew Trick | ffea03f | 2012-02-08 21:22:39 +0000 | [diff] [blame] | 237 | DisableVerify(false), |
| 238 | EnableTailMerge(true) { |
| 239 | |
Andrew Trick | 5e108ee | 2012-02-15 03:21:47 +0000 | [diff] [blame] | 240 | Impl = new PassConfigImpl(); |
| 241 | |
Andrew Trick | 7461334 | 2012-02-04 02:56:45 +0000 | [diff] [blame] | 242 | // Register all target independent codegen passes to activate their PassIDs, |
| 243 | // including this pass itself. |
| 244 | initializeCodeGen(*PassRegistry::getPassRegistry()); |
Andrew Trick | 79bf288 | 2012-02-15 03:21:51 +0000 | [diff] [blame] | 245 | |
| 246 | // Substitute Pseudo Pass IDs for real ones. |
Bob Wilson | 3fb99a7 | 2012-07-02 19:48:37 +0000 | [diff] [blame] | 247 | substitutePass(&EarlyTailDuplicateID, &TailDuplicateID); |
| 248 | substitutePass(&PostRAMachineLICMID, &MachineLICMID); |
Andrew Trick | 79bf288 | 2012-02-15 03:21:51 +0000 | [diff] [blame] | 249 | |
| 250 | // Temporarily disable experimental passes. |
Andrew Trick | ad1cc1d | 2012-11-13 08:47:29 +0000 | [diff] [blame] | 251 | const TargetSubtargetInfo &ST = TM->getSubtarget<TargetSubtargetInfo>(); |
Andrew Trick | b6ac11c | 2013-09-26 05:53:35 +0000 | [diff] [blame] | 252 | if (!ST.useMachineScheduler()) |
Andrew Trick | ad1cc1d | 2012-11-13 08:47:29 +0000 | [diff] [blame] | 253 | disablePass(&MachineSchedulerID); |
Andrew Trick | 7461334 | 2012-02-04 02:56:45 +0000 | [diff] [blame] | 254 | } |
| 255 | |
Bob Wilson | 6e1b812 | 2012-05-30 00:17:12 +0000 | [diff] [blame] | 256 | /// Insert InsertedPassID pass after TargetPassID. |
Bob Wilson | 3fb99a7 | 2012-07-02 19:48:37 +0000 | [diff] [blame] | 257 | void TargetPassConfig::insertPass(AnalysisID TargetPassID, |
Andrew Trick | 5ed0283 | 2013-04-10 01:06:56 +0000 | [diff] [blame] | 258 | IdentifyingPassPtr InsertedPassID) { |
Benjamin Kramer | fdca221 | 2013-04-11 11:57:01 +0000 | [diff] [blame] | 259 | assert(((!InsertedPassID.isInstance() && |
| 260 | TargetPassID != InsertedPassID.getID()) || |
| 261 | (InsertedPassID.isInstance() && |
| 262 | TargetPassID != InsertedPassID.getInstance()->getPassID())) && |
Andrew Trick | 5ed0283 | 2013-04-10 01:06:56 +0000 | [diff] [blame] | 263 | "Insert a pass after itself!"); |
| 264 | std::pair<AnalysisID, IdentifyingPassPtr> P(TargetPassID, InsertedPassID); |
Bob Wilson | 6e1b812 | 2012-05-30 00:17:12 +0000 | [diff] [blame] | 265 | Impl->InsertedPasses.push_back(P); |
| 266 | } |
| 267 | |
Andrew Trick | 7461334 | 2012-02-04 02:56:45 +0000 | [diff] [blame] | 268 | /// createPassConfig - Create a pass configuration object to be used by |
| 269 | /// addPassToEmitX methods for generating a pipeline of CodeGen passes. |
| 270 | /// |
| 271 | /// Targets may override this to extend TargetPassConfig. |
Andrew Trick | 061efcf | 2012-02-04 02:56:59 +0000 | [diff] [blame] | 272 | TargetPassConfig *LLVMTargetMachine::createPassConfig(PassManagerBase &PM) { |
| 273 | return new TargetPassConfig(this, PM); |
Andrew Trick | 7461334 | 2012-02-04 02:56:45 +0000 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | TargetPassConfig::TargetPassConfig() |
Stephen Hines | dce4a40 | 2014-05-29 02:49:00 -0700 | [diff] [blame^] | 277 | : ImmutablePass(ID), PM(nullptr) { |
Andrew Trick | 7461334 | 2012-02-04 02:56:45 +0000 | [diff] [blame] | 278 | llvm_unreachable("TargetPassConfig should not be constructed on-the-fly"); |
| 279 | } |
| 280 | |
Andrew Trick | ffea03f | 2012-02-08 21:22:39 +0000 | [diff] [blame] | 281 | // Helper to verify the analysis is really immutable. |
| 282 | void TargetPassConfig::setOpt(bool &Opt, bool Val) { |
| 283 | assert(!Initialized && "PassConfig is immutable"); |
| 284 | Opt = Val; |
| 285 | } |
| 286 | |
Bob Wilson | 3fb99a7 | 2012-07-02 19:48:37 +0000 | [diff] [blame] | 287 | void TargetPassConfig::substitutePass(AnalysisID StandardID, |
Andrew Trick | 5ed0283 | 2013-04-10 01:06:56 +0000 | [diff] [blame] | 288 | IdentifyingPassPtr TargetID) { |
Bob Wilson | 3fb99a7 | 2012-07-02 19:48:37 +0000 | [diff] [blame] | 289 | Impl->TargetPasses[StandardID] = TargetID; |
Andrew Trick | 5e108ee | 2012-02-15 03:21:47 +0000 | [diff] [blame] | 290 | } |
Andrew Trick | 746f24b | 2012-02-11 07:11:32 +0000 | [diff] [blame] | 291 | |
Andrew Trick | 5ed0283 | 2013-04-10 01:06:56 +0000 | [diff] [blame] | 292 | IdentifyingPassPtr TargetPassConfig::getPassSubstitution(AnalysisID ID) const { |
| 293 | DenseMap<AnalysisID, IdentifyingPassPtr>::const_iterator |
Andrew Trick | 5e108ee | 2012-02-15 03:21:47 +0000 | [diff] [blame] | 294 | I = Impl->TargetPasses.find(ID); |
| 295 | if (I == Impl->TargetPasses.end()) |
| 296 | return ID; |
| 297 | return I->second; |
| 298 | } |
| 299 | |
Bob Wilson | 30a507a | 2012-07-02 19:48:45 +0000 | [diff] [blame] | 300 | /// Add a pass to the PassManager if that pass is supposed to be run. If the |
| 301 | /// Started/Stopped flags indicate either that the compilation should start at |
| 302 | /// a later pass or that it should stop after an earlier pass, then do not add |
| 303 | /// the pass. Finally, compare the current pass against the StartAfter |
| 304 | /// and StopAfter options and change the Started/Stopped flags accordingly. |
Bob Wilson | 564fbf6 | 2012-07-02 19:48:31 +0000 | [diff] [blame] | 305 | void TargetPassConfig::addPass(Pass *P) { |
Bob Wilson | 6b2bb15 | 2012-07-02 19:48:39 +0000 | [diff] [blame] | 306 | assert(!Initialized && "PassConfig is immutable"); |
| 307 | |
Chandler Carruth | 6068c48 | 2012-07-02 22:56:41 +0000 | [diff] [blame] | 308 | // Cache the Pass ID here in case the pass manager finds this pass is |
| 309 | // redundant with ones already scheduled / available, and deletes it. |
| 310 | // Fundamentally, once we add the pass to the manager, we no longer own it |
| 311 | // and shouldn't reference it. |
| 312 | AnalysisID PassID = P->getPassID(); |
| 313 | |
Bob Wilson | 30a507a | 2012-07-02 19:48:45 +0000 | [diff] [blame] | 314 | if (Started && !Stopped) |
| 315 | PM->add(P); |
Benjamin Kramer | f8e16c6 | 2013-08-05 11:11:11 +0000 | [diff] [blame] | 316 | else |
| 317 | delete P; |
Chandler Carruth | 6068c48 | 2012-07-02 22:56:41 +0000 | [diff] [blame] | 318 | if (StopAfter == PassID) |
Bob Wilson | 30a507a | 2012-07-02 19:48:45 +0000 | [diff] [blame] | 319 | Stopped = true; |
Chandler Carruth | 6068c48 | 2012-07-02 22:56:41 +0000 | [diff] [blame] | 320 | if (StartAfter == PassID) |
Bob Wilson | 30a507a | 2012-07-02 19:48:45 +0000 | [diff] [blame] | 321 | Started = true; |
| 322 | if (Stopped && !Started) |
| 323 | report_fatal_error("Cannot stop compilation after pass that is not run"); |
Bob Wilson | 564fbf6 | 2012-07-02 19:48:31 +0000 | [diff] [blame] | 324 | } |
| 325 | |
Andrew Trick | 5e108ee | 2012-02-15 03:21:47 +0000 | [diff] [blame] | 326 | /// Add a CodeGen pass at this point in the pipeline after checking for target |
| 327 | /// and command line overrides. |
Andrew Trick | 5ed0283 | 2013-04-10 01:06:56 +0000 | [diff] [blame] | 328 | /// |
| 329 | /// addPass cannot return a pointer to the pass instance because is internal the |
| 330 | /// PassManager and the instance we create here may already be freed. |
Bob Wilson | 3fb99a7 | 2012-07-02 19:48:37 +0000 | [diff] [blame] | 331 | AnalysisID TargetPassConfig::addPass(AnalysisID PassID) { |
Andrew Trick | 5ed0283 | 2013-04-10 01:06:56 +0000 | [diff] [blame] | 332 | IdentifyingPassPtr TargetID = getPassSubstitution(PassID); |
| 333 | IdentifyingPassPtr FinalPtr = overridePass(PassID, TargetID); |
| 334 | if (!FinalPtr.isValid()) |
Stephen Hines | dce4a40 | 2014-05-29 02:49:00 -0700 | [diff] [blame^] | 335 | return nullptr; |
Andrew Trick | 5e108ee | 2012-02-15 03:21:47 +0000 | [diff] [blame] | 336 | |
Andrew Trick | 5ed0283 | 2013-04-10 01:06:56 +0000 | [diff] [blame] | 337 | Pass *P; |
| 338 | if (FinalPtr.isInstance()) |
| 339 | P = FinalPtr.getInstance(); |
| 340 | else { |
| 341 | P = Pass::createPass(FinalPtr.getID()); |
| 342 | if (!P) |
| 343 | llvm_unreachable("Pass ID not registered"); |
| 344 | } |
| 345 | AnalysisID FinalID = P->getPassID(); |
| 346 | addPass(P); // Ends the lifetime of P. |
| 347 | |
Bob Wilson | 6e1b812 | 2012-05-30 00:17:12 +0000 | [diff] [blame] | 348 | // Add the passes after the pass P if there is any. |
Craig Topper | f22fd3f | 2013-07-03 05:11:49 +0000 | [diff] [blame] | 349 | for (SmallVectorImpl<std::pair<AnalysisID, IdentifyingPassPtr> >::iterator |
Bob Wilson | 6e1b812 | 2012-05-30 00:17:12 +0000 | [diff] [blame] | 350 | I = Impl->InsertedPasses.begin(), E = Impl->InsertedPasses.end(); |
| 351 | I != E; ++I) { |
Bob Wilson | 3fb99a7 | 2012-07-02 19:48:37 +0000 | [diff] [blame] | 352 | if ((*I).first == PassID) { |
Andrew Trick | 5ed0283 | 2013-04-10 01:06:56 +0000 | [diff] [blame] | 353 | assert((*I).second.isValid() && "Illegal Pass ID!"); |
| 354 | Pass *NP; |
| 355 | if ((*I).second.isInstance()) |
| 356 | NP = (*I).second.getInstance(); |
| 357 | else { |
| 358 | NP = Pass::createPass((*I).second.getID()); |
| 359 | assert(NP && "Pass ID not registered"); |
| 360 | } |
Bob Wilson | 564fbf6 | 2012-07-02 19:48:31 +0000 | [diff] [blame] | 361 | addPass(NP); |
Bob Wilson | 6e1b812 | 2012-05-30 00:17:12 +0000 | [diff] [blame] | 362 | } |
| 363 | } |
Andrew Trick | 5e108ee | 2012-02-15 03:21:47 +0000 | [diff] [blame] | 364 | return FinalID; |
Andrew Trick | 061efcf | 2012-02-04 02:56:59 +0000 | [diff] [blame] | 365 | } |
Andrew Trick | d542265 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 366 | |
Bob Wilson | 564fbf6 | 2012-07-02 19:48:31 +0000 | [diff] [blame] | 367 | void TargetPassConfig::printAndVerify(const char *Banner) { |
Andrew Trick | d542265 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 368 | if (TM->shouldPrintMachineCode()) |
Bob Wilson | 564fbf6 | 2012-07-02 19:48:31 +0000 | [diff] [blame] | 369 | addPass(createMachineFunctionPrinterPass(dbgs(), Banner)); |
Andrew Trick | d542265 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 370 | |
| 371 | if (VerifyMachineCode) |
Bob Wilson | 564fbf6 | 2012-07-02 19:48:31 +0000 | [diff] [blame] | 372 | addPass(createMachineVerifierPass(Banner)); |
Andrew Trick | d542265 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 373 | } |
| 374 | |
Andrew Trick | 061efcf | 2012-02-04 02:56:59 +0000 | [diff] [blame] | 375 | /// Add common target configurable passes that perform LLVM IR to IR transforms |
| 376 | /// following machine independent optimization. |
| 377 | void TargetPassConfig::addIRPasses() { |
Andrew Trick | d542265 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 378 | // Basic AliasAnalysis support. |
| 379 | // Add TypeBasedAliasAnalysis before BasicAliasAnalysis so that |
| 380 | // BasicAliasAnalysis wins if they disagree. This is intended to help |
| 381 | // support "obvious" type-punning idioms. |
Bob Wilson | 564fbf6 | 2012-07-02 19:48:31 +0000 | [diff] [blame] | 382 | addPass(createTypeBasedAliasAnalysisPass()); |
| 383 | addPass(createBasicAliasAnalysisPass()); |
Andrew Trick | d542265 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 384 | |
| 385 | // Before running any passes, run the verifier to determine if the input |
| 386 | // coming from the front-end and/or optimizer is valid. |
Stephen Hines | dce4a40 | 2014-05-29 02:49:00 -0700 | [diff] [blame^] | 387 | if (!DisableVerify) { |
Bob Wilson | 564fbf6 | 2012-07-02 19:48:31 +0000 | [diff] [blame] | 388 | addPass(createVerifierPass()); |
Stephen Hines | dce4a40 | 2014-05-29 02:49:00 -0700 | [diff] [blame^] | 389 | addPass(createDebugInfoVerifierPass()); |
| 390 | } |
Andrew Trick | d542265 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 391 | |
| 392 | // Run loop strength reduction before anything else. |
| 393 | if (getOptLevel() != CodeGenOpt::None && !DisableLSR) { |
Chandler Carruth | e4ba75f | 2013-01-07 14:41:08 +0000 | [diff] [blame] | 394 | addPass(createLoopStrengthReducePass()); |
Andrew Trick | d542265 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 395 | if (PrintLSR) |
Stephen Hines | 36b5688 | 2014-04-23 16:57:46 -0700 | [diff] [blame] | 396 | addPass(createPrintFunctionPass(dbgs(), "\n\n*** Code after LSR ***\n")); |
Andrew Trick | d542265 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 397 | } |
| 398 | |
Bob Wilson | 564fbf6 | 2012-07-02 19:48:31 +0000 | [diff] [blame] | 399 | addPass(createGCLoweringPass()); |
Andrew Trick | d542265 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 400 | |
| 401 | // Make sure that no unreachable blocks are instruction selected. |
Bob Wilson | 564fbf6 | 2012-07-02 19:48:31 +0000 | [diff] [blame] | 402 | addPass(createUnreachableBlockEliminationPass()); |
Stephen Hines | 36b5688 | 2014-04-23 16:57:46 -0700 | [diff] [blame] | 403 | |
| 404 | // Prepare expensive constants for SelectionDAG. |
| 405 | if (getOptLevel() != CodeGenOpt::None && !DisableConstantHoisting) |
| 406 | addPass(createConstantHoistingPass()); |
Bob Wilson | 564fbf6 | 2012-07-02 19:48:31 +0000 | [diff] [blame] | 407 | } |
| 408 | |
| 409 | /// Turn exception handling constructs into something the code generators can |
| 410 | /// handle. |
| 411 | void TargetPassConfig::addPassesToHandleExceptions() { |
| 412 | switch (TM->getMCAsmInfo()->getExceptionHandlingType()) { |
| 413 | case ExceptionHandling::SjLj: |
| 414 | // SjLj piggy-backs on dwarf for this bit. The cleanups done apply to both |
| 415 | // Dwarf EH prepare needs to be run after SjLj prepare. Otherwise, |
| 416 | // catch info can get misplaced when a selector ends up more than one block |
| 417 | // removed from the parent invoke(s). This could happen when a landing |
| 418 | // pad is shared by multiple invokes and is also a target of a normal |
| 419 | // edge from elsewhere. |
Bill Wendling | ea44281 | 2013-06-19 20:51:24 +0000 | [diff] [blame] | 420 | addPass(createSjLjEHPreparePass(TM)); |
Bob Wilson | 564fbf6 | 2012-07-02 19:48:31 +0000 | [diff] [blame] | 421 | // FALLTHROUGH |
| 422 | case ExceptionHandling::DwarfCFI: |
| 423 | case ExceptionHandling::ARM: |
| 424 | case ExceptionHandling::Win64: |
Bill Wendling | ea44281 | 2013-06-19 20:51:24 +0000 | [diff] [blame] | 425 | addPass(createDwarfEHPass(TM)); |
Bob Wilson | 564fbf6 | 2012-07-02 19:48:31 +0000 | [diff] [blame] | 426 | break; |
| 427 | case ExceptionHandling::None: |
Stephen Hines | 36b5688 | 2014-04-23 16:57:46 -0700 | [diff] [blame] | 428 | addPass(createLowerInvokePass()); |
Bob Wilson | 564fbf6 | 2012-07-02 19:48:31 +0000 | [diff] [blame] | 429 | |
| 430 | // The lower invoke pass may create unreachable code. Remove it. |
| 431 | addPass(createUnreachableBlockEliminationPass()); |
| 432 | break; |
| 433 | } |
Andrew Trick | 061efcf | 2012-02-04 02:56:59 +0000 | [diff] [blame] | 434 | } |
Andrew Trick | d542265 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 435 | |
Bill Wendling | 08510b1 | 2012-11-30 22:08:55 +0000 | [diff] [blame] | 436 | /// Add pass to prepare the LLVM IR for code generation. This should be done |
| 437 | /// before exception handling preparation passes. |
| 438 | void TargetPassConfig::addCodeGenPrepare() { |
| 439 | if (getOptLevel() != CodeGenOpt::None && !DisableCGP) |
Bill Wendling | f9fd58a | 2013-06-19 21:07:11 +0000 | [diff] [blame] | 440 | addPass(createCodeGenPreparePass(TM)); |
Bill Wendling | 08510b1 | 2012-11-30 22:08:55 +0000 | [diff] [blame] | 441 | } |
| 442 | |
Andrew Trick | 061efcf | 2012-02-04 02:56:59 +0000 | [diff] [blame] | 443 | /// Add common passes that perform LLVM IR to IR transforms in preparation for |
| 444 | /// instruction selection. |
| 445 | void TargetPassConfig::addISelPrepare() { |
Andrew Trick | d542265 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 446 | addPreISel(); |
| 447 | |
Stephen Hines | dce4a40 | 2014-05-29 02:49:00 -0700 | [diff] [blame^] | 448 | // Need to verify DebugInfo *before* creating the stack protector analysis. |
| 449 | // It's a function pass, and verifying between it and its users causes a |
| 450 | // crash. |
| 451 | if (!DisableVerify) |
| 452 | addPass(createDebugInfoVerifierPass()); |
| 453 | |
Stephen Hines | 36b5688 | 2014-04-23 16:57:46 -0700 | [diff] [blame] | 454 | addPass(createStackProtectorPass(TM)); |
| 455 | |
Andrew Trick | d542265 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 456 | if (PrintISelInput) |
Stephen Hines | 36b5688 | 2014-04-23 16:57:46 -0700 | [diff] [blame] | 457 | addPass(createPrintFunctionPass( |
| 458 | dbgs(), "\n\n*** Final LLVM Code input to ISel ***\n")); |
Andrew Trick | d542265 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 459 | |
| 460 | // All passes which modify the LLVM IR are now complete; run the verifier |
| 461 | // to ensure that the IR is valid. |
| 462 | if (!DisableVerify) |
Bob Wilson | 564fbf6 | 2012-07-02 19:48:31 +0000 | [diff] [blame] | 463 | addPass(createVerifierPass()); |
Andrew Trick | 061efcf | 2012-02-04 02:56:59 +0000 | [diff] [blame] | 464 | } |
Andrew Trick | d542265 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 465 | |
Andrew Trick | f7b9631 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 466 | /// Add the complete set of target-independent postISel code generator passes. |
| 467 | /// |
| 468 | /// This can be read as the standard order of major LLVM CodeGen stages. Stages |
| 469 | /// with nontrivial configuration or multiple passes are broken out below in |
| 470 | /// add%Stage routines. |
| 471 | /// |
| 472 | /// Any TargetPassConfig::addXX routine may be overriden by the Target. The |
| 473 | /// addPre/Post methods with empty header implementations allow injecting |
| 474 | /// target-specific fixups just before or after major stages. Additionally, |
| 475 | /// targets have the flexibility to change pass order within a stage by |
| 476 | /// overriding default implementation of add%Stage routines below. Each |
| 477 | /// technique has maintainability tradeoffs because alternate pass orders are |
| 478 | /// not well supported. addPre/Post works better if the target pass is easily |
| 479 | /// 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] | 480 | /// the target should override the stage instead. |
Andrew Trick | f7b9631 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 481 | /// |
| 482 | /// TODO: We could use a single addPre/Post(ID) hook to allow pass injection |
| 483 | /// before/after any target-independent pass. But it's currently overkill. |
Andrew Trick | 061efcf | 2012-02-04 02:56:59 +0000 | [diff] [blame] | 484 | void TargetPassConfig::addMachinePasses() { |
Bob Wilson | 6e1b812 | 2012-05-30 00:17:12 +0000 | [diff] [blame] | 485 | // Insert a machine instr printer pass after the specified pass. |
| 486 | // If -print-machineinstrs specified, print machineinstrs after all passes. |
| 487 | if (StringRef(PrintMachineInstrs.getValue()).equals("")) |
| 488 | TM->Options.PrintMachineCode = true; |
| 489 | else if (!StringRef(PrintMachineInstrs.getValue()) |
| 490 | .equals("option-unspecified")) { |
| 491 | const PassRegistry *PR = PassRegistry::getPassRegistry(); |
| 492 | const PassInfo *TPI = PR->getPassInfo(PrintMachineInstrs.getValue()); |
| 493 | const PassInfo *IPI = PR->getPassInfo(StringRef("print-machineinstrs")); |
| 494 | assert (TPI && IPI && "Pass ID not registered!"); |
Roman Divacky | 5932429 | 2012-09-05 22:26:57 +0000 | [diff] [blame] | 495 | const char *TID = (const char *)(TPI->getTypeInfo()); |
| 496 | const char *IID = (const char *)(IPI->getTypeInfo()); |
Bob Wilson | 3fb99a7 | 2012-07-02 19:48:37 +0000 | [diff] [blame] | 497 | insertPass(TID, IID); |
Bob Wilson | 6e1b812 | 2012-05-30 00:17:12 +0000 | [diff] [blame] | 498 | } |
| 499 | |
Jakob Stoklund Olesen | f86c00f | 2012-07-04 19:28:27 +0000 | [diff] [blame] | 500 | // Print the instruction selected machine code... |
| 501 | printAndVerify("After Instruction Selection"); |
| 502 | |
Andrew Trick | d542265 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 503 | // Expand pseudo-instructions emitted by ISel. |
Jakob Stoklund Olesen | 228e3f5 | 2012-08-20 20:52:08 +0000 | [diff] [blame] | 504 | if (addPass(&ExpandISelPseudosID)) |
| 505 | printAndVerify("After ExpandISelPseudos"); |
Andrew Trick | d542265 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 506 | |
Andrew Trick | f7b9631 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 507 | // Add passes that optimize machine instructions in SSA form. |
Andrew Trick | d542265 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 508 | if (getOptLevel() != CodeGenOpt::None) { |
Andrew Trick | f7b9631 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 509 | addMachineSSAOptimization(); |
Craig Topper | 8f54a53 | 2012-11-19 00:11:50 +0000 | [diff] [blame] | 510 | } else { |
Andrew Trick | f7b9631 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 511 | // If the target requests it, assign local variables to stack slots relative |
| 512 | // to one another and simplify frame index references where possible. |
Bob Wilson | 3fb99a7 | 2012-07-02 19:48:37 +0000 | [diff] [blame] | 513 | addPass(&LocalStackSlotAllocationID); |
Andrew Trick | d542265 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 514 | } |
| 515 | |
| 516 | // Run pre-ra passes. |
| 517 | if (addPreRegAlloc()) |
| 518 | printAndVerify("After PreRegAlloc passes"); |
| 519 | |
Andrew Trick | f7b9631 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 520 | // Run register allocation and passes that are tightly coupled with it, |
| 521 | // including phi elimination and scheduling. |
Andrew Trick | 8dd2625 | 2012-02-10 04:10:36 +0000 | [diff] [blame] | 522 | if (getOptimizeRegAlloc()) |
| 523 | addOptimizedRegAlloc(createRegAllocPass(true)); |
| 524 | else |
| 525 | addFastRegAlloc(createRegAllocPass(false)); |
Andrew Trick | d542265 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 526 | |
| 527 | // Run post-ra passes. |
| 528 | if (addPostRegAlloc()) |
| 529 | printAndVerify("After PostRegAlloc passes"); |
| 530 | |
| 531 | // Insert prolog/epilog code. Eliminate abstract frame index references... |
Bob Wilson | 3fb99a7 | 2012-07-02 19:48:37 +0000 | [diff] [blame] | 532 | addPass(&PrologEpilogCodeInserterID); |
Andrew Trick | d542265 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 533 | printAndVerify("After PrologEpilogCodeInserter"); |
| 534 | |
Andrew Trick | f7b9631 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 535 | /// Add passes that optimize machine instructions after register allocation. |
| 536 | if (getOptLevel() != CodeGenOpt::None) |
| 537 | addMachineLateOptimization(); |
Andrew Trick | d542265 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 538 | |
| 539 | // Expand pseudo instructions before second scheduling pass. |
Bob Wilson | 3fb99a7 | 2012-07-02 19:48:37 +0000 | [diff] [blame] | 540 | addPass(&ExpandPostRAPseudosID); |
Jakob Stoklund Olesen | 2ef5bf6 | 2012-03-28 20:49:30 +0000 | [diff] [blame] | 541 | printAndVerify("After ExpandPostRAPseudos"); |
Andrew Trick | d542265 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 542 | |
| 543 | // Run pre-sched2 passes. |
| 544 | if (addPreSched2()) |
Jakob Stoklund Olesen | 7881166 | 2012-03-28 23:31:15 +0000 | [diff] [blame] | 545 | printAndVerify("After PreSched2 passes"); |
Andrew Trick | d542265 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 546 | |
| 547 | // Second pass scheduler. |
Andrew Trick | 79bf288 | 2012-02-15 03:21:51 +0000 | [diff] [blame] | 548 | if (getOptLevel() != CodeGenOpt::None) { |
Stephen Hines | 36b5688 | 2014-04-23 16:57:46 -0700 | [diff] [blame] | 549 | if (MISchedPostRA) |
| 550 | addPass(&PostMachineSchedulerID); |
| 551 | else |
| 552 | addPass(&PostRASchedulerID); |
Jakob Stoklund Olesen | 8b4c502 | 2012-03-28 23:54:28 +0000 | [diff] [blame] | 553 | printAndVerify("After PostRAScheduler"); |
Andrew Trick | d542265 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 554 | } |
| 555 | |
Andrew Trick | f7b9631 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 556 | // GC |
Evan Cheng | ab37b2c | 2012-12-21 02:57:04 +0000 | [diff] [blame] | 557 | if (addGCPasses()) { |
| 558 | if (PrintGCInfo) |
| 559 | addPass(createGCInfoPrinter(dbgs())); |
| 560 | } |
Andrew Trick | d542265 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 561 | |
Andrew Trick | f7b9631 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 562 | // Basic block placement. |
Andrew Trick | 79bf288 | 2012-02-15 03:21:51 +0000 | [diff] [blame] | 563 | if (getOptLevel() != CodeGenOpt::None) |
Andrew Trick | f7b9631 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 564 | addBlockPlacement(); |
Andrew Trick | d542265 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 565 | |
| 566 | if (addPreEmitPass()) |
Jakob Stoklund Olesen | 8b4c502 | 2012-03-28 23:54:28 +0000 | [diff] [blame] | 567 | printAndVerify("After PreEmit passes"); |
Stephen Hines | 36b5688 | 2014-04-23 16:57:46 -0700 | [diff] [blame] | 568 | |
| 569 | if (EnableStackMapLiveness || EnablePatchPointLiveness) |
| 570 | addPass(&StackMapLivenessID); |
Andrew Trick | d542265 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 571 | } |
| 572 | |
Andrew Trick | f7b9631 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 573 | /// Add passes that optimize machine instructions in SSA form. |
| 574 | void TargetPassConfig::addMachineSSAOptimization() { |
| 575 | // Pre-ra tail duplication. |
Bob Wilson | 3fb99a7 | 2012-07-02 19:48:37 +0000 | [diff] [blame] | 576 | if (addPass(&EarlyTailDuplicateID)) |
Andrew Trick | f7b9631 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 577 | printAndVerify("After Pre-RegAlloc TailDuplicate"); |
Andrew Trick | f7b9631 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 578 | |
| 579 | // Optimize PHIs before DCE: removing dead PHI cycles may make more |
| 580 | // instructions dead. |
Bob Wilson | 3fb99a7 | 2012-07-02 19:48:37 +0000 | [diff] [blame] | 581 | addPass(&OptimizePHIsID); |
Andrew Trick | f7b9631 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 582 | |
Nadav Rotem | c05d306 | 2012-09-06 09:17:37 +0000 | [diff] [blame] | 583 | // This pass merges large allocas. StackSlotColoring is a different pass |
| 584 | // which merges spill slots. |
| 585 | addPass(&StackColoringID); |
| 586 | |
Andrew Trick | f7b9631 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 587 | // If the target requests it, assign local variables to stack slots relative |
| 588 | // to one another and simplify frame index references where possible. |
Bob Wilson | 3fb99a7 | 2012-07-02 19:48:37 +0000 | [diff] [blame] | 589 | addPass(&LocalStackSlotAllocationID); |
Andrew Trick | f7b9631 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 590 | |
| 591 | // With optimization, dead code should already be eliminated. However |
| 592 | // there is one known exception: lowered code for arguments that are only |
| 593 | // used by tail calls, where the tail calls reuse the incoming stack |
| 594 | // arguments directly (see t11 in test/CodeGen/X86/sibcall.ll). |
Bob Wilson | 3fb99a7 | 2012-07-02 19:48:37 +0000 | [diff] [blame] | 595 | addPass(&DeadMachineInstructionElimID); |
Andrew Trick | f7b9631 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 596 | printAndVerify("After codegen DCE pass"); |
| 597 | |
Jakob Stoklund Olesen | 02c6325 | 2013-01-17 00:58:38 +0000 | [diff] [blame] | 598 | // Allow targets to insert passes that improve instruction level parallelism, |
| 599 | // like if-conversion. Such passes will typically need dominator trees and |
| 600 | // loop info, just like LICM and CSE below. |
| 601 | if (addILPOpts()) |
| 602 | printAndVerify("After ILP optimizations"); |
| 603 | |
Bob Wilson | 3fb99a7 | 2012-07-02 19:48:37 +0000 | [diff] [blame] | 604 | addPass(&MachineLICMID); |
| 605 | addPass(&MachineCSEID); |
| 606 | addPass(&MachineSinkingID); |
Andrew Trick | f7b9631 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 607 | printAndVerify("After Machine LICM, CSE and Sinking passes"); |
| 608 | |
Bob Wilson | 3fb99a7 | 2012-07-02 19:48:37 +0000 | [diff] [blame] | 609 | addPass(&PeepholeOptimizerID); |
Andrew Trick | f7b9631 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 610 | printAndVerify("After codegen peephole optimization pass"); |
| 611 | } |
| 612 | |
Andrew Trick | 7461334 | 2012-02-04 02:56:45 +0000 | [diff] [blame] | 613 | //===---------------------------------------------------------------------===// |
Andrew Trick | f7b9631 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 614 | /// Register Allocation Pass Configuration |
Jim Laskey | eb577ba | 2006-08-02 12:30:23 +0000 | [diff] [blame] | 615 | //===---------------------------------------------------------------------===// |
Andrew Trick | f7b9631 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 616 | |
Andrew Trick | 8dd2625 | 2012-02-10 04:10:36 +0000 | [diff] [blame] | 617 | bool TargetPassConfig::getOptimizeRegAlloc() const { |
| 618 | switch (OptimizeRegAlloc) { |
| 619 | case cl::BOU_UNSET: return getOptLevel() != CodeGenOpt::None; |
| 620 | case cl::BOU_TRUE: return true; |
| 621 | case cl::BOU_FALSE: return false; |
| 622 | } |
| 623 | llvm_unreachable("Invalid optimize-regalloc state"); |
| 624 | } |
| 625 | |
Andrew Trick | f7b9631 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 626 | /// RegisterRegAlloc's global Registry tracks allocator registration. |
Jim Laskey | eb577ba | 2006-08-02 12:30:23 +0000 | [diff] [blame] | 627 | MachinePassRegistry RegisterRegAlloc::Registry; |
| 628 | |
Andrew Trick | f7b9631 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 629 | /// A dummy default pass factory indicates whether the register allocator is |
| 630 | /// overridden on the command line. |
Stephen Hines | dce4a40 | 2014-05-29 02:49:00 -0700 | [diff] [blame^] | 631 | static FunctionPass *useDefaultRegisterAllocator() { return nullptr; } |
Jakob Stoklund Olesen | 700bfad | 2010-05-27 23:57:25 +0000 | [diff] [blame] | 632 | static RegisterRegAlloc |
| 633 | defaultRegAlloc("default", |
| 634 | "pick register allocator based on -O option", |
Andrew Trick | 8dd2625 | 2012-02-10 04:10:36 +0000 | [diff] [blame] | 635 | useDefaultRegisterAllocator); |
Jim Laskey | eb577ba | 2006-08-02 12:30:23 +0000 | [diff] [blame] | 636 | |
Andrew Trick | f7b9631 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 637 | /// -regalloc=... command line option. |
Dan Gohman | 844731a | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 638 | static cl::opt<RegisterRegAlloc::FunctionPassCtor, false, |
| 639 | RegisterPassParser<RegisterRegAlloc> > |
| 640 | RegAlloc("regalloc", |
Andrew Trick | 8dd2625 | 2012-02-10 04:10:36 +0000 | [diff] [blame] | 641 | cl::init(&useDefaultRegisterAllocator), |
Jakob Stoklund Olesen | 700bfad | 2010-05-27 23:57:25 +0000 | [diff] [blame] | 642 | cl::desc("Register allocator to use")); |
Alkis Evlogimenos | 7237ece | 2003-10-02 16:57:49 +0000 | [diff] [blame] | 643 | |
Jim Laskey | eb577ba | 2006-08-02 12:30:23 +0000 | [diff] [blame] | 644 | |
Andrew Trick | 8dd2625 | 2012-02-10 04:10:36 +0000 | [diff] [blame] | 645 | /// Instantiate the default register allocator pass for this target for either |
| 646 | /// the optimized or unoptimized allocation path. This will be added to the pass |
| 647 | /// manager by addFastRegAlloc in the unoptimized case or addOptimizedRegAlloc |
| 648 | /// in the optimized case. |
| 649 | /// |
| 650 | /// A target that uses the standard regalloc pass order for fast or optimized |
| 651 | /// allocation may still override this for per-target regalloc |
| 652 | /// selection. But -regalloc=... always takes precedence. |
| 653 | FunctionPass *TargetPassConfig::createTargetRegisterAllocator(bool Optimized) { |
| 654 | if (Optimized) |
| 655 | return createGreedyRegisterAllocator(); |
| 656 | else |
| 657 | return createFastRegisterAllocator(); |
| 658 | } |
| 659 | |
| 660 | /// Find and instantiate the register allocation pass requested by this target |
| 661 | /// at the current optimization level. Different register allocators are |
| 662 | /// defined as separate passes because they may require different analysis. |
| 663 | /// |
| 664 | /// This helper ensures that the regalloc= option is always available, |
| 665 | /// even for targets that override the default allocator. |
| 666 | /// |
| 667 | /// FIXME: When MachinePassRegistry register pass IDs instead of function ptrs, |
| 668 | /// this can be folded into addPass. |
| 669 | FunctionPass *TargetPassConfig::createRegAllocPass(bool Optimized) { |
Jim Laskey | 9ff542f | 2006-08-01 18:29:48 +0000 | [diff] [blame] | 670 | RegisterRegAlloc::FunctionPassCtor Ctor = RegisterRegAlloc::getDefault(); |
Jakob Stoklund Olesen | 700bfad | 2010-05-27 23:57:25 +0000 | [diff] [blame] | 671 | |
Andrew Trick | 8dd2625 | 2012-02-10 04:10:36 +0000 | [diff] [blame] | 672 | // Initialize the global default. |
Jim Laskey | 13ec702 | 2006-08-01 14:21:23 +0000 | [diff] [blame] | 673 | if (!Ctor) { |
Jim Laskey | eb577ba | 2006-08-02 12:30:23 +0000 | [diff] [blame] | 674 | Ctor = RegAlloc; |
| 675 | RegisterRegAlloc::setDefault(RegAlloc); |
Jim Laskey | 13ec702 | 2006-08-01 14:21:23 +0000 | [diff] [blame] | 676 | } |
Andrew Trick | 8dd2625 | 2012-02-10 04:10:36 +0000 | [diff] [blame] | 677 | if (Ctor != useDefaultRegisterAllocator) |
Jakob Stoklund Olesen | 700bfad | 2010-05-27 23:57:25 +0000 | [diff] [blame] | 678 | return Ctor(); |
| 679 | |
Andrew Trick | 8dd2625 | 2012-02-10 04:10:36 +0000 | [diff] [blame] | 680 | // With no -regalloc= override, ask the target for a regalloc pass. |
| 681 | return createTargetRegisterAllocator(Optimized); |
| 682 | } |
| 683 | |
| 684 | /// Add the minimum set of target-independent passes that are required for |
| 685 | /// register allocation. No coalescing or scheduling. |
| 686 | void TargetPassConfig::addFastRegAlloc(FunctionPass *RegAllocPass) { |
Bob Wilson | 3fb99a7 | 2012-07-02 19:48:37 +0000 | [diff] [blame] | 687 | addPass(&PHIEliminationID); |
| 688 | addPass(&TwoAddressInstructionPassID); |
Andrew Trick | 8dd2625 | 2012-02-10 04:10:36 +0000 | [diff] [blame] | 689 | |
Bob Wilson | 564fbf6 | 2012-07-02 19:48:31 +0000 | [diff] [blame] | 690 | addPass(RegAllocPass); |
Andrew Trick | 8dd2625 | 2012-02-10 04:10:36 +0000 | [diff] [blame] | 691 | printAndVerify("After Register Allocation"); |
Jim Laskey | 33a0a6d | 2006-07-27 20:05:00 +0000 | [diff] [blame] | 692 | } |
Andrew Trick | f7b9631 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 693 | |
| 694 | /// Add standard target-independent passes that are tightly coupled with |
Andrew Trick | 8dd2625 | 2012-02-10 04:10:36 +0000 | [diff] [blame] | 695 | /// optimized register allocation, including coalescing, machine instruction |
| 696 | /// scheduling, and register allocation itself. |
| 697 | void TargetPassConfig::addOptimizedRegAlloc(FunctionPass *RegAllocPass) { |
Bob Wilson | 3fb99a7 | 2012-07-02 19:48:37 +0000 | [diff] [blame] | 698 | addPass(&ProcessImplicitDefsID); |
Jakob Stoklund Olesen | 5984d2b | 2012-06-25 18:12:18 +0000 | [diff] [blame] | 699 | |
Andrew Trick | 8dd2625 | 2012-02-10 04:10:36 +0000 | [diff] [blame] | 700 | // LiveVariables currently requires pure SSA form. |
| 701 | // |
| 702 | // FIXME: Once TwoAddressInstruction pass no longer uses kill flags, |
| 703 | // LiveVariables can be removed completely, and LiveIntervals can be directly |
| 704 | // computed. (We still either need to regenerate kill flags after regalloc, or |
| 705 | // preferably fix the scavenger to not depend on them). |
Bob Wilson | 3fb99a7 | 2012-07-02 19:48:37 +0000 | [diff] [blame] | 706 | addPass(&LiveVariablesID); |
Andrew Trick | 8dd2625 | 2012-02-10 04:10:36 +0000 | [diff] [blame] | 707 | |
Rafael Espindola | 67b2882 | 2013-10-14 16:39:04 +0000 | [diff] [blame] | 708 | // Edge splitting is smarter with machine loop info. |
| 709 | addPass(&MachineLoopInfoID); |
| 710 | addPass(&PHIEliminationID); |
Jakob Stoklund Olesen | dcc4436 | 2012-08-03 22:12:54 +0000 | [diff] [blame] | 711 | |
| 712 | // Eventually, we want to run LiveIntervals before PHI elimination. |
| 713 | if (EarlyLiveIntervals) |
| 714 | addPass(&LiveIntervalsID); |
| 715 | |
Bob Wilson | 3fb99a7 | 2012-07-02 19:48:37 +0000 | [diff] [blame] | 716 | addPass(&TwoAddressInstructionPassID); |
Bob Wilson | 3fb99a7 | 2012-07-02 19:48:37 +0000 | [diff] [blame] | 717 | addPass(&RegisterCoalescerID); |
Andrew Trick | 8dd2625 | 2012-02-10 04:10:36 +0000 | [diff] [blame] | 718 | |
| 719 | // PreRA instruction scheduling. |
Bob Wilson | 3fb99a7 | 2012-07-02 19:48:37 +0000 | [diff] [blame] | 720 | if (addPass(&MachineSchedulerID)) |
Andrew Trick | 17d35e5 | 2012-03-14 04:00:41 +0000 | [diff] [blame] | 721 | printAndVerify("After Machine Scheduling"); |
Andrew Trick | 8dd2625 | 2012-02-10 04:10:36 +0000 | [diff] [blame] | 722 | |
| 723 | // Add the selected register allocation pass. |
Bob Wilson | 564fbf6 | 2012-07-02 19:48:31 +0000 | [diff] [blame] | 724 | addPass(RegAllocPass); |
Jakob Stoklund Olesen | 34f5a2b | 2012-06-26 17:09:29 +0000 | [diff] [blame] | 725 | printAndVerify("After Register Allocation, before rewriter"); |
| 726 | |
| 727 | // Allow targets to change the register assignments before rewriting. |
| 728 | if (addPreRewrite()) |
| 729 | printAndVerify("After pre-rewrite passes"); |
Andrew Trick | f7b9631 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 730 | |
Jakob Stoklund Olesen | 05ec712 | 2012-06-08 23:44:45 +0000 | [diff] [blame] | 731 | // Finally rewrite virtual registers. |
Bob Wilson | 3fb99a7 | 2012-07-02 19:48:37 +0000 | [diff] [blame] | 732 | addPass(&VirtRegRewriterID); |
Jakob Stoklund Olesen | 05ec712 | 2012-06-08 23:44:45 +0000 | [diff] [blame] | 733 | printAndVerify("After Virtual Register Rewriter"); |
| 734 | |
Andrew Trick | f7b9631 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 735 | // Perform stack slot coloring and post-ra machine LICM. |
Andrew Trick | 8dd2625 | 2012-02-10 04:10:36 +0000 | [diff] [blame] | 736 | // |
| 737 | // FIXME: Re-enable coloring with register when it's capable of adding |
| 738 | // kill markers. |
Bob Wilson | 3fb99a7 | 2012-07-02 19:48:37 +0000 | [diff] [blame] | 739 | addPass(&StackSlotColoringID); |
Andrew Trick | 900d7b7 | 2012-02-15 07:57:03 +0000 | [diff] [blame] | 740 | |
| 741 | // Run post-ra machine LICM to hoist reloads / remats. |
| 742 | // |
| 743 | // FIXME: can this move into MachineLateOptimization? |
Bob Wilson | 3fb99a7 | 2012-07-02 19:48:37 +0000 | [diff] [blame] | 744 | addPass(&PostRAMachineLICMID); |
Andrew Trick | 900d7b7 | 2012-02-15 07:57:03 +0000 | [diff] [blame] | 745 | |
| 746 | printAndVerify("After StackSlotColoring and postra Machine LICM"); |
Andrew Trick | f7b9631 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 747 | } |
| 748 | |
| 749 | //===---------------------------------------------------------------------===// |
| 750 | /// Post RegAlloc Pass Configuration |
| 751 | //===---------------------------------------------------------------------===// |
| 752 | |
| 753 | /// Add passes that optimize machine instructions after register allocation. |
| 754 | void TargetPassConfig::addMachineLateOptimization() { |
| 755 | // Branch folding must be run after regalloc and prolog/epilog insertion. |
Bob Wilson | 3fb99a7 | 2012-07-02 19:48:37 +0000 | [diff] [blame] | 756 | if (addPass(&BranchFolderPassID)) |
Jakob Stoklund Olesen | 663ee20 | 2012-03-28 20:47:37 +0000 | [diff] [blame] | 757 | printAndVerify("After BranchFolding"); |
Andrew Trick | f7b9631 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 758 | |
| 759 | // Tail duplication. |
Stephen Hines | 36b5688 | 2014-04-23 16:57:46 -0700 | [diff] [blame] | 760 | // Note that duplicating tail just increases code size and degrades |
| 761 | // performance for targets that require Structured Control Flow. |
| 762 | // In addition it can also make CFG irreducible. Thus we disable it. |
| 763 | if (!TM->requiresStructuredCFG() && addPass(&TailDuplicateID)) |
Jakob Stoklund Olesen | 663ee20 | 2012-03-28 20:47:37 +0000 | [diff] [blame] | 764 | printAndVerify("After TailDuplicate"); |
Andrew Trick | f7b9631 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 765 | |
| 766 | // Copy propagation. |
Bob Wilson | 3fb99a7 | 2012-07-02 19:48:37 +0000 | [diff] [blame] | 767 | if (addPass(&MachineCopyPropagationID)) |
Jakob Stoklund Olesen | 663ee20 | 2012-03-28 20:47:37 +0000 | [diff] [blame] | 768 | printAndVerify("After copy propagation pass"); |
Andrew Trick | f7b9631 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 769 | } |
| 770 | |
Evan Cheng | ab37b2c | 2012-12-21 02:57:04 +0000 | [diff] [blame] | 771 | /// Add standard GC passes. |
| 772 | bool TargetPassConfig::addGCPasses() { |
| 773 | addPass(&GCMachineCodeAnalysisID); |
| 774 | return true; |
| 775 | } |
| 776 | |
Andrew Trick | f7b9631 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 777 | /// Add standard basic block placement passes. |
| 778 | void TargetPassConfig::addBlockPlacement() { |
Benjamin Kramer | 74a4533 | 2013-03-29 17:14:24 +0000 | [diff] [blame] | 779 | if (addPass(&MachineBlockPlacementID)) { |
Andrew Trick | 79bf288 | 2012-02-15 03:21:51 +0000 | [diff] [blame] | 780 | // Run a separate pass to collect block placement statistics. |
| 781 | if (EnableBlockPlacementStats) |
Bob Wilson | 3fb99a7 | 2012-07-02 19:48:37 +0000 | [diff] [blame] | 782 | addPass(&MachineBlockPlacementStatsID); |
Andrew Trick | f7b9631 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 783 | |
Jakob Stoklund Olesen | 8b4c502 | 2012-03-28 23:54:28 +0000 | [diff] [blame] | 784 | printAndVerify("After machine block placement."); |
Andrew Trick | f7b9631 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 785 | } |
| 786 | } |