blob: 6665c67bafc798251bc3fa4d49174aeb5910e7b5 [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
Evan Chenga8b4aea2006-10-16 21:00:37 +000037
Chris Lattnerdc842c02009-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
Anton Korobeynikov6dbdfe22006-11-30 22:42:55 +0000114
Bill Wendlingbd092622008-09-30 21:22:07 +0000115/// getBZeroEntry - This function returns the name of a function which has an
116/// interface like the non-standard bzero function, if such a function exists on
117/// the current subtarget and it is considered prefereable over memset with zero
118/// passed as the second argument. Otherwise it returns null.
Bill Wendling17825842008-09-30 22:05:33 +0000119const char *X86Subtarget::getBZeroEntry() const {
Dan Gohman980d7202008-04-01 20:38:36 +0000120 // Darwin 10 has a __bzero entry point for this purpose.
121 if (getDarwinVers() >= 10)
Bill Wendling17825842008-09-30 22:05:33 +0000122 return "__bzero";
Dan Gohman980d7202008-04-01 20:38:36 +0000123
124 return 0;
125}
126
Evan Cheng96098332009-05-20 04:53:57 +0000127/// IsLegalToCallImmediateAddr - Return true if the subtarget allows calls
128/// to immediate address.
129bool X86Subtarget::IsLegalToCallImmediateAddr(const TargetMachine &TM) const {
130 if (Is64Bit)
131 return false;
132 return isTargetELF() || TM.getRelocationModel() == Reloc::Static;
133}
134
Dan Gohmanb9a01212008-12-16 03:35:01 +0000135/// getSpecialAddressLatency - For targets where it is beneficial to
136/// backschedule instructions that compute addresses, return a value
137/// indicating the number of scheduling cycles of backscheduling that
138/// should be attempted.
139unsigned X86Subtarget::getSpecialAddressLatency() const {
140 // For x86 out-of-order targets, back-schedule address computations so
141 // that loads and stores aren't blocked.
142 // This value was chosen arbitrarily.
143 return 200;
144}
145
Chris Lattnerdc8bbb62006-01-28 06:05:41 +0000146/// GetCpuIDAndInfo - Execute the specified cpuid and return the 4 values in the
147/// specified arguments. If we can't run cpuid on the host, return true.
Evan Chenga8b4aea2006-10-16 21:00:37 +0000148bool X86::GetCpuIDAndInfo(unsigned value, unsigned *rEAX, unsigned *rEBX,
149 unsigned *rECX, unsigned *rEDX) {
Chris Lattner3ad60b12009-04-25 18:27:23 +0000150#if defined(__x86_64__) || defined(_M_AMD64)
151 #if defined(__GNUC__)
152 // gcc doesn't know cpuid would clobber ebx/rbx. Preseve it manually.
153 asm ("movq\t%%rbx, %%rsi\n\t"
154 "cpuid\n\t"
155 "xchgq\t%%rbx, %%rsi\n\t"
156 : "=a" (*rEAX),
157 "=S" (*rEBX),
158 "=c" (*rECX),
159 "=d" (*rEDX)
160 : "a" (value));
161 return false;
162 #elif defined(_MSC_VER)
163 int registers[4];
164 __cpuid(registers, value);
165 *rEAX = registers[0];
166 *rEBX = registers[1];
167 *rECX = registers[2];
168 *rEDX = registers[3];
169 return false;
170 #endif
Evan Cheng11b0a5d2006-09-08 06:48:29 +0000171#elif defined(i386) || defined(__i386__) || defined(__x86__) || defined(_M_IX86)
Chris Lattner3ad60b12009-04-25 18:27:23 +0000172 #if defined(__GNUC__)
173 asm ("movl\t%%ebx, %%esi\n\t"
174 "cpuid\n\t"
175 "xchgl\t%%ebx, %%esi\n\t"
176 : "=a" (*rEAX),
177 "=S" (*rEBX),
178 "=c" (*rECX),
179 "=d" (*rEDX)
180 : "a" (value));
181 return false;
182 #elif defined(_MSC_VER)
183 __asm {
184 mov eax,value
185 cpuid
186 mov esi,rEAX
187 mov dword ptr [esi],eax
188 mov esi,rEBX
189 mov dword ptr [esi],ebx
190 mov esi,rECX
191 mov dword ptr [esi],ecx
192 mov esi,rEDX
193 mov dword ptr [esi],edx
194 }
195 return false;
196 #endif
Evan Chengcde9e302006-01-27 08:10:46 +0000197#endif
Chris Lattnerdc8bbb62006-01-28 06:05:41 +0000198 return true;
Evan Chengcde9e302006-01-27 08:10:46 +0000199}
200
Evan Cheng4c91aa32009-01-02 05:35:45 +0000201static void DetectFamilyModel(unsigned EAX, unsigned &Family, unsigned &Model) {
202 Family = (EAX >> 8) & 0xf; // Bits 8 - 11
203 Model = (EAX >> 4) & 0xf; // Bits 4 - 7
204 if (Family == 6 || Family == 0xf) {
205 if (Family == 0xf)
206 // Examine extended family ID if family ID is F.
207 Family += (EAX >> 20) & 0xff; // Bits 20 - 27
208 // Examine extended model ID if family ID is 6 or F.
209 Model += ((EAX >> 16) & 0xf) << 4; // Bits 16 - 19
210 }
211}
212
Evan Chengff1beda2006-10-06 09:17:41 +0000213void X86Subtarget::AutoDetectSubtargetFeatures() {
Evan Chengafab7aa2006-01-27 19:30:30 +0000214 unsigned EAX = 0, EBX = 0, ECX = 0, EDX = 0;
Jeff Cohen71287082006-01-28 18:47:32 +0000215 union {
Jeff Cohen58ca0be92006-01-28 19:48:34 +0000216 unsigned u[3];
217 char c[12];
Jeff Cohen71287082006-01-28 18:47:32 +0000218 } text;
Chris Lattner3e962112006-11-20 18:16:05 +0000219
Evan Chenga8b4aea2006-10-16 21:00:37 +0000220 if (X86::GetCpuIDAndInfo(0, &EAX, text.u+0, text.u+2, text.u+1))
Evan Cheng9274f722006-10-06 08:21:07 +0000221 return;
Anton Korobeynikov8aae2d72007-03-23 23:46:48 +0000222
223 X86::GetCpuIDAndInfo(0x1, &EAX, &EBX, &ECX, &EDX);
Chris Lattner3e962112006-11-20 18:16:05 +0000224
Anton Korobeynikov8aae2d72007-03-23 23:46:48 +0000225 if ((EDX >> 23) & 0x1) X86SSELevel = MMX;
226 if ((EDX >> 25) & 0x1) X86SSELevel = SSE1;
227 if ((EDX >> 26) & 0x1) X86SSELevel = SSE2;
228 if (ECX & 0x1) X86SSELevel = SSE3;
Bill Wendlingf0998412007-04-10 22:10:25 +0000229 if ((ECX >> 9) & 0x1) X86SSELevel = SSSE3;
Nate Begemane14fdfa2008-02-03 07:18:54 +0000230 if ((ECX >> 19) & 0x1) X86SSELevel = SSE41;
231 if ((ECX >> 20) & 0x1) X86SSELevel = SSE42;
Anton Korobeynikov8aae2d72007-03-23 23:46:48 +0000232
Evan Cheng4c91aa32009-01-02 05:35:45 +0000233 bool IsIntel = memcmp(text.c, "GenuineIntel", 12) == 0;
234 bool IsAMD = !IsIntel && memcmp(text.c, "AuthenticAMD", 12) == 0;
David Greene8f6f72c2009-06-26 22:46:54 +0000235
236 HasFMA3 = IsIntel && ((ECX >> 12) & 0x1);
237 HasAVX = ((ECX >> 28) & 0x1);
238
Evan Cheng4c91aa32009-01-02 05:35:45 +0000239 if (IsIntel || IsAMD) {
240 // Determine if bit test memory instructions are slow.
241 unsigned Family = 0;
242 unsigned Model = 0;
243 DetectFamilyModel(EAX, Family, Model);
244 IsBTMemSlow = IsAMD || (Family == 6 && Model >= 13);
245
Jeff Cohen6f3a5482007-04-16 21:59:44 +0000246 X86::GetCpuIDAndInfo(0x80000001, &EAX, &EBX, &ECX, &EDX);
247 HasX86_64 = (EDX >> 29) & 0x1;
Stefanus Du Toit96180b52009-05-26 21:04:35 +0000248 HasSSE4A = IsAMD && ((ECX >> 6) & 0x1);
David Greene8f6f72c2009-06-26 22:46:54 +0000249 HasFMA4 = IsAMD && ((ECX >> 16) & 0x1);
Jeff Cohen6f3a5482007-04-16 21:59:44 +0000250 }
Evan Chengcde9e302006-01-27 08:10:46 +0000251}
Evan Cheng54c13da2006-01-26 09:53:06 +0000252
Evan Chengff1beda2006-10-06 09:17:41 +0000253static const char *GetCurrentX86CPU() {
254 unsigned EAX = 0, EBX = 0, ECX = 0, EDX = 0;
Evan Chenga8b4aea2006-10-16 21:00:37 +0000255 if (X86::GetCpuIDAndInfo(0x1, &EAX, &EBX, &ECX, &EDX))
Evan Chengff1beda2006-10-06 09:17:41 +0000256 return "generic";
Evan Cheng4c91aa32009-01-02 05:35:45 +0000257 unsigned Family = 0;
258 unsigned Model = 0;
259 DetectFamilyModel(EAX, Family, Model);
Evan Cheng13f3a332009-01-02 05:29:20 +0000260
Evan Chenga8b4aea2006-10-16 21:00:37 +0000261 X86::GetCpuIDAndInfo(0x80000001, &EAX, &EBX, &ECX, &EDX);
Evan Cheng5fe96802006-10-06 18:57:51 +0000262 bool Em64T = (EDX >> 29) & 0x1;
Stefanus Du Toit96180b52009-05-26 21:04:35 +0000263 bool HasSSE3 = (ECX & 0x1);
Evan Chengff1beda2006-10-06 09:17:41 +0000264
265 union {
266 unsigned u[3];
267 char c[12];
268 } text;
269
Evan Chenga8b4aea2006-10-16 21:00:37 +0000270 X86::GetCpuIDAndInfo(0, &EAX, text.u+0, text.u+2, text.u+1);
Evan Chengff1beda2006-10-06 09:17:41 +0000271 if (memcmp(text.c, "GenuineIntel", 12) == 0) {
272 switch (Family) {
273 case 3:
274 return "i386";
275 case 4:
276 return "i486";
277 case 5:
278 switch (Model) {
279 case 4: return "pentium-mmx";
280 default: return "pentium";
281 }
282 case 6:
283 switch (Model) {
284 case 1: return "pentiumpro";
285 case 3:
286 case 5:
287 case 6: return "pentium2";
288 case 7:
289 case 8:
290 case 10:
291 case 11: return "pentium3";
292 case 9:
293 case 13: return "pentium-m";
294 case 14: return "yonah";
Evan Cheng9a3ec1b2009-01-03 04:04:46 +0000295 case 15:
296 case 22: // Celeron M 540
297 return "core2";
298 case 23: // 45nm: Penryn , Wolfdale, Yorkfield (XE)
299 return "penryn";
Evan Chengff1beda2006-10-06 09:17:41 +0000300 default: return "i686";
301 }
302 case 15: {
303 switch (Model) {
304 case 3:
305 case 4:
Evan Cheng9a3ec1b2009-01-03 04:04:46 +0000306 case 6: // same as 4, but 65nm
Evan Chengff1beda2006-10-06 09:17:41 +0000307 return (Em64T) ? "nocona" : "prescott";
Evan Chengc3b09c32009-01-05 08:45:01 +0000308 case 26:
309 return "corei7";
Evan Cheng9a3ec1b2009-01-03 04:04:46 +0000310 case 28:
Evan Chengc3b09c32009-01-05 08:45:01 +0000311 return "atom";
Evan Chengff1beda2006-10-06 09:17:41 +0000312 default:
313 return (Em64T) ? "x86-64" : "pentium4";
314 }
315 }
316
317 default:
318 return "generic";
319 }
320 } else if (memcmp(text.c, "AuthenticAMD", 12) == 0) {
321 // FIXME: this poorly matches the generated SubtargetFeatureKV table. There
322 // appears to be no way to generate the wide variety of AMD-specific targets
323 // from the information returned from CPUID.
324 switch (Family) {
325 case 4:
326 return "i486";
327 case 5:
328 switch (Model) {
329 case 6:
330 case 7: return "k6";
331 case 8: return "k6-2";
332 case 9:
333 case 13: return "k6-3";
334 default: return "pentium";
335 }
336 case 6:
337 switch (Model) {
338 case 4: return "athlon-tbird";
339 case 6:
340 case 7:
341 case 8: return "athlon-mp";
342 case 10: return "athlon-xp";
343 default: return "athlon";
344 }
345 case 15:
Stefanus Du Toit96180b52009-05-26 21:04:35 +0000346 if (HasSSE3) {
347 switch (Model) {
348 default: return "k8-sse3";
349 }
350 } else {
351 switch (Model) {
352 case 1: return "opteron";
353 case 5: return "athlon-fx"; // also opteron
354 default: return "athlon64";
355 }
356 }
357 case 16:
Evan Chengff1beda2006-10-06 09:17:41 +0000358 switch (Model) {
Stefanus Du Toit96180b52009-05-26 21:04:35 +0000359 default: return "amdfam10";
Evan Chengff1beda2006-10-06 09:17:41 +0000360 }
Evan Chengff1beda2006-10-06 09:17:41 +0000361 default:
362 return "generic";
363 }
364 } else {
365 return "generic";
366 }
367}
368
Evan Cheng11b0a5d2006-09-08 06:48:29 +0000369X86Subtarget::X86Subtarget(const Module &M, const std::string &FS, bool is64Bit)
Evan Cheng412aaab2006-10-04 18:33:00 +0000370 : AsmFlavor(AsmWriterFlavor)
Duncan Sands595a4422008-11-28 09:29:37 +0000371 , PICStyle(PICStyles::None)
Evan Cheng11b0a5d2006-09-08 06:48:29 +0000372 , X86SSELevel(NoMMXSSE)
Evan Chenga15cee12008-04-16 19:03:02 +0000373 , X863DNowLevel(NoThreeDNow)
Evan Cheng11b0a5d2006-09-08 06:48:29 +0000374 , HasX86_64(false)
David Greene8f6f72c2009-06-26 22:46:54 +0000375 , HasSSE4A(false)
376 , HasAVX(false)
377 , HasFMA3(false)
378 , HasFMA4(false)
Evan Cheng4c91aa32009-01-02 05:35:45 +0000379 , IsBTMemSlow(false)
Chris Lattnercce79c62008-01-02 19:44:55 +0000380 , DarwinVers(0)
Dan Gohmanb42c28c2008-05-05 18:43:07 +0000381 , IsLinux(false)
Evan Cheng11b0a5d2006-09-08 06:48:29 +0000382 , stackAlignment(8)
383 // FIXME: this is a known good value for Yonah. How about others?
Rafael Espindola063f1772007-10-31 11:52:06 +0000384 , MaxInlineSizeThreshold(128)
Evan Cheng11b0a5d2006-09-08 06:48:29 +0000385 , Is64Bit(is64Bit)
386 , TargetType(isELF) { // Default to ELF unless otherwise specified.
Anton Korobeynikov77d19432009-06-08 22:53:56 +0000387
388 // default to hard float ABI
389 if (FloatABIType == FloatABI::Default)
390 FloatABIType = FloatABI::Hard;
Mon P Wang3e583932008-05-05 19:05:59 +0000391
Evan Cheng54c13da2006-01-26 09:53:06 +0000392 // Determine default and user specified characteristics
Evan Chengff1beda2006-10-06 09:17:41 +0000393 if (!FS.empty()) {
394 // If feature string is not empty, parse features string.
395 std::string CPU = GetCurrentX86CPU();
396 ParseSubtargetFeatures(FS, CPU);
Torok Edwine8386602009-02-02 21:57:34 +0000397 // All X86-64 CPUs also have SSE2, however user might request no SSE via
398 // -mattr, so don't force SSELevel here.
Chris Lattner3e962112006-11-20 18:16:05 +0000399 } else {
400 // Otherwise, use CPUID to auto-detect feature set.
401 AutoDetectSubtargetFeatures();
Dan Gohman74037512009-02-03 00:04:43 +0000402 // Make sure SSE2 is enabled; it is available on all X86-64 CPUs.
403 if (Is64Bit && X86SSELevel < SSE2)
404 X86SSELevel = SSE2;
Evan Cheng11b0a5d2006-09-08 06:48:29 +0000405 }
Dan Gohman74037512009-02-03 00:04:43 +0000406
Dan Gohman561d1222009-02-03 18:53:21 +0000407 // If requesting codegen for X86-64, make sure that 64-bit features
408 // are enabled.
409 if (Is64Bit)
410 HasX86_64 = true;
411
Evan Cheng9a3ec1b2009-01-03 04:04:46 +0000412 DOUT << "Subtarget features: SSELevel " << X86SSELevel
413 << ", 3DNowLevel " << X863DNowLevel
414 << ", 64bit " << HasX86_64 << "\n";
Dan Gohman74037512009-02-03 00:04:43 +0000415 assert((!Is64Bit || HasX86_64) &&
416 "64-bit code requested on a subtarget that doesn't support it!");
Evan Cheng11b0a5d2006-09-08 06:48:29 +0000417
Nate Begemanf26625e2005-07-12 01:41:54 +0000418 // Set the boolean corresponding to the current target triple, or the default
419 // if one cannot be determined, to true.
420 const std::string& TT = M.getTargetTriple();
421 if (TT.length() > 5) {
Duncan Sandsbb956ca2008-01-08 10:06:15 +0000422 size_t Pos;
Chris Lattnercce79c62008-01-02 19:44:55 +0000423 if ((Pos = TT.find("-darwin")) != std::string::npos) {
Chris Lattner3eb87612005-11-21 22:31:58 +0000424 TargetType = isDarwin;
Chris Lattnercce79c62008-01-02 19:44:55 +0000425
426 // Compute the darwin version number.
427 if (isdigit(TT[Pos+7]))
428 DarwinVers = atoi(&TT[Pos+7]);
429 else
430 DarwinVers = 8; // Minimum supported darwin is Tiger.
Dan Gohmanbcde1722008-05-05 00:28:39 +0000431 } else if (TT.find("linux") != std::string::npos) {
Dan Gohman6fd71c62008-05-05 16:11:31 +0000432 // Linux doesn't imply ELF, but we don't currently support anything else.
433 TargetType = isELF;
434 IsLinux = true;
Chris Lattnercce79c62008-01-02 19:44:55 +0000435 } else if (TT.find("cygwin") != std::string::npos) {
436 TargetType = isCygwin;
437 } else if (TT.find("mingw") != std::string::npos) {
438 TargetType = isMingw;
439 } else if (TT.find("win32") != std::string::npos) {
Chris Lattner3eb87612005-11-21 22:31:58 +0000440 TargetType = isWindows;
Anton Korobeynikov07a789d2008-03-22 21:12:53 +0000441 } else if (TT.find("windows") != std::string::npos) {
442 TargetType = isWindows;
Chris Lattnercce79c62008-01-02 19:44:55 +0000443 }
Mon P Wangd844dc32009-02-28 00:25:30 +0000444 else if (TT.find("-cl") != std::string::npos) {
445 TargetType = isDarwin;
446 DarwinVers = 9;
447 }
Nate Begemanf26625e2005-07-12 01:41:54 +0000448 } else if (TT.empty()) {
Anton Korobeynikov4efbbc92007-01-03 11:43:14 +0000449#if defined(__CYGWIN__)
Chris Lattner3eb87612005-11-21 22:31:58 +0000450 TargetType = isCygwin;
Anton Korobeynikovcec773d2008-03-22 21:18:22 +0000451#elif defined(__MINGW32__) || defined(__MINGW64__)
Anton Korobeynikov4efbbc92007-01-03 11:43:14 +0000452 TargetType = isMingw;
Nate Begemanf26625e2005-07-12 01:41:54 +0000453#elif defined(__APPLE__)
Chris Lattner3eb87612005-11-21 22:31:58 +0000454 TargetType = isDarwin;
Chris Lattnercce79c62008-01-02 19:44:55 +0000455#if __APPLE_CC__ > 5400
456 DarwinVers = 9; // GCC 5400+ is Leopard.
457#else
458 DarwinVers = 8; // Minimum supported darwin is Tiger.
459#endif
460
Anton Korobeynikovcec773d2008-03-22 21:18:22 +0000461#elif defined(_WIN32) || defined(_WIN64)
Chris Lattner3eb87612005-11-21 22:31:58 +0000462 TargetType = isWindows;
Dan Gohmanbcde1722008-05-05 00:28:39 +0000463#elif defined(__linux__)
464 // Linux doesn't imply ELF, but we don't currently support anything else.
Dan Gohman6fd71c62008-05-05 16:11:31 +0000465 TargetType = isELF;
466 IsLinux = true;
Nate Begemanf26625e2005-07-12 01:41:54 +0000467#endif
468 }
469
Chris Lattnerb9e0a9e2006-09-07 22:29:41 +0000470 // If the asm syntax hasn't been overridden on the command line, use whatever
471 // the target wants.
Anton Korobeynikova0554d92007-01-12 19:20:47 +0000472 if (AsmFlavor == X86Subtarget::Unset) {
Chris Lattnercce79c62008-01-02 19:44:55 +0000473 AsmFlavor = (TargetType == isWindows)
474 ? X86Subtarget::Intel : X86Subtarget::ATT;
Chris Lattnerb9e0a9e2006-09-07 22:29:41 +0000475 }
476
Anton Korobeynikova7495262008-04-23 18:16:16 +0000477 // Stack alignment is 16 bytes on Darwin (both 32 and 64 bit) and for all 64
478 // bit targets.
479 if (TargetType == isDarwin || Is64Bit)
Nate Begemanf26625e2005-07-12 01:41:54 +0000480 stackAlignment = 16;
Anton Korobeynikovb9f38f32008-04-12 22:12:22 +0000481
482 if (StackAlignment)
483 stackAlignment = StackAlignment;
Nate Begemanf26625e2005-07-12 01:41:54 +0000484}