blob: db9a09f76dadd7efdf8c5c61ba333ee7d64d0666 [file] [log] [blame]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001//===-- X86Subtarget.cpp - X86 Subtarget Information ------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner081ce942007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the X86 specific subclass of TargetSubtarget.
11//
12//===----------------------------------------------------------------------===//
13
Evan Cheng5211b422009-01-03 04:04:46 +000014#define DEBUG_TYPE "subtarget"
Dan Gohmanf17a25c2007-07-18 16:29:46 +000015#include "X86Subtarget.h"
Chris Lattner505aa6c2009-07-10 07:20:05 +000016#include "X86InstrInfo.h"
Dan Gohmanf17a25c2007-07-18 16:29:46 +000017#include "X86GenSubtarget.inc"
18#include "llvm/Module.h"
19#include "llvm/Support/CommandLine.h"
Evan Cheng5211b422009-01-03 04:04:46 +000020#include "llvm/Support/Debug.h"
Dan Gohmanf17a25c2007-07-18 16:29:46 +000021#include "llvm/Target/TargetMachine.h"
Anton Korobeynikovb214a522008-04-23 18:18:10 +000022#include "llvm/Target/TargetOptions.h"
Dan Gohmanf17a25c2007-07-18 16:29:46 +000023using namespace llvm;
24
Chris Lattner1d8091f2009-04-25 18:27:23 +000025#if defined(_MSC_VER)
26 #include <intrin.h>
27#endif
28
Dan Gohman089efff2008-05-13 00:00:25 +000029static cl::opt<X86Subtarget::AsmWriterFlavorTy>
Dan Gohmanf17a25c2007-07-18 16:29:46 +000030AsmWriterFlavor("x86-asm-syntax", cl::init(X86Subtarget::Unset),
31 cl::desc("Choose style of code to emit from X86 backend:"),
32 cl::values(
Dan Gohman669b9bf2008-10-14 20:25:08 +000033 clEnumValN(X86Subtarget::ATT, "att", "Emit AT&T-style assembly"),
34 clEnumValN(X86Subtarget::Intel, "intel", "Emit Intel-style assembly"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +000035 clEnumValEnd));
36
Chris Lattner4a948932009-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
Dan Gohmanf17a25c2007-07-18 16:29:46 +000048
Chris Lattner505aa6c2009-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 Lattner144e3482009-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 Lattner505aa6c2009-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 Lattner144e3482009-07-10 20:53:38 +000097 return X86II::MO_PIC_BASE_OFFSET;
Chris Lattner505aa6c2009-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 Lattner144e3482009-07-10 20:53:38 +0000101 if (!GV->hasHiddenVisibility()) // Non-hidden $non_lazy_ptr reference.
102 return X86II::MO_DARWIN_NONLAZY_PIC_BASE;
Chris Lattner505aa6c2009-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 Lattner144e3482009-07-10 20:53:38 +0000108 return X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE;
Chris Lattner505aa6c2009-07-10 07:20:05 +0000109 }
110
111 // Otherwise, no stub.
Chris Lattner144e3482009-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 Lattner505aa6c2009-07-10 07:20:05 +0000137 }
138
139 // Direct static reference to global.
140 return X86II::MO_NO_FLAG;
141}
142
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000143
Bill Wendling5db7ffb2008-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 Wendlingd3752032008-09-30 22:05:33 +0000148const char *X86Subtarget::getBZeroEntry() const {
Dan Gohmanf95c2bf2008-04-01 20:38:36 +0000149 // Darwin 10 has a __bzero entry point for this purpose.
150 if (getDarwinVers() >= 10)
Bill Wendlingd3752032008-09-30 22:05:33 +0000151 return "__bzero";
Dan Gohmanf95c2bf2008-04-01 20:38:36 +0000152
153 return 0;
154}
155
Evan Cheng6d35a4d2009-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 Gohman47170992008-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
Dan Gohmanf17a25c2007-07-18 16:29:46 +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.
177bool X86::GetCpuIDAndInfo(unsigned value, unsigned *rEAX, unsigned *rEBX,
178 unsigned *rECX, unsigned *rEDX) {
Chris Lattner1d8091f2009-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
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000200#elif defined(i386) || defined(__i386__) || defined(__x86__) || defined(_M_IX86)
Chris Lattner1d8091f2009-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
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000226#endif
227 return true;
228}
229
Evan Cheng95a77fd2009-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
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000242void X86Subtarget::AutoDetectSubtargetFeatures() {
243 unsigned EAX = 0, EBX = 0, ECX = 0, EDX = 0;
244 union {
245 unsigned u[3];
246 char c[12];
247 } text;
248
249 if (X86::GetCpuIDAndInfo(0, &EAX, text.u+0, text.u+2, text.u+1))
250 return;
251
252 X86::GetCpuIDAndInfo(0x1, &EAX, &EBX, &ECX, &EDX);
253
254 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;
258 if ((ECX >> 9) & 0x1) X86SSELevel = SSSE3;
Nate Begemanb2975562008-02-03 07:18:54 +0000259 if ((ECX >> 19) & 0x1) X86SSELevel = SSE41;
260 if ((ECX >> 20) & 0x1) X86SSELevel = SSE42;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000261
Evan Cheng95a77fd2009-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 Greene8bf22bc2009-06-26 22:46:54 +0000264
265 HasFMA3 = IsIntel && ((ECX >> 12) & 0x1);
266 HasAVX = ((ECX >> 28) & 0x1);
267
Evan Cheng95a77fd2009-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
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000275 X86::GetCpuIDAndInfo(0x80000001, &EAX, &EBX, &ECX, &EDX);
276 HasX86_64 = (EDX >> 29) & 0x1;
Stefanus Du Toitfe086e62009-05-26 21:04:35 +0000277 HasSSE4A = IsAMD && ((ECX >> 6) & 0x1);
David Greene8bf22bc2009-06-26 22:46:54 +0000278 HasFMA4 = IsAMD && ((ECX >> 16) & 0x1);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000279 }
280}
281
282static const char *GetCurrentX86CPU() {
283 unsigned EAX = 0, EBX = 0, ECX = 0, EDX = 0;
284 if (X86::GetCpuIDAndInfo(0x1, &EAX, &EBX, &ECX, &EDX))
285 return "generic";
Evan Cheng95a77fd2009-01-02 05:35:45 +0000286 unsigned Family = 0;
287 unsigned Model = 0;
288 DetectFamilyModel(EAX, Family, Model);
Evan Chengedde6842009-01-02 05:29:20 +0000289
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000290 X86::GetCpuIDAndInfo(0x80000001, &EAX, &EBX, &ECX, &EDX);
291 bool Em64T = (EDX >> 29) & 0x1;
Stefanus Du Toitfe086e62009-05-26 21:04:35 +0000292 bool HasSSE3 = (ECX & 0x1);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000293
294 union {
295 unsigned u[3];
296 char c[12];
297 } text;
298
299 X86::GetCpuIDAndInfo(0, &EAX, text.u+0, text.u+2, text.u+1);
300 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 Cheng5211b422009-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";
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000329 default: return "i686";
330 }
331 case 15: {
332 switch (Model) {
333 case 3:
334 case 4:
Evan Cheng5211b422009-01-03 04:04:46 +0000335 case 6: // same as 4, but 65nm
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000336 return (Em64T) ? "nocona" : "prescott";
Evan Chengcfadd3b2009-01-05 08:45:01 +0000337 case 26:
338 return "corei7";
Evan Cheng5211b422009-01-03 04:04:46 +0000339 case 28:
Evan Chengcfadd3b2009-01-05 08:45:01 +0000340 return "atom";
Dan Gohmanf17a25c2007-07-18 16:29:46 +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 Toitfe086e62009-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:
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000387 switch (Model) {
Stefanus Du Toitfe086e62009-05-26 21:04:35 +0000388 default: return "amdfam10";
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000389 }
390 default:
391 return "generic";
392 }
393 } else {
394 return "generic";
395 }
396}
397
398X86Subtarget::X86Subtarget(const Module &M, const std::string &FS, bool is64Bit)
399 : AsmFlavor(AsmWriterFlavor)
Duncan Sandsde5f95f2008-11-28 09:29:37 +0000400 , PICStyle(PICStyles::None)
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000401 , X86SSELevel(NoMMXSSE)
Evan Chengb6992de2008-04-16 19:03:02 +0000402 , X863DNowLevel(NoThreeDNow)
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000403 , HasX86_64(false)
David Greene8bf22bc2009-06-26 22:46:54 +0000404 , HasSSE4A(false)
405 , HasAVX(false)
406 , HasFMA3(false)
407 , HasFMA4(false)
Evan Cheng95a77fd2009-01-02 05:35:45 +0000408 , IsBTMemSlow(false)
Chris Lattner93a2d432008-01-02 19:44:55 +0000409 , DarwinVers(0)
Dan Gohmande22f242008-05-05 18:43:07 +0000410 , IsLinux(false)
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000411 , stackAlignment(8)
412 // FIXME: this is a known good value for Yonah. How about others?
Rafael Espindola7afa9b12007-10-31 11:52:06 +0000413 , MaxInlineSizeThreshold(128)
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000414 , Is64Bit(is64Bit)
415 , TargetType(isELF) { // Default to ELF unless otherwise specified.
Anton Korobeynikov11713322009-06-08 22:53:56 +0000416
417 // default to hard float ABI
418 if (FloatABIType == FloatABI::Default)
419 FloatABIType = FloatABI::Hard;
Mon P Wang078a62d2008-05-05 19:05:59 +0000420
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000421 // Determine default and user specified characteristics
422 if (!FS.empty()) {
423 // If feature string is not empty, parse features string.
424 std::string CPU = GetCurrentX86CPU();
425 ParseSubtargetFeatures(FS, CPU);
Edwin Török4031b792009-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.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000428 } else {
429 // Otherwise, use CPUID to auto-detect feature set.
430 AutoDetectSubtargetFeatures();
Dan Gohman4092bbc2009-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;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000434 }
Dan Gohman4092bbc2009-02-03 00:04:43 +0000435
Dan Gohmand3ef6c92009-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 Cheng5211b422009-01-03 04:04:46 +0000441 DOUT << "Subtarget features: SSELevel " << X86SSELevel
442 << ", 3DNowLevel " << X863DNowLevel
443 << ", 64bit " << HasX86_64 << "\n";
Dan Gohman4092bbc2009-02-03 00:04:43 +0000444 assert((!Is64Bit || HasX86_64) &&
445 "64-bit code requested on a subtarget that doesn't support it!");
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000446
447 // 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 Sandsdfd94582008-01-08 10:06:15 +0000451 size_t Pos;
Chris Lattner93a2d432008-01-02 19:44:55 +0000452 if ((Pos = TT.find("-darwin")) != std::string::npos) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000453 TargetType = isDarwin;
Chris Lattner93a2d432008-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 Gohmana65530a2008-05-05 00:28:39 +0000460 } else if (TT.find("linux") != std::string::npos) {
Dan Gohman2593e2b2008-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 Lattner93a2d432008-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) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000469 TargetType = isWindows;
Anton Korobeynikovf0ce64b2008-03-22 21:12:53 +0000470 } else if (TT.find("windows") != std::string::npos) {
471 TargetType = isWindows;
Chris Lattner93a2d432008-01-02 19:44:55 +0000472 }
Mon P Wang23bbfc32009-02-28 00:25:30 +0000473 else if (TT.find("-cl") != std::string::npos) {
474 TargetType = isDarwin;
475 DarwinVers = 9;
476 }
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000477 } else if (TT.empty()) {
478#if defined(__CYGWIN__)
479 TargetType = isCygwin;
Anton Korobeynikov62a51e42008-03-22 21:18:22 +0000480#elif defined(__MINGW32__) || defined(__MINGW64__)
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000481 TargetType = isMingw;
482#elif defined(__APPLE__)
483 TargetType = isDarwin;
Chris Lattner93a2d432008-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 Korobeynikov62a51e42008-03-22 21:18:22 +0000490#elif defined(_WIN32) || defined(_WIN64)
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000491 TargetType = isWindows;
Dan Gohmana65530a2008-05-05 00:28:39 +0000492#elif defined(__linux__)
493 // Linux doesn't imply ELF, but we don't currently support anything else.
Dan Gohman2593e2b2008-05-05 16:11:31 +0000494 TargetType = isELF;
495 IsLinux = true;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000496#endif
497 }
498
499 // If the asm syntax hasn't been overridden on the command line, use whatever
500 // the target wants.
501 if (AsmFlavor == X86Subtarget::Unset) {
Chris Lattner93a2d432008-01-02 19:44:55 +0000502 AsmFlavor = (TargetType == isWindows)
503 ? X86Subtarget::Intel : X86Subtarget::ATT;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000504 }
505
Anton Korobeynikovcdd93812008-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)
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000509 stackAlignment = 16;
Anton Korobeynikov06c42402008-04-12 22:12:22 +0000510
511 if (StackAlignment)
512 stackAlignment = StackAlignment;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000513}