blob: 0f98d52084f2699d034a4ce0ee2bf3a9edd527cd [file] [log] [blame]
Rafael Espindolaffdc24b2006-05-14 22:18:28 +00001//===-- ARMTargetMachine.cpp - Define TargetMachine for ARM ---------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattnerf3ebc3f2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
Rafael Espindolaffdc24b2006-05-14 22:18:28 +00006// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10//
11//===----------------------------------------------------------------------===//
12
Rafael Espindolaffdc24b2006-05-14 22:18:28 +000013#include "ARM.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000014#include "ARMFrameLowering.h"
Chandler Carruthd9903882015-01-14 11:23:27 +000015#include "ARMTargetMachine.h"
Aditya Nandakumara2719322014-11-13 09:26:31 +000016#include "ARMTargetObjectFile.h"
Chandler Carruth93dcdc42015-01-31 11:17:59 +000017#include "ARMTargetTransformInfo.h"
Evan Chengad3aac712007-05-16 02:01:49 +000018#include "llvm/CodeGen/Passes.h"
Eric Christopher3faf2f12014-10-06 06:45:36 +000019#include "llvm/IR/Function.h"
Chandler Carruth30d69c22015-02-13 10:01:29 +000020#include "llvm/IR/LegacyPassManager.h"
Bill Wendling354ff9e2011-09-27 22:14:12 +000021#include "llvm/MC/MCAsmInfo.h"
Evan Cheng62c7b5b2010-12-05 22:04:16 +000022#include "llvm/Support/CommandLine.h"
David Greenea31f96c2009-07-14 20:18:05 +000023#include "llvm/Support/FormattedStream.h"
Evan Cheng2bb40352011-08-24 18:08:43 +000024#include "llvm/Support/TargetRegistry.h"
Evan Cheng10043e22007-01-19 07:51:42 +000025#include "llvm/Target/TargetOptions.h"
Devang Patel76c85632011-10-17 17:17:43 +000026#include "llvm/Transforms/Scalar.h"
Rafael Espindolaffdc24b2006-05-14 22:18:28 +000027using namespace llvm;
28
Evan Chengf066b2f2011-08-25 01:00:36 +000029static cl::opt<bool>
Silviu Baranga82dd6ac2013-03-15 18:28:25 +000030DisableA15SDOptimization("disable-a15-sd-optimization", cl::Hidden,
31 cl::desc("Inhibit optimization of S->D register accesses on A15"),
32 cl::init(false));
33
Tim Northoverb4ddc082014-05-30 10:09:59 +000034static cl::opt<bool>
35EnableAtomicTidy("arm-atomic-cfg-tidy", cl::Hidden,
36 cl::desc("Run SimplifyCFG after expanding atomic operations"
37 " to make use of cmpxchg flow-based information"),
38 cl::init(true));
39
Renato Golin4c871392015-03-26 18:38:04 +000040static cl::opt<bool>
41EnableARMLoadStoreOpt("arm-load-store-opt", cl::Hidden,
42 cl::desc("Enable ARM load/store optimization pass"),
43 cl::init(true));
44
Ahmed Bougachab96444e2015-04-11 00:06:36 +000045// FIXME: Unify control over GlobalMerge.
46static cl::opt<cl::boolOrDefault>
47EnableGlobalMerge("arm-global-merge", cl::Hidden,
48 cl::desc("Enable the global merge pass"));
49
Jim Grosbachf24f9d92009-08-11 15:33:49 +000050extern "C" void LLVMInitializeARMTarget() {
Daniel Dunbar5680b4f2009-07-25 06:49:55 +000051 // Register the target.
Christian Pirkerdc9ff752014-04-01 15:19:30 +000052 RegisterTargetMachine<ARMLETargetMachine> X(TheARMLETarget);
53 RegisterTargetMachine<ARMBETargetMachine> Y(TheARMBETarget);
54 RegisterTargetMachine<ThumbLETargetMachine> A(TheThumbLETarget);
55 RegisterTargetMachine<ThumbBETargetMachine> B(TheThumbBETarget);
Daniel Dunbar5680b4f2009-07-25 06:49:55 +000056}
Douglas Gregor1b731d52009-06-16 20:12:29 +000057
Aditya Nandakumara2719322014-11-13 09:26:31 +000058static std::unique_ptr<TargetLoweringObjectFile> createTLOF(const Triple &TT) {
59 if (TT.isOSBinFormatMachO())
60 return make_unique<TargetLoweringObjectFileMachO>();
61 if (TT.isOSWindows())
62 return make_unique<TargetLoweringObjectFileCOFF>();
63 return make_unique<ARMElfTargetObjectFile>();
64}
65
Eric Christopher661f2d12014-12-18 02:20:58 +000066static ARMBaseTargetMachine::ARMABI
67computeTargetABI(const Triple &TT, StringRef CPU,
68 const TargetOptions &Options) {
Eric Christopher6e30cd92015-01-14 00:50:31 +000069 if (Options.MCOptions.getABIName().startswith("aapcs"))
Eric Christopher661f2d12014-12-18 02:20:58 +000070 return ARMBaseTargetMachine::ARM_ABI_AAPCS;
Eric Christopher6e30cd92015-01-14 00:50:31 +000071 else if (Options.MCOptions.getABIName().startswith("apcs"))
Eric Christopher661f2d12014-12-18 02:20:58 +000072 return ARMBaseTargetMachine::ARM_ABI_APCS;
73
Eric Christopher6e30cd92015-01-14 00:50:31 +000074 assert(Options.MCOptions.getABIName().empty() &&
75 "Unknown target-abi option!");
Eric Christopher661f2d12014-12-18 02:20:58 +000076
77 ARMBaseTargetMachine::ARMABI TargetABI =
78 ARMBaseTargetMachine::ARM_ABI_UNKNOWN;
79
80 // FIXME: This is duplicated code from the front end and should be unified.
81 if (TT.isOSBinFormatMachO()) {
82 if (TT.getEnvironment() == llvm::Triple::EABI ||
83 (TT.getOS() == llvm::Triple::UnknownOS &&
84 TT.getObjectFormat() == llvm::Triple::MachO) ||
85 CPU.startswith("cortex-m")) {
86 TargetABI = ARMBaseTargetMachine::ARM_ABI_AAPCS;
87 } else {
88 TargetABI = ARMBaseTargetMachine::ARM_ABI_APCS;
89 }
90 } else if (TT.isOSWindows()) {
91 // FIXME: this is invalid for WindowsCE
92 TargetABI = ARMBaseTargetMachine::ARM_ABI_AAPCS;
93 } else {
94 // Select the default based on the platform.
95 switch (TT.getEnvironment()) {
96 case llvm::Triple::Android:
97 case llvm::Triple::GNUEABI:
98 case llvm::Triple::GNUEABIHF:
99 case llvm::Triple::EABIHF:
100 case llvm::Triple::EABI:
101 TargetABI = ARMBaseTargetMachine::ARM_ABI_AAPCS;
102 break;
103 case llvm::Triple::GNU:
104 TargetABI = ARMBaseTargetMachine::ARM_ABI_APCS;
105 break;
106 default:
107 if (TT.getOS() == llvm::Triple::NetBSD)
108 TargetABI = ARMBaseTargetMachine::ARM_ABI_APCS;
109 else
110 TargetABI = ARMBaseTargetMachine::ARM_ABI_AAPCS;
111 break;
112 }
113 }
114
115 return TargetABI;
116}
117
Mehdi Amini93e1ea12015-03-12 00:07:24 +0000118static std::string computeDataLayout(StringRef TT, StringRef CPU,
119 const TargetOptions &Options,
Eric Christopher8b770652015-01-26 19:03:15 +0000120 bool isLittle) {
Mehdi Amini93e1ea12015-03-12 00:07:24 +0000121 const Triple Triple(TT);
122 auto ABI = computeTargetABI(Triple, CPU, Options);
Eric Christopher8b770652015-01-26 19:03:15 +0000123 std::string Ret = "";
124
125 if (isLittle)
126 // Little endian.
127 Ret += "e";
128 else
129 // Big endian.
130 Ret += "E";
131
Mehdi Amini93e1ea12015-03-12 00:07:24 +0000132 Ret += DataLayout::getManglingComponent(Triple);
Eric Christopher8b770652015-01-26 19:03:15 +0000133
134 // Pointers are 32 bits and aligned to 32 bits.
135 Ret += "-p:32:32";
136
137 // ABIs other than APCS have 64 bit integers with natural alignment.
138 if (ABI != ARMBaseTargetMachine::ARM_ABI_APCS)
139 Ret += "-i64:64";
140
141 // We have 64 bits floats. The APCS ABI requires them to be aligned to 32
142 // bits, others to 64 bits. We always try to align to 64 bits.
143 if (ABI == ARMBaseTargetMachine::ARM_ABI_APCS)
144 Ret += "-f64:32:64";
145
146 // We have 128 and 64 bit vectors. The APCS ABI aligns them to 32 bits, others
147 // to 64. We always ty to give them natural alignment.
148 if (ABI == ARMBaseTargetMachine::ARM_ABI_APCS)
149 Ret += "-v64:32:64-v128:32:128";
150 else
151 Ret += "-v128:64:128";
152
153 // Try to align aggregates to 32 bits (the default is 64 bits, which has no
154 // particular hardware support on 32-bit ARM).
155 Ret += "-a:0:32";
156
157 // Integer registers are 32 bits.
158 Ret += "-n32";
159
160 // The stack is 128 bit aligned on NaCl, 64 bit aligned on AAPCS and 32 bit
161 // aligned everywhere else.
Mehdi Amini93e1ea12015-03-12 00:07:24 +0000162 if (Triple.isOSNaCl())
Eric Christopher8b770652015-01-26 19:03:15 +0000163 Ret += "-S128";
164 else if (ABI == ARMBaseTargetMachine::ARM_ABI_AAPCS)
165 Ret += "-S64";
166 else
167 Ret += "-S32";
168
169 return Ret;
170}
171
Evan Cheng9f830142007-02-23 03:14:31 +0000172/// TargetMachine ctor - Create an ARM architecture model.
173///
Evan Cheng2129f592011-07-19 06:37:02 +0000174ARMBaseTargetMachine::ARMBaseTargetMachine(const Target &T, StringRef TT,
175 StringRef CPU, StringRef FS,
Nick Lewycky50f02cb2011-12-02 22:16:29 +0000176 const TargetOptions &Options,
Evan Chengecb29082011-11-16 08:38:26 +0000177 Reloc::Model RM, CodeModel::Model CM,
Eric Christopher80b24ef2014-06-26 19:30:02 +0000178 CodeGenOpt::Level OL, bool isLittle)
Mehdi Amini93e1ea12015-03-12 00:07:24 +0000179 : LLVMTargetMachine(T, computeDataLayout(TT, CPU, Options, isLittle), TT,
180 CPU, FS, Options, RM, CM, OL),
Eric Christopher661f2d12014-12-18 02:20:58 +0000181 TargetABI(computeTargetABI(Triple(TT), CPU, Options)),
Aditya Nandakumara2719322014-11-13 09:26:31 +0000182 TLOF(createTLOF(Triple(getTargetTriple()))),
Eric Christopher3faf2f12014-10-06 06:45:36 +0000183 Subtarget(TT, CPU, FS, *this, isLittle), isLittle(isLittle) {
Tim Northoverf1c31b92013-12-18 14:18:36 +0000184
185 // Default to triple-appropriate float ABI
Nick Lewycky50f02cb2011-12-02 22:16:29 +0000186 if (Options.FloatABIType == FloatABI::Default)
Tim Northover44594ad2013-12-18 09:27:33 +0000187 this->Options.FloatABIType =
188 Subtarget.isTargetHardFloat() ? FloatABI::Hard : FloatABI::Soft;
Evan Cheng66cff402008-10-30 16:10:54 +0000189}
Rafael Espindolaffdc24b2006-05-14 22:18:28 +0000190
Reid Kleckner357600e2014-11-20 23:37:18 +0000191ARMBaseTargetMachine::~ARMBaseTargetMachine() {}
192
Eric Christopher3faf2f12014-10-06 06:45:36 +0000193const ARMSubtarget *
194ARMBaseTargetMachine::getSubtargetImpl(const Function &F) const {
Duncan P. N. Exon Smith2cff9e12015-02-14 02:24:44 +0000195 Attribute CPUAttr = F.getFnAttribute("target-cpu");
196 Attribute FSAttr = F.getFnAttribute("target-features");
Eric Christopher3faf2f12014-10-06 06:45:36 +0000197
198 std::string CPU = !CPUAttr.hasAttribute(Attribute::None)
199 ? CPUAttr.getValueAsString().str()
200 : TargetCPU;
201 std::string FS = !FSAttr.hasAttribute(Attribute::None)
202 ? FSAttr.getValueAsString().str()
203 : TargetFS;
204
205 // FIXME: This is related to the code below to reset the target options,
206 // we need to know whether or not the soft float flag is set on the
207 // function before we can generate a subtarget. We also need to use
208 // it as a key for the subtarget since that can be the only difference
209 // between two functions.
Eric Christopher824f42f2015-05-12 01:26:05 +0000210 bool SoftFloat =
211 F.hasFnAttribute("use-soft-float") &&
212 F.getFnAttribute("use-soft-float").getValueAsString() == "true";
213 // If the soft float attribute is set on the function turn on the soft float
214 // subtarget feature.
215 if (SoftFloat)
216 FS += FS.empty() ? "+soft-float" : ",+soft-float";
Eric Christopher3faf2f12014-10-06 06:45:36 +0000217
Eric Christopher824f42f2015-05-12 01:26:05 +0000218 auto &I = SubtargetMap[CPU + FS];
Eric Christopher3faf2f12014-10-06 06:45:36 +0000219 if (!I) {
220 // This needs to be done before we create a new subtarget since any
221 // creation will depend on the TM and the code generation flags on the
222 // function that reside in TargetOptions.
223 resetTargetOptions(F);
224 I = llvm::make_unique<ARMSubtarget>(TargetTriple, CPU, FS, *this, isLittle);
225 }
226 return I.get();
227}
228
Chandler Carruth8b04c0d2015-02-01 13:20:00 +0000229TargetIRAnalysis ARMBaseTargetMachine::getTargetIRAnalysis() {
230 return TargetIRAnalysis(
231 [this](Function &F) { return TargetTransformInfo(ARMTTIImpl(this, F)); });
Chandler Carruth664e3542013-01-07 01:37:14 +0000232}
233
234
David Blaikiea379b1812011-12-20 02:50:00 +0000235void ARMTargetMachine::anchor() { }
236
Eric Christopher80b24ef2014-06-26 19:30:02 +0000237ARMTargetMachine::ARMTargetMachine(const Target &T, StringRef TT, StringRef CPU,
238 StringRef FS, const TargetOptions &Options,
Evan Chengecb29082011-11-16 08:38:26 +0000239 Reloc::Model RM, CodeModel::Model CM,
Eric Christopher80b24ef2014-06-26 19:30:02 +0000240 CodeGenOpt::Level OL, bool isLittle)
241 : ARMBaseTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL, isLittle) {
Rafael Espindola227144c2013-05-13 01:16:13 +0000242 initAsmInfo();
Evan Cheng5190f092010-08-11 07:17:46 +0000243 if (!Subtarget.hasARMOps())
244 report_fatal_error("CPU: '" + Subtarget.getCPUString() + "' does not "
245 "support ARM mode execution!");
Anton Korobeynikov99152f32009-06-26 21:28:53 +0000246}
247
Christian Pirkerdc9ff752014-04-01 15:19:30 +0000248void ARMLETargetMachine::anchor() { }
Christian Pirker2a111602014-03-28 14:35:30 +0000249
Eric Christopher80b24ef2014-06-26 19:30:02 +0000250ARMLETargetMachine::ARMLETargetMachine(const Target &T, StringRef TT,
251 StringRef CPU, StringRef FS,
252 const TargetOptions &Options,
253 Reloc::Model RM, CodeModel::Model CM,
254 CodeGenOpt::Level OL)
255 : ARMTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL, true) {}
Christian Pirker2a111602014-03-28 14:35:30 +0000256
Christian Pirkerdc9ff752014-04-01 15:19:30 +0000257void ARMBETargetMachine::anchor() { }
Christian Pirker2a111602014-03-28 14:35:30 +0000258
Eric Christopher80b24ef2014-06-26 19:30:02 +0000259ARMBETargetMachine::ARMBETargetMachine(const Target &T, StringRef TT,
260 StringRef CPU, StringRef FS,
261 const TargetOptions &Options,
262 Reloc::Model RM, CodeModel::Model CM,
263 CodeGenOpt::Level OL)
264 : ARMTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL, false) {}
Christian Pirker2a111602014-03-28 14:35:30 +0000265
David Blaikiea379b1812011-12-20 02:50:00 +0000266void ThumbTargetMachine::anchor() { }
267
Evan Cheng2129f592011-07-19 06:37:02 +0000268ThumbTargetMachine::ThumbTargetMachine(const Target &T, StringRef TT,
269 StringRef CPU, StringRef FS,
Nick Lewycky50f02cb2011-12-02 22:16:29 +0000270 const TargetOptions &Options,
Evan Chengecb29082011-11-16 08:38:26 +0000271 Reloc::Model RM, CodeModel::Model CM,
Eric Christopher80b24ef2014-06-26 19:30:02 +0000272 CodeGenOpt::Level OL, bool isLittle)
273 : ARMBaseTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL,
274 isLittle) {
Rafael Espindola227144c2013-05-13 01:16:13 +0000275 initAsmInfo();
Anton Korobeynikov99152f32009-06-26 21:28:53 +0000276}
277
Christian Pirkerdc9ff752014-04-01 15:19:30 +0000278void ThumbLETargetMachine::anchor() { }
Christian Pirker2a111602014-03-28 14:35:30 +0000279
Eric Christopher80b24ef2014-06-26 19:30:02 +0000280ThumbLETargetMachine::ThumbLETargetMachine(const Target &T, StringRef TT,
281 StringRef CPU, StringRef FS,
282 const TargetOptions &Options,
283 Reloc::Model RM, CodeModel::Model CM,
284 CodeGenOpt::Level OL)
285 : ThumbTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL, true) {}
Christian Pirker2a111602014-03-28 14:35:30 +0000286
Christian Pirkerdc9ff752014-04-01 15:19:30 +0000287void ThumbBETargetMachine::anchor() { }
Christian Pirker2a111602014-03-28 14:35:30 +0000288
Eric Christopher80b24ef2014-06-26 19:30:02 +0000289ThumbBETargetMachine::ThumbBETargetMachine(const Target &T, StringRef TT,
290 StringRef CPU, StringRef FS,
291 const TargetOptions &Options,
292 Reloc::Model RM, CodeModel::Model CM,
293 CodeGenOpt::Level OL)
294 : ThumbTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL, false) {}
Christian Pirker2a111602014-03-28 14:35:30 +0000295
Andrew Trickccb67362012-02-03 05:12:41 +0000296namespace {
297/// ARM Code Generator Pass Configuration Options.
298class ARMPassConfig : public TargetPassConfig {
299public:
Andrew Trickf8ea1082012-02-04 02:56:59 +0000300 ARMPassConfig(ARMBaseTargetMachine *TM, PassManagerBase &PM)
301 : TargetPassConfig(TM, PM) {}
Andrew Trickccb67362012-02-03 05:12:41 +0000302
303 ARMBaseTargetMachine &getARMTargetMachine() const {
304 return getTM<ARMBaseTargetMachine>();
305 }
306
307 const ARMSubtarget &getARMSubtarget() const {
308 return *getARMTargetMachine().getSubtargetImpl();
309 }
310
Tim Northoverb4ddc082014-05-30 10:09:59 +0000311 void addIRPasses() override;
Craig Topper6bc27bf2014-03-10 02:09:33 +0000312 bool addPreISel() override;
313 bool addInstSelector() override;
Matthias Braun7e37a5f2014-12-11 21:26:47 +0000314 void addPreRegAlloc() override;
315 void addPreSched2() override;
316 void addPreEmitPass() override;
Andrew Trickccb67362012-02-03 05:12:41 +0000317};
318} // namespace
319
Andrew Trickf8ea1082012-02-04 02:56:59 +0000320TargetPassConfig *ARMBaseTargetMachine::createPassConfig(PassManagerBase &PM) {
321 return new ARMPassConfig(this, PM);
Andrew Trickccb67362012-02-03 05:12:41 +0000322}
323
Tim Northoverb4ddc082014-05-30 10:09:59 +0000324void ARMPassConfig::addIRPasses() {
Jonathan Roelofs5e98ff92014-08-21 14:35:47 +0000325 if (TM->Options.ThreadModel == ThreadModel::Single)
326 addPass(createLowerAtomicPass());
327 else
Robin Morisset59c23cd2014-08-21 21:50:01 +0000328 addPass(createAtomicExpandPass(TM));
Tim Northoverc882eb02014-04-03 11:44:58 +0000329
Eric Christopherc40e5ed2014-06-19 21:03:04 +0000330 // Cmpxchg instructions are often used with a subsequent comparison to
331 // determine whether it succeeded. We can exploit existing control-flow in
332 // ldrex/strex loops to simplify this, but it needs tidying up.
333 const ARMSubtarget *Subtarget = &getARMSubtarget();
334 if (Subtarget->hasAnyDataBarrier() && !Subtarget->isThumb1Only())
Tim Northoverb4ddc082014-05-30 10:09:59 +0000335 if (TM->getOptLevel() != CodeGenOpt::None && EnableAtomicTidy)
336 addPass(createCFGSimplificationPass());
Tim Northoverb4ddc082014-05-30 10:09:59 +0000337
338 TargetPassConfig::addIRPasses();
339}
340
341bool ARMPassConfig::addPreISel() {
Ahmed Bougacha82076412015-06-04 20:39:23 +0000342 if ((TM->getOptLevel() != CodeGenOpt::None &&
Ahmed Bougachab96444e2015-04-11 00:06:36 +0000343 EnableGlobalMerge == cl::BOU_UNSET) ||
Ahmed Bougacha82076412015-06-04 20:39:23 +0000344 EnableGlobalMerge == cl::BOU_TRUE) {
Eric Christophered47b222015-02-23 19:28:45 +0000345 // FIXME: This is using the thumb1 only constant value for
346 // maximal global offset for merging globals. We may want
347 // to look into using the old value for non-thumb1 code of
348 // 4095 based on the TargetMachine, but this starts to become
349 // tricky when doing code gen per function.
Ahmed Bougacha82076412015-06-04 20:39:23 +0000350 bool OnlyOptimizeForSize = (TM->getOptLevel() < CodeGenOpt::Aggressive) &&
351 (EnableGlobalMerge == cl::BOU_UNSET);
352 addPass(createGlobalMergePass(TM, 127, OnlyOptimizeForSize));
353 }
Anton Korobeynikov19edda02010-07-24 21:52:08 +0000354
355 return false;
356}
357
Andrew Trickccb67362012-02-03 05:12:41 +0000358bool ARMPassConfig::addInstSelector() {
Bob Wilsonbbd38dd2012-07-02 19:48:31 +0000359 addPass(createARMISelDag(getARMTargetMachine(), getOptLevel()));
Jush Lu47172a02012-09-27 05:21:41 +0000360
Eric Christopher63b44882015-03-05 00:23:40 +0000361 if (Triple(TM->getTargetTriple()).isOSBinFormatELF() &&
Jush Lu47172a02012-09-27 05:21:41 +0000362 TM->Options.EnableFastISel)
363 addPass(createARMGlobalBaseRegPass());
Chris Lattner12e97302006-09-04 04:14:57 +0000364 return false;
365}
Rafael Espindolaf7d4a992006-09-19 15:49:25 +0000366
Matthias Braun7e37a5f2014-12-11 21:26:47 +0000367void ARMPassConfig::addPreRegAlloc() {
Renato Golin4c871392015-03-26 18:38:04 +0000368 if (getOptLevel() != CodeGenOpt::None) {
Matthias Braunb2f23882014-12-11 23:18:03 +0000369 addPass(createMLxExpansionPass());
Renato Golin4c871392015-03-26 18:38:04 +0000370
371 if (EnableARMLoadStoreOpt)
372 addPass(createARMLoadStoreOptimizationPass(/* pre-register alloc */ true));
373
374 if (!DisableA15SDOptimization)
375 addPass(createA15SDOptimizerPass());
Silviu Baranga82dd6ac2013-03-15 18:28:25 +0000376 }
Evan Cheng185c9ef2009-06-13 09:12:55 +0000377}
378
Matthias Braun7e37a5f2014-12-11 21:26:47 +0000379void ARMPassConfig::addPreSched2() {
Evan Chengecb29082011-11-16 08:38:26 +0000380 if (getOptLevel() != CodeGenOpt::None) {
Renato Golin4c871392015-03-26 18:38:04 +0000381 if (EnableARMLoadStoreOpt)
382 addPass(createARMLoadStoreOptimizationPass());
383
Eric Christopher7e70aba2015-03-07 00:12:22 +0000384 addPass(createExecutionDependencyFixPass(&ARM::DPRRegClass));
Eric Christopher7ae11c62010-11-11 20:50:14 +0000385 }
Evan Chengce5a8ca2009-09-30 08:53:01 +0000386
Evan Cheng207b2462009-11-06 23:52:48 +0000387 // Expand some pseudo instructions into multiple instructions to allow
388 // proper scheduling.
Matthias Braunb2f23882014-12-11 23:18:03 +0000389 addPass(createARMExpandPseudoPass());
Evan Cheng207b2462009-11-06 23:52:48 +0000390
Evan Chengecb29082011-11-16 08:38:26 +0000391 if (getOptLevel() != CodeGenOpt::None) {
Eric Christopher63b44882015-03-05 00:23:40 +0000392 // in v8, IfConversion depends on Thumb instruction widths
393 if (getARMSubtarget().restrictIT())
394 addPass(createThumb2SizeReductionPass());
395 if (!getARMSubtarget().isThumb1Only())
Matthias Braunb2f23882014-12-11 23:18:03 +0000396 addPass(&IfConverterID);
Renato Golin4c871392015-03-26 18:38:04 +0000397 }
Eric Christopher63b44882015-03-05 00:23:40 +0000398 addPass(createThumb2ITBlockPass());
Evan Chengce5a8ca2009-09-30 08:53:01 +0000399}
400
Matthias Braun7e37a5f2014-12-11 21:26:47 +0000401void ARMPassConfig::addPreEmitPass() {
Eric Christopher63b44882015-03-05 00:23:40 +0000402 addPass(createThumb2SizeReductionPass());
Evan Cheng7fae11b2011-12-14 02:11:42 +0000403
Eric Christopher63b44882015-03-05 00:23:40 +0000404 // Constant island pass work on unbundled instructions.
405 if (getARMSubtarget().isThumb2())
Matthias Braunb2f23882014-12-11 23:18:03 +0000406 addPass(&UnpackMachineBundlesID);
Evan Cheng0f9cce72009-07-10 01:54:42 +0000407
Davide Italiano141b28912015-05-20 21:40:38 +0000408 // Don't optimize barriers at -O0.
409 if (getOptLevel() != CodeGenOpt::None)
410 addPass(createARMOptimizeBarriersPass());
411
Bob Wilsonbbd38dd2012-07-02 19:48:31 +0000412 addPass(createARMConstantIslandPass());
Rafael Espindolaf7d4a992006-09-19 15:49:25 +0000413}