blob: 694b31385b27a3c6dfc533c56fe16491dd745200 [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"
Bob Wilson45825302009-06-22 21:01:46 +000018#include "llvm/Support/CommandLine.h"
David Goodwin0d412c22009-11-10 00:48:55 +000019#include "llvm/ADT/SmallVector.h"
Evan Cheng10043e22007-01-19 07:51:42 +000020using namespace llvm;
21
Bob Wilson45825302009-06-22 21:01:46 +000022static cl::opt<bool>
23ReserveR9("arm-reserve-r9", cl::Hidden,
24 cl::desc("Reserve R9, making it unavailable as GPR"));
25
Anton Korobeynikov25229082009-11-24 00:44:37 +000026static cl::opt<bool>
Evan Cheng2f2435d2011-01-21 18:55:51 +000027DarwinUseMOVT("arm-darwin-use-movt", cl::init(true), cl::Hidden);
Anton Korobeynikov25229082009-11-24 00:44:37 +000028
Bob Wilson3dc97322010-09-28 04:09:35 +000029static cl::opt<bool>
30StrictAlign("arm-strict-align", cl::Hidden,
31 cl::desc("Disallow all unaligned memory accesses"));
32
Evan Chengfe6e4052011-06-30 01:53:36 +000033ARMSubtarget::ARMSubtarget(const std::string &TT, const std::string &CPU,
34 const std::string &FS, bool isT)
Anton Korobeynikovbf16a172010-03-06 19:39:36 +000035 : ARMArchVersion(V4)
Evan Chengbf407072010-09-10 01:29:16 +000036 , ARMProcFamily(Others)
Anton Korobeynikov0b91cc42009-05-23 19:51:43 +000037 , ARMFPUType(None)
Jim Grosbach71fcb4f2010-03-25 23:47:34 +000038 , UseNEONForSinglePrecisionFP(false)
Evan Cheng62c7b5b2010-12-05 22:04:16 +000039 , SlowFPVMLx(false)
Benjamin Kramerbb21fac2011-04-01 09:20:31 +000040 , HasVMLxForwarding(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)
Bob Wilsona2881ee2011-04-19 18:11:49 +000054 , AvoidCPSRPartialUpdate(false)
Evan Cheng8740ee32010-11-03 06:34:55 +000055 , HasMPExtension(false)
Jim Grosbach4d5dc3e2010-08-11 15:44:15 +000056 , FPOnlySP(false)
Bob Wilson3dc97322010-09-28 04:09:35 +000057 , AllowsUnalignedMem(false)
Lauro Ramos Venancio048e16ff2007-02-13 19:52:28 +000058 , stackAlignment(4)
Evan Chengfe6e4052011-06-30 01:53:36 +000059 , CPUString(CPU)
Evan Chenge45d6852011-01-11 21:46:47 +000060 , TargetTriple(TT)
Lauro Ramos Venancio048e16ff2007-02-13 19:52:28 +000061 , TargetABI(ARM_ABI_APCS) {
Evan Cheng10043e22007-01-19 07:51:42 +000062 // Determine default and user specified characteristics
Evan Cheng10043e22007-01-19 07:51:42 +000063
Anton Korobeynikovbf16a172010-03-06 19:39:36 +000064 // When no arch is specified either by CPU or by attributes, make the default
65 // ARMv4T.
Bob Wilsond0046ca2010-11-09 22:50:47 +000066 const char *ARMArchFeature = "";
Evan Chengfe6e4052011-06-30 01:53:36 +000067 if (CPUString.empty())
68 CPUString = "generic";
Bob Wilsond0046ca2010-11-09 22:50:47 +000069 if (CPUString == "generic" && (FS.empty() || FS == "generic")) {
Anton Korobeynikovbf16a172010-03-06 19:39:36 +000070 ARMArchVersion = V4T;
Evan Chengfe6e4052011-06-30 01:53:36 +000071 ARMArchFeature = "+v4t";
Bob Wilsond0046ca2010-11-09 22:50:47 +000072 }
Anton Korobeynikovbf16a172010-03-06 19:39:36 +000073
Evan Cheng10043e22007-01-19 07:51:42 +000074 // Set the boolean corresponding to the current target triple, or the default
75 // if one cannot be determined, to true.
Evan Chengec415ef2009-03-08 04:02:49 +000076 unsigned Len = TT.length();
Evan Cheng0ee0da82009-03-09 20:25:39 +000077 unsigned Idx = 0;
Anton Korobeynikovb6f45382009-05-29 23:41:08 +000078
Evan Cheng0ee0da82009-03-09 20:25:39 +000079 if (Len >= 5 && TT.substr(0, 4) == "armv")
80 Idx = 4;
Bob Wilson48249562009-06-22 21:28:22 +000081 else if (Len >= 6 && TT.substr(0, 5) == "thumb") {
Anton Korobeynikov12694bd2009-06-01 20:00:48 +000082 IsThumb = true;
Evan Cheng0ee0da82009-03-09 20:25:39 +000083 if (Len >= 7 && TT[5] == 'v')
84 Idx = 6;
85 }
86 if (Idx) {
87 unsigned SubVer = TT[Idx];
Anton Korobeynikovbf16a172010-03-06 19:39:36 +000088 if (SubVer >= '7' && SubVer <= '9') {
89 ARMArchVersion = V7A;
Evan Chengfe6e4052011-06-30 01:53:36 +000090 ARMArchFeature = "+v7a";
Bob Wilsond0046ca2010-11-09 22:50:47 +000091 if (Len >= Idx+2 && TT[Idx+1] == 'm') {
Jim Grosbach92d999002010-05-05 20:44:35 +000092 ARMArchVersion = V7M;
Evan Chengfe6e4052011-06-30 01:53:36 +000093 ARMArchFeature = "+v7m";
Bob Wilsond0046ca2010-11-09 22:50:47 +000094 }
Anton Korobeynikovbf16a172010-03-06 19:39:36 +000095 } else if (SubVer == '6') {
96 ARMArchVersion = V6;
Evan Chengfe6e4052011-06-30 01:53:36 +000097 ARMArchFeature = "+v6";
Bob Wilsond0046ca2010-11-09 22:50:47 +000098 if (Len >= Idx+3 && TT[Idx+1] == 't' && TT[Idx+2] == '2') {
Anton Korobeynikovbf16a172010-03-06 19:39:36 +000099 ARMArchVersion = V6T2;
Evan Chengfe6e4052011-06-30 01:53:36 +0000100 ARMArchFeature = "+v6t2";
Bob Wilsond0046ca2010-11-09 22:50:47 +0000101 }
Anton Korobeynikovbf16a172010-03-06 19:39:36 +0000102 } else if (SubVer == '5') {
103 ARMArchVersion = V5T;
Evan Chengfe6e4052011-06-30 01:53:36 +0000104 ARMArchFeature = "+v5t";
Bob Wilsond0046ca2010-11-09 22:50:47 +0000105 if (Len >= Idx+3 && TT[Idx+1] == 't' && TT[Idx+2] == 'e') {
Anton Korobeynikovbf16a172010-03-06 19:39:36 +0000106 ARMArchVersion = V5TE;
Evan Chengfe6e4052011-06-30 01:53:36 +0000107 ARMArchFeature = "+v5te";
Bob Wilsond0046ca2010-11-09 22:50:47 +0000108 }
Anton Korobeynikovbf16a172010-03-06 19:39:36 +0000109 } else if (SubVer == '4') {
Bob Wilsond0046ca2010-11-09 22:50:47 +0000110 if (Len >= Idx+2 && TT[Idx+1] == 't') {
Anton Korobeynikovbf16a172010-03-06 19:39:36 +0000111 ARMArchVersion = V4T;
Evan Chengfe6e4052011-06-30 01:53:36 +0000112 ARMArchFeature = "+v4t";
Bob Wilsond0046ca2010-11-09 22:50:47 +0000113 } else {
Anton Korobeynikovbf16a172010-03-06 19:39:36 +0000114 ARMArchVersion = V4;
Bob Wilsond0046ca2010-11-09 22:50:47 +0000115 ARMArchFeature = "";
116 }
Evan Chengec415ef2009-03-08 04:02:49 +0000117 }
118 }
119
Lauro Ramos Venancio048e16ff2007-02-13 19:52:28 +0000120 if (TT.find("eabi") != std::string::npos)
121 TargetABI = ARM_ABI_AAPCS;
122
Evan Cheng0b33a322011-06-30 02:12:44 +0000123 // Insert the architecture feature derived from the target triple into the
124 // feature string. This is important for setting features that are implied
125 // based on the architecture version.
126 std::string FSWithArch = std::string(ARMArchFeature);
127 if (FSWithArch.empty())
Bob Wilsond0046ca2010-11-09 22:50:47 +0000128 FSWithArch = FS;
Evan Cheng0b33a322011-06-30 02:12:44 +0000129 else if (!FS.empty())
130 FSWithArch = FSWithArch + "," + FS;
Evan Chengfe6e4052011-06-30 01:53:36 +0000131 ParseSubtargetFeatures(FSWithArch, CPUString);
Bob Wilsond0046ca2010-11-09 22:50:47 +0000132
Andrew Trick10ffc2b2010-12-24 05:03:26 +0000133 // After parsing Itineraries, set ItinData.IssueWidth.
134 computeIssueWidth();
135
Bob Wilsond0046ca2010-11-09 22:50:47 +0000136 // Thumb2 implies at least V6T2.
137 if (ARMArchVersion >= V6T2)
138 ThumbMode = Thumb2;
139 else if (ThumbMode >= Thumb2)
140 ARMArchVersion = V6T2;
141
Lauro Ramos Venancio048e16ff2007-02-13 19:52:28 +0000142 if (isAAPCS_ABI())
143 stackAlignment = 8;
144
Evan Chengdfce83c2011-01-17 08:03:18 +0000145 if (!isTargetDarwin())
146 UseMovt = hasV6T2Ops();
147 else {
Bob Wilson45825302009-06-22 21:01:46 +0000148 IsR9Reserved = ReserveR9 | (ARMArchVersion < V6);
Evan Cheng2f2435d2011-01-21 18:55:51 +0000149 UseMovt = DarwinUseMOVT && hasV6T2Ops();
Evan Chengdfce83c2011-01-17 08:03:18 +0000150 }
David Goodwin9a051a52009-10-01 21:46:35 +0000151
Evan Cheng03da4db2009-10-16 06:11:08 +0000152 if (!isThumb() || hasThumb2())
153 PostRAScheduler = true;
Bob Wilson3dc97322010-09-28 04:09:35 +0000154
155 // v6+ may or may not support unaligned mem access depending on the system
156 // configuration.
157 if (!StrictAlign && hasV6Ops() && isTargetDarwin())
158 AllowsUnalignedMem = true;
Evan Cheng10043e22007-01-19 07:51:42 +0000159}
Evan Cheng43b9ca62009-08-28 23:18:09 +0000160
161/// GVIsIndirectSymbol - true if the GV will be accessed via an indirect symbol.
Evan Cheng1b389522009-09-03 07:04:02 +0000162bool
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000163ARMSubtarget::GVIsIndirectSymbol(const GlobalValue *GV,
164 Reloc::Model RelocM) const {
Evan Cheng1b389522009-09-03 07:04:02 +0000165 if (RelocM == Reloc::Static)
Evan Cheng43b9ca62009-08-28 23:18:09 +0000166 return false;
Evan Cheng1b389522009-09-03 07:04:02 +0000167
Jeffrey Yasskin091217b2010-01-27 20:34:15 +0000168 // Materializable GVs (in JIT lazy compilation mode) do not require an extra
169 // load from stub.
Evan Cheng2ce66302011-02-22 06:58:34 +0000170 bool isDecl = GV->hasAvailableExternallyLinkage();
171 if (GV->isDeclaration() && !GV->isMaterializable())
172 isDecl = true;
Evan Cheng1b389522009-09-03 07:04:02 +0000173
174 if (!isTargetDarwin()) {
175 // Extra load is needed for all externally visible.
176 if (GV->hasLocalLinkage() || GV->hasHiddenVisibility())
177 return false;
178 return true;
179 } else {
180 if (RelocM == Reloc::PIC_) {
181 // If this is a strong reference to a definition, it is definitely not
182 // through a stub.
183 if (!isDecl && !GV->isWeakForLinker())
184 return false;
185
186 // Unless we have a symbol with hidden visibility, we have to go through a
187 // normal $non_lazy_ptr stub because this symbol might be resolved late.
188 if (!GV->hasHiddenVisibility()) // Non-hidden $non_lazy_ptr reference.
189 return true;
190
191 // If symbol visibility is hidden, we have a stub for common symbol
192 // references and external declarations.
193 if (isDecl || GV->hasCommonLinkage())
194 // Hidden $non_lazy_ptr reference.
195 return true;
196
197 return false;
198 } else {
199 // If this is a strong reference to a definition, it is definitely not
200 // through a stub.
201 if (!isDecl && !GV->isWeakForLinker())
202 return false;
Andrew Trickc416ba62010-12-24 04:28:06 +0000203
Evan Cheng1b389522009-09-03 07:04:02 +0000204 // Unless we have a symbol with hidden visibility, we have to go through a
205 // normal $non_lazy_ptr stub because this symbol might be resolved late.
206 if (!GV->hasHiddenVisibility()) // Non-hidden $non_lazy_ptr reference.
207 return true;
208 }
209 }
210
211 return false;
Evan Cheng43b9ca62009-08-28 23:18:09 +0000212}
David Goodwin0d412c22009-11-10 00:48:55 +0000213
Owen Andersona3181e22010-09-28 21:57:50 +0000214unsigned ARMSubtarget::getMispredictionPenalty() const {
215 // If we have a reasonable estimate of the pipeline depth, then we can
216 // estimate the penalty of a misprediction based on that.
217 if (isCortexA8())
218 return 13;
219 else if (isCortexA9())
220 return 8;
Andrew Trickc416ba62010-12-24 04:28:06 +0000221
Owen Andersona3181e22010-09-28 21:57:50 +0000222 // Otherwise, just return a sensible default.
223 return 10;
224}
225
Andrew Trick10ffc2b2010-12-24 05:03:26 +0000226void ARMSubtarget::computeIssueWidth() {
227 unsigned allStage1Units = 0;
228 for (const InstrItinerary *itin = InstrItins.Itineraries;
229 itin->FirstStage != ~0U; ++itin) {
230 const InstrStage *IS = InstrItins.Stages + itin->FirstStage;
231 allStage1Units |= IS->getUnits();
232 }
233 InstrItins.IssueWidth = 0;
234 while (allStage1Units) {
235 ++InstrItins.IssueWidth;
236 // clear the lowest bit
237 allStage1Units ^= allStage1Units & ~(allStage1Units - 1);
238 }
Andrew Trick163a2442011-01-04 00:32:57 +0000239 assert(InstrItins.IssueWidth <= 2 && "itinerary bug, too many stage 1 units");
Andrew Trick10ffc2b2010-12-24 05:03:26 +0000240}
241
David Goodwin0d412c22009-11-10 00:48:55 +0000242bool ARMSubtarget::enablePostRAScheduler(
243 CodeGenOpt::Level OptLevel,
244 TargetSubtarget::AntiDepBreakMode& Mode,
David Goodwinb9fe5d52009-11-13 19:52:48 +0000245 RegClassVector& CriticalPathRCs) const {
David Goodwin0d412c22009-11-10 00:48:55 +0000246 Mode = TargetSubtarget::ANTIDEP_CRITICAL;
David Goodwinb9fe5d52009-11-13 19:52:48 +0000247 CriticalPathRCs.clear();
248 CriticalPathRCs.push_back(&ARM::GPRRegClass);
David Goodwin0d412c22009-11-10 00:48:55 +0000249 return PostRAScheduler && OptLevel >= CodeGenOpt::Default;
250}