blob: fc8b41606f5074b85191a9909e0fae523d6d6e06 [file] [log] [blame]
Nate Begeman6cca84e2005-10-16 05:39:50 +00001//===-- PPCTargetMachine.cpp - Define TargetMachine for PowerPC -----------===//
Misha Brukmanb4402432005-04-21 23:30:14 +00002//
Misha Brukmane05203f2004-06-21 16:55:25 +00003// The LLVM Compiler Infrastructure
4//
Chris Lattnerf3ebc3f2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Misha Brukmanb4402432005-04-21 23:30:14 +00007//
Misha Brukmane05203f2004-06-21 16:55:25 +00008//===----------------------------------------------------------------------===//
Misha Brukmanb4402432005-04-21 23:30:14 +00009//
Chris Lattner73785d22005-08-15 23:47:04 +000010// Top-level implementation for the PowerPC target.
Misha Brukmane05203f2004-06-21 16:55:25 +000011//
12//===----------------------------------------------------------------------===//
13
Chris Lattner6f3b9542005-10-14 23:59:06 +000014#include "PPCTargetMachine.h"
Craig Topperb25fda92012-03-17 18:46:09 +000015#include "PPC.h"
Chandler Carruthd9903882015-01-14 11:23:27 +000016#include "PPCTargetObjectFile.h"
Chandler Carruth93dcdc42015-01-31 11:17:59 +000017#include "PPCTargetTransformInfo.h"
Matthias Braunf84547c2016-04-28 23:42:51 +000018#include "llvm/CodeGen/LiveVariables.h"
Andrew Trickccb67362012-02-03 05:12:41 +000019#include "llvm/CodeGen/Passes.h"
Matthias Braun31d19d42016-05-10 03:21:59 +000020#include "llvm/CodeGen/TargetPassConfig.h"
Eric Christopher3faf2f12014-10-06 06:45:36 +000021#include "llvm/IR/Function.h"
Chandler Carruth30d69c22015-02-13 10:01:29 +000022#include "llvm/IR/LegacyPassManager.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000023#include "llvm/MC/MCStreamer.h"
Hal Finkel96c2d4d2012-06-08 15:38:21 +000024#include "llvm/Support/CommandLine.h"
David Greenea31f96c2009-07-14 20:18:05 +000025#include "llvm/Support/FormattedStream.h"
Evan Cheng2bb40352011-08-24 18:08:43 +000026#include "llvm/Support/TargetRegistry.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000027#include "llvm/Target/TargetOptions.h"
Hal Finkelf413be12014-11-21 04:35:51 +000028#include "llvm/Transforms/Scalar.h"
Misha Brukmane05203f2004-06-21 16:55:25 +000029using namespace llvm;
30
Hal Finkel96c2d4d2012-06-08 15:38:21 +000031static cl::
Hal Finkelc6b5deb2012-06-08 19:19:53 +000032opt<bool> DisableCTRLoops("disable-ppc-ctrloops", cl::Hidden,
33 cl::desc("Disable CTR loops for PPC"));
Hal Finkel96c2d4d2012-06-08 15:38:21 +000034
Hal Finkelc9dd0202015-02-05 18:43:00 +000035static cl::
36opt<bool> DisablePreIncPrep("disable-ppc-preinc-prep", cl::Hidden,
37 cl::desc("Disable PPC loop preinc prep"));
38
Hal Finkel174e5902014-03-25 23:29:21 +000039static cl::opt<bool>
40VSXFMAMutateEarly("schedule-ppc-vsx-fma-mutation-early",
41 cl::Hidden, cl::desc("Schedule VSX FMA instruction mutation early"));
42
Bill Schmidtfe723b92015-04-27 19:57:34 +000043static cl::
44opt<bool> DisableVSXSwapRemoval("disable-ppc-vsx-swap-removal", cl::Hidden,
45 cl::desc("Disable VSX Swap Removal for PPC"));
46
Bill Schmidt34af5e12015-11-10 21:38:26 +000047static cl::
Hal Finkelfc353912016-03-31 20:39:41 +000048opt<bool> DisableQPXLoadSplat("disable-ppc-qpx-load-splat", cl::Hidden,
49 cl::desc("Disable QPX load splat simplification"));
50
51static cl::
Bill Schmidt34af5e12015-11-10 21:38:26 +000052opt<bool> DisableMIPeephole("disable-ppc-peephole", cl::Hidden,
53 cl::desc("Disable machine peepholes for PPC"));
54
Hal Finkelf413be12014-11-21 04:35:51 +000055static cl::opt<bool>
56EnableGEPOpt("ppc-gep-opt", cl::Hidden,
57 cl::desc("Enable optimizations on complex GEPs"),
58 cl::init(true));
59
Hal Finkele5aaf3f2015-02-20 05:08:21 +000060static cl::opt<bool>
61EnablePrefetch("enable-ppc-prefetching",
62 cl::desc("disable software prefetching on PPC"),
63 cl::init(false), cl::Hidden);
64
Hal Finkel8340de12015-05-18 06:25:59 +000065static cl::opt<bool>
66EnableExtraTOCRegDeps("enable-ppc-extra-toc-reg-deps",
67 cl::desc("Add extra TOC register dependencies"),
68 cl::init(true), cl::Hidden);
69
Hal Finkel5d36b232015-07-15 08:23:05 +000070static cl::opt<bool>
71EnableMachineCombinerPass("ppc-machine-combiner",
72 cl::desc("Enable the machine combiner pass"),
73 cl::init(true), cl::Hidden);
74
Daniel Dunbar5680b4f2009-07-25 06:49:55 +000075extern "C" void LLVMInitializePowerPCTarget() {
76 // Register the targets
Andrew Trick808a7a62012-02-03 05:12:30 +000077 RegisterTargetMachine<PPC32TargetMachine> A(ThePPC32Target);
Daniel Dunbar5680b4f2009-07-25 06:49:55 +000078 RegisterTargetMachine<PPC64TargetMachine> B(ThePPC64Target);
Bill Schmidt0a9170d2013-07-26 01:35:43 +000079 RegisterTargetMachine<PPC64TargetMachine> C(ThePPC64LETarget);
Kit Bartona1c712f2015-12-07 20:50:29 +000080
81 PassRegistry &PR = *PassRegistry::getPassRegistry();
82 initializePPCBoolRetToIntPass(PR);
Daniel Dunbar5680b4f2009-07-25 06:49:55 +000083}
Douglas Gregor1b731d52009-06-16 20:12:29 +000084
Eric Christopher8b770652015-01-26 19:03:15 +000085/// Return the datalayout string of a subtarget.
86static std::string getDataLayoutString(const Triple &T) {
87 bool is64Bit = T.getArch() == Triple::ppc64 || T.getArch() == Triple::ppc64le;
88 std::string Ret;
89
90 // Most PPC* platforms are big endian, PPC64LE is little endian.
91 if (T.getArch() == Triple::ppc64le)
92 Ret = "e";
93 else
94 Ret = "E";
95
96 Ret += DataLayout::getManglingComponent(T);
97
98 // PPC32 has 32 bit pointers. The PS3 (OS Lv2) is a PPC64 machine with 32 bit
99 // pointers.
100 if (!is64Bit || T.getOS() == Triple::Lv2)
101 Ret += "-p:32:32";
102
103 // Note, the alignment values for f64 and i64 on ppc64 in Darwin
104 // documentation are wrong; these are correct (i.e. "what gcc does").
105 if (is64Bit || !T.isOSDarwin())
106 Ret += "-i64:64";
107 else
108 Ret += "-f64:32:64";
109
110 // PPC64 has 32 and 64 bit registers, PPC32 has only 32 bit ones.
111 if (is64Bit)
112 Ret += "-n32:64";
113 else
114 Ret += "-n32";
115
116 return Ret;
117}
118
Daniel Sanders335487a2015-06-16 13:15:50 +0000119static std::string computeFSAdditions(StringRef FS, CodeGenOpt::Level OL,
120 const Triple &TT) {
Eric Christopher36448af2014-10-01 20:38:26 +0000121 std::string FullFS = FS;
Eric Christopher36448af2014-10-01 20:38:26 +0000122
123 // Make sure 64-bit features are available when CPUname is generic
Daniel Sanders335487a2015-06-16 13:15:50 +0000124 if (TT.getArch() == Triple::ppc64 || TT.getArch() == Triple::ppc64le) {
Eric Christopher36448af2014-10-01 20:38:26 +0000125 if (!FullFS.empty())
126 FullFS = "+64bit," + FullFS;
127 else
128 FullFS = "+64bit";
129 }
130
131 if (OL >= CodeGenOpt::Default) {
132 if (!FullFS.empty())
133 FullFS = "+crbits," + FullFS;
134 else
135 FullFS = "+crbits";
136 }
Hal Finkele2ab0f12015-01-15 21:17:34 +0000137
138 if (OL != CodeGenOpt::None) {
NAKAMURA Takumi70ad98a2015-09-22 11:13:55 +0000139 if (!FullFS.empty())
Hal Finkele2ab0f12015-01-15 21:17:34 +0000140 FullFS = "+invariant-function-descriptors," + FullFS;
141 else
142 FullFS = "+invariant-function-descriptors";
143 }
144
Eric Christopher36448af2014-10-01 20:38:26 +0000145 return FullFS;
146}
147
Aditya Nandakumara2719322014-11-13 09:26:31 +0000148static std::unique_ptr<TargetLoweringObjectFile> createTLOF(const Triple &TT) {
149 // If it isn't a Mach-O file then it's going to be a linux ELF
150 // object file.
151 if (TT.isOSDarwin())
152 return make_unique<TargetLoweringObjectFileMachO>();
153
154 return make_unique<PPC64LinuxTargetObjectFile>();
155}
156
Eric Christopherfee6aaf2015-02-17 06:45:15 +0000157static PPCTargetMachine::PPCABI computeTargetABI(const Triple &TT,
158 const TargetOptions &Options) {
159 if (Options.MCOptions.getABIName().startswith("elfv1"))
160 return PPCTargetMachine::PPC_ABI_ELFv1;
161 else if (Options.MCOptions.getABIName().startswith("elfv2"))
162 return PPCTargetMachine::PPC_ABI_ELFv2;
163
164 assert(Options.MCOptions.getABIName().empty() &&
NAKAMURA Takumi0a7d0ad2015-09-22 11:15:07 +0000165 "Unknown target-abi option!");
Eric Christopherfee6aaf2015-02-17 06:45:15 +0000166
167 if (!TT.isMacOSX()) {
168 switch (TT.getArch()) {
169 case Triple::ppc64le:
170 return PPCTargetMachine::PPC_ABI_ELFv2;
171 case Triple::ppc64:
172 return PPCTargetMachine::PPC_ABI_ELFv1;
173 default:
174 // Fallthrough.
175 ;
176 }
177 }
178 return PPCTargetMachine::PPC_ABI_UNKNOWN;
179}
180
NAKAMURA Takumi84965032015-09-22 11:14:12 +0000181// The FeatureString here is a little subtle. We are modifying the feature
182// string with what are (currently) non-function specific overrides as it goes
183// into the LLVMTargetMachine constructor and then using the stored value in the
Eric Christopher36448af2014-10-01 20:38:26 +0000184// Subtarget constructor below it.
Daniel Sanders3e5de882015-06-11 19:41:26 +0000185PPCTargetMachine::PPCTargetMachine(const Target &T, const Triple &TT,
186 StringRef CPU, StringRef FS,
187 const TargetOptions &Options,
Evan Chengefd9b422011-07-20 07:51:56 +0000188 Reloc::Model RM, CodeModel::Model CM,
Eric Christopher3770cf52014-08-09 04:38:56 +0000189 CodeGenOpt::Level OL)
Daniel Sanders3e5de882015-06-11 19:41:26 +0000190 : LLVMTargetMachine(T, getDataLayoutString(TT), TT, CPU,
Daniel Sanders335487a2015-06-16 13:15:50 +0000191 computeFSAdditions(FS, OL, TT), Options, RM, CM, OL),
Daniel Sandersc81f4502015-06-16 15:44:21 +0000192 TLOF(createTLOF(getTargetTriple())),
Hal Finkelcbf08922015-07-12 02:33:57 +0000193 TargetABI(computeTargetABI(TT, Options)),
194 Subtarget(TargetTriple, CPU, computeFSAdditions(FS, OL, TT), *this) {
195
196 // For the estimates, convergence is quadratic, so we essentially double the
197 // number of digits correct after every iteration. For both FRE and FRSQRTE,
198 // the minimum architected relative accuracy is 2^-5. When hasRecipPrec(),
199 // this is 2^-14. IEEE float has 23 digits and double has 52 digits.
200 unsigned RefinementSteps = Subtarget.hasRecipPrec() ? 1 : 3,
201 RefinementSteps64 = RefinementSteps + 1;
202
203 this->Options.Reciprocals.setDefaults("sqrtf", true, RefinementSteps);
204 this->Options.Reciprocals.setDefaults("vec-sqrtf", true, RefinementSteps);
205 this->Options.Reciprocals.setDefaults("divf", true, RefinementSteps);
206 this->Options.Reciprocals.setDefaults("vec-divf", true, RefinementSteps);
207
208 this->Options.Reciprocals.setDefaults("sqrtd", true, RefinementSteps64);
209 this->Options.Reciprocals.setDefaults("vec-sqrtd", true, RefinementSteps64);
210 this->Options.Reciprocals.setDefaults("divd", true, RefinementSteps64);
211 this->Options.Reciprocals.setDefaults("vec-divd", true, RefinementSteps64);
212
Rafael Espindola227144c2013-05-13 01:16:13 +0000213 initAsmInfo();
Nate Begeman6cca84e2005-10-16 05:39:50 +0000214}
215
Reid Kleckner357600e2014-11-20 23:37:18 +0000216PPCTargetMachine::~PPCTargetMachine() {}
217
David Blaikiea379b1812011-12-20 02:50:00 +0000218void PPC32TargetMachine::anchor() { }
219
Daniel Sanders3e5de882015-06-11 19:41:26 +0000220PPC32TargetMachine::PPC32TargetMachine(const Target &T, const Triple &TT,
Evan Chengefd9b422011-07-20 07:51:56 +0000221 StringRef CPU, StringRef FS,
Nick Lewycky50f02cb2011-12-02 22:16:29 +0000222 const TargetOptions &Options,
Evan Chengecb29082011-11-16 08:38:26 +0000223 Reloc::Model RM, CodeModel::Model CM,
224 CodeGenOpt::Level OL)
Daniel Sanders3e5de882015-06-11 19:41:26 +0000225 : PPCTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL) {}
Chris Lattner0c4aa142006-06-16 01:37:27 +0000226
David Blaikiea379b1812011-12-20 02:50:00 +0000227void PPC64TargetMachine::anchor() { }
Chris Lattner0c4aa142006-06-16 01:37:27 +0000228
Daniel Sanders3e5de882015-06-11 19:41:26 +0000229PPC64TargetMachine::PPC64TargetMachine(const Target &T, const Triple &TT,
230 StringRef CPU, StringRef FS,
Nick Lewycky50f02cb2011-12-02 22:16:29 +0000231 const TargetOptions &Options,
Evan Chengecb29082011-11-16 08:38:26 +0000232 Reloc::Model RM, CodeModel::Model CM,
233 CodeGenOpt::Level OL)
Daniel Sanders3e5de882015-06-11 19:41:26 +0000234 : PPCTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL) {}
Chris Lattner0c4aa142006-06-16 01:37:27 +0000235
Eric Christopher3faf2f12014-10-06 06:45:36 +0000236const PPCSubtarget *
237PPCTargetMachine::getSubtargetImpl(const Function &F) const {
Duncan P. N. Exon Smith5bedaf932015-02-14 02:54:07 +0000238 Attribute CPUAttr = F.getFnAttribute("target-cpu");
239 Attribute FSAttr = F.getFnAttribute("target-features");
Eric Christopher3faf2f12014-10-06 06:45:36 +0000240
241 std::string CPU = !CPUAttr.hasAttribute(Attribute::None)
242 ? CPUAttr.getValueAsString().str()
243 : TargetCPU;
244 std::string FS = !FSAttr.hasAttribute(Attribute::None)
245 ? FSAttr.getValueAsString().str()
246 : TargetFS;
247
Petar Jovanovic280f7102015-12-14 17:57:33 +0000248 // FIXME: This is related to the code below to reset the target options,
249 // we need to know whether or not the soft float flag is set on the
250 // function before we can generate a subtarget. We also need to use
251 // it as a key for the subtarget since that can be the only difference
252 // between two functions.
253 bool SoftFloat =
Nirav Dave8dd66e52016-03-30 15:41:12 +0000254 F.getFnAttribute("use-soft-float").getValueAsString() == "true";
Petar Jovanovic280f7102015-12-14 17:57:33 +0000255 // If the soft float attribute is set on the function turn on the soft float
256 // subtarget feature.
257 if (SoftFloat)
258 FS += FS.empty() ? "+soft-float" : ",+soft-float";
259
Eric Christopher3faf2f12014-10-06 06:45:36 +0000260 auto &I = SubtargetMap[CPU + FS];
261 if (!I) {
262 // This needs to be done before we create a new subtarget since any
263 // creation will depend on the TM and the code generation flags on the
264 // function that reside in TargetOptions.
265 resetTargetOptions(F);
Eric Christophered1042b2015-03-26 00:50:23 +0000266 I = llvm::make_unique<PPCSubtarget>(
Daniel Sandersc81f4502015-06-16 15:44:21 +0000267 TargetTriple, CPU,
Eric Christophered1042b2015-03-26 00:50:23 +0000268 // FIXME: It would be good to have the subtarget additions here
269 // not necessary. Anything that turns them on/off (overrides) ends
270 // up being put at the end of the feature string, but the defaults
271 // shouldn't require adding them. Fixing this means pulling Feature64Bit
272 // out of most of the target cpus in the .td file and making it set only
273 // as part of initialization via the TargetTriple.
274 computeFSAdditions(FS, getOptLevel(), getTargetTriple()), *this);
Eric Christopher3faf2f12014-10-06 06:45:36 +0000275 }
276 return I.get();
277}
Misha Brukmanb4402432005-04-21 23:30:14 +0000278
Chris Lattner12e97302006-09-04 04:14:57 +0000279//===----------------------------------------------------------------------===//
280// Pass Pipeline Configuration
281//===----------------------------------------------------------------------===//
Nate Begemanf17ea0f2004-08-11 07:40:04 +0000282
Andrew Trickccb67362012-02-03 05:12:41 +0000283namespace {
284/// PPC Code Generator Pass Configuration Options.
285class PPCPassConfig : public TargetPassConfig {
286public:
Andrew Trickf8ea1082012-02-04 02:56:59 +0000287 PPCPassConfig(PPCTargetMachine *TM, PassManagerBase &PM)
288 : TargetPassConfig(TM, PM) {}
Andrew Trickccb67362012-02-03 05:12:41 +0000289
290 PPCTargetMachine &getPPCTargetMachine() const {
291 return getTM<PPCTargetMachine>();
292 }
293
Robin Morisset22129962014-09-23 20:46:49 +0000294 void addIRPasses() override;
Craig Topper0d3fa922014-04-29 07:57:37 +0000295 bool addPreISel() override;
296 bool addILPOpts() override;
297 bool addInstSelector() override;
Bill Schmidtfe723b92015-04-27 19:57:34 +0000298 void addMachineSSAOptimization() override;
Matthias Braun7e37a5f2014-12-11 21:26:47 +0000299 void addPreRegAlloc() override;
300 void addPreSched2() override;
301 void addPreEmitPass() override;
Andrew Trickccb67362012-02-03 05:12:41 +0000302};
303} // namespace
304
Andrew Trickf8ea1082012-02-04 02:56:59 +0000305TargetPassConfig *PPCTargetMachine::createPassConfig(PassManagerBase &PM) {
Hal Finkeleb50c2d2012-06-09 03:14:50 +0000306 return new PPCPassConfig(this, PM);
Andrew Trickccb67362012-02-03 05:12:41 +0000307}
308
Robin Morisset22129962014-09-23 20:46:49 +0000309void PPCPassConfig::addIRPasses() {
Kit Bartona1c712f2015-12-07 20:50:29 +0000310 if (TM->getOptLevel() != CodeGenOpt::None)
311 addPass(createPPCBoolRetToIntPass());
Robin Morisset22129962014-09-23 20:46:49 +0000312 addPass(createAtomicExpandPass(&getPPCTargetMachine()));
Hal Finkelf413be12014-11-21 04:35:51 +0000313
Hal Finkele5aaf3f2015-02-20 05:08:21 +0000314 // For the BG/Q (or if explicitly requested), add explicit data prefetch
315 // intrinsics.
Daniel Sandersc81f4502015-06-16 15:44:21 +0000316 bool UsePrefetching = TM->getTargetTriple().getVendor() == Triple::BGQ &&
317 getOptLevel() != CodeGenOpt::None;
Hal Finkele5aaf3f2015-02-20 05:08:21 +0000318 if (EnablePrefetch.getNumOccurrences() > 0)
319 UsePrefetching = EnablePrefetch;
320 if (UsePrefetching)
Adam Nemet9d9cb272016-02-18 21:38:19 +0000321 addPass(createLoopDataPrefetchPass());
Hal Finkele5aaf3f2015-02-20 05:08:21 +0000322
Ehsan Amiri4701a912016-04-07 15:30:55 +0000323 if (TM->getOptLevel() >= CodeGenOpt::Default && EnableGEPOpt) {
Hal Finkelf413be12014-11-21 04:35:51 +0000324 // Call SeparateConstOffsetFromGEP pass to extract constants within indices
325 // and lower a GEP with multiple indices to either arithmetic operations or
326 // multiple GEPs with single index.
327 addPass(createSeparateConstOffsetFromGEPPass(TM, true));
328 // Call EarlyCSE pass to find and remove subexpressions in the lowered
329 // result.
330 addPass(createEarlyCSEPass());
331 // Do loop invariant code motion in case part of the lowered result is
332 // invariant.
333 addPass(createLICMPass());
334 }
335
Robin Morisset22129962014-09-23 20:46:49 +0000336 TargetPassConfig::addIRPasses();
337}
338
Hal Finkel25c19922013-05-15 21:37:41 +0000339bool PPCPassConfig::addPreISel() {
Hal Finkelc9dd0202015-02-05 18:43:00 +0000340 if (!DisablePreIncPrep && getOptLevel() != CodeGenOpt::None)
341 addPass(createPPCLoopPreIncPrepPass(getPPCTargetMachine()));
342
Hal Finkelc6b5deb2012-06-08 19:19:53 +0000343 if (!DisableCTRLoops && getOptLevel() != CodeGenOpt::None)
Hal Finkel25c19922013-05-15 21:37:41 +0000344 addPass(createPPCCTRLoops(getPPCTargetMachine()));
Hal Finkel96c2d4d2012-06-08 15:38:21 +0000345
346 return false;
347}
348
Hal Finkeled6a2852013-04-05 23:29:01 +0000349bool PPCPassConfig::addILPOpts() {
Eric Christopher6b0fcfe2014-05-21 23:40:26 +0000350 addPass(&EarlyIfConverterID);
Hal Finkel5d36b232015-07-15 08:23:05 +0000351
352 if (EnableMachineCombinerPass)
353 addPass(&MachineCombinerID);
354
Eric Christopher6b0fcfe2014-05-21 23:40:26 +0000355 return true;
Hal Finkeled6a2852013-04-05 23:29:01 +0000356}
357
Andrew Trickccb67362012-02-03 05:12:41 +0000358bool PPCPassConfig::addInstSelector() {
Chris Lattnerc6aa8062005-08-17 19:33:30 +0000359 // Install an instruction selector.
Bob Wilsonbbd38dd2012-07-02 19:48:31 +0000360 addPass(createPPCISelDag(getPPCTargetMachine()));
Hal Finkel8ca38842013-05-20 16:08:17 +0000361
362#ifndef NDEBUG
363 if (!DisableCTRLoops && getOptLevel() != CodeGenOpt::None)
364 addPass(createPPCCTRLoopsVerify());
365#endif
366
Eric Christopherd71e4442014-05-22 01:21:35 +0000367 addPass(createPPCVSXCopyPass());
Nate Begemanf17ea0f2004-08-11 07:40:04 +0000368 return false;
369}
370
Bill Schmidtfe723b92015-04-27 19:57:34 +0000371void PPCPassConfig::addMachineSSAOptimization() {
372 TargetPassConfig::addMachineSSAOptimization();
373 // For little endian, remove where possible the vector swap instructions
374 // introduced at code generation to normalize vector element order.
Daniel Sandersc81f4502015-06-16 15:44:21 +0000375 if (TM->getTargetTriple().getArch() == Triple::ppc64le &&
Bill Schmidtfe723b92015-04-27 19:57:34 +0000376 !DisableVSXSwapRemoval)
377 addPass(createPPCVSXSwapRemovalPass());
Bill Schmidt34af5e12015-11-10 21:38:26 +0000378 // Target-specific peephole cleanups performed after instruction
379 // selection.
380 if (!DisableMIPeephole) {
381 addPass(createPPCMIPeepholePass());
382 addPass(&DeadMachineInstructionElimID);
383 }
Bill Schmidtfe723b92015-04-27 19:57:34 +0000384}
385
Matthias Braun7e37a5f2014-12-11 21:26:47 +0000386void PPCPassConfig::addPreRegAlloc() {
Andrew Kaylor289bd5f2016-04-27 19:39:32 +0000387 if (getOptLevel() != CodeGenOpt::None) {
388 initializePPCVSXFMAMutatePass(*PassRegistry::getPassRegistry());
389 insertPass(VSXFMAMutateEarly ? &RegisterCoalescerID : &MachineSchedulerID,
390 &PPCVSXFMAMutateID);
391 }
Matthias Braunf84547c2016-04-28 23:42:51 +0000392 if (getPPCTargetMachine().getRelocationModel() == Reloc::PIC_) {
393 // FIXME: LiveVariables should not be necessary here!
394 // PPCTLSDYnamicCallPass uses LiveIntervals which previously dependet on
395 // LiveVariables. This (unnecessary) dependency has been removed now,
396 // however a stage-2 clang build fails without LiveVariables computed here.
397 addPass(&LiveVariablesID, false);
Bill Schmidt82f1c772015-02-10 19:09:05 +0000398 addPass(createPPCTLSDynamicCallPass());
Matthias Braunf84547c2016-04-28 23:42:51 +0000399 }
Hal Finkel8340de12015-05-18 06:25:59 +0000400 if (EnableExtraTOCRegDeps)
401 addPass(createPPCTOCRegDepsPass());
Hal Finkel174e5902014-03-25 23:29:21 +0000402}
403
Matthias Braun7e37a5f2014-12-11 21:26:47 +0000404void PPCPassConfig::addPreSched2() {
Hal Finkelfc353912016-03-31 20:39:41 +0000405 if (getOptLevel() != CodeGenOpt::None) {
Hal Finkel5711eca2013-04-09 22:58:37 +0000406 addPass(&IfConverterID);
Hal Finkelfc353912016-03-31 20:39:41 +0000407
408 // This optimization must happen after anything that might do store-to-load
409 // forwarding. Here we're after RA (and, thus, when spills are inserted)
410 // but before post-RA scheduling.
411 if (!DisableQPXLoadSplat)
412 addPass(createPPCQPXLoadSplatPass());
413 }
Hal Finkel5711eca2013-04-09 22:58:37 +0000414}
415
Matthias Braun7e37a5f2014-12-11 21:26:47 +0000416void PPCPassConfig::addPreEmitPass() {
Hal Finkelb5aa7e52013-04-08 16:24:03 +0000417 if (getOptLevel() != CodeGenOpt::None)
Matthias Braun7e37a5f2014-12-11 21:26:47 +0000418 addPass(createPPCEarlyReturnPass(), false);
Chris Lattner12e97302006-09-04 04:14:57 +0000419 // Must run branch selection immediately preceding the asm printer.
Matthias Braun7e37a5f2014-12-11 21:26:47 +0000420 addPass(createPPCBranchSelectionPass(), false);
Chris Lattner12e97302006-09-04 04:14:57 +0000421}
422
Chandler Carruth8b04c0d2015-02-01 13:20:00 +0000423TargetIRAnalysis PPCTargetMachine::getTargetIRAnalysis() {
Eric Christophera4e5d3c2015-09-16 23:38:13 +0000424 return TargetIRAnalysis([this](const Function &F) {
425 return TargetTransformInfo(PPCTTIImpl(this, F));
426 });
Hal Finkel4e5ca9e2013-01-25 23:05:59 +0000427}