blob: db9a09f76dadd7efdf8c5c61ba333ee7d64d0666 [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"
Nate Begemanf26625e2005-07-12 01:41:54 +000018#include "llvm/Module.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 Lattnere2f524f2009-07-10 20:47:30 +000037bool X86Subtarget::isPICStyleStubPIC(const TargetMachine &TM) const {
38 return PICStyle == PICStyles::Stub &&
39 TM.getRelocationModel() == Reloc::PIC_;
40}
41
42bool X86Subtarget::isPICStyleStubNoDynamic(const TargetMachine &TM) const {
43 return PICStyle == PICStyles::Stub &&
44 TM.getRelocationModel() == Reloc::DynamicNoPIC;
45}
46
47
Evan Chenga8b4aea2006-10-16 21:00:37 +000048
Chris Lattnerdc842c02009-07-10 07:20:05 +000049/// ClassifyGlobalReference - Classify a global variable reference for the
50/// current subtarget according to how we should reference it in a non-pcrel
51/// context.
52unsigned char X86Subtarget::
53ClassifyGlobalReference(const GlobalValue *GV, const TargetMachine &TM) const {
54 // DLLImport only exists on windows, it is implemented as a load from a
55 // DLLIMPORT stub.
56 if (GV->hasDLLImportLinkage())
57 return X86II::MO_DLLIMPORT;
58
59 // X86-64 in PIC mode.
60 if (isPICStyleRIPRel()) {
61 // Large model never uses stubs.
62 if (TM.getCodeModel() == CodeModel::Large)
63 return X86II::MO_NO_FLAG;
64
65 if (isTargetDarwin()) {
66 // If symbol visibility is hidden, the extra load is not needed if
67 // target is x86-64 or the symbol is definitely defined in the current
68 // translation unit.
69 if (GV->hasDefaultVisibility() &&
70 (GV->isDeclaration() || GV->isWeakForLinker()))
71 return X86II::MO_GOTPCREL;
72 } else {
73 assert(isTargetELF() && "Unknown rip-relative target");
74
75 // Extra load is needed for all externally visible.
76 if (!GV->hasLocalLinkage() && GV->hasDefaultVisibility())
77 return X86II::MO_GOTPCREL;
78 }
79
80 return X86II::MO_NO_FLAG;
81 }
82
83 if (isPICStyleGOT()) { // 32-bit ELF targets.
84 // Extra load is needed for all externally visible.
85 if (GV->hasLocalLinkage() || GV->hasHiddenVisibility())
86 return X86II::MO_GOTOFF;
87 return X86II::MO_GOT;
88 }
89
Chris Lattnerbd3e5602009-07-10 20:53:38 +000090 if (isPICStyleStubPIC(TM)) { // Darwin/32 in PIC mode.
91 // Determine whether we have a stub reference and/or whether the reference
92 // is relative to the PIC base or not.
Chris Lattnerdc842c02009-07-10 07:20:05 +000093
94 // If this is a strong reference to a definition, it is definitely not
95 // through a stub.
96 if (!GV->isDeclaration() && !GV->isWeakForLinker())
Chris Lattnerbd3e5602009-07-10 20:53:38 +000097 return X86II::MO_PIC_BASE_OFFSET;
Chris Lattnerdc842c02009-07-10 07:20:05 +000098
99 // Unless we have a symbol with hidden visibility, we have to go through a
100 // normal $non_lazy_ptr stub because this symbol might be resolved late.
Chris Lattnerbd3e5602009-07-10 20:53:38 +0000101 if (!GV->hasHiddenVisibility()) // Non-hidden $non_lazy_ptr reference.
102 return X86II::MO_DARWIN_NONLAZY_PIC_BASE;
Chris Lattnerdc842c02009-07-10 07:20:05 +0000103
104 // If symbol visibility is hidden, we have a stub for common symbol
105 // references and external declarations.
106 if (GV->isDeclaration() || GV->hasCommonLinkage()) {
107 // Hidden $non_lazy_ptr reference.
Chris Lattnerbd3e5602009-07-10 20:53:38 +0000108 return X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE;
Chris Lattnerdc842c02009-07-10 07:20:05 +0000109 }
110
111 // Otherwise, no stub.
Chris Lattnerbd3e5602009-07-10 20:53:38 +0000112 return X86II::MO_PIC_BASE_OFFSET;
113 }
114
115 if (isPICStyleStubNoDynamic(TM)) { // Darwin/32 in -mdynamic-no-pic mode.
116 // Determine whether we have a stub reference.
117
118 // If this is a strong reference to a definition, it is definitely not
119 // through a stub.
120 if (!GV->isDeclaration() && !GV->isWeakForLinker())
121 return X86II::MO_NO_FLAG;
122
123 // Unless we have a symbol with hidden visibility, we have to go through a
124 // normal $non_lazy_ptr stub because this symbol might be resolved late.
125 if (!GV->hasHiddenVisibility()) // Non-hidden $non_lazy_ptr reference.
126 return X86II::MO_DARWIN_NONLAZY;
127
128 // If symbol visibility is hidden, we have a stub for common symbol
129 // references and external declarations.
130 if (GV->isDeclaration() || GV->hasCommonLinkage()) {
131 // Hidden $non_lazy_ptr reference.
132 return X86II::MO_DARWIN_HIDDEN_NONLAZY;
133 }
134
135 // Otherwise, no stub.
136 return X86II::MO_NO_FLAG;
Chris Lattnerdc842c02009-07-10 07:20:05 +0000137 }
138
139 // Direct static reference to global.
140 return X86II::MO_NO_FLAG;
141}
142
Anton Korobeynikov6dbdfe22006-11-30 22:42:55 +0000143
Bill Wendlingbd092622008-09-30 21:22:07 +0000144/// getBZeroEntry - This function returns the name of a function which has an
145/// interface like the non-standard bzero function, if such a function exists on
146/// the current subtarget and it is considered prefereable over memset with zero
147/// passed as the second argument. Otherwise it returns null.
Bill Wendling17825842008-09-30 22:05:33 +0000148const char *X86Subtarget::getBZeroEntry() const {
Dan Gohman980d7202008-04-01 20:38:36 +0000149 // Darwin 10 has a __bzero entry point for this purpose.
150 if (getDarwinVers() >= 10)
Bill Wendling17825842008-09-30 22:05:33 +0000151 return "__bzero";
Dan Gohman980d7202008-04-01 20:38:36 +0000152
153 return 0;
154}
155
Evan Cheng96098332009-05-20 04:53:57 +0000156/// IsLegalToCallImmediateAddr - Return true if the subtarget allows calls
157/// to immediate address.
158bool X86Subtarget::IsLegalToCallImmediateAddr(const TargetMachine &TM) const {
159 if (Is64Bit)
160 return false;
161 return isTargetELF() || TM.getRelocationModel() == Reloc::Static;
162}
163
Dan Gohmanb9a01212008-12-16 03:35:01 +0000164/// getSpecialAddressLatency - For targets where it is beneficial to
165/// backschedule instructions that compute addresses, return a value
166/// indicating the number of scheduling cycles of backscheduling that
167/// should be attempted.
168unsigned X86Subtarget::getSpecialAddressLatency() const {
169 // For x86 out-of-order targets, back-schedule address computations so
170 // that loads and stores aren't blocked.
171 // This value was chosen arbitrarily.
172 return 200;
173}
174
Chris Lattnerdc8bbb62006-01-28 06:05:41 +0000175/// GetCpuIDAndInfo - Execute the specified cpuid and return the 4 values in the
176/// specified arguments. If we can't run cpuid on the host, return true.
Evan Chenga8b4aea2006-10-16 21:00:37 +0000177bool X86::GetCpuIDAndInfo(unsigned value, unsigned *rEAX, unsigned *rEBX,
178 unsigned *rECX, unsigned *rEDX) {
Chris Lattner3ad60b12009-04-25 18:27:23 +0000179#if defined(__x86_64__) || defined(_M_AMD64)
180 #if defined(__GNUC__)
181 // gcc doesn't know cpuid would clobber ebx/rbx. Preseve it manually.
182 asm ("movq\t%%rbx, %%rsi\n\t"
183 "cpuid\n\t"
184 "xchgq\t%%rbx, %%rsi\n\t"
185 : "=a" (*rEAX),
186 "=S" (*rEBX),
187 "=c" (*rECX),
188 "=d" (*rEDX)
189 : "a" (value));
190 return false;
191 #elif defined(_MSC_VER)
192 int registers[4];
193 __cpuid(registers, value);
194 *rEAX = registers[0];
195 *rEBX = registers[1];
196 *rECX = registers[2];
197 *rEDX = registers[3];
198 return false;
199 #endif
Evan Cheng11b0a5d2006-09-08 06:48:29 +0000200#elif defined(i386) || defined(__i386__) || defined(__x86__) || defined(_M_IX86)
Chris Lattner3ad60b12009-04-25 18:27:23 +0000201 #if defined(__GNUC__)
202 asm ("movl\t%%ebx, %%esi\n\t"
203 "cpuid\n\t"
204 "xchgl\t%%ebx, %%esi\n\t"
205 : "=a" (*rEAX),
206 "=S" (*rEBX),
207 "=c" (*rECX),
208 "=d" (*rEDX)
209 : "a" (value));
210 return false;
211 #elif defined(_MSC_VER)
212 __asm {
213 mov eax,value
214 cpuid
215 mov esi,rEAX
216 mov dword ptr [esi],eax
217 mov esi,rEBX
218 mov dword ptr [esi],ebx
219 mov esi,rECX
220 mov dword ptr [esi],ecx
221 mov esi,rEDX
222 mov dword ptr [esi],edx
223 }
224 return false;
225 #endif
Evan Chengcde9e302006-01-27 08:10:46 +0000226#endif
Chris Lattnerdc8bbb62006-01-28 06:05:41 +0000227 return true;
Evan Chengcde9e302006-01-27 08:10:46 +0000228}
229
Evan Cheng4c91aa32009-01-02 05:35:45 +0000230static void DetectFamilyModel(unsigned EAX, unsigned &Family, unsigned &Model) {
231 Family = (EAX >> 8) & 0xf; // Bits 8 - 11
232 Model = (EAX >> 4) & 0xf; // Bits 4 - 7
233 if (Family == 6 || Family == 0xf) {
234 if (Family == 0xf)
235 // Examine extended family ID if family ID is F.
236 Family += (EAX >> 20) & 0xff; // Bits 20 - 27
237 // Examine extended model ID if family ID is 6 or F.
238 Model += ((EAX >> 16) & 0xf) << 4; // Bits 16 - 19
239 }
240}
241
Evan Chengff1beda2006-10-06 09:17:41 +0000242void X86Subtarget::AutoDetectSubtargetFeatures() {
Evan Chengafab7aa2006-01-27 19:30:30 +0000243 unsigned EAX = 0, EBX = 0, ECX = 0, EDX = 0;
Jeff Cohen71287082006-01-28 18:47:32 +0000244 union {
Jeff Cohen58ca0be92006-01-28 19:48:34 +0000245 unsigned u[3];
246 char c[12];
Jeff Cohen71287082006-01-28 18:47:32 +0000247 } text;
Chris Lattner3e962112006-11-20 18:16:05 +0000248
Evan Chenga8b4aea2006-10-16 21:00:37 +0000249 if (X86::GetCpuIDAndInfo(0, &EAX, text.u+0, text.u+2, text.u+1))
Evan Cheng9274f722006-10-06 08:21:07 +0000250 return;
Anton Korobeynikov8aae2d72007-03-23 23:46:48 +0000251
252 X86::GetCpuIDAndInfo(0x1, &EAX, &EBX, &ECX, &EDX);
Chris Lattner3e962112006-11-20 18:16:05 +0000253
Anton Korobeynikov8aae2d72007-03-23 23:46:48 +0000254 if ((EDX >> 23) & 0x1) X86SSELevel = MMX;
255 if ((EDX >> 25) & 0x1) X86SSELevel = SSE1;
256 if ((EDX >> 26) & 0x1) X86SSELevel = SSE2;
257 if (ECX & 0x1) X86SSELevel = SSE3;
Bill Wendlingf0998412007-04-10 22:10:25 +0000258 if ((ECX >> 9) & 0x1) X86SSELevel = SSSE3;
Nate Begemane14fdfa2008-02-03 07:18:54 +0000259 if ((ECX >> 19) & 0x1) X86SSELevel = SSE41;
260 if ((ECX >> 20) & 0x1) X86SSELevel = SSE42;
Anton Korobeynikov8aae2d72007-03-23 23:46:48 +0000261
Evan Cheng4c91aa32009-01-02 05:35:45 +0000262 bool IsIntel = memcmp(text.c, "GenuineIntel", 12) == 0;
263 bool IsAMD = !IsIntel && memcmp(text.c, "AuthenticAMD", 12) == 0;
David Greene8f6f72c2009-06-26 22:46:54 +0000264
265 HasFMA3 = IsIntel && ((ECX >> 12) & 0x1);
266 HasAVX = ((ECX >> 28) & 0x1);
267
Evan Cheng4c91aa32009-01-02 05:35:45 +0000268 if (IsIntel || IsAMD) {
269 // Determine if bit test memory instructions are slow.
270 unsigned Family = 0;
271 unsigned Model = 0;
272 DetectFamilyModel(EAX, Family, Model);
273 IsBTMemSlow = IsAMD || (Family == 6 && Model >= 13);
274
Jeff Cohen6f3a5482007-04-16 21:59:44 +0000275 X86::GetCpuIDAndInfo(0x80000001, &EAX, &EBX, &ECX, &EDX);
276 HasX86_64 = (EDX >> 29) & 0x1;
Stefanus Du Toit96180b52009-05-26 21:04:35 +0000277 HasSSE4A = IsAMD && ((ECX >> 6) & 0x1);
David Greene8f6f72c2009-06-26 22:46:54 +0000278 HasFMA4 = IsAMD && ((ECX >> 16) & 0x1);
Jeff Cohen6f3a5482007-04-16 21:59:44 +0000279 }
Evan Chengcde9e302006-01-27 08:10:46 +0000280}
Evan Cheng54c13da2006-01-26 09:53:06 +0000281
Evan Chengff1beda2006-10-06 09:17:41 +0000282static const char *GetCurrentX86CPU() {
283 unsigned EAX = 0, EBX = 0, ECX = 0, EDX = 0;
Evan Chenga8b4aea2006-10-16 21:00:37 +0000284 if (X86::GetCpuIDAndInfo(0x1, &EAX, &EBX, &ECX, &EDX))
Evan Chengff1beda2006-10-06 09:17:41 +0000285 return "generic";
Evan Cheng4c91aa32009-01-02 05:35:45 +0000286 unsigned Family = 0;
287 unsigned Model = 0;
288 DetectFamilyModel(EAX, Family, Model);
Evan Cheng13f3a332009-01-02 05:29:20 +0000289
Evan Chenga8b4aea2006-10-16 21:00:37 +0000290 X86::GetCpuIDAndInfo(0x80000001, &EAX, &EBX, &ECX, &EDX);
Evan Cheng5fe96802006-10-06 18:57:51 +0000291 bool Em64T = (EDX >> 29) & 0x1;
Stefanus Du Toit96180b52009-05-26 21:04:35 +0000292 bool HasSSE3 = (ECX & 0x1);
Evan Chengff1beda2006-10-06 09:17:41 +0000293
294 union {
295 unsigned u[3];
296 char c[12];
297 } text;
298
Evan Chenga8b4aea2006-10-16 21:00:37 +0000299 X86::GetCpuIDAndInfo(0, &EAX, text.u+0, text.u+2, text.u+1);
Evan Chengff1beda2006-10-06 09:17:41 +0000300 if (memcmp(text.c, "GenuineIntel", 12) == 0) {
301 switch (Family) {
302 case 3:
303 return "i386";
304 case 4:
305 return "i486";
306 case 5:
307 switch (Model) {
308 case 4: return "pentium-mmx";
309 default: return "pentium";
310 }
311 case 6:
312 switch (Model) {
313 case 1: return "pentiumpro";
314 case 3:
315 case 5:
316 case 6: return "pentium2";
317 case 7:
318 case 8:
319 case 10:
320 case 11: return "pentium3";
321 case 9:
322 case 13: return "pentium-m";
323 case 14: return "yonah";
Evan Cheng9a3ec1b2009-01-03 04:04:46 +0000324 case 15:
325 case 22: // Celeron M 540
326 return "core2";
327 case 23: // 45nm: Penryn , Wolfdale, Yorkfield (XE)
328 return "penryn";
Evan Chengff1beda2006-10-06 09:17:41 +0000329 default: return "i686";
330 }
331 case 15: {
332 switch (Model) {
333 case 3:
334 case 4:
Evan Cheng9a3ec1b2009-01-03 04:04:46 +0000335 case 6: // same as 4, but 65nm
Evan Chengff1beda2006-10-06 09:17:41 +0000336 return (Em64T) ? "nocona" : "prescott";
Evan Chengc3b09c32009-01-05 08:45:01 +0000337 case 26:
338 return "corei7";
Evan Cheng9a3ec1b2009-01-03 04:04:46 +0000339 case 28:
Evan Chengc3b09c32009-01-05 08:45:01 +0000340 return "atom";
Evan Chengff1beda2006-10-06 09:17:41 +0000341 default:
342 return (Em64T) ? "x86-64" : "pentium4";
343 }
344 }
345
346 default:
347 return "generic";
348 }
349 } else if (memcmp(text.c, "AuthenticAMD", 12) == 0) {
350 // FIXME: this poorly matches the generated SubtargetFeatureKV table. There
351 // appears to be no way to generate the wide variety of AMD-specific targets
352 // from the information returned from CPUID.
353 switch (Family) {
354 case 4:
355 return "i486";
356 case 5:
357 switch (Model) {
358 case 6:
359 case 7: return "k6";
360 case 8: return "k6-2";
361 case 9:
362 case 13: return "k6-3";
363 default: return "pentium";
364 }
365 case 6:
366 switch (Model) {
367 case 4: return "athlon-tbird";
368 case 6:
369 case 7:
370 case 8: return "athlon-mp";
371 case 10: return "athlon-xp";
372 default: return "athlon";
373 }
374 case 15:
Stefanus Du Toit96180b52009-05-26 21:04:35 +0000375 if (HasSSE3) {
376 switch (Model) {
377 default: return "k8-sse3";
378 }
379 } else {
380 switch (Model) {
381 case 1: return "opteron";
382 case 5: return "athlon-fx"; // also opteron
383 default: return "athlon64";
384 }
385 }
386 case 16:
Evan Chengff1beda2006-10-06 09:17:41 +0000387 switch (Model) {
Stefanus Du Toit96180b52009-05-26 21:04:35 +0000388 default: return "amdfam10";
Evan Chengff1beda2006-10-06 09:17:41 +0000389 }
Evan Chengff1beda2006-10-06 09:17:41 +0000390 default:
391 return "generic";
392 }
393 } else {
394 return "generic";
395 }
396}
397
Evan Cheng11b0a5d2006-09-08 06:48:29 +0000398X86Subtarget::X86Subtarget(const Module &M, const std::string &FS, bool is64Bit)
Evan Cheng412aaab2006-10-04 18:33:00 +0000399 : AsmFlavor(AsmWriterFlavor)
Duncan Sands595a4422008-11-28 09:29:37 +0000400 , PICStyle(PICStyles::None)
Evan Cheng11b0a5d2006-09-08 06:48:29 +0000401 , X86SSELevel(NoMMXSSE)
Evan Chenga15cee12008-04-16 19:03:02 +0000402 , X863DNowLevel(NoThreeDNow)
Evan Cheng11b0a5d2006-09-08 06:48:29 +0000403 , HasX86_64(false)
David Greene8f6f72c2009-06-26 22:46:54 +0000404 , HasSSE4A(false)
405 , HasAVX(false)
406 , HasFMA3(false)
407 , HasFMA4(false)
Evan Cheng4c91aa32009-01-02 05:35:45 +0000408 , IsBTMemSlow(false)
Chris Lattnercce79c62008-01-02 19:44:55 +0000409 , DarwinVers(0)
Dan Gohmanb42c28c2008-05-05 18:43:07 +0000410 , IsLinux(false)
Evan Cheng11b0a5d2006-09-08 06:48:29 +0000411 , stackAlignment(8)
412 // FIXME: this is a known good value for Yonah. How about others?
Rafael Espindola063f1772007-10-31 11:52:06 +0000413 , MaxInlineSizeThreshold(128)
Evan Cheng11b0a5d2006-09-08 06:48:29 +0000414 , Is64Bit(is64Bit)
415 , TargetType(isELF) { // Default to ELF unless otherwise specified.
Anton Korobeynikov77d19432009-06-08 22:53:56 +0000416
417 // default to hard float ABI
418 if (FloatABIType == FloatABI::Default)
419 FloatABIType = FloatABI::Hard;
Mon P Wang3e583932008-05-05 19:05:59 +0000420
Evan Cheng54c13da2006-01-26 09:53:06 +0000421 // Determine default and user specified characteristics
Evan Chengff1beda2006-10-06 09:17:41 +0000422 if (!FS.empty()) {
423 // If feature string is not empty, parse features string.
424 std::string CPU = GetCurrentX86CPU();
425 ParseSubtargetFeatures(FS, CPU);
Torok Edwine8386602009-02-02 21:57:34 +0000426 // All X86-64 CPUs also have SSE2, however user might request no SSE via
427 // -mattr, so don't force SSELevel here.
Chris Lattner3e962112006-11-20 18:16:05 +0000428 } else {
429 // Otherwise, use CPUID to auto-detect feature set.
430 AutoDetectSubtargetFeatures();
Dan Gohman74037512009-02-03 00:04:43 +0000431 // Make sure SSE2 is enabled; it is available on all X86-64 CPUs.
432 if (Is64Bit && X86SSELevel < SSE2)
433 X86SSELevel = SSE2;
Evan Cheng11b0a5d2006-09-08 06:48:29 +0000434 }
Dan Gohman74037512009-02-03 00:04:43 +0000435
Dan Gohman561d1222009-02-03 18:53:21 +0000436 // If requesting codegen for X86-64, make sure that 64-bit features
437 // are enabled.
438 if (Is64Bit)
439 HasX86_64 = true;
440
Evan Cheng9a3ec1b2009-01-03 04:04:46 +0000441 DOUT << "Subtarget features: SSELevel " << X86SSELevel
442 << ", 3DNowLevel " << X863DNowLevel
443 << ", 64bit " << HasX86_64 << "\n";
Dan Gohman74037512009-02-03 00:04:43 +0000444 assert((!Is64Bit || HasX86_64) &&
445 "64-bit code requested on a subtarget that doesn't support it!");
Evan Cheng11b0a5d2006-09-08 06:48:29 +0000446
Nate Begemanf26625e2005-07-12 01:41:54 +0000447 // Set the boolean corresponding to the current target triple, or the default
448 // if one cannot be determined, to true.
449 const std::string& TT = M.getTargetTriple();
450 if (TT.length() > 5) {
Duncan Sandsbb956ca2008-01-08 10:06:15 +0000451 size_t Pos;
Chris Lattnercce79c62008-01-02 19:44:55 +0000452 if ((Pos = TT.find("-darwin")) != std::string::npos) {
Chris Lattner3eb87612005-11-21 22:31:58 +0000453 TargetType = isDarwin;
Chris Lattnercce79c62008-01-02 19:44:55 +0000454
455 // Compute the darwin version number.
456 if (isdigit(TT[Pos+7]))
457 DarwinVers = atoi(&TT[Pos+7]);
458 else
459 DarwinVers = 8; // Minimum supported darwin is Tiger.
Dan Gohmanbcde1722008-05-05 00:28:39 +0000460 } else if (TT.find("linux") != std::string::npos) {
Dan Gohman6fd71c62008-05-05 16:11:31 +0000461 // Linux doesn't imply ELF, but we don't currently support anything else.
462 TargetType = isELF;
463 IsLinux = true;
Chris Lattnercce79c62008-01-02 19:44:55 +0000464 } else if (TT.find("cygwin") != std::string::npos) {
465 TargetType = isCygwin;
466 } else if (TT.find("mingw") != std::string::npos) {
467 TargetType = isMingw;
468 } else if (TT.find("win32") != std::string::npos) {
Chris Lattner3eb87612005-11-21 22:31:58 +0000469 TargetType = isWindows;
Anton Korobeynikov07a789d2008-03-22 21:12:53 +0000470 } else if (TT.find("windows") != std::string::npos) {
471 TargetType = isWindows;
Chris Lattnercce79c62008-01-02 19:44:55 +0000472 }
Mon P Wangd844dc32009-02-28 00:25:30 +0000473 else if (TT.find("-cl") != std::string::npos) {
474 TargetType = isDarwin;
475 DarwinVers = 9;
476 }
Nate Begemanf26625e2005-07-12 01:41:54 +0000477 } else if (TT.empty()) {
Anton Korobeynikov4efbbc92007-01-03 11:43:14 +0000478#if defined(__CYGWIN__)
Chris Lattner3eb87612005-11-21 22:31:58 +0000479 TargetType = isCygwin;
Anton Korobeynikovcec773d2008-03-22 21:18:22 +0000480#elif defined(__MINGW32__) || defined(__MINGW64__)
Anton Korobeynikov4efbbc92007-01-03 11:43:14 +0000481 TargetType = isMingw;
Nate Begemanf26625e2005-07-12 01:41:54 +0000482#elif defined(__APPLE__)
Chris Lattner3eb87612005-11-21 22:31:58 +0000483 TargetType = isDarwin;
Chris Lattnercce79c62008-01-02 19:44:55 +0000484#if __APPLE_CC__ > 5400
485 DarwinVers = 9; // GCC 5400+ is Leopard.
486#else
487 DarwinVers = 8; // Minimum supported darwin is Tiger.
488#endif
489
Anton Korobeynikovcec773d2008-03-22 21:18:22 +0000490#elif defined(_WIN32) || defined(_WIN64)
Chris Lattner3eb87612005-11-21 22:31:58 +0000491 TargetType = isWindows;
Dan Gohmanbcde1722008-05-05 00:28:39 +0000492#elif defined(__linux__)
493 // Linux doesn't imply ELF, but we don't currently support anything else.
Dan Gohman6fd71c62008-05-05 16:11:31 +0000494 TargetType = isELF;
495 IsLinux = true;
Nate Begemanf26625e2005-07-12 01:41:54 +0000496#endif
497 }
498
Chris Lattnerb9e0a9e2006-09-07 22:29:41 +0000499 // If the asm syntax hasn't been overridden on the command line, use whatever
500 // the target wants.
Anton Korobeynikova0554d92007-01-12 19:20:47 +0000501 if (AsmFlavor == X86Subtarget::Unset) {
Chris Lattnercce79c62008-01-02 19:44:55 +0000502 AsmFlavor = (TargetType == isWindows)
503 ? X86Subtarget::Intel : X86Subtarget::ATT;
Chris Lattnerb9e0a9e2006-09-07 22:29:41 +0000504 }
505
Anton Korobeynikova7495262008-04-23 18:16:16 +0000506 // Stack alignment is 16 bytes on Darwin (both 32 and 64 bit) and for all 64
507 // bit targets.
508 if (TargetType == isDarwin || Is64Bit)
Nate Begemanf26625e2005-07-12 01:41:54 +0000509 stackAlignment = 16;
Anton Korobeynikovb9f38f32008-04-12 22:12:22 +0000510
511 if (StackAlignment)
512 stackAlignment = StackAlignment;
Nate Begemanf26625e2005-07-12 01:41:54 +0000513}