Eugene Zelenko | 76bf48d | 2017-06-26 22:44:03 +0000 | [diff] [blame] | 1 | //===- TargetPassConfig.cpp - Target independent code generation passes ---===// |
Misha Brukman | 835702a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 2 | // |
John Criswell | 482202a | 2003-10-20 19:43:21 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | f3ebc3f | 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 | 835702a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 7 | // |
John Criswell | 482202a | 2003-10-20 19:43:21 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
Alkis Evlogimenos | 5facafa | 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 | |
Matthias Braun | 31d19d4 | 2016-05-10 03:21:59 +0000 | [diff] [blame] | 15 | #include "llvm/CodeGen/TargetPassConfig.h" |
Eugene Zelenko | 76bf48d | 2017-06-26 22:44:03 +0000 | [diff] [blame] | 16 | #include "llvm/ADT/DenseMap.h" |
| 17 | #include "llvm/ADT/SmallVector.h" |
| 18 | #include "llvm/ADT/StringRef.h" |
Chandler Carruth | 17e0bc3 | 2015-08-06 07:33:15 +0000 | [diff] [blame] | 19 | #include "llvm/Analysis/BasicAliasAnalysis.h" |
George Burgess IV | bfa401e | 2016-07-06 00:26:41 +0000 | [diff] [blame] | 20 | #include "llvm/Analysis/CFLAndersAliasAnalysis.h" |
| 21 | #include "llvm/Analysis/CFLSteensAliasAnalysis.h" |
Mehdi Amini | bbacddf | 2016-06-10 16:19:46 +0000 | [diff] [blame] | 22 | #include "llvm/Analysis/CallGraphSCCPass.h" |
Chandler Carruth | 42ff448 | 2015-08-14 02:55:50 +0000 | [diff] [blame] | 23 | #include "llvm/Analysis/ScopedNoAliasAA.h" |
Matthias Braun | c7c06f1 | 2017-06-06 00:26:13 +0000 | [diff] [blame] | 24 | #include "llvm/Analysis/TargetTransformInfo.h" |
Chandler Carruth | 1db2282 | 2015-08-14 03:33:48 +0000 | [diff] [blame] | 25 | #include "llvm/Analysis/TypeBasedAliasAnalysis.h" |
Andrew Trick | de401d3 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 26 | #include "llvm/CodeGen/MachineFunctionPass.h" |
Eugene Zelenko | 76bf48d | 2017-06-26 22:44:03 +0000 | [diff] [blame] | 27 | #include "llvm/CodeGen/MachinePassRegistry.h" |
| 28 | #include "llvm/CodeGen/Passes.h" |
Andrew Trick | de401d3 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 29 | #include "llvm/CodeGen/RegAllocRegistry.h" |
Chandler Carruth | b8ddc70 | 2014-01-12 11:10:32 +0000 | [diff] [blame] | 30 | #include "llvm/IR/IRPrintingPasses.h" |
Chandler Carruth | 30d69c2 | 2015-02-13 10:01:29 +0000 | [diff] [blame] | 31 | #include "llvm/IR/LegacyPassManager.h" |
Chandler Carruth | 5ad5f15 | 2014-01-13 09:26:24 +0000 | [diff] [blame] | 32 | #include "llvm/IR/Verifier.h" |
Bob Wilson | bbd38dd | 2012-07-02 19:48:31 +0000 | [diff] [blame] | 33 | #include "llvm/MC/MCAsmInfo.h" |
Eugene Zelenko | 76bf48d | 2017-06-26 22:44:03 +0000 | [diff] [blame] | 34 | #include "llvm/MC/MCTargetOptions.h" |
| 35 | #include "llvm/Pass.h" |
| 36 | #include "llvm/Support/CodeGen.h" |
| 37 | #include "llvm/Support/CommandLine.h" |
| 38 | #include "llvm/Support/Compiler.h" |
Andrew Trick | de401d3 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 39 | #include "llvm/Support/Debug.h" |
Andrew Trick | b755133 | 2012-02-04 02:56:45 +0000 | [diff] [blame] | 40 | #include "llvm/Support/ErrorHandling.h" |
Eugene Zelenko | 76bf48d | 2017-06-26 22:44:03 +0000 | [diff] [blame] | 41 | #include "llvm/Support/Threading.h" |
Matthias Braun | 31d19d4 | 2016-05-10 03:21:59 +0000 | [diff] [blame] | 42 | #include "llvm/Target/TargetMachine.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 43 | #include "llvm/Transforms/Scalar.h" |
Saleem Abdulrasool | 5898e09 | 2014-11-07 21:32:08 +0000 | [diff] [blame] | 44 | #include "llvm/Transforms/Utils/SymbolRewriter.h" |
Eugene Zelenko | 76bf48d | 2017-06-26 22:44:03 +0000 | [diff] [blame] | 45 | #include <cassert> |
| 46 | #include <string> |
Jim Laskey | 95eda5b | 2006-08-01 14:21:23 +0000 | [diff] [blame] | 47 | |
Chris Lattner | 27dd642 | 2003-12-28 07:59:53 +0000 | [diff] [blame] | 48 | using namespace llvm; |
Brian Gaeke | 960707c | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 49 | |
Matt Arsenault | 81da0d4 | 2017-08-14 19:54:47 +0000 | [diff] [blame] | 50 | cl::opt<bool> EnableIPRA("enable-ipra", cl::init(false), cl::Hidden, |
| 51 | cl::desc("Enable interprocedural register allocation " |
| 52 | "to reduce load/store at procedure calls.")); |
Matthias Braun | e2d2ead | 2016-12-08 00:16:08 +0000 | [diff] [blame] | 53 | static cl::opt<bool> DisablePostRASched("disable-post-ra", cl::Hidden, |
| 54 | cl::desc("Disable Post Regalloc Scheduler")); |
Andrew Trick | de401d3 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 55 | static cl::opt<bool> DisableBranchFold("disable-branch-fold", cl::Hidden, |
| 56 | cl::desc("Disable branch folding")); |
| 57 | static cl::opt<bool> DisableTailDuplicate("disable-tail-duplicate", cl::Hidden, |
| 58 | cl::desc("Disable tail duplication")); |
| 59 | static cl::opt<bool> DisableEarlyTailDup("disable-early-taildup", cl::Hidden, |
| 60 | cl::desc("Disable pre-register allocation tail duplication")); |
Chandler Carruth | 4190b50 | 2012-04-16 13:49:17 +0000 | [diff] [blame] | 61 | static cl::opt<bool> DisableBlockPlacement("disable-block-placement", |
Benjamin Kramer | 70671b9 | 2013-03-29 17:14:24 +0000 | [diff] [blame] | 62 | cl::Hidden, cl::desc("Disable probability-driven block placement")); |
Andrew Trick | de401d3 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 63 | static cl::opt<bool> EnableBlockPlacementStats("enable-block-placement-stats", |
| 64 | cl::Hidden, cl::desc("Collect probability-driven block placement stats")); |
Andrew Trick | de401d3 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 65 | static cl::opt<bool> DisableSSC("disable-ssc", cl::Hidden, |
| 66 | cl::desc("Disable Stack Slot Coloring")); |
| 67 | static cl::opt<bool> DisableMachineDCE("disable-machine-dce", cl::Hidden, |
| 68 | cl::desc("Disable Machine Dead Code Elimination")); |
Jakob Stoklund Olesen | 0f6e8bb | 2012-10-03 00:51:32 +0000 | [diff] [blame] | 69 | static cl::opt<bool> DisableEarlyIfConversion("disable-early-ifcvt", cl::Hidden, |
| 70 | cl::desc("Disable Early If-conversion")); |
Andrew Trick | de401d3 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 71 | static cl::opt<bool> DisableMachineLICM("disable-machine-licm", cl::Hidden, |
| 72 | cl::desc("Disable Machine LICM")); |
| 73 | static cl::opt<bool> DisableMachineCSE("disable-machine-cse", cl::Hidden, |
| 74 | cl::desc("Disable Machine Common Subexpression Elimination")); |
Quentin Colombet | 61b305e | 2015-05-05 17:38:16 +0000 | [diff] [blame] | 75 | static cl::opt<cl::boolOrDefault> OptimizeRegAlloc( |
| 76 | "optimize-regalloc", cl::Hidden, |
Andrew Trick | d3f8fe8 | 2012-02-10 04:10:36 +0000 | [diff] [blame] | 77 | cl::desc("Enable optimized register allocation compilation path.")); |
Andrew Trick | de401d3 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 78 | static cl::opt<bool> DisablePostRAMachineLICM("disable-postra-machine-licm", |
| 79 | cl::Hidden, |
| 80 | cl::desc("Disable Machine LICM")); |
| 81 | static cl::opt<bool> DisableMachineSink("disable-machine-sink", cl::Hidden, |
| 82 | cl::desc("Disable Machine Sinking")); |
| 83 | static cl::opt<bool> DisableLSR("disable-lsr", cl::Hidden, |
| 84 | cl::desc("Disable Loop Strength Reduction Pass")); |
Juergen Ributzka | f26beda | 2014-01-25 02:02:55 +0000 | [diff] [blame] | 85 | static cl::opt<bool> DisableConstantHoisting("disable-constant-hoisting", |
| 86 | cl::Hidden, cl::desc("Disable ConstantHoisting")); |
Andrew Trick | de401d3 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 87 | static cl::opt<bool> DisableCGP("disable-cgp", cl::Hidden, |
| 88 | cl::desc("Disable Codegen Prepare")); |
| 89 | static cl::opt<bool> DisableCopyProp("disable-copyprop", cl::Hidden, |
Evan Cheng | 63618f9 | 2012-02-20 23:28:17 +0000 | [diff] [blame] | 90 | cl::desc("Disable Copy Propagation pass")); |
James Molloy | bc9fed8 | 2014-07-23 13:33:00 +0000 | [diff] [blame] | 91 | static cl::opt<bool> DisablePartialLibcallInlining("disable-partial-libcall-inlining", |
| 92 | cl::Hidden, cl::desc("Disable Partial Libcall Inlining")); |
Sanjoy Das | 69fad07 | 2015-06-15 18:44:27 +0000 | [diff] [blame] | 93 | static cl::opt<bool> EnableImplicitNullChecks( |
| 94 | "enable-implicit-null-checks", |
| 95 | cl::desc("Fold null checks into faulting memory operations"), |
| 96 | cl::init(false)); |
Clement Courbet | 65130e2 | 2017-09-01 10:56:34 +0000 | [diff] [blame] | 97 | static cl::opt<bool> EnableMergeICmps( |
| 98 | "enable-mergeicmps", |
| 99 | cl::desc("Merge ICmp chains into a single memcmp"), |
| 100 | cl::init(false)); |
Andrew Trick | de401d3 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 101 | static cl::opt<bool> PrintLSR("print-lsr-output", cl::Hidden, |
| 102 | cl::desc("Print LLVM IR produced by the loop-reduce pass")); |
| 103 | static cl::opt<bool> PrintISelInput("print-isel-input", cl::Hidden, |
| 104 | cl::desc("Print LLVM IR input to isel pass")); |
| 105 | static cl::opt<bool> PrintGCInfo("print-gc", cl::Hidden, |
| 106 | cl::desc("Dump garbage collector data")); |
| 107 | static cl::opt<bool> VerifyMachineCode("verify-machineinstrs", cl::Hidden, |
| 108 | cl::desc("Verify generated machine code"), |
Owen Anderson | 21b1788 | 2015-02-04 00:02:59 +0000 | [diff] [blame] | 109 | cl::init(false), |
| 110 | cl::ZeroOrMore); |
Jessica Paquette | 596f483 | 2017-03-06 21:31:18 +0000 | [diff] [blame] | 111 | static cl::opt<bool> EnableMachineOutliner("enable-machine-outliner", |
| 112 | cl::Hidden, |
| 113 | cl::desc("Enable machine outliner")); |
Jessica Paquette | 1359384 | 2017-10-07 00:16:34 +0000 | [diff] [blame] | 114 | static cl::opt<bool> EnableLinkOnceODROutlining( |
| 115 | "enable-linkonceodr-outlining", |
| 116 | cl::Hidden, |
| 117 | cl::desc("Enable the machine outliner on linkonceodr functions"), |
| 118 | cl::init(false)); |
Matthias Braun | c7c06f1 | 2017-06-06 00:26:13 +0000 | [diff] [blame] | 119 | // Enable or disable FastISel. Both options are needed, because |
| 120 | // FastISel is enabled by default with -fast, and we wish to be |
| 121 | // able to enable or disable fast-isel independently from -O0. |
| 122 | static cl::opt<cl::boolOrDefault> |
| 123 | EnableFastISelOption("fast-isel", cl::Hidden, |
| 124 | cl::desc("Enable the \"fast\" instruction selector")); |
| 125 | |
| 126 | static cl::opt<cl::boolOrDefault> |
| 127 | EnableGlobalISel("global-isel", cl::Hidden, |
| 128 | cl::desc("Enable the \"global\" instruction selector")); |
Owen Anderson | 21b1788 | 2015-02-04 00:02:59 +0000 | [diff] [blame] | 129 | |
Bob Wilson | 33e5188 | 2012-05-30 00:17:12 +0000 | [diff] [blame] | 130 | static cl::opt<std::string> |
| 131 | PrintMachineInstrs("print-machineinstrs", cl::ValueOptional, |
| 132 | cl::desc("Print machine instrs"), |
| 133 | cl::value_desc("pass-name"), cl::init("option-unspecified")); |
Andrew Trick | de401d3 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 134 | |
Quentin Colombet | 1c06a73 | 2016-08-31 18:43:04 +0000 | [diff] [blame] | 135 | static cl::opt<int> EnableGlobalISelAbort( |
Quentin Colombet | 0de43b2 | 2016-08-26 22:32:59 +0000 | [diff] [blame] | 136 | "global-isel-abort", cl::Hidden, |
| 137 | cl::desc("Enable abort calls when \"global\" instruction selection " |
Quentin Colombet | 1c06a73 | 2016-08-31 18:43:04 +0000 | [diff] [blame] | 138 | "fails to lower/select an instruction: 0 disable the abort, " |
| 139 | "1 enable the abort, and " |
| 140 | "2 disable the abort but emit a diagnostic on failure"), |
| 141 | cl::init(1)); |
Quentin Colombet | 0de43b2 | 2016-08-26 22:32:59 +0000 | [diff] [blame] | 142 | |
Andrew Trick | 17080b9 | 2013-12-28 21:56:51 +0000 | [diff] [blame] | 143 | // Temporary option to allow experimenting with MachineScheduler as a post-RA |
| 144 | // scheduler. Targets can "properly" enable this with |
Jonas Paulsson | e451eef | 2015-12-10 09:10:07 +0000 | [diff] [blame] | 145 | // substitutePass(&PostRASchedulerID, &PostMachineSchedulerID). |
| 146 | // Targets can return true in targetSchedulesPostRAScheduling() and |
| 147 | // insert a PostRA scheduling pass wherever it wants. |
| 148 | cl::opt<bool> MISchedPostRA("misched-postra", cl::Hidden, |
Andrew Trick | 17080b9 | 2013-12-28 21:56:51 +0000 | [diff] [blame] | 149 | cl::desc("Run MachineScheduler post regalloc (independent of preRA sched)")); |
| 150 | |
Cameron Zwarich | 71f0acb | 2013-02-10 06:42:34 +0000 | [diff] [blame] | 151 | // Experimental option to run live interval analysis early. |
Jakob Stoklund Olesen | 1c46589 | 2012-08-03 22:12:54 +0000 | [diff] [blame] | 152 | static cl::opt<bool> EarlyLiveIntervals("early-live-intervals", cl::Hidden, |
| 153 | cl::desc("Run live interval analysis earlier in the pipeline")); |
| 154 | |
George Burgess IV | bfa401e | 2016-07-06 00:26:41 +0000 | [diff] [blame] | 155 | // Experimental option to use CFL-AA in codegen |
| 156 | enum class CFLAAType { None, Steensgaard, Andersen, Both }; |
| 157 | static cl::opt<CFLAAType> UseCFLAA( |
| 158 | "use-cfl-aa-in-codegen", cl::init(CFLAAType::None), cl::Hidden, |
| 159 | cl::desc("Enable the new, experimental CFL alias analysis in CodeGen"), |
| 160 | cl::values(clEnumValN(CFLAAType::None, "none", "Disable CFL-AA"), |
| 161 | clEnumValN(CFLAAType::Steensgaard, "steens", |
| 162 | "Enable unification-based CFL-AA"), |
| 163 | clEnumValN(CFLAAType::Andersen, "anders", |
| 164 | "Enable inclusion-based CFL-AA"), |
| 165 | clEnumValN(CFLAAType::Both, "both", |
Mehdi Amini | 732afdd | 2016-10-08 19:41:06 +0000 | [diff] [blame] | 166 | "Enable both variants of CFL-AA"))); |
Hal Finkel | 445dda5 | 2014-09-02 22:12:54 +0000 | [diff] [blame] | 167 | |
Quentin Colombet | 15f6ffb | 2017-07-31 18:24:07 +0000 | [diff] [blame] | 168 | /// Option names for limiting the codegen pipeline. |
| 169 | /// Those are used in error reporting and we didn't want |
| 170 | /// to duplicate their names all over the place. |
| 171 | const char *StartAfterOptName = "start-after"; |
| 172 | const char *StartBeforeOptName = "start-before"; |
| 173 | const char *StopAfterOptName = "stop-after"; |
| 174 | const char *StopBeforeOptName = "stop-before"; |
| 175 | |
| 176 | static cl::opt<std::string> |
| 177 | StartAfterOpt(StringRef(StartAfterOptName), |
| 178 | cl::desc("Resume compilation after a specific pass"), |
| 179 | cl::value_desc("pass-name"), cl::init("")); |
| 180 | |
| 181 | static cl::opt<std::string> |
| 182 | StartBeforeOpt(StringRef(StartBeforeOptName), |
| 183 | cl::desc("Resume compilation before a specific pass"), |
| 184 | cl::value_desc("pass-name"), cl::init("")); |
| 185 | |
| 186 | static cl::opt<std::string> |
| 187 | StopAfterOpt(StringRef(StopAfterOptName), |
| 188 | cl::desc("Stop compilation after a specific pass"), |
| 189 | cl::value_desc("pass-name"), cl::init("")); |
| 190 | |
| 191 | static cl::opt<std::string> |
| 192 | StopBeforeOpt(StringRef(StopBeforeOptName), |
| 193 | cl::desc("Stop compilation before a specific pass"), |
| 194 | cl::value_desc("pass-name"), cl::init("")); |
| 195 | |
Andrew Trick | e9a951c | 2012-02-15 03:21:51 +0000 | [diff] [blame] | 196 | /// Allow standard passes to be disabled by command line options. This supports |
| 197 | /// simple binary flags that either suppress the pass or do nothing. |
| 198 | /// i.e. -disable-mypass=false has no effect. |
| 199 | /// These should be converted to boolOrDefault in order to use applyOverride. |
Andrew Trick | e220323 | 2013-04-10 01:06:56 +0000 | [diff] [blame] | 200 | static IdentifyingPassPtr applyDisable(IdentifyingPassPtr PassID, |
| 201 | bool Override) { |
Andrew Trick | e9a951c | 2012-02-15 03:21:51 +0000 | [diff] [blame] | 202 | if (Override) |
Andrew Trick | e220323 | 2013-04-10 01:06:56 +0000 | [diff] [blame] | 203 | return IdentifyingPassPtr(); |
Bob Wilson | b9b6936 | 2012-07-02 19:48:37 +0000 | [diff] [blame] | 204 | return PassID; |
Andrew Trick | e9a951c | 2012-02-15 03:21:51 +0000 | [diff] [blame] | 205 | } |
| 206 | |
Andrew Trick | e9a951c | 2012-02-15 03:21:51 +0000 | [diff] [blame] | 207 | /// Allow standard passes to be disabled by the command line, regardless of who |
| 208 | /// is adding the pass. |
| 209 | /// |
| 210 | /// StandardID is the pass identified in the standard pass pipeline and provided |
| 211 | /// to addPass(). It may be a target-specific ID in the case that the target |
| 212 | /// directly adds its own pass, but in that case we harmlessly fall through. |
| 213 | /// |
| 214 | /// TargetID is the pass that the target has configured to override StandardID. |
| 215 | /// |
| 216 | /// StandardID may be a pseudo ID. In that case TargetID is the name of the real |
| 217 | /// pass to run. This allows multiple options to control a single pass depending |
| 218 | /// on where in the pipeline that pass is added. |
Andrew Trick | e220323 | 2013-04-10 01:06:56 +0000 | [diff] [blame] | 219 | static IdentifyingPassPtr overridePass(AnalysisID StandardID, |
| 220 | IdentifyingPassPtr TargetID) { |
Andrew Trick | e9a951c | 2012-02-15 03:21:51 +0000 | [diff] [blame] | 221 | if (StandardID == &PostRASchedulerID) |
Matthias Braun | e2d2ead | 2016-12-08 00:16:08 +0000 | [diff] [blame] | 222 | return applyDisable(TargetID, DisablePostRASched); |
Andrew Trick | e9a951c | 2012-02-15 03:21:51 +0000 | [diff] [blame] | 223 | |
| 224 | if (StandardID == &BranchFolderPassID) |
| 225 | return applyDisable(TargetID, DisableBranchFold); |
| 226 | |
| 227 | if (StandardID == &TailDuplicateID) |
| 228 | return applyDisable(TargetID, DisableTailDuplicate); |
| 229 | |
| 230 | if (StandardID == &TargetPassConfig::EarlyTailDuplicateID) |
| 231 | return applyDisable(TargetID, DisableEarlyTailDup); |
| 232 | |
| 233 | if (StandardID == &MachineBlockPlacementID) |
Benjamin Kramer | 70671b9 | 2013-03-29 17:14:24 +0000 | [diff] [blame] | 234 | return applyDisable(TargetID, DisableBlockPlacement); |
Andrew Trick | e9a951c | 2012-02-15 03:21:51 +0000 | [diff] [blame] | 235 | |
| 236 | if (StandardID == &StackSlotColoringID) |
| 237 | return applyDisable(TargetID, DisableSSC); |
| 238 | |
| 239 | if (StandardID == &DeadMachineInstructionElimID) |
| 240 | return applyDisable(TargetID, DisableMachineDCE); |
| 241 | |
Jakob Stoklund Olesen | f8a63a1 | 2012-07-04 00:09:54 +0000 | [diff] [blame] | 242 | if (StandardID == &EarlyIfConverterID) |
Jakob Stoklund Olesen | 0f6e8bb | 2012-10-03 00:51:32 +0000 | [diff] [blame] | 243 | return applyDisable(TargetID, DisableEarlyIfConversion); |
Jakob Stoklund Olesen | f8a63a1 | 2012-07-04 00:09:54 +0000 | [diff] [blame] | 244 | |
Andrew Trick | e9a951c | 2012-02-15 03:21:51 +0000 | [diff] [blame] | 245 | if (StandardID == &MachineLICMID) |
| 246 | return applyDisable(TargetID, DisableMachineLICM); |
| 247 | |
| 248 | if (StandardID == &MachineCSEID) |
| 249 | return applyDisable(TargetID, DisableMachineCSE); |
| 250 | |
Andrew Trick | e9a951c | 2012-02-15 03:21:51 +0000 | [diff] [blame] | 251 | if (StandardID == &TargetPassConfig::PostRAMachineLICMID) |
| 252 | return applyDisable(TargetID, DisablePostRAMachineLICM); |
| 253 | |
| 254 | if (StandardID == &MachineSinkingID) |
| 255 | return applyDisable(TargetID, DisableMachineSink); |
| 256 | |
| 257 | if (StandardID == &MachineCopyPropagationID) |
| 258 | return applyDisable(TargetID, DisableCopyProp); |
| 259 | |
| 260 | return TargetID; |
| 261 | } |
| 262 | |
Jim Laskey | 29e635d | 2006-08-02 12:30:23 +0000 | [diff] [blame] | 263 | //===---------------------------------------------------------------------===// |
Andrew Trick | b755133 | 2012-02-04 02:56:45 +0000 | [diff] [blame] | 264 | /// TargetPassConfig |
| 265 | //===---------------------------------------------------------------------===// |
| 266 | |
| 267 | INITIALIZE_PASS(TargetPassConfig, "targetpassconfig", |
| 268 | "Target Pass Configuration", false, false) |
| 269 | char TargetPassConfig::ID = 0; |
| 270 | |
Andrew Trick | e9a951c | 2012-02-15 03:21:51 +0000 | [diff] [blame] | 271 | // Pseudo Pass IDs. |
| 272 | char TargetPassConfig::EarlyTailDuplicateID = 0; |
| 273 | char TargetPassConfig::PostRAMachineLICMID = 0; |
| 274 | |
Justin Bogner | 468c998 | 2015-10-08 00:36:22 +0000 | [diff] [blame] | 275 | namespace { |
Eugene Zelenko | 76bf48d | 2017-06-26 22:44:03 +0000 | [diff] [blame] | 276 | |
Justin Bogner | 468c998 | 2015-10-08 00:36:22 +0000 | [diff] [blame] | 277 | struct InsertedPass { |
| 278 | AnalysisID TargetPassID; |
| 279 | IdentifyingPassPtr InsertedPassID; |
| 280 | bool VerifyAfter; |
| 281 | bool PrintAfter; |
| 282 | |
| 283 | InsertedPass(AnalysisID TargetPassID, IdentifyingPassPtr InsertedPassID, |
| 284 | bool VerifyAfter, bool PrintAfter) |
| 285 | : TargetPassID(TargetPassID), InsertedPassID(InsertedPassID), |
| 286 | VerifyAfter(VerifyAfter), PrintAfter(PrintAfter) {} |
| 287 | |
| 288 | Pass *getInsertedPass() const { |
| 289 | assert(InsertedPassID.isValid() && "Illegal Pass ID!"); |
| 290 | if (InsertedPassID.isInstance()) |
| 291 | return InsertedPassID.getInstance(); |
| 292 | Pass *NP = Pass::createPass(InsertedPassID.getID()); |
| 293 | assert(NP && "Pass ID not registered"); |
| 294 | return NP; |
| 295 | } |
| 296 | }; |
Eugene Zelenko | 76bf48d | 2017-06-26 22:44:03 +0000 | [diff] [blame] | 297 | |
| 298 | } // end anonymous namespace |
Justin Bogner | 468c998 | 2015-10-08 00:36:22 +0000 | [diff] [blame] | 299 | |
Andrew Trick | c9ce9d2 | 2012-02-15 03:21:47 +0000 | [diff] [blame] | 300 | namespace llvm { |
Eugene Zelenko | 76bf48d | 2017-06-26 22:44:03 +0000 | [diff] [blame] | 301 | |
Andrew Trick | c9ce9d2 | 2012-02-15 03:21:47 +0000 | [diff] [blame] | 302 | class PassConfigImpl { |
| 303 | public: |
| 304 | // List of passes explicitly substituted by this target. Normally this is |
| 305 | // empty, but it is a convenient way to suppress or replace specific passes |
| 306 | // that are part of a standard pass pipeline without overridding the entire |
| 307 | // pipeline. This mechanism allows target options to inherit a standard pass's |
| 308 | // user interface. For example, a target may disable a standard pass by |
Bob Wilson | b9b6936 | 2012-07-02 19:48:37 +0000 | [diff] [blame] | 309 | // default by substituting a pass ID of zero, and the user may still enable |
| 310 | // that standard pass with an explicit command line option. |
Andrew Trick | e220323 | 2013-04-10 01:06:56 +0000 | [diff] [blame] | 311 | DenseMap<AnalysisID,IdentifyingPassPtr> TargetPasses; |
Bob Wilson | 33e5188 | 2012-05-30 00:17:12 +0000 | [diff] [blame] | 312 | |
| 313 | /// Store the pairs of <AnalysisID, AnalysisID> of which the second pass |
| 314 | /// is inserted after each instance of the first one. |
Justin Bogner | 468c998 | 2015-10-08 00:36:22 +0000 | [diff] [blame] | 315 | SmallVector<InsertedPass, 4> InsertedPasses; |
Andrew Trick | c9ce9d2 | 2012-02-15 03:21:47 +0000 | [diff] [blame] | 316 | }; |
Eugene Zelenko | 76bf48d | 2017-06-26 22:44:03 +0000 | [diff] [blame] | 317 | |
| 318 | } // end namespace llvm |
Andrew Trick | c9ce9d2 | 2012-02-15 03:21:47 +0000 | [diff] [blame] | 319 | |
Andrew Trick | b755133 | 2012-02-04 02:56:45 +0000 | [diff] [blame] | 320 | // Out of line virtual method. |
Andrew Trick | c9ce9d2 | 2012-02-15 03:21:47 +0000 | [diff] [blame] | 321 | TargetPassConfig::~TargetPassConfig() { |
| 322 | delete Impl; |
| 323 | } |
Andrew Trick | b755133 | 2012-02-04 02:56:45 +0000 | [diff] [blame] | 324 | |
Quentin Colombet | 15f6ffb | 2017-07-31 18:24:07 +0000 | [diff] [blame] | 325 | static const PassInfo *getPassInfo(StringRef PassName) { |
| 326 | if (PassName.empty()) |
| 327 | return nullptr; |
| 328 | |
| 329 | const PassRegistry &PR = *PassRegistry::getPassRegistry(); |
| 330 | const PassInfo *PI = PR.getPassInfo(PassName); |
| 331 | if (!PI) |
| 332 | report_fatal_error(Twine('\"') + Twine(PassName) + |
| 333 | Twine("\" pass is not registered.")); |
| 334 | return PI; |
| 335 | } |
| 336 | |
| 337 | static AnalysisID getPassIDFromName(StringRef PassName) { |
| 338 | const PassInfo *PI = getPassInfo(PassName); |
| 339 | return PI ? PI->getTypeInfo() : nullptr; |
| 340 | } |
| 341 | |
| 342 | void TargetPassConfig::setStartStopPasses() { |
| 343 | StartBefore = getPassIDFromName(StartBeforeOpt); |
| 344 | StartAfter = getPassIDFromName(StartAfterOpt); |
| 345 | StopBefore = getPassIDFromName(StopBeforeOpt); |
| 346 | StopAfter = getPassIDFromName(StopAfterOpt); |
| 347 | if (StartBefore && StartAfter) |
| 348 | report_fatal_error(Twine(StartBeforeOptName) + Twine(" and ") + |
| 349 | Twine(StartAfterOptName) + Twine(" specified!")); |
| 350 | if (StopBefore && StopAfter) |
| 351 | report_fatal_error(Twine(StopBeforeOptName) + Twine(" and ") + |
| 352 | Twine(StopAfterOptName) + Twine(" specified!")); |
| 353 | Started = (StartAfter == nullptr) && (StartBefore == nullptr); |
| 354 | } |
| 355 | |
Andrew Trick | 58648e4 | 2012-02-08 21:22:48 +0000 | [diff] [blame] | 356 | // Out of line constructor provides default values for pass options and |
| 357 | // registers all common codegen passes. |
Matthias Braun | bb8507e | 2017-10-12 22:57:28 +0000 | [diff] [blame^] | 358 | TargetPassConfig::TargetPassConfig(LLVMTargetMachine &TM, PassManagerBase &pm) |
Eugene Zelenko | 76bf48d | 2017-06-26 22:44:03 +0000 | [diff] [blame] | 359 | : ImmutablePass(ID), PM(&pm), TM(&TM) { |
Andrew Trick | c9ce9d2 | 2012-02-15 03:21:47 +0000 | [diff] [blame] | 360 | Impl = new PassConfigImpl(); |
| 361 | |
Andrew Trick | b755133 | 2012-02-04 02:56:45 +0000 | [diff] [blame] | 362 | // Register all target independent codegen passes to activate their PassIDs, |
| 363 | // including this pass itself. |
| 364 | initializeCodeGen(*PassRegistry::getPassRegistry()); |
Andrew Trick | e9a951c | 2012-02-15 03:21:51 +0000 | [diff] [blame] | 365 | |
Chandler Carruth | 7b560d4 | 2015-09-09 17:55:00 +0000 | [diff] [blame] | 366 | // Also register alias analysis passes required by codegen passes. |
| 367 | initializeBasicAAWrapperPassPass(*PassRegistry::getPassRegistry()); |
| 368 | initializeAAResultsWrapperPassPass(*PassRegistry::getPassRegistry()); |
| 369 | |
Andrew Trick | e9a951c | 2012-02-15 03:21:51 +0000 | [diff] [blame] | 370 | // Substitute Pseudo Pass IDs for real ones. |
Bob Wilson | b9b6936 | 2012-07-02 19:48:37 +0000 | [diff] [blame] | 371 | substitutePass(&EarlyTailDuplicateID, &TailDuplicateID); |
| 372 | substitutePass(&PostRAMachineLICMID, &MachineLICMID); |
Matthias Braun | 0663b61 | 2016-05-10 04:51:04 +0000 | [diff] [blame] | 373 | |
| 374 | if (StringRef(PrintMachineInstrs.getValue()).equals("")) |
Matthias Braun | 5e394c3 | 2017-05-30 21:36:41 +0000 | [diff] [blame] | 375 | TM.Options.PrintMachineCode = true; |
Matt Arsenault | 7b0d947 | 2017-04-04 23:44:46 +0000 | [diff] [blame] | 376 | |
Matt Arsenault | 81da0d4 | 2017-08-14 19:54:47 +0000 | [diff] [blame] | 377 | if (EnableIPRA.getNumOccurrences()) |
| 378 | TM.Options.EnableIPRA = EnableIPRA; |
| 379 | else { |
| 380 | // If not explicitly specified, use target default. |
| 381 | TM.Options.EnableIPRA = TM.useIPRA(); |
| 382 | } |
| 383 | |
Matthias Braun | 5e394c3 | 2017-05-30 21:36:41 +0000 | [diff] [blame] | 384 | if (TM.Options.EnableIPRA) |
Matt Arsenault | 7b0d947 | 2017-04-04 23:44:46 +0000 | [diff] [blame] | 385 | setRequiresCodeGenSCCOrder(); |
Quentin Colombet | 15f6ffb | 2017-07-31 18:24:07 +0000 | [diff] [blame] | 386 | |
| 387 | setStartStopPasses(); |
Andrew Trick | b755133 | 2012-02-04 02:56:45 +0000 | [diff] [blame] | 388 | } |
| 389 | |
Matthias Braun | 31d19d4 | 2016-05-10 03:21:59 +0000 | [diff] [blame] | 390 | CodeGenOpt::Level TargetPassConfig::getOptLevel() const { |
| 391 | return TM->getOptLevel(); |
| 392 | } |
| 393 | |
Bob Wilson | 33e5188 | 2012-05-30 00:17:12 +0000 | [diff] [blame] | 394 | /// Insert InsertedPassID pass after TargetPassID. |
Bob Wilson | b9b6936 | 2012-07-02 19:48:37 +0000 | [diff] [blame] | 395 | void TargetPassConfig::insertPass(AnalysisID TargetPassID, |
Justin Bogner | 468c998 | 2015-10-08 00:36:22 +0000 | [diff] [blame] | 396 | IdentifyingPassPtr InsertedPassID, |
| 397 | bool VerifyAfter, bool PrintAfter) { |
Benjamin Kramer | e7c45bc | 2013-04-11 11:57:01 +0000 | [diff] [blame] | 398 | assert(((!InsertedPassID.isInstance() && |
| 399 | TargetPassID != InsertedPassID.getID()) || |
| 400 | (InsertedPassID.isInstance() && |
| 401 | TargetPassID != InsertedPassID.getInstance()->getPassID())) && |
Andrew Trick | e220323 | 2013-04-10 01:06:56 +0000 | [diff] [blame] | 402 | "Insert a pass after itself!"); |
Justin Bogner | 468c998 | 2015-10-08 00:36:22 +0000 | [diff] [blame] | 403 | Impl->InsertedPasses.emplace_back(TargetPassID, InsertedPassID, VerifyAfter, |
| 404 | PrintAfter); |
Bob Wilson | 33e5188 | 2012-05-30 00:17:12 +0000 | [diff] [blame] | 405 | } |
| 406 | |
Andrew Trick | b755133 | 2012-02-04 02:56:45 +0000 | [diff] [blame] | 407 | /// createPassConfig - Create a pass configuration object to be used by |
| 408 | /// addPassToEmitX methods for generating a pipeline of CodeGen passes. |
| 409 | /// |
| 410 | /// Targets may override this to extend TargetPassConfig. |
Matthias Braun | bb8507e | 2017-10-12 22:57:28 +0000 | [diff] [blame^] | 411 | TargetPassConfig *LLVMTargetMachine::createPassConfig(PassManagerBase &PM) { |
Matthias Braun | 5e394c3 | 2017-05-30 21:36:41 +0000 | [diff] [blame] | 412 | return new TargetPassConfig(*this, PM); |
Andrew Trick | b755133 | 2012-02-04 02:56:45 +0000 | [diff] [blame] | 413 | } |
| 414 | |
| 415 | TargetPassConfig::TargetPassConfig() |
Eugene Zelenko | 76bf48d | 2017-06-26 22:44:03 +0000 | [diff] [blame] | 416 | : ImmutablePass(ID) { |
Francis Visoiu Mistrih | 8b61764 | 2017-05-18 17:21:13 +0000 | [diff] [blame] | 417 | report_fatal_error("Trying to construct TargetPassConfig without a target " |
| 418 | "machine. Scheduling a CodeGen pass without a target " |
| 419 | "triple set?"); |
Andrew Trick | b755133 | 2012-02-04 02:56:45 +0000 | [diff] [blame] | 420 | } |
| 421 | |
Quentin Colombet | 15f6ffb | 2017-07-31 18:24:07 +0000 | [diff] [blame] | 422 | bool TargetPassConfig::hasLimitedCodeGenPipeline() const { |
| 423 | return StartBefore || StartAfter || StopBefore || StopAfter; |
| 424 | } |
| 425 | |
| 426 | std::string |
| 427 | TargetPassConfig::getLimitedCodeGenPipelineReason(const char *Separator) const { |
| 428 | if (!hasLimitedCodeGenPipeline()) |
| 429 | return std::string(); |
| 430 | std::string Res; |
| 431 | static cl::opt<std::string> *PassNames[] = {&StartAfterOpt, &StartBeforeOpt, |
| 432 | &StopAfterOpt, &StopBeforeOpt}; |
| 433 | static const char *OptNames[] = {StartAfterOptName, StartBeforeOptName, |
| 434 | StopAfterOptName, StopBeforeOptName}; |
| 435 | bool IsFirst = true; |
| 436 | for (int Idx = 0; Idx < 4; ++Idx) |
| 437 | if (!PassNames[Idx]->empty()) { |
| 438 | if (!IsFirst) |
| 439 | Res += Separator; |
| 440 | IsFirst = false; |
| 441 | Res += OptNames[Idx]; |
| 442 | } |
| 443 | return Res; |
| 444 | } |
| 445 | |
Andrew Trick | dd37d52 | 2012-02-08 21:22:39 +0000 | [diff] [blame] | 446 | // Helper to verify the analysis is really immutable. |
| 447 | void TargetPassConfig::setOpt(bool &Opt, bool Val) { |
| 448 | assert(!Initialized && "PassConfig is immutable"); |
| 449 | Opt = Val; |
| 450 | } |
| 451 | |
Bob Wilson | b9b6936 | 2012-07-02 19:48:37 +0000 | [diff] [blame] | 452 | void TargetPassConfig::substitutePass(AnalysisID StandardID, |
Andrew Trick | e220323 | 2013-04-10 01:06:56 +0000 | [diff] [blame] | 453 | IdentifyingPassPtr TargetID) { |
Bob Wilson | b9b6936 | 2012-07-02 19:48:37 +0000 | [diff] [blame] | 454 | Impl->TargetPasses[StandardID] = TargetID; |
Andrew Trick | c9ce9d2 | 2012-02-15 03:21:47 +0000 | [diff] [blame] | 455 | } |
Andrew Trick | ee874db | 2012-02-11 07:11:32 +0000 | [diff] [blame] | 456 | |
Andrew Trick | e220323 | 2013-04-10 01:06:56 +0000 | [diff] [blame] | 457 | IdentifyingPassPtr TargetPassConfig::getPassSubstitution(AnalysisID ID) const { |
| 458 | DenseMap<AnalysisID, IdentifyingPassPtr>::const_iterator |
Andrew Trick | c9ce9d2 | 2012-02-15 03:21:47 +0000 | [diff] [blame] | 459 | I = Impl->TargetPasses.find(ID); |
| 460 | if (I == Impl->TargetPasses.end()) |
| 461 | return ID; |
| 462 | return I->second; |
| 463 | } |
| 464 | |
Derek Schuff | 1aaf87e | 2016-05-17 08:49:59 +0000 | [diff] [blame] | 465 | bool TargetPassConfig::isPassSubstitutedOrOverridden(AnalysisID ID) const { |
| 466 | IdentifyingPassPtr TargetID = getPassSubstitution(ID); |
| 467 | IdentifyingPassPtr FinalPtr = overridePass(ID, TargetID); |
| 468 | return !FinalPtr.isValid() || FinalPtr.isInstance() || |
| 469 | FinalPtr.getID() != ID; |
| 470 | } |
| 471 | |
Bob Wilson | cac3b90 | 2012-07-02 19:48:45 +0000 | [diff] [blame] | 472 | /// Add a pass to the PassManager if that pass is supposed to be run. If the |
| 473 | /// Started/Stopped flags indicate either that the compilation should start at |
| 474 | /// a later pass or that it should stop after an earlier pass, then do not add |
| 475 | /// the pass. Finally, compare the current pass against the StartAfter |
| 476 | /// and StopAfter options and change the Started/Stopped flags accordingly. |
Matthias Braun | 7e37a5f | 2014-12-11 21:26:47 +0000 | [diff] [blame] | 477 | void TargetPassConfig::addPass(Pass *P, bool verifyAfter, bool printAfter) { |
Bob Wilson | a3f9fa7 | 2012-07-02 19:48:39 +0000 | [diff] [blame] | 478 | assert(!Initialized && "PassConfig is immutable"); |
| 479 | |
Chandler Carruth | 34263a0 | 2012-07-02 22:56:41 +0000 | [diff] [blame] | 480 | // Cache the Pass ID here in case the pass manager finds this pass is |
| 481 | // redundant with ones already scheduled / available, and deletes it. |
| 482 | // Fundamentally, once we add the pass to the manager, we no longer own it |
| 483 | // and shouldn't reference it. |
| 484 | AnalysisID PassID = P->getPassID(); |
| 485 | |
Alex Lorenz | e2d7523 | 2015-07-06 17:44:26 +0000 | [diff] [blame] | 486 | if (StartBefore == PassID) |
| 487 | Started = true; |
Matthias Braun | 729c989 | 2016-09-23 21:46:02 +0000 | [diff] [blame] | 488 | if (StopBefore == PassID) |
| 489 | Stopped = true; |
Matthias Braun | 7e37a5f | 2014-12-11 21:26:47 +0000 | [diff] [blame] | 490 | if (Started && !Stopped) { |
| 491 | std::string Banner; |
| 492 | // Construct banner message before PM->add() as that may delete the pass. |
| 493 | if (AddingMachinePasses && (printAfter || verifyAfter)) |
| 494 | Banner = std::string("After ") + std::string(P->getPassName()); |
Bob Wilson | cac3b90 | 2012-07-02 19:48:45 +0000 | [diff] [blame] | 495 | PM->add(P); |
Matthias Braun | 7e37a5f | 2014-12-11 21:26:47 +0000 | [diff] [blame] | 496 | if (AddingMachinePasses) { |
| 497 | if (printAfter) |
| 498 | addPrintPass(Banner); |
| 499 | if (verifyAfter) |
| 500 | addVerifyPass(Banner); |
| 501 | } |
Akira Hatanaka | c100c56 | 2015-06-05 21:58:14 +0000 | [diff] [blame] | 502 | |
| 503 | // Add the passes after the pass P if there is any. |
Justin Bogner | 468c998 | 2015-10-08 00:36:22 +0000 | [diff] [blame] | 504 | for (auto IP : Impl->InsertedPasses) { |
| 505 | if (IP.TargetPassID == PassID) |
| 506 | addPass(IP.getInsertedPass(), IP.VerifyAfter, IP.PrintAfter); |
Akira Hatanaka | c100c56 | 2015-06-05 21:58:14 +0000 | [diff] [blame] | 507 | } |
Matthias Braun | 7e37a5f | 2014-12-11 21:26:47 +0000 | [diff] [blame] | 508 | } else { |
Benjamin Kramer | 483b9fb | 2013-08-05 11:11:11 +0000 | [diff] [blame] | 509 | delete P; |
Matthias Braun | 7e37a5f | 2014-12-11 21:26:47 +0000 | [diff] [blame] | 510 | } |
Chandler Carruth | 34263a0 | 2012-07-02 22:56:41 +0000 | [diff] [blame] | 511 | if (StopAfter == PassID) |
Bob Wilson | cac3b90 | 2012-07-02 19:48:45 +0000 | [diff] [blame] | 512 | Stopped = true; |
Chandler Carruth | 34263a0 | 2012-07-02 22:56:41 +0000 | [diff] [blame] | 513 | if (StartAfter == PassID) |
Bob Wilson | cac3b90 | 2012-07-02 19:48:45 +0000 | [diff] [blame] | 514 | Started = true; |
| 515 | if (Stopped && !Started) |
| 516 | report_fatal_error("Cannot stop compilation after pass that is not run"); |
Bob Wilson | bbd38dd | 2012-07-02 19:48:31 +0000 | [diff] [blame] | 517 | } |
| 518 | |
Andrew Trick | c9ce9d2 | 2012-02-15 03:21:47 +0000 | [diff] [blame] | 519 | /// Add a CodeGen pass at this point in the pipeline after checking for target |
| 520 | /// and command line overrides. |
Andrew Trick | e220323 | 2013-04-10 01:06:56 +0000 | [diff] [blame] | 521 | /// |
| 522 | /// addPass cannot return a pointer to the pass instance because is internal the |
| 523 | /// PassManager and the instance we create here may already be freed. |
Matthias Braun | 7e37a5f | 2014-12-11 21:26:47 +0000 | [diff] [blame] | 524 | AnalysisID TargetPassConfig::addPass(AnalysisID PassID, bool verifyAfter, |
| 525 | bool printAfter) { |
Andrew Trick | e220323 | 2013-04-10 01:06:56 +0000 | [diff] [blame] | 526 | IdentifyingPassPtr TargetID = getPassSubstitution(PassID); |
| 527 | IdentifyingPassPtr FinalPtr = overridePass(PassID, TargetID); |
| 528 | if (!FinalPtr.isValid()) |
Craig Topper | c0196b1 | 2014-04-14 00:51:57 +0000 | [diff] [blame] | 529 | return nullptr; |
Andrew Trick | c9ce9d2 | 2012-02-15 03:21:47 +0000 | [diff] [blame] | 530 | |
Andrew Trick | e220323 | 2013-04-10 01:06:56 +0000 | [diff] [blame] | 531 | Pass *P; |
| 532 | if (FinalPtr.isInstance()) |
| 533 | P = FinalPtr.getInstance(); |
| 534 | else { |
| 535 | P = Pass::createPass(FinalPtr.getID()); |
| 536 | if (!P) |
| 537 | llvm_unreachable("Pass ID not registered"); |
| 538 | } |
| 539 | AnalysisID FinalID = P->getPassID(); |
Matthias Braun | 7e37a5f | 2014-12-11 21:26:47 +0000 | [diff] [blame] | 540 | addPass(P, verifyAfter, printAfter); // Ends the lifetime of P. |
Andrew Trick | e220323 | 2013-04-10 01:06:56 +0000 | [diff] [blame] | 541 | |
Andrew Trick | c9ce9d2 | 2012-02-15 03:21:47 +0000 | [diff] [blame] | 542 | return FinalID; |
Andrew Trick | f8ea108 | 2012-02-04 02:56:59 +0000 | [diff] [blame] | 543 | } |
Andrew Trick | de401d3 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 544 | |
Matthias Braun | 7e37a5f | 2014-12-11 21:26:47 +0000 | [diff] [blame] | 545 | void TargetPassConfig::printAndVerify(const std::string &Banner) { |
| 546 | addPrintPass(Banner); |
| 547 | addVerifyPass(Banner); |
| 548 | } |
Matthias Braun | a7c82a9 | 2014-12-11 19:42:05 +0000 | [diff] [blame] | 549 | |
Matthias Braun | 7e37a5f | 2014-12-11 21:26:47 +0000 | [diff] [blame] | 550 | void TargetPassConfig::addPrintPass(const std::string &Banner) { |
| 551 | if (TM->shouldPrintMachineCode()) |
| 552 | PM->add(createMachineFunctionPrinterPass(dbgs(), Banner)); |
| 553 | } |
| 554 | |
| 555 | void TargetPassConfig::addVerifyPass(const std::string &Banner) { |
Matthias Braun | d6a36ae | 2017-05-31 18:41:23 +0000 | [diff] [blame] | 556 | bool Verify = VerifyMachineCode; |
| 557 | #ifdef EXPENSIVE_CHECKS |
| 558 | if (VerifyMachineCode == cl::BOU_UNSET) |
| 559 | Verify = TM->isMachineVerifierClean(); |
| 560 | #endif |
| 561 | if (Verify) |
Matthias Braun | 7e37a5f | 2014-12-11 21:26:47 +0000 | [diff] [blame] | 562 | PM->add(createMachineVerifierPass(Banner)); |
Andrew Trick | de401d3 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 563 | } |
| 564 | |
Andrew Trick | f8ea108 | 2012-02-04 02:56:59 +0000 | [diff] [blame] | 565 | /// Add common target configurable passes that perform LLVM IR to IR transforms |
| 566 | /// following machine independent optimization. |
| 567 | void TargetPassConfig::addIRPasses() { |
George Burgess IV | bfa401e | 2016-07-06 00:26:41 +0000 | [diff] [blame] | 568 | switch (UseCFLAA) { |
| 569 | case CFLAAType::Steensgaard: |
| 570 | addPass(createCFLSteensAAWrapperPass()); |
| 571 | break; |
| 572 | case CFLAAType::Andersen: |
| 573 | addPass(createCFLAndersAAWrapperPass()); |
| 574 | break; |
| 575 | case CFLAAType::Both: |
| 576 | addPass(createCFLAndersAAWrapperPass()); |
| 577 | addPass(createCFLSteensAAWrapperPass()); |
| 578 | break; |
| 579 | default: |
| 580 | break; |
| 581 | } |
| 582 | |
Andrew Trick | de401d3 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 583 | // Basic AliasAnalysis support. |
| 584 | // Add TypeBasedAliasAnalysis before BasicAliasAnalysis so that |
| 585 | // BasicAliasAnalysis wins if they disagree. This is intended to help |
| 586 | // support "obvious" type-punning idioms. |
Chandler Carruth | 7b560d4 | 2015-09-09 17:55:00 +0000 | [diff] [blame] | 587 | addPass(createTypeBasedAAWrapperPass()); |
| 588 | addPass(createScopedNoAliasAAWrapperPass()); |
| 589 | addPass(createBasicAAWrapperPass()); |
Andrew Trick | de401d3 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 590 | |
| 591 | // Before running any passes, run the verifier to determine if the input |
| 592 | // coming from the front-end and/or optimizer is valid. |
Duncan P. N. Exon Smith | ab58a56 | 2015-03-19 22:24:17 +0000 | [diff] [blame] | 593 | if (!DisableVerify) |
Bob Wilson | bbd38dd | 2012-07-02 19:48:31 +0000 | [diff] [blame] | 594 | addPass(createVerifierPass()); |
Andrew Trick | de401d3 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 595 | |
| 596 | // Run loop strength reduction before anything else. |
| 597 | if (getOptLevel() != CodeGenOpt::None && !DisableLSR) { |
Chandler Carruth | 26c59fa | 2013-01-07 14:41:08 +0000 | [diff] [blame] | 598 | addPass(createLoopStrengthReducePass()); |
Andrew Trick | de401d3 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 599 | if (PrintLSR) |
Chandler Carruth | 9d80513 | 2014-01-12 11:30:46 +0000 | [diff] [blame] | 600 | addPass(createPrintFunctionPass(dbgs(), "\n\n*** Code after LSR ***\n")); |
Andrew Trick | de401d3 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 601 | } |
| 602 | |
Clement Courbet | 65130e2 | 2017-09-01 10:56:34 +0000 | [diff] [blame] | 603 | if (getOptLevel() != CodeGenOpt::None && EnableMergeICmps) { |
| 604 | addPass(createMergeICmpsPass()); |
| 605 | } |
| 606 | |
Philip Reames | 23cf2e2 | 2015-01-28 19:28:03 +0000 | [diff] [blame] | 607 | // Run GC lowering passes for builtin collectors |
| 608 | // TODO: add a pass insertion point here |
Bob Wilson | bbd38dd | 2012-07-02 19:48:31 +0000 | [diff] [blame] | 609 | addPass(createGCLoweringPass()); |
Philip Reames | 23cf2e2 | 2015-01-28 19:28:03 +0000 | [diff] [blame] | 610 | addPass(createShadowStackGCLoweringPass()); |
Andrew Trick | de401d3 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 611 | |
| 612 | // Make sure that no unreachable blocks are instruction selected. |
Bob Wilson | bbd38dd | 2012-07-02 19:48:31 +0000 | [diff] [blame] | 613 | addPass(createUnreachableBlockEliminationPass()); |
Juergen Ributzka | f26beda | 2014-01-25 02:02:55 +0000 | [diff] [blame] | 614 | |
| 615 | // Prepare expensive constants for SelectionDAG. |
| 616 | if (getOptLevel() != CodeGenOpt::None && !DisableConstantHoisting) |
| 617 | addPass(createConstantHoistingPass()); |
James Molloy | bc9fed8 | 2014-07-23 13:33:00 +0000 | [diff] [blame] | 618 | |
| 619 | if (getOptLevel() != CodeGenOpt::None && !DisablePartialLibcallInlining) |
| 620 | addPass(createPartiallyInlineLibCallsPass()); |
Hal Finkel | 40d7f5c | 2016-09-01 09:42:39 +0000 | [diff] [blame] | 621 | |
| 622 | // Insert calls to mcount-like functions. |
| 623 | addPass(createCountingFunctionInserterPass()); |
Amara Emerson | 836b0f4 | 2017-05-10 09:42:49 +0000 | [diff] [blame] | 624 | |
Ayman Musa | c5490e5 | 2017-05-15 11:30:54 +0000 | [diff] [blame] | 625 | // Add scalarization of target's unsupported masked memory intrinsics pass. |
| 626 | // the unsupported intrinsic will be replaced with a chain of basic blocks, |
| 627 | // that stores/loads element one-by-one if the appropriate mask bit is set. |
| 628 | addPass(createScalarizeMaskedMemIntrinPass()); |
| 629 | |
Amara Emerson | 836b0f4 | 2017-05-10 09:42:49 +0000 | [diff] [blame] | 630 | // Expand reduction intrinsics into shuffle sequences if the target wants to. |
| 631 | addPass(createExpandReductionsPass()); |
Bob Wilson | bbd38dd | 2012-07-02 19:48:31 +0000 | [diff] [blame] | 632 | } |
| 633 | |
| 634 | /// Turn exception handling constructs into something the code generators can |
| 635 | /// handle. |
| 636 | void TargetPassConfig::addPassesToHandleExceptions() { |
Alex Bradbury | 3447ca3 | 2016-08-18 13:08:58 +0000 | [diff] [blame] | 637 | const MCAsmInfo *MCAI = TM->getMCAsmInfo(); |
| 638 | assert(MCAI && "No MCAsmInfo"); |
| 639 | switch (MCAI->getExceptionHandlingType()) { |
Bob Wilson | bbd38dd | 2012-07-02 19:48:31 +0000 | [diff] [blame] | 640 | case ExceptionHandling::SjLj: |
| 641 | // SjLj piggy-backs on dwarf for this bit. The cleanups done apply to both |
| 642 | // Dwarf EH prepare needs to be run after SjLj prepare. Otherwise, |
| 643 | // catch info can get misplaced when a selector ends up more than one block |
| 644 | // removed from the parent invoke(s). This could happen when a landing |
| 645 | // pad is shared by multiple invokes and is also a target of a normal |
| 646 | // edge from elsewhere. |
Mehdi Amini | f50daed | 2015-07-08 01:00:31 +0000 | [diff] [blame] | 647 | addPass(createSjLjEHPreparePass()); |
Justin Bogner | b03fd12 | 2016-08-17 05:10:15 +0000 | [diff] [blame] | 648 | LLVM_FALLTHROUGH; |
Bob Wilson | bbd38dd | 2012-07-02 19:48:31 +0000 | [diff] [blame] | 649 | case ExceptionHandling::DwarfCFI: |
| 650 | case ExceptionHandling::ARM: |
Francis Visoiu Mistrih | 8b61764 | 2017-05-18 17:21:13 +0000 | [diff] [blame] | 651 | addPass(createDwarfEHPass()); |
Bob Wilson | bbd38dd | 2012-07-02 19:48:31 +0000 | [diff] [blame] | 652 | break; |
Reid Kleckner | 1185fce | 2015-01-29 00:41:44 +0000 | [diff] [blame] | 653 | case ExceptionHandling::WinEH: |
Reid Kleckner | 47c8e7a | 2015-03-12 00:36:20 +0000 | [diff] [blame] | 654 | // We support using both GCC-style and MSVC-style exceptions on Windows, so |
| 655 | // add both preparation passes. Each pass will only actually run if it |
| 656 | // recognizes the personality function. |
Francis Visoiu Mistrih | 8b61764 | 2017-05-18 17:21:13 +0000 | [diff] [blame] | 657 | addPass(createWinEHPass()); |
| 658 | addPass(createDwarfEHPass()); |
Reid Kleckner | 1185fce | 2015-01-29 00:41:44 +0000 | [diff] [blame] | 659 | break; |
Bob Wilson | bbd38dd | 2012-07-02 19:48:31 +0000 | [diff] [blame] | 660 | case ExceptionHandling::None: |
Mark Seaborn | b6118c5 | 2014-03-20 19:54:47 +0000 | [diff] [blame] | 661 | addPass(createLowerInvokePass()); |
Bob Wilson | bbd38dd | 2012-07-02 19:48:31 +0000 | [diff] [blame] | 662 | |
| 663 | // The lower invoke pass may create unreachable code. Remove it. |
| 664 | addPass(createUnreachableBlockEliminationPass()); |
| 665 | break; |
| 666 | } |
Andrew Trick | f8ea108 | 2012-02-04 02:56:59 +0000 | [diff] [blame] | 667 | } |
Andrew Trick | de401d3 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 668 | |
Bill Wendling | c786b31 | 2012-11-30 22:08:55 +0000 | [diff] [blame] | 669 | /// Add pass to prepare the LLVM IR for code generation. This should be done |
| 670 | /// before exception handling preparation passes. |
| 671 | void TargetPassConfig::addCodeGenPrepare() { |
| 672 | if (getOptLevel() != CodeGenOpt::None && !DisableCGP) |
Francis Visoiu Mistrih | 8b61764 | 2017-05-18 17:21:13 +0000 | [diff] [blame] | 673 | addPass(createCodeGenPreparePass()); |
Saleem Abdulrasool | d2c5d7f | 2014-11-08 00:00:50 +0000 | [diff] [blame] | 674 | addPass(createRewriteSymbolsPass()); |
Bill Wendling | c786b31 | 2012-11-30 22:08:55 +0000 | [diff] [blame] | 675 | } |
| 676 | |
Andrew Trick | f8ea108 | 2012-02-04 02:56:59 +0000 | [diff] [blame] | 677 | /// Add common passes that perform LLVM IR to IR transforms in preparation for |
| 678 | /// instruction selection. |
| 679 | void TargetPassConfig::addISelPrepare() { |
Andrew Trick | de401d3 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 680 | addPreISel(); |
| 681 | |
Mehdi Amini | bbacddf | 2016-06-10 16:19:46 +0000 | [diff] [blame] | 682 | // Force codegen to run according to the callgraph. |
Matt Arsenault | 7b0d947 | 2017-04-04 23:44:46 +0000 | [diff] [blame] | 683 | if (requiresCodeGenSCCOrder()) |
Mehdi Amini | bbacddf | 2016-06-10 16:19:46 +0000 | [diff] [blame] | 684 | addPass(new DummyCGSCCPass); |
| 685 | |
Peter Collingbourne | 82437bf | 2015-06-15 21:07:11 +0000 | [diff] [blame] | 686 | // Add both the safe stack and the stack protection passes: each of them will |
| 687 | // only protect functions that have corresponding attributes. |
Francis Visoiu Mistrih | 8b61764 | 2017-05-18 17:21:13 +0000 | [diff] [blame] | 688 | addPass(createSafeStackPass()); |
| 689 | addPass(createStackProtectorPass()); |
Josh Magee | 22b8ba2 | 2013-12-19 03:17:11 +0000 | [diff] [blame] | 690 | |
Andrew Trick | de401d3 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 691 | if (PrintISelInput) |
Chandler Carruth | 9d80513 | 2014-01-12 11:30:46 +0000 | [diff] [blame] | 692 | addPass(createPrintFunctionPass( |
| 693 | dbgs(), "\n\n*** Final LLVM Code input to ISel ***\n")); |
Andrew Trick | de401d3 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 694 | |
| 695 | // All passes which modify the LLVM IR are now complete; run the verifier |
| 696 | // to ensure that the IR is valid. |
| 697 | if (!DisableVerify) |
Bob Wilson | bbd38dd | 2012-07-02 19:48:31 +0000 | [diff] [blame] | 698 | addPass(createVerifierPass()); |
Andrew Trick | f8ea108 | 2012-02-04 02:56:59 +0000 | [diff] [blame] | 699 | } |
Andrew Trick | de401d3 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 700 | |
Matthias Braun | c7c06f1 | 2017-06-06 00:26:13 +0000 | [diff] [blame] | 701 | bool TargetPassConfig::addCoreISelPasses() { |
| 702 | // Enable FastISel with -fast, but allow that to be overridden. |
| 703 | TM->setO0WantsFastISel(EnableFastISelOption != cl::BOU_FALSE); |
| 704 | if (EnableFastISelOption == cl::BOU_TRUE || |
| 705 | (TM->getOptLevel() == CodeGenOpt::None && TM->getO0WantsFastISel())) |
| 706 | TM->setFastISel(true); |
| 707 | |
| 708 | // Ask the target for an isel. |
| 709 | // Enable GlobalISel if the target wants to, but allow that to be overriden. |
| 710 | if (EnableGlobalISel == cl::BOU_TRUE || |
| 711 | (EnableGlobalISel == cl::BOU_UNSET && isGlobalISelEnabled())) { |
| 712 | if (addIRTranslator()) |
| 713 | return true; |
| 714 | |
| 715 | addPreLegalizeMachineIR(); |
| 716 | |
| 717 | if (addLegalizeMachineIR()) |
| 718 | return true; |
| 719 | |
| 720 | // Before running the register bank selector, ask the target if it |
| 721 | // wants to run some passes. |
| 722 | addPreRegBankSelect(); |
| 723 | |
| 724 | if (addRegBankSelect()) |
| 725 | return true; |
| 726 | |
| 727 | addPreGlobalInstructionSelect(); |
| 728 | |
| 729 | if (addGlobalInstructionSelect()) |
| 730 | return true; |
| 731 | |
| 732 | // Pass to reset the MachineFunction if the ISel failed. |
| 733 | addPass(createResetMachineFunctionPass( |
| 734 | reportDiagnosticWhenGlobalISelFallback(), isGlobalISelAbortEnabled())); |
| 735 | |
| 736 | // Provide a fallback path when we do not want to abort on |
| 737 | // not-yet-supported input. |
| 738 | if (!isGlobalISelAbortEnabled() && addInstSelector()) |
| 739 | return true; |
| 740 | |
| 741 | } else if (addInstSelector()) |
| 742 | return true; |
| 743 | |
| 744 | return false; |
| 745 | } |
| 746 | |
| 747 | bool TargetPassConfig::addISelPasses() { |
| 748 | if (TM->Options.EmulatedTLS) |
| 749 | addPass(createLowerEmuTLSPass()); |
| 750 | |
| 751 | addPass(createPreISelIntrinsicLoweringPass()); |
| 752 | addPass(createTargetTransformInfoWrapperPass(TM->getTargetIRAnalysis())); |
| 753 | addIRPasses(); |
| 754 | addCodeGenPrepare(); |
| 755 | addPassesToHandleExceptions(); |
| 756 | addISelPrepare(); |
| 757 | |
| 758 | return addCoreISelPasses(); |
| 759 | } |
| 760 | |
Jonas Paulsson | 0f86780 | 2017-05-17 07:36:03 +0000 | [diff] [blame] | 761 | /// -regalloc=... command line option. |
| 762 | static FunctionPass *useDefaultRegisterAllocator() { return nullptr; } |
| 763 | static cl::opt<RegisterRegAlloc::FunctionPassCtor, false, |
| 764 | RegisterPassParser<RegisterRegAlloc> > |
| 765 | RegAlloc("regalloc", |
| 766 | cl::init(&useDefaultRegisterAllocator), |
| 767 | cl::desc("Register allocator to use")); |
| 768 | |
Andrew Trick | f542675 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 769 | /// Add the complete set of target-independent postISel code generator passes. |
| 770 | /// |
| 771 | /// This can be read as the standard order of major LLVM CodeGen stages. Stages |
| 772 | /// with nontrivial configuration or multiple passes are broken out below in |
| 773 | /// add%Stage routines. |
| 774 | /// |
| 775 | /// Any TargetPassConfig::addXX routine may be overriden by the Target. The |
| 776 | /// addPre/Post methods with empty header implementations allow injecting |
| 777 | /// target-specific fixups just before or after major stages. Additionally, |
| 778 | /// targets have the flexibility to change pass order within a stage by |
| 779 | /// overriding default implementation of add%Stage routines below. Each |
| 780 | /// technique has maintainability tradeoffs because alternate pass orders are |
| 781 | /// not well supported. addPre/Post works better if the target pass is easily |
| 782 | /// tied to a common pass. But if it has subtle dependencies on multiple passes, |
Andrew Trick | 09fc1bb | 2012-02-10 07:08:25 +0000 | [diff] [blame] | 783 | /// the target should override the stage instead. |
Andrew Trick | f542675 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 784 | /// |
| 785 | /// TODO: We could use a single addPre/Post(ID) hook to allow pass injection |
| 786 | /// before/after any target-independent pass. But it's currently overkill. |
Andrew Trick | f8ea108 | 2012-02-04 02:56:59 +0000 | [diff] [blame] | 787 | void TargetPassConfig::addMachinePasses() { |
Matthias Braun | 7e37a5f | 2014-12-11 21:26:47 +0000 | [diff] [blame] | 788 | AddingMachinePasses = true; |
| 789 | |
Bob Wilson | 33e5188 | 2012-05-30 00:17:12 +0000 | [diff] [blame] | 790 | // Insert a machine instr printer pass after the specified pass. |
Matthias Braun | 0663b61 | 2016-05-10 04:51:04 +0000 | [diff] [blame] | 791 | if (!StringRef(PrintMachineInstrs.getValue()).equals("") && |
| 792 | !StringRef(PrintMachineInstrs.getValue()).equals("option-unspecified")) { |
Bob Wilson | 33e5188 | 2012-05-30 00:17:12 +0000 | [diff] [blame] | 793 | const PassRegistry *PR = PassRegistry::getPassRegistry(); |
| 794 | const PassInfo *TPI = PR->getPassInfo(PrintMachineInstrs.getValue()); |
Akira Hatanaka | 7ba7830 | 2014-12-13 04:52:04 +0000 | [diff] [blame] | 795 | const PassInfo *IPI = PR->getPassInfo(StringRef("machineinstr-printer")); |
Bob Wilson | 33e5188 | 2012-05-30 00:17:12 +0000 | [diff] [blame] | 796 | assert (TPI && IPI && "Pass ID not registered!"); |
Roman Divacky | ad06cee | 2012-09-05 22:26:57 +0000 | [diff] [blame] | 797 | const char *TID = (const char *)(TPI->getTypeInfo()); |
| 798 | const char *IID = (const char *)(IPI->getTypeInfo()); |
Bob Wilson | b9b6936 | 2012-07-02 19:48:37 +0000 | [diff] [blame] | 799 | insertPass(TID, IID); |
Bob Wilson | 33e5188 | 2012-05-30 00:17:12 +0000 | [diff] [blame] | 800 | } |
| 801 | |
Jakob Stoklund Olesen | 29506f5 | 2012-07-04 19:28:27 +0000 | [diff] [blame] | 802 | // Print the instruction selected machine code... |
| 803 | printAndVerify("After Instruction Selection"); |
| 804 | |
Andrew Trick | de401d3 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 805 | // Expand pseudo-instructions emitted by ISel. |
Matthias Braun | 7e37a5f | 2014-12-11 21:26:47 +0000 | [diff] [blame] | 806 | addPass(&ExpandISelPseudosID); |
Andrew Trick | de401d3 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 807 | |
Andrew Trick | f542675 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 808 | // Add passes that optimize machine instructions in SSA form. |
Andrew Trick | de401d3 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 809 | if (getOptLevel() != CodeGenOpt::None) { |
Andrew Trick | f542675 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 810 | addMachineSSAOptimization(); |
Craig Topper | 36f2912 | 2012-11-19 00:11:50 +0000 | [diff] [blame] | 811 | } else { |
Andrew Trick | f542675 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 812 | // If the target requests it, assign local variables to stack slots relative |
| 813 | // to one another and simplify frame index references where possible. |
Matthias Braun | 7e37a5f | 2014-12-11 21:26:47 +0000 | [diff] [blame] | 814 | addPass(&LocalStackSlotAllocationID, false); |
Andrew Trick | de401d3 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 815 | } |
| 816 | |
Matt Arsenault | f9273c8 | 2017-08-14 19:54:45 +0000 | [diff] [blame] | 817 | if (TM->Options.EnableIPRA) |
| 818 | addPass(createRegUsageInfoPropPass()); |
| 819 | |
Andrew Trick | de401d3 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 820 | // Run pre-ra passes. |
Matthias Braun | 7e37a5f | 2014-12-11 21:26:47 +0000 | [diff] [blame] | 821 | addPreRegAlloc(); |
Andrew Trick | de401d3 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 822 | |
Andrew Trick | f542675 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 823 | // Run register allocation and passes that are tightly coupled with it, |
| 824 | // including phi elimination and scheduling. |
Andrew Trick | d3f8fe8 | 2012-02-10 04:10:36 +0000 | [diff] [blame] | 825 | if (getOptimizeRegAlloc()) |
| 826 | addOptimizedRegAlloc(createRegAllocPass(true)); |
Jonas Paulsson | 0f86780 | 2017-05-17 07:36:03 +0000 | [diff] [blame] | 827 | else { |
| 828 | if (RegAlloc != &useDefaultRegisterAllocator && |
| 829 | RegAlloc != &createFastRegisterAllocator) |
| 830 | report_fatal_error("Must use fast (default) register allocator for unoptimized regalloc."); |
Andrew Trick | d3f8fe8 | 2012-02-10 04:10:36 +0000 | [diff] [blame] | 831 | addFastRegAlloc(createRegAllocPass(false)); |
Jonas Paulsson | 0f86780 | 2017-05-17 07:36:03 +0000 | [diff] [blame] | 832 | } |
Andrew Trick | de401d3 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 833 | |
| 834 | // Run post-ra passes. |
Matthias Braun | 7e37a5f | 2014-12-11 21:26:47 +0000 | [diff] [blame] | 835 | addPostRegAlloc(); |
Andrew Trick | de401d3 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 836 | |
| 837 | // Insert prolog/epilog code. Eliminate abstract frame index references... |
Junmo Park | 3347e78 | 2016-01-18 06:42:51 +0000 | [diff] [blame] | 838 | if (getOptLevel() != CodeGenOpt::None) |
Kit Barton | ae78d53 | 2015-08-14 16:54:32 +0000 | [diff] [blame] | 839 | addPass(&ShrinkWrapID); |
Kit Barton | d3cc167 | 2015-08-31 18:26:45 +0000 | [diff] [blame] | 840 | |
Derek Schuff | 1aaf87e | 2016-05-17 08:49:59 +0000 | [diff] [blame] | 841 | // Prolog/Epilog inserter needs a TargetMachine to instantiate. But only |
| 842 | // do so if it hasn't been disabled, substituted, or overridden. |
| 843 | if (!isPassSubstitutedOrOverridden(&PrologEpilogCodeInserterID)) |
Francis Visoiu Mistrih | 8b61764 | 2017-05-18 17:21:13 +0000 | [diff] [blame] | 844 | addPass(createPrologEpilogInserterPass()); |
Andrew Trick | de401d3 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 845 | |
Andrew Trick | f542675 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 846 | /// Add passes that optimize machine instructions after register allocation. |
| 847 | if (getOptLevel() != CodeGenOpt::None) |
| 848 | addMachineLateOptimization(); |
Andrew Trick | de401d3 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 849 | |
| 850 | // Expand pseudo instructions before second scheduling pass. |
Bob Wilson | b9b6936 | 2012-07-02 19:48:37 +0000 | [diff] [blame] | 851 | addPass(&ExpandPostRAPseudosID); |
Andrew Trick | de401d3 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 852 | |
| 853 | // Run pre-sched2 passes. |
Matthias Braun | 7e37a5f | 2014-12-11 21:26:47 +0000 | [diff] [blame] | 854 | addPreSched2(); |
Andrew Trick | de401d3 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 855 | |
Sanjoy Das | 69fad07 | 2015-06-15 18:44:27 +0000 | [diff] [blame] | 856 | if (EnableImplicitNullChecks) |
| 857 | addPass(&ImplicitNullChecksID); |
| 858 | |
Andrew Trick | de401d3 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 859 | // Second pass scheduler. |
Jonas Paulsson | e451eef | 2015-12-10 09:10:07 +0000 | [diff] [blame] | 860 | // Let Target optionally insert this pass by itself at some other |
| 861 | // point. |
| 862 | if (getOptLevel() != CodeGenOpt::None && |
| 863 | !TM->targetSchedulesPostRAScheduling()) { |
Andrew Trick | 17080b9 | 2013-12-28 21:56:51 +0000 | [diff] [blame] | 864 | if (MISchedPostRA) |
| 865 | addPass(&PostMachineSchedulerID); |
| 866 | else |
| 867 | addPass(&PostRASchedulerID); |
Andrew Trick | de401d3 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 868 | } |
| 869 | |
Andrew Trick | f542675 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 870 | // GC |
Evan Cheng | 59421ae | 2012-12-21 02:57:04 +0000 | [diff] [blame] | 871 | if (addGCPasses()) { |
| 872 | if (PrintGCInfo) |
Matthias Braun | 7e37a5f | 2014-12-11 21:26:47 +0000 | [diff] [blame] | 873 | addPass(createGCInfoPrinter(dbgs()), false, false); |
Evan Cheng | 59421ae | 2012-12-21 02:57:04 +0000 | [diff] [blame] | 874 | } |
Andrew Trick | de401d3 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 875 | |
Andrew Trick | f542675 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 876 | // Basic block placement. |
Andrew Trick | e9a951c | 2012-02-15 03:21:51 +0000 | [diff] [blame] | 877 | if (getOptLevel() != CodeGenOpt::None) |
Andrew Trick | f542675 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 878 | addBlockPlacement(); |
Andrew Trick | de401d3 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 879 | |
Matthias Braun | 7e37a5f | 2014-12-11 21:26:47 +0000 | [diff] [blame] | 880 | addPreEmitPass(); |
Juergen Ributzka | e829475 | 2013-12-14 06:53:06 +0000 | [diff] [blame] | 881 | |
Mehdi Amini | cfed256 | 2016-07-13 23:39:46 +0000 | [diff] [blame] | 882 | if (TM->Options.EnableIPRA) |
Mehdi Amini | bbacddf | 2016-06-10 16:19:46 +0000 | [diff] [blame] | 883 | // Collect register usage information and produce a register mask of |
| 884 | // clobbered registers, to be used to optimize call sites. |
| 885 | addPass(createRegUsageInfoCollector()); |
| 886 | |
David Majnemer | 9789023 | 2015-09-17 20:45:18 +0000 | [diff] [blame] | 887 | addPass(&FuncletLayoutID, false); |
| 888 | |
Matthias Braun | 7e37a5f | 2014-12-11 21:26:47 +0000 | [diff] [blame] | 889 | addPass(&StackMapLivenessID, false); |
Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 890 | addPass(&LiveDebugValuesID, false); |
Matthias Braun | 7e37a5f | 2014-12-11 21:26:47 +0000 | [diff] [blame] | 891 | |
Nirav Dave | a7c041d | 2017-01-31 17:00:27 +0000 | [diff] [blame] | 892 | // Insert before XRay Instrumentation. |
| 893 | addPass(&FEntryInserterID, false); |
| 894 | |
Dean Michael Berris | 52735fc | 2016-07-14 04:06:33 +0000 | [diff] [blame] | 895 | addPass(&XRayInstrumentationID, false); |
Sanjoy Das | c0441c2 | 2016-04-19 05:24:47 +0000 | [diff] [blame] | 896 | addPass(&PatchableFunctionID, false); |
| 897 | |
Jessica Paquette | 596f483 | 2017-03-06 21:31:18 +0000 | [diff] [blame] | 898 | if (EnableMachineOutliner) |
Jessica Paquette | 1359384 | 2017-10-07 00:16:34 +0000 | [diff] [blame] | 899 | PM->add(createMachineOutlinerPass(EnableLinkOnceODROutlining)); |
Jessica Paquette | 596f483 | 2017-03-06 21:31:18 +0000 | [diff] [blame] | 900 | |
Matthias Braun | 7e37a5f | 2014-12-11 21:26:47 +0000 | [diff] [blame] | 901 | AddingMachinePasses = false; |
Andrew Trick | de401d3 | 2012-02-04 02:56:48 +0000 | [diff] [blame] | 902 | } |
| 903 | |
Andrew Trick | f542675 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 904 | /// Add passes that optimize machine instructions in SSA form. |
| 905 | void TargetPassConfig::addMachineSSAOptimization() { |
| 906 | // Pre-ra tail duplication. |
Matthias Braun | 7e37a5f | 2014-12-11 21:26:47 +0000 | [diff] [blame] | 907 | addPass(&EarlyTailDuplicateID); |
Andrew Trick | f542675 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 908 | |
| 909 | // Optimize PHIs before DCE: removing dead PHI cycles may make more |
| 910 | // instructions dead. |
Matthias Braun | 7e37a5f | 2014-12-11 21:26:47 +0000 | [diff] [blame] | 911 | addPass(&OptimizePHIsID, false); |
Andrew Trick | f542675 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 912 | |
Nadav Rotem | 7c277da | 2012-09-06 09:17:37 +0000 | [diff] [blame] | 913 | // This pass merges large allocas. StackSlotColoring is a different pass |
| 914 | // which merges spill slots. |
Matthias Braun | 7e37a5f | 2014-12-11 21:26:47 +0000 | [diff] [blame] | 915 | addPass(&StackColoringID, false); |
Nadav Rotem | 7c277da | 2012-09-06 09:17:37 +0000 | [diff] [blame] | 916 | |
Andrew Trick | f542675 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 917 | // If the target requests it, assign local variables to stack slots relative |
| 918 | // to one another and simplify frame index references where possible. |
Matthias Braun | 7e37a5f | 2014-12-11 21:26:47 +0000 | [diff] [blame] | 919 | addPass(&LocalStackSlotAllocationID, false); |
Andrew Trick | f542675 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 920 | |
| 921 | // With optimization, dead code should already be eliminated. However |
| 922 | // there is one known exception: lowered code for arguments that are only |
| 923 | // used by tail calls, where the tail calls reuse the incoming stack |
| 924 | // arguments directly (see t11 in test/CodeGen/X86/sibcall.ll). |
Bob Wilson | b9b6936 | 2012-07-02 19:48:37 +0000 | [diff] [blame] | 925 | addPass(&DeadMachineInstructionElimID); |
Andrew Trick | f542675 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 926 | |
Jakob Stoklund Olesen | 213a2f8 | 2013-01-17 00:58:38 +0000 | [diff] [blame] | 927 | // Allow targets to insert passes that improve instruction level parallelism, |
| 928 | // like if-conversion. Such passes will typically need dominator trees and |
| 929 | // loop info, just like LICM and CSE below. |
Matthias Braun | 7e37a5f | 2014-12-11 21:26:47 +0000 | [diff] [blame] | 930 | addILPOpts(); |
Jakob Stoklund Olesen | 213a2f8 | 2013-01-17 00:58:38 +0000 | [diff] [blame] | 931 | |
Matthias Braun | 7e37a5f | 2014-12-11 21:26:47 +0000 | [diff] [blame] | 932 | addPass(&MachineLICMID, false); |
| 933 | addPass(&MachineCSEID, false); |
Nemanja Ivanovic | b223cfa | 2017-03-01 20:29:34 +0000 | [diff] [blame] | 934 | |
Bob Wilson | b9b6936 | 2012-07-02 19:48:37 +0000 | [diff] [blame] | 935 | addPass(&MachineSinkingID); |
Andrew Trick | f542675 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 936 | |
Matt Arsenault | 07a72ba | 2015-10-12 17:43:56 +0000 | [diff] [blame] | 937 | addPass(&PeepholeOptimizerID); |
Quentin Colombet | 03e43f8 | 2014-08-20 17:41:48 +0000 | [diff] [blame] | 938 | // Clean-up the dead code that may have been generated by peephole |
| 939 | // rewriting. |
| 940 | addPass(&DeadMachineInstructionElimID); |
Andrew Trick | f542675 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 941 | } |
| 942 | |
Andrew Trick | b755133 | 2012-02-04 02:56:45 +0000 | [diff] [blame] | 943 | //===---------------------------------------------------------------------===// |
Andrew Trick | f542675 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 944 | /// Register Allocation Pass Configuration |
Jim Laskey | 29e635d | 2006-08-02 12:30:23 +0000 | [diff] [blame] | 945 | //===---------------------------------------------------------------------===// |
Andrew Trick | f542675 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 946 | |
Andrew Trick | d3f8fe8 | 2012-02-10 04:10:36 +0000 | [diff] [blame] | 947 | bool TargetPassConfig::getOptimizeRegAlloc() const { |
| 948 | switch (OptimizeRegAlloc) { |
| 949 | case cl::BOU_UNSET: return getOptLevel() != CodeGenOpt::None; |
| 950 | case cl::BOU_TRUE: return true; |
| 951 | case cl::BOU_FALSE: return false; |
| 952 | } |
| 953 | llvm_unreachable("Invalid optimize-regalloc state"); |
| 954 | } |
| 955 | |
Andrew Trick | f542675 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 956 | /// RegisterRegAlloc's global Registry tracks allocator registration. |
Jim Laskey | 29e635d | 2006-08-02 12:30:23 +0000 | [diff] [blame] | 957 | MachinePassRegistry RegisterRegAlloc::Registry; |
| 958 | |
Andrew Trick | f542675 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 959 | /// A dummy default pass factory indicates whether the register allocator is |
| 960 | /// overridden on the command line. |
Kamil Rytarowski | 5d2bd8d | 2017-02-05 21:13:06 +0000 | [diff] [blame] | 961 | static llvm::once_flag InitializeDefaultRegisterAllocatorFlag; |
Jonas Paulsson | 0f86780 | 2017-05-17 07:36:03 +0000 | [diff] [blame] | 962 | |
Jakob Stoklund Olesen | b613ae2 | 2010-05-27 23:57:25 +0000 | [diff] [blame] | 963 | static RegisterRegAlloc |
| 964 | defaultRegAlloc("default", |
| 965 | "pick register allocator based on -O option", |
Andrew Trick | d3f8fe8 | 2012-02-10 04:10:36 +0000 | [diff] [blame] | 966 | useDefaultRegisterAllocator); |
Jim Laskey | 29e635d | 2006-08-02 12:30:23 +0000 | [diff] [blame] | 967 | |
David Majnemer | d9d02d8 | 2016-07-08 16:39:00 +0000 | [diff] [blame] | 968 | static void initializeDefaultRegisterAllocatorOnce() { |
| 969 | RegisterRegAlloc::FunctionPassCtor Ctor = RegisterRegAlloc::getDefault(); |
| 970 | |
| 971 | if (!Ctor) { |
| 972 | Ctor = RegAlloc; |
| 973 | RegisterRegAlloc::setDefault(RegAlloc); |
| 974 | } |
| 975 | } |
| 976 | |
Andrew Trick | d3f8fe8 | 2012-02-10 04:10:36 +0000 | [diff] [blame] | 977 | /// Instantiate the default register allocator pass for this target for either |
| 978 | /// the optimized or unoptimized allocation path. This will be added to the pass |
| 979 | /// manager by addFastRegAlloc in the unoptimized case or addOptimizedRegAlloc |
| 980 | /// in the optimized case. |
| 981 | /// |
| 982 | /// A target that uses the standard regalloc pass order for fast or optimized |
| 983 | /// allocation may still override this for per-target regalloc |
| 984 | /// selection. But -regalloc=... always takes precedence. |
| 985 | FunctionPass *TargetPassConfig::createTargetRegisterAllocator(bool Optimized) { |
| 986 | if (Optimized) |
| 987 | return createGreedyRegisterAllocator(); |
| 988 | else |
| 989 | return createFastRegisterAllocator(); |
| 990 | } |
| 991 | |
| 992 | /// Find and instantiate the register allocation pass requested by this target |
| 993 | /// at the current optimization level. Different register allocators are |
| 994 | /// defined as separate passes because they may require different analysis. |
| 995 | /// |
| 996 | /// This helper ensures that the regalloc= option is always available, |
| 997 | /// even for targets that override the default allocator. |
| 998 | /// |
| 999 | /// FIXME: When MachinePassRegistry register pass IDs instead of function ptrs, |
| 1000 | /// this can be folded into addPass. |
| 1001 | FunctionPass *TargetPassConfig::createRegAllocPass(bool Optimized) { |
Andrew Trick | d3f8fe8 | 2012-02-10 04:10:36 +0000 | [diff] [blame] | 1002 | // Initialize the global default. |
David Majnemer | d9d02d8 | 2016-07-08 16:39:00 +0000 | [diff] [blame] | 1003 | llvm::call_once(InitializeDefaultRegisterAllocatorFlag, |
| 1004 | initializeDefaultRegisterAllocatorOnce); |
| 1005 | |
| 1006 | RegisterRegAlloc::FunctionPassCtor Ctor = RegisterRegAlloc::getDefault(); |
Andrew Trick | d3f8fe8 | 2012-02-10 04:10:36 +0000 | [diff] [blame] | 1007 | if (Ctor != useDefaultRegisterAllocator) |
Jakob Stoklund Olesen | b613ae2 | 2010-05-27 23:57:25 +0000 | [diff] [blame] | 1008 | return Ctor(); |
| 1009 | |
Andrew Trick | d3f8fe8 | 2012-02-10 04:10:36 +0000 | [diff] [blame] | 1010 | // With no -regalloc= override, ask the target for a regalloc pass. |
| 1011 | return createTargetRegisterAllocator(Optimized); |
| 1012 | } |
| 1013 | |
Arnaud A. de Grandmaison | a61262f | 2014-10-21 20:47:22 +0000 | [diff] [blame] | 1014 | /// Return true if the default global register allocator is in use and |
| 1015 | /// has not be overriden on the command line with '-regalloc=...' |
| 1016 | bool TargetPassConfig::usingDefaultRegAlloc() const { |
Arnaud A. de Grandmaison | 5c7fe7e9 | 2014-10-21 21:50:49 +0000 | [diff] [blame] | 1017 | return RegAlloc.getNumOccurrences() == 0; |
Arnaud A. de Grandmaison | a61262f | 2014-10-21 20:47:22 +0000 | [diff] [blame] | 1018 | } |
| 1019 | |
Andrew Trick | d3f8fe8 | 2012-02-10 04:10:36 +0000 | [diff] [blame] | 1020 | /// Add the minimum set of target-independent passes that are required for |
| 1021 | /// register allocation. No coalescing or scheduling. |
| 1022 | void TargetPassConfig::addFastRegAlloc(FunctionPass *RegAllocPass) { |
Matthias Braun | 7e37a5f | 2014-12-11 21:26:47 +0000 | [diff] [blame] | 1023 | addPass(&PHIEliminationID, false); |
| 1024 | addPass(&TwoAddressInstructionPassID, false); |
Andrew Trick | d3f8fe8 | 2012-02-10 04:10:36 +0000 | [diff] [blame] | 1025 | |
Dan Gohman | e32c574 | 2015-09-08 20:36:33 +0000 | [diff] [blame] | 1026 | if (RegAllocPass) |
| 1027 | addPass(RegAllocPass); |
Jim Laskey | d1a714e | 2006-07-27 20:05:00 +0000 | [diff] [blame] | 1028 | } |
Andrew Trick | f542675 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 1029 | |
| 1030 | /// Add standard target-independent passes that are tightly coupled with |
Andrew Trick | d3f8fe8 | 2012-02-10 04:10:36 +0000 | [diff] [blame] | 1031 | /// optimized register allocation, including coalescing, machine instruction |
| 1032 | /// scheduling, and register allocation itself. |
| 1033 | void TargetPassConfig::addOptimizedRegAlloc(FunctionPass *RegAllocPass) { |
Matthias Braun | fbe85ae | 2016-04-28 03:07:16 +0000 | [diff] [blame] | 1034 | addPass(&DetectDeadLanesID, false); |
| 1035 | |
Matthias Braun | 7e37a5f | 2014-12-11 21:26:47 +0000 | [diff] [blame] | 1036 | addPass(&ProcessImplicitDefsID, false); |
Jakob Stoklund Olesen | eb49566 | 2012-06-25 18:12:18 +0000 | [diff] [blame] | 1037 | |
Andrew Trick | d3f8fe8 | 2012-02-10 04:10:36 +0000 | [diff] [blame] | 1038 | // LiveVariables currently requires pure SSA form. |
| 1039 | // |
| 1040 | // FIXME: Once TwoAddressInstruction pass no longer uses kill flags, |
| 1041 | // LiveVariables can be removed completely, and LiveIntervals can be directly |
| 1042 | // computed. (We still either need to regenerate kill flags after regalloc, or |
| 1043 | // preferably fix the scavenger to not depend on them). |
Matthias Braun | 7e37a5f | 2014-12-11 21:26:47 +0000 | [diff] [blame] | 1044 | addPass(&LiveVariablesID, false); |
Andrew Trick | d3f8fe8 | 2012-02-10 04:10:36 +0000 | [diff] [blame] | 1045 | |
Rafael Espindola | 9770bde | 2013-10-14 16:39:04 +0000 | [diff] [blame] | 1046 | // Edge splitting is smarter with machine loop info. |
Matthias Braun | 7e37a5f | 2014-12-11 21:26:47 +0000 | [diff] [blame] | 1047 | addPass(&MachineLoopInfoID, false); |
| 1048 | addPass(&PHIEliminationID, false); |
Jakob Stoklund Olesen | 1c46589 | 2012-08-03 22:12:54 +0000 | [diff] [blame] | 1049 | |
| 1050 | // Eventually, we want to run LiveIntervals before PHI elimination. |
| 1051 | if (EarlyLiveIntervals) |
Matthias Braun | 7e37a5f | 2014-12-11 21:26:47 +0000 | [diff] [blame] | 1052 | addPass(&LiveIntervalsID, false); |
Jakob Stoklund Olesen | 1c46589 | 2012-08-03 22:12:54 +0000 | [diff] [blame] | 1053 | |
Matthias Braun | 7e37a5f | 2014-12-11 21:26:47 +0000 | [diff] [blame] | 1054 | addPass(&TwoAddressInstructionPassID, false); |
Bob Wilson | b9b6936 | 2012-07-02 19:48:37 +0000 | [diff] [blame] | 1055 | addPass(&RegisterCoalescerID); |
Andrew Trick | d3f8fe8 | 2012-02-10 04:10:36 +0000 | [diff] [blame] | 1056 | |
Matthias Braun | f9acaca | 2016-05-31 22:38:06 +0000 | [diff] [blame] | 1057 | // The machine scheduler may accidentally create disconnected components |
| 1058 | // when moving subregister definitions around, avoid this by splitting them to |
| 1059 | // separate vregs before. Splitting can also improve reg. allocation quality. |
| 1060 | addPass(&RenameIndependentSubregsID); |
| 1061 | |
Andrew Trick | d3f8fe8 | 2012-02-10 04:10:36 +0000 | [diff] [blame] | 1062 | // PreRA instruction scheduling. |
Matthias Braun | 7e37a5f | 2014-12-11 21:26:47 +0000 | [diff] [blame] | 1063 | addPass(&MachineSchedulerID); |
Andrew Trick | d3f8fe8 | 2012-02-10 04:10:36 +0000 | [diff] [blame] | 1064 | |
Dan Gohman | e32c574 | 2015-09-08 20:36:33 +0000 | [diff] [blame] | 1065 | if (RegAllocPass) { |
| 1066 | // Add the selected register allocation pass. |
| 1067 | addPass(RegAllocPass); |
Jakob Stoklund Olesen | 59a0d32 | 2012-06-26 17:09:29 +0000 | [diff] [blame] | 1068 | |
Dan Gohman | e32c574 | 2015-09-08 20:36:33 +0000 | [diff] [blame] | 1069 | // Allow targets to change the register assignments before rewriting. |
| 1070 | addPreRewrite(); |
Andrew Trick | f542675 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 1071 | |
Dan Gohman | e32c574 | 2015-09-08 20:36:33 +0000 | [diff] [blame] | 1072 | // Finally rewrite virtual registers. |
| 1073 | addPass(&VirtRegRewriterID); |
Jakob Stoklund Olesen | 1224312 | 2012-06-08 23:44:45 +0000 | [diff] [blame] | 1074 | |
Dan Gohman | e32c574 | 2015-09-08 20:36:33 +0000 | [diff] [blame] | 1075 | // Perform stack slot coloring and post-ra machine LICM. |
| 1076 | // |
| 1077 | // FIXME: Re-enable coloring with register when it's capable of adding |
| 1078 | // kill markers. |
| 1079 | addPass(&StackSlotColoringID); |
Andrew Trick | 899f46c | 2012-02-15 07:57:03 +0000 | [diff] [blame] | 1080 | |
Dan Gohman | e32c574 | 2015-09-08 20:36:33 +0000 | [diff] [blame] | 1081 | // Run post-ra machine LICM to hoist reloads / remats. |
| 1082 | // |
| 1083 | // FIXME: can this move into MachineLateOptimization? |
| 1084 | addPass(&PostRAMachineLICMID); |
| 1085 | } |
Andrew Trick | f542675 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 1086 | } |
| 1087 | |
| 1088 | //===---------------------------------------------------------------------===// |
| 1089 | /// Post RegAlloc Pass Configuration |
| 1090 | //===---------------------------------------------------------------------===// |
| 1091 | |
| 1092 | /// Add passes that optimize machine instructions after register allocation. |
| 1093 | void TargetPassConfig::addMachineLateOptimization() { |
| 1094 | // Branch folding must be run after regalloc and prolog/epilog insertion. |
Matthias Braun | 7e37a5f | 2014-12-11 21:26:47 +0000 | [diff] [blame] | 1095 | addPass(&BranchFolderPassID); |
Andrew Trick | f542675 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 1096 | |
| 1097 | // Tail duplication. |
Vincent Lejeune | 92b0a64 | 2013-12-07 01:49:19 +0000 | [diff] [blame] | 1098 | // Note that duplicating tail just increases code size and degrades |
| 1099 | // performance for targets that require Structured Control Flow. |
| 1100 | // In addition it can also make CFG irreducible. Thus we disable it. |
Matthias Braun | 7e37a5f | 2014-12-11 21:26:47 +0000 | [diff] [blame] | 1101 | if (!TM->requiresStructuredCFG()) |
| 1102 | addPass(&TailDuplicateID); |
Andrew Trick | f542675 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 1103 | |
| 1104 | // Copy propagation. |
Matthias Braun | 7e37a5f | 2014-12-11 21:26:47 +0000 | [diff] [blame] | 1105 | addPass(&MachineCopyPropagationID); |
Andrew Trick | f542675 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 1106 | } |
| 1107 | |
Evan Cheng | 59421ae | 2012-12-21 02:57:04 +0000 | [diff] [blame] | 1108 | /// Add standard GC passes. |
| 1109 | bool TargetPassConfig::addGCPasses() { |
Matthias Braun | 7e37a5f | 2014-12-11 21:26:47 +0000 | [diff] [blame] | 1110 | addPass(&GCMachineCodeAnalysisID, false); |
Evan Cheng | 59421ae | 2012-12-21 02:57:04 +0000 | [diff] [blame] | 1111 | return true; |
| 1112 | } |
| 1113 | |
Andrew Trick | f542675 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 1114 | /// Add standard basic block placement passes. |
| 1115 | void TargetPassConfig::addBlockPlacement() { |
Matt Arsenault | 8023233 | 2016-06-09 23:31:55 +0000 | [diff] [blame] | 1116 | if (addPass(&MachineBlockPlacementID)) { |
Andrew Trick | e9a951c | 2012-02-15 03:21:51 +0000 | [diff] [blame] | 1117 | // Run a separate pass to collect block placement statistics. |
| 1118 | if (EnableBlockPlacementStats) |
Bob Wilson | b9b6936 | 2012-07-02 19:48:37 +0000 | [diff] [blame] | 1119 | addPass(&MachineBlockPlacementStatsID); |
Andrew Trick | f542675 | 2012-02-09 00:40:55 +0000 | [diff] [blame] | 1120 | } |
| 1121 | } |
Quentin Colombet | 0de43b2 | 2016-08-26 22:32:59 +0000 | [diff] [blame] | 1122 | |
| 1123 | //===---------------------------------------------------------------------===// |
| 1124 | /// GlobalISel Configuration |
| 1125 | //===---------------------------------------------------------------------===// |
Ahmed Bougacha | 120ae22 | 2017-03-01 23:33:08 +0000 | [diff] [blame] | 1126 | |
| 1127 | bool TargetPassConfig::isGlobalISelEnabled() const { |
| 1128 | return false; |
| 1129 | } |
| 1130 | |
Quentin Colombet | 0de43b2 | 2016-08-26 22:32:59 +0000 | [diff] [blame] | 1131 | bool TargetPassConfig::isGlobalISelAbortEnabled() const { |
Quentin Colombet | 1c06a73 | 2016-08-31 18:43:04 +0000 | [diff] [blame] | 1132 | return EnableGlobalISelAbort == 1; |
| 1133 | } |
| 1134 | |
| 1135 | bool TargetPassConfig::reportDiagnosticWhenGlobalISelFallback() const { |
| 1136 | return EnableGlobalISelAbort == 2; |
Quentin Colombet | 0de43b2 | 2016-08-26 22:32:59 +0000 | [diff] [blame] | 1137 | } |