blob: e096d21797c004380affcae38030da42a121f3c9 [file] [log] [blame]
Jia Liub22310f2012-02-18 12:03:15 +00001//===-- ARMSubtarget.cpp - ARM Subtarget Information ----------------------===//
Evan Cheng10043e22007-01-19 07:51:42 +00002//
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
6// License. See LICENSE.TXT for details.
Evan Cheng10043e22007-01-19 07:51:42 +00007//
8//===----------------------------------------------------------------------===//
9//
Evan Cheng0d639a22011-07-01 21:01:15 +000010// This file implements the ARM specific subclass of TargetSubtargetInfo.
Evan Cheng10043e22007-01-19 07:51:42 +000011//
12//===----------------------------------------------------------------------===//
13
14#include "ARMSubtarget.h"
Andrew Trickab722bd2012-09-18 03:18:56 +000015#include "ARMBaseInstrInfo.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000016#include "ARMBaseRegisterInfo.h"
Bill Wendling5a92eec2013-02-15 22:41:25 +000017#include "llvm/IR/Attributes.h"
Bill Wendling5a92eec2013-02-15 22:41:25 +000018#include "llvm/IR/Function.h"
Chandler Carruth8a8cd2b2014-01-07 11:48:04 +000019#include "llvm/IR/GlobalValue.h"
Bob Wilson45825302009-06-22 21:01:46 +000020#include "llvm/Support/CommandLine.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000021#include "llvm/Target/TargetInstrInfo.h"
Renato Golinb4dd6c52013-03-21 18:47:47 +000022#include "llvm/Target/TargetOptions.h"
Evan Cheng54b68e32011-07-01 20:45:01 +000023
Chandler Carruthe96dd892014-04-21 22:55:11 +000024#define DEBUG_TYPE "arm-subtarget"
25
Evan Cheng54b68e32011-07-01 20:45:01 +000026#define GET_SUBTARGETINFO_TARGET_DESC
Evan Cheng4d1ca962011-07-08 01:53:10 +000027#define GET_SUBTARGETINFO_CTOR
Evan Chengc9c090d2011-07-01 22:36:09 +000028#include "ARMGenSubtargetInfo.inc"
Evan Cheng54b68e32011-07-01 20:45:01 +000029
Evan Cheng10043e22007-01-19 07:51:42 +000030using namespace llvm;
31
Bob Wilson45825302009-06-22 21:01:46 +000032static cl::opt<bool>
33ReserveR9("arm-reserve-r9", cl::Hidden,
34 cl::desc("Reserve R9, making it unavailable as GPR"));
35
Anton Korobeynikov25229082009-11-24 00:44:37 +000036static cl::opt<bool>
Renato Golinca570632013-08-15 20:54:38 +000037ArmUseMOVT("arm-use-movt", cl::init(true), cl::Hidden);
Anton Korobeynikov25229082009-11-24 00:44:37 +000038
Bob Wilson3dc97322010-09-28 04:09:35 +000039static cl::opt<bool>
Bob Wilsone8a549c2012-09-29 21:43:49 +000040UseFusedMulOps("arm-use-mulops",
41 cl::init(true), cl::Hidden);
42
JF Bastien97b08c402013-05-17 23:49:01 +000043enum AlignMode {
44 DefaultAlign,
45 StrictAlign,
46 NoStrictAlign
47};
48
49static cl::opt<AlignMode>
50Align(cl::desc("Load/store alignment support"),
51 cl::Hidden, cl::init(DefaultAlign),
52 cl::values(
53 clEnumValN(DefaultAlign, "arm-default-align",
54 "Generate unaligned accesses only on hardware/OS "
55 "combinations that are known to support them"),
56 clEnumValN(StrictAlign, "arm-strict-align",
57 "Disallow all unaligned memory accesses"),
58 clEnumValN(NoStrictAlign, "arm-no-strict-align",
59 "Allow unaligned memory accesses"),
60 clEnumValEnd));
Bob Wilson3dc97322010-09-28 04:09:35 +000061
Weiming Zhao0da5cc02013-11-13 18:29:49 +000062enum ITMode {
63 DefaultIT,
64 RestrictedIT,
65 NoRestrictedIT
66};
67
68static cl::opt<ITMode>
69IT(cl::desc("IT block support"), cl::Hidden, cl::init(DefaultIT),
70 cl::ZeroOrMore,
71 cl::values(clEnumValN(DefaultIT, "arm-default-it",
72 "Generate IT block based on arch"),
73 clEnumValN(RestrictedIT, "arm-restrict-it",
74 "Disallow deprecated IT based on ARMv8"),
75 clEnumValN(NoRestrictedIT, "arm-no-restrict-it",
76 "Allow IT blocks based on ARMv7"),
77 clEnumValEnd));
78
Evan Chengfe6e4052011-06-30 01:53:36 +000079ARMSubtarget::ARMSubtarget(const std::string &TT, const std::string &CPU,
Christian Pirker2a111602014-03-28 14:35:30 +000080 const std::string &FS, bool IsLittle,
81 const TargetOptions &Options)
Evan Cheng1a72add62011-07-07 07:07:08 +000082 : ARMGenSubtargetInfo(TT, CPU, FS)
Evan Chengbf407072010-09-10 01:29:16 +000083 , ARMProcFamily(Others)
Amara Emerson330afb52013-09-23 14:26:15 +000084 , ARMProcClass(None)
Lauro Ramos Venancio048e16ff2007-02-13 19:52:28 +000085 , stackAlignment(4)
Evan Chengfe6e4052011-06-30 01:53:36 +000086 , CPUString(CPU)
Christian Pirker2a111602014-03-28 14:35:30 +000087 , IsLittle(IsLittle)
Evan Chenge45d6852011-01-11 21:46:47 +000088 , TargetTriple(TT)
Renato Golinb4dd6c52013-03-21 18:47:47 +000089 , Options(Options)
Rafael Espindolad89b16d2014-01-02 13:40:08 +000090 , TargetABI(ARM_ABI_UNKNOWN) {
Bill Wendling61375d82013-02-16 01:36:26 +000091 initializeEnvironment();
Bill Wendling5a92eec2013-02-15 22:41:25 +000092 resetSubtargetFeatures(CPU, FS);
93}
94
Bill Wendling61375d82013-02-16 01:36:26 +000095void ARMSubtarget::initializeEnvironment() {
96 HasV4TOps = false;
97 HasV5TOps = false;
98 HasV5TEOps = false;
99 HasV6Ops = false;
Amara Emerson5035ee02013-10-07 16:55:23 +0000100 HasV6MOps = false;
Bill Wendling61375d82013-02-16 01:36:26 +0000101 HasV6T2Ops = false;
102 HasV7Ops = false;
Joey Goulyb3f550e2013-06-26 16:58:26 +0000103 HasV8Ops = false;
Bill Wendling61375d82013-02-16 01:36:26 +0000104 HasVFPv2 = false;
105 HasVFPv3 = false;
106 HasVFPv4 = false;
Joey Goulyccd04892013-09-13 13:46:57 +0000107 HasFPARMv8 = false;
Bill Wendling61375d82013-02-16 01:36:26 +0000108 HasNEON = false;
Tim Northoverdee86042013-12-02 14:46:26 +0000109 MinSize = false;
Bill Wendling61375d82013-02-16 01:36:26 +0000110 UseNEONForSinglePrecisionFP = false;
111 UseMulOps = UseFusedMulOps;
112 SlowFPVMLx = false;
113 HasVMLxForwarding = false;
114 SlowFPBrcc = false;
115 InThumbMode = false;
116 HasThumb2 = false;
Bill Wendling61375d82013-02-16 01:36:26 +0000117 NoARM = false;
118 PostRAScheduler = false;
119 IsR9Reserved = ReserveR9;
120 UseMovt = false;
121 SupportsTailCall = false;
122 HasFP16 = false;
123 HasD16 = false;
124 HasHardwareDivide = false;
125 HasHardwareDivideInARM = false;
126 HasT2ExtractPack = false;
127 HasDataBarrier = false;
128 Pref32BitThumb = false;
129 AvoidCPSRPartialUpdate = false;
130 AvoidMOVsShifterOperand = false;
131 HasRAS = false;
132 HasMPExtension = false;
Bradley Smith25219752013-11-01 13:27:35 +0000133 HasVirtualization = false;
Bill Wendling61375d82013-02-16 01:36:26 +0000134 FPOnlySP = false;
Tim Northovercedd4812013-05-23 19:11:14 +0000135 HasPerfMon = false;
Tim Northoverc6047652013-04-10 12:08:35 +0000136 HasTrustZone = false;
Amara Emerson33089092013-09-19 11:59:01 +0000137 HasCrypto = false;
Amara Emersonf9a67fc2013-10-29 16:54:52 +0000138 HasCRC = false;
Tim Northover13510302014-04-01 13:22:02 +0000139 HasZeroCycleZeroing = false;
Bill Wendling61375d82013-02-16 01:36:26 +0000140 AllowsUnalignedMem = false;
141 Thumb2DSP = false;
142 UseNaClTrap = false;
Renato Golinb4dd6c52013-03-21 18:47:47 +0000143 UnsafeFPMath = false;
Bill Wendling61375d82013-02-16 01:36:26 +0000144}
145
Bill Wendling5a92eec2013-02-15 22:41:25 +0000146void ARMSubtarget::resetSubtargetFeatures(const MachineFunction *MF) {
147 AttributeSet FnAttrs = MF->getFunction()->getAttributes();
148 Attribute CPUAttr = FnAttrs.getAttribute(AttributeSet::FunctionIndex,
149 "target-cpu");
150 Attribute FSAttr = FnAttrs.getAttribute(AttributeSet::FunctionIndex,
151 "target-features");
152 std::string CPU =
153 !CPUAttr.hasAttribute(Attribute::None) ?CPUAttr.getValueAsString() : "";
154 std::string FS =
155 !FSAttr.hasAttribute(Attribute::None) ? FSAttr.getValueAsString() : "";
Bill Wendling61375d82013-02-16 01:36:26 +0000156 if (!FS.empty()) {
157 initializeEnvironment();
Bill Wendling5a92eec2013-02-15 22:41:25 +0000158 resetSubtargetFeatures(CPU, FS);
Bill Wendling61375d82013-02-16 01:36:26 +0000159 }
Tim Northoverdee86042013-12-02 14:46:26 +0000160
161 MinSize =
162 FnAttrs.hasAttribute(AttributeSet::FunctionIndex, Attribute::MinSize);
Bill Wendling5a92eec2013-02-15 22:41:25 +0000163}
164
165void ARMSubtarget::resetSubtargetFeatures(StringRef CPU, StringRef FS) {
Tilmann Scheller63872ce2013-09-02 17:09:01 +0000166 if (CPUString.empty()) {
167 if (isTargetIOS() && TargetTriple.getArchName().endswith("v7s"))
168 // Default to the Swift CPU when targeting armv7s/thumbv7s.
169 CPUString = "swift";
170 else
171 CPUString = "generic";
172 }
Evan Chengec415ef2009-03-08 04:02:49 +0000173
Evan Cheng0b33a322011-06-30 02:12:44 +0000174 // Insert the architecture feature derived from the target triple into the
175 // feature string. This is important for setting features that are implied
176 // based on the architecture version.
Bill Wendling5a92eec2013-02-15 22:41:25 +0000177 std::string ArchFS = ARM_MC::ParseARMTriple(TargetTriple.getTriple(),
178 CPUString);
Evan Cheng2bd65362011-07-07 00:08:19 +0000179 if (!FS.empty()) {
180 if (!ArchFS.empty())
Bill Wendling5a92eec2013-02-15 22:41:25 +0000181 ArchFS = ArchFS + "," + FS.str();
Evan Cheng2bd65362011-07-07 00:08:19 +0000182 else
183 ArchFS = FS;
184 }
Evan Cheng1a72add62011-07-07 07:07:08 +0000185 ParseSubtargetFeatures(CPUString, ArchFS);
Evan Cheng2bd65362011-07-07 00:08:19 +0000186
Joerg Sonnenberger002a1472013-12-13 11:16:00 +0000187 // FIXME: This used enable V6T2 support implicitly for Thumb2 mode.
188 // Assert this for now to make the change obvious.
189 assert(hasV6T2Ops() || !hasThumb2());
Bob Wilsond0046ca2010-11-09 22:50:47 +0000190
Andrew Trick352abc12012-08-08 02:44:16 +0000191 // Keep a pointer to static instruction cost data for the specified CPU.
192 SchedModel = getSchedModelForCPU(CPUString);
193
Evan Cheng54b68e32011-07-01 20:45:01 +0000194 // Initialize scheduling itinerary for the specified CPU.
195 InstrItins = getInstrItineraryForCPU(CPUString);
196
Rafael Espindolad89b16d2014-01-02 13:40:08 +0000197 if (TargetABI == ARM_ABI_UNKNOWN) {
198 switch (TargetTriple.getEnvironment()) {
199 case Triple::Android:
200 case Triple::EABI:
201 case Triple::EABIHF:
202 case Triple::GNUEABI:
203 case Triple::GNUEABIHF:
Joerg Sonnenberger74669792013-12-15 00:12:52 +0000204 TargetABI = ARM_ABI_AAPCS;
Rafael Espindolad89b16d2014-01-02 13:40:08 +0000205 break;
206 default:
Saleem Abdulrasool35476332014-03-06 20:47:11 +0000207 if ((isTargetIOS() && isMClass()) ||
208 (TargetTriple.isOSBinFormatMachO() &&
209 TargetTriple.getOS() == Triple::UnknownOS))
Rafael Espindolad89b16d2014-01-02 13:40:08 +0000210 TargetABI = ARM_ABI_AAPCS;
211 else
212 TargetABI = ARM_ABI_APCS;
213 break;
214 }
Joerg Sonnenberger74669792013-12-15 00:12:52 +0000215 }
Evan Cheng1a72add62011-07-07 07:07:08 +0000216
Saleem Abdulrasoolcd130822014-04-02 20:32:05 +0000217 // FIXME: this is invalid for WindowsCE
218 if (isTargetWindows()) {
219 TargetABI = ARM_ABI_AAPCS;
220 NoARM = true;
221 }
222
Lauro Ramos Venancio048e16ff2007-02-13 19:52:28 +0000223 if (isAAPCS_ABI())
224 stackAlignment = 8;
Mark Seabornbe266aa2014-02-16 18:59:48 +0000225 if (isTargetNaCl())
226 stackAlignment = 16;
Lauro Ramos Venancio048e16ff2007-02-13 19:52:28 +0000227
Renato Golinca570632013-08-15 20:54:38 +0000228 UseMovt = hasV6T2Ops() && ArmUseMOVT;
229
Tim Northoverd6a729b2014-01-06 14:28:05 +0000230 if (isTargetMachO()) {
Evan Cheng8b2bda02011-07-07 03:55:05 +0000231 IsR9Reserved = ReserveR9 | !HasV6Ops;
Tim Northoverd6a729b2014-01-06 14:28:05 +0000232 SupportsTailCall = !isTargetIOS() || !getTargetTriple().isOSVersionLT(5, 0);
Saleem Abdulrasoolec1ec1b2014-03-11 15:09:44 +0000233 } else {
Tim Northoverd6a729b2014-01-06 14:28:05 +0000234 IsR9Reserved = ReserveR9;
Saleem Abdulrasoolec1ec1b2014-03-11 15:09:44 +0000235 SupportsTailCall = !isThumb1Only();
236 }
David Goodwin9a051a52009-10-01 21:46:35 +0000237
Evan Cheng03da4db2009-10-16 06:11:08 +0000238 if (!isThumb() || hasThumb2())
239 PostRAScheduler = true;
Bob Wilson3dc97322010-09-28 04:09:35 +0000240
JF Bastien97b08c402013-05-17 23:49:01 +0000241 switch (Align) {
242 case DefaultAlign:
243 // Assume pre-ARMv6 doesn't support unaligned accesses.
244 //
245 // ARMv6 may or may not support unaligned accesses depending on the
246 // SCTLR.U bit, which is architecture-specific. We assume ARMv6
Jim Grosbach4a1a9ce2014-04-02 19:28:13 +0000247 // Darwin and NetBSD targets support unaligned accesses, and others don't.
JF Bastien97b08c402013-05-17 23:49:01 +0000248 //
249 // ARMv7 always has SCTLR.U set to 1, but it has a new SCTLR.A bit
250 // which raises an alignment fault on unaligned accesses. Linux
251 // defaults this bit to 0 and handles it as a system-wide (not
252 // per-process) setting. It is therefore safe to assume that ARMv7+
253 // Linux targets support unaligned accesses. The same goes for NaCl.
254 //
255 // The above behavior is consistent with GCC.
Joerg Sonnenberger4455ffc2014-02-02 21:18:36 +0000256 AllowsUnalignedMem =
257 (hasV7Ops() && (isTargetLinux() || isTargetNaCl() ||
258 isTargetNetBSD())) ||
259 (hasV6Ops() && (isTargetMachO() || isTargetNetBSD()));
Jim Grosbach4a1a9ce2014-04-02 19:28:13 +0000260 // The one exception is cortex-m0, which despite being v6, does not
261 // support unaligned accesses. Rather than make the above boolean
262 // expression even more obtuse, just override the value here.
263 if (isThumb1Only() && isMClass())
264 AllowsUnalignedMem = false;
JF Bastien97b08c402013-05-17 23:49:01 +0000265 break;
266 case StrictAlign:
267 AllowsUnalignedMem = false;
268 break;
269 case NoStrictAlign:
270 AllowsUnalignedMem = true;
271 break;
272 }
Renato Golinb4dd6c52013-03-21 18:47:47 +0000273
Weiming Zhao0da5cc02013-11-13 18:29:49 +0000274 switch (IT) {
275 case DefaultIT:
276 RestrictIT = hasV8Ops() ? true : false;
277 break;
278 case RestrictedIT:
279 RestrictIT = true;
280 break;
281 case NoRestrictedIT:
282 RestrictIT = false;
283 break;
284 }
285
Renato Golinb4dd6c52013-03-21 18:47:47 +0000286 // NEON f32 ops are non-IEEE 754 compliant. Darwin is ok with it by default.
287 uint64_t Bits = getFeatureBits();
288 if ((Bits & ARM::ProcA5 || Bits & ARM::ProcA8) && // Where this matters
289 (Options.UnsafeFPMath || isTargetDarwin()))
290 UseNEONForSinglePrecisionFP = true;
Evan Cheng10043e22007-01-19 07:51:42 +0000291}
Evan Cheng43b9ca62009-08-28 23:18:09 +0000292
293/// GVIsIndirectSymbol - true if the GV will be accessed via an indirect symbol.
Evan Cheng1b389522009-09-03 07:04:02 +0000294bool
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000295ARMSubtarget::GVIsIndirectSymbol(const GlobalValue *GV,
296 Reloc::Model RelocM) const {
Evan Cheng1b389522009-09-03 07:04:02 +0000297 if (RelocM == Reloc::Static)
Evan Cheng43b9ca62009-08-28 23:18:09 +0000298 return false;
Evan Cheng1b389522009-09-03 07:04:02 +0000299
Jeffrey Yasskin091217b2010-01-27 20:34:15 +0000300 // Materializable GVs (in JIT lazy compilation mode) do not require an extra
301 // load from stub.
Evan Cheng2ce66302011-02-22 06:58:34 +0000302 bool isDecl = GV->hasAvailableExternallyLinkage();
303 if (GV->isDeclaration() && !GV->isMaterializable())
304 isDecl = true;
Evan Cheng1b389522009-09-03 07:04:02 +0000305
Tim Northoverd6a729b2014-01-06 14:28:05 +0000306 if (!isTargetMachO()) {
Evan Cheng1b389522009-09-03 07:04:02 +0000307 // Extra load is needed for all externally visible.
308 if (GV->hasLocalLinkage() || GV->hasHiddenVisibility())
309 return false;
310 return true;
311 } else {
312 if (RelocM == Reloc::PIC_) {
313 // If this is a strong reference to a definition, it is definitely not
314 // through a stub.
315 if (!isDecl && !GV->isWeakForLinker())
316 return false;
317
318 // Unless we have a symbol with hidden visibility, we have to go through a
319 // normal $non_lazy_ptr stub because this symbol might be resolved late.
320 if (!GV->hasHiddenVisibility()) // Non-hidden $non_lazy_ptr reference.
321 return true;
322
323 // If symbol visibility is hidden, we have a stub for common symbol
324 // references and external declarations.
325 if (isDecl || GV->hasCommonLinkage())
326 // Hidden $non_lazy_ptr reference.
327 return true;
328
329 return false;
330 } else {
331 // If this is a strong reference to a definition, it is definitely not
332 // through a stub.
333 if (!isDecl && !GV->isWeakForLinker())
334 return false;
Andrew Trickc416ba62010-12-24 04:28:06 +0000335
Evan Cheng1b389522009-09-03 07:04:02 +0000336 // Unless we have a symbol with hidden visibility, we have to go through a
337 // normal $non_lazy_ptr stub because this symbol might be resolved late.
338 if (!GV->hasHiddenVisibility()) // Non-hidden $non_lazy_ptr reference.
339 return true;
340 }
341 }
342
343 return false;
Evan Cheng43b9ca62009-08-28 23:18:09 +0000344}
David Goodwin0d412c22009-11-10 00:48:55 +0000345
Owen Andersona3181e22010-09-28 21:57:50 +0000346unsigned ARMSubtarget::getMispredictionPenalty() const {
Andrew Trick352abc12012-08-08 02:44:16 +0000347 return SchedModel->MispredictPenalty;
Owen Andersona3181e22010-09-28 21:57:50 +0000348}
349
Bob Wilsone7dde0c2013-11-03 06:14:38 +0000350bool ARMSubtarget::hasSinCos() const {
351 return getTargetTriple().getOS() == Triple::IOS &&
352 !getTargetTriple().isOSVersionLT(7, 0);
353}
354
David Goodwin0d412c22009-11-10 00:48:55 +0000355bool ARMSubtarget::enablePostRAScheduler(
356 CodeGenOpt::Level OptLevel,
Evan Cheng0d639a22011-07-01 21:01:15 +0000357 TargetSubtargetInfo::AntiDepBreakMode& Mode,
David Goodwinb9fe5d52009-11-13 19:52:48 +0000358 RegClassVector& CriticalPathRCs) const {
Andrew Trickd24698c2013-09-25 00:26:16 +0000359 Mode = TargetSubtargetInfo::ANTIDEP_NONE;
David Goodwin0d412c22009-11-10 00:48:55 +0000360 return PostRAScheduler && OptLevel >= CodeGenOpt::Default;
361}