Nate Begeman | 6cca84e | 2005-10-16 05:39:50 +0000 | [diff] [blame] | 1 | //===-- PPCTargetMachine.cpp - Define TargetMachine for PowerPC -----------===// |
Misha Brukman | b440243 | 2005-04-21 23:30:14 +0000 | [diff] [blame] | 2 | // |
Misha Brukman | e05203f | 2004-06-21 16:55:25 +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 | b440243 | 2005-04-21 23:30:14 +0000 | [diff] [blame] | 7 | // |
Misha Brukman | e05203f | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
Misha Brukman | b440243 | 2005-04-21 23:30:14 +0000 | [diff] [blame] | 9 | // |
Chris Lattner | 73785d2 | 2005-08-15 23:47:04 +0000 | [diff] [blame] | 10 | // Top-level implementation for the PowerPC target. |
Misha Brukman | e05203f | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Chris Lattner | 6f3b954 | 2005-10-14 23:59:06 +0000 | [diff] [blame] | 14 | #include "PPCTargetMachine.h" |
Craig Topper | b25fda9 | 2012-03-17 18:46:09 +0000 | [diff] [blame] | 15 | #include "PPC.h" |
Chandler Carruth | d990388 | 2015-01-14 11:23:27 +0000 | [diff] [blame] | 16 | #include "PPCTargetObjectFile.h" |
Chandler Carruth | 93dcdc4 | 2015-01-31 11:17:59 +0000 | [diff] [blame] | 17 | #include "PPCTargetTransformInfo.h" |
Andrew Trick | ccb6736 | 2012-02-03 05:12:41 +0000 | [diff] [blame] | 18 | #include "llvm/CodeGen/Passes.h" |
Eric Christopher | 3faf2f1 | 2014-10-06 06:45:36 +0000 | [diff] [blame] | 19 | #include "llvm/IR/Function.h" |
Chandler Carruth | 30d69c2 | 2015-02-13 10:01:29 +0000 | [diff] [blame] | 20 | #include "llvm/IR/LegacyPassManager.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 21 | #include "llvm/MC/MCStreamer.h" |
Hal Finkel | 96c2d4d | 2012-06-08 15:38:21 +0000 | [diff] [blame] | 22 | #include "llvm/Support/CommandLine.h" |
David Greene | a31f96c | 2009-07-14 20:18:05 +0000 | [diff] [blame] | 23 | #include "llvm/Support/FormattedStream.h" |
Evan Cheng | 2bb4035 | 2011-08-24 18:08:43 +0000 | [diff] [blame] | 24 | #include "llvm/Support/TargetRegistry.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 25 | #include "llvm/Target/TargetOptions.h" |
Hal Finkel | f413be1 | 2014-11-21 04:35:51 +0000 | [diff] [blame] | 26 | #include "llvm/Transforms/Scalar.h" |
Misha Brukman | e05203f | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 27 | using namespace llvm; |
| 28 | |
Hal Finkel | 96c2d4d | 2012-06-08 15:38:21 +0000 | [diff] [blame] | 29 | static cl:: |
Hal Finkel | c6b5deb | 2012-06-08 19:19:53 +0000 | [diff] [blame] | 30 | opt<bool> DisableCTRLoops("disable-ppc-ctrloops", cl::Hidden, |
| 31 | cl::desc("Disable CTR loops for PPC")); |
Hal Finkel | 96c2d4d | 2012-06-08 15:38:21 +0000 | [diff] [blame] | 32 | |
Hal Finkel | c9dd020 | 2015-02-05 18:43:00 +0000 | [diff] [blame] | 33 | static cl:: |
| 34 | opt<bool> DisablePreIncPrep("disable-ppc-preinc-prep", cl::Hidden, |
| 35 | cl::desc("Disable PPC loop preinc prep")); |
| 36 | |
Hal Finkel | 174e590 | 2014-03-25 23:29:21 +0000 | [diff] [blame] | 37 | static cl::opt<bool> |
| 38 | VSXFMAMutateEarly("schedule-ppc-vsx-fma-mutation-early", |
| 39 | cl::Hidden, cl::desc("Schedule VSX FMA instruction mutation early")); |
| 40 | |
Bill Schmidt | fe723b9 | 2015-04-27 19:57:34 +0000 | [diff] [blame] | 41 | static cl:: |
| 42 | opt<bool> DisableVSXSwapRemoval("disable-ppc-vsx-swap-removal", cl::Hidden, |
| 43 | cl::desc("Disable VSX Swap Removal for PPC")); |
| 44 | |
Bill Schmidt | 34af5e1 | 2015-11-10 21:38:26 +0000 | [diff] [blame^] | 45 | static cl:: |
| 46 | opt<bool> DisableMIPeephole("disable-ppc-peephole", cl::Hidden, |
| 47 | cl::desc("Disable machine peepholes for PPC")); |
| 48 | |
Hal Finkel | f413be1 | 2014-11-21 04:35:51 +0000 | [diff] [blame] | 49 | static cl::opt<bool> |
| 50 | EnableGEPOpt("ppc-gep-opt", cl::Hidden, |
| 51 | cl::desc("Enable optimizations on complex GEPs"), |
| 52 | cl::init(true)); |
| 53 | |
Hal Finkel | e5aaf3f | 2015-02-20 05:08:21 +0000 | [diff] [blame] | 54 | static cl::opt<bool> |
| 55 | EnablePrefetch("enable-ppc-prefetching", |
| 56 | cl::desc("disable software prefetching on PPC"), |
| 57 | cl::init(false), cl::Hidden); |
| 58 | |
Hal Finkel | 8340de1 | 2015-05-18 06:25:59 +0000 | [diff] [blame] | 59 | static cl::opt<bool> |
| 60 | EnableExtraTOCRegDeps("enable-ppc-extra-toc-reg-deps", |
| 61 | cl::desc("Add extra TOC register dependencies"), |
| 62 | cl::init(true), cl::Hidden); |
| 63 | |
Hal Finkel | 5d36b23 | 2015-07-15 08:23:05 +0000 | [diff] [blame] | 64 | static cl::opt<bool> |
| 65 | EnableMachineCombinerPass("ppc-machine-combiner", |
| 66 | cl::desc("Enable the machine combiner pass"), |
| 67 | cl::init(true), cl::Hidden); |
| 68 | |
Daniel Dunbar | 5680b4f | 2009-07-25 06:49:55 +0000 | [diff] [blame] | 69 | extern "C" void LLVMInitializePowerPCTarget() { |
| 70 | // Register the targets |
Andrew Trick | 808a7a6 | 2012-02-03 05:12:30 +0000 | [diff] [blame] | 71 | RegisterTargetMachine<PPC32TargetMachine> A(ThePPC32Target); |
Daniel Dunbar | 5680b4f | 2009-07-25 06:49:55 +0000 | [diff] [blame] | 72 | RegisterTargetMachine<PPC64TargetMachine> B(ThePPC64Target); |
Bill Schmidt | 0a9170d | 2013-07-26 01:35:43 +0000 | [diff] [blame] | 73 | RegisterTargetMachine<PPC64TargetMachine> C(ThePPC64LETarget); |
Daniel Dunbar | 5680b4f | 2009-07-25 06:49:55 +0000 | [diff] [blame] | 74 | } |
Douglas Gregor | 1b731d5 | 2009-06-16 20:12:29 +0000 | [diff] [blame] | 75 | |
Eric Christopher | 8b77065 | 2015-01-26 19:03:15 +0000 | [diff] [blame] | 76 | /// Return the datalayout string of a subtarget. |
| 77 | static std::string getDataLayoutString(const Triple &T) { |
| 78 | bool is64Bit = T.getArch() == Triple::ppc64 || T.getArch() == Triple::ppc64le; |
| 79 | std::string Ret; |
| 80 | |
| 81 | // Most PPC* platforms are big endian, PPC64LE is little endian. |
| 82 | if (T.getArch() == Triple::ppc64le) |
| 83 | Ret = "e"; |
| 84 | else |
| 85 | Ret = "E"; |
| 86 | |
| 87 | Ret += DataLayout::getManglingComponent(T); |
| 88 | |
| 89 | // PPC32 has 32 bit pointers. The PS3 (OS Lv2) is a PPC64 machine with 32 bit |
| 90 | // pointers. |
| 91 | if (!is64Bit || T.getOS() == Triple::Lv2) |
| 92 | Ret += "-p:32:32"; |
| 93 | |
| 94 | // Note, the alignment values for f64 and i64 on ppc64 in Darwin |
| 95 | // documentation are wrong; these are correct (i.e. "what gcc does"). |
| 96 | if (is64Bit || !T.isOSDarwin()) |
| 97 | Ret += "-i64:64"; |
| 98 | else |
| 99 | Ret += "-f64:32:64"; |
| 100 | |
| 101 | // PPC64 has 32 and 64 bit registers, PPC32 has only 32 bit ones. |
| 102 | if (is64Bit) |
| 103 | Ret += "-n32:64"; |
| 104 | else |
| 105 | Ret += "-n32"; |
| 106 | |
| 107 | return Ret; |
| 108 | } |
| 109 | |
Daniel Sanders | 335487a | 2015-06-16 13:15:50 +0000 | [diff] [blame] | 110 | static std::string computeFSAdditions(StringRef FS, CodeGenOpt::Level OL, |
| 111 | const Triple &TT) { |
Eric Christopher | 36448af | 2014-10-01 20:38:26 +0000 | [diff] [blame] | 112 | std::string FullFS = FS; |
Eric Christopher | 36448af | 2014-10-01 20:38:26 +0000 | [diff] [blame] | 113 | |
| 114 | // Make sure 64-bit features are available when CPUname is generic |
Daniel Sanders | 335487a | 2015-06-16 13:15:50 +0000 | [diff] [blame] | 115 | if (TT.getArch() == Triple::ppc64 || TT.getArch() == Triple::ppc64le) { |
Eric Christopher | 36448af | 2014-10-01 20:38:26 +0000 | [diff] [blame] | 116 | if (!FullFS.empty()) |
| 117 | FullFS = "+64bit," + FullFS; |
| 118 | else |
| 119 | FullFS = "+64bit"; |
| 120 | } |
| 121 | |
| 122 | if (OL >= CodeGenOpt::Default) { |
| 123 | if (!FullFS.empty()) |
| 124 | FullFS = "+crbits," + FullFS; |
| 125 | else |
| 126 | FullFS = "+crbits"; |
| 127 | } |
Hal Finkel | e2ab0f1 | 2015-01-15 21:17:34 +0000 | [diff] [blame] | 128 | |
| 129 | if (OL != CodeGenOpt::None) { |
NAKAMURA Takumi | 70ad98a | 2015-09-22 11:13:55 +0000 | [diff] [blame] | 130 | if (!FullFS.empty()) |
Hal Finkel | e2ab0f1 | 2015-01-15 21:17:34 +0000 | [diff] [blame] | 131 | FullFS = "+invariant-function-descriptors," + FullFS; |
| 132 | else |
| 133 | FullFS = "+invariant-function-descriptors"; |
| 134 | } |
| 135 | |
Eric Christopher | 36448af | 2014-10-01 20:38:26 +0000 | [diff] [blame] | 136 | return FullFS; |
| 137 | } |
| 138 | |
Aditya Nandakumar | a271932 | 2014-11-13 09:26:31 +0000 | [diff] [blame] | 139 | static std::unique_ptr<TargetLoweringObjectFile> createTLOF(const Triple &TT) { |
| 140 | // If it isn't a Mach-O file then it's going to be a linux ELF |
| 141 | // object file. |
| 142 | if (TT.isOSDarwin()) |
| 143 | return make_unique<TargetLoweringObjectFileMachO>(); |
| 144 | |
| 145 | return make_unique<PPC64LinuxTargetObjectFile>(); |
| 146 | } |
| 147 | |
Eric Christopher | fee6aaf | 2015-02-17 06:45:15 +0000 | [diff] [blame] | 148 | static PPCTargetMachine::PPCABI computeTargetABI(const Triple &TT, |
| 149 | const TargetOptions &Options) { |
| 150 | if (Options.MCOptions.getABIName().startswith("elfv1")) |
| 151 | return PPCTargetMachine::PPC_ABI_ELFv1; |
| 152 | else if (Options.MCOptions.getABIName().startswith("elfv2")) |
| 153 | return PPCTargetMachine::PPC_ABI_ELFv2; |
| 154 | |
| 155 | assert(Options.MCOptions.getABIName().empty() && |
NAKAMURA Takumi | 0a7d0ad | 2015-09-22 11:15:07 +0000 | [diff] [blame] | 156 | "Unknown target-abi option!"); |
Eric Christopher | fee6aaf | 2015-02-17 06:45:15 +0000 | [diff] [blame] | 157 | |
| 158 | if (!TT.isMacOSX()) { |
| 159 | switch (TT.getArch()) { |
| 160 | case Triple::ppc64le: |
| 161 | return PPCTargetMachine::PPC_ABI_ELFv2; |
| 162 | case Triple::ppc64: |
| 163 | return PPCTargetMachine::PPC_ABI_ELFv1; |
| 164 | default: |
| 165 | // Fallthrough. |
| 166 | ; |
| 167 | } |
| 168 | } |
| 169 | return PPCTargetMachine::PPC_ABI_UNKNOWN; |
| 170 | } |
| 171 | |
NAKAMURA Takumi | 8496503 | 2015-09-22 11:14:12 +0000 | [diff] [blame] | 172 | // The FeatureString here is a little subtle. We are modifying the feature |
| 173 | // string with what are (currently) non-function specific overrides as it goes |
| 174 | // into the LLVMTargetMachine constructor and then using the stored value in the |
Eric Christopher | 36448af | 2014-10-01 20:38:26 +0000 | [diff] [blame] | 175 | // Subtarget constructor below it. |
Daniel Sanders | 3e5de88 | 2015-06-11 19:41:26 +0000 | [diff] [blame] | 176 | PPCTargetMachine::PPCTargetMachine(const Target &T, const Triple &TT, |
| 177 | StringRef CPU, StringRef FS, |
| 178 | const TargetOptions &Options, |
Evan Cheng | efd9b42 | 2011-07-20 07:51:56 +0000 | [diff] [blame] | 179 | Reloc::Model RM, CodeModel::Model CM, |
Eric Christopher | 3770cf5 | 2014-08-09 04:38:56 +0000 | [diff] [blame] | 180 | CodeGenOpt::Level OL) |
Daniel Sanders | 3e5de88 | 2015-06-11 19:41:26 +0000 | [diff] [blame] | 181 | : LLVMTargetMachine(T, getDataLayoutString(TT), TT, CPU, |
Daniel Sanders | 335487a | 2015-06-16 13:15:50 +0000 | [diff] [blame] | 182 | computeFSAdditions(FS, OL, TT), Options, RM, CM, OL), |
Daniel Sanders | c81f450 | 2015-06-16 15:44:21 +0000 | [diff] [blame] | 183 | TLOF(createTLOF(getTargetTriple())), |
Hal Finkel | cbf0892 | 2015-07-12 02:33:57 +0000 | [diff] [blame] | 184 | TargetABI(computeTargetABI(TT, Options)), |
| 185 | Subtarget(TargetTriple, CPU, computeFSAdditions(FS, OL, TT), *this) { |
| 186 | |
| 187 | // For the estimates, convergence is quadratic, so we essentially double the |
| 188 | // number of digits correct after every iteration. For both FRE and FRSQRTE, |
| 189 | // the minimum architected relative accuracy is 2^-5. When hasRecipPrec(), |
| 190 | // this is 2^-14. IEEE float has 23 digits and double has 52 digits. |
| 191 | unsigned RefinementSteps = Subtarget.hasRecipPrec() ? 1 : 3, |
| 192 | RefinementSteps64 = RefinementSteps + 1; |
| 193 | |
| 194 | this->Options.Reciprocals.setDefaults("sqrtf", true, RefinementSteps); |
| 195 | this->Options.Reciprocals.setDefaults("vec-sqrtf", true, RefinementSteps); |
| 196 | this->Options.Reciprocals.setDefaults("divf", true, RefinementSteps); |
| 197 | this->Options.Reciprocals.setDefaults("vec-divf", true, RefinementSteps); |
| 198 | |
| 199 | this->Options.Reciprocals.setDefaults("sqrtd", true, RefinementSteps64); |
| 200 | this->Options.Reciprocals.setDefaults("vec-sqrtd", true, RefinementSteps64); |
| 201 | this->Options.Reciprocals.setDefaults("divd", true, RefinementSteps64); |
| 202 | this->Options.Reciprocals.setDefaults("vec-divd", true, RefinementSteps64); |
| 203 | |
Rafael Espindola | 227144c | 2013-05-13 01:16:13 +0000 | [diff] [blame] | 204 | initAsmInfo(); |
Nate Begeman | 6cca84e | 2005-10-16 05:39:50 +0000 | [diff] [blame] | 205 | } |
| 206 | |
Reid Kleckner | 357600e | 2014-11-20 23:37:18 +0000 | [diff] [blame] | 207 | PPCTargetMachine::~PPCTargetMachine() {} |
| 208 | |
David Blaikie | a379b181 | 2011-12-20 02:50:00 +0000 | [diff] [blame] | 209 | void PPC32TargetMachine::anchor() { } |
| 210 | |
Daniel Sanders | 3e5de88 | 2015-06-11 19:41:26 +0000 | [diff] [blame] | 211 | PPC32TargetMachine::PPC32TargetMachine(const Target &T, const Triple &TT, |
Evan Cheng | efd9b42 | 2011-07-20 07:51:56 +0000 | [diff] [blame] | 212 | StringRef CPU, StringRef FS, |
Nick Lewycky | 50f02cb | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 213 | const TargetOptions &Options, |
Evan Cheng | ecb2908 | 2011-11-16 08:38:26 +0000 | [diff] [blame] | 214 | Reloc::Model RM, CodeModel::Model CM, |
| 215 | CodeGenOpt::Level OL) |
Daniel Sanders | 3e5de88 | 2015-06-11 19:41:26 +0000 | [diff] [blame] | 216 | : PPCTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL) {} |
Chris Lattner | 0c4aa14 | 2006-06-16 01:37:27 +0000 | [diff] [blame] | 217 | |
David Blaikie | a379b181 | 2011-12-20 02:50:00 +0000 | [diff] [blame] | 218 | void PPC64TargetMachine::anchor() { } |
Chris Lattner | 0c4aa14 | 2006-06-16 01:37:27 +0000 | [diff] [blame] | 219 | |
Daniel Sanders | 3e5de88 | 2015-06-11 19:41:26 +0000 | [diff] [blame] | 220 | PPC64TargetMachine::PPC64TargetMachine(const Target &T, const Triple &TT, |
| 221 | StringRef CPU, StringRef FS, |
Nick Lewycky | 50f02cb | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 222 | const TargetOptions &Options, |
Evan Cheng | ecb2908 | 2011-11-16 08:38:26 +0000 | [diff] [blame] | 223 | Reloc::Model RM, CodeModel::Model CM, |
| 224 | CodeGenOpt::Level OL) |
Daniel Sanders | 3e5de88 | 2015-06-11 19:41:26 +0000 | [diff] [blame] | 225 | : PPCTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL) {} |
Chris Lattner | 0c4aa14 | 2006-06-16 01:37:27 +0000 | [diff] [blame] | 226 | |
Eric Christopher | 3faf2f1 | 2014-10-06 06:45:36 +0000 | [diff] [blame] | 227 | const PPCSubtarget * |
| 228 | PPCTargetMachine::getSubtargetImpl(const Function &F) const { |
Duncan P. N. Exon Smith | 5bedaf93 | 2015-02-14 02:54:07 +0000 | [diff] [blame] | 229 | Attribute CPUAttr = F.getFnAttribute("target-cpu"); |
| 230 | Attribute FSAttr = F.getFnAttribute("target-features"); |
Eric Christopher | 3faf2f1 | 2014-10-06 06:45:36 +0000 | [diff] [blame] | 231 | |
| 232 | std::string CPU = !CPUAttr.hasAttribute(Attribute::None) |
| 233 | ? CPUAttr.getValueAsString().str() |
| 234 | : TargetCPU; |
| 235 | std::string FS = !FSAttr.hasAttribute(Attribute::None) |
| 236 | ? FSAttr.getValueAsString().str() |
| 237 | : TargetFS; |
| 238 | |
| 239 | auto &I = SubtargetMap[CPU + FS]; |
| 240 | if (!I) { |
| 241 | // This needs to be done before we create a new subtarget since any |
| 242 | // creation will depend on the TM and the code generation flags on the |
| 243 | // function that reside in TargetOptions. |
| 244 | resetTargetOptions(F); |
Eric Christopher | ed1042b | 2015-03-26 00:50:23 +0000 | [diff] [blame] | 245 | I = llvm::make_unique<PPCSubtarget>( |
Daniel Sanders | c81f450 | 2015-06-16 15:44:21 +0000 | [diff] [blame] | 246 | TargetTriple, CPU, |
Eric Christopher | ed1042b | 2015-03-26 00:50:23 +0000 | [diff] [blame] | 247 | // FIXME: It would be good to have the subtarget additions here |
| 248 | // not necessary. Anything that turns them on/off (overrides) ends |
| 249 | // up being put at the end of the feature string, but the defaults |
| 250 | // shouldn't require adding them. Fixing this means pulling Feature64Bit |
| 251 | // out of most of the target cpus in the .td file and making it set only |
| 252 | // as part of initialization via the TargetTriple. |
| 253 | computeFSAdditions(FS, getOptLevel(), getTargetTriple()), *this); |
Eric Christopher | 3faf2f1 | 2014-10-06 06:45:36 +0000 | [diff] [blame] | 254 | } |
| 255 | return I.get(); |
| 256 | } |
Misha Brukman | b440243 | 2005-04-21 23:30:14 +0000 | [diff] [blame] | 257 | |
Chris Lattner | 12e9730 | 2006-09-04 04:14:57 +0000 | [diff] [blame] | 258 | //===----------------------------------------------------------------------===// |
| 259 | // Pass Pipeline Configuration |
| 260 | //===----------------------------------------------------------------------===// |
Nate Begeman | f17ea0f | 2004-08-11 07:40:04 +0000 | [diff] [blame] | 261 | |
Andrew Trick | ccb6736 | 2012-02-03 05:12:41 +0000 | [diff] [blame] | 262 | namespace { |
| 263 | /// PPC Code Generator Pass Configuration Options. |
| 264 | class PPCPassConfig : public TargetPassConfig { |
| 265 | public: |
Andrew Trick | f8ea108 | 2012-02-04 02:56:59 +0000 | [diff] [blame] | 266 | PPCPassConfig(PPCTargetMachine *TM, PassManagerBase &PM) |
| 267 | : TargetPassConfig(TM, PM) {} |
Andrew Trick | ccb6736 | 2012-02-03 05:12:41 +0000 | [diff] [blame] | 268 | |
| 269 | PPCTargetMachine &getPPCTargetMachine() const { |
| 270 | return getTM<PPCTargetMachine>(); |
| 271 | } |
| 272 | |
Robin Morisset | 2212996 | 2014-09-23 20:46:49 +0000 | [diff] [blame] | 273 | void addIRPasses() override; |
Craig Topper | 0d3fa92 | 2014-04-29 07:57:37 +0000 | [diff] [blame] | 274 | bool addPreISel() override; |
| 275 | bool addILPOpts() override; |
| 276 | bool addInstSelector() override; |
Bill Schmidt | fe723b9 | 2015-04-27 19:57:34 +0000 | [diff] [blame] | 277 | void addMachineSSAOptimization() override; |
Matthias Braun | 7e37a5f | 2014-12-11 21:26:47 +0000 | [diff] [blame] | 278 | void addPreRegAlloc() override; |
| 279 | void addPreSched2() override; |
| 280 | void addPreEmitPass() override; |
Andrew Trick | ccb6736 | 2012-02-03 05:12:41 +0000 | [diff] [blame] | 281 | }; |
| 282 | } // namespace |
| 283 | |
Andrew Trick | f8ea108 | 2012-02-04 02:56:59 +0000 | [diff] [blame] | 284 | TargetPassConfig *PPCTargetMachine::createPassConfig(PassManagerBase &PM) { |
Hal Finkel | eb50c2d | 2012-06-09 03:14:50 +0000 | [diff] [blame] | 285 | return new PPCPassConfig(this, PM); |
Andrew Trick | ccb6736 | 2012-02-03 05:12:41 +0000 | [diff] [blame] | 286 | } |
| 287 | |
Robin Morisset | 2212996 | 2014-09-23 20:46:49 +0000 | [diff] [blame] | 288 | void PPCPassConfig::addIRPasses() { |
| 289 | addPass(createAtomicExpandPass(&getPPCTargetMachine())); |
Hal Finkel | f413be1 | 2014-11-21 04:35:51 +0000 | [diff] [blame] | 290 | |
Hal Finkel | e5aaf3f | 2015-02-20 05:08:21 +0000 | [diff] [blame] | 291 | // For the BG/Q (or if explicitly requested), add explicit data prefetch |
| 292 | // intrinsics. |
Daniel Sanders | c81f450 | 2015-06-16 15:44:21 +0000 | [diff] [blame] | 293 | bool UsePrefetching = TM->getTargetTriple().getVendor() == Triple::BGQ && |
| 294 | getOptLevel() != CodeGenOpt::None; |
Hal Finkel | e5aaf3f | 2015-02-20 05:08:21 +0000 | [diff] [blame] | 295 | if (EnablePrefetch.getNumOccurrences() > 0) |
| 296 | UsePrefetching = EnablePrefetch; |
| 297 | if (UsePrefetching) |
| 298 | addPass(createPPCLoopDataPrefetchPass()); |
| 299 | |
Hal Finkel | f413be1 | 2014-11-21 04:35:51 +0000 | [diff] [blame] | 300 | if (TM->getOptLevel() == CodeGenOpt::Aggressive && EnableGEPOpt) { |
| 301 | // Call SeparateConstOffsetFromGEP pass to extract constants within indices |
| 302 | // and lower a GEP with multiple indices to either arithmetic operations or |
| 303 | // multiple GEPs with single index. |
| 304 | addPass(createSeparateConstOffsetFromGEPPass(TM, true)); |
| 305 | // Call EarlyCSE pass to find and remove subexpressions in the lowered |
| 306 | // result. |
| 307 | addPass(createEarlyCSEPass()); |
| 308 | // Do loop invariant code motion in case part of the lowered result is |
| 309 | // invariant. |
| 310 | addPass(createLICMPass()); |
| 311 | } |
| 312 | |
Robin Morisset | 2212996 | 2014-09-23 20:46:49 +0000 | [diff] [blame] | 313 | TargetPassConfig::addIRPasses(); |
| 314 | } |
| 315 | |
Hal Finkel | 25c1992 | 2013-05-15 21:37:41 +0000 | [diff] [blame] | 316 | bool PPCPassConfig::addPreISel() { |
Hal Finkel | c9dd020 | 2015-02-05 18:43:00 +0000 | [diff] [blame] | 317 | if (!DisablePreIncPrep && getOptLevel() != CodeGenOpt::None) |
| 318 | addPass(createPPCLoopPreIncPrepPass(getPPCTargetMachine())); |
| 319 | |
Hal Finkel | c6b5deb | 2012-06-08 19:19:53 +0000 | [diff] [blame] | 320 | if (!DisableCTRLoops && getOptLevel() != CodeGenOpt::None) |
Hal Finkel | 25c1992 | 2013-05-15 21:37:41 +0000 | [diff] [blame] | 321 | addPass(createPPCCTRLoops(getPPCTargetMachine())); |
Hal Finkel | 96c2d4d | 2012-06-08 15:38:21 +0000 | [diff] [blame] | 322 | |
| 323 | return false; |
| 324 | } |
| 325 | |
Hal Finkel | ed6a285 | 2013-04-05 23:29:01 +0000 | [diff] [blame] | 326 | bool PPCPassConfig::addILPOpts() { |
Eric Christopher | 6b0fcfe | 2014-05-21 23:40:26 +0000 | [diff] [blame] | 327 | addPass(&EarlyIfConverterID); |
Hal Finkel | 5d36b23 | 2015-07-15 08:23:05 +0000 | [diff] [blame] | 328 | |
| 329 | if (EnableMachineCombinerPass) |
| 330 | addPass(&MachineCombinerID); |
| 331 | |
Eric Christopher | 6b0fcfe | 2014-05-21 23:40:26 +0000 | [diff] [blame] | 332 | return true; |
Hal Finkel | ed6a285 | 2013-04-05 23:29:01 +0000 | [diff] [blame] | 333 | } |
| 334 | |
Andrew Trick | ccb6736 | 2012-02-03 05:12:41 +0000 | [diff] [blame] | 335 | bool PPCPassConfig::addInstSelector() { |
Chris Lattner | c6aa806 | 2005-08-17 19:33:30 +0000 | [diff] [blame] | 336 | // Install an instruction selector. |
Bob Wilson | bbd38dd | 2012-07-02 19:48:31 +0000 | [diff] [blame] | 337 | addPass(createPPCISelDag(getPPCTargetMachine())); |
Hal Finkel | 8ca3884 | 2013-05-20 16:08:17 +0000 | [diff] [blame] | 338 | |
| 339 | #ifndef NDEBUG |
| 340 | if (!DisableCTRLoops && getOptLevel() != CodeGenOpt::None) |
| 341 | addPass(createPPCCTRLoopsVerify()); |
| 342 | #endif |
| 343 | |
Eric Christopher | d71e444 | 2014-05-22 01:21:35 +0000 | [diff] [blame] | 344 | addPass(createPPCVSXCopyPass()); |
Nate Begeman | f17ea0f | 2004-08-11 07:40:04 +0000 | [diff] [blame] | 345 | return false; |
| 346 | } |
| 347 | |
Bill Schmidt | fe723b9 | 2015-04-27 19:57:34 +0000 | [diff] [blame] | 348 | void PPCPassConfig::addMachineSSAOptimization() { |
| 349 | TargetPassConfig::addMachineSSAOptimization(); |
| 350 | // For little endian, remove where possible the vector swap instructions |
| 351 | // introduced at code generation to normalize vector element order. |
Daniel Sanders | c81f450 | 2015-06-16 15:44:21 +0000 | [diff] [blame] | 352 | if (TM->getTargetTriple().getArch() == Triple::ppc64le && |
Bill Schmidt | fe723b9 | 2015-04-27 19:57:34 +0000 | [diff] [blame] | 353 | !DisableVSXSwapRemoval) |
| 354 | addPass(createPPCVSXSwapRemovalPass()); |
Bill Schmidt | 34af5e1 | 2015-11-10 21:38:26 +0000 | [diff] [blame^] | 355 | // Target-specific peephole cleanups performed after instruction |
| 356 | // selection. |
| 357 | if (!DisableMIPeephole) { |
| 358 | addPass(createPPCMIPeepholePass()); |
| 359 | addPass(&DeadMachineInstructionElimID); |
| 360 | } |
Bill Schmidt | fe723b9 | 2015-04-27 19:57:34 +0000 | [diff] [blame] | 361 | } |
| 362 | |
Matthias Braun | 7e37a5f | 2014-12-11 21:26:47 +0000 | [diff] [blame] | 363 | void PPCPassConfig::addPreRegAlloc() { |
Eric Christopher | d71e444 | 2014-05-22 01:21:35 +0000 | [diff] [blame] | 364 | initializePPCVSXFMAMutatePass(*PassRegistry::getPassRegistry()); |
| 365 | insertPass(VSXFMAMutateEarly ? &RegisterCoalescerID : &MachineSchedulerID, |
| 366 | &PPCVSXFMAMutateID); |
Bill Schmidt | 82f1c77 | 2015-02-10 19:09:05 +0000 | [diff] [blame] | 367 | if (getPPCTargetMachine().getRelocationModel() == Reloc::PIC_) |
| 368 | addPass(createPPCTLSDynamicCallPass()); |
Hal Finkel | 8340de1 | 2015-05-18 06:25:59 +0000 | [diff] [blame] | 369 | if (EnableExtraTOCRegDeps) |
| 370 | addPass(createPPCTOCRegDepsPass()); |
Hal Finkel | 174e590 | 2014-03-25 23:29:21 +0000 | [diff] [blame] | 371 | } |
| 372 | |
Matthias Braun | 7e37a5f | 2014-12-11 21:26:47 +0000 | [diff] [blame] | 373 | void PPCPassConfig::addPreSched2() { |
Hal Finkel | 5711eca | 2013-04-09 22:58:37 +0000 | [diff] [blame] | 374 | if (getOptLevel() != CodeGenOpt::None) |
| 375 | addPass(&IfConverterID); |
Hal Finkel | 5711eca | 2013-04-09 22:58:37 +0000 | [diff] [blame] | 376 | } |
| 377 | |
Matthias Braun | 7e37a5f | 2014-12-11 21:26:47 +0000 | [diff] [blame] | 378 | void PPCPassConfig::addPreEmitPass() { |
Hal Finkel | b5aa7e5 | 2013-04-08 16:24:03 +0000 | [diff] [blame] | 379 | if (getOptLevel() != CodeGenOpt::None) |
Matthias Braun | 7e37a5f | 2014-12-11 21:26:47 +0000 | [diff] [blame] | 380 | addPass(createPPCEarlyReturnPass(), false); |
Chris Lattner | 12e9730 | 2006-09-04 04:14:57 +0000 | [diff] [blame] | 381 | // Must run branch selection immediately preceding the asm printer. |
Matthias Braun | 7e37a5f | 2014-12-11 21:26:47 +0000 | [diff] [blame] | 382 | addPass(createPPCBranchSelectionPass(), false); |
Chris Lattner | 12e9730 | 2006-09-04 04:14:57 +0000 | [diff] [blame] | 383 | } |
| 384 | |
Chandler Carruth | 8b04c0d | 2015-02-01 13:20:00 +0000 | [diff] [blame] | 385 | TargetIRAnalysis PPCTargetMachine::getTargetIRAnalysis() { |
Eric Christopher | a4e5d3c | 2015-09-16 23:38:13 +0000 | [diff] [blame] | 386 | return TargetIRAnalysis([this](const Function &F) { |
| 387 | return TargetTransformInfo(PPCTTIImpl(this, F)); |
| 388 | }); |
Hal Finkel | 4e5ca9e | 2013-01-25 23:05:59 +0000 | [diff] [blame] | 389 | } |