blob: 09b3ed641e3cb95ccae86c776be72fb752a964cf [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"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000018#include "llvm/IR/GlobalValue.h"
Bill Wendling5a92eec2013-02-15 22:41:25 +000019#include "llvm/IR/Function.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
Evan Cheng54b68e32011-07-01 20:45:01 +000024#define GET_SUBTARGETINFO_TARGET_DESC
Evan Cheng4d1ca962011-07-08 01:53:10 +000025#define GET_SUBTARGETINFO_CTOR
Evan Chengc9c090d2011-07-01 22:36:09 +000026#include "ARMGenSubtargetInfo.inc"
Evan Cheng54b68e32011-07-01 20:45:01 +000027
Evan Cheng10043e22007-01-19 07:51:42 +000028using namespace llvm;
29
Bob Wilson45825302009-06-22 21:01:46 +000030static cl::opt<bool>
31ReserveR9("arm-reserve-r9", cl::Hidden,
32 cl::desc("Reserve R9, making it unavailable as GPR"));
33
Anton Korobeynikov25229082009-11-24 00:44:37 +000034static cl::opt<bool>
Renato Golinca570632013-08-15 20:54:38 +000035ArmUseMOVT("arm-use-movt", cl::init(true), cl::Hidden);
Anton Korobeynikov25229082009-11-24 00:44:37 +000036
Bob Wilson3dc97322010-09-28 04:09:35 +000037static cl::opt<bool>
Bob Wilsone8a549c2012-09-29 21:43:49 +000038UseFusedMulOps("arm-use-mulops",
39 cl::init(true), cl::Hidden);
40
JF Bastien97b08c402013-05-17 23:49:01 +000041enum AlignMode {
42 DefaultAlign,
43 StrictAlign,
44 NoStrictAlign
45};
46
47static cl::opt<AlignMode>
48Align(cl::desc("Load/store alignment support"),
49 cl::Hidden, cl::init(DefaultAlign),
50 cl::values(
51 clEnumValN(DefaultAlign, "arm-default-align",
52 "Generate unaligned accesses only on hardware/OS "
53 "combinations that are known to support them"),
54 clEnumValN(StrictAlign, "arm-strict-align",
55 "Disallow all unaligned memory accesses"),
56 clEnumValN(NoStrictAlign, "arm-no-strict-align",
57 "Allow unaligned memory accesses"),
58 clEnumValEnd));
Bob Wilson3dc97322010-09-28 04:09:35 +000059
Weiming Zhao0da5cc02013-11-13 18:29:49 +000060enum ITMode {
61 DefaultIT,
62 RestrictedIT,
63 NoRestrictedIT
64};
65
66static cl::opt<ITMode>
67IT(cl::desc("IT block support"), cl::Hidden, cl::init(DefaultIT),
68 cl::ZeroOrMore,
69 cl::values(clEnumValN(DefaultIT, "arm-default-it",
70 "Generate IT block based on arch"),
71 clEnumValN(RestrictedIT, "arm-restrict-it",
72 "Disallow deprecated IT based on ARMv8"),
73 clEnumValN(NoRestrictedIT, "arm-no-restrict-it",
74 "Allow IT blocks based on ARMv7"),
75 clEnumValEnd));
76
Evan Chengfe6e4052011-06-30 01:53:36 +000077ARMSubtarget::ARMSubtarget(const std::string &TT, const std::string &CPU,
Renato Golinb4dd6c52013-03-21 18:47:47 +000078 const std::string &FS, const TargetOptions &Options)
Evan Cheng1a72add62011-07-07 07:07:08 +000079 : ARMGenSubtargetInfo(TT, CPU, FS)
Evan Chengbf407072010-09-10 01:29:16 +000080 , ARMProcFamily(Others)
Amara Emerson330afb52013-09-23 14:26:15 +000081 , ARMProcClass(None)
Lauro Ramos Venancio048e16ff2007-02-13 19:52:28 +000082 , stackAlignment(4)
Evan Chengfe6e4052011-06-30 01:53:36 +000083 , CPUString(CPU)
Evan Chenge45d6852011-01-11 21:46:47 +000084 , TargetTriple(TT)
Renato Golinb4dd6c52013-03-21 18:47:47 +000085 , Options(Options)
Lauro Ramos Venancio048e16ff2007-02-13 19:52:28 +000086 , TargetABI(ARM_ABI_APCS) {
Bill Wendling61375d82013-02-16 01:36:26 +000087 initializeEnvironment();
Bill Wendling5a92eec2013-02-15 22:41:25 +000088 resetSubtargetFeatures(CPU, FS);
89}
90
Bill Wendling61375d82013-02-16 01:36:26 +000091void ARMSubtarget::initializeEnvironment() {
92 HasV4TOps = false;
93 HasV5TOps = false;
94 HasV5TEOps = false;
95 HasV6Ops = false;
Amara Emerson5035ee02013-10-07 16:55:23 +000096 HasV6MOps = false;
Bill Wendling61375d82013-02-16 01:36:26 +000097 HasV6T2Ops = false;
98 HasV7Ops = false;
Joey Goulyb3f550e2013-06-26 16:58:26 +000099 HasV8Ops = false;
Bill Wendling61375d82013-02-16 01:36:26 +0000100 HasVFPv2 = false;
101 HasVFPv3 = false;
102 HasVFPv4 = false;
Joey Goulyccd04892013-09-13 13:46:57 +0000103 HasFPARMv8 = false;
Bill Wendling61375d82013-02-16 01:36:26 +0000104 HasNEON = false;
Tim Northoverdee86042013-12-02 14:46:26 +0000105 MinSize = false;
Bill Wendling61375d82013-02-16 01:36:26 +0000106 UseNEONForSinglePrecisionFP = false;
107 UseMulOps = UseFusedMulOps;
108 SlowFPVMLx = false;
109 HasVMLxForwarding = false;
110 SlowFPBrcc = false;
111 InThumbMode = false;
112 HasThumb2 = false;
Bill Wendling61375d82013-02-16 01:36:26 +0000113 NoARM = false;
114 PostRAScheduler = false;
115 IsR9Reserved = ReserveR9;
116 UseMovt = false;
117 SupportsTailCall = false;
118 HasFP16 = false;
119 HasD16 = false;
120 HasHardwareDivide = false;
121 HasHardwareDivideInARM = false;
122 HasT2ExtractPack = false;
123 HasDataBarrier = false;
124 Pref32BitThumb = false;
125 AvoidCPSRPartialUpdate = false;
126 AvoidMOVsShifterOperand = false;
127 HasRAS = false;
128 HasMPExtension = false;
Bradley Smith25219752013-11-01 13:27:35 +0000129 HasVirtualization = false;
Bill Wendling61375d82013-02-16 01:36:26 +0000130 FPOnlySP = false;
Tim Northovercedd4812013-05-23 19:11:14 +0000131 HasPerfMon = false;
Tim Northoverc6047652013-04-10 12:08:35 +0000132 HasTrustZone = false;
Amara Emerson33089092013-09-19 11:59:01 +0000133 HasCrypto = false;
Amara Emersonf9a67fc2013-10-29 16:54:52 +0000134 HasCRC = false;
Bill Wendling61375d82013-02-16 01:36:26 +0000135 AllowsUnalignedMem = false;
136 Thumb2DSP = false;
137 UseNaClTrap = false;
Renato Golinb4dd6c52013-03-21 18:47:47 +0000138 UnsafeFPMath = false;
Bill Wendling61375d82013-02-16 01:36:26 +0000139}
140
Bill Wendling5a92eec2013-02-15 22:41:25 +0000141void ARMSubtarget::resetSubtargetFeatures(const MachineFunction *MF) {
142 AttributeSet FnAttrs = MF->getFunction()->getAttributes();
143 Attribute CPUAttr = FnAttrs.getAttribute(AttributeSet::FunctionIndex,
144 "target-cpu");
145 Attribute FSAttr = FnAttrs.getAttribute(AttributeSet::FunctionIndex,
146 "target-features");
147 std::string CPU =
148 !CPUAttr.hasAttribute(Attribute::None) ?CPUAttr.getValueAsString() : "";
149 std::string FS =
150 !FSAttr.hasAttribute(Attribute::None) ? FSAttr.getValueAsString() : "";
Bill Wendling61375d82013-02-16 01:36:26 +0000151 if (!FS.empty()) {
152 initializeEnvironment();
Bill Wendling5a92eec2013-02-15 22:41:25 +0000153 resetSubtargetFeatures(CPU, FS);
Bill Wendling61375d82013-02-16 01:36:26 +0000154 }
Tim Northoverdee86042013-12-02 14:46:26 +0000155
156 MinSize =
157 FnAttrs.hasAttribute(AttributeSet::FunctionIndex, Attribute::MinSize);
Bill Wendling5a92eec2013-02-15 22:41:25 +0000158}
159
160void ARMSubtarget::resetSubtargetFeatures(StringRef CPU, StringRef FS) {
Tilmann Scheller63872ce2013-09-02 17:09:01 +0000161 if (CPUString.empty()) {
162 if (isTargetIOS() && TargetTriple.getArchName().endswith("v7s"))
163 // Default to the Swift CPU when targeting armv7s/thumbv7s.
164 CPUString = "swift";
165 else
166 CPUString = "generic";
167 }
Evan Chengec415ef2009-03-08 04:02:49 +0000168
Evan Cheng0b33a322011-06-30 02:12:44 +0000169 // Insert the architecture feature derived from the target triple into the
170 // feature string. This is important for setting features that are implied
171 // based on the architecture version.
Bill Wendling5a92eec2013-02-15 22:41:25 +0000172 std::string ArchFS = ARM_MC::ParseARMTriple(TargetTriple.getTriple(),
173 CPUString);
Evan Cheng2bd65362011-07-07 00:08:19 +0000174 if (!FS.empty()) {
175 if (!ArchFS.empty())
Bill Wendling5a92eec2013-02-15 22:41:25 +0000176 ArchFS = ArchFS + "," + FS.str();
Evan Cheng2bd65362011-07-07 00:08:19 +0000177 else
178 ArchFS = FS;
179 }
Evan Cheng1a72add62011-07-07 07:07:08 +0000180 ParseSubtargetFeatures(CPUString, ArchFS);
Evan Cheng2bd65362011-07-07 00:08:19 +0000181
Joerg Sonnenberger002a1472013-12-13 11:16:00 +0000182 // FIXME: This used enable V6T2 support implicitly for Thumb2 mode.
183 // Assert this for now to make the change obvious.
184 assert(hasV6T2Ops() || !hasThumb2());
Bob Wilsond0046ca2010-11-09 22:50:47 +0000185
Andrew Trick352abc12012-08-08 02:44:16 +0000186 // Keep a pointer to static instruction cost data for the specified CPU.
187 SchedModel = getSchedModelForCPU(CPUString);
188
Evan Cheng54b68e32011-07-01 20:45:01 +0000189 // Initialize scheduling itinerary for the specified CPU.
190 InstrItins = getInstrItineraryForCPU(CPUString);
191
Bill Wendling5a92eec2013-02-15 22:41:25 +0000192 if ((TargetTriple.getTriple().find("eabi") != std::string::npos) ||
193 (isTargetIOS() && isMClass()))
Evan Cheng0460ae82012-02-21 20:46:00 +0000194 // FIXME: We might want to separate AAPCS and EABI. Some systems, e.g.
195 // Darwin-EABI conforms to AACPS but not the rest of EABI.
Evan Cheng1a72add62011-07-07 07:07:08 +0000196 TargetABI = ARM_ABI_AAPCS;
197
Lauro Ramos Venancio048e16ff2007-02-13 19:52:28 +0000198 if (isAAPCS_ABI())
199 stackAlignment = 8;
200
Renato Golinca570632013-08-15 20:54:38 +0000201 UseMovt = hasV6T2Ops() && ArmUseMOVT;
202
Renato Golin0a41d9a2013-08-15 20:45:13 +0000203 if (!isTargetIOS()) {
Renato Golin0a41d9a2013-08-15 20:45:13 +0000204 IsR9Reserved = ReserveR9;
205 } else {
Evan Cheng8b2bda02011-07-07 03:55:05 +0000206 IsR9Reserved = ReserveR9 | !HasV6Ops;
Evan Cheng0460ae82012-02-21 20:46:00 +0000207 SupportsTailCall = !getTargetTriple().isOSVersionLT(5, 0);
Evan Chengdfce83c2011-01-17 08:03:18 +0000208 }
David Goodwin9a051a52009-10-01 21:46:35 +0000209
Evan Cheng03da4db2009-10-16 06:11:08 +0000210 if (!isThumb() || hasThumb2())
211 PostRAScheduler = true;
Bob Wilson3dc97322010-09-28 04:09:35 +0000212
JF Bastien97b08c402013-05-17 23:49:01 +0000213 switch (Align) {
214 case DefaultAlign:
215 // Assume pre-ARMv6 doesn't support unaligned accesses.
216 //
217 // ARMv6 may or may not support unaligned accesses depending on the
218 // SCTLR.U bit, which is architecture-specific. We assume ARMv6
219 // Darwin targets support unaligned accesses, and others don't.
220 //
221 // ARMv7 always has SCTLR.U set to 1, but it has a new SCTLR.A bit
222 // which raises an alignment fault on unaligned accesses. Linux
223 // defaults this bit to 0 and handles it as a system-wide (not
224 // per-process) setting. It is therefore safe to assume that ARMv7+
225 // Linux targets support unaligned accesses. The same goes for NaCl.
226 //
227 // The above behavior is consistent with GCC.
228 AllowsUnalignedMem = (
229 (hasV7Ops() && (isTargetLinux() || isTargetNaCl())) ||
230 (hasV6Ops() && isTargetDarwin()));
231 break;
232 case StrictAlign:
233 AllowsUnalignedMem = false;
234 break;
235 case NoStrictAlign:
236 AllowsUnalignedMem = true;
237 break;
238 }
Renato Golinb4dd6c52013-03-21 18:47:47 +0000239
Weiming Zhao0da5cc02013-11-13 18:29:49 +0000240 switch (IT) {
241 case DefaultIT:
242 RestrictIT = hasV8Ops() ? true : false;
243 break;
244 case RestrictedIT:
245 RestrictIT = true;
246 break;
247 case NoRestrictedIT:
248 RestrictIT = false;
249 break;
250 }
251
Renato Golinb4dd6c52013-03-21 18:47:47 +0000252 // NEON f32 ops are non-IEEE 754 compliant. Darwin is ok with it by default.
253 uint64_t Bits = getFeatureBits();
254 if ((Bits & ARM::ProcA5 || Bits & ARM::ProcA8) && // Where this matters
255 (Options.UnsafeFPMath || isTargetDarwin()))
256 UseNEONForSinglePrecisionFP = true;
Evan Cheng10043e22007-01-19 07:51:42 +0000257}
Evan Cheng43b9ca62009-08-28 23:18:09 +0000258
259/// GVIsIndirectSymbol - true if the GV will be accessed via an indirect symbol.
Evan Cheng1b389522009-09-03 07:04:02 +0000260bool
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000261ARMSubtarget::GVIsIndirectSymbol(const GlobalValue *GV,
262 Reloc::Model RelocM) const {
Evan Cheng1b389522009-09-03 07:04:02 +0000263 if (RelocM == Reloc::Static)
Evan Cheng43b9ca62009-08-28 23:18:09 +0000264 return false;
Evan Cheng1b389522009-09-03 07:04:02 +0000265
Jeffrey Yasskin091217b2010-01-27 20:34:15 +0000266 // Materializable GVs (in JIT lazy compilation mode) do not require an extra
267 // load from stub.
Evan Cheng2ce66302011-02-22 06:58:34 +0000268 bool isDecl = GV->hasAvailableExternallyLinkage();
269 if (GV->isDeclaration() && !GV->isMaterializable())
270 isDecl = true;
Evan Cheng1b389522009-09-03 07:04:02 +0000271
272 if (!isTargetDarwin()) {
273 // Extra load is needed for all externally visible.
274 if (GV->hasLocalLinkage() || GV->hasHiddenVisibility())
275 return false;
276 return true;
277 } else {
278 if (RelocM == Reloc::PIC_) {
279 // If this is a strong reference to a definition, it is definitely not
280 // through a stub.
281 if (!isDecl && !GV->isWeakForLinker())
282 return false;
283
284 // Unless we have a symbol with hidden visibility, we have to go through a
285 // normal $non_lazy_ptr stub because this symbol might be resolved late.
286 if (!GV->hasHiddenVisibility()) // Non-hidden $non_lazy_ptr reference.
287 return true;
288
289 // If symbol visibility is hidden, we have a stub for common symbol
290 // references and external declarations.
291 if (isDecl || GV->hasCommonLinkage())
292 // Hidden $non_lazy_ptr reference.
293 return true;
294
295 return false;
296 } else {
297 // If this is a strong reference to a definition, it is definitely not
298 // through a stub.
299 if (!isDecl && !GV->isWeakForLinker())
300 return false;
Andrew Trickc416ba62010-12-24 04:28:06 +0000301
Evan Cheng1b389522009-09-03 07:04:02 +0000302 // Unless we have a symbol with hidden visibility, we have to go through a
303 // normal $non_lazy_ptr stub because this symbol might be resolved late.
304 if (!GV->hasHiddenVisibility()) // Non-hidden $non_lazy_ptr reference.
305 return true;
306 }
307 }
308
309 return false;
Evan Cheng43b9ca62009-08-28 23:18:09 +0000310}
David Goodwin0d412c22009-11-10 00:48:55 +0000311
Owen Andersona3181e22010-09-28 21:57:50 +0000312unsigned ARMSubtarget::getMispredictionPenalty() const {
Andrew Trick352abc12012-08-08 02:44:16 +0000313 return SchedModel->MispredictPenalty;
Owen Andersona3181e22010-09-28 21:57:50 +0000314}
315
Bob Wilsone7dde0c2013-11-03 06:14:38 +0000316bool ARMSubtarget::hasSinCos() const {
317 return getTargetTriple().getOS() == Triple::IOS &&
318 !getTargetTriple().isOSVersionLT(7, 0);
319}
320
David Goodwin0d412c22009-11-10 00:48:55 +0000321bool ARMSubtarget::enablePostRAScheduler(
322 CodeGenOpt::Level OptLevel,
Evan Cheng0d639a22011-07-01 21:01:15 +0000323 TargetSubtargetInfo::AntiDepBreakMode& Mode,
David Goodwinb9fe5d52009-11-13 19:52:48 +0000324 RegClassVector& CriticalPathRCs) const {
Andrew Trickd24698c2013-09-25 00:26:16 +0000325 Mode = TargetSubtargetInfo::ANTIDEP_NONE;
David Goodwin0d412c22009-11-10 00:48:55 +0000326 return PostRAScheduler && OptLevel >= CodeGenOpt::Default;
327}