blob: 82eee216bdbe425dbf4557a8a617e6240aebd391 [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"
Nate Begemanfb5792f2005-07-12 01:41:54 +000018#include "llvm/Module.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"
Anton Korobeynikov2b2bc682006-12-22 22:29:05 +000021#include "llvm/Target/TargetMachine.h"
Anton Korobeynikov45709ae2008-04-23 18:18:10 +000022#include "llvm/Target/TargetOptions.h"
Nate Begemanfb5792f2005-07-12 01:41:54 +000023using namespace llvm;
24
Chris Lattnerbc583222009-04-25 18:27:23 +000025#if defined(_MSC_VER)
26 #include <intrin.h>
27#endif
28
Dan Gohman844731a2008-05-13 00:00:25 +000029static cl::opt<X86Subtarget::AsmWriterFlavorTy>
Anton Korobeynikov7f705592007-01-12 19:20:47 +000030AsmWriterFlavor("x86-asm-syntax", cl::init(X86Subtarget::Unset),
Jim Laskey05a059d2006-09-07 12:23:47 +000031 cl::desc("Choose style of code to emit from X86 backend:"),
32 cl::values(
Dan Gohmanb8cab922008-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 Lattnercdb341d2006-09-07 22:29:41 +000035 clEnumValEnd));
Jim Laskey05a059d2006-09-07 12:23:47 +000036
Evan Cheng751c0e12006-10-16 21:00:37 +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
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 Korobeynikov7784ebc2006-11-30 22:42:55 +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 Lattnere6c07b52009-07-10 05:45:15 +0000118bool X86Subtarget::GVRequiresExtraLoad(const GlobalValue *GV,
Chris Lattnered0dca62009-07-10 05:52:02 +0000119 const TargetMachine &TM) const {
Chris Lattnerd392bd92009-07-10 07:20:05 +0000120 return isGlobalStubReference(ClassifyGlobalReference(GV, TM));
Dale Johannesen203af582008-12-05 21:47:27 +0000121}
122
Anton Korobeynikov7784ebc2006-11-30 22:42:55 +0000123
Bill Wendling6f287b22008-09-30 21:22:07 +0000124/// getBZeroEntry - This function returns the name of a function which has an
125/// interface like the non-standard bzero function, if such a function exists on
126/// the current subtarget and it is considered prefereable over memset with zero
127/// passed as the second argument. Otherwise it returns null.
Bill Wendling6e087382008-09-30 22:05:33 +0000128const char *X86Subtarget::getBZeroEntry() const {
Dan Gohman68d599d2008-04-01 20:38:36 +0000129 // Darwin 10 has a __bzero entry point for this purpose.
130 if (getDarwinVers() >= 10)
Bill Wendling6e087382008-09-30 22:05:33 +0000131 return "__bzero";
Dan Gohman68d599d2008-04-01 20:38:36 +0000132
133 return 0;
134}
135
Evan Chengd7f666a2009-05-20 04:53:57 +0000136/// IsLegalToCallImmediateAddr - Return true if the subtarget allows calls
137/// to immediate address.
138bool X86Subtarget::IsLegalToCallImmediateAddr(const TargetMachine &TM) const {
139 if (Is64Bit)
140 return false;
141 return isTargetELF() || TM.getRelocationModel() == Reloc::Static;
142}
143
Dan Gohman8749b612008-12-16 03:35:01 +0000144/// getSpecialAddressLatency - For targets where it is beneficial to
145/// backschedule instructions that compute addresses, return a value
146/// indicating the number of scheduling cycles of backscheduling that
147/// should be attempted.
148unsigned X86Subtarget::getSpecialAddressLatency() const {
149 // For x86 out-of-order targets, back-schedule address computations so
150 // that loads and stores aren't blocked.
151 // This value was chosen arbitrarily.
152 return 200;
153}
154
Chris Lattner1e39a152006-01-28 06:05:41 +0000155/// GetCpuIDAndInfo - Execute the specified cpuid and return the 4 values in the
156/// specified arguments. If we can't run cpuid on the host, return true.
Evan Cheng751c0e12006-10-16 21:00:37 +0000157bool X86::GetCpuIDAndInfo(unsigned value, unsigned *rEAX, unsigned *rEBX,
158 unsigned *rECX, unsigned *rEDX) {
Chris Lattnerbc583222009-04-25 18:27:23 +0000159#if defined(__x86_64__) || defined(_M_AMD64)
160 #if defined(__GNUC__)
161 // gcc doesn't know cpuid would clobber ebx/rbx. Preseve it manually.
162 asm ("movq\t%%rbx, %%rsi\n\t"
163 "cpuid\n\t"
164 "xchgq\t%%rbx, %%rsi\n\t"
165 : "=a" (*rEAX),
166 "=S" (*rEBX),
167 "=c" (*rECX),
168 "=d" (*rEDX)
169 : "a" (value));
170 return false;
171 #elif defined(_MSC_VER)
172 int registers[4];
173 __cpuid(registers, value);
174 *rEAX = registers[0];
175 *rEBX = registers[1];
176 *rECX = registers[2];
177 *rEDX = registers[3];
178 return false;
179 #endif
Evan Cheng25ab6902006-09-08 06:48:29 +0000180#elif defined(i386) || defined(__i386__) || defined(__x86__) || defined(_M_IX86)
Chris Lattnerbc583222009-04-25 18:27:23 +0000181 #if defined(__GNUC__)
182 asm ("movl\t%%ebx, %%esi\n\t"
183 "cpuid\n\t"
184 "xchgl\t%%ebx, %%esi\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 __asm {
193 mov eax,value
194 cpuid
195 mov esi,rEAX
196 mov dword ptr [esi],eax
197 mov esi,rEBX
198 mov dword ptr [esi],ebx
199 mov esi,rECX
200 mov dword ptr [esi],ecx
201 mov esi,rEDX
202 mov dword ptr [esi],edx
203 }
204 return false;
205 #endif
Evan Cheng559806f2006-01-27 08:10:46 +0000206#endif
Chris Lattner1e39a152006-01-28 06:05:41 +0000207 return true;
Evan Cheng559806f2006-01-27 08:10:46 +0000208}
209
Evan Chengccb69762009-01-02 05:35:45 +0000210static void DetectFamilyModel(unsigned EAX, unsigned &Family, unsigned &Model) {
211 Family = (EAX >> 8) & 0xf; // Bits 8 - 11
212 Model = (EAX >> 4) & 0xf; // Bits 4 - 7
213 if (Family == 6 || Family == 0xf) {
214 if (Family == 0xf)
215 // Examine extended family ID if family ID is F.
216 Family += (EAX >> 20) & 0xff; // Bits 20 - 27
217 // Examine extended model ID if family ID is 6 or F.
218 Model += ((EAX >> 16) & 0xf) << 4; // Bits 16 - 19
219 }
220}
221
Evan Chenga26eb5e2006-10-06 09:17:41 +0000222void X86Subtarget::AutoDetectSubtargetFeatures() {
Evan Chengb3a7e212006-01-27 19:30:30 +0000223 unsigned EAX = 0, EBX = 0, ECX = 0, EDX = 0;
Jeff Cohena3496402006-01-28 18:47:32 +0000224 union {
Jeff Cohen216d2812006-01-28 19:48:34 +0000225 unsigned u[3];
226 char c[12];
Jeff Cohena3496402006-01-28 18:47:32 +0000227 } text;
Chris Lattner3b6f4972006-11-20 18:16:05 +0000228
Evan Cheng751c0e12006-10-16 21:00:37 +0000229 if (X86::GetCpuIDAndInfo(0, &EAX, text.u+0, text.u+2, text.u+1))
Evan Chengabc346c2006-10-06 08:21:07 +0000230 return;
Anton Korobeynikov3b5ee732007-03-23 23:46:48 +0000231
232 X86::GetCpuIDAndInfo(0x1, &EAX, &EBX, &ECX, &EDX);
Chris Lattner3b6f4972006-11-20 18:16:05 +0000233
Anton Korobeynikov3b5ee732007-03-23 23:46:48 +0000234 if ((EDX >> 23) & 0x1) X86SSELevel = MMX;
235 if ((EDX >> 25) & 0x1) X86SSELevel = SSE1;
236 if ((EDX >> 26) & 0x1) X86SSELevel = SSE2;
237 if (ECX & 0x1) X86SSELevel = SSE3;
Bill Wendlingbb1ee052007-04-10 22:10:25 +0000238 if ((ECX >> 9) & 0x1) X86SSELevel = SSSE3;
Nate Begeman63ec90a2008-02-03 07:18:54 +0000239 if ((ECX >> 19) & 0x1) X86SSELevel = SSE41;
240 if ((ECX >> 20) & 0x1) X86SSELevel = SSE42;
Anton Korobeynikov3b5ee732007-03-23 23:46:48 +0000241
Evan Chengccb69762009-01-02 05:35:45 +0000242 bool IsIntel = memcmp(text.c, "GenuineIntel", 12) == 0;
243 bool IsAMD = !IsIntel && memcmp(text.c, "AuthenticAMD", 12) == 0;
David Greene343dadb2009-06-26 22:46:54 +0000244
245 HasFMA3 = IsIntel && ((ECX >> 12) & 0x1);
246 HasAVX = ((ECX >> 28) & 0x1);
247
Evan Chengccb69762009-01-02 05:35:45 +0000248 if (IsIntel || IsAMD) {
249 // Determine if bit test memory instructions are slow.
250 unsigned Family = 0;
251 unsigned Model = 0;
252 DetectFamilyModel(EAX, Family, Model);
253 IsBTMemSlow = IsAMD || (Family == 6 && Model >= 13);
254
Jeff Cohenc3987092007-04-16 21:59:44 +0000255 X86::GetCpuIDAndInfo(0x80000001, &EAX, &EBX, &ECX, &EDX);
256 HasX86_64 = (EDX >> 29) & 0x1;
Stefanus Du Toit8cf5ab12009-05-26 21:04:35 +0000257 HasSSE4A = IsAMD && ((ECX >> 6) & 0x1);
David Greene343dadb2009-06-26 22:46:54 +0000258 HasFMA4 = IsAMD && ((ECX >> 16) & 0x1);
Jeff Cohenc3987092007-04-16 21:59:44 +0000259 }
Evan Cheng559806f2006-01-27 08:10:46 +0000260}
Evan Cheng97c7fc32006-01-26 09:53:06 +0000261
Evan Chenga26eb5e2006-10-06 09:17:41 +0000262static const char *GetCurrentX86CPU() {
263 unsigned EAX = 0, EBX = 0, ECX = 0, EDX = 0;
Evan Cheng751c0e12006-10-16 21:00:37 +0000264 if (X86::GetCpuIDAndInfo(0x1, &EAX, &EBX, &ECX, &EDX))
Evan Chenga26eb5e2006-10-06 09:17:41 +0000265 return "generic";
Evan Chengccb69762009-01-02 05:35:45 +0000266 unsigned Family = 0;
267 unsigned Model = 0;
268 DetectFamilyModel(EAX, Family, Model);
Evan Cheng018b7ee2009-01-02 05:29:20 +0000269
Evan Cheng751c0e12006-10-16 21:00:37 +0000270 X86::GetCpuIDAndInfo(0x80000001, &EAX, &EBX, &ECX, &EDX);
Evan Cheng3cff9f82006-10-06 18:57:51 +0000271 bool Em64T = (EDX >> 29) & 0x1;
Stefanus Du Toit8cf5ab12009-05-26 21:04:35 +0000272 bool HasSSE3 = (ECX & 0x1);
Evan Chenga26eb5e2006-10-06 09:17:41 +0000273
274 union {
275 unsigned u[3];
276 char c[12];
277 } text;
278
Evan Cheng751c0e12006-10-16 21:00:37 +0000279 X86::GetCpuIDAndInfo(0, &EAX, text.u+0, text.u+2, text.u+1);
Evan Chenga26eb5e2006-10-06 09:17:41 +0000280 if (memcmp(text.c, "GenuineIntel", 12) == 0) {
281 switch (Family) {
282 case 3:
283 return "i386";
284 case 4:
285 return "i486";
286 case 5:
287 switch (Model) {
288 case 4: return "pentium-mmx";
289 default: return "pentium";
290 }
291 case 6:
292 switch (Model) {
293 case 1: return "pentiumpro";
294 case 3:
295 case 5:
296 case 6: return "pentium2";
297 case 7:
298 case 8:
299 case 10:
300 case 11: return "pentium3";
301 case 9:
302 case 13: return "pentium-m";
303 case 14: return "yonah";
Evan Cheng5b925c02009-01-03 04:04:46 +0000304 case 15:
305 case 22: // Celeron M 540
306 return "core2";
307 case 23: // 45nm: Penryn , Wolfdale, Yorkfield (XE)
308 return "penryn";
Evan Chenga26eb5e2006-10-06 09:17:41 +0000309 default: return "i686";
310 }
311 case 15: {
312 switch (Model) {
313 case 3:
314 case 4:
Evan Cheng5b925c02009-01-03 04:04:46 +0000315 case 6: // same as 4, but 65nm
Evan Chenga26eb5e2006-10-06 09:17:41 +0000316 return (Em64T) ? "nocona" : "prescott";
Evan Cheng78771122009-01-05 08:45:01 +0000317 case 26:
318 return "corei7";
Evan Cheng5b925c02009-01-03 04:04:46 +0000319 case 28:
Evan Cheng78771122009-01-05 08:45:01 +0000320 return "atom";
Evan Chenga26eb5e2006-10-06 09:17:41 +0000321 default:
322 return (Em64T) ? "x86-64" : "pentium4";
323 }
324 }
325
326 default:
327 return "generic";
328 }
329 } else if (memcmp(text.c, "AuthenticAMD", 12) == 0) {
330 // FIXME: this poorly matches the generated SubtargetFeatureKV table. There
331 // appears to be no way to generate the wide variety of AMD-specific targets
332 // from the information returned from CPUID.
333 switch (Family) {
334 case 4:
335 return "i486";
336 case 5:
337 switch (Model) {
338 case 6:
339 case 7: return "k6";
340 case 8: return "k6-2";
341 case 9:
342 case 13: return "k6-3";
343 default: return "pentium";
344 }
345 case 6:
346 switch (Model) {
347 case 4: return "athlon-tbird";
348 case 6:
349 case 7:
350 case 8: return "athlon-mp";
351 case 10: return "athlon-xp";
352 default: return "athlon";
353 }
354 case 15:
Stefanus Du Toit8cf5ab12009-05-26 21:04:35 +0000355 if (HasSSE3) {
356 switch (Model) {
357 default: return "k8-sse3";
358 }
359 } else {
360 switch (Model) {
361 case 1: return "opteron";
362 case 5: return "athlon-fx"; // also opteron
363 default: return "athlon64";
364 }
365 }
366 case 16:
Evan Chenga26eb5e2006-10-06 09:17:41 +0000367 switch (Model) {
Stefanus Du Toit8cf5ab12009-05-26 21:04:35 +0000368 default: return "amdfam10";
Evan Chenga26eb5e2006-10-06 09:17:41 +0000369 }
Evan Chenga26eb5e2006-10-06 09:17:41 +0000370 default:
371 return "generic";
372 }
373 } else {
374 return "generic";
375 }
376}
377
Evan Cheng25ab6902006-09-08 06:48:29 +0000378X86Subtarget::X86Subtarget(const Module &M, const std::string &FS, bool is64Bit)
Evan Cheng8e0055d2006-10-04 18:33:00 +0000379 : AsmFlavor(AsmWriterFlavor)
Duncan Sandsf9a67a82008-11-28 09:29:37 +0000380 , PICStyle(PICStyles::None)
Evan Cheng25ab6902006-09-08 06:48:29 +0000381 , X86SSELevel(NoMMXSSE)
Evan Chengdc008582008-04-16 19:03:02 +0000382 , X863DNowLevel(NoThreeDNow)
Evan Cheng25ab6902006-09-08 06:48:29 +0000383 , HasX86_64(false)
David Greene343dadb2009-06-26 22:46:54 +0000384 , HasSSE4A(false)
385 , HasAVX(false)
386 , HasFMA3(false)
387 , HasFMA4(false)
Evan Chengccb69762009-01-02 05:35:45 +0000388 , IsBTMemSlow(false)
Chris Lattner7ad92d82008-01-02 19:44:55 +0000389 , DarwinVers(0)
Dan Gohman94bbdc82008-05-05 18:43:07 +0000390 , IsLinux(false)
Evan Cheng25ab6902006-09-08 06:48:29 +0000391 , stackAlignment(8)
392 // FIXME: this is a known good value for Yonah. How about others?
Rafael Espindolafc05f402007-10-31 11:52:06 +0000393 , MaxInlineSizeThreshold(128)
Evan Cheng25ab6902006-09-08 06:48:29 +0000394 , Is64Bit(is64Bit)
395 , TargetType(isELF) { // Default to ELF unless otherwise specified.
Anton Korobeynikov0eebf652009-06-08 22:53:56 +0000396
397 // default to hard float ABI
398 if (FloatABIType == FloatABI::Default)
399 FloatABIType = FloatABI::Hard;
Mon P Wang63307c32008-05-05 19:05:59 +0000400
Evan Cheng97c7fc32006-01-26 09:53:06 +0000401 // Determine default and user specified characteristics
Evan Chenga26eb5e2006-10-06 09:17:41 +0000402 if (!FS.empty()) {
403 // If feature string is not empty, parse features string.
404 std::string CPU = GetCurrentX86CPU();
405 ParseSubtargetFeatures(FS, CPU);
Torok Edwinb68a88b2009-02-02 21:57:34 +0000406 // All X86-64 CPUs also have SSE2, however user might request no SSE via
407 // -mattr, so don't force SSELevel here.
Chris Lattner3b6f4972006-11-20 18:16:05 +0000408 } else {
409 // Otherwise, use CPUID to auto-detect feature set.
410 AutoDetectSubtargetFeatures();
Dan Gohmanf75e5b42009-02-03 00:04:43 +0000411 // Make sure SSE2 is enabled; it is available on all X86-64 CPUs.
412 if (Is64Bit && X86SSELevel < SSE2)
413 X86SSELevel = SSE2;
Evan Cheng25ab6902006-09-08 06:48:29 +0000414 }
Dan Gohmanf75e5b42009-02-03 00:04:43 +0000415
Dan Gohman605679f2009-02-03 18:53:21 +0000416 // If requesting codegen for X86-64, make sure that 64-bit features
417 // are enabled.
418 if (Is64Bit)
419 HasX86_64 = true;
420
Evan Cheng5b925c02009-01-03 04:04:46 +0000421 DOUT << "Subtarget features: SSELevel " << X86SSELevel
422 << ", 3DNowLevel " << X863DNowLevel
423 << ", 64bit " << HasX86_64 << "\n";
Dan Gohmanf75e5b42009-02-03 00:04:43 +0000424 assert((!Is64Bit || HasX86_64) &&
425 "64-bit code requested on a subtarget that doesn't support it!");
Evan Cheng25ab6902006-09-08 06:48:29 +0000426
Nate Begemanfb5792f2005-07-12 01:41:54 +0000427 // Set the boolean corresponding to the current target triple, or the default
428 // if one cannot be determined, to true.
429 const std::string& TT = M.getTargetTriple();
430 if (TT.length() > 5) {
Duncan Sandse51775d2008-01-08 10:06:15 +0000431 size_t Pos;
Chris Lattner7ad92d82008-01-02 19:44:55 +0000432 if ((Pos = TT.find("-darwin")) != std::string::npos) {
Chris Lattnere5600e52005-11-21 22:31:58 +0000433 TargetType = isDarwin;
Chris Lattner7ad92d82008-01-02 19:44:55 +0000434
435 // Compute the darwin version number.
436 if (isdigit(TT[Pos+7]))
437 DarwinVers = atoi(&TT[Pos+7]);
438 else
439 DarwinVers = 8; // Minimum supported darwin is Tiger.
Dan Gohmana779a982008-05-05 00:28:39 +0000440 } else if (TT.find("linux") != std::string::npos) {
Dan Gohman600bf162008-05-05 16:11:31 +0000441 // Linux doesn't imply ELF, but we don't currently support anything else.
442 TargetType = isELF;
443 IsLinux = true;
Chris Lattner7ad92d82008-01-02 19:44:55 +0000444 } else if (TT.find("cygwin") != std::string::npos) {
445 TargetType = isCygwin;
446 } else if (TT.find("mingw") != std::string::npos) {
447 TargetType = isMingw;
448 } else if (TT.find("win32") != std::string::npos) {
Chris Lattnere5600e52005-11-21 22:31:58 +0000449 TargetType = isWindows;
Anton Korobeynikov508f0fd2008-03-22 21:12:53 +0000450 } else if (TT.find("windows") != std::string::npos) {
451 TargetType = isWindows;
Chris Lattner7ad92d82008-01-02 19:44:55 +0000452 }
Mon P Wang9feb5dd2009-02-28 00:25:30 +0000453 else if (TT.find("-cl") != std::string::npos) {
454 TargetType = isDarwin;
455 DarwinVers = 9;
456 }
Nate Begemanfb5792f2005-07-12 01:41:54 +0000457 } else if (TT.empty()) {
Anton Korobeynikov317848f2007-01-03 11:43:14 +0000458#if defined(__CYGWIN__)
Chris Lattnere5600e52005-11-21 22:31:58 +0000459 TargetType = isCygwin;
Anton Korobeynikov2b4f7802008-03-22 21:18:22 +0000460#elif defined(__MINGW32__) || defined(__MINGW64__)
Anton Korobeynikov317848f2007-01-03 11:43:14 +0000461 TargetType = isMingw;
Nate Begemanfb5792f2005-07-12 01:41:54 +0000462#elif defined(__APPLE__)
Chris Lattnere5600e52005-11-21 22:31:58 +0000463 TargetType = isDarwin;
Chris Lattner7ad92d82008-01-02 19:44:55 +0000464#if __APPLE_CC__ > 5400
465 DarwinVers = 9; // GCC 5400+ is Leopard.
466#else
467 DarwinVers = 8; // Minimum supported darwin is Tiger.
468#endif
469
Anton Korobeynikov2b4f7802008-03-22 21:18:22 +0000470#elif defined(_WIN32) || defined(_WIN64)
Chris Lattnere5600e52005-11-21 22:31:58 +0000471 TargetType = isWindows;
Dan Gohmana779a982008-05-05 00:28:39 +0000472#elif defined(__linux__)
473 // Linux doesn't imply ELF, but we don't currently support anything else.
Dan Gohman600bf162008-05-05 16:11:31 +0000474 TargetType = isELF;
475 IsLinux = true;
Nate Begemanfb5792f2005-07-12 01:41:54 +0000476#endif
477 }
478
Chris Lattnercdb341d2006-09-07 22:29:41 +0000479 // If the asm syntax hasn't been overridden on the command line, use whatever
480 // the target wants.
Anton Korobeynikov7f705592007-01-12 19:20:47 +0000481 if (AsmFlavor == X86Subtarget::Unset) {
Chris Lattner7ad92d82008-01-02 19:44:55 +0000482 AsmFlavor = (TargetType == isWindows)
483 ? X86Subtarget::Intel : X86Subtarget::ATT;
Chris Lattnercdb341d2006-09-07 22:29:41 +0000484 }
485
Anton Korobeynikov890fe882008-04-23 18:16:16 +0000486 // Stack alignment is 16 bytes on Darwin (both 32 and 64 bit) and for all 64
487 // bit targets.
488 if (TargetType == isDarwin || Is64Bit)
Nate Begemanfb5792f2005-07-12 01:41:54 +0000489 stackAlignment = 16;
Anton Korobeynikov78c80fd2008-04-12 22:12:22 +0000490
491 if (StackAlignment)
492 stackAlignment = StackAlignment;
Nate Begemanfb5792f2005-07-12 01:41:54 +0000493}