blob: e11314d4fcd2745bdab617dccd1fcf0d1f57e8aa [file] [log] [blame]
Jia Liu31d157a2012-02-18 12:03:15 +00001//===-- ARMSubtarget.cpp - ARM Subtarget Information ----------------------===//
Evan Chenga8e29892007-01-19 07:51:42 +00002//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-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 Chenga8e29892007-01-19 07:51:42 +00007//
8//===----------------------------------------------------------------------===//
9//
Evan Cheng5b1b44892011-07-01 21:01:15 +000010// This file implements the ARM specific subclass of TargetSubtargetInfo.
Evan Chenga8e29892007-01-19 07:51:42 +000011//
12//===----------------------------------------------------------------------===//
13
14#include "ARMSubtarget.h"
Andrew Tricke127dfd2012-09-18 03:18:56 +000015#include "ARMBaseInstrInfo.h"
Chandler Carruthd04a8d42012-12-03 16:50:05 +000016#include "ARMBaseRegisterInfo.h"
Bill Wendling4788d142013-02-15 22:41:25 +000017#include "llvm/IR/Attributes.h"
Chandler Carruth0b8c9a82013-01-02 11:36:10 +000018#include "llvm/IR/GlobalValue.h"
Bill Wendling4788d142013-02-15 22:41:25 +000019#include "llvm/IR/Function.h"
Bob Wilson54fc1242009-06-22 21:01:46 +000020#include "llvm/Support/CommandLine.h"
Chandler Carruthd04a8d42012-12-03 16:50:05 +000021#include "llvm/Target/TargetInstrInfo.h"
Evan Cheng94214702011-07-01 20:45:01 +000022
Evan Cheng94214702011-07-01 20:45:01 +000023#define GET_SUBTARGETINFO_TARGET_DESC
Evan Chengebdeeab2011-07-08 01:53:10 +000024#define GET_SUBTARGETINFO_CTOR
Evan Cheng385e9302011-07-01 22:36:09 +000025#include "ARMGenSubtargetInfo.inc"
Evan Cheng94214702011-07-01 20:45:01 +000026
Evan Chenga8e29892007-01-19 07:51:42 +000027using namespace llvm;
28
Bob Wilson54fc1242009-06-22 21:01:46 +000029static cl::opt<bool>
30ReserveR9("arm-reserve-r9", cl::Hidden,
31 cl::desc("Reserve R9, making it unavailable as GPR"));
32
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +000033static cl::opt<bool>
Evan Cheng53519f02011-01-21 18:55:51 +000034DarwinUseMOVT("arm-darwin-use-movt", cl::init(true), cl::Hidden);
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +000035
Bob Wilson02aba732010-09-28 04:09:35 +000036static cl::opt<bool>
Bob Wilsoneb1641d2012-09-29 21:43:49 +000037UseFusedMulOps("arm-use-mulops",
38 cl::init(true), cl::Hidden);
39
40static cl::opt<bool>
Bob Wilson02aba732010-09-28 04:09:35 +000041StrictAlign("arm-strict-align", cl::Hidden,
42 cl::desc("Disallow all unaligned memory accesses"));
43
Evan Cheng276365d2011-06-30 01:53:36 +000044ARMSubtarget::ARMSubtarget(const std::string &TT, const std::string &CPU,
Evan Cheng94ca42f2011-07-07 00:08:19 +000045 const std::string &FS)
Evan Cheng0ddff1b2011-07-07 07:07:08 +000046 : ARMGenSubtargetInfo(TT, CPU, FS)
Evan Cheng3ef1c872010-09-10 01:29:16 +000047 , ARMProcFamily(Others)
Lauro Ramos Venancio3630e782007-02-13 19:52:28 +000048 , stackAlignment(4)
Evan Cheng276365d2011-06-30 01:53:36 +000049 , CPUString(CPU)
Evan Chengb72d2a92011-01-11 21:46:47 +000050 , TargetTriple(TT)
Lauro Ramos Venancio3630e782007-02-13 19:52:28 +000051 , TargetABI(ARM_ABI_APCS) {
Bill Wendling901d8002013-02-16 01:36:26 +000052 initializeEnvironment();
Bill Wendling4788d142013-02-15 22:41:25 +000053 resetSubtargetFeatures(CPU, FS);
54}
55
Bill Wendling901d8002013-02-16 01:36:26 +000056void ARMSubtarget::initializeEnvironment() {
57 HasV4TOps = false;
58 HasV5TOps = false;
59 HasV5TEOps = false;
60 HasV6Ops = false;
61 HasV6T2Ops = false;
62 HasV7Ops = false;
63 HasVFPv2 = false;
64 HasVFPv3 = false;
65 HasVFPv4 = false;
66 HasNEON = false;
67 UseNEONForSinglePrecisionFP = false;
68 UseMulOps = UseFusedMulOps;
69 SlowFPVMLx = false;
70 HasVMLxForwarding = false;
71 SlowFPBrcc = false;
72 InThumbMode = false;
73 HasThumb2 = false;
74 IsMClass = false;
75 NoARM = false;
76 PostRAScheduler = false;
77 IsR9Reserved = ReserveR9;
78 UseMovt = false;
79 SupportsTailCall = false;
80 HasFP16 = false;
81 HasD16 = false;
82 HasHardwareDivide = false;
83 HasHardwareDivideInARM = false;
84 HasT2ExtractPack = false;
85 HasDataBarrier = false;
86 Pref32BitThumb = false;
87 AvoidCPSRPartialUpdate = false;
88 AvoidMOVsShifterOperand = false;
89 HasRAS = false;
90 HasMPExtension = false;
91 FPOnlySP = false;
92 AllowsUnalignedMem = false;
93 Thumb2DSP = false;
94 UseNaClTrap = false;
95}
96
Bill Wendling4788d142013-02-15 22:41:25 +000097void ARMSubtarget::resetSubtargetFeatures(const MachineFunction *MF) {
98 AttributeSet FnAttrs = MF->getFunction()->getAttributes();
99 Attribute CPUAttr = FnAttrs.getAttribute(AttributeSet::FunctionIndex,
100 "target-cpu");
101 Attribute FSAttr = FnAttrs.getAttribute(AttributeSet::FunctionIndex,
102 "target-features");
103 std::string CPU =
104 !CPUAttr.hasAttribute(Attribute::None) ?CPUAttr.getValueAsString() : "";
105 std::string FS =
106 !FSAttr.hasAttribute(Attribute::None) ? FSAttr.getValueAsString() : "";
Bill Wendling901d8002013-02-16 01:36:26 +0000107 if (!FS.empty()) {
108 initializeEnvironment();
Bill Wendling4788d142013-02-15 22:41:25 +0000109 resetSubtargetFeatures(CPU, FS);
Bill Wendling901d8002013-02-16 01:36:26 +0000110 }
Bill Wendling4788d142013-02-15 22:41:25 +0000111}
112
113void ARMSubtarget::resetSubtargetFeatures(StringRef CPU, StringRef FS) {
Evan Cheng276365d2011-06-30 01:53:36 +0000114 if (CPUString.empty())
115 CPUString = "generic";
Evan Cheng4b174742009-03-08 04:02:49 +0000116
Evan Cheng4cc446b2011-06-30 02:12:44 +0000117 // Insert the architecture feature derived from the target triple into the
118 // feature string. This is important for setting features that are implied
119 // based on the architecture version.
Bill Wendling4788d142013-02-15 22:41:25 +0000120 std::string ArchFS = ARM_MC::ParseARMTriple(TargetTriple.getTriple(),
121 CPUString);
Evan Cheng94ca42f2011-07-07 00:08:19 +0000122 if (!FS.empty()) {
123 if (!ArchFS.empty())
Bill Wendling4788d142013-02-15 22:41:25 +0000124 ArchFS = ArchFS + "," + FS.str();
Evan Cheng94ca42f2011-07-07 00:08:19 +0000125 else
126 ArchFS = FS;
127 }
Evan Cheng0ddff1b2011-07-07 07:07:08 +0000128 ParseSubtargetFeatures(CPUString, ArchFS);
Evan Cheng94ca42f2011-07-07 00:08:19 +0000129
130 // Thumb2 implies at least V6T2. FIXME: Fix tests to explicitly specify a
131 // ARM version or CPU and then remove this.
Evan Cheng39dfb0f2011-07-07 03:55:05 +0000132 if (!HasV6T2Ops && hasThumb2())
133 HasV4TOps = HasV5TOps = HasV5TEOps = HasV6Ops = HasV6T2Ops = true;
Bob Wilson66f6c792010-11-09 22:50:47 +0000134
Andrew Trickd43b5c92012-08-08 02:44:16 +0000135 // Keep a pointer to static instruction cost data for the specified CPU.
136 SchedModel = getSchedModelForCPU(CPUString);
137
Evan Cheng94214702011-07-01 20:45:01 +0000138 // Initialize scheduling itinerary for the specified CPU.
139 InstrItins = getInstrItineraryForCPU(CPUString);
140
Bill Wendling4788d142013-02-15 22:41:25 +0000141 if ((TargetTriple.getTriple().find("eabi") != std::string::npos) ||
142 (isTargetIOS() && isMClass()))
Evan Cheng07043272012-02-21 20:46:00 +0000143 // FIXME: We might want to separate AAPCS and EABI. Some systems, e.g.
144 // Darwin-EABI conforms to AACPS but not the rest of EABI.
Evan Cheng0ddff1b2011-07-07 07:07:08 +0000145 TargetABI = ARM_ABI_AAPCS;
146
Lauro Ramos Venancio3630e782007-02-13 19:52:28 +0000147 if (isAAPCS_ABI())
148 stackAlignment = 8;
149
Evan Chengafff9412011-12-20 18:26:50 +0000150 if (!isTargetIOS())
Evan Cheng5de5d4b2011-01-17 08:03:18 +0000151 UseMovt = hasV6T2Ops();
152 else {
Evan Cheng39dfb0f2011-07-07 03:55:05 +0000153 IsR9Reserved = ReserveR9 | !HasV6Ops;
Evan Cheng53519f02011-01-21 18:55:51 +0000154 UseMovt = DarwinUseMOVT && hasV6T2Ops();
Evan Cheng07043272012-02-21 20:46:00 +0000155 SupportsTailCall = !getTargetTriple().isOSVersionLT(5, 0);
Evan Cheng5de5d4b2011-01-17 08:03:18 +0000156 }
David Goodwin471850a2009-10-01 21:46:35 +0000157
Evan Chengd3dd50f2009-10-16 06:11:08 +0000158 if (!isThumb() || hasThumb2())
159 PostRAScheduler = true;
Bob Wilson02aba732010-09-28 04:09:35 +0000160
161 // v6+ may or may not support unaligned mem access depending on the system
162 // configuration.
163 if (!StrictAlign && hasV6Ops() && isTargetDarwin())
164 AllowsUnalignedMem = true;
Evan Chenga8e29892007-01-19 07:51:42 +0000165}
Evan Chenge4e4ed32009-08-28 23:18:09 +0000166
167/// GVIsIndirectSymbol - true if the GV will be accessed via an indirect symbol.
Evan Cheng63476a82009-09-03 07:04:02 +0000168bool
Dan Gohman46510a72010-04-15 01:51:59 +0000169ARMSubtarget::GVIsIndirectSymbol(const GlobalValue *GV,
170 Reloc::Model RelocM) const {
Evan Cheng63476a82009-09-03 07:04:02 +0000171 if (RelocM == Reloc::Static)
Evan Chenge4e4ed32009-08-28 23:18:09 +0000172 return false;
Evan Cheng63476a82009-09-03 07:04:02 +0000173
Jeffrey Yasskinf0356fe2010-01-27 20:34:15 +0000174 // Materializable GVs (in JIT lazy compilation mode) do not require an extra
175 // load from stub.
Evan Chengaf05c692011-02-22 06:58:34 +0000176 bool isDecl = GV->hasAvailableExternallyLinkage();
177 if (GV->isDeclaration() && !GV->isMaterializable())
178 isDecl = true;
Evan Cheng63476a82009-09-03 07:04:02 +0000179
180 if (!isTargetDarwin()) {
181 // Extra load is needed for all externally visible.
182 if (GV->hasLocalLinkage() || GV->hasHiddenVisibility())
183 return false;
184 return true;
185 } else {
186 if (RelocM == Reloc::PIC_) {
187 // If this is a strong reference to a definition, it is definitely not
188 // through a stub.
189 if (!isDecl && !GV->isWeakForLinker())
190 return false;
191
192 // Unless we have a symbol with hidden visibility, we have to go through a
193 // normal $non_lazy_ptr stub because this symbol might be resolved late.
194 if (!GV->hasHiddenVisibility()) // Non-hidden $non_lazy_ptr reference.
195 return true;
196
197 // If symbol visibility is hidden, we have a stub for common symbol
198 // references and external declarations.
199 if (isDecl || GV->hasCommonLinkage())
200 // Hidden $non_lazy_ptr reference.
201 return true;
202
203 return false;
204 } else {
205 // If this is a strong reference to a definition, it is definitely not
206 // through a stub.
207 if (!isDecl && !GV->isWeakForLinker())
208 return false;
Andrew Trick6e8f4c42010-12-24 04:28:06 +0000209
Evan Cheng63476a82009-09-03 07:04:02 +0000210 // Unless we have a symbol with hidden visibility, we have to go through a
211 // normal $non_lazy_ptr stub because this symbol might be resolved late.
212 if (!GV->hasHiddenVisibility()) // Non-hidden $non_lazy_ptr reference.
213 return true;
214 }
215 }
216
217 return false;
Evan Chenge4e4ed32009-08-28 23:18:09 +0000218}
David Goodwinc2e8a7e2009-11-10 00:48:55 +0000219
Owen Anderson654d5442010-09-28 21:57:50 +0000220unsigned ARMSubtarget::getMispredictionPenalty() const {
Andrew Trickd43b5c92012-08-08 02:44:16 +0000221 return SchedModel->MispredictPenalty;
Owen Anderson654d5442010-09-28 21:57:50 +0000222}
223
David Goodwinc2e8a7e2009-11-10 00:48:55 +0000224bool ARMSubtarget::enablePostRAScheduler(
225 CodeGenOpt::Level OptLevel,
Evan Cheng5b1b44892011-07-01 21:01:15 +0000226 TargetSubtargetInfo::AntiDepBreakMode& Mode,
David Goodwin87d21b92009-11-13 19:52:48 +0000227 RegClassVector& CriticalPathRCs) const {
Evan Cheng5b1b44892011-07-01 21:01:15 +0000228 Mode = TargetSubtargetInfo::ANTIDEP_CRITICAL;
David Goodwin87d21b92009-11-13 19:52:48 +0000229 CriticalPathRCs.clear();
230 CriticalPathRCs.push_back(&ARM::GPRRegClass);
David Goodwinc2e8a7e2009-11-10 00:48:55 +0000231 return PostRAScheduler && OptLevel >= CodeGenOpt::Default;
232}