blob: d9c915a696b2b7a42b083d3985d0858ad2e85147 [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
37
Chris Lattner505aa6c2009-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
48 // X86-64 in PIC mode.
49 if (isPICStyleRIPRel()) {
50 // Large model never uses stubs.
51 if (TM.getCodeModel() == CodeModel::Large)
52 return X86II::MO_NO_FLAG;
53
54 if (isTargetDarwin()) {
55 // If symbol visibility is hidden, the extra load is not needed if
56 // target is x86-64 or the symbol is definitely defined in the current
57 // translation unit.
58 if (GV->hasDefaultVisibility() &&
59 (GV->isDeclaration() || GV->isWeakForLinker()))
60 return X86II::MO_GOTPCREL;
61 } else {
62 assert(isTargetELF() && "Unknown rip-relative target");
63
64 // Extra load is needed for all externally visible.
65 if (!GV->hasLocalLinkage() && GV->hasDefaultVisibility())
66 return X86II::MO_GOTPCREL;
67 }
68
69 return X86II::MO_NO_FLAG;
70 }
71
72 if (isPICStyleGOT()) { // 32-bit ELF targets.
73 // Extra load is needed for all externally visible.
74 if (GV->hasLocalLinkage() || GV->hasHiddenVisibility())
75 return X86II::MO_GOTOFF;
76 return X86II::MO_GOT;
77 }
78
79 if (isPICStyleStub()) {
80 // In Darwin/32, we have multiple different stub types, and we have both PIC
81 // and -mdynamic-no-pic. Determine whether we have a stub reference
82 // and/or whether the reference is relative to the PIC base or not.
83 bool IsPIC = TM.getRelocationModel() == Reloc::PIC_;
84
85 // If this is a strong reference to a definition, it is definitely not
86 // through a stub.
87 if (!GV->isDeclaration() && !GV->isWeakForLinker())
88 return IsPIC ? X86II::MO_PIC_BASE_OFFSET : 0;
89
90 // Unless we have a symbol with hidden visibility, we have to go through a
91 // normal $non_lazy_ptr stub because this symbol might be resolved late.
92 if (!GV->hasHiddenVisibility()) {
93 // Non-hidden $non_lazy_ptr reference.
94 return IsPIC ? X86II::MO_DARWIN_NONLAZY_PIC_BASE :
95 X86II::MO_DARWIN_NONLAZY;
96 }
97
98 // If symbol visibility is hidden, we have a stub for common symbol
99 // references and external declarations.
100 if (GV->isDeclaration() || GV->hasCommonLinkage()) {
101 // Hidden $non_lazy_ptr reference.
102 return IsPIC ? X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE :
103 X86II::MO_DARWIN_HIDDEN_NONLAZY;
104 }
105
106 // Otherwise, no stub.
107 return IsPIC ? X86II::MO_PIC_BASE_OFFSET : 0;
108 }
109
110 // Direct static reference to global.
111 return X86II::MO_NO_FLAG;
112}
113
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000114/// True if accessing the GV requires an extra load. For Windows, dllimported
115/// symbols are indirect, loading the value at address GV rather then the
116/// value of GV itself. This means that the GlobalAddress must be in the base
117/// or index register of the address, not the GV offset field.
Chris Lattner08323962009-07-10 05:45:15 +0000118bool X86Subtarget::GVRequiresExtraLoad(const GlobalValue *GV,
Chris Lattner6bdfa1c2009-07-10 05:52:02 +0000119 const TargetMachine &TM) const {
Chris Lattner505aa6c2009-07-10 07:20:05 +0000120 return isGlobalStubReference(ClassifyGlobalReference(GV, TM));
Dale Johannesen64660e92008-12-05 21:47:27 +0000121}
122
123/// True if accessing the GV requires a register. This is a superset of the
124/// cases where GVRequiresExtraLoad is true. Some variations of PIC require
125/// a register, but not an extra load.
126bool X86Subtarget::GVRequiresRegister(const GlobalValue *GV,
Chris Lattnera35337f2009-07-10 05:37:11 +0000127 const TargetMachine &TM) const {
Chris Lattner6bdfa1c2009-07-10 05:52:02 +0000128 if (GVRequiresExtraLoad(GV, TM))
Dale Johannesen64660e92008-12-05 21:47:27 +0000129 return true;
Chris Lattnera35337f2009-07-10 05:37:11 +0000130
Dale Johannesen64660e92008-12-05 21:47:27 +0000131 // Code below here need only consider cases where GVRequiresExtraLoad
132 // returns false.
133 if (TM.getRelocationModel() == Reloc::PIC_)
Chris Lattnera35337f2009-07-10 05:37:11 +0000134 return GV->hasLocalLinkage() || GV->hasExternalLinkage();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000135 return false;
136}
137
Bill Wendling5db7ffb2008-09-30 21:22:07 +0000138/// getBZeroEntry - This function returns the name of a function which has an
139/// interface like the non-standard bzero function, if such a function exists on
140/// the current subtarget and it is considered prefereable over memset with zero
141/// passed as the second argument. Otherwise it returns null.
Bill Wendlingd3752032008-09-30 22:05:33 +0000142const char *X86Subtarget::getBZeroEntry() const {
Dan Gohmanf95c2bf2008-04-01 20:38:36 +0000143 // Darwin 10 has a __bzero entry point for this purpose.
144 if (getDarwinVers() >= 10)
Bill Wendlingd3752032008-09-30 22:05:33 +0000145 return "__bzero";
Dan Gohmanf95c2bf2008-04-01 20:38:36 +0000146
147 return 0;
148}
149
Evan Cheng6d35a4d2009-05-20 04:53:57 +0000150/// IsLegalToCallImmediateAddr - Return true if the subtarget allows calls
151/// to immediate address.
152bool X86Subtarget::IsLegalToCallImmediateAddr(const TargetMachine &TM) const {
153 if (Is64Bit)
154 return false;
155 return isTargetELF() || TM.getRelocationModel() == Reloc::Static;
156}
157
Dan Gohman47170992008-12-16 03:35:01 +0000158/// getSpecialAddressLatency - For targets where it is beneficial to
159/// backschedule instructions that compute addresses, return a value
160/// indicating the number of scheduling cycles of backscheduling that
161/// should be attempted.
162unsigned X86Subtarget::getSpecialAddressLatency() const {
163 // For x86 out-of-order targets, back-schedule address computations so
164 // that loads and stores aren't blocked.
165 // This value was chosen arbitrarily.
166 return 200;
167}
168
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000169/// GetCpuIDAndInfo - Execute the specified cpuid and return the 4 values in the
170/// specified arguments. If we can't run cpuid on the host, return true.
171bool X86::GetCpuIDAndInfo(unsigned value, unsigned *rEAX, unsigned *rEBX,
172 unsigned *rECX, unsigned *rEDX) {
Chris Lattner1d8091f2009-04-25 18:27:23 +0000173#if defined(__x86_64__) || defined(_M_AMD64)
174 #if defined(__GNUC__)
175 // gcc doesn't know cpuid would clobber ebx/rbx. Preseve it manually.
176 asm ("movq\t%%rbx, %%rsi\n\t"
177 "cpuid\n\t"
178 "xchgq\t%%rbx, %%rsi\n\t"
179 : "=a" (*rEAX),
180 "=S" (*rEBX),
181 "=c" (*rECX),
182 "=d" (*rEDX)
183 : "a" (value));
184 return false;
185 #elif defined(_MSC_VER)
186 int registers[4];
187 __cpuid(registers, value);
188 *rEAX = registers[0];
189 *rEBX = registers[1];
190 *rECX = registers[2];
191 *rEDX = registers[3];
192 return false;
193 #endif
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000194#elif defined(i386) || defined(__i386__) || defined(__x86__) || defined(_M_IX86)
Chris Lattner1d8091f2009-04-25 18:27:23 +0000195 #if defined(__GNUC__)
196 asm ("movl\t%%ebx, %%esi\n\t"
197 "cpuid\n\t"
198 "xchgl\t%%ebx, %%esi\n\t"
199 : "=a" (*rEAX),
200 "=S" (*rEBX),
201 "=c" (*rECX),
202 "=d" (*rEDX)
203 : "a" (value));
204 return false;
205 #elif defined(_MSC_VER)
206 __asm {
207 mov eax,value
208 cpuid
209 mov esi,rEAX
210 mov dword ptr [esi],eax
211 mov esi,rEBX
212 mov dword ptr [esi],ebx
213 mov esi,rECX
214 mov dword ptr [esi],ecx
215 mov esi,rEDX
216 mov dword ptr [esi],edx
217 }
218 return false;
219 #endif
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000220#endif
221 return true;
222}
223
Evan Cheng95a77fd2009-01-02 05:35:45 +0000224static void DetectFamilyModel(unsigned EAX, unsigned &Family, unsigned &Model) {
225 Family = (EAX >> 8) & 0xf; // Bits 8 - 11
226 Model = (EAX >> 4) & 0xf; // Bits 4 - 7
227 if (Family == 6 || Family == 0xf) {
228 if (Family == 0xf)
229 // Examine extended family ID if family ID is F.
230 Family += (EAX >> 20) & 0xff; // Bits 20 - 27
231 // Examine extended model ID if family ID is 6 or F.
232 Model += ((EAX >> 16) & 0xf) << 4; // Bits 16 - 19
233 }
234}
235
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000236void X86Subtarget::AutoDetectSubtargetFeatures() {
237 unsigned EAX = 0, EBX = 0, ECX = 0, EDX = 0;
238 union {
239 unsigned u[3];
240 char c[12];
241 } text;
242
243 if (X86::GetCpuIDAndInfo(0, &EAX, text.u+0, text.u+2, text.u+1))
244 return;
245
246 X86::GetCpuIDAndInfo(0x1, &EAX, &EBX, &ECX, &EDX);
247
248 if ((EDX >> 23) & 0x1) X86SSELevel = MMX;
249 if ((EDX >> 25) & 0x1) X86SSELevel = SSE1;
250 if ((EDX >> 26) & 0x1) X86SSELevel = SSE2;
251 if (ECX & 0x1) X86SSELevel = SSE3;
252 if ((ECX >> 9) & 0x1) X86SSELevel = SSSE3;
Nate Begemanb2975562008-02-03 07:18:54 +0000253 if ((ECX >> 19) & 0x1) X86SSELevel = SSE41;
254 if ((ECX >> 20) & 0x1) X86SSELevel = SSE42;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000255
Evan Cheng95a77fd2009-01-02 05:35:45 +0000256 bool IsIntel = memcmp(text.c, "GenuineIntel", 12) == 0;
257 bool IsAMD = !IsIntel && memcmp(text.c, "AuthenticAMD", 12) == 0;
David Greene8bf22bc2009-06-26 22:46:54 +0000258
259 HasFMA3 = IsIntel && ((ECX >> 12) & 0x1);
260 HasAVX = ((ECX >> 28) & 0x1);
261
Evan Cheng95a77fd2009-01-02 05:35:45 +0000262 if (IsIntel || IsAMD) {
263 // Determine if bit test memory instructions are slow.
264 unsigned Family = 0;
265 unsigned Model = 0;
266 DetectFamilyModel(EAX, Family, Model);
267 IsBTMemSlow = IsAMD || (Family == 6 && Model >= 13);
268
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000269 X86::GetCpuIDAndInfo(0x80000001, &EAX, &EBX, &ECX, &EDX);
270 HasX86_64 = (EDX >> 29) & 0x1;
Stefanus Du Toitfe086e62009-05-26 21:04:35 +0000271 HasSSE4A = IsAMD && ((ECX >> 6) & 0x1);
David Greene8bf22bc2009-06-26 22:46:54 +0000272 HasFMA4 = IsAMD && ((ECX >> 16) & 0x1);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000273 }
274}
275
276static const char *GetCurrentX86CPU() {
277 unsigned EAX = 0, EBX = 0, ECX = 0, EDX = 0;
278 if (X86::GetCpuIDAndInfo(0x1, &EAX, &EBX, &ECX, &EDX))
279 return "generic";
Evan Cheng95a77fd2009-01-02 05:35:45 +0000280 unsigned Family = 0;
281 unsigned Model = 0;
282 DetectFamilyModel(EAX, Family, Model);
Evan Chengedde6842009-01-02 05:29:20 +0000283
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000284 X86::GetCpuIDAndInfo(0x80000001, &EAX, &EBX, &ECX, &EDX);
285 bool Em64T = (EDX >> 29) & 0x1;
Stefanus Du Toitfe086e62009-05-26 21:04:35 +0000286 bool HasSSE3 = (ECX & 0x1);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000287
288 union {
289 unsigned u[3];
290 char c[12];
291 } text;
292
293 X86::GetCpuIDAndInfo(0, &EAX, text.u+0, text.u+2, text.u+1);
294 if (memcmp(text.c, "GenuineIntel", 12) == 0) {
295 switch (Family) {
296 case 3:
297 return "i386";
298 case 4:
299 return "i486";
300 case 5:
301 switch (Model) {
302 case 4: return "pentium-mmx";
303 default: return "pentium";
304 }
305 case 6:
306 switch (Model) {
307 case 1: return "pentiumpro";
308 case 3:
309 case 5:
310 case 6: return "pentium2";
311 case 7:
312 case 8:
313 case 10:
314 case 11: return "pentium3";
315 case 9:
316 case 13: return "pentium-m";
317 case 14: return "yonah";
Evan Cheng5211b422009-01-03 04:04:46 +0000318 case 15:
319 case 22: // Celeron M 540
320 return "core2";
321 case 23: // 45nm: Penryn , Wolfdale, Yorkfield (XE)
322 return "penryn";
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000323 default: return "i686";
324 }
325 case 15: {
326 switch (Model) {
327 case 3:
328 case 4:
Evan Cheng5211b422009-01-03 04:04:46 +0000329 case 6: // same as 4, but 65nm
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000330 return (Em64T) ? "nocona" : "prescott";
Evan Chengcfadd3b2009-01-05 08:45:01 +0000331 case 26:
332 return "corei7";
Evan Cheng5211b422009-01-03 04:04:46 +0000333 case 28:
Evan Chengcfadd3b2009-01-05 08:45:01 +0000334 return "atom";
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000335 default:
336 return (Em64T) ? "x86-64" : "pentium4";
337 }
338 }
339
340 default:
341 return "generic";
342 }
343 } else if (memcmp(text.c, "AuthenticAMD", 12) == 0) {
344 // FIXME: this poorly matches the generated SubtargetFeatureKV table. There
345 // appears to be no way to generate the wide variety of AMD-specific targets
346 // from the information returned from CPUID.
347 switch (Family) {
348 case 4:
349 return "i486";
350 case 5:
351 switch (Model) {
352 case 6:
353 case 7: return "k6";
354 case 8: return "k6-2";
355 case 9:
356 case 13: return "k6-3";
357 default: return "pentium";
358 }
359 case 6:
360 switch (Model) {
361 case 4: return "athlon-tbird";
362 case 6:
363 case 7:
364 case 8: return "athlon-mp";
365 case 10: return "athlon-xp";
366 default: return "athlon";
367 }
368 case 15:
Stefanus Du Toitfe086e62009-05-26 21:04:35 +0000369 if (HasSSE3) {
370 switch (Model) {
371 default: return "k8-sse3";
372 }
373 } else {
374 switch (Model) {
375 case 1: return "opteron";
376 case 5: return "athlon-fx"; // also opteron
377 default: return "athlon64";
378 }
379 }
380 case 16:
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000381 switch (Model) {
Stefanus Du Toitfe086e62009-05-26 21:04:35 +0000382 default: return "amdfam10";
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000383 }
384 default:
385 return "generic";
386 }
387 } else {
388 return "generic";
389 }
390}
391
392X86Subtarget::X86Subtarget(const Module &M, const std::string &FS, bool is64Bit)
393 : AsmFlavor(AsmWriterFlavor)
Duncan Sandsde5f95f2008-11-28 09:29:37 +0000394 , PICStyle(PICStyles::None)
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000395 , X86SSELevel(NoMMXSSE)
Evan Chengb6992de2008-04-16 19:03:02 +0000396 , X863DNowLevel(NoThreeDNow)
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000397 , HasX86_64(false)
David Greene8bf22bc2009-06-26 22:46:54 +0000398 , HasSSE4A(false)
399 , HasAVX(false)
400 , HasFMA3(false)
401 , HasFMA4(false)
Evan Cheng95a77fd2009-01-02 05:35:45 +0000402 , IsBTMemSlow(false)
Chris Lattner93a2d432008-01-02 19:44:55 +0000403 , DarwinVers(0)
Dan Gohmande22f242008-05-05 18:43:07 +0000404 , IsLinux(false)
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000405 , stackAlignment(8)
406 // FIXME: this is a known good value for Yonah. How about others?
Rafael Espindola7afa9b12007-10-31 11:52:06 +0000407 , MaxInlineSizeThreshold(128)
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000408 , Is64Bit(is64Bit)
409 , TargetType(isELF) { // Default to ELF unless otherwise specified.
Anton Korobeynikov11713322009-06-08 22:53:56 +0000410
411 // default to hard float ABI
412 if (FloatABIType == FloatABI::Default)
413 FloatABIType = FloatABI::Hard;
Mon P Wang078a62d2008-05-05 19:05:59 +0000414
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000415 // Determine default and user specified characteristics
416 if (!FS.empty()) {
417 // If feature string is not empty, parse features string.
418 std::string CPU = GetCurrentX86CPU();
419 ParseSubtargetFeatures(FS, CPU);
Edwin Török4031b792009-02-02 21:57:34 +0000420 // All X86-64 CPUs also have SSE2, however user might request no SSE via
421 // -mattr, so don't force SSELevel here.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000422 } else {
423 // Otherwise, use CPUID to auto-detect feature set.
424 AutoDetectSubtargetFeatures();
Dan Gohman4092bbc2009-02-03 00:04:43 +0000425 // Make sure SSE2 is enabled; it is available on all X86-64 CPUs.
426 if (Is64Bit && X86SSELevel < SSE2)
427 X86SSELevel = SSE2;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000428 }
Dan Gohman4092bbc2009-02-03 00:04:43 +0000429
Dan Gohmand3ef6c92009-02-03 18:53:21 +0000430 // If requesting codegen for X86-64, make sure that 64-bit features
431 // are enabled.
432 if (Is64Bit)
433 HasX86_64 = true;
434
Evan Cheng5211b422009-01-03 04:04:46 +0000435 DOUT << "Subtarget features: SSELevel " << X86SSELevel
436 << ", 3DNowLevel " << X863DNowLevel
437 << ", 64bit " << HasX86_64 << "\n";
Dan Gohman4092bbc2009-02-03 00:04:43 +0000438 assert((!Is64Bit || HasX86_64) &&
439 "64-bit code requested on a subtarget that doesn't support it!");
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000440
441 // Set the boolean corresponding to the current target triple, or the default
442 // if one cannot be determined, to true.
443 const std::string& TT = M.getTargetTriple();
444 if (TT.length() > 5) {
Duncan Sandsdfd94582008-01-08 10:06:15 +0000445 size_t Pos;
Chris Lattner93a2d432008-01-02 19:44:55 +0000446 if ((Pos = TT.find("-darwin")) != std::string::npos) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000447 TargetType = isDarwin;
Chris Lattner93a2d432008-01-02 19:44:55 +0000448
449 // Compute the darwin version number.
450 if (isdigit(TT[Pos+7]))
451 DarwinVers = atoi(&TT[Pos+7]);
452 else
453 DarwinVers = 8; // Minimum supported darwin is Tiger.
Dan Gohmana65530a2008-05-05 00:28:39 +0000454 } else if (TT.find("linux") != std::string::npos) {
Dan Gohman2593e2b2008-05-05 16:11:31 +0000455 // Linux doesn't imply ELF, but we don't currently support anything else.
456 TargetType = isELF;
457 IsLinux = true;
Chris Lattner93a2d432008-01-02 19:44:55 +0000458 } else if (TT.find("cygwin") != std::string::npos) {
459 TargetType = isCygwin;
460 } else if (TT.find("mingw") != std::string::npos) {
461 TargetType = isMingw;
462 } else if (TT.find("win32") != std::string::npos) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000463 TargetType = isWindows;
Anton Korobeynikovf0ce64b2008-03-22 21:12:53 +0000464 } else if (TT.find("windows") != std::string::npos) {
465 TargetType = isWindows;
Chris Lattner93a2d432008-01-02 19:44:55 +0000466 }
Mon P Wang23bbfc32009-02-28 00:25:30 +0000467 else if (TT.find("-cl") != std::string::npos) {
468 TargetType = isDarwin;
469 DarwinVers = 9;
470 }
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000471 } else if (TT.empty()) {
472#if defined(__CYGWIN__)
473 TargetType = isCygwin;
Anton Korobeynikov62a51e42008-03-22 21:18:22 +0000474#elif defined(__MINGW32__) || defined(__MINGW64__)
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000475 TargetType = isMingw;
476#elif defined(__APPLE__)
477 TargetType = isDarwin;
Chris Lattner93a2d432008-01-02 19:44:55 +0000478#if __APPLE_CC__ > 5400
479 DarwinVers = 9; // GCC 5400+ is Leopard.
480#else
481 DarwinVers = 8; // Minimum supported darwin is Tiger.
482#endif
483
Anton Korobeynikov62a51e42008-03-22 21:18:22 +0000484#elif defined(_WIN32) || defined(_WIN64)
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000485 TargetType = isWindows;
Dan Gohmana65530a2008-05-05 00:28:39 +0000486#elif defined(__linux__)
487 // Linux doesn't imply ELF, but we don't currently support anything else.
Dan Gohman2593e2b2008-05-05 16:11:31 +0000488 TargetType = isELF;
489 IsLinux = true;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000490#endif
491 }
492
493 // If the asm syntax hasn't been overridden on the command line, use whatever
494 // the target wants.
495 if (AsmFlavor == X86Subtarget::Unset) {
Chris Lattner93a2d432008-01-02 19:44:55 +0000496 AsmFlavor = (TargetType == isWindows)
497 ? X86Subtarget::Intel : X86Subtarget::ATT;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000498 }
499
Anton Korobeynikovcdd93812008-04-23 18:16:16 +0000500 // Stack alignment is 16 bytes on Darwin (both 32 and 64 bit) and for all 64
501 // bit targets.
502 if (TargetType == isDarwin || Is64Bit)
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000503 stackAlignment = 16;
Anton Korobeynikov06c42402008-04-12 22:12:22 +0000504
505 if (StackAlignment)
506 stackAlignment = StackAlignment;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000507}