blob: 4586a9f45bf0296176310fd9fc2a145e99c1cbc8 [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
Jim Grosbachf24f9d92009-08-11 15:33:49 +000040extern "C" void LLVMInitializeARMTarget() {
Daniel Dunbar5680b4f2009-07-25 06:49:55 +000041 // Register the target.
Christian Pirkerdc9ff752014-04-01 15:19:30 +000042 RegisterTargetMachine<ARMLETargetMachine> X(TheARMLETarget);
43 RegisterTargetMachine<ARMBETargetMachine> Y(TheARMBETarget);
44 RegisterTargetMachine<ThumbLETargetMachine> A(TheThumbLETarget);
45 RegisterTargetMachine<ThumbBETargetMachine> B(TheThumbBETarget);
Daniel Dunbar5680b4f2009-07-25 06:49:55 +000046}
Douglas Gregor1b731d52009-06-16 20:12:29 +000047
Aditya Nandakumara2719322014-11-13 09:26:31 +000048static std::unique_ptr<TargetLoweringObjectFile> createTLOF(const Triple &TT) {
49 if (TT.isOSBinFormatMachO())
50 return make_unique<TargetLoweringObjectFileMachO>();
51 if (TT.isOSWindows())
52 return make_unique<TargetLoweringObjectFileCOFF>();
53 return make_unique<ARMElfTargetObjectFile>();
54}
55
Eric Christopher661f2d12014-12-18 02:20:58 +000056static ARMBaseTargetMachine::ARMABI
57computeTargetABI(const Triple &TT, StringRef CPU,
58 const TargetOptions &Options) {
Eric Christopher6e30cd92015-01-14 00:50:31 +000059 if (Options.MCOptions.getABIName().startswith("aapcs"))
Eric Christopher661f2d12014-12-18 02:20:58 +000060 return ARMBaseTargetMachine::ARM_ABI_AAPCS;
Eric Christopher6e30cd92015-01-14 00:50:31 +000061 else if (Options.MCOptions.getABIName().startswith("apcs"))
Eric Christopher661f2d12014-12-18 02:20:58 +000062 return ARMBaseTargetMachine::ARM_ABI_APCS;
63
Eric Christopher6e30cd92015-01-14 00:50:31 +000064 assert(Options.MCOptions.getABIName().empty() &&
65 "Unknown target-abi option!");
Eric Christopher661f2d12014-12-18 02:20:58 +000066
67 ARMBaseTargetMachine::ARMABI TargetABI =
68 ARMBaseTargetMachine::ARM_ABI_UNKNOWN;
69
70 // FIXME: This is duplicated code from the front end and should be unified.
71 if (TT.isOSBinFormatMachO()) {
72 if (TT.getEnvironment() == llvm::Triple::EABI ||
73 (TT.getOS() == llvm::Triple::UnknownOS &&
74 TT.getObjectFormat() == llvm::Triple::MachO) ||
75 CPU.startswith("cortex-m")) {
76 TargetABI = ARMBaseTargetMachine::ARM_ABI_AAPCS;
77 } else {
78 TargetABI = ARMBaseTargetMachine::ARM_ABI_APCS;
79 }
80 } else if (TT.isOSWindows()) {
81 // FIXME: this is invalid for WindowsCE
82 TargetABI = ARMBaseTargetMachine::ARM_ABI_AAPCS;
83 } else {
84 // Select the default based on the platform.
85 switch (TT.getEnvironment()) {
86 case llvm::Triple::Android:
87 case llvm::Triple::GNUEABI:
88 case llvm::Triple::GNUEABIHF:
89 case llvm::Triple::EABIHF:
90 case llvm::Triple::EABI:
91 TargetABI = ARMBaseTargetMachine::ARM_ABI_AAPCS;
92 break;
93 case llvm::Triple::GNU:
94 TargetABI = ARMBaseTargetMachine::ARM_ABI_APCS;
95 break;
96 default:
97 if (TT.getOS() == llvm::Triple::NetBSD)
98 TargetABI = ARMBaseTargetMachine::ARM_ABI_APCS;
99 else
100 TargetABI = ARMBaseTargetMachine::ARM_ABI_AAPCS;
101 break;
102 }
103 }
104
105 return TargetABI;
106}
107
Mehdi Amini93e1ea12015-03-12 00:07:24 +0000108static std::string computeDataLayout(StringRef TT, StringRef CPU,
109 const TargetOptions &Options,
Eric Christopher8b770652015-01-26 19:03:15 +0000110 bool isLittle) {
Mehdi Amini93e1ea12015-03-12 00:07:24 +0000111 const Triple Triple(TT);
112 auto ABI = computeTargetABI(Triple, CPU, Options);
Eric Christopher8b770652015-01-26 19:03:15 +0000113 std::string Ret = "";
114
115 if (isLittle)
116 // Little endian.
117 Ret += "e";
118 else
119 // Big endian.
120 Ret += "E";
121
Mehdi Amini93e1ea12015-03-12 00:07:24 +0000122 Ret += DataLayout::getManglingComponent(Triple);
Eric Christopher8b770652015-01-26 19:03:15 +0000123
124 // Pointers are 32 bits and aligned to 32 bits.
125 Ret += "-p:32:32";
126
127 // ABIs other than APCS have 64 bit integers with natural alignment.
128 if (ABI != ARMBaseTargetMachine::ARM_ABI_APCS)
129 Ret += "-i64:64";
130
131 // We have 64 bits floats. The APCS ABI requires them to be aligned to 32
132 // bits, others to 64 bits. We always try to align to 64 bits.
133 if (ABI == ARMBaseTargetMachine::ARM_ABI_APCS)
134 Ret += "-f64:32:64";
135
136 // We have 128 and 64 bit vectors. The APCS ABI aligns them to 32 bits, others
137 // to 64. We always ty to give them natural alignment.
138 if (ABI == ARMBaseTargetMachine::ARM_ABI_APCS)
139 Ret += "-v64:32:64-v128:32:128";
140 else
141 Ret += "-v128:64:128";
142
143 // Try to align aggregates to 32 bits (the default is 64 bits, which has no
144 // particular hardware support on 32-bit ARM).
145 Ret += "-a:0:32";
146
147 // Integer registers are 32 bits.
148 Ret += "-n32";
149
150 // The stack is 128 bit aligned on NaCl, 64 bit aligned on AAPCS and 32 bit
151 // aligned everywhere else.
Mehdi Amini93e1ea12015-03-12 00:07:24 +0000152 if (Triple.isOSNaCl())
Eric Christopher8b770652015-01-26 19:03:15 +0000153 Ret += "-S128";
154 else if (ABI == ARMBaseTargetMachine::ARM_ABI_AAPCS)
155 Ret += "-S64";
156 else
157 Ret += "-S32";
158
159 return Ret;
160}
161
Evan Cheng9f830142007-02-23 03:14:31 +0000162/// TargetMachine ctor - Create an ARM architecture model.
163///
Evan Cheng2129f592011-07-19 06:37:02 +0000164ARMBaseTargetMachine::ARMBaseTargetMachine(const Target &T, StringRef TT,
165 StringRef CPU, StringRef FS,
Nick Lewycky50f02cb2011-12-02 22:16:29 +0000166 const TargetOptions &Options,
Evan Chengecb29082011-11-16 08:38:26 +0000167 Reloc::Model RM, CodeModel::Model CM,
Eric Christopher80b24ef2014-06-26 19:30:02 +0000168 CodeGenOpt::Level OL, bool isLittle)
Mehdi Amini93e1ea12015-03-12 00:07:24 +0000169 : LLVMTargetMachine(T, computeDataLayout(TT, CPU, Options, isLittle), TT,
170 CPU, FS, Options, RM, CM, OL),
Eric Christopher661f2d12014-12-18 02:20:58 +0000171 TargetABI(computeTargetABI(Triple(TT), CPU, Options)),
Aditya Nandakumara2719322014-11-13 09:26:31 +0000172 TLOF(createTLOF(Triple(getTargetTriple()))),
Eric Christopher3faf2f12014-10-06 06:45:36 +0000173 Subtarget(TT, CPU, FS, *this, isLittle), isLittle(isLittle) {
Tim Northoverf1c31b92013-12-18 14:18:36 +0000174
175 // Default to triple-appropriate float ABI
Nick Lewycky50f02cb2011-12-02 22:16:29 +0000176 if (Options.FloatABIType == FloatABI::Default)
Tim Northover44594ad2013-12-18 09:27:33 +0000177 this->Options.FloatABIType =
178 Subtarget.isTargetHardFloat() ? FloatABI::Hard : FloatABI::Soft;
Evan Cheng66cff402008-10-30 16:10:54 +0000179}
Rafael Espindolaffdc24b2006-05-14 22:18:28 +0000180
Reid Kleckner357600e2014-11-20 23:37:18 +0000181ARMBaseTargetMachine::~ARMBaseTargetMachine() {}
182
Eric Christopher3faf2f12014-10-06 06:45:36 +0000183const ARMSubtarget *
184ARMBaseTargetMachine::getSubtargetImpl(const Function &F) const {
Duncan P. N. Exon Smith2cff9e12015-02-14 02:24:44 +0000185 Attribute CPUAttr = F.getFnAttribute("target-cpu");
186 Attribute FSAttr = F.getFnAttribute("target-features");
Eric Christopher3faf2f12014-10-06 06:45:36 +0000187
188 std::string CPU = !CPUAttr.hasAttribute(Attribute::None)
189 ? CPUAttr.getValueAsString().str()
190 : TargetCPU;
191 std::string FS = !FSAttr.hasAttribute(Attribute::None)
192 ? FSAttr.getValueAsString().str()
193 : TargetFS;
194
195 // FIXME: This is related to the code below to reset the target options,
196 // we need to know whether or not the soft float flag is set on the
197 // function before we can generate a subtarget. We also need to use
198 // it as a key for the subtarget since that can be the only difference
199 // between two functions.
Duncan P. N. Exon Smith2cff9e12015-02-14 02:24:44 +0000200 Attribute SFAttr = F.getFnAttribute("use-soft-float");
Eric Christopher3faf2f12014-10-06 06:45:36 +0000201 bool SoftFloat = !SFAttr.hasAttribute(Attribute::None)
202 ? SFAttr.getValueAsString() == "true"
203 : Options.UseSoftFloat;
204
205 auto &I = SubtargetMap[CPU + FS + (SoftFloat ? "use-soft-float=true"
206 : "use-soft-float=false")];
207 if (!I) {
208 // This needs to be done before we create a new subtarget since any
209 // creation will depend on the TM and the code generation flags on the
210 // function that reside in TargetOptions.
211 resetTargetOptions(F);
212 I = llvm::make_unique<ARMSubtarget>(TargetTriple, CPU, FS, *this, isLittle);
213 }
214 return I.get();
215}
216
Chandler Carruth8b04c0d2015-02-01 13:20:00 +0000217TargetIRAnalysis ARMBaseTargetMachine::getTargetIRAnalysis() {
218 return TargetIRAnalysis(
219 [this](Function &F) { return TargetTransformInfo(ARMTTIImpl(this, F)); });
Chandler Carruth664e3542013-01-07 01:37:14 +0000220}
221
222
David Blaikiea379b1812011-12-20 02:50:00 +0000223void ARMTargetMachine::anchor() { }
224
Eric Christopher80b24ef2014-06-26 19:30:02 +0000225ARMTargetMachine::ARMTargetMachine(const Target &T, StringRef TT, StringRef CPU,
226 StringRef FS, const TargetOptions &Options,
Evan Chengecb29082011-11-16 08:38:26 +0000227 Reloc::Model RM, CodeModel::Model CM,
Eric Christopher80b24ef2014-06-26 19:30:02 +0000228 CodeGenOpt::Level OL, bool isLittle)
229 : ARMBaseTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL, isLittle) {
Rafael Espindola227144c2013-05-13 01:16:13 +0000230 initAsmInfo();
Evan Cheng5190f092010-08-11 07:17:46 +0000231 if (!Subtarget.hasARMOps())
232 report_fatal_error("CPU: '" + Subtarget.getCPUString() + "' does not "
233 "support ARM mode execution!");
Anton Korobeynikov99152f32009-06-26 21:28:53 +0000234}
235
Christian Pirkerdc9ff752014-04-01 15:19:30 +0000236void ARMLETargetMachine::anchor() { }
Christian Pirker2a111602014-03-28 14:35:30 +0000237
Eric Christopher80b24ef2014-06-26 19:30:02 +0000238ARMLETargetMachine::ARMLETargetMachine(const Target &T, StringRef TT,
239 StringRef CPU, StringRef FS,
240 const TargetOptions &Options,
241 Reloc::Model RM, CodeModel::Model CM,
242 CodeGenOpt::Level OL)
243 : ARMTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL, true) {}
Christian Pirker2a111602014-03-28 14:35:30 +0000244
Christian Pirkerdc9ff752014-04-01 15:19:30 +0000245void ARMBETargetMachine::anchor() { }
Christian Pirker2a111602014-03-28 14:35:30 +0000246
Eric Christopher80b24ef2014-06-26 19:30:02 +0000247ARMBETargetMachine::ARMBETargetMachine(const Target &T, StringRef TT,
248 StringRef CPU, StringRef FS,
249 const TargetOptions &Options,
250 Reloc::Model RM, CodeModel::Model CM,
251 CodeGenOpt::Level OL)
252 : ARMTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL, false) {}
Christian Pirker2a111602014-03-28 14:35:30 +0000253
David Blaikiea379b1812011-12-20 02:50:00 +0000254void ThumbTargetMachine::anchor() { }
255
Evan Cheng2129f592011-07-19 06:37:02 +0000256ThumbTargetMachine::ThumbTargetMachine(const Target &T, StringRef TT,
257 StringRef CPU, StringRef FS,
Nick Lewycky50f02cb2011-12-02 22:16:29 +0000258 const TargetOptions &Options,
Evan Chengecb29082011-11-16 08:38:26 +0000259 Reloc::Model RM, CodeModel::Model CM,
Eric Christopher80b24ef2014-06-26 19:30:02 +0000260 CodeGenOpt::Level OL, bool isLittle)
261 : ARMBaseTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL,
262 isLittle) {
Rafael Espindola227144c2013-05-13 01:16:13 +0000263 initAsmInfo();
Anton Korobeynikov99152f32009-06-26 21:28:53 +0000264}
265
Christian Pirkerdc9ff752014-04-01 15:19:30 +0000266void ThumbLETargetMachine::anchor() { }
Christian Pirker2a111602014-03-28 14:35:30 +0000267
Eric Christopher80b24ef2014-06-26 19:30:02 +0000268ThumbLETargetMachine::ThumbLETargetMachine(const Target &T, StringRef TT,
269 StringRef CPU, StringRef FS,
270 const TargetOptions &Options,
271 Reloc::Model RM, CodeModel::Model CM,
272 CodeGenOpt::Level OL)
273 : ThumbTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL, true) {}
Christian Pirker2a111602014-03-28 14:35:30 +0000274
Christian Pirkerdc9ff752014-04-01 15:19:30 +0000275void ThumbBETargetMachine::anchor() { }
Christian Pirker2a111602014-03-28 14:35:30 +0000276
Eric Christopher80b24ef2014-06-26 19:30:02 +0000277ThumbBETargetMachine::ThumbBETargetMachine(const Target &T, StringRef TT,
278 StringRef CPU, StringRef FS,
279 const TargetOptions &Options,
280 Reloc::Model RM, CodeModel::Model CM,
281 CodeGenOpt::Level OL)
282 : ThumbTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL, false) {}
Christian Pirker2a111602014-03-28 14:35:30 +0000283
Andrew Trickccb67362012-02-03 05:12:41 +0000284namespace {
285/// ARM Code Generator Pass Configuration Options.
286class ARMPassConfig : public TargetPassConfig {
287public:
Andrew Trickf8ea1082012-02-04 02:56:59 +0000288 ARMPassConfig(ARMBaseTargetMachine *TM, PassManagerBase &PM)
289 : TargetPassConfig(TM, PM) {}
Andrew Trickccb67362012-02-03 05:12:41 +0000290
291 ARMBaseTargetMachine &getARMTargetMachine() const {
292 return getTM<ARMBaseTargetMachine>();
293 }
294
295 const ARMSubtarget &getARMSubtarget() const {
296 return *getARMTargetMachine().getSubtargetImpl();
297 }
298
Tim Northoverb4ddc082014-05-30 10:09:59 +0000299 void addIRPasses() override;
Craig Topper6bc27bf2014-03-10 02:09:33 +0000300 bool addPreISel() override;
301 bool addInstSelector() override;
Matthias Braun7e37a5f2014-12-11 21:26:47 +0000302 void addPreRegAlloc() override;
303 void addPreSched2() override;
304 void addPreEmitPass() override;
Andrew Trickccb67362012-02-03 05:12:41 +0000305};
306} // namespace
307
Andrew Trickf8ea1082012-02-04 02:56:59 +0000308TargetPassConfig *ARMBaseTargetMachine::createPassConfig(PassManagerBase &PM) {
309 return new ARMPassConfig(this, PM);
Andrew Trickccb67362012-02-03 05:12:41 +0000310}
311
Tim Northoverb4ddc082014-05-30 10:09:59 +0000312void ARMPassConfig::addIRPasses() {
Jonathan Roelofs5e98ff92014-08-21 14:35:47 +0000313 if (TM->Options.ThreadModel == ThreadModel::Single)
314 addPass(createLowerAtomicPass());
315 else
Robin Morisset59c23cd2014-08-21 21:50:01 +0000316 addPass(createAtomicExpandPass(TM));
Tim Northoverc882eb02014-04-03 11:44:58 +0000317
Eric Christopherc40e5ed2014-06-19 21:03:04 +0000318 // Cmpxchg instructions are often used with a subsequent comparison to
319 // determine whether it succeeded. We can exploit existing control-flow in
320 // ldrex/strex loops to simplify this, but it needs tidying up.
321 const ARMSubtarget *Subtarget = &getARMSubtarget();
322 if (Subtarget->hasAnyDataBarrier() && !Subtarget->isThumb1Only())
Tim Northoverb4ddc082014-05-30 10:09:59 +0000323 if (TM->getOptLevel() != CodeGenOpt::None && EnableAtomicTidy)
324 addPass(createCFGSimplificationPass());
Tim Northoverb4ddc082014-05-30 10:09:59 +0000325
326 TargetPassConfig::addIRPasses();
327}
328
329bool ARMPassConfig::addPreISel() {
Tim Northoverf804c172014-02-18 11:17:29 +0000330 if (TM->getOptLevel() != CodeGenOpt::None)
Eric Christophered47b222015-02-23 19:28:45 +0000331 // FIXME: This is using the thumb1 only constant value for
332 // maximal global offset for merging globals. We may want
333 // to look into using the old value for non-thumb1 code of
334 // 4095 based on the TargetMachine, but this starts to become
335 // tricky when doing code gen per function.
336 addPass(createGlobalMergePass(TM, 127));
Anton Korobeynikov19edda02010-07-24 21:52:08 +0000337
338 return false;
339}
340
Andrew Trickccb67362012-02-03 05:12:41 +0000341bool ARMPassConfig::addInstSelector() {
Bob Wilsonbbd38dd2012-07-02 19:48:31 +0000342 addPass(createARMISelDag(getARMTargetMachine(), getOptLevel()));
Jush Lu47172a02012-09-27 05:21:41 +0000343
Eric Christopher63b44882015-03-05 00:23:40 +0000344 if (Triple(TM->getTargetTriple()).isOSBinFormatELF() &&
Jush Lu47172a02012-09-27 05:21:41 +0000345 TM->Options.EnableFastISel)
346 addPass(createARMGlobalBaseRegPass());
Chris Lattner12e97302006-09-04 04:14:57 +0000347 return false;
348}
Rafael Espindolaf7d4a992006-09-19 15:49:25 +0000349
Matthias Braun7e37a5f2014-12-11 21:26:47 +0000350void ARMPassConfig::addPreRegAlloc() {
James Molloyf6419cf2014-06-16 16:42:53 +0000351 if (getOptLevel() != CodeGenOpt::None)
Matthias Braunb2f23882014-12-11 23:18:03 +0000352 addPass(createARMLoadStoreOptimizationPass(true));
Eric Christopher63b44882015-03-05 00:23:40 +0000353 if (getOptLevel() != CodeGenOpt::None)
Matthias Braunb2f23882014-12-11 23:18:03 +0000354 addPass(createMLxExpansionPass());
Eric Christopher63b44882015-03-05 00:23:40 +0000355 if (getOptLevel() != CodeGenOpt::None && !DisableA15SDOptimization) {
Silviu Baranga82dd6ac2013-03-15 18:28:25 +0000356 addPass(createA15SDOptimizerPass());
357 }
Evan Cheng185c9ef2009-06-13 09:12:55 +0000358}
359
Matthias Braun7e37a5f2014-12-11 21:26:47 +0000360void ARMPassConfig::addPreSched2() {
Evan Chengecb29082011-11-16 08:38:26 +0000361 if (getOptLevel() != CodeGenOpt::None) {
Matthias Braunb2f23882014-12-11 23:18:03 +0000362 addPass(createARMLoadStoreOptimizationPass());
Eric Christopher7e70aba2015-03-07 00:12:22 +0000363 addPass(createExecutionDependencyFixPass(&ARM::DPRRegClass));
Eric Christopher7ae11c62010-11-11 20:50:14 +0000364 }
Evan Chengce5a8ca2009-09-30 08:53:01 +0000365
Evan Cheng207b2462009-11-06 23:52:48 +0000366 // Expand some pseudo instructions into multiple instructions to allow
367 // proper scheduling.
Matthias Braunb2f23882014-12-11 23:18:03 +0000368 addPass(createARMExpandPseudoPass());
Evan Cheng207b2462009-11-06 23:52:48 +0000369
Evan Chengecb29082011-11-16 08:38:26 +0000370 if (getOptLevel() != CodeGenOpt::None) {
Eric Christopher63b44882015-03-05 00:23:40 +0000371 // in v8, IfConversion depends on Thumb instruction widths
372 if (getARMSubtarget().restrictIT())
373 addPass(createThumb2SizeReductionPass());
374 if (!getARMSubtarget().isThumb1Only())
Matthias Braunb2f23882014-12-11 23:18:03 +0000375 addPass(&IfConverterID);
Eric Christopher63b44882015-03-05 00:23:40 +0000376 }
377 addPass(createThumb2ITBlockPass());
Evan Chengce5a8ca2009-09-30 08:53:01 +0000378}
379
Matthias Braun7e37a5f2014-12-11 21:26:47 +0000380void ARMPassConfig::addPreEmitPass() {
Eric Christopher63b44882015-03-05 00:23:40 +0000381 addPass(createThumb2SizeReductionPass());
Evan Cheng7fae11b2011-12-14 02:11:42 +0000382
Eric Christopher63b44882015-03-05 00:23:40 +0000383 // Constant island pass work on unbundled instructions.
384 if (getARMSubtarget().isThumb2())
Matthias Braunb2f23882014-12-11 23:18:03 +0000385 addPass(&UnpackMachineBundlesID);
Evan Cheng0f9cce72009-07-10 01:54:42 +0000386
Matthias Braunb2f23882014-12-11 23:18:03 +0000387 addPass(createARMOptimizeBarriersPass());
Bob Wilsonbbd38dd2012-07-02 19:48:31 +0000388 addPass(createARMConstantIslandPass());
Rafael Espindolaf7d4a992006-09-19 15:49:25 +0000389}