blob: 3111f5e385ee2023b45b6579e55b1af751ae6e9c [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
Evan Chengfe6e4052011-06-30 01:53:36 +000060ARMSubtarget::ARMSubtarget(const std::string &TT, const std::string &CPU,
Renato Golinb4dd6c52013-03-21 18:47:47 +000061 const std::string &FS, const TargetOptions &Options)
Evan Cheng1a72add62011-07-07 07:07:08 +000062 : ARMGenSubtargetInfo(TT, CPU, FS)
Evan Chengbf407072010-09-10 01:29:16 +000063 , ARMProcFamily(Others)
Lauro Ramos Venancio048e16ff2007-02-13 19:52:28 +000064 , stackAlignment(4)
Evan Chengfe6e4052011-06-30 01:53:36 +000065 , CPUString(CPU)
Evan Chenge45d6852011-01-11 21:46:47 +000066 , TargetTriple(TT)
Renato Golinb4dd6c52013-03-21 18:47:47 +000067 , Options(Options)
Lauro Ramos Venancio048e16ff2007-02-13 19:52:28 +000068 , TargetABI(ARM_ABI_APCS) {
Bill Wendling61375d82013-02-16 01:36:26 +000069 initializeEnvironment();
Bill Wendling5a92eec2013-02-15 22:41:25 +000070 resetSubtargetFeatures(CPU, FS);
71}
72
Bill Wendling61375d82013-02-16 01:36:26 +000073void ARMSubtarget::initializeEnvironment() {
74 HasV4TOps = false;
75 HasV5TOps = false;
76 HasV5TEOps = false;
77 HasV6Ops = false;
78 HasV6T2Ops = false;
79 HasV7Ops = false;
Joey Goulyb3f550e2013-06-26 16:58:26 +000080 HasV8Ops = false;
Bill Wendling61375d82013-02-16 01:36:26 +000081 HasVFPv2 = false;
82 HasVFPv3 = false;
83 HasVFPv4 = false;
Joey Goulyb1b0dd82013-06-27 11:49:26 +000084 HasV8FP = false;
Bill Wendling61375d82013-02-16 01:36:26 +000085 HasNEON = false;
86 UseNEONForSinglePrecisionFP = false;
87 UseMulOps = UseFusedMulOps;
88 SlowFPVMLx = false;
89 HasVMLxForwarding = false;
90 SlowFPBrcc = false;
91 InThumbMode = false;
92 HasThumb2 = false;
93 IsMClass = false;
94 NoARM = false;
95 PostRAScheduler = false;
96 IsR9Reserved = ReserveR9;
97 UseMovt = false;
98 SupportsTailCall = false;
99 HasFP16 = false;
100 HasD16 = false;
101 HasHardwareDivide = false;
102 HasHardwareDivideInARM = false;
103 HasT2ExtractPack = false;
104 HasDataBarrier = false;
105 Pref32BitThumb = false;
106 AvoidCPSRPartialUpdate = false;
107 AvoidMOVsShifterOperand = false;
108 HasRAS = false;
109 HasMPExtension = false;
110 FPOnlySP = false;
Tim Northovercedd4812013-05-23 19:11:14 +0000111 HasPerfMon = false;
Tim Northoverc6047652013-04-10 12:08:35 +0000112 HasTrustZone = false;
Bill Wendling61375d82013-02-16 01:36:26 +0000113 AllowsUnalignedMem = false;
114 Thumb2DSP = false;
115 UseNaClTrap = false;
Renato Golinb4dd6c52013-03-21 18:47:47 +0000116 UnsafeFPMath = false;
Bill Wendling61375d82013-02-16 01:36:26 +0000117}
118
Bill Wendling5a92eec2013-02-15 22:41:25 +0000119void ARMSubtarget::resetSubtargetFeatures(const MachineFunction *MF) {
120 AttributeSet FnAttrs = MF->getFunction()->getAttributes();
121 Attribute CPUAttr = FnAttrs.getAttribute(AttributeSet::FunctionIndex,
122 "target-cpu");
123 Attribute FSAttr = FnAttrs.getAttribute(AttributeSet::FunctionIndex,
124 "target-features");
125 std::string CPU =
126 !CPUAttr.hasAttribute(Attribute::None) ?CPUAttr.getValueAsString() : "";
127 std::string FS =
128 !FSAttr.hasAttribute(Attribute::None) ? FSAttr.getValueAsString() : "";
Bill Wendling61375d82013-02-16 01:36:26 +0000129 if (!FS.empty()) {
130 initializeEnvironment();
Bill Wendling5a92eec2013-02-15 22:41:25 +0000131 resetSubtargetFeatures(CPU, FS);
Bill Wendling61375d82013-02-16 01:36:26 +0000132 }
Bill Wendling5a92eec2013-02-15 22:41:25 +0000133}
134
135void ARMSubtarget::resetSubtargetFeatures(StringRef CPU, StringRef FS) {
Tilmann Scheller8f79ee92013-09-02 15:48:17 +0000136 if (CPUString.empty())
137 CPUString = "generic";
Evan Chengec415ef2009-03-08 04:02:49 +0000138
Evan Cheng0b33a322011-06-30 02:12:44 +0000139 // Insert the architecture feature derived from the target triple into the
140 // feature string. This is important for setting features that are implied
141 // based on the architecture version.
Bill Wendling5a92eec2013-02-15 22:41:25 +0000142 std::string ArchFS = ARM_MC::ParseARMTriple(TargetTriple.getTriple(),
143 CPUString);
Evan Cheng2bd65362011-07-07 00:08:19 +0000144 if (!FS.empty()) {
145 if (!ArchFS.empty())
Bill Wendling5a92eec2013-02-15 22:41:25 +0000146 ArchFS = ArchFS + "," + FS.str();
Evan Cheng2bd65362011-07-07 00:08:19 +0000147 else
148 ArchFS = FS;
149 }
Evan Cheng1a72add62011-07-07 07:07:08 +0000150 ParseSubtargetFeatures(CPUString, ArchFS);
Evan Cheng2bd65362011-07-07 00:08:19 +0000151
152 // Thumb2 implies at least V6T2. FIXME: Fix tests to explicitly specify a
153 // ARM version or CPU and then remove this.
Evan Cheng8b2bda02011-07-07 03:55:05 +0000154 if (!HasV6T2Ops && hasThumb2())
155 HasV4TOps = HasV5TOps = HasV5TEOps = HasV6Ops = HasV6T2Ops = true;
Bob Wilsond0046ca2010-11-09 22:50:47 +0000156
Andrew Trick352abc12012-08-08 02:44:16 +0000157 // Keep a pointer to static instruction cost data for the specified CPU.
158 SchedModel = getSchedModelForCPU(CPUString);
159
Evan Cheng54b68e32011-07-01 20:45:01 +0000160 // Initialize scheduling itinerary for the specified CPU.
161 InstrItins = getInstrItineraryForCPU(CPUString);
162
Bill Wendling5a92eec2013-02-15 22:41:25 +0000163 if ((TargetTriple.getTriple().find("eabi") != std::string::npos) ||
164 (isTargetIOS() && isMClass()))
Evan Cheng0460ae82012-02-21 20:46:00 +0000165 // FIXME: We might want to separate AAPCS and EABI. Some systems, e.g.
166 // Darwin-EABI conforms to AACPS but not the rest of EABI.
Evan Cheng1a72add62011-07-07 07:07:08 +0000167 TargetABI = ARM_ABI_AAPCS;
168
Lauro Ramos Venancio048e16ff2007-02-13 19:52:28 +0000169 if (isAAPCS_ABI())
170 stackAlignment = 8;
171
Renato Golinca570632013-08-15 20:54:38 +0000172 UseMovt = hasV6T2Ops() && ArmUseMOVT;
173
Renato Golin0a41d9a2013-08-15 20:45:13 +0000174 if (!isTargetIOS()) {
Renato Golin0a41d9a2013-08-15 20:45:13 +0000175 IsR9Reserved = ReserveR9;
176 } else {
Evan Cheng8b2bda02011-07-07 03:55:05 +0000177 IsR9Reserved = ReserveR9 | !HasV6Ops;
Evan Cheng0460ae82012-02-21 20:46:00 +0000178 SupportsTailCall = !getTargetTriple().isOSVersionLT(5, 0);
Evan Chengdfce83c2011-01-17 08:03:18 +0000179 }
David Goodwin9a051a52009-10-01 21:46:35 +0000180
Evan Cheng03da4db2009-10-16 06:11:08 +0000181 if (!isThumb() || hasThumb2())
182 PostRAScheduler = true;
Bob Wilson3dc97322010-09-28 04:09:35 +0000183
JF Bastien97b08c402013-05-17 23:49:01 +0000184 switch (Align) {
185 case DefaultAlign:
186 // Assume pre-ARMv6 doesn't support unaligned accesses.
187 //
188 // ARMv6 may or may not support unaligned accesses depending on the
189 // SCTLR.U bit, which is architecture-specific. We assume ARMv6
190 // Darwin targets support unaligned accesses, and others don't.
191 //
192 // ARMv7 always has SCTLR.U set to 1, but it has a new SCTLR.A bit
193 // which raises an alignment fault on unaligned accesses. Linux
194 // defaults this bit to 0 and handles it as a system-wide (not
195 // per-process) setting. It is therefore safe to assume that ARMv7+
196 // Linux targets support unaligned accesses. The same goes for NaCl.
197 //
198 // The above behavior is consistent with GCC.
199 AllowsUnalignedMem = (
200 (hasV7Ops() && (isTargetLinux() || isTargetNaCl())) ||
201 (hasV6Ops() && isTargetDarwin()));
202 break;
203 case StrictAlign:
204 AllowsUnalignedMem = false;
205 break;
206 case NoStrictAlign:
207 AllowsUnalignedMem = true;
208 break;
209 }
Renato Golinb4dd6c52013-03-21 18:47:47 +0000210
211 // NEON f32 ops are non-IEEE 754 compliant. Darwin is ok with it by default.
212 uint64_t Bits = getFeatureBits();
213 if ((Bits & ARM::ProcA5 || Bits & ARM::ProcA8) && // Where this matters
214 (Options.UnsafeFPMath || isTargetDarwin()))
215 UseNEONForSinglePrecisionFP = true;
Evan Cheng10043e22007-01-19 07:51:42 +0000216}
Evan Cheng43b9ca62009-08-28 23:18:09 +0000217
218/// GVIsIndirectSymbol - true if the GV will be accessed via an indirect symbol.
Evan Cheng1b389522009-09-03 07:04:02 +0000219bool
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000220ARMSubtarget::GVIsIndirectSymbol(const GlobalValue *GV,
221 Reloc::Model RelocM) const {
Evan Cheng1b389522009-09-03 07:04:02 +0000222 if (RelocM == Reloc::Static)
Evan Cheng43b9ca62009-08-28 23:18:09 +0000223 return false;
Evan Cheng1b389522009-09-03 07:04:02 +0000224
Jeffrey Yasskin091217b2010-01-27 20:34:15 +0000225 // Materializable GVs (in JIT lazy compilation mode) do not require an extra
226 // load from stub.
Evan Cheng2ce66302011-02-22 06:58:34 +0000227 bool isDecl = GV->hasAvailableExternallyLinkage();
228 if (GV->isDeclaration() && !GV->isMaterializable())
229 isDecl = true;
Evan Cheng1b389522009-09-03 07:04:02 +0000230
231 if (!isTargetDarwin()) {
232 // Extra load is needed for all externally visible.
233 if (GV->hasLocalLinkage() || GV->hasHiddenVisibility())
234 return false;
235 return true;
236 } else {
237 if (RelocM == Reloc::PIC_) {
238 // If this is a strong reference to a definition, it is definitely not
239 // through a stub.
240 if (!isDecl && !GV->isWeakForLinker())
241 return false;
242
243 // Unless we have a symbol with hidden visibility, we have to go through a
244 // normal $non_lazy_ptr stub because this symbol might be resolved late.
245 if (!GV->hasHiddenVisibility()) // Non-hidden $non_lazy_ptr reference.
246 return true;
247
248 // If symbol visibility is hidden, we have a stub for common symbol
249 // references and external declarations.
250 if (isDecl || GV->hasCommonLinkage())
251 // Hidden $non_lazy_ptr reference.
252 return true;
253
254 return false;
255 } else {
256 // If this is a strong reference to a definition, it is definitely not
257 // through a stub.
258 if (!isDecl && !GV->isWeakForLinker())
259 return false;
Andrew Trickc416ba62010-12-24 04:28:06 +0000260
Evan Cheng1b389522009-09-03 07:04:02 +0000261 // Unless we have a symbol with hidden visibility, we have to go through a
262 // normal $non_lazy_ptr stub because this symbol might be resolved late.
263 if (!GV->hasHiddenVisibility()) // Non-hidden $non_lazy_ptr reference.
264 return true;
265 }
266 }
267
268 return false;
Evan Cheng43b9ca62009-08-28 23:18:09 +0000269}
David Goodwin0d412c22009-11-10 00:48:55 +0000270
Owen Andersona3181e22010-09-28 21:57:50 +0000271unsigned ARMSubtarget::getMispredictionPenalty() const {
Andrew Trick352abc12012-08-08 02:44:16 +0000272 return SchedModel->MispredictPenalty;
Owen Andersona3181e22010-09-28 21:57:50 +0000273}
274
David Goodwin0d412c22009-11-10 00:48:55 +0000275bool ARMSubtarget::enablePostRAScheduler(
276 CodeGenOpt::Level OptLevel,
Evan Cheng0d639a22011-07-01 21:01:15 +0000277 TargetSubtargetInfo::AntiDepBreakMode& Mode,
David Goodwinb9fe5d52009-11-13 19:52:48 +0000278 RegClassVector& CriticalPathRCs) const {
Evan Cheng0d639a22011-07-01 21:01:15 +0000279 Mode = TargetSubtargetInfo::ANTIDEP_CRITICAL;
David Goodwinb9fe5d52009-11-13 19:52:48 +0000280 CriticalPathRCs.clear();
281 CriticalPathRCs.push_back(&ARM::GPRRegClass);
David Goodwin0d412c22009-11-10 00:48:55 +0000282 return PostRAScheduler && OptLevel >= CodeGenOpt::Default;
283}