blob: 6ceacc898e2fbaa6314505c9f060cb5b8b903627 [file] [log] [blame]
Bill Wendlingd6434862010-12-04 23:57:24 +00001//===-- X86Subtarget.cpp - X86 Subtarget Information ----------------------===//
Nate Begemanfb5792f2005-07-12 01:41:54 +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.
Nate Begemanfb5792f2005-07-12 01:41:54 +00007//
8//===----------------------------------------------------------------------===//
9//
Evan Cheng5b1b44892011-07-01 21:01:15 +000010// This file implements the X86 specific subclass of TargetSubtargetInfo.
Nate Begemanfb5792f2005-07-12 01:41:54 +000011//
12//===----------------------------------------------------------------------===//
13
Evan Cheng5b925c02009-01-03 04:04:46 +000014#define DEBUG_TYPE "subtarget"
Nate Begemanfb5792f2005-07-12 01:41:54 +000015#include "X86Subtarget.h"
Chris Lattnerd392bd92009-07-10 07:20:05 +000016#include "X86InstrInfo.h"
Daniel Dunbar3be03402009-08-02 22:11:08 +000017#include "llvm/GlobalValue.h"
Evan Cheng5b925c02009-01-03 04:04:46 +000018#include "llvm/Support/Debug.h"
Rafael Espindolaca592212011-09-07 16:10:57 +000019#include "llvm/Support/ErrorHandling.h"
Bill Wendling0ea8bf32009-08-03 00:11:34 +000020#include "llvm/Support/raw_ostream.h"
Michael J. Spencer1f6efa32010-11-29 18:16:10 +000021#include "llvm/Support/Host.h"
Anton Korobeynikov2b2bc682006-12-22 22:29:05 +000022#include "llvm/Target/TargetMachine.h"
Rafael Espindolaca592212011-09-07 16:10:57 +000023#include "llvm/Target/TargetOptions.h"
Evan Cheng94214702011-07-01 20:45:01 +000024
Evan Cheng94214702011-07-01 20:45:01 +000025#define GET_SUBTARGETINFO_TARGET_DESC
Evan Chengebdeeab2011-07-08 01:53:10 +000026#define GET_SUBTARGETINFO_CTOR
Evan Cheng385e9302011-07-01 22:36:09 +000027#include "X86GenSubtargetInfo.inc"
Evan Cheng94214702011-07-01 20:45:01 +000028
Nate Begemanfb5792f2005-07-12 01:41:54 +000029using namespace llvm;
30
Chris Lattnerbc583222009-04-25 18:27:23 +000031#if defined(_MSC_VER)
Bill Wendling0ea8bf32009-08-03 00:11:34 +000032#include <intrin.h>
Chris Lattnerbc583222009-04-25 18:27:23 +000033#endif
34
Dan Gohman29cbade2009-11-20 23:18:13 +000035/// ClassifyBlockAddressReference - Classify a blockaddress reference for the
36/// current subtarget according to how we should reference it in a non-pcrel
37/// context.
38unsigned char X86Subtarget::
39ClassifyBlockAddressReference() const {
40 if (isPICStyleGOT()) // 32-bit ELF targets.
41 return X86II::MO_GOTOFF;
42
43 if (isPICStyleStubPIC()) // Darwin/32 in PIC mode.
44 return X86II::MO_PIC_BASE_OFFSET;
45
46 // Direct static reference to label.
47 return X86II::MO_NO_FLAG;
48}
49
Chris Lattnerd392bd92009-07-10 07:20:05 +000050/// ClassifyGlobalReference - Classify a global variable reference for the
51/// current subtarget according to how we should reference it in a non-pcrel
52/// context.
53unsigned char X86Subtarget::
54ClassifyGlobalReference(const GlobalValue *GV, const TargetMachine &TM) const {
55 // DLLImport only exists on windows, it is implemented as a load from a
56 // DLLIMPORT stub.
57 if (GV->hasDLLImportLinkage())
58 return X86II::MO_DLLIMPORT;
59
Chris Lattner6b601532010-06-14 20:11:56 +000060 // Determine whether this is a reference to a definition or a declaration.
61 // Materializable GVs (in JIT lazy compilation mode) do not require an extra
62 // load from stub.
63 bool isDecl = GV->hasAvailableExternallyLinkage();
64 if (GV->isDeclaration() && !GV->isMaterializable())
65 isDecl = true;
Evan Chenga82b22c2009-07-16 22:53:10 +000066
Chris Lattnerd392bd92009-07-10 07:20:05 +000067 // X86-64 in PIC mode.
68 if (isPICStyleRIPRel()) {
69 // Large model never uses stubs.
70 if (TM.getCodeModel() == CodeModel::Large)
71 return X86II::MO_NO_FLAG;
72
Chris Lattnerc7822322009-07-10 21:01:59 +000073 if (isTargetDarwin()) {
74 // If symbol visibility is hidden, the extra load is not needed if
75 // target is x86-64 or the symbol is definitely defined in the current
76 // translation unit.
77 if (GV->hasDefaultVisibility() &&
Evan Chenga82b22c2009-07-16 22:53:10 +000078 (isDecl || GV->isWeakForLinker()))
Chris Lattnerc7822322009-07-10 21:01:59 +000079 return X86II::MO_GOTPCREL;
Anton Korobeynikov699647c2010-08-21 17:21:11 +000080 } else if (!isTargetWin64()) {
Chris Lattnerc7822322009-07-10 21:01:59 +000081 assert(isTargetELF() && "Unknown rip-relative target");
Chris Lattnerd392bd92009-07-10 07:20:05 +000082
Chris Lattnerc7822322009-07-10 21:01:59 +000083 // Extra load is needed for all externally visible.
84 if (!GV->hasLocalLinkage() && GV->hasDefaultVisibility())
85 return X86II::MO_GOTPCREL;
86 }
Chris Lattnerd392bd92009-07-10 07:20:05 +000087
88 return X86II::MO_NO_FLAG;
89 }
90
91 if (isPICStyleGOT()) { // 32-bit ELF targets.
92 // Extra load is needed for all externally visible.
93 if (GV->hasLocalLinkage() || GV->hasHiddenVisibility())
94 return X86II::MO_GOTOFF;
95 return X86II::MO_GOT;
96 }
97
Chris Lattnere2c92082009-07-10 21:00:45 +000098 if (isPICStyleStubPIC()) { // Darwin/32 in PIC mode.
Chris Lattner84853a12009-07-10 20:53:38 +000099 // Determine whether we have a stub reference and/or whether the reference
100 // is relative to the PIC base or not.
Chris Lattnerd392bd92009-07-10 07:20:05 +0000101
102 // If this is a strong reference to a definition, it is definitely not
103 // through a stub.
Evan Chenga82b22c2009-07-16 22:53:10 +0000104 if (!isDecl && !GV->isWeakForLinker())
Chris Lattner84853a12009-07-10 20:53:38 +0000105 return X86II::MO_PIC_BASE_OFFSET;
Chris Lattnerd392bd92009-07-10 07:20:05 +0000106
107 // Unless we have a symbol with hidden visibility, we have to go through a
108 // normal $non_lazy_ptr stub because this symbol might be resolved late.
Chris Lattner84853a12009-07-10 20:53:38 +0000109 if (!GV->hasHiddenVisibility()) // Non-hidden $non_lazy_ptr reference.
110 return X86II::MO_DARWIN_NONLAZY_PIC_BASE;
Chris Lattnerd392bd92009-07-10 07:20:05 +0000111
112 // If symbol visibility is hidden, we have a stub for common symbol
113 // references and external declarations.
Evan Chenga82b22c2009-07-16 22:53:10 +0000114 if (isDecl || GV->hasCommonLinkage()) {
Chris Lattnerd392bd92009-07-10 07:20:05 +0000115 // Hidden $non_lazy_ptr reference.
Chris Lattner84853a12009-07-10 20:53:38 +0000116 return X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE;
Chris Lattnerd392bd92009-07-10 07:20:05 +0000117 }
118
119 // Otherwise, no stub.
Chris Lattner84853a12009-07-10 20:53:38 +0000120 return X86II::MO_PIC_BASE_OFFSET;
121 }
122
Chris Lattnere2c92082009-07-10 21:00:45 +0000123 if (isPICStyleStubNoDynamic()) { // Darwin/32 in -mdynamic-no-pic mode.
Chris Lattner84853a12009-07-10 20:53:38 +0000124 // Determine whether we have a stub reference.
125
126 // If this is a strong reference to a definition, it is definitely not
127 // through a stub.
Evan Chenga82b22c2009-07-16 22:53:10 +0000128 if (!isDecl && !GV->isWeakForLinker())
Chris Lattner84853a12009-07-10 20:53:38 +0000129 return X86II::MO_NO_FLAG;
130
131 // Unless we have a symbol with hidden visibility, we have to go through a
132 // normal $non_lazy_ptr stub because this symbol might be resolved late.
133 if (!GV->hasHiddenVisibility()) // Non-hidden $non_lazy_ptr reference.
134 return X86II::MO_DARWIN_NONLAZY;
Evan Cheng63476a82009-09-03 07:04:02 +0000135
Chris Lattner84853a12009-07-10 20:53:38 +0000136 // Otherwise, no stub.
137 return X86II::MO_NO_FLAG;
Chris Lattnerd392bd92009-07-10 07:20:05 +0000138 }
139
140 // Direct static reference to global.
141 return X86II::MO_NO_FLAG;
142}
143
Anton Korobeynikov7784ebc2006-11-30 22:42:55 +0000144
Bill Wendling6f287b22008-09-30 21:22:07 +0000145/// getBZeroEntry - This function returns the name of a function which has an
146/// interface like the non-standard bzero function, if such a function exists on
147/// the current subtarget and it is considered prefereable over memset with zero
148/// passed as the second argument. Otherwise it returns null.
Bill Wendling6e087382008-09-30 22:05:33 +0000149const char *X86Subtarget::getBZeroEntry() const {
Dan Gohman68d599d2008-04-01 20:38:36 +0000150 // Darwin 10 has a __bzero entry point for this purpose.
Daniel Dunbar558692f2011-04-20 00:14:25 +0000151 if (getTargetTriple().isMacOSX() &&
152 !getTargetTriple().isMacOSXVersionLT(10, 6))
Bill Wendling6e087382008-09-30 22:05:33 +0000153 return "__bzero";
Dan Gohman68d599d2008-04-01 20:38:36 +0000154
155 return 0;
156}
157
Evan Chengd7f666a2009-05-20 04:53:57 +0000158/// IsLegalToCallImmediateAddr - Return true if the subtarget allows calls
159/// to immediate address.
160bool X86Subtarget::IsLegalToCallImmediateAddr(const TargetMachine &TM) const {
Evan Cheng18fb1d32011-07-07 21:06:52 +0000161 if (In64BitMode)
Evan Chengd7f666a2009-05-20 04:53:57 +0000162 return false;
163 return isTargetELF() || TM.getRelocationModel() == Reloc::Static;
164}
165
Dan Gohman8749b612008-12-16 03:35:01 +0000166/// getSpecialAddressLatency - For targets where it is beneficial to
167/// backschedule instructions that compute addresses, return a value
168/// indicating the number of scheduling cycles of backscheduling that
169/// should be attempted.
170unsigned X86Subtarget::getSpecialAddressLatency() const {
171 // For x86 out-of-order targets, back-schedule address computations so
172 // that loads and stores aren't blocked.
173 // This value was chosen arbitrarily.
174 return 200;
175}
176
Evan Chenga26eb5e2006-10-06 09:17:41 +0000177void X86Subtarget::AutoDetectSubtargetFeatures() {
Evan Chengb3a7e212006-01-27 19:30:30 +0000178 unsigned EAX = 0, EBX = 0, ECX = 0, EDX = 0;
Craig Topper4145c492011-10-16 00:21:51 +0000179 unsigned MaxLevel;
Jeff Cohena3496402006-01-28 18:47:32 +0000180 union {
Jeff Cohen216d2812006-01-28 19:48:34 +0000181 unsigned u[3];
182 char c[12];
Jeff Cohena3496402006-01-28 18:47:32 +0000183 } text;
Craig Topper4145c492011-10-16 00:21:51 +0000184
185 if (X86_MC::GetCpuIDAndInfo(0, &MaxLevel, text.u+0, text.u+2, text.u+1) ||
186 MaxLevel < 1)
Evan Chengabc346c2006-10-06 08:21:07 +0000187 return;
Anton Korobeynikov3b5ee732007-03-23 23:46:48 +0000188
Evan Cheng18fb1d32011-07-07 21:06:52 +0000189 X86_MC::GetCpuIDAndInfo(0x1, &EAX, &EBX, &ECX, &EDX);
Craig Topper4145c492011-10-16 00:21:51 +0000190
Craig Topper1f104802011-10-10 05:34:02 +0000191 if ((EDX >> 15) & 1) { HasCMov = true; ToggleFeature(X86::FeatureCMOV); }
192 if ((EDX >> 23) & 1) { X86SSELevel = MMX; ToggleFeature(X86::FeatureMMX); }
193 if ((EDX >> 25) & 1) { X86SSELevel = SSE1; ToggleFeature(X86::FeatureSSE1); }
194 if ((EDX >> 26) & 1) { X86SSELevel = SSE2; ToggleFeature(X86::FeatureSSE2); }
195 if (ECX & 0x1) { X86SSELevel = SSE3; ToggleFeature(X86::FeatureSSE3); }
196 if ((ECX >> 9) & 1) { X86SSELevel = SSSE3; ToggleFeature(X86::FeatureSSSE3);}
197 if ((ECX >> 19) & 1) { X86SSELevel = SSE41; ToggleFeature(X86::FeatureSSE41);}
198 if ((ECX >> 20) & 1) { X86SSELevel = SSE42; ToggleFeature(X86::FeatureSSE42);}
Craig Topper1203f2f2012-04-26 06:40:15 +0000199 if ((ECX >> 28) & 1) { X86SSELevel = AVX; ToggleFeature(X86::FeatureAVX); }
Anton Korobeynikov3b5ee732007-03-23 23:46:48 +0000200
Evan Chengccb69762009-01-02 05:35:45 +0000201 bool IsIntel = memcmp(text.c, "GenuineIntel", 12) == 0;
202 bool IsAMD = !IsIntel && memcmp(text.c, "AuthenticAMD", 12) == 0;
David Greene343dadb2009-06-26 22:46:54 +0000203
Craig Topperc80e7d22012-05-01 07:10:32 +0000204 if ((ECX >> 1) & 0x1) {
Benjamin Kramerc8e340d2012-05-31 14:34:17 +0000205 HasPCLMUL = true;
206 ToggleFeature(X86::FeaturePCLMUL);
Craig Topper1f104802011-10-10 05:34:02 +0000207 }
Craig Topper14f094b2012-06-01 06:10:14 +0000208 if ((ECX >> 12) & 0x1) {
Craig Toppera15f9d52012-06-03 18:58:46 +0000209 HasFMA = true;
210 ToggleFeature(X86::FeatureFMA);
Craig Topper14f094b2012-06-01 06:10:14 +0000211 }
Craig Topper1f104802011-10-10 05:34:02 +0000212 if (IsIntel && ((ECX >> 22) & 0x1)) {
213 HasMOVBE = true;
214 ToggleFeature(X86::FeatureMOVBE);
215 }
Craig Topperc80e7d22012-05-01 07:10:32 +0000216 if ((ECX >> 23) & 0x1) {
Craig Topper1f104802011-10-10 05:34:02 +0000217 HasPOPCNT = true;
218 ToggleFeature(X86::FeaturePOPCNT);
219 }
Craig Topperc80e7d22012-05-01 07:10:32 +0000220 if ((ECX >> 25) & 0x1) {
Craig Topper1f104802011-10-10 05:34:02 +0000221 HasAES = true;
222 ToggleFeature(X86::FeatureAES);
223 }
Craig Topperc80e7d22012-05-01 07:10:32 +0000224 if ((ECX >> 29) & 0x1) {
Craig Topper1f104802011-10-10 05:34:02 +0000225 HasF16C = true;
226 ToggleFeature(X86::FeatureF16C);
227 }
228 if (IsIntel && ((ECX >> 30) & 0x1)) {
229 HasRDRAND = true;
230 ToggleFeature(X86::FeatureRDRAND);
231 }
232
233 if ((ECX >> 13) & 0x1) {
234 HasCmpxchg16b = true;
235 ToggleFeature(X86::FeatureCMPXCHG16B);
236 }
David Greene343dadb2009-06-26 22:46:54 +0000237
Evan Chengccb69762009-01-02 05:35:45 +0000238 if (IsIntel || IsAMD) {
239 // Determine if bit test memory instructions are slow.
240 unsigned Family = 0;
241 unsigned Model = 0;
Evan Cheng18fb1d32011-07-07 21:06:52 +0000242 X86_MC::DetectFamilyModel(EAX, Family, Model);
Evan Cheng59ee62d2011-07-11 03:57:24 +0000243 if (IsAMD || (Family == 6 && Model >= 13)) {
244 IsBTMemSlow = true;
245 ToggleFeature(X86::FeatureSlowBTMem);
246 }
Andrew Trick922d3142012-02-01 23:20:51 +0000247
Evan Cheng48c58bb2010-04-01 05:58:17 +0000248 // If it's Nehalem, unaligned memory access is fast.
Craig Topper4145c492011-10-16 00:21:51 +0000249 // FIXME: Nehalem is family 6. Also include Westmere and later processors?
Evan Cheng59ee62d2011-07-11 03:57:24 +0000250 if (Family == 15 && Model == 26) {
Evan Cheng48c58bb2010-04-01 05:58:17 +0000251 IsUAMemFast = true;
Evan Cheng59ee62d2011-07-11 03:57:24 +0000252 ToggleFeature(X86::FeatureFastUAMem);
253 }
Evan Chengccb69762009-01-02 05:35:45 +0000254
Andrew Trick922d3142012-02-01 23:20:51 +0000255 // Set processor type. Currently only Atom is detected.
Preston Gurd79bbe852012-05-02 21:38:46 +0000256 if (Family == 6 &&
Preston Gurdd4d96162012-07-18 20:49:17 +0000257 (Model == 28 || Model == 38 || Model == 39
258 /*|| Model == 53 || Model == 54*/)) {
Andrew Trick922d3142012-02-01 23:20:51 +0000259 X86ProcFamily = IntelAtom;
Preston Gurdc573b1f2012-04-26 19:52:27 +0000260
261 UseLeaForSP = true;
Evan Chengde1df102012-02-07 22:50:41 +0000262 ToggleFeature(X86::FeatureLeaForSP);
Andrew Trick922d3142012-02-01 23:20:51 +0000263 }
264
Craig Topper4145c492011-10-16 00:21:51 +0000265 unsigned MaxExtLevel;
266 X86_MC::GetCpuIDAndInfo(0x80000000, &MaxExtLevel, &EBX, &ECX, &EDX);
267
268 if (MaxExtLevel >= 0x80000001) {
269 X86_MC::GetCpuIDAndInfo(0x80000001, &EAX, &EBX, &ECX, &EDX);
270 if ((EDX >> 29) & 0x1) {
271 HasX86_64 = true;
272 ToggleFeature(X86::Feature64Bit);
273 }
274 if ((ECX >> 5) & 0x1) {
275 HasLZCNT = true;
276 ToggleFeature(X86::FeatureLZCNT);
277 }
Craig Topper5ebee442011-12-29 19:25:56 +0000278 if (IsAMD) {
279 if ((ECX >> 6) & 0x1) {
280 HasSSE4A = true;
281 ToggleFeature(X86::FeatureSSE4A);
282 }
283 if ((ECX >> 11) & 0x1) {
284 HasXOP = true;
285 ToggleFeature(X86::FeatureXOP);
286 }
287 if ((ECX >> 16) & 0x1) {
288 HasFMA4 = true;
289 ToggleFeature(X86::FeatureFMA4);
290 }
Craig Topper4145c492011-10-16 00:21:51 +0000291 }
Evan Cheng59ee62d2011-07-11 03:57:24 +0000292 }
Craig Topper4145c492011-10-16 00:21:51 +0000293 }
294
Craig Topperc80e7d22012-05-01 07:10:32 +0000295 if (MaxLevel >= 7) {
Craig Topper4b2dc742011-10-17 05:33:10 +0000296 if (!X86_MC::GetCpuIDAndInfoEx(0x7, 0x0, &EAX, &EBX, &ECX, &EDX)) {
Craig Topperc80e7d22012-05-01 07:10:32 +0000297 if (IsIntel && (EBX & 0x1)) {
Craig Toppere7b05502011-10-30 19:57:21 +0000298 HasFSGSBase = true;
299 ToggleFeature(X86::FeatureFSGSBase);
300 }
Craig Topper4b2dc742011-10-17 05:33:10 +0000301 if ((EBX >> 3) & 0x1) {
302 HasBMI = true;
303 ToggleFeature(X86::FeatureBMI);
304 }
Craig Topperc80e7d22012-05-01 07:10:32 +0000305 if (IsIntel && ((EBX >> 5) & 0x1)) {
Craig Topper1203f2f2012-04-26 06:40:15 +0000306 X86SSELevel = AVX2;
307 ToggleFeature(X86::FeatureAVX2);
308 }
Craig Topperc80e7d22012-05-01 07:10:32 +0000309 if (IsIntel && ((EBX >> 8) & 0x1)) {
Craig Topper4b2dc742011-10-17 05:33:10 +0000310 HasBMI2 = true;
311 ToggleFeature(X86::FeatureBMI2);
312 }
Craig Topperb53fa8b2011-10-16 07:55:05 +0000313 }
Jeff Cohenc3987092007-04-16 21:59:44 +0000314 }
Evan Cheng559806f2006-01-27 08:10:46 +0000315}
Evan Cheng97c7fc32006-01-26 09:53:06 +0000316
Evan Cheng276365d2011-06-30 01:53:36 +0000317X86Subtarget::X86Subtarget(const std::string &TT, const std::string &CPU,
318 const std::string &FS,
Evan Cheng4d1a8dd2011-07-08 22:30:25 +0000319 unsigned StackAlignOverride, bool is64Bit)
Evan Cheng0ddff1b2011-07-07 07:07:08 +0000320 : X86GenSubtargetInfo(TT, CPU, FS)
Andrew Trick922d3142012-02-01 23:20:51 +0000321 , X86ProcFamily(Others)
Evan Cheng94214702011-07-01 20:45:01 +0000322 , PICStyle(PICStyles::None)
Evan Cheng25ab6902006-09-08 06:48:29 +0000323 , X86SSELevel(NoMMXSSE)
Evan Chengdc008582008-04-16 19:03:02 +0000324 , X863DNowLevel(NoThreeDNow)
Chris Lattner70084162009-09-02 05:53:04 +0000325 , HasCMov(false)
Evan Cheng25ab6902006-09-08 06:48:29 +0000326 , HasX86_64(false)
Bill Wendlingd6434862010-12-04 23:57:24 +0000327 , HasPOPCNT(false)
David Greene343dadb2009-06-26 22:46:54 +0000328 , HasSSE4A(false)
Eric Christopher6d1cd1c2010-04-02 21:54:27 +0000329 , HasAES(false)
Benjamin Kramerc8e340d2012-05-31 14:34:17 +0000330 , HasPCLMUL(false)
Craig Toppera15f9d52012-06-03 18:58:46 +0000331 , HasFMA(false)
David Greene343dadb2009-06-26 22:46:54 +0000332 , HasFMA4(false)
Jan Sjödince25d262011-12-02 15:14:37 +0000333 , HasXOP(false)
Craig Topper581fe822011-10-03 17:28:23 +0000334 , HasMOVBE(false)
335 , HasRDRAND(false)
Craig Topperda394042011-10-09 07:31:39 +0000336 , HasF16C(false)
Craig Toppere7b05502011-10-30 19:57:21 +0000337 , HasFSGSBase(false)
Craig Topper37f21672011-10-11 06:44:02 +0000338 , HasLZCNT(false)
Craig Topper909652f2011-10-14 03:21:46 +0000339 , HasBMI(false)
Craig Topperb53fa8b2011-10-16 07:55:05 +0000340 , HasBMI2(false)
Evan Chengccb69762009-01-02 05:35:45 +0000341 , IsBTMemSlow(false)
Evan Cheng48c58bb2010-04-01 05:58:17 +0000342 , IsUAMemFast(false)
David Greene95eb2ee2010-01-11 16:29:42 +0000343 , HasVectorUAMem(false)
Eli Friedman43f51ae2011-08-26 21:21:21 +0000344 , HasCmpxchg16b(false)
Evan Chengde1df102012-02-07 22:50:41 +0000345 , UseLeaForSP(false)
Andrew Trick922d3142012-02-01 23:20:51 +0000346 , PostRAScheduler(false)
Joerg Sonnenberger216f6372012-01-10 22:43:53 +0000347 , stackAlignment(4)
Evan Cheng25ab6902006-09-08 06:48:29 +0000348 // FIXME: this is a known good value for Yonah. How about others?
Rafael Espindolafc05f402007-10-31 11:52:06 +0000349 , MaxInlineSizeThreshold(128)
Eric Christopher62f35a22010-07-05 19:26:33 +0000350 , TargetTriple(TT)
David Meyer928698b2011-10-18 05:29:23 +0000351 , In64BitMode(is64Bit) {
Evan Cheng97c7fc32006-01-26 09:53:06 +0000352 // Determine default and user specified characteristics
Andrew Trick922d3142012-02-01 23:20:51 +0000353 std::string CPUName = CPU;
Evan Cheng4d1a8dd2011-07-08 22:30:25 +0000354 if (!FS.empty() || !CPU.empty()) {
Evan Chengcc0ddc72011-07-08 21:14:14 +0000355 if (CPUName.empty()) {
Evan Cheng893a0452012-01-30 23:10:32 +0000356#if defined(i386) || defined(__i386__) || defined(__x86__) || defined(_M_IX86)\
357 || defined(__x86_64__) || defined(_M_AMD64) || defined (_M_X64)
Evan Chengcc0ddc72011-07-08 21:14:14 +0000358 CPUName = sys::getHostCPUName();
359#else
360 CPUName = "generic";
361#endif
362 }
363
Eli Friedman439d05d2011-07-08 23:43:01 +0000364 // Make sure 64-bit features are available in 64-bit mode. (But make sure
365 // SSE2 can be turned off explicitly.)
366 std::string FullFS = FS;
367 if (In64BitMode) {
368 if (!FullFS.empty())
369 FullFS = "+64bit,+sse2," + FullFS;
370 else
371 FullFS = "+64bit,+sse2";
372 }
Evan Cheng4d1a8dd2011-07-08 22:30:25 +0000373
Eli Friedman439d05d2011-07-08 23:43:01 +0000374 // If feature string is not empty, parse features string.
375 ParseSubtargetFeatures(CPUName, FullFS);
Chris Lattner3b6f4972006-11-20 18:16:05 +0000376 } else {
Andrew Trick922d3142012-02-01 23:20:51 +0000377 if (CPUName.empty()) {
378#if defined (__x86_64__) || defined(__i386__)
379 CPUName = sys::getHostCPUName();
380#else
381 CPUName = "generic";
382#endif
383 }
Chris Lattner3b6f4972006-11-20 18:16:05 +0000384 // Otherwise, use CPUID to auto-detect feature set.
385 AutoDetectSubtargetFeatures();
Evan Cheng18fb1d32011-07-07 21:06:52 +0000386
Eli Friedman6dfef662011-07-08 23:07:42 +0000387 // Make sure 64-bit features are available in 64-bit mode.
388 if (In64BitMode) {
Evan Cheng59ee62d2011-07-11 03:57:24 +0000389 HasX86_64 = true; ToggleFeature(X86::Feature64Bit);
390 HasCMov = true; ToggleFeature(X86::FeatureCMOV);
Eli Friedman6dfef662011-07-08 23:07:42 +0000391
Craig Topper16de4632012-01-09 09:02:13 +0000392 if (X86SSELevel < SSE2) {
Eli Friedman6dfef662011-07-08 23:07:42 +0000393 X86SSELevel = SSE2;
Evan Cheng59ee62d2011-07-11 03:57:24 +0000394 ToggleFeature(X86::FeatureSSE1);
395 ToggleFeature(X86::FeatureSSE2);
396 }
Eli Friedman6dfef662011-07-08 23:07:42 +0000397 }
Evan Cheng25ab6902006-09-08 06:48:29 +0000398 }
Evan Cheng59ee62d2011-07-11 03:57:24 +0000399
Andrew Trick922d3142012-02-01 23:20:51 +0000400 if (X86ProcFamily == IntelAtom) {
401 PostRAScheduler = true;
402 InstrItins = getInstrItineraryForCPU(CPUName);
403 }
404
Evan Cheng59ee62d2011-07-11 03:57:24 +0000405 // It's important to keep the MCSubtargetInfo feature bits in sync with
406 // target data structure which is shared with MC code emitter, etc.
407 if (In64BitMode)
408 ToggleFeature(X86::Mode64Bit);
409
David Greenebd7b8452010-01-05 01:29:13 +0000410 DEBUG(dbgs() << "Subtarget features: SSELevel " << X86SSELevel
Bill Wendling0ea8bf32009-08-03 00:11:34 +0000411 << ", 3DNowLevel " << X863DNowLevel
412 << ", 64bit " << HasX86_64 << "\n");
Evan Cheng18fb1d32011-07-07 21:06:52 +0000413 assert((!In64BitMode || HasX86_64) &&
Dan Gohmanf75e5b42009-02-03 00:04:43 +0000414 "64-bit code requested on a subtarget that doesn't support it!");
Evan Cheng25ab6902006-09-08 06:48:29 +0000415
Roman Divacky4c3ab582011-02-22 17:30:05 +0000416 // Stack alignment is 16 bytes on Darwin, FreeBSD, Linux and Solaris (both
417 // 32 and 64 bit) and for all 64-bit targets.
Evan Chengef41ff62011-06-23 17:54:54 +0000418 if (StackAlignOverride)
419 stackAlignment = StackAlignOverride;
420 else if (isTargetDarwin() || isTargetFreeBSD() || isTargetLinux() ||
Evan Cheng18fb1d32011-07-07 21:06:52 +0000421 isTargetSolaris() || In64BitMode)
Nate Begemanfb5792f2005-07-12 01:41:54 +0000422 stackAlignment = 16;
Dan Gohman4d3d6e12010-05-27 18:43:40 +0000423}
Andrew Trick922d3142012-02-01 23:20:51 +0000424
425bool X86Subtarget::enablePostRAScheduler(
426 CodeGenOpt::Level OptLevel,
427 TargetSubtargetInfo::AntiDepBreakMode& Mode,
428 RegClassVector& CriticalPathRCs) const {
Preston Gurd6a8c7bf2012-04-23 21:39:35 +0000429 Mode = TargetSubtargetInfo::ANTIDEP_CRITICAL;
Andrew Trick922d3142012-02-01 23:20:51 +0000430 CriticalPathRCs.clear();
431 return PostRAScheduler && OptLevel >= CodeGenOpt::Default;
432}