blob: 9525f0474d57587cf5d27ccac0cd5ec9ff094a5e [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"
Daniel Dunbar31b44e82009-08-02 22:11:08 +000018#include "llvm/GlobalValue.h"
Evan Cheng9a3ec1b2009-01-03 04:04:46 +000019#include "llvm/Support/Debug.h"
Bill Wendling6eecd562009-08-03 00:11:34 +000020#include "llvm/Support/raw_ostream.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)
Bill Wendling6eecd562009-08-03 00:11:34 +000026#include <intrin.h>
Chris Lattner3ad60b12009-04-25 18:27:23 +000027#endif
28
Chris Lattnerdc842c02009-07-10 07:20:05 +000029/// ClassifyGlobalReference - Classify a global variable reference for the
30/// current subtarget according to how we should reference it in a non-pcrel
31/// context.
32unsigned char X86Subtarget::
33ClassifyGlobalReference(const GlobalValue *GV, const TargetMachine &TM) const {
34 // DLLImport only exists on windows, it is implemented as a load from a
35 // DLLIMPORT stub.
36 if (GV->hasDLLImportLinkage())
37 return X86II::MO_DLLIMPORT;
38
Evan Cheng02a76522009-07-16 22:53:10 +000039 // GV with ghost linkage (in JIT lazy compilation mode) do not require an
40 // extra load from stub.
41 bool isDecl = GV->isDeclaration() && !GV->hasNotBeenReadFromBitcode();
42
Chris Lattnerdc842c02009-07-10 07:20:05 +000043 // X86-64 in PIC mode.
44 if (isPICStyleRIPRel()) {
45 // Large model never uses stubs.
46 if (TM.getCodeModel() == CodeModel::Large)
47 return X86II::MO_NO_FLAG;
48
Chris Lattner7dce9912009-07-10 21:01:59 +000049 if (isTargetDarwin()) {
50 // If symbol visibility is hidden, the extra load is not needed if
51 // target is x86-64 or the symbol is definitely defined in the current
52 // translation unit.
53 if (GV->hasDefaultVisibility() &&
Evan Cheng02a76522009-07-16 22:53:10 +000054 (isDecl || GV->isWeakForLinker()))
Chris Lattner7dce9912009-07-10 21:01:59 +000055 return X86II::MO_GOTPCREL;
56 } else {
57 assert(isTargetELF() && "Unknown rip-relative target");
Chris Lattnerdc842c02009-07-10 07:20:05 +000058
Chris Lattner7dce9912009-07-10 21:01:59 +000059 // Extra load is needed for all externally visible.
60 if (!GV->hasLocalLinkage() && GV->hasDefaultVisibility())
61 return X86II::MO_GOTPCREL;
62 }
Chris Lattnerdc842c02009-07-10 07:20:05 +000063
64 return X86II::MO_NO_FLAG;
65 }
66
67 if (isPICStyleGOT()) { // 32-bit ELF targets.
68 // Extra load is needed for all externally visible.
69 if (GV->hasLocalLinkage() || GV->hasHiddenVisibility())
70 return X86II::MO_GOTOFF;
71 return X86II::MO_GOT;
72 }
73
Chris Lattner21c29402009-07-10 21:00:45 +000074 if (isPICStyleStubPIC()) { // Darwin/32 in PIC mode.
Chris Lattnerbd3e5602009-07-10 20:53:38 +000075 // Determine whether we have a stub reference and/or whether the reference
76 // is relative to the PIC base or not.
Chris Lattnerdc842c02009-07-10 07:20:05 +000077
78 // If this is a strong reference to a definition, it is definitely not
79 // through a stub.
Evan Cheng02a76522009-07-16 22:53:10 +000080 if (!isDecl && !GV->isWeakForLinker())
Chris Lattnerbd3e5602009-07-10 20:53:38 +000081 return X86II::MO_PIC_BASE_OFFSET;
Chris Lattnerdc842c02009-07-10 07:20:05 +000082
83 // Unless we have a symbol with hidden visibility, we have to go through a
84 // normal $non_lazy_ptr stub because this symbol might be resolved late.
Chris Lattnerbd3e5602009-07-10 20:53:38 +000085 if (!GV->hasHiddenVisibility()) // Non-hidden $non_lazy_ptr reference.
86 return X86II::MO_DARWIN_NONLAZY_PIC_BASE;
Chris Lattnerdc842c02009-07-10 07:20:05 +000087
88 // If symbol visibility is hidden, we have a stub for common symbol
89 // references and external declarations.
Evan Cheng02a76522009-07-16 22:53:10 +000090 if (isDecl || GV->hasCommonLinkage()) {
Chris Lattnerdc842c02009-07-10 07:20:05 +000091 // Hidden $non_lazy_ptr reference.
Chris Lattnerbd3e5602009-07-10 20:53:38 +000092 return X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE;
Chris Lattnerdc842c02009-07-10 07:20:05 +000093 }
94
95 // Otherwise, no stub.
Chris Lattnerbd3e5602009-07-10 20:53:38 +000096 return X86II::MO_PIC_BASE_OFFSET;
97 }
98
Chris Lattner21c29402009-07-10 21:00:45 +000099 if (isPICStyleStubNoDynamic()) { // Darwin/32 in -mdynamic-no-pic mode.
Chris Lattnerbd3e5602009-07-10 20:53:38 +0000100 // Determine whether we have a stub reference.
101
102 // If this is a strong reference to a definition, it is definitely not
103 // through a stub.
Evan Cheng02a76522009-07-16 22:53:10 +0000104 if (!isDecl && !GV->isWeakForLinker())
Chris Lattnerbd3e5602009-07-10 20:53:38 +0000105 return X86II::MO_NO_FLAG;
106
107 // Unless we have a symbol with hidden visibility, we have to go through a
108 // normal $non_lazy_ptr stub because this symbol might be resolved late.
109 if (!GV->hasHiddenVisibility()) // Non-hidden $non_lazy_ptr reference.
110 return X86II::MO_DARWIN_NONLAZY;
Evan Cheng1b389522009-09-03 07:04:02 +0000111
Chris Lattnerbd3e5602009-07-10 20:53:38 +0000112 // Otherwise, no stub.
113 return X86II::MO_NO_FLAG;
Chris Lattnerdc842c02009-07-10 07:20:05 +0000114 }
115
116 // Direct static reference to global.
117 return X86II::MO_NO_FLAG;
118}
119
Anton Korobeynikov6dbdfe22006-11-30 22:42:55 +0000120
Bill Wendlingbd092622008-09-30 21:22:07 +0000121/// getBZeroEntry - This function returns the name of a function which has an
122/// interface like the non-standard bzero function, if such a function exists on
123/// the current subtarget and it is considered prefereable over memset with zero
124/// passed as the second argument. Otherwise it returns null.
Bill Wendling17825842008-09-30 22:05:33 +0000125const char *X86Subtarget::getBZeroEntry() const {
Dan Gohman980d7202008-04-01 20:38:36 +0000126 // Darwin 10 has a __bzero entry point for this purpose.
127 if (getDarwinVers() >= 10)
Bill Wendling17825842008-09-30 22:05:33 +0000128 return "__bzero";
Dan Gohman980d7202008-04-01 20:38:36 +0000129
130 return 0;
131}
132
Evan Cheng96098332009-05-20 04:53:57 +0000133/// IsLegalToCallImmediateAddr - Return true if the subtarget allows calls
134/// to immediate address.
135bool X86Subtarget::IsLegalToCallImmediateAddr(const TargetMachine &TM) const {
136 if (Is64Bit)
137 return false;
138 return isTargetELF() || TM.getRelocationModel() == Reloc::Static;
139}
140
Dan Gohmanb9a01212008-12-16 03:35:01 +0000141/// getSpecialAddressLatency - For targets where it is beneficial to
142/// backschedule instructions that compute addresses, return a value
143/// indicating the number of scheduling cycles of backscheduling that
144/// should be attempted.
145unsigned X86Subtarget::getSpecialAddressLatency() const {
146 // For x86 out-of-order targets, back-schedule address computations so
147 // that loads and stores aren't blocked.
148 // This value was chosen arbitrarily.
149 return 200;
150}
151
Chris Lattnerdc8bbb62006-01-28 06:05:41 +0000152/// GetCpuIDAndInfo - Execute the specified cpuid and return the 4 values in the
153/// specified arguments. If we can't run cpuid on the host, return true.
Daniel Dunbarc3a0aba2009-09-03 05:47:34 +0000154static bool GetCpuIDAndInfo(unsigned value, unsigned *rEAX,
155 unsigned *rEBX, unsigned *rECX, unsigned *rEDX) {
Anton Korobeynikovf43ab912009-08-28 16:06:41 +0000156#if defined(__x86_64__) || defined(_M_AMD64) || defined (_M_X64)
Chris Lattner3ad60b12009-04-25 18:27:23 +0000157 #if defined(__GNUC__)
158 // gcc doesn't know cpuid would clobber ebx/rbx. Preseve it manually.
159 asm ("movq\t%%rbx, %%rsi\n\t"
160 "cpuid\n\t"
161 "xchgq\t%%rbx, %%rsi\n\t"
162 : "=a" (*rEAX),
163 "=S" (*rEBX),
164 "=c" (*rECX),
165 "=d" (*rEDX)
166 : "a" (value));
167 return false;
168 #elif defined(_MSC_VER)
169 int registers[4];
170 __cpuid(registers, value);
171 *rEAX = registers[0];
172 *rEBX = registers[1];
173 *rECX = registers[2];
174 *rEDX = registers[3];
175 return false;
176 #endif
Evan Cheng11b0a5d2006-09-08 06:48:29 +0000177#elif defined(i386) || defined(__i386__) || defined(__x86__) || defined(_M_IX86)
Chris Lattner3ad60b12009-04-25 18:27:23 +0000178 #if defined(__GNUC__)
179 asm ("movl\t%%ebx, %%esi\n\t"
180 "cpuid\n\t"
181 "xchgl\t%%ebx, %%esi\n\t"
182 : "=a" (*rEAX),
183 "=S" (*rEBX),
184 "=c" (*rECX),
185 "=d" (*rEDX)
186 : "a" (value));
187 return false;
188 #elif defined(_MSC_VER)
189 __asm {
190 mov eax,value
191 cpuid
192 mov esi,rEAX
193 mov dword ptr [esi],eax
194 mov esi,rEBX
195 mov dword ptr [esi],ebx
196 mov esi,rECX
197 mov dword ptr [esi],ecx
198 mov esi,rEDX
199 mov dword ptr [esi],edx
200 }
201 return false;
202 #endif
Evan Chengcde9e302006-01-27 08:10:46 +0000203#endif
Chris Lattnerdc8bbb62006-01-28 06:05:41 +0000204 return true;
Evan Chengcde9e302006-01-27 08:10:46 +0000205}
206
Evan Cheng4c91aa32009-01-02 05:35:45 +0000207static void DetectFamilyModel(unsigned EAX, unsigned &Family, unsigned &Model) {
208 Family = (EAX >> 8) & 0xf; // Bits 8 - 11
209 Model = (EAX >> 4) & 0xf; // Bits 4 - 7
210 if (Family == 6 || Family == 0xf) {
211 if (Family == 0xf)
212 // Examine extended family ID if family ID is F.
213 Family += (EAX >> 20) & 0xff; // Bits 20 - 27
214 // Examine extended model ID if family ID is 6 or F.
215 Model += ((EAX >> 16) & 0xf) << 4; // Bits 16 - 19
216 }
217}
218
Evan Chengff1beda2006-10-06 09:17:41 +0000219void X86Subtarget::AutoDetectSubtargetFeatures() {
Evan Chengafab7aa2006-01-27 19:30:30 +0000220 unsigned EAX = 0, EBX = 0, ECX = 0, EDX = 0;
Jeff Cohen71287082006-01-28 18:47:32 +0000221 union {
Jeff Cohen58ca0be92006-01-28 19:48:34 +0000222 unsigned u[3];
223 char c[12];
Jeff Cohen71287082006-01-28 18:47:32 +0000224 } text;
Chris Lattner3e962112006-11-20 18:16:05 +0000225
Evan Cheng47455a72009-09-03 04:37:05 +0000226 if (GetCpuIDAndInfo(0, &EAX, text.u+0, text.u+2, text.u+1))
Evan Cheng9274f722006-10-06 08:21:07 +0000227 return;
Anton Korobeynikov8aae2d72007-03-23 23:46:48 +0000228
Evan Cheng47455a72009-09-03 04:37:05 +0000229 GetCpuIDAndInfo(0x1, &EAX, &EBX, &ECX, &EDX);
Chris Lattner3e962112006-11-20 18:16:05 +0000230
Chris Lattnercc8c5812009-09-02 05:53:04 +0000231 if ((EDX >> 15) & 1) HasCMov = true;
232 if ((EDX >> 23) & 1) X86SSELevel = MMX;
233 if ((EDX >> 25) & 1) X86SSELevel = SSE1;
234 if ((EDX >> 26) & 1) X86SSELevel = SSE2;
Daniel Dunbarc3a0aba2009-09-03 05:47:34 +0000235 if (ECX & 0x1) X86SSELevel = SSE3;
Chris Lattnercc8c5812009-09-02 05:53:04 +0000236 if ((ECX >> 9) & 1) X86SSELevel = SSSE3;
237 if ((ECX >> 19) & 1) X86SSELevel = SSE41;
238 if ((ECX >> 20) & 1) X86SSELevel = SSE42;
Anton Korobeynikov8aae2d72007-03-23 23:46:48 +0000239
Evan Cheng4c91aa32009-01-02 05:35:45 +0000240 bool IsIntel = memcmp(text.c, "GenuineIntel", 12) == 0;
241 bool IsAMD = !IsIntel && memcmp(text.c, "AuthenticAMD", 12) == 0;
David Greene8f6f72c2009-06-26 22:46:54 +0000242
243 HasFMA3 = IsIntel && ((ECX >> 12) & 0x1);
244 HasAVX = ((ECX >> 28) & 0x1);
245
Evan Cheng4c91aa32009-01-02 05:35:45 +0000246 if (IsIntel || IsAMD) {
247 // Determine if bit test memory instructions are slow.
248 unsigned Family = 0;
249 unsigned Model = 0;
250 DetectFamilyModel(EAX, Family, Model);
251 IsBTMemSlow = IsAMD || (Family == 6 && Model >= 13);
252
Evan Cheng47455a72009-09-03 04:37:05 +0000253 GetCpuIDAndInfo(0x80000001, &EAX, &EBX, &ECX, &EDX);
Jeff Cohen6f3a5482007-04-16 21:59:44 +0000254 HasX86_64 = (EDX >> 29) & 0x1;
Stefanus Du Toit96180b52009-05-26 21:04:35 +0000255 HasSSE4A = IsAMD && ((ECX >> 6) & 0x1);
David Greene8f6f72c2009-06-26 22:46:54 +0000256 HasFMA4 = IsAMD && ((ECX >> 16) & 0x1);
Jeff Cohen6f3a5482007-04-16 21:59:44 +0000257 }
Evan Chengcde9e302006-01-27 08:10:46 +0000258}
Evan Cheng54c13da2006-01-26 09:53:06 +0000259
Daniel Dunbarc3a0aba2009-09-03 05:47:34 +0000260static const char *GetCurrentX86CPU() {
Evan Chengff1beda2006-10-06 09:17:41 +0000261 unsigned EAX = 0, EBX = 0, ECX = 0, EDX = 0;
Evan Cheng47455a72009-09-03 04:37:05 +0000262 if (GetCpuIDAndInfo(0x1, &EAX, &EBX, &ECX, &EDX))
Evan Chengff1beda2006-10-06 09:17:41 +0000263 return "generic";
Evan Cheng4c91aa32009-01-02 05:35:45 +0000264 unsigned Family = 0;
265 unsigned Model = 0;
266 DetectFamilyModel(EAX, Family, Model);
Evan Cheng13f3a332009-01-02 05:29:20 +0000267
Evan Cheng47455a72009-09-03 04:37:05 +0000268 GetCpuIDAndInfo(0x80000001, &EAX, &EBX, &ECX, &EDX);
Evan Cheng5fe96802006-10-06 18:57:51 +0000269 bool Em64T = (EDX >> 29) & 0x1;
Stefanus Du Toit96180b52009-05-26 21:04:35 +0000270 bool HasSSE3 = (ECX & 0x1);
Evan Chengff1beda2006-10-06 09:17:41 +0000271
272 union {
273 unsigned u[3];
274 char c[12];
275 } text;
276
Evan Cheng47455a72009-09-03 04:37:05 +0000277 GetCpuIDAndInfo(0, &EAX, text.u+0, text.u+2, text.u+1);
Evan Chengff1beda2006-10-06 09:17:41 +0000278 if (memcmp(text.c, "GenuineIntel", 12) == 0) {
279 switch (Family) {
280 case 3:
281 return "i386";
282 case 4:
283 return "i486";
284 case 5:
285 switch (Model) {
286 case 4: return "pentium-mmx";
287 default: return "pentium";
288 }
289 case 6:
290 switch (Model) {
291 case 1: return "pentiumpro";
292 case 3:
293 case 5:
294 case 6: return "pentium2";
295 case 7:
296 case 8:
297 case 10:
298 case 11: return "pentium3";
299 case 9:
300 case 13: return "pentium-m";
301 case 14: return "yonah";
Evan Cheng9a3ec1b2009-01-03 04:04:46 +0000302 case 15:
303 case 22: // Celeron M 540
304 return "core2";
305 case 23: // 45nm: Penryn , Wolfdale, Yorkfield (XE)
306 return "penryn";
Evan Chengff1beda2006-10-06 09:17:41 +0000307 default: return "i686";
308 }
309 case 15: {
310 switch (Model) {
311 case 3:
312 case 4:
Evan Cheng9a3ec1b2009-01-03 04:04:46 +0000313 case 6: // same as 4, but 65nm
Evan Chengff1beda2006-10-06 09:17:41 +0000314 return (Em64T) ? "nocona" : "prescott";
Evan Chengc3b09c32009-01-05 08:45:01 +0000315 case 26:
316 return "corei7";
Evan Cheng9a3ec1b2009-01-03 04:04:46 +0000317 case 28:
Evan Chengc3b09c32009-01-05 08:45:01 +0000318 return "atom";
Evan Chengff1beda2006-10-06 09:17:41 +0000319 default:
320 return (Em64T) ? "x86-64" : "pentium4";
321 }
322 }
323
324 default:
325 return "generic";
326 }
327 } else if (memcmp(text.c, "AuthenticAMD", 12) == 0) {
328 // FIXME: this poorly matches the generated SubtargetFeatureKV table. There
329 // appears to be no way to generate the wide variety of AMD-specific targets
330 // from the information returned from CPUID.
331 switch (Family) {
332 case 4:
333 return "i486";
334 case 5:
335 switch (Model) {
336 case 6:
337 case 7: return "k6";
338 case 8: return "k6-2";
339 case 9:
340 case 13: return "k6-3";
341 default: return "pentium";
342 }
343 case 6:
344 switch (Model) {
345 case 4: return "athlon-tbird";
346 case 6:
347 case 7:
348 case 8: return "athlon-mp";
349 case 10: return "athlon-xp";
350 default: return "athlon";
351 }
352 case 15:
Stefanus Du Toit96180b52009-05-26 21:04:35 +0000353 if (HasSSE3) {
Daniel Dunbarac0ca922009-07-19 01:38:38 +0000354 return "k8-sse3";
Stefanus Du Toit96180b52009-05-26 21:04:35 +0000355 } else {
356 switch (Model) {
357 case 1: return "opteron";
358 case 5: return "athlon-fx"; // also opteron
359 default: return "athlon64";
360 }
361 }
362 case 16:
Daniel Dunbarac0ca922009-07-19 01:38:38 +0000363 return "amdfam10";
Evan Chengff1beda2006-10-06 09:17:41 +0000364 default:
365 return "generic";
366 }
367 } else {
368 return "generic";
369 }
370}
371
Daniel Dunbar31b44e82009-08-02 22:11:08 +0000372X86Subtarget::X86Subtarget(const std::string &TT, const std::string &FS,
373 bool is64Bit)
Chris Lattner1e9097e2009-08-11 23:01:09 +0000374 : PICStyle(PICStyles::None)
Evan Cheng11b0a5d2006-09-08 06:48:29 +0000375 , X86SSELevel(NoMMXSSE)
Evan Chenga15cee12008-04-16 19:03:02 +0000376 , X863DNowLevel(NoThreeDNow)
Chris Lattnercc8c5812009-09-02 05:53:04 +0000377 , HasCMov(false)
Evan Cheng11b0a5d2006-09-08 06:48:29 +0000378 , HasX86_64(false)
David Greene8f6f72c2009-06-26 22:46:54 +0000379 , HasSSE4A(false)
380 , HasAVX(false)
381 , HasFMA3(false)
382 , HasFMA4(false)
Evan Cheng4c91aa32009-01-02 05:35:45 +0000383 , IsBTMemSlow(false)
Chris Lattnercce79c62008-01-02 19:44:55 +0000384 , DarwinVers(0)
Evan Cheng11b0a5d2006-09-08 06:48:29 +0000385 , stackAlignment(8)
386 // FIXME: this is a known good value for Yonah. How about others?
Rafael Espindola063f1772007-10-31 11:52:06 +0000387 , MaxInlineSizeThreshold(128)
Evan Cheng11b0a5d2006-09-08 06:48:29 +0000388 , Is64Bit(is64Bit)
389 , TargetType(isELF) { // Default to ELF unless otherwise specified.
Anton Korobeynikov77d19432009-06-08 22:53:56 +0000390
391 // default to hard float ABI
392 if (FloatABIType == FloatABI::Default)
393 FloatABIType = FloatABI::Hard;
Mon P Wang3e583932008-05-05 19:05:59 +0000394
Evan Cheng54c13da2006-01-26 09:53:06 +0000395 // Determine default and user specified characteristics
Evan Chengff1beda2006-10-06 09:17:41 +0000396 if (!FS.empty()) {
397 // If feature string is not empty, parse features string.
398 std::string CPU = GetCurrentX86CPU();
399 ParseSubtargetFeatures(FS, CPU);
Torok Edwine8386602009-02-02 21:57:34 +0000400 // All X86-64 CPUs also have SSE2, however user might request no SSE via
401 // -mattr, so don't force SSELevel here.
Chris Lattner3e962112006-11-20 18:16:05 +0000402 } else {
403 // Otherwise, use CPUID to auto-detect feature set.
404 AutoDetectSubtargetFeatures();
Dan Gohman74037512009-02-03 00:04:43 +0000405 // Make sure SSE2 is enabled; it is available on all X86-64 CPUs.
406 if (Is64Bit && X86SSELevel < SSE2)
407 X86SSELevel = SSE2;
Evan Cheng11b0a5d2006-09-08 06:48:29 +0000408 }
Dan Gohman74037512009-02-03 00:04:43 +0000409
Dan Gohman561d1222009-02-03 18:53:21 +0000410 // If requesting codegen for X86-64, make sure that 64-bit features
411 // are enabled.
412 if (Is64Bit)
413 HasX86_64 = true;
414
Bill Wendling6eecd562009-08-03 00:11:34 +0000415 DEBUG(errs() << "Subtarget features: SSELevel " << X86SSELevel
416 << ", 3DNowLevel " << X863DNowLevel
417 << ", 64bit " << HasX86_64 << "\n");
Dan Gohman74037512009-02-03 00:04:43 +0000418 assert((!Is64Bit || HasX86_64) &&
419 "64-bit code requested on a subtarget that doesn't support it!");
Evan Cheng11b0a5d2006-09-08 06:48:29 +0000420
Nate Begemanf26625e2005-07-12 01:41:54 +0000421 // Set the boolean corresponding to the current target triple, or the default
422 // if one cannot be determined, to true.
Nate Begemanf26625e2005-07-12 01:41:54 +0000423 if (TT.length() > 5) {
Duncan Sandsbb956ca2008-01-08 10:06:15 +0000424 size_t Pos;
Chris Lattnercce79c62008-01-02 19:44:55 +0000425 if ((Pos = TT.find("-darwin")) != std::string::npos) {
Chris Lattner3eb87612005-11-21 22:31:58 +0000426 TargetType = isDarwin;
Chris Lattnercce79c62008-01-02 19:44:55 +0000427
428 // Compute the darwin version number.
429 if (isdigit(TT[Pos+7]))
430 DarwinVers = atoi(&TT[Pos+7]);
431 else
432 DarwinVers = 8; // Minimum supported darwin is Tiger.
Dan Gohmanbcde1722008-05-05 00:28:39 +0000433 } else if (TT.find("linux") != std::string::npos) {
Dan Gohman6fd71c62008-05-05 16:11:31 +0000434 // Linux doesn't imply ELF, but we don't currently support anything else.
435 TargetType = isELF;
Chris Lattnercce79c62008-01-02 19:44:55 +0000436 } else if (TT.find("cygwin") != std::string::npos) {
437 TargetType = isCygwin;
438 } else if (TT.find("mingw") != std::string::npos) {
439 TargetType = isMingw;
440 } else if (TT.find("win32") != std::string::npos) {
Chris Lattner3eb87612005-11-21 22:31:58 +0000441 TargetType = isWindows;
Anton Korobeynikov07a789d2008-03-22 21:12:53 +0000442 } else if (TT.find("windows") != std::string::npos) {
443 TargetType = isWindows;
Daniel Dunbar4cc1fef2009-08-05 18:12:37 +0000444 } else if (TT.find("-cl") != std::string::npos) {
Mon P Wangd844dc32009-02-28 00:25:30 +0000445 TargetType = isDarwin;
446 DarwinVers = 9;
447 }
Nate Begemanf26625e2005-07-12 01:41:54 +0000448 }
449
Anton Korobeynikova7495262008-04-23 18:16:16 +0000450 // Stack alignment is 16 bytes on Darwin (both 32 and 64 bit) and for all 64
451 // bit targets.
452 if (TargetType == isDarwin || Is64Bit)
Nate Begemanf26625e2005-07-12 01:41:54 +0000453 stackAlignment = 16;
Anton Korobeynikovb9f38f32008-04-12 22:12:22 +0000454
455 if (StackAlignment)
456 stackAlignment = StackAlignment;
Nate Begemanf26625e2005-07-12 01:41:54 +0000457}