blob: 6e5d8d808d8a90b2343dc1bb15a113d7677b3c56 [file] [log] [blame]
Nate Begeman3bcfcd92005-08-04 07:12:09 +00001//===-- X86Subtarget.cpp - X86 Subtarget Information ------------*- C++ -*-===//
Nate Begemanf26625e2005-07-12 01:41:54 +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.
Nate Begemanf26625e2005-07-12 01:41:54 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the X86 specific subclass of TargetSubtarget.
11//
12//===----------------------------------------------------------------------===//
13
Evan Cheng9a3ec1b2009-01-03 04:04:46 +000014#define DEBUG_TYPE "subtarget"
Nate Begemanf26625e2005-07-12 01:41:54 +000015#include "X86Subtarget.h"
Chris Lattnerdc842c02009-07-10 07:20:05 +000016#include "X86InstrInfo.h"
Evan Chengff1beda2006-10-06 09:17:41 +000017#include "X86GenSubtarget.inc"
Daniel Dunbar31b44e82009-08-02 22:11:08 +000018#include "llvm/GlobalValue.h"
Jim Laskeyc7abe472006-09-07 12:23:47 +000019#include "llvm/Support/CommandLine.h"
Evan Cheng9a3ec1b2009-01-03 04:04:46 +000020#include "llvm/Support/Debug.h"
Anton Korobeynikov430e68a12006-12-22 22:29:05 +000021#include "llvm/Target/TargetMachine.h"
Anton Korobeynikovcb195f52008-04-23 18:18:10 +000022#include "llvm/Target/TargetOptions.h"
Nate Begemanf26625e2005-07-12 01:41:54 +000023using namespace llvm;
24
Chris Lattner3ad60b12009-04-25 18:27:23 +000025#if defined(_MSC_VER)
26 #include <intrin.h>
27#endif
28
Dan Gohmand78c4002008-05-13 00:00:25 +000029static cl::opt<X86Subtarget::AsmWriterFlavorTy>
Anton Korobeynikova0554d92007-01-12 19:20:47 +000030AsmWriterFlavor("x86-asm-syntax", cl::init(X86Subtarget::Unset),
Jim Laskeyc7abe472006-09-07 12:23:47 +000031 cl::desc("Choose style of code to emit from X86 backend:"),
32 cl::values(
Dan Gohman9c4b7d52008-10-14 20:25:08 +000033 clEnumValN(X86Subtarget::ATT, "att", "Emit AT&T-style assembly"),
34 clEnumValN(X86Subtarget::Intel, "intel", "Emit Intel-style assembly"),
Chris Lattnerb9e0a9e2006-09-07 22:29:41 +000035 clEnumValEnd));
Jim Laskeyc7abe472006-09-07 12:23:47 +000036
Chris Lattnerdc842c02009-07-10 07:20:05 +000037/// ClassifyGlobalReference - Classify a global variable reference for the
38/// current subtarget according to how we should reference it in a non-pcrel
39/// context.
40unsigned char X86Subtarget::
41ClassifyGlobalReference(const GlobalValue *GV, const TargetMachine &TM) const {
42 // DLLImport only exists on windows, it is implemented as a load from a
43 // DLLIMPORT stub.
44 if (GV->hasDLLImportLinkage())
45 return X86II::MO_DLLIMPORT;
46
Evan Cheng02a76522009-07-16 22:53:10 +000047 // GV with ghost linkage (in JIT lazy compilation mode) do not require an
48 // extra load from stub.
49 bool isDecl = GV->isDeclaration() && !GV->hasNotBeenReadFromBitcode();
50
Chris Lattnerdc842c02009-07-10 07:20:05 +000051 // X86-64 in PIC mode.
52 if (isPICStyleRIPRel()) {
53 // Large model never uses stubs.
54 if (TM.getCodeModel() == CodeModel::Large)
55 return X86II::MO_NO_FLAG;
56
Chris Lattner7dce9912009-07-10 21:01:59 +000057 if (isTargetDarwin()) {
58 // If symbol visibility is hidden, the extra load is not needed if
59 // target is x86-64 or the symbol is definitely defined in the current
60 // translation unit.
61 if (GV->hasDefaultVisibility() &&
Evan Cheng02a76522009-07-16 22:53:10 +000062 (isDecl || GV->isWeakForLinker()))
Chris Lattner7dce9912009-07-10 21:01:59 +000063 return X86II::MO_GOTPCREL;
64 } else {
65 assert(isTargetELF() && "Unknown rip-relative target");
Chris Lattnerdc842c02009-07-10 07:20:05 +000066
Chris Lattner7dce9912009-07-10 21:01:59 +000067 // Extra load is needed for all externally visible.
68 if (!GV->hasLocalLinkage() && GV->hasDefaultVisibility())
69 return X86II::MO_GOTPCREL;
70 }
Chris Lattnerdc842c02009-07-10 07:20:05 +000071
72 return X86II::MO_NO_FLAG;
73 }
74
75 if (isPICStyleGOT()) { // 32-bit ELF targets.
76 // Extra load is needed for all externally visible.
77 if (GV->hasLocalLinkage() || GV->hasHiddenVisibility())
78 return X86II::MO_GOTOFF;
79 return X86II::MO_GOT;
80 }
81
Chris Lattner21c29402009-07-10 21:00:45 +000082 if (isPICStyleStubPIC()) { // Darwin/32 in PIC mode.
Chris Lattnerbd3e5602009-07-10 20:53:38 +000083 // Determine whether we have a stub reference and/or whether the reference
84 // is relative to the PIC base or not.
Chris Lattnerdc842c02009-07-10 07:20:05 +000085
86 // If this is a strong reference to a definition, it is definitely not
87 // through a stub.
Evan Cheng02a76522009-07-16 22:53:10 +000088 if (!isDecl && !GV->isWeakForLinker())
Chris Lattnerbd3e5602009-07-10 20:53:38 +000089 return X86II::MO_PIC_BASE_OFFSET;
Chris Lattnerdc842c02009-07-10 07:20:05 +000090
91 // Unless we have a symbol with hidden visibility, we have to go through a
92 // normal $non_lazy_ptr stub because this symbol might be resolved late.
Chris Lattnerbd3e5602009-07-10 20:53:38 +000093 if (!GV->hasHiddenVisibility()) // Non-hidden $non_lazy_ptr reference.
94 return X86II::MO_DARWIN_NONLAZY_PIC_BASE;
Chris Lattnerdc842c02009-07-10 07:20:05 +000095
96 // If symbol visibility is hidden, we have a stub for common symbol
97 // references and external declarations.
Evan Cheng02a76522009-07-16 22:53:10 +000098 if (isDecl || GV->hasCommonLinkage()) {
Chris Lattnerdc842c02009-07-10 07:20:05 +000099 // Hidden $non_lazy_ptr reference.
Chris Lattnerbd3e5602009-07-10 20:53:38 +0000100 return X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE;
Chris Lattnerdc842c02009-07-10 07:20:05 +0000101 }
102
103 // Otherwise, no stub.
Chris Lattnerbd3e5602009-07-10 20:53:38 +0000104 return X86II::MO_PIC_BASE_OFFSET;
105 }
106
Chris Lattner21c29402009-07-10 21:00:45 +0000107 if (isPICStyleStubNoDynamic()) { // Darwin/32 in -mdynamic-no-pic mode.
Chris Lattnerbd3e5602009-07-10 20:53:38 +0000108 // Determine whether we have a stub reference.
109
110 // If this is a strong reference to a definition, it is definitely not
111 // through a stub.
Evan Cheng02a76522009-07-16 22:53:10 +0000112 if (!isDecl && !GV->isWeakForLinker())
Chris Lattnerbd3e5602009-07-10 20:53:38 +0000113 return X86II::MO_NO_FLAG;
114
115 // Unless we have a symbol with hidden visibility, we have to go through a
116 // normal $non_lazy_ptr stub because this symbol might be resolved late.
117 if (!GV->hasHiddenVisibility()) // Non-hidden $non_lazy_ptr reference.
118 return X86II::MO_DARWIN_NONLAZY;
119
120 // If symbol visibility is hidden, we have a stub for common symbol
121 // references and external declarations.
Evan Cheng02a76522009-07-16 22:53:10 +0000122 if (isDecl || GV->hasCommonLinkage()) {
Chris Lattnerbd3e5602009-07-10 20:53:38 +0000123 // Hidden $non_lazy_ptr reference.
124 return X86II::MO_DARWIN_HIDDEN_NONLAZY;
125 }
126
127 // Otherwise, no stub.
128 return X86II::MO_NO_FLAG;
Chris Lattnerdc842c02009-07-10 07:20:05 +0000129 }
130
131 // Direct static reference to global.
132 return X86II::MO_NO_FLAG;
133}
134
Anton Korobeynikov6dbdfe22006-11-30 22:42:55 +0000135
Bill Wendlingbd092622008-09-30 21:22:07 +0000136/// getBZeroEntry - This function returns the name of a function which has an
137/// interface like the non-standard bzero function, if such a function exists on
138/// the current subtarget and it is considered prefereable over memset with zero
139/// passed as the second argument. Otherwise it returns null.
Bill Wendling17825842008-09-30 22:05:33 +0000140const char *X86Subtarget::getBZeroEntry() const {
Dan Gohman980d7202008-04-01 20:38:36 +0000141 // Darwin 10 has a __bzero entry point for this purpose.
142 if (getDarwinVers() >= 10)
Bill Wendling17825842008-09-30 22:05:33 +0000143 return "__bzero";
Dan Gohman980d7202008-04-01 20:38:36 +0000144
145 return 0;
146}
147
Evan Cheng96098332009-05-20 04:53:57 +0000148/// IsLegalToCallImmediateAddr - Return true if the subtarget allows calls
149/// to immediate address.
150bool X86Subtarget::IsLegalToCallImmediateAddr(const TargetMachine &TM) const {
151 if (Is64Bit)
152 return false;
153 return isTargetELF() || TM.getRelocationModel() == Reloc::Static;
154}
155
Dan Gohmanb9a01212008-12-16 03:35:01 +0000156/// getSpecialAddressLatency - For targets where it is beneficial to
157/// backschedule instructions that compute addresses, return a value
158/// indicating the number of scheduling cycles of backscheduling that
159/// should be attempted.
160unsigned X86Subtarget::getSpecialAddressLatency() const {
161 // For x86 out-of-order targets, back-schedule address computations so
162 // that loads and stores aren't blocked.
163 // This value was chosen arbitrarily.
164 return 200;
165}
166
Chris Lattnerdc8bbb62006-01-28 06:05:41 +0000167/// GetCpuIDAndInfo - Execute the specified cpuid and return the 4 values in the
168/// specified arguments. If we can't run cpuid on the host, return true.
Evan Chenga8b4aea2006-10-16 21:00:37 +0000169bool X86::GetCpuIDAndInfo(unsigned value, unsigned *rEAX, unsigned *rEBX,
170 unsigned *rECX, unsigned *rEDX) {
Chris Lattner3ad60b12009-04-25 18:27:23 +0000171#if defined(__x86_64__) || defined(_M_AMD64)
172 #if defined(__GNUC__)
173 // gcc doesn't know cpuid would clobber ebx/rbx. Preseve it manually.
174 asm ("movq\t%%rbx, %%rsi\n\t"
175 "cpuid\n\t"
176 "xchgq\t%%rbx, %%rsi\n\t"
177 : "=a" (*rEAX),
178 "=S" (*rEBX),
179 "=c" (*rECX),
180 "=d" (*rEDX)
181 : "a" (value));
182 return false;
183 #elif defined(_MSC_VER)
184 int registers[4];
185 __cpuid(registers, value);
186 *rEAX = registers[0];
187 *rEBX = registers[1];
188 *rECX = registers[2];
189 *rEDX = registers[3];
190 return false;
191 #endif
Evan Cheng11b0a5d2006-09-08 06:48:29 +0000192#elif defined(i386) || defined(__i386__) || defined(__x86__) || defined(_M_IX86)
Chris Lattner3ad60b12009-04-25 18:27:23 +0000193 #if defined(__GNUC__)
194 asm ("movl\t%%ebx, %%esi\n\t"
195 "cpuid\n\t"
196 "xchgl\t%%ebx, %%esi\n\t"
197 : "=a" (*rEAX),
198 "=S" (*rEBX),
199 "=c" (*rECX),
200 "=d" (*rEDX)
201 : "a" (value));
202 return false;
203 #elif defined(_MSC_VER)
204 __asm {
205 mov eax,value
206 cpuid
207 mov esi,rEAX
208 mov dword ptr [esi],eax
209 mov esi,rEBX
210 mov dword ptr [esi],ebx
211 mov esi,rECX
212 mov dword ptr [esi],ecx
213 mov esi,rEDX
214 mov dword ptr [esi],edx
215 }
216 return false;
217 #endif
Evan Chengcde9e302006-01-27 08:10:46 +0000218#endif
Chris Lattnerdc8bbb62006-01-28 06:05:41 +0000219 return true;
Evan Chengcde9e302006-01-27 08:10:46 +0000220}
221
Evan Cheng4c91aa32009-01-02 05:35:45 +0000222static void DetectFamilyModel(unsigned EAX, unsigned &Family, unsigned &Model) {
223 Family = (EAX >> 8) & 0xf; // Bits 8 - 11
224 Model = (EAX >> 4) & 0xf; // Bits 4 - 7
225 if (Family == 6 || Family == 0xf) {
226 if (Family == 0xf)
227 // Examine extended family ID if family ID is F.
228 Family += (EAX >> 20) & 0xff; // Bits 20 - 27
229 // Examine extended model ID if family ID is 6 or F.
230 Model += ((EAX >> 16) & 0xf) << 4; // Bits 16 - 19
231 }
232}
233
Evan Chengff1beda2006-10-06 09:17:41 +0000234void X86Subtarget::AutoDetectSubtargetFeatures() {
Evan Chengafab7aa2006-01-27 19:30:30 +0000235 unsigned EAX = 0, EBX = 0, ECX = 0, EDX = 0;
Jeff Cohen71287082006-01-28 18:47:32 +0000236 union {
Jeff Cohen58ca0be92006-01-28 19:48:34 +0000237 unsigned u[3];
238 char c[12];
Jeff Cohen71287082006-01-28 18:47:32 +0000239 } text;
Chris Lattner3e962112006-11-20 18:16:05 +0000240
Evan Chenga8b4aea2006-10-16 21:00:37 +0000241 if (X86::GetCpuIDAndInfo(0, &EAX, text.u+0, text.u+2, text.u+1))
Evan Cheng9274f722006-10-06 08:21:07 +0000242 return;
Anton Korobeynikov8aae2d72007-03-23 23:46:48 +0000243
244 X86::GetCpuIDAndInfo(0x1, &EAX, &EBX, &ECX, &EDX);
Chris Lattner3e962112006-11-20 18:16:05 +0000245
Anton Korobeynikov8aae2d72007-03-23 23:46:48 +0000246 if ((EDX >> 23) & 0x1) X86SSELevel = MMX;
247 if ((EDX >> 25) & 0x1) X86SSELevel = SSE1;
248 if ((EDX >> 26) & 0x1) X86SSELevel = SSE2;
249 if (ECX & 0x1) X86SSELevel = SSE3;
Bill Wendlingf0998412007-04-10 22:10:25 +0000250 if ((ECX >> 9) & 0x1) X86SSELevel = SSSE3;
Nate Begemane14fdfa2008-02-03 07:18:54 +0000251 if ((ECX >> 19) & 0x1) X86SSELevel = SSE41;
252 if ((ECX >> 20) & 0x1) X86SSELevel = SSE42;
Anton Korobeynikov8aae2d72007-03-23 23:46:48 +0000253
Evan Cheng4c91aa32009-01-02 05:35:45 +0000254 bool IsIntel = memcmp(text.c, "GenuineIntel", 12) == 0;
255 bool IsAMD = !IsIntel && memcmp(text.c, "AuthenticAMD", 12) == 0;
David Greene8f6f72c2009-06-26 22:46:54 +0000256
257 HasFMA3 = IsIntel && ((ECX >> 12) & 0x1);
258 HasAVX = ((ECX >> 28) & 0x1);
259
Evan Cheng4c91aa32009-01-02 05:35:45 +0000260 if (IsIntel || IsAMD) {
261 // Determine if bit test memory instructions are slow.
262 unsigned Family = 0;
263 unsigned Model = 0;
264 DetectFamilyModel(EAX, Family, Model);
265 IsBTMemSlow = IsAMD || (Family == 6 && Model >= 13);
266
Jeff Cohen6f3a5482007-04-16 21:59:44 +0000267 X86::GetCpuIDAndInfo(0x80000001, &EAX, &EBX, &ECX, &EDX);
268 HasX86_64 = (EDX >> 29) & 0x1;
Stefanus Du Toit96180b52009-05-26 21:04:35 +0000269 HasSSE4A = IsAMD && ((ECX >> 6) & 0x1);
David Greene8f6f72c2009-06-26 22:46:54 +0000270 HasFMA4 = IsAMD && ((ECX >> 16) & 0x1);
Jeff Cohen6f3a5482007-04-16 21:59:44 +0000271 }
Evan Chengcde9e302006-01-27 08:10:46 +0000272}
Evan Cheng54c13da2006-01-26 09:53:06 +0000273
Evan Chengff1beda2006-10-06 09:17:41 +0000274static const char *GetCurrentX86CPU() {
275 unsigned EAX = 0, EBX = 0, ECX = 0, EDX = 0;
Evan Chenga8b4aea2006-10-16 21:00:37 +0000276 if (X86::GetCpuIDAndInfo(0x1, &EAX, &EBX, &ECX, &EDX))
Evan Chengff1beda2006-10-06 09:17:41 +0000277 return "generic";
Evan Cheng4c91aa32009-01-02 05:35:45 +0000278 unsigned Family = 0;
279 unsigned Model = 0;
280 DetectFamilyModel(EAX, Family, Model);
Evan Cheng13f3a332009-01-02 05:29:20 +0000281
Evan Chenga8b4aea2006-10-16 21:00:37 +0000282 X86::GetCpuIDAndInfo(0x80000001, &EAX, &EBX, &ECX, &EDX);
Evan Cheng5fe96802006-10-06 18:57:51 +0000283 bool Em64T = (EDX >> 29) & 0x1;
Stefanus Du Toit96180b52009-05-26 21:04:35 +0000284 bool HasSSE3 = (ECX & 0x1);
Evan Chengff1beda2006-10-06 09:17:41 +0000285
286 union {
287 unsigned u[3];
288 char c[12];
289 } text;
290
Evan Chenga8b4aea2006-10-16 21:00:37 +0000291 X86::GetCpuIDAndInfo(0, &EAX, text.u+0, text.u+2, text.u+1);
Evan Chengff1beda2006-10-06 09:17:41 +0000292 if (memcmp(text.c, "GenuineIntel", 12) == 0) {
293 switch (Family) {
294 case 3:
295 return "i386";
296 case 4:
297 return "i486";
298 case 5:
299 switch (Model) {
300 case 4: return "pentium-mmx";
301 default: return "pentium";
302 }
303 case 6:
304 switch (Model) {
305 case 1: return "pentiumpro";
306 case 3:
307 case 5:
308 case 6: return "pentium2";
309 case 7:
310 case 8:
311 case 10:
312 case 11: return "pentium3";
313 case 9:
314 case 13: return "pentium-m";
315 case 14: return "yonah";
Evan Cheng9a3ec1b2009-01-03 04:04:46 +0000316 case 15:
317 case 22: // Celeron M 540
318 return "core2";
319 case 23: // 45nm: Penryn , Wolfdale, Yorkfield (XE)
320 return "penryn";
Evan Chengff1beda2006-10-06 09:17:41 +0000321 default: return "i686";
322 }
323 case 15: {
324 switch (Model) {
325 case 3:
326 case 4:
Evan Cheng9a3ec1b2009-01-03 04:04:46 +0000327 case 6: // same as 4, but 65nm
Evan Chengff1beda2006-10-06 09:17:41 +0000328 return (Em64T) ? "nocona" : "prescott";
Evan Chengc3b09c32009-01-05 08:45:01 +0000329 case 26:
330 return "corei7";
Evan Cheng9a3ec1b2009-01-03 04:04:46 +0000331 case 28:
Evan Chengc3b09c32009-01-05 08:45:01 +0000332 return "atom";
Evan Chengff1beda2006-10-06 09:17:41 +0000333 default:
334 return (Em64T) ? "x86-64" : "pentium4";
335 }
336 }
337
338 default:
339 return "generic";
340 }
341 } else if (memcmp(text.c, "AuthenticAMD", 12) == 0) {
342 // FIXME: this poorly matches the generated SubtargetFeatureKV table. There
343 // appears to be no way to generate the wide variety of AMD-specific targets
344 // from the information returned from CPUID.
345 switch (Family) {
346 case 4:
347 return "i486";
348 case 5:
349 switch (Model) {
350 case 6:
351 case 7: return "k6";
352 case 8: return "k6-2";
353 case 9:
354 case 13: return "k6-3";
355 default: return "pentium";
356 }
357 case 6:
358 switch (Model) {
359 case 4: return "athlon-tbird";
360 case 6:
361 case 7:
362 case 8: return "athlon-mp";
363 case 10: return "athlon-xp";
364 default: return "athlon";
365 }
366 case 15:
Stefanus Du Toit96180b52009-05-26 21:04:35 +0000367 if (HasSSE3) {
Daniel Dunbarac0ca922009-07-19 01:38:38 +0000368 return "k8-sse3";
Stefanus Du Toit96180b52009-05-26 21:04:35 +0000369 } else {
370 switch (Model) {
371 case 1: return "opteron";
372 case 5: return "athlon-fx"; // also opteron
373 default: return "athlon64";
374 }
375 }
376 case 16:
Daniel Dunbarac0ca922009-07-19 01:38:38 +0000377 return "amdfam10";
Evan Chengff1beda2006-10-06 09:17:41 +0000378 default:
379 return "generic";
380 }
381 } else {
382 return "generic";
383 }
384}
385
Daniel Dunbar31b44e82009-08-02 22:11:08 +0000386X86Subtarget::X86Subtarget(const std::string &TT, const std::string &FS,
387 bool is64Bit)
Evan Cheng412aaab2006-10-04 18:33:00 +0000388 : AsmFlavor(AsmWriterFlavor)
Duncan Sands595a4422008-11-28 09:29:37 +0000389 , PICStyle(PICStyles::None)
Evan Cheng11b0a5d2006-09-08 06:48:29 +0000390 , X86SSELevel(NoMMXSSE)
Evan Chenga15cee12008-04-16 19:03:02 +0000391 , X863DNowLevel(NoThreeDNow)
Evan Cheng11b0a5d2006-09-08 06:48:29 +0000392 , HasX86_64(false)
David Greene8f6f72c2009-06-26 22:46:54 +0000393 , HasSSE4A(false)
394 , HasAVX(false)
395 , HasFMA3(false)
396 , HasFMA4(false)
Evan Cheng4c91aa32009-01-02 05:35:45 +0000397 , IsBTMemSlow(false)
Chris Lattnercce79c62008-01-02 19:44:55 +0000398 , DarwinVers(0)
Dan Gohmanb42c28c2008-05-05 18:43:07 +0000399 , IsLinux(false)
Evan Cheng11b0a5d2006-09-08 06:48:29 +0000400 , stackAlignment(8)
401 // FIXME: this is a known good value for Yonah. How about others?
Rafael Espindola063f1772007-10-31 11:52:06 +0000402 , MaxInlineSizeThreshold(128)
Evan Cheng11b0a5d2006-09-08 06:48:29 +0000403 , Is64Bit(is64Bit)
404 , TargetType(isELF) { // Default to ELF unless otherwise specified.
Anton Korobeynikov77d19432009-06-08 22:53:56 +0000405
406 // default to hard float ABI
407 if (FloatABIType == FloatABI::Default)
408 FloatABIType = FloatABI::Hard;
Mon P Wang3e583932008-05-05 19:05:59 +0000409
Evan Cheng54c13da2006-01-26 09:53:06 +0000410 // Determine default and user specified characteristics
Evan Chengff1beda2006-10-06 09:17:41 +0000411 if (!FS.empty()) {
412 // If feature string is not empty, parse features string.
413 std::string CPU = GetCurrentX86CPU();
414 ParseSubtargetFeatures(FS, CPU);
Torok Edwine8386602009-02-02 21:57:34 +0000415 // All X86-64 CPUs also have SSE2, however user might request no SSE via
416 // -mattr, so don't force SSELevel here.
Chris Lattner3e962112006-11-20 18:16:05 +0000417 } else {
418 // Otherwise, use CPUID to auto-detect feature set.
419 AutoDetectSubtargetFeatures();
Dan Gohman74037512009-02-03 00:04:43 +0000420 // Make sure SSE2 is enabled; it is available on all X86-64 CPUs.
421 if (Is64Bit && X86SSELevel < SSE2)
422 X86SSELevel = SSE2;
Evan Cheng11b0a5d2006-09-08 06:48:29 +0000423 }
Dan Gohman74037512009-02-03 00:04:43 +0000424
Dan Gohman561d1222009-02-03 18:53:21 +0000425 // If requesting codegen for X86-64, make sure that 64-bit features
426 // are enabled.
427 if (Is64Bit)
428 HasX86_64 = true;
429
Evan Cheng9a3ec1b2009-01-03 04:04:46 +0000430 DOUT << "Subtarget features: SSELevel " << X86SSELevel
431 << ", 3DNowLevel " << X863DNowLevel
432 << ", 64bit " << HasX86_64 << "\n";
Dan Gohman74037512009-02-03 00:04:43 +0000433 assert((!Is64Bit || HasX86_64) &&
434 "64-bit code requested on a subtarget that doesn't support it!");
Evan Cheng11b0a5d2006-09-08 06:48:29 +0000435
Nate Begemanf26625e2005-07-12 01:41:54 +0000436 // Set the boolean corresponding to the current target triple, or the default
437 // if one cannot be determined, to true.
Nate Begemanf26625e2005-07-12 01:41:54 +0000438 if (TT.length() > 5) {
Duncan Sandsbb956ca2008-01-08 10:06:15 +0000439 size_t Pos;
Chris Lattnercce79c62008-01-02 19:44:55 +0000440 if ((Pos = TT.find("-darwin")) != std::string::npos) {
Chris Lattner3eb87612005-11-21 22:31:58 +0000441 TargetType = isDarwin;
Chris Lattnercce79c62008-01-02 19:44:55 +0000442
443 // Compute the darwin version number.
444 if (isdigit(TT[Pos+7]))
445 DarwinVers = atoi(&TT[Pos+7]);
446 else
447 DarwinVers = 8; // Minimum supported darwin is Tiger.
Dan Gohmanbcde1722008-05-05 00:28:39 +0000448 } else if (TT.find("linux") != std::string::npos) {
Dan Gohman6fd71c62008-05-05 16:11:31 +0000449 // Linux doesn't imply ELF, but we don't currently support anything else.
450 TargetType = isELF;
451 IsLinux = true;
Chris Lattnercce79c62008-01-02 19:44:55 +0000452 } else if (TT.find("cygwin") != std::string::npos) {
453 TargetType = isCygwin;
454 } else if (TT.find("mingw") != std::string::npos) {
455 TargetType = isMingw;
456 } else if (TT.find("win32") != std::string::npos) {
Chris Lattner3eb87612005-11-21 22:31:58 +0000457 TargetType = isWindows;
Anton Korobeynikov07a789d2008-03-22 21:12:53 +0000458 } else if (TT.find("windows") != std::string::npos) {
459 TargetType = isWindows;
Chris Lattnercce79c62008-01-02 19:44:55 +0000460 }
Mon P Wangd844dc32009-02-28 00:25:30 +0000461 else if (TT.find("-cl") != std::string::npos) {
462 TargetType = isDarwin;
463 DarwinVers = 9;
464 }
Nate Begemanf26625e2005-07-12 01:41:54 +0000465 } else if (TT.empty()) {
Anton Korobeynikov4efbbc92007-01-03 11:43:14 +0000466#if defined(__CYGWIN__)
Chris Lattner3eb87612005-11-21 22:31:58 +0000467 TargetType = isCygwin;
Anton Korobeynikovcec773d2008-03-22 21:18:22 +0000468#elif defined(__MINGW32__) || defined(__MINGW64__)
Anton Korobeynikov4efbbc92007-01-03 11:43:14 +0000469 TargetType = isMingw;
Nate Begemanf26625e2005-07-12 01:41:54 +0000470#elif defined(__APPLE__)
Chris Lattner3eb87612005-11-21 22:31:58 +0000471 TargetType = isDarwin;
Chris Lattnercce79c62008-01-02 19:44:55 +0000472#if __APPLE_CC__ > 5400
473 DarwinVers = 9; // GCC 5400+ is Leopard.
474#else
475 DarwinVers = 8; // Minimum supported darwin is Tiger.
476#endif
477
Anton Korobeynikovcec773d2008-03-22 21:18:22 +0000478#elif defined(_WIN32) || defined(_WIN64)
Chris Lattner3eb87612005-11-21 22:31:58 +0000479 TargetType = isWindows;
Dan Gohmanbcde1722008-05-05 00:28:39 +0000480#elif defined(__linux__)
481 // Linux doesn't imply ELF, but we don't currently support anything else.
Dan Gohman6fd71c62008-05-05 16:11:31 +0000482 TargetType = isELF;
483 IsLinux = true;
Nate Begemanf26625e2005-07-12 01:41:54 +0000484#endif
485 }
486
Chris Lattnerb9e0a9e2006-09-07 22:29:41 +0000487 // If the asm syntax hasn't been overridden on the command line, use whatever
488 // the target wants.
Anton Korobeynikova0554d92007-01-12 19:20:47 +0000489 if (AsmFlavor == X86Subtarget::Unset) {
Chris Lattnercce79c62008-01-02 19:44:55 +0000490 AsmFlavor = (TargetType == isWindows)
491 ? X86Subtarget::Intel : X86Subtarget::ATT;
Chris Lattnerb9e0a9e2006-09-07 22:29:41 +0000492 }
493
Anton Korobeynikova7495262008-04-23 18:16:16 +0000494 // Stack alignment is 16 bytes on Darwin (both 32 and 64 bit) and for all 64
495 // bit targets.
496 if (TargetType == isDarwin || Is64Bit)
Nate Begemanf26625e2005-07-12 01:41:54 +0000497 stackAlignment = 16;
Anton Korobeynikovb9f38f32008-04-12 22:12:22 +0000498
499 if (StackAlignment)
500 stackAlignment = StackAlignment;
Nate Begemanf26625e2005-07-12 01:41:54 +0000501}