blob: 0bd740cfb28c0d6212b44a63b857a365e3b1e749 [file] [log] [blame]
Evan Cheng10043e22007-01-19 07:51:42 +00001//===-- ARMSubtarget.cpp - ARM Subtarget Information ------------*- C++ -*-===//
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
6// License. See LICENSE.TXT for details.
Evan Cheng10043e22007-01-19 07:51:42 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the ARM specific subclass of TargetSubtarget.
11//
12//===----------------------------------------------------------------------===//
13
14#include "ARMSubtarget.h"
15#include "ARMGenSubtarget.inc"
Evan Chenge45d6852011-01-11 21:46:47 +000016#include "ARMBaseRegisterInfo.h"
Evan Cheng43b9ca62009-08-28 23:18:09 +000017#include "llvm/GlobalValue.h"
Anton Korobeynikov77d19432009-06-08 22:53:56 +000018#include "llvm/Target/TargetOptions.h"
Bob Wilson45825302009-06-22 21:01:46 +000019#include "llvm/Support/CommandLine.h"
David Goodwin0d412c22009-11-10 00:48:55 +000020#include "llvm/ADT/SmallVector.h"
Evan Cheng10043e22007-01-19 07:51:42 +000021using namespace llvm;
22
Bob Wilson45825302009-06-22 21:01:46 +000023static cl::opt<bool>
24ReserveR9("arm-reserve-r9", cl::Hidden,
25 cl::desc("Reserve R9, making it unavailable as GPR"));
26
Anton Korobeynikov25229082009-11-24 00:44:37 +000027static cl::opt<bool>
Evan Cheng2f2435d2011-01-21 18:55:51 +000028DarwinUseMOVT("arm-darwin-use-movt", cl::init(true), cl::Hidden);
Anton Korobeynikov25229082009-11-24 00:44:37 +000029
Bob Wilson3dc97322010-09-28 04:09:35 +000030static cl::opt<bool>
31StrictAlign("arm-strict-align", cl::Hidden,
32 cl::desc("Disallow all unaligned memory accesses"));
33
Daniel Dunbar31b44e82009-08-02 22:11:08 +000034ARMSubtarget::ARMSubtarget(const std::string &TT, const std::string &FS,
Evan Cheng03da4db2009-10-16 06:11:08 +000035 bool isT)
Anton Korobeynikovbf16a172010-03-06 19:39:36 +000036 : ARMArchVersion(V4)
Evan Chengbf407072010-09-10 01:29:16 +000037 , ARMProcFamily(Others)
Anton Korobeynikov0b91cc42009-05-23 19:51:43 +000038 , ARMFPUType(None)
Jim Grosbach71fcb4f2010-03-25 23:47:34 +000039 , UseNEONForSinglePrecisionFP(false)
Evan Cheng62c7b5b2010-12-05 22:04:16 +000040 , SlowFPVMLx(false)
Evan Cheng891f8312010-08-09 19:19:36 +000041 , SlowFPBrcc(false)
Evan Cheng03da4db2009-10-16 06:11:08 +000042 , IsThumb(isT)
Anton Korobeynikov12694bd2009-06-01 20:00:48 +000043 , ThumbMode(Thumb1)
Evan Cheng5190f092010-08-11 07:17:46 +000044 , NoARM(false)
David Goodwin17199b52009-09-30 00:10:16 +000045 , PostRAScheduler(false)
Bob Wilson45825302009-06-22 21:01:46 +000046 , IsR9Reserved(ReserveR9)
Evan Chengdfce83c2011-01-17 08:03:18 +000047 , UseMovt(false)
Anton Korobeynikov0a65a372010-03-14 18:42:38 +000048 , HasFP16(false)
Bob Wilsondd6eb5b2010-10-12 16:22:47 +000049 , HasD16(false)
Jim Grosbach151cd8f2010-05-05 23:44:43 +000050 , HasHardwareDivide(false)
51 , HasT2ExtractPack(false)
Evan Cheng6e809de2010-08-11 06:22:01 +000052 , HasDataBarrier(false)
Evan Cheng891f8312010-08-09 19:19:36 +000053 , Pref32BitThumb(false)
Evan Cheng8740ee32010-11-03 06:34:55 +000054 , HasMPExtension(false)
Jim Grosbach4d5dc3e2010-08-11 15:44:15 +000055 , FPOnlySP(false)
Bob Wilson3dc97322010-09-28 04:09:35 +000056 , AllowsUnalignedMem(false)
Lauro Ramos Venancio048e16ff2007-02-13 19:52:28 +000057 , stackAlignment(4)
Anton Korobeynikov08bf4c02009-05-23 19:50:50 +000058 , CPUString("generic")
Evan Chenge45d6852011-01-11 21:46:47 +000059 , TargetTriple(TT)
Lauro Ramos Venancio048e16ff2007-02-13 19:52:28 +000060 , TargetABI(ARM_ABI_APCS) {
Evan Chengbf407072010-09-10 01:29:16 +000061 // Default to soft float ABI
Anton Korobeynikov77d19432009-06-08 22:53:56 +000062 if (FloatABIType == FloatABI::Default)
63 FloatABIType = FloatABI::Soft;
64
Evan Cheng10043e22007-01-19 07:51:42 +000065 // Determine default and user specified characteristics
Evan Cheng10043e22007-01-19 07:51:42 +000066
Anton Korobeynikovbf16a172010-03-06 19:39:36 +000067 // When no arch is specified either by CPU or by attributes, make the default
68 // ARMv4T.
Bob Wilsond0046ca2010-11-09 22:50:47 +000069 const char *ARMArchFeature = "";
70 if (CPUString == "generic" && (FS.empty() || FS == "generic")) {
Anton Korobeynikovbf16a172010-03-06 19:39:36 +000071 ARMArchVersion = V4T;
Bob Wilsond0046ca2010-11-09 22:50:47 +000072 ARMArchFeature = ",+v4t";
73 }
Anton Korobeynikovbf16a172010-03-06 19:39:36 +000074
Evan Cheng10043e22007-01-19 07:51:42 +000075 // Set the boolean corresponding to the current target triple, or the default
76 // if one cannot be determined, to true.
Evan Chengec415ef2009-03-08 04:02:49 +000077 unsigned Len = TT.length();
Evan Cheng0ee0da82009-03-09 20:25:39 +000078 unsigned Idx = 0;
Anton Korobeynikovb6f45382009-05-29 23:41:08 +000079
Evan Cheng0ee0da82009-03-09 20:25:39 +000080 if (Len >= 5 && TT.substr(0, 4) == "armv")
81 Idx = 4;
Bob Wilson48249562009-06-22 21:28:22 +000082 else if (Len >= 6 && TT.substr(0, 5) == "thumb") {
Anton Korobeynikov12694bd2009-06-01 20:00:48 +000083 IsThumb = true;
Evan Cheng0ee0da82009-03-09 20:25:39 +000084 if (Len >= 7 && TT[5] == 'v')
85 Idx = 6;
86 }
87 if (Idx) {
88 unsigned SubVer = TT[Idx];
Anton Korobeynikovbf16a172010-03-06 19:39:36 +000089 if (SubVer >= '7' && SubVer <= '9') {
90 ARMArchVersion = V7A;
Bob Wilsond0046ca2010-11-09 22:50:47 +000091 ARMArchFeature = ",+v7a";
92 if (Len >= Idx+2 && TT[Idx+1] == 'm') {
Jim Grosbach92d999002010-05-05 20:44:35 +000093 ARMArchVersion = V7M;
Bob Wilsond0046ca2010-11-09 22:50:47 +000094 ARMArchFeature = ",+v7m";
95 }
Anton Korobeynikovbf16a172010-03-06 19:39:36 +000096 } else if (SubVer == '6') {
97 ARMArchVersion = V6;
Bob Wilsond0046ca2010-11-09 22:50:47 +000098 ARMArchFeature = ",+v6";
99 if (Len >= Idx+3 && TT[Idx+1] == 't' && TT[Idx+2] == '2') {
Anton Korobeynikovbf16a172010-03-06 19:39:36 +0000100 ARMArchVersion = V6T2;
Bob Wilsond0046ca2010-11-09 22:50:47 +0000101 ARMArchFeature = ",+v6t2";
102 }
Anton Korobeynikovbf16a172010-03-06 19:39:36 +0000103 } else if (SubVer == '5') {
104 ARMArchVersion = V5T;
Bob Wilsond0046ca2010-11-09 22:50:47 +0000105 ARMArchFeature = ",+v5t";
106 if (Len >= Idx+3 && TT[Idx+1] == 't' && TT[Idx+2] == 'e') {
Anton Korobeynikovbf16a172010-03-06 19:39:36 +0000107 ARMArchVersion = V5TE;
Bob Wilsond0046ca2010-11-09 22:50:47 +0000108 ARMArchFeature = ",+v5te";
109 }
Anton Korobeynikovbf16a172010-03-06 19:39:36 +0000110 } else if (SubVer == '4') {
Bob Wilsond0046ca2010-11-09 22:50:47 +0000111 if (Len >= Idx+2 && TT[Idx+1] == 't') {
Anton Korobeynikovbf16a172010-03-06 19:39:36 +0000112 ARMArchVersion = V4T;
Bob Wilsond0046ca2010-11-09 22:50:47 +0000113 ARMArchFeature = ",+v4t";
114 } else {
Anton Korobeynikovbf16a172010-03-06 19:39:36 +0000115 ARMArchVersion = V4;
Bob Wilsond0046ca2010-11-09 22:50:47 +0000116 ARMArchFeature = "";
117 }
Evan Chengec415ef2009-03-08 04:02:49 +0000118 }
119 }
120
Lauro Ramos Venancio048e16ff2007-02-13 19:52:28 +0000121 if (TT.find("eabi") != std::string::npos)
122 TargetABI = ARM_ABI_AAPCS;
123
Bob Wilsond0046ca2010-11-09 22:50:47 +0000124 // Parse features string. If the first entry in FS (the CPU) is missing,
125 // insert the architecture feature derived from the target triple. This is
126 // important for setting features that are implied based on the architecture
127 // version.
128 std::string FSWithArch;
129 if (FS.empty())
130 FSWithArch = std::string(ARMArchFeature);
131 else if (FS.find(',') == 0)
132 FSWithArch = std::string(ARMArchFeature) + FS;
133 else
134 FSWithArch = FS;
135 CPUString = ParseSubtargetFeatures(FSWithArch, CPUString);
136
Andrew Trick10ffc2b2010-12-24 05:03:26 +0000137 // After parsing Itineraries, set ItinData.IssueWidth.
138 computeIssueWidth();
139
Bob Wilsond0046ca2010-11-09 22:50:47 +0000140 // Thumb2 implies at least V6T2.
141 if (ARMArchVersion >= V6T2)
142 ThumbMode = Thumb2;
143 else if (ThumbMode >= Thumb2)
144 ARMArchVersion = V6T2;
145
Lauro Ramos Venancio048e16ff2007-02-13 19:52:28 +0000146 if (isAAPCS_ABI())
147 stackAlignment = 8;
148
Evan Chengdfce83c2011-01-17 08:03:18 +0000149 if (!isTargetDarwin())
150 UseMovt = hasV6T2Ops();
151 else {
Bob Wilson45825302009-06-22 21:01:46 +0000152 IsR9Reserved = ReserveR9 | (ARMArchVersion < V6);
Evan Cheng2f2435d2011-01-21 18:55:51 +0000153 UseMovt = DarwinUseMOVT && hasV6T2Ops();
Evan Chengdfce83c2011-01-17 08:03:18 +0000154 }
David Goodwin9a051a52009-10-01 21:46:35 +0000155
Evan Cheng03da4db2009-10-16 06:11:08 +0000156 if (!isThumb() || hasThumb2())
157 PostRAScheduler = true;
Bob Wilson3dc97322010-09-28 04:09:35 +0000158
159 // v6+ may or may not support unaligned mem access depending on the system
160 // configuration.
161 if (!StrictAlign && hasV6Ops() && isTargetDarwin())
162 AllowsUnalignedMem = true;
Evan Cheng10043e22007-01-19 07:51:42 +0000163}
Evan Cheng43b9ca62009-08-28 23:18:09 +0000164
165/// GVIsIndirectSymbol - true if the GV will be accessed via an indirect symbol.
Evan Cheng1b389522009-09-03 07:04:02 +0000166bool
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000167ARMSubtarget::GVIsIndirectSymbol(const GlobalValue *GV,
168 Reloc::Model RelocM) const {
Evan Cheng1b389522009-09-03 07:04:02 +0000169 if (RelocM == Reloc::Static)
Evan Cheng43b9ca62009-08-28 23:18:09 +0000170 return false;
Evan Cheng1b389522009-09-03 07:04:02 +0000171
Jeffrey Yasskin091217b2010-01-27 20:34:15 +0000172 // Materializable GVs (in JIT lazy compilation mode) do not require an extra
173 // load from stub.
174 bool isDecl = GV->isDeclaration() && !GV->isMaterializable();
Evan Cheng1b389522009-09-03 07:04:02 +0000175
176 if (!isTargetDarwin()) {
177 // Extra load is needed for all externally visible.
178 if (GV->hasLocalLinkage() || GV->hasHiddenVisibility())
179 return false;
180 return true;
181 } else {
182 if (RelocM == Reloc::PIC_) {
183 // If this is a strong reference to a definition, it is definitely not
184 // through a stub.
185 if (!isDecl && !GV->isWeakForLinker())
186 return false;
187
188 // Unless we have a symbol with hidden visibility, we have to go through a
189 // normal $non_lazy_ptr stub because this symbol might be resolved late.
190 if (!GV->hasHiddenVisibility()) // Non-hidden $non_lazy_ptr reference.
191 return true;
192
193 // If symbol visibility is hidden, we have a stub for common symbol
194 // references and external declarations.
195 if (isDecl || GV->hasCommonLinkage())
196 // Hidden $non_lazy_ptr reference.
197 return true;
198
199 return false;
200 } else {
201 // If this is a strong reference to a definition, it is definitely not
202 // through a stub.
203 if (!isDecl && !GV->isWeakForLinker())
204 return false;
Andrew Trickc416ba62010-12-24 04:28:06 +0000205
Evan Cheng1b389522009-09-03 07:04:02 +0000206 // Unless we have a symbol with hidden visibility, we have to go through a
207 // normal $non_lazy_ptr stub because this symbol might be resolved late.
208 if (!GV->hasHiddenVisibility()) // Non-hidden $non_lazy_ptr reference.
209 return true;
210 }
211 }
212
213 return false;
Evan Cheng43b9ca62009-08-28 23:18:09 +0000214}
David Goodwin0d412c22009-11-10 00:48:55 +0000215
Owen Andersona3181e22010-09-28 21:57:50 +0000216unsigned ARMSubtarget::getMispredictionPenalty() const {
217 // If we have a reasonable estimate of the pipeline depth, then we can
218 // estimate the penalty of a misprediction based on that.
219 if (isCortexA8())
220 return 13;
221 else if (isCortexA9())
222 return 8;
Andrew Trickc416ba62010-12-24 04:28:06 +0000223
Owen Andersona3181e22010-09-28 21:57:50 +0000224 // Otherwise, just return a sensible default.
225 return 10;
226}
227
Andrew Trick10ffc2b2010-12-24 05:03:26 +0000228void ARMSubtarget::computeIssueWidth() {
229 unsigned allStage1Units = 0;
230 for (const InstrItinerary *itin = InstrItins.Itineraries;
231 itin->FirstStage != ~0U; ++itin) {
232 const InstrStage *IS = InstrItins.Stages + itin->FirstStage;
233 allStage1Units |= IS->getUnits();
234 }
235 InstrItins.IssueWidth = 0;
236 while (allStage1Units) {
237 ++InstrItins.IssueWidth;
238 // clear the lowest bit
239 allStage1Units ^= allStage1Units & ~(allStage1Units - 1);
240 }
Andrew Trick163a2442011-01-04 00:32:57 +0000241 assert(InstrItins.IssueWidth <= 2 && "itinerary bug, too many stage 1 units");
Andrew Trick10ffc2b2010-12-24 05:03:26 +0000242}
243
David Goodwin0d412c22009-11-10 00:48:55 +0000244bool ARMSubtarget::enablePostRAScheduler(
245 CodeGenOpt::Level OptLevel,
246 TargetSubtarget::AntiDepBreakMode& Mode,
David Goodwinb9fe5d52009-11-13 19:52:48 +0000247 RegClassVector& CriticalPathRCs) const {
David Goodwin0d412c22009-11-10 00:48:55 +0000248 Mode = TargetSubtarget::ANTIDEP_CRITICAL;
David Goodwinb9fe5d52009-11-13 19:52:48 +0000249 CriticalPathRCs.clear();
250 CriticalPathRCs.push_back(&ARM::GPRRegClass);
David Goodwin0d412c22009-11-10 00:48:55 +0000251 return PostRAScheduler && OptLevel >= CodeGenOpt::Default;
252}