blob: f3a8d75c8a07aabdb6793139e7169a3acc5713f1 [file] [log] [blame]
Nate Begeman8c00f8c2005-08-04 07:12:09 +00001//===-- X86Subtarget.cpp - X86 Subtarget Information ------------*- C++ -*-===//
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//
10// This file implements the X86 specific subclass of TargetSubtarget.
11//
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"
Evan Chenga26eb5e2006-10-06 09:17:41 +000017#include "X86GenSubtarget.inc"
Daniel Dunbar3be03402009-08-02 22:11:08 +000018#include "llvm/GlobalValue.h"
Jim Laskey05a059d2006-09-07 12:23:47 +000019#include "llvm/Support/CommandLine.h"
Evan Cheng5b925c02009-01-03 04:04:46 +000020#include "llvm/Support/Debug.h"
Bill Wendling0ea8bf32009-08-03 00:11:34 +000021#include "llvm/Support/raw_ostream.h"
Anton Korobeynikov2b2bc682006-12-22 22:29:05 +000022#include "llvm/Target/TargetMachine.h"
Anton Korobeynikov45709ae2008-04-23 18:18:10 +000023#include "llvm/Target/TargetOptions.h"
Nate Begemanfb5792f2005-07-12 01:41:54 +000024using namespace llvm;
25
Chris Lattnerbc583222009-04-25 18:27:23 +000026#if defined(_MSC_VER)
Bill Wendling0ea8bf32009-08-03 00:11:34 +000027#include <intrin.h>
Chris Lattnerbc583222009-04-25 18:27:23 +000028#endif
29
Dan Gohman844731a2008-05-13 00:00:25 +000030static cl::opt<X86Subtarget::AsmWriterFlavorTy>
Anton Korobeynikov7f705592007-01-12 19:20:47 +000031AsmWriterFlavor("x86-asm-syntax", cl::init(X86Subtarget::Unset),
Jim Laskey05a059d2006-09-07 12:23:47 +000032 cl::desc("Choose style of code to emit from X86 backend:"),
33 cl::values(
Dan Gohmanb8cab922008-10-14 20:25:08 +000034 clEnumValN(X86Subtarget::ATT, "att", "Emit AT&T-style assembly"),
35 clEnumValN(X86Subtarget::Intel, "intel", "Emit Intel-style assembly"),
Chris Lattnercdb341d2006-09-07 22:29:41 +000036 clEnumValEnd));
Jim Laskey05a059d2006-09-07 12:23:47 +000037
Chris Lattnerd392bd92009-07-10 07:20:05 +000038/// ClassifyGlobalReference - Classify a global variable reference for the
39/// current subtarget according to how we should reference it in a non-pcrel
40/// context.
41unsigned char X86Subtarget::
42ClassifyGlobalReference(const GlobalValue *GV, const TargetMachine &TM) const {
43 // DLLImport only exists on windows, it is implemented as a load from a
44 // DLLIMPORT stub.
45 if (GV->hasDLLImportLinkage())
46 return X86II::MO_DLLIMPORT;
47
Evan Chenga82b22c2009-07-16 22:53:10 +000048 // GV with ghost linkage (in JIT lazy compilation mode) do not require an
49 // extra load from stub.
50 bool isDecl = GV->isDeclaration() && !GV->hasNotBeenReadFromBitcode();
51
Chris Lattnerd392bd92009-07-10 07:20:05 +000052 // X86-64 in PIC mode.
53 if (isPICStyleRIPRel()) {
54 // Large model never uses stubs.
55 if (TM.getCodeModel() == CodeModel::Large)
56 return X86II::MO_NO_FLAG;
57
Chris Lattnerc7822322009-07-10 21:01:59 +000058 if (isTargetDarwin()) {
59 // If symbol visibility is hidden, the extra load is not needed if
60 // target is x86-64 or the symbol is definitely defined in the current
61 // translation unit.
62 if (GV->hasDefaultVisibility() &&
Evan Chenga82b22c2009-07-16 22:53:10 +000063 (isDecl || GV->isWeakForLinker()))
Chris Lattnerc7822322009-07-10 21:01:59 +000064 return X86II::MO_GOTPCREL;
65 } else {
66 assert(isTargetELF() && "Unknown rip-relative target");
Chris Lattnerd392bd92009-07-10 07:20:05 +000067
Chris Lattnerc7822322009-07-10 21:01:59 +000068 // Extra load is needed for all externally visible.
69 if (!GV->hasLocalLinkage() && GV->hasDefaultVisibility())
70 return X86II::MO_GOTPCREL;
71 }
Chris Lattnerd392bd92009-07-10 07:20:05 +000072
73 return X86II::MO_NO_FLAG;
74 }
75
76 if (isPICStyleGOT()) { // 32-bit ELF targets.
77 // Extra load is needed for all externally visible.
78 if (GV->hasLocalLinkage() || GV->hasHiddenVisibility())
79 return X86II::MO_GOTOFF;
80 return X86II::MO_GOT;
81 }
82
Chris Lattnere2c92082009-07-10 21:00:45 +000083 if (isPICStyleStubPIC()) { // Darwin/32 in PIC mode.
Chris Lattner84853a12009-07-10 20:53:38 +000084 // Determine whether we have a stub reference and/or whether the reference
85 // is relative to the PIC base or not.
Chris Lattnerd392bd92009-07-10 07:20:05 +000086
87 // If this is a strong reference to a definition, it is definitely not
88 // through a stub.
Evan Chenga82b22c2009-07-16 22:53:10 +000089 if (!isDecl && !GV->isWeakForLinker())
Chris Lattner84853a12009-07-10 20:53:38 +000090 return X86II::MO_PIC_BASE_OFFSET;
Chris Lattnerd392bd92009-07-10 07:20:05 +000091
92 // Unless we have a symbol with hidden visibility, we have to go through a
93 // normal $non_lazy_ptr stub because this symbol might be resolved late.
Chris Lattner84853a12009-07-10 20:53:38 +000094 if (!GV->hasHiddenVisibility()) // Non-hidden $non_lazy_ptr reference.
95 return X86II::MO_DARWIN_NONLAZY_PIC_BASE;
Chris Lattnerd392bd92009-07-10 07:20:05 +000096
97 // If symbol visibility is hidden, we have a stub for common symbol
98 // references and external declarations.
Evan Chenga82b22c2009-07-16 22:53:10 +000099 if (isDecl || GV->hasCommonLinkage()) {
Chris Lattnerd392bd92009-07-10 07:20:05 +0000100 // Hidden $non_lazy_ptr reference.
Chris Lattner84853a12009-07-10 20:53:38 +0000101 return X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE;
Chris Lattnerd392bd92009-07-10 07:20:05 +0000102 }
103
104 // Otherwise, no stub.
Chris Lattner84853a12009-07-10 20:53:38 +0000105 return X86II::MO_PIC_BASE_OFFSET;
106 }
107
Chris Lattnere2c92082009-07-10 21:00:45 +0000108 if (isPICStyleStubNoDynamic()) { // Darwin/32 in -mdynamic-no-pic mode.
Chris Lattner84853a12009-07-10 20:53:38 +0000109 // Determine whether we have a stub reference.
110
111 // If this is a strong reference to a definition, it is definitely not
112 // through a stub.
Evan Chenga82b22c2009-07-16 22:53:10 +0000113 if (!isDecl && !GV->isWeakForLinker())
Chris Lattner84853a12009-07-10 20:53:38 +0000114 return X86II::MO_NO_FLAG;
115
116 // Unless we have a symbol with hidden visibility, we have to go through a
117 // normal $non_lazy_ptr stub because this symbol might be resolved late.
118 if (!GV->hasHiddenVisibility()) // Non-hidden $non_lazy_ptr reference.
119 return X86II::MO_DARWIN_NONLAZY;
120
121 // If symbol visibility is hidden, we have a stub for common symbol
122 // references and external declarations.
Evan Chenga82b22c2009-07-16 22:53:10 +0000123 if (isDecl || GV->hasCommonLinkage()) {
Chris Lattner84853a12009-07-10 20:53:38 +0000124 // Hidden $non_lazy_ptr reference.
125 return X86II::MO_DARWIN_HIDDEN_NONLAZY;
126 }
127
128 // Otherwise, no stub.
129 return X86II::MO_NO_FLAG;
Chris Lattnerd392bd92009-07-10 07:20:05 +0000130 }
131
132 // Direct static reference to global.
133 return X86II::MO_NO_FLAG;
134}
135
Anton Korobeynikov7784ebc2006-11-30 22:42:55 +0000136
Bill Wendling6f287b22008-09-30 21:22:07 +0000137/// getBZeroEntry - This function returns the name of a function which has an
138/// interface like the non-standard bzero function, if such a function exists on
139/// the current subtarget and it is considered prefereable over memset with zero
140/// passed as the second argument. Otherwise it returns null.
Bill Wendling6e087382008-09-30 22:05:33 +0000141const char *X86Subtarget::getBZeroEntry() const {
Dan Gohman68d599d2008-04-01 20:38:36 +0000142 // Darwin 10 has a __bzero entry point for this purpose.
143 if (getDarwinVers() >= 10)
Bill Wendling6e087382008-09-30 22:05:33 +0000144 return "__bzero";
Dan Gohman68d599d2008-04-01 20:38:36 +0000145
146 return 0;
147}
148
Evan Chengd7f666a2009-05-20 04:53:57 +0000149/// IsLegalToCallImmediateAddr - Return true if the subtarget allows calls
150/// to immediate address.
151bool X86Subtarget::IsLegalToCallImmediateAddr(const TargetMachine &TM) const {
152 if (Is64Bit)
153 return false;
154 return isTargetELF() || TM.getRelocationModel() == Reloc::Static;
155}
156
Dan Gohman8749b612008-12-16 03:35:01 +0000157/// getSpecialAddressLatency - For targets where it is beneficial to
158/// backschedule instructions that compute addresses, return a value
159/// indicating the number of scheduling cycles of backscheduling that
160/// should be attempted.
161unsigned X86Subtarget::getSpecialAddressLatency() const {
162 // For x86 out-of-order targets, back-schedule address computations so
163 // that loads and stores aren't blocked.
164 // This value was chosen arbitrarily.
165 return 200;
166}
167
Chris Lattner1e39a152006-01-28 06:05:41 +0000168/// GetCpuIDAndInfo - Execute the specified cpuid and return the 4 values in the
169/// specified arguments. If we can't run cpuid on the host, return true.
Evan Cheng751c0e12006-10-16 21:00:37 +0000170bool X86::GetCpuIDAndInfo(unsigned value, unsigned *rEAX, unsigned *rEBX,
171 unsigned *rECX, unsigned *rEDX) {
Chris Lattnerbc583222009-04-25 18:27:23 +0000172#if defined(__x86_64__) || defined(_M_AMD64)
173 #if defined(__GNUC__)
174 // gcc doesn't know cpuid would clobber ebx/rbx. Preseve it manually.
175 asm ("movq\t%%rbx, %%rsi\n\t"
176 "cpuid\n\t"
177 "xchgq\t%%rbx, %%rsi\n\t"
178 : "=a" (*rEAX),
179 "=S" (*rEBX),
180 "=c" (*rECX),
181 "=d" (*rEDX)
182 : "a" (value));
183 return false;
184 #elif defined(_MSC_VER)
185 int registers[4];
186 __cpuid(registers, value);
187 *rEAX = registers[0];
188 *rEBX = registers[1];
189 *rECX = registers[2];
190 *rEDX = registers[3];
191 return false;
192 #endif
Evan Cheng25ab6902006-09-08 06:48:29 +0000193#elif defined(i386) || defined(__i386__) || defined(__x86__) || defined(_M_IX86)
Chris Lattnerbc583222009-04-25 18:27:23 +0000194 #if defined(__GNUC__)
195 asm ("movl\t%%ebx, %%esi\n\t"
196 "cpuid\n\t"
197 "xchgl\t%%ebx, %%esi\n\t"
198 : "=a" (*rEAX),
199 "=S" (*rEBX),
200 "=c" (*rECX),
201 "=d" (*rEDX)
202 : "a" (value));
203 return false;
204 #elif defined(_MSC_VER)
205 __asm {
206 mov eax,value
207 cpuid
208 mov esi,rEAX
209 mov dword ptr [esi],eax
210 mov esi,rEBX
211 mov dword ptr [esi],ebx
212 mov esi,rECX
213 mov dword ptr [esi],ecx
214 mov esi,rEDX
215 mov dword ptr [esi],edx
216 }
217 return false;
218 #endif
Evan Cheng559806f2006-01-27 08:10:46 +0000219#endif
Chris Lattner1e39a152006-01-28 06:05:41 +0000220 return true;
Evan Cheng559806f2006-01-27 08:10:46 +0000221}
222
Evan Chengccb69762009-01-02 05:35:45 +0000223static void DetectFamilyModel(unsigned EAX, unsigned &Family, unsigned &Model) {
224 Family = (EAX >> 8) & 0xf; // Bits 8 - 11
225 Model = (EAX >> 4) & 0xf; // Bits 4 - 7
226 if (Family == 6 || Family == 0xf) {
227 if (Family == 0xf)
228 // Examine extended family ID if family ID is F.
229 Family += (EAX >> 20) & 0xff; // Bits 20 - 27
230 // Examine extended model ID if family ID is 6 or F.
231 Model += ((EAX >> 16) & 0xf) << 4; // Bits 16 - 19
232 }
233}
234
Evan Chenga26eb5e2006-10-06 09:17:41 +0000235void X86Subtarget::AutoDetectSubtargetFeatures() {
Evan Chengb3a7e212006-01-27 19:30:30 +0000236 unsigned EAX = 0, EBX = 0, ECX = 0, EDX = 0;
Jeff Cohena3496402006-01-28 18:47:32 +0000237 union {
Jeff Cohen216d2812006-01-28 19:48:34 +0000238 unsigned u[3];
239 char c[12];
Jeff Cohena3496402006-01-28 18:47:32 +0000240 } text;
Chris Lattner3b6f4972006-11-20 18:16:05 +0000241
Evan Cheng751c0e12006-10-16 21:00:37 +0000242 if (X86::GetCpuIDAndInfo(0, &EAX, text.u+0, text.u+2, text.u+1))
Evan Chengabc346c2006-10-06 08:21:07 +0000243 return;
Anton Korobeynikov3b5ee732007-03-23 23:46:48 +0000244
245 X86::GetCpuIDAndInfo(0x1, &EAX, &EBX, &ECX, &EDX);
Chris Lattner3b6f4972006-11-20 18:16:05 +0000246
Anton Korobeynikov3b5ee732007-03-23 23:46:48 +0000247 if ((EDX >> 23) & 0x1) X86SSELevel = MMX;
248 if ((EDX >> 25) & 0x1) X86SSELevel = SSE1;
249 if ((EDX >> 26) & 0x1) X86SSELevel = SSE2;
250 if (ECX & 0x1) X86SSELevel = SSE3;
Bill Wendlingbb1ee052007-04-10 22:10:25 +0000251 if ((ECX >> 9) & 0x1) X86SSELevel = SSSE3;
Nate Begeman63ec90a2008-02-03 07:18:54 +0000252 if ((ECX >> 19) & 0x1) X86SSELevel = SSE41;
253 if ((ECX >> 20) & 0x1) X86SSELevel = SSE42;
Anton Korobeynikov3b5ee732007-03-23 23:46:48 +0000254
Evan Chengccb69762009-01-02 05:35:45 +0000255 bool IsIntel = memcmp(text.c, "GenuineIntel", 12) == 0;
256 bool IsAMD = !IsIntel && memcmp(text.c, "AuthenticAMD", 12) == 0;
David Greene343dadb2009-06-26 22:46:54 +0000257
258 HasFMA3 = IsIntel && ((ECX >> 12) & 0x1);
259 HasAVX = ((ECX >> 28) & 0x1);
260
Evan Chengccb69762009-01-02 05:35:45 +0000261 if (IsIntel || IsAMD) {
262 // Determine if bit test memory instructions are slow.
263 unsigned Family = 0;
264 unsigned Model = 0;
265 DetectFamilyModel(EAX, Family, Model);
266 IsBTMemSlow = IsAMD || (Family == 6 && Model >= 13);
267
Jeff Cohenc3987092007-04-16 21:59:44 +0000268 X86::GetCpuIDAndInfo(0x80000001, &EAX, &EBX, &ECX, &EDX);
269 HasX86_64 = (EDX >> 29) & 0x1;
Stefanus Du Toit8cf5ab12009-05-26 21:04:35 +0000270 HasSSE4A = IsAMD && ((ECX >> 6) & 0x1);
David Greene343dadb2009-06-26 22:46:54 +0000271 HasFMA4 = IsAMD && ((ECX >> 16) & 0x1);
Jeff Cohenc3987092007-04-16 21:59:44 +0000272 }
Evan Cheng559806f2006-01-27 08:10:46 +0000273}
Evan Cheng97c7fc32006-01-26 09:53:06 +0000274
Evan Chenga26eb5e2006-10-06 09:17:41 +0000275static const char *GetCurrentX86CPU() {
276 unsigned EAX = 0, EBX = 0, ECX = 0, EDX = 0;
Evan Cheng751c0e12006-10-16 21:00:37 +0000277 if (X86::GetCpuIDAndInfo(0x1, &EAX, &EBX, &ECX, &EDX))
Evan Chenga26eb5e2006-10-06 09:17:41 +0000278 return "generic";
Evan Chengccb69762009-01-02 05:35:45 +0000279 unsigned Family = 0;
280 unsigned Model = 0;
281 DetectFamilyModel(EAX, Family, Model);
Evan Cheng018b7ee2009-01-02 05:29:20 +0000282
Evan Cheng751c0e12006-10-16 21:00:37 +0000283 X86::GetCpuIDAndInfo(0x80000001, &EAX, &EBX, &ECX, &EDX);
Evan Cheng3cff9f82006-10-06 18:57:51 +0000284 bool Em64T = (EDX >> 29) & 0x1;
Stefanus Du Toit8cf5ab12009-05-26 21:04:35 +0000285 bool HasSSE3 = (ECX & 0x1);
Evan Chenga26eb5e2006-10-06 09:17:41 +0000286
287 union {
288 unsigned u[3];
289 char c[12];
290 } text;
291
Evan Cheng751c0e12006-10-16 21:00:37 +0000292 X86::GetCpuIDAndInfo(0, &EAX, text.u+0, text.u+2, text.u+1);
Evan Chenga26eb5e2006-10-06 09:17:41 +0000293 if (memcmp(text.c, "GenuineIntel", 12) == 0) {
294 switch (Family) {
295 case 3:
296 return "i386";
297 case 4:
298 return "i486";
299 case 5:
300 switch (Model) {
301 case 4: return "pentium-mmx";
302 default: return "pentium";
303 }
304 case 6:
305 switch (Model) {
306 case 1: return "pentiumpro";
307 case 3:
308 case 5:
309 case 6: return "pentium2";
310 case 7:
311 case 8:
312 case 10:
313 case 11: return "pentium3";
314 case 9:
315 case 13: return "pentium-m";
316 case 14: return "yonah";
Evan Cheng5b925c02009-01-03 04:04:46 +0000317 case 15:
318 case 22: // Celeron M 540
319 return "core2";
320 case 23: // 45nm: Penryn , Wolfdale, Yorkfield (XE)
321 return "penryn";
Evan Chenga26eb5e2006-10-06 09:17:41 +0000322 default: return "i686";
323 }
324 case 15: {
325 switch (Model) {
326 case 3:
327 case 4:
Evan Cheng5b925c02009-01-03 04:04:46 +0000328 case 6: // same as 4, but 65nm
Evan Chenga26eb5e2006-10-06 09:17:41 +0000329 return (Em64T) ? "nocona" : "prescott";
Evan Cheng78771122009-01-05 08:45:01 +0000330 case 26:
331 return "corei7";
Evan Cheng5b925c02009-01-03 04:04:46 +0000332 case 28:
Evan Cheng78771122009-01-05 08:45:01 +0000333 return "atom";
Evan Chenga26eb5e2006-10-06 09:17:41 +0000334 default:
335 return (Em64T) ? "x86-64" : "pentium4";
336 }
337 }
338
339 default:
340 return "generic";
341 }
342 } else if (memcmp(text.c, "AuthenticAMD", 12) == 0) {
343 // FIXME: this poorly matches the generated SubtargetFeatureKV table. There
344 // appears to be no way to generate the wide variety of AMD-specific targets
345 // from the information returned from CPUID.
346 switch (Family) {
347 case 4:
348 return "i486";
349 case 5:
350 switch (Model) {
351 case 6:
352 case 7: return "k6";
353 case 8: return "k6-2";
354 case 9:
355 case 13: return "k6-3";
356 default: return "pentium";
357 }
358 case 6:
359 switch (Model) {
360 case 4: return "athlon-tbird";
361 case 6:
362 case 7:
363 case 8: return "athlon-mp";
364 case 10: return "athlon-xp";
365 default: return "athlon";
366 }
367 case 15:
Stefanus Du Toit8cf5ab12009-05-26 21:04:35 +0000368 if (HasSSE3) {
Daniel Dunbarcfb8a1b2009-07-19 01:38:38 +0000369 return "k8-sse3";
Stefanus Du Toit8cf5ab12009-05-26 21:04:35 +0000370 } else {
371 switch (Model) {
372 case 1: return "opteron";
373 case 5: return "athlon-fx"; // also opteron
374 default: return "athlon64";
375 }
376 }
377 case 16:
Daniel Dunbarcfb8a1b2009-07-19 01:38:38 +0000378 return "amdfam10";
Evan Chenga26eb5e2006-10-06 09:17:41 +0000379 default:
380 return "generic";
381 }
382 } else {
383 return "generic";
384 }
385}
386
Daniel Dunbar3be03402009-08-02 22:11:08 +0000387X86Subtarget::X86Subtarget(const std::string &TT, const std::string &FS,
388 bool is64Bit)
Evan Cheng8e0055d2006-10-04 18:33:00 +0000389 : AsmFlavor(AsmWriterFlavor)
Duncan Sandsf9a67a82008-11-28 09:29:37 +0000390 , PICStyle(PICStyles::None)
Evan Cheng25ab6902006-09-08 06:48:29 +0000391 , X86SSELevel(NoMMXSSE)
Evan Chengdc008582008-04-16 19:03:02 +0000392 , X863DNowLevel(NoThreeDNow)
Evan Cheng25ab6902006-09-08 06:48:29 +0000393 , HasX86_64(false)
David Greene343dadb2009-06-26 22:46:54 +0000394 , HasSSE4A(false)
395 , HasAVX(false)
396 , HasFMA3(false)
397 , HasFMA4(false)
Evan Chengccb69762009-01-02 05:35:45 +0000398 , IsBTMemSlow(false)
Chris Lattner7ad92d82008-01-02 19:44:55 +0000399 , DarwinVers(0)
Dan Gohman94bbdc82008-05-05 18:43:07 +0000400 , IsLinux(false)
Evan Cheng25ab6902006-09-08 06:48:29 +0000401 , stackAlignment(8)
402 // FIXME: this is a known good value for Yonah. How about others?
Rafael Espindolafc05f402007-10-31 11:52:06 +0000403 , MaxInlineSizeThreshold(128)
Evan Cheng25ab6902006-09-08 06:48:29 +0000404 , Is64Bit(is64Bit)
405 , TargetType(isELF) { // Default to ELF unless otherwise specified.
Anton Korobeynikov0eebf652009-06-08 22:53:56 +0000406
407 // default to hard float ABI
408 if (FloatABIType == FloatABI::Default)
409 FloatABIType = FloatABI::Hard;
Mon P Wang63307c32008-05-05 19:05:59 +0000410
Evan Cheng97c7fc32006-01-26 09:53:06 +0000411 // Determine default and user specified characteristics
Evan Chenga26eb5e2006-10-06 09:17:41 +0000412 if (!FS.empty()) {
413 // If feature string is not empty, parse features string.
414 std::string CPU = GetCurrentX86CPU();
415 ParseSubtargetFeatures(FS, CPU);
Torok Edwinb68a88b2009-02-02 21:57:34 +0000416 // All X86-64 CPUs also have SSE2, however user might request no SSE via
417 // -mattr, so don't force SSELevel here.
Chris Lattner3b6f4972006-11-20 18:16:05 +0000418 } else {
419 // Otherwise, use CPUID to auto-detect feature set.
420 AutoDetectSubtargetFeatures();
Dan Gohmanf75e5b42009-02-03 00:04:43 +0000421 // Make sure SSE2 is enabled; it is available on all X86-64 CPUs.
422 if (Is64Bit && X86SSELevel < SSE2)
423 X86SSELevel = SSE2;
Evan Cheng25ab6902006-09-08 06:48:29 +0000424 }
Dan Gohmanf75e5b42009-02-03 00:04:43 +0000425
Dan Gohman605679f2009-02-03 18:53:21 +0000426 // If requesting codegen for X86-64, make sure that 64-bit features
427 // are enabled.
428 if (Is64Bit)
429 HasX86_64 = true;
430
Bill Wendling0ea8bf32009-08-03 00:11:34 +0000431 DEBUG(errs() << "Subtarget features: SSELevel " << X86SSELevel
432 << ", 3DNowLevel " << X863DNowLevel
433 << ", 64bit " << HasX86_64 << "\n");
Dan Gohmanf75e5b42009-02-03 00:04:43 +0000434 assert((!Is64Bit || HasX86_64) &&
435 "64-bit code requested on a subtarget that doesn't support it!");
Evan Cheng25ab6902006-09-08 06:48:29 +0000436
Nate Begemanfb5792f2005-07-12 01:41:54 +0000437 // Set the boolean corresponding to the current target triple, or the default
438 // if one cannot be determined, to true.
Nate Begemanfb5792f2005-07-12 01:41:54 +0000439 if (TT.length() > 5) {
Duncan Sandse51775d2008-01-08 10:06:15 +0000440 size_t Pos;
Chris Lattner7ad92d82008-01-02 19:44:55 +0000441 if ((Pos = TT.find("-darwin")) != std::string::npos) {
Chris Lattnere5600e52005-11-21 22:31:58 +0000442 TargetType = isDarwin;
Chris Lattner7ad92d82008-01-02 19:44:55 +0000443
444 // Compute the darwin version number.
445 if (isdigit(TT[Pos+7]))
446 DarwinVers = atoi(&TT[Pos+7]);
447 else
448 DarwinVers = 8; // Minimum supported darwin is Tiger.
Dan Gohmana779a982008-05-05 00:28:39 +0000449 } else if (TT.find("linux") != std::string::npos) {
Dan Gohman600bf162008-05-05 16:11:31 +0000450 // Linux doesn't imply ELF, but we don't currently support anything else.
451 TargetType = isELF;
452 IsLinux = true;
Chris Lattner7ad92d82008-01-02 19:44:55 +0000453 } else if (TT.find("cygwin") != std::string::npos) {
454 TargetType = isCygwin;
455 } else if (TT.find("mingw") != std::string::npos) {
456 TargetType = isMingw;
457 } else if (TT.find("win32") != std::string::npos) {
Chris Lattnere5600e52005-11-21 22:31:58 +0000458 TargetType = isWindows;
Anton Korobeynikov508f0fd2008-03-22 21:12:53 +0000459 } else if (TT.find("windows") != std::string::npos) {
460 TargetType = isWindows;
Chris Lattner7ad92d82008-01-02 19:44:55 +0000461 }
Mon P Wang9feb5dd2009-02-28 00:25:30 +0000462 else if (TT.find("-cl") != std::string::npos) {
463 TargetType = isDarwin;
464 DarwinVers = 9;
465 }
Nate Begemanfb5792f2005-07-12 01:41:54 +0000466 } else if (TT.empty()) {
Anton Korobeynikov317848f2007-01-03 11:43:14 +0000467#if defined(__CYGWIN__)
Chris Lattnere5600e52005-11-21 22:31:58 +0000468 TargetType = isCygwin;
Anton Korobeynikov2b4f7802008-03-22 21:18:22 +0000469#elif defined(__MINGW32__) || defined(__MINGW64__)
Anton Korobeynikov317848f2007-01-03 11:43:14 +0000470 TargetType = isMingw;
Nate Begemanfb5792f2005-07-12 01:41:54 +0000471#elif defined(__APPLE__)
Chris Lattnere5600e52005-11-21 22:31:58 +0000472 TargetType = isDarwin;
Chris Lattner7ad92d82008-01-02 19:44:55 +0000473#if __APPLE_CC__ > 5400
474 DarwinVers = 9; // GCC 5400+ is Leopard.
475#else
476 DarwinVers = 8; // Minimum supported darwin is Tiger.
477#endif
478
Anton Korobeynikov2b4f7802008-03-22 21:18:22 +0000479#elif defined(_WIN32) || defined(_WIN64)
Chris Lattnere5600e52005-11-21 22:31:58 +0000480 TargetType = isWindows;
Dan Gohmana779a982008-05-05 00:28:39 +0000481#elif defined(__linux__)
482 // Linux doesn't imply ELF, but we don't currently support anything else.
Dan Gohman600bf162008-05-05 16:11:31 +0000483 TargetType = isELF;
484 IsLinux = true;
Nate Begemanfb5792f2005-07-12 01:41:54 +0000485#endif
486 }
487
Chris Lattnercdb341d2006-09-07 22:29:41 +0000488 // If the asm syntax hasn't been overridden on the command line, use whatever
489 // the target wants.
Anton Korobeynikov7f705592007-01-12 19:20:47 +0000490 if (AsmFlavor == X86Subtarget::Unset) {
Chris Lattner7ad92d82008-01-02 19:44:55 +0000491 AsmFlavor = (TargetType == isWindows)
492 ? X86Subtarget::Intel : X86Subtarget::ATT;
Chris Lattnercdb341d2006-09-07 22:29:41 +0000493 }
494
Anton Korobeynikov890fe882008-04-23 18:16:16 +0000495 // Stack alignment is 16 bytes on Darwin (both 32 and 64 bit) and for all 64
496 // bit targets.
497 if (TargetType == isDarwin || Is64Bit)
Nate Begemanfb5792f2005-07-12 01:41:54 +0000498 stackAlignment = 16;
Anton Korobeynikov78c80fd2008-04-12 22:12:22 +0000499
500 if (StackAlignment)
501 stackAlignment = StackAlignment;
Nate Begemanfb5792f2005-07-12 01:41:54 +0000502}