blob: 5d68f32ccc5e1afb0de2e92c7ed6853fedb9adef [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
Eugene Zelenko8187c192017-01-13 00:58:58 +000014#include "MCTargetDesc/PPCMCTargetDesc.h"
Craig Topperb25fda92012-03-17 18:46:09 +000015#include "PPC.h"
Eugene Zelenko8187c192017-01-13 00:58:58 +000016#include "PPCSubtarget.h"
Chandler Carruthd9903882015-01-14 11:23:27 +000017#include "PPCTargetObjectFile.h"
Eugene Zelenko8187c192017-01-13 00:58:58 +000018#include "PPCTargetMachine.h"
Chandler Carruth93dcdc42015-01-31 11:17:59 +000019#include "PPCTargetTransformInfo.h"
Eugene Zelenko8187c192017-01-13 00:58:58 +000020#include "llvm/ADT/Optional.h"
21#include "llvm/ADT/STLExtras.h"
22#include "llvm/ADT/StringRef.h"
23#include "llvm/ADT/Triple.h"
24#include "llvm/Analysis/TargetTransformInfo.h"
Andrew Trickccb67362012-02-03 05:12:41 +000025#include "llvm/CodeGen/Passes.h"
Matthias Braun31d19d42016-05-10 03:21:59 +000026#include "llvm/CodeGen/TargetPassConfig.h"
Eugene Zelenko8187c192017-01-13 00:58:58 +000027#include "llvm/IR/Attributes.h"
28#include "llvm/IR/DataLayout.h"
Eric Christopher3faf2f12014-10-06 06:45:36 +000029#include "llvm/IR/Function.h"
Eugene Zelenko8187c192017-01-13 00:58:58 +000030#include "llvm/Pass.h"
31#include "llvm/Support/CodeGen.h"
Hal Finkel96c2d4d2012-06-08 15:38:21 +000032#include "llvm/Support/CommandLine.h"
Evan Cheng2bb40352011-08-24 18:08:43 +000033#include "llvm/Support/TargetRegistry.h"
Eugene Zelenko8187c192017-01-13 00:58:58 +000034#include "llvm/Target/TargetLoweringObjectFile.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000035#include "llvm/Target/TargetOptions.h"
Hal Finkelf413be12014-11-21 04:35:51 +000036#include "llvm/Transforms/Scalar.h"
Eugene Zelenko8187c192017-01-13 00:58:58 +000037#include <cassert>
38#include <memory>
39#include <string>
40
Misha Brukmane05203f2004-06-21 16:55:25 +000041using namespace llvm;
42
Hal Finkel96c2d4d2012-06-08 15:38:21 +000043static cl::
Hal Finkelc6b5deb2012-06-08 19:19:53 +000044opt<bool> DisableCTRLoops("disable-ppc-ctrloops", cl::Hidden,
45 cl::desc("Disable CTR loops for PPC"));
Hal Finkel96c2d4d2012-06-08 15:38:21 +000046
Hal Finkelc9dd0202015-02-05 18:43:00 +000047static cl::
48opt<bool> DisablePreIncPrep("disable-ppc-preinc-prep", cl::Hidden,
49 cl::desc("Disable PPC loop preinc prep"));
50
Hal Finkel174e5902014-03-25 23:29:21 +000051static cl::opt<bool>
52VSXFMAMutateEarly("schedule-ppc-vsx-fma-mutation-early",
53 cl::Hidden, cl::desc("Schedule VSX FMA instruction mutation early"));
54
Bill Schmidtfe723b92015-04-27 19:57:34 +000055static cl::
56opt<bool> DisableVSXSwapRemoval("disable-ppc-vsx-swap-removal", cl::Hidden,
57 cl::desc("Disable VSX Swap Removal for PPC"));
58
Bill Schmidt34af5e12015-11-10 21:38:26 +000059static cl::
Hal Finkelfc353912016-03-31 20:39:41 +000060opt<bool> DisableQPXLoadSplat("disable-ppc-qpx-load-splat", cl::Hidden,
61 cl::desc("Disable QPX load splat simplification"));
62
63static cl::
Bill Schmidt34af5e12015-11-10 21:38:26 +000064opt<bool> DisableMIPeephole("disable-ppc-peephole", cl::Hidden,
65 cl::desc("Disable machine peepholes for PPC"));
66
Hal Finkelf413be12014-11-21 04:35:51 +000067static cl::opt<bool>
68EnableGEPOpt("ppc-gep-opt", cl::Hidden,
69 cl::desc("Enable optimizations on complex GEPs"),
70 cl::init(true));
71
Hal Finkele5aaf3f2015-02-20 05:08:21 +000072static cl::opt<bool>
73EnablePrefetch("enable-ppc-prefetching",
74 cl::desc("disable software prefetching on PPC"),
75 cl::init(false), cl::Hidden);
76
Hal Finkel8340de12015-05-18 06:25:59 +000077static cl::opt<bool>
78EnableExtraTOCRegDeps("enable-ppc-extra-toc-reg-deps",
79 cl::desc("Add extra TOC register dependencies"),
80 cl::init(true), cl::Hidden);
81
Hal Finkel5d36b232015-07-15 08:23:05 +000082static cl::opt<bool>
83EnableMachineCombinerPass("ppc-machine-combiner",
84 cl::desc("Enable the machine combiner pass"),
85 cl::init(true), cl::Hidden);
86
Daniel Dunbar5680b4f2009-07-25 06:49:55 +000087extern "C" void LLVMInitializePowerPCTarget() {
88 // Register the targets
Mehdi Aminif42454b2016-10-09 23:00:34 +000089 RegisterTargetMachine<PPC32TargetMachine> A(getThePPC32Target());
90 RegisterTargetMachine<PPC64TargetMachine> B(getThePPC64Target());
91 RegisterTargetMachine<PPC64TargetMachine> C(getThePPC64LETarget());
Kit Bartona1c712f2015-12-07 20:50:29 +000092
93 PassRegistry &PR = *PassRegistry::getPassRegistry();
94 initializePPCBoolRetToIntPass(PR);
Tony Jiang8e8c4442017-01-16 20:12:26 +000095 initializePPCExpandISELPass(PR);
Daniel Dunbar5680b4f2009-07-25 06:49:55 +000096}
Douglas Gregor1b731d52009-06-16 20:12:29 +000097
Eric Christopher8b770652015-01-26 19:03:15 +000098/// Return the datalayout string of a subtarget.
99static std::string getDataLayoutString(const Triple &T) {
100 bool is64Bit = T.getArch() == Triple::ppc64 || T.getArch() == Triple::ppc64le;
101 std::string Ret;
102
103 // Most PPC* platforms are big endian, PPC64LE is little endian.
104 if (T.getArch() == Triple::ppc64le)
105 Ret = "e";
106 else
107 Ret = "E";
108
109 Ret += DataLayout::getManglingComponent(T);
110
111 // PPC32 has 32 bit pointers. The PS3 (OS Lv2) is a PPC64 machine with 32 bit
112 // pointers.
113 if (!is64Bit || T.getOS() == Triple::Lv2)
114 Ret += "-p:32:32";
115
116 // Note, the alignment values for f64 and i64 on ppc64 in Darwin
117 // documentation are wrong; these are correct (i.e. "what gcc does").
118 if (is64Bit || !T.isOSDarwin())
119 Ret += "-i64:64";
120 else
121 Ret += "-f64:32:64";
122
123 // PPC64 has 32 and 64 bit registers, PPC32 has only 32 bit ones.
124 if (is64Bit)
125 Ret += "-n32:64";
126 else
127 Ret += "-n32";
128
129 return Ret;
130}
131
Daniel Sanders335487a2015-06-16 13:15:50 +0000132static std::string computeFSAdditions(StringRef FS, CodeGenOpt::Level OL,
133 const Triple &TT) {
Eric Christopher36448af2014-10-01 20:38:26 +0000134 std::string FullFS = FS;
Eric Christopher36448af2014-10-01 20:38:26 +0000135
136 // Make sure 64-bit features are available when CPUname is generic
Daniel Sanders335487a2015-06-16 13:15:50 +0000137 if (TT.getArch() == Triple::ppc64 || TT.getArch() == Triple::ppc64le) {
Eric Christopher36448af2014-10-01 20:38:26 +0000138 if (!FullFS.empty())
139 FullFS = "+64bit," + FullFS;
140 else
141 FullFS = "+64bit";
142 }
143
144 if (OL >= CodeGenOpt::Default) {
145 if (!FullFS.empty())
146 FullFS = "+crbits," + FullFS;
147 else
148 FullFS = "+crbits";
149 }
Hal Finkele2ab0f12015-01-15 21:17:34 +0000150
151 if (OL != CodeGenOpt::None) {
NAKAMURA Takumi70ad98a2015-09-22 11:13:55 +0000152 if (!FullFS.empty())
Hal Finkele2ab0f12015-01-15 21:17:34 +0000153 FullFS = "+invariant-function-descriptors," + FullFS;
154 else
155 FullFS = "+invariant-function-descriptors";
156 }
157
Eric Christopher36448af2014-10-01 20:38:26 +0000158 return FullFS;
159}
160
Aditya Nandakumara2719322014-11-13 09:26:31 +0000161static std::unique_ptr<TargetLoweringObjectFile> createTLOF(const Triple &TT) {
162 // If it isn't a Mach-O file then it's going to be a linux ELF
163 // object file.
164 if (TT.isOSDarwin())
Eugene Zelenko8187c192017-01-13 00:58:58 +0000165 return llvm::make_unique<TargetLoweringObjectFileMachO>();
Aditya Nandakumara2719322014-11-13 09:26:31 +0000166
Eugene Zelenko8187c192017-01-13 00:58:58 +0000167 return llvm::make_unique<PPC64LinuxTargetObjectFile>();
Aditya Nandakumara2719322014-11-13 09:26:31 +0000168}
169
Eric Christopherfee6aaf2015-02-17 06:45:15 +0000170static PPCTargetMachine::PPCABI computeTargetABI(const Triple &TT,
171 const TargetOptions &Options) {
172 if (Options.MCOptions.getABIName().startswith("elfv1"))
173 return PPCTargetMachine::PPC_ABI_ELFv1;
174 else if (Options.MCOptions.getABIName().startswith("elfv2"))
175 return PPCTargetMachine::PPC_ABI_ELFv2;
176
177 assert(Options.MCOptions.getABIName().empty() &&
NAKAMURA Takumi0a7d0ad2015-09-22 11:15:07 +0000178 "Unknown target-abi option!");
Eric Christopherfee6aaf2015-02-17 06:45:15 +0000179
180 if (!TT.isMacOSX()) {
181 switch (TT.getArch()) {
182 case Triple::ppc64le:
183 return PPCTargetMachine::PPC_ABI_ELFv2;
184 case Triple::ppc64:
185 return PPCTargetMachine::PPC_ABI_ELFv1;
186 default:
187 // Fallthrough.
188 ;
189 }
190 }
191 return PPCTargetMachine::PPC_ABI_UNKNOWN;
192}
193
Rafael Espindola8c34dd82016-05-18 22:04:49 +0000194static Reloc::Model getEffectiveRelocModel(const Triple &TT,
195 Optional<Reloc::Model> RM) {
196 if (!RM.hasValue()) {
Joerg Sonnenberger400e7b72016-12-15 00:01:53 +0000197 if (TT.getArch() == Triple::ppc64 || TT.getArch() == Triple::ppc64le) {
198 if (!TT.isOSBinFormatMachO() && !TT.isMacOSX())
199 return Reloc::PIC_;
200 }
Rafael Espindola8c34dd82016-05-18 22:04:49 +0000201 if (TT.isOSDarwin())
202 return Reloc::DynamicNoPIC;
203 return Reloc::Static;
204 }
205 return *RM;
206}
207
NAKAMURA Takumi84965032015-09-22 11:14:12 +0000208// The FeatureString here is a little subtle. We are modifying the feature
209// string with what are (currently) non-function specific overrides as it goes
210// into the LLVMTargetMachine constructor and then using the stored value in the
Eric Christopher36448af2014-10-01 20:38:26 +0000211// Subtarget constructor below it.
Daniel Sanders3e5de882015-06-11 19:41:26 +0000212PPCTargetMachine::PPCTargetMachine(const Target &T, const Triple &TT,
213 StringRef CPU, StringRef FS,
214 const TargetOptions &Options,
Rafael Espindola8c34dd82016-05-18 22:04:49 +0000215 Optional<Reloc::Model> RM,
216 CodeModel::Model CM, CodeGenOpt::Level OL)
Daniel Sanders3e5de882015-06-11 19:41:26 +0000217 : LLVMTargetMachine(T, getDataLayoutString(TT), TT, CPU,
Rafael Espindola8c34dd82016-05-18 22:04:49 +0000218 computeFSAdditions(FS, OL, TT), Options,
219 getEffectiveRelocModel(TT, RM), CM, OL),
Daniel Sandersc81f4502015-06-16 15:44:21 +0000220 TLOF(createTLOF(getTargetTriple())),
Hal Finkelcbf08922015-07-12 02:33:57 +0000221 TargetABI(computeTargetABI(TT, Options)),
222 Subtarget(TargetTriple, CPU, computeFSAdditions(FS, OL, TT), *this) {
223
Rafael Espindola227144c2013-05-13 01:16:13 +0000224 initAsmInfo();
Nate Begeman6cca84e2005-10-16 05:39:50 +0000225}
226
Eugene Zelenko8187c192017-01-13 00:58:58 +0000227PPCTargetMachine::~PPCTargetMachine() = default;
Reid Kleckner357600e2014-11-20 23:37:18 +0000228
Eugene Zelenko8187c192017-01-13 00:58:58 +0000229void PPC32TargetMachine::anchor() {}
David Blaikiea379b1812011-12-20 02:50:00 +0000230
Daniel Sanders3e5de882015-06-11 19:41:26 +0000231PPC32TargetMachine::PPC32TargetMachine(const Target &T, const Triple &TT,
Evan Chengefd9b422011-07-20 07:51:56 +0000232 StringRef CPU, StringRef FS,
Nick Lewycky50f02cb2011-12-02 22:16:29 +0000233 const TargetOptions &Options,
Rafael Espindola8c34dd82016-05-18 22:04:49 +0000234 Optional<Reloc::Model> RM,
235 CodeModel::Model CM,
Evan Chengecb29082011-11-16 08:38:26 +0000236 CodeGenOpt::Level OL)
Daniel Sanders3e5de882015-06-11 19:41:26 +0000237 : PPCTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL) {}
Chris Lattner0c4aa142006-06-16 01:37:27 +0000238
Eugene Zelenko8187c192017-01-13 00:58:58 +0000239void PPC64TargetMachine::anchor() {}
Chris Lattner0c4aa142006-06-16 01:37:27 +0000240
Daniel Sanders3e5de882015-06-11 19:41:26 +0000241PPC64TargetMachine::PPC64TargetMachine(const Target &T, const Triple &TT,
242 StringRef CPU, StringRef FS,
Nick Lewycky50f02cb2011-12-02 22:16:29 +0000243 const TargetOptions &Options,
Rafael Espindola8c34dd82016-05-18 22:04:49 +0000244 Optional<Reloc::Model> RM,
245 CodeModel::Model CM,
Evan Chengecb29082011-11-16 08:38:26 +0000246 CodeGenOpt::Level OL)
Daniel Sanders3e5de882015-06-11 19:41:26 +0000247 : PPCTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL) {}
Chris Lattner0c4aa142006-06-16 01:37:27 +0000248
Eric Christopher3faf2f12014-10-06 06:45:36 +0000249const PPCSubtarget *
250PPCTargetMachine::getSubtargetImpl(const Function &F) const {
Duncan P. N. Exon Smith5bedaf932015-02-14 02:54:07 +0000251 Attribute CPUAttr = F.getFnAttribute("target-cpu");
252 Attribute FSAttr = F.getFnAttribute("target-features");
Eric Christopher3faf2f12014-10-06 06:45:36 +0000253
254 std::string CPU = !CPUAttr.hasAttribute(Attribute::None)
255 ? CPUAttr.getValueAsString().str()
256 : TargetCPU;
257 std::string FS = !FSAttr.hasAttribute(Attribute::None)
258 ? FSAttr.getValueAsString().str()
259 : TargetFS;
260
Petar Jovanovic280f7102015-12-14 17:57:33 +0000261 // FIXME: This is related to the code below to reset the target options,
262 // we need to know whether or not the soft float flag is set on the
263 // function before we can generate a subtarget. We also need to use
264 // it as a key for the subtarget since that can be the only difference
265 // between two functions.
266 bool SoftFloat =
Nirav Dave8dd66e52016-03-30 15:41:12 +0000267 F.getFnAttribute("use-soft-float").getValueAsString() == "true";
Petar Jovanovic280f7102015-12-14 17:57:33 +0000268 // If the soft float attribute is set on the function turn on the soft float
269 // subtarget feature.
270 if (SoftFloat)
Hal Finkela9321052016-10-02 02:10:20 +0000271 FS += FS.empty() ? "-hard-float" : ",-hard-float";
Petar Jovanovic280f7102015-12-14 17:57:33 +0000272
Eric Christopher3faf2f12014-10-06 06:45:36 +0000273 auto &I = SubtargetMap[CPU + FS];
274 if (!I) {
275 // This needs to be done before we create a new subtarget since any
276 // creation will depend on the TM and the code generation flags on the
277 // function that reside in TargetOptions.
278 resetTargetOptions(F);
Eric Christophered1042b2015-03-26 00:50:23 +0000279 I = llvm::make_unique<PPCSubtarget>(
Daniel Sandersc81f4502015-06-16 15:44:21 +0000280 TargetTriple, CPU,
Eric Christophered1042b2015-03-26 00:50:23 +0000281 // FIXME: It would be good to have the subtarget additions here
282 // not necessary. Anything that turns them on/off (overrides) ends
283 // up being put at the end of the feature string, but the defaults
284 // shouldn't require adding them. Fixing this means pulling Feature64Bit
285 // out of most of the target cpus in the .td file and making it set only
286 // as part of initialization via the TargetTriple.
287 computeFSAdditions(FS, getOptLevel(), getTargetTriple()), *this);
Eric Christopher3faf2f12014-10-06 06:45:36 +0000288 }
289 return I.get();
290}
Misha Brukmanb4402432005-04-21 23:30:14 +0000291
Chris Lattner12e97302006-09-04 04:14:57 +0000292//===----------------------------------------------------------------------===//
293// Pass Pipeline Configuration
294//===----------------------------------------------------------------------===//
Nate Begemanf17ea0f2004-08-11 07:40:04 +0000295
Andrew Trickccb67362012-02-03 05:12:41 +0000296namespace {
Eugene Zelenko8187c192017-01-13 00:58:58 +0000297
Andrew Trickccb67362012-02-03 05:12:41 +0000298/// PPC Code Generator Pass Configuration Options.
299class PPCPassConfig : public TargetPassConfig {
300public:
Andrew Trickf8ea1082012-02-04 02:56:59 +0000301 PPCPassConfig(PPCTargetMachine *TM, PassManagerBase &PM)
302 : TargetPassConfig(TM, PM) {}
Andrew Trickccb67362012-02-03 05:12:41 +0000303
304 PPCTargetMachine &getPPCTargetMachine() const {
305 return getTM<PPCTargetMachine>();
306 }
307
Robin Morisset22129962014-09-23 20:46:49 +0000308 void addIRPasses() override;
Craig Topper0d3fa922014-04-29 07:57:37 +0000309 bool addPreISel() override;
310 bool addILPOpts() override;
311 bool addInstSelector() override;
Bill Schmidtfe723b92015-04-27 19:57:34 +0000312 void addMachineSSAOptimization() override;
Matthias Braun7e37a5f2014-12-11 21:26:47 +0000313 void addPreRegAlloc() override;
314 void addPreSched2() override;
315 void addPreEmitPass() override;
Andrew Trickccb67362012-02-03 05:12:41 +0000316};
Eugene Zelenko8187c192017-01-13 00:58:58 +0000317
318} // end anonymous namespace
Andrew Trickccb67362012-02-03 05:12:41 +0000319
Andrew Trickf8ea1082012-02-04 02:56:59 +0000320TargetPassConfig *PPCTargetMachine::createPassConfig(PassManagerBase &PM) {
Hal Finkeleb50c2d2012-06-09 03:14:50 +0000321 return new PPCPassConfig(this, PM);
Andrew Trickccb67362012-02-03 05:12:41 +0000322}
323
Robin Morisset22129962014-09-23 20:46:49 +0000324void PPCPassConfig::addIRPasses() {
Kit Bartona1c712f2015-12-07 20:50:29 +0000325 if (TM->getOptLevel() != CodeGenOpt::None)
326 addPass(createPPCBoolRetToIntPass());
Robin Morisset22129962014-09-23 20:46:49 +0000327 addPass(createAtomicExpandPass(&getPPCTargetMachine()));
Hal Finkelf413be12014-11-21 04:35:51 +0000328
Hal Finkele5aaf3f2015-02-20 05:08:21 +0000329 // For the BG/Q (or if explicitly requested), add explicit data prefetch
330 // intrinsics.
Daniel Sandersc81f4502015-06-16 15:44:21 +0000331 bool UsePrefetching = TM->getTargetTriple().getVendor() == Triple::BGQ &&
332 getOptLevel() != CodeGenOpt::None;
Hal Finkele5aaf3f2015-02-20 05:08:21 +0000333 if (EnablePrefetch.getNumOccurrences() > 0)
334 UsePrefetching = EnablePrefetch;
335 if (UsePrefetching)
Adam Nemet9d9cb272016-02-18 21:38:19 +0000336 addPass(createLoopDataPrefetchPass());
Hal Finkele5aaf3f2015-02-20 05:08:21 +0000337
Ehsan Amiri4701a912016-04-07 15:30:55 +0000338 if (TM->getOptLevel() >= CodeGenOpt::Default && EnableGEPOpt) {
Hal Finkelf413be12014-11-21 04:35:51 +0000339 // Call SeparateConstOffsetFromGEP pass to extract constants within indices
340 // and lower a GEP with multiple indices to either arithmetic operations or
341 // multiple GEPs with single index.
342 addPass(createSeparateConstOffsetFromGEPPass(TM, true));
343 // Call EarlyCSE pass to find and remove subexpressions in the lowered
344 // result.
345 addPass(createEarlyCSEPass());
346 // Do loop invariant code motion in case part of the lowered result is
347 // invariant.
348 addPass(createLICMPass());
349 }
350
Robin Morisset22129962014-09-23 20:46:49 +0000351 TargetPassConfig::addIRPasses();
352}
353
Hal Finkel25c19922013-05-15 21:37:41 +0000354bool PPCPassConfig::addPreISel() {
Hal Finkelc9dd0202015-02-05 18:43:00 +0000355 if (!DisablePreIncPrep && getOptLevel() != CodeGenOpt::None)
356 addPass(createPPCLoopPreIncPrepPass(getPPCTargetMachine()));
357
Hal Finkelc6b5deb2012-06-08 19:19:53 +0000358 if (!DisableCTRLoops && getOptLevel() != CodeGenOpt::None)
Hal Finkel25c19922013-05-15 21:37:41 +0000359 addPass(createPPCCTRLoops(getPPCTargetMachine()));
Hal Finkel96c2d4d2012-06-08 15:38:21 +0000360
361 return false;
362}
363
Hal Finkeled6a2852013-04-05 23:29:01 +0000364bool PPCPassConfig::addILPOpts() {
Eric Christopher6b0fcfe2014-05-21 23:40:26 +0000365 addPass(&EarlyIfConverterID);
Hal Finkel5d36b232015-07-15 08:23:05 +0000366
367 if (EnableMachineCombinerPass)
368 addPass(&MachineCombinerID);
369
Eric Christopher6b0fcfe2014-05-21 23:40:26 +0000370 return true;
Hal Finkeled6a2852013-04-05 23:29:01 +0000371}
372
Andrew Trickccb67362012-02-03 05:12:41 +0000373bool PPCPassConfig::addInstSelector() {
Chris Lattnerc6aa8062005-08-17 19:33:30 +0000374 // Install an instruction selector.
Bob Wilsonbbd38dd2012-07-02 19:48:31 +0000375 addPass(createPPCISelDag(getPPCTargetMachine()));
Hal Finkel8ca38842013-05-20 16:08:17 +0000376
377#ifndef NDEBUG
378 if (!DisableCTRLoops && getOptLevel() != CodeGenOpt::None)
379 addPass(createPPCCTRLoopsVerify());
380#endif
381
Eric Christopherd71e4442014-05-22 01:21:35 +0000382 addPass(createPPCVSXCopyPass());
Nate Begemanf17ea0f2004-08-11 07:40:04 +0000383 return false;
384}
385
Bill Schmidtfe723b92015-04-27 19:57:34 +0000386void PPCPassConfig::addMachineSSAOptimization() {
387 TargetPassConfig::addMachineSSAOptimization();
388 // For little endian, remove where possible the vector swap instructions
389 // introduced at code generation to normalize vector element order.
Daniel Sandersc81f4502015-06-16 15:44:21 +0000390 if (TM->getTargetTriple().getArch() == Triple::ppc64le &&
Bill Schmidtfe723b92015-04-27 19:57:34 +0000391 !DisableVSXSwapRemoval)
392 addPass(createPPCVSXSwapRemovalPass());
Bill Schmidt34af5e12015-11-10 21:38:26 +0000393 // Target-specific peephole cleanups performed after instruction
394 // selection.
395 if (!DisableMIPeephole) {
396 addPass(createPPCMIPeepholePass());
397 addPass(&DeadMachineInstructionElimID);
398 }
Bill Schmidtfe723b92015-04-27 19:57:34 +0000399}
400
Matthias Braun7e37a5f2014-12-11 21:26:47 +0000401void PPCPassConfig::addPreRegAlloc() {
Andrew Kaylor289bd5f2016-04-27 19:39:32 +0000402 if (getOptLevel() != CodeGenOpt::None) {
403 initializePPCVSXFMAMutatePass(*PassRegistry::getPassRegistry());
404 insertPass(VSXFMAMutateEarly ? &RegisterCoalescerID : &MachineSchedulerID,
405 &PPCVSXFMAMutateID);
406 }
Rafael Espindola248cfb92016-06-28 12:49:12 +0000407
408 // FIXME: We probably don't need to run these for -fPIE.
409 if (getPPCTargetMachine().isPositionIndependent()) {
Matthias Braunf84547c2016-04-28 23:42:51 +0000410 // FIXME: LiveVariables should not be necessary here!
411 // PPCTLSDYnamicCallPass uses LiveIntervals which previously dependet on
412 // LiveVariables. This (unnecessary) dependency has been removed now,
413 // however a stage-2 clang build fails without LiveVariables computed here.
414 addPass(&LiveVariablesID, false);
Bill Schmidt82f1c772015-02-10 19:09:05 +0000415 addPass(createPPCTLSDynamicCallPass());
Matthias Braunf84547c2016-04-28 23:42:51 +0000416 }
Hal Finkel8340de12015-05-18 06:25:59 +0000417 if (EnableExtraTOCRegDeps)
418 addPass(createPPCTOCRegDepsPass());
Hal Finkel174e5902014-03-25 23:29:21 +0000419}
420
Matthias Braun7e37a5f2014-12-11 21:26:47 +0000421void PPCPassConfig::addPreSched2() {
Hal Finkelfc353912016-03-31 20:39:41 +0000422 if (getOptLevel() != CodeGenOpt::None) {
Hal Finkel5711eca2013-04-09 22:58:37 +0000423 addPass(&IfConverterID);
Hal Finkelfc353912016-03-31 20:39:41 +0000424
425 // This optimization must happen after anything that might do store-to-load
426 // forwarding. Here we're after RA (and, thus, when spills are inserted)
427 // but before post-RA scheduling.
428 if (!DisableQPXLoadSplat)
429 addPass(createPPCQPXLoadSplatPass());
430 }
Hal Finkel5711eca2013-04-09 22:58:37 +0000431}
432
Matthias Braun7e37a5f2014-12-11 21:26:47 +0000433void PPCPassConfig::addPreEmitPass() {
Tony Jiang8e8c4442017-01-16 20:12:26 +0000434 addPass(createPPCExpandISELPass());
435
Hal Finkelb5aa7e52013-04-08 16:24:03 +0000436 if (getOptLevel() != CodeGenOpt::None)
Matthias Braun7e37a5f2014-12-11 21:26:47 +0000437 addPass(createPPCEarlyReturnPass(), false);
Chris Lattner12e97302006-09-04 04:14:57 +0000438 // Must run branch selection immediately preceding the asm printer.
Matthias Braun7e37a5f2014-12-11 21:26:47 +0000439 addPass(createPPCBranchSelectionPass(), false);
Chris Lattner12e97302006-09-04 04:14:57 +0000440}
441
Chandler Carruth8b04c0d2015-02-01 13:20:00 +0000442TargetIRAnalysis PPCTargetMachine::getTargetIRAnalysis() {
Eric Christophera4e5d3c2015-09-16 23:38:13 +0000443 return TargetIRAnalysis([this](const Function &F) {
444 return TargetTransformInfo(PPCTTIImpl(this, F));
445 });
Hal Finkel4e5ca9e2013-01-25 23:05:59 +0000446}