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