blob: 812089546bafe7aa000052bf9989c356d51ecc26 [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"
Daniel Dunbar3be03402009-08-02 22:11:08 +000018#include "llvm/GlobalValue.h"
Evan Cheng5b925c02009-01-03 04:04:46 +000019#include "llvm/Support/Debug.h"
Bill Wendling0ea8bf32009-08-03 00:11:34 +000020#include "llvm/Support/raw_ostream.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)
Bill Wendling0ea8bf32009-08-03 00:11:34 +000026#include <intrin.h>
Chris Lattnerbc583222009-04-25 18:27:23 +000027#endif
28
Chris Lattnerd392bd92009-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 Chenga82b22c2009-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 Lattnerd392bd92009-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 Lattnerc7822322009-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 Chenga82b22c2009-07-16 22:53:10 +000054 (isDecl || GV->isWeakForLinker()))
Chris Lattnerc7822322009-07-10 21:01:59 +000055 return X86II::MO_GOTPCREL;
56 } else {
57 assert(isTargetELF() && "Unknown rip-relative target");
Chris Lattnerd392bd92009-07-10 07:20:05 +000058
Chris Lattnerc7822322009-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 Lattnerd392bd92009-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 Lattnere2c92082009-07-10 21:00:45 +000074 if (isPICStyleStubPIC()) { // Darwin/32 in PIC mode.
Chris Lattner84853a12009-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 Lattnerd392bd92009-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 Chenga82b22c2009-07-16 22:53:10 +000080 if (!isDecl && !GV->isWeakForLinker())
Chris Lattner84853a12009-07-10 20:53:38 +000081 return X86II::MO_PIC_BASE_OFFSET;
Chris Lattnerd392bd92009-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 Lattner84853a12009-07-10 20:53:38 +000085 if (!GV->hasHiddenVisibility()) // Non-hidden $non_lazy_ptr reference.
86 return X86II::MO_DARWIN_NONLAZY_PIC_BASE;
Chris Lattnerd392bd92009-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 Chenga82b22c2009-07-16 22:53:10 +000090 if (isDecl || GV->hasCommonLinkage()) {
Chris Lattnerd392bd92009-07-10 07:20:05 +000091 // Hidden $non_lazy_ptr reference.
Chris Lattner84853a12009-07-10 20:53:38 +000092 return X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE;
Chris Lattnerd392bd92009-07-10 07:20:05 +000093 }
94
95 // Otherwise, no stub.
Chris Lattner84853a12009-07-10 20:53:38 +000096 return X86II::MO_PIC_BASE_OFFSET;
97 }
98
Chris Lattnere2c92082009-07-10 21:00:45 +000099 if (isPICStyleStubNoDynamic()) { // Darwin/32 in -mdynamic-no-pic mode.
Chris Lattner84853a12009-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 Chenga82b22c2009-07-16 22:53:10 +0000104 if (!isDecl && !GV->isWeakForLinker())
Chris Lattner84853a12009-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;
111
112 // If symbol visibility is hidden, we have a stub for common symbol
113 // references and external declarations.
Evan Chenga82b22c2009-07-16 22:53:10 +0000114 if (isDecl || GV->hasCommonLinkage()) {
Chris Lattner84853a12009-07-10 20:53:38 +0000115 // Hidden $non_lazy_ptr reference.
116 return X86II::MO_DARWIN_HIDDEN_NONLAZY;
117 }
118
119 // Otherwise, no stub.
120 return X86II::MO_NO_FLAG;
Chris Lattnerd392bd92009-07-10 07:20:05 +0000121 }
122
123 // Direct static reference to global.
124 return X86II::MO_NO_FLAG;
125}
126
Anton Korobeynikov7784ebc2006-11-30 22:42:55 +0000127
Bill Wendling6f287b22008-09-30 21:22:07 +0000128/// getBZeroEntry - This function returns the name of a function which has an
129/// interface like the non-standard bzero function, if such a function exists on
130/// the current subtarget and it is considered prefereable over memset with zero
131/// passed as the second argument. Otherwise it returns null.
Bill Wendling6e087382008-09-30 22:05:33 +0000132const char *X86Subtarget::getBZeroEntry() const {
Dan Gohman68d599d2008-04-01 20:38:36 +0000133 // Darwin 10 has a __bzero entry point for this purpose.
134 if (getDarwinVers() >= 10)
Bill Wendling6e087382008-09-30 22:05:33 +0000135 return "__bzero";
Dan Gohman68d599d2008-04-01 20:38:36 +0000136
137 return 0;
138}
139
Evan Chengd7f666a2009-05-20 04:53:57 +0000140/// IsLegalToCallImmediateAddr - Return true if the subtarget allows calls
141/// to immediate address.
142bool X86Subtarget::IsLegalToCallImmediateAddr(const TargetMachine &TM) const {
143 if (Is64Bit)
144 return false;
145 return isTargetELF() || TM.getRelocationModel() == Reloc::Static;
146}
147
Dan Gohman8749b612008-12-16 03:35:01 +0000148/// getSpecialAddressLatency - For targets where it is beneficial to
149/// backschedule instructions that compute addresses, return a value
150/// indicating the number of scheduling cycles of backscheduling that
151/// should be attempted.
152unsigned X86Subtarget::getSpecialAddressLatency() const {
153 // For x86 out-of-order targets, back-schedule address computations so
154 // that loads and stores aren't blocked.
155 // This value was chosen arbitrarily.
156 return 200;
157}
158
Chris Lattner1e39a152006-01-28 06:05:41 +0000159/// GetCpuIDAndInfo - Execute the specified cpuid and return the 4 values in the
160/// specified arguments. If we can't run cpuid on the host, return true.
Evan Chengd0da6ff2009-09-03 04:37:05 +0000161bool
162X86Subtarget::GetCpuIDAndInfo(unsigned value, unsigned *rEAX,
163 unsigned *rEBX, unsigned *rECX, unsigned *rEDX) {
Anton Korobeynikov6f9bb6f2009-08-28 16:06:41 +0000164#if defined(__x86_64__) || defined(_M_AMD64) || defined (_M_X64)
Chris Lattnerbc583222009-04-25 18:27:23 +0000165 #if defined(__GNUC__)
166 // gcc doesn't know cpuid would clobber ebx/rbx. Preseve it manually.
167 asm ("movq\t%%rbx, %%rsi\n\t"
168 "cpuid\n\t"
169 "xchgq\t%%rbx, %%rsi\n\t"
170 : "=a" (*rEAX),
171 "=S" (*rEBX),
172 "=c" (*rECX),
173 "=d" (*rEDX)
174 : "a" (value));
175 return false;
176 #elif defined(_MSC_VER)
177 int registers[4];
178 __cpuid(registers, value);
179 *rEAX = registers[0];
180 *rEBX = registers[1];
181 *rECX = registers[2];
182 *rEDX = registers[3];
183 return false;
184 #endif
Evan Cheng25ab6902006-09-08 06:48:29 +0000185#elif defined(i386) || defined(__i386__) || defined(__x86__) || defined(_M_IX86)
Chris Lattnerbc583222009-04-25 18:27:23 +0000186 #if defined(__GNUC__)
187 asm ("movl\t%%ebx, %%esi\n\t"
188 "cpuid\n\t"
189 "xchgl\t%%ebx, %%esi\n\t"
190 : "=a" (*rEAX),
191 "=S" (*rEBX),
192 "=c" (*rECX),
193 "=d" (*rEDX)
194 : "a" (value));
195 return false;
196 #elif defined(_MSC_VER)
197 __asm {
198 mov eax,value
199 cpuid
200 mov esi,rEAX
201 mov dword ptr [esi],eax
202 mov esi,rEBX
203 mov dword ptr [esi],ebx
204 mov esi,rECX
205 mov dword ptr [esi],ecx
206 mov esi,rEDX
207 mov dword ptr [esi],edx
208 }
209 return false;
210 #endif
Evan Cheng559806f2006-01-27 08:10:46 +0000211#endif
Chris Lattner1e39a152006-01-28 06:05:41 +0000212 return true;
Evan Cheng559806f2006-01-27 08:10:46 +0000213}
214
Evan Chengccb69762009-01-02 05:35:45 +0000215static void DetectFamilyModel(unsigned EAX, unsigned &Family, unsigned &Model) {
216 Family = (EAX >> 8) & 0xf; // Bits 8 - 11
217 Model = (EAX >> 4) & 0xf; // Bits 4 - 7
218 if (Family == 6 || Family == 0xf) {
219 if (Family == 0xf)
220 // Examine extended family ID if family ID is F.
221 Family += (EAX >> 20) & 0xff; // Bits 20 - 27
222 // Examine extended model ID if family ID is 6 or F.
223 Model += ((EAX >> 16) & 0xf) << 4; // Bits 16 - 19
224 }
225}
226
Evan Chenga26eb5e2006-10-06 09:17:41 +0000227void X86Subtarget::AutoDetectSubtargetFeatures() {
Evan Chengb3a7e212006-01-27 19:30:30 +0000228 unsigned EAX = 0, EBX = 0, ECX = 0, EDX = 0;
Jeff Cohena3496402006-01-28 18:47:32 +0000229 union {
Jeff Cohen216d2812006-01-28 19:48:34 +0000230 unsigned u[3];
231 char c[12];
Jeff Cohena3496402006-01-28 18:47:32 +0000232 } text;
Chris Lattner3b6f4972006-11-20 18:16:05 +0000233
Evan Chengd0da6ff2009-09-03 04:37:05 +0000234 if (GetCpuIDAndInfo(0, &EAX, text.u+0, text.u+2, text.u+1))
Evan Chengabc346c2006-10-06 08:21:07 +0000235 return;
Anton Korobeynikov3b5ee732007-03-23 23:46:48 +0000236
Evan Chengd0da6ff2009-09-03 04:37:05 +0000237 GetCpuIDAndInfo(0x1, &EAX, &EBX, &ECX, &EDX);
Chris Lattner3b6f4972006-11-20 18:16:05 +0000238
Chris Lattner70084162009-09-02 05:53:04 +0000239 if ((EDX >> 15) & 1) HasCMov = true;
240 if ((EDX >> 23) & 1) X86SSELevel = MMX;
241 if ((EDX >> 25) & 1) X86SSELevel = SSE1;
242 if ((EDX >> 26) & 1) X86SSELevel = SSE2;
Anton Korobeynikov3b5ee732007-03-23 23:46:48 +0000243 if (ECX & 0x1) X86SSELevel = SSE3;
Chris Lattner70084162009-09-02 05:53:04 +0000244 if ((ECX >> 9) & 1) X86SSELevel = SSSE3;
245 if ((ECX >> 19) & 1) X86SSELevel = SSE41;
246 if ((ECX >> 20) & 1) X86SSELevel = SSE42;
Anton Korobeynikov3b5ee732007-03-23 23:46:48 +0000247
Evan Chengccb69762009-01-02 05:35:45 +0000248 bool IsIntel = memcmp(text.c, "GenuineIntel", 12) == 0;
249 bool IsAMD = !IsIntel && memcmp(text.c, "AuthenticAMD", 12) == 0;
David Greene343dadb2009-06-26 22:46:54 +0000250
251 HasFMA3 = IsIntel && ((ECX >> 12) & 0x1);
252 HasAVX = ((ECX >> 28) & 0x1);
253
Evan Chengccb69762009-01-02 05:35:45 +0000254 if (IsIntel || IsAMD) {
255 // Determine if bit test memory instructions are slow.
256 unsigned Family = 0;
257 unsigned Model = 0;
258 DetectFamilyModel(EAX, Family, Model);
259 IsBTMemSlow = IsAMD || (Family == 6 && Model >= 13);
260
Evan Chengd0da6ff2009-09-03 04:37:05 +0000261 GetCpuIDAndInfo(0x80000001, &EAX, &EBX, &ECX, &EDX);
Jeff Cohenc3987092007-04-16 21:59:44 +0000262 HasX86_64 = (EDX >> 29) & 0x1;
Stefanus Du Toit8cf5ab12009-05-26 21:04:35 +0000263 HasSSE4A = IsAMD && ((ECX >> 6) & 0x1);
David Greene343dadb2009-06-26 22:46:54 +0000264 HasFMA4 = IsAMD && ((ECX >> 16) & 0x1);
Jeff Cohenc3987092007-04-16 21:59:44 +0000265 }
Evan Cheng559806f2006-01-27 08:10:46 +0000266}
Evan Cheng97c7fc32006-01-26 09:53:06 +0000267
Evan Chengd0da6ff2009-09-03 04:37:05 +0000268const char *X86Subtarget::GetCurrentX86CPU() {
Evan Chenga26eb5e2006-10-06 09:17:41 +0000269 unsigned EAX = 0, EBX = 0, ECX = 0, EDX = 0;
Evan Chengd0da6ff2009-09-03 04:37:05 +0000270 if (GetCpuIDAndInfo(0x1, &EAX, &EBX, &ECX, &EDX))
Evan Chenga26eb5e2006-10-06 09:17:41 +0000271 return "generic";
Evan Chengccb69762009-01-02 05:35:45 +0000272 unsigned Family = 0;
273 unsigned Model = 0;
274 DetectFamilyModel(EAX, Family, Model);
Evan Cheng018b7ee2009-01-02 05:29:20 +0000275
Evan Chengd0da6ff2009-09-03 04:37:05 +0000276 GetCpuIDAndInfo(0x80000001, &EAX, &EBX, &ECX, &EDX);
Evan Cheng3cff9f82006-10-06 18:57:51 +0000277 bool Em64T = (EDX >> 29) & 0x1;
Stefanus Du Toit8cf5ab12009-05-26 21:04:35 +0000278 bool HasSSE3 = (ECX & 0x1);
Evan Chenga26eb5e2006-10-06 09:17:41 +0000279
280 union {
281 unsigned u[3];
282 char c[12];
283 } text;
284
Evan Chengd0da6ff2009-09-03 04:37:05 +0000285 GetCpuIDAndInfo(0, &EAX, text.u+0, text.u+2, text.u+1);
Evan Chenga26eb5e2006-10-06 09:17:41 +0000286 if (memcmp(text.c, "GenuineIntel", 12) == 0) {
287 switch (Family) {
288 case 3:
289 return "i386";
290 case 4:
291 return "i486";
292 case 5:
293 switch (Model) {
294 case 4: return "pentium-mmx";
295 default: return "pentium";
296 }
297 case 6:
298 switch (Model) {
299 case 1: return "pentiumpro";
300 case 3:
301 case 5:
302 case 6: return "pentium2";
303 case 7:
304 case 8:
305 case 10:
306 case 11: return "pentium3";
307 case 9:
308 case 13: return "pentium-m";
309 case 14: return "yonah";
Evan Cheng5b925c02009-01-03 04:04:46 +0000310 case 15:
311 case 22: // Celeron M 540
312 return "core2";
313 case 23: // 45nm: Penryn , Wolfdale, Yorkfield (XE)
314 return "penryn";
Evan Chenga26eb5e2006-10-06 09:17:41 +0000315 default: return "i686";
316 }
317 case 15: {
318 switch (Model) {
319 case 3:
320 case 4:
Evan Cheng5b925c02009-01-03 04:04:46 +0000321 case 6: // same as 4, but 65nm
Evan Chenga26eb5e2006-10-06 09:17:41 +0000322 return (Em64T) ? "nocona" : "prescott";
Evan Cheng78771122009-01-05 08:45:01 +0000323 case 26:
324 return "corei7";
Evan Cheng5b925c02009-01-03 04:04:46 +0000325 case 28:
Evan Cheng78771122009-01-05 08:45:01 +0000326 return "atom";
Evan Chenga26eb5e2006-10-06 09:17:41 +0000327 default:
328 return (Em64T) ? "x86-64" : "pentium4";
329 }
330 }
331
332 default:
333 return "generic";
334 }
335 } else if (memcmp(text.c, "AuthenticAMD", 12) == 0) {
336 // FIXME: this poorly matches the generated SubtargetFeatureKV table. There
337 // appears to be no way to generate the wide variety of AMD-specific targets
338 // from the information returned from CPUID.
339 switch (Family) {
340 case 4:
341 return "i486";
342 case 5:
343 switch (Model) {
344 case 6:
345 case 7: return "k6";
346 case 8: return "k6-2";
347 case 9:
348 case 13: return "k6-3";
349 default: return "pentium";
350 }
351 case 6:
352 switch (Model) {
353 case 4: return "athlon-tbird";
354 case 6:
355 case 7:
356 case 8: return "athlon-mp";
357 case 10: return "athlon-xp";
358 default: return "athlon";
359 }
360 case 15:
Stefanus Du Toit8cf5ab12009-05-26 21:04:35 +0000361 if (HasSSE3) {
Daniel Dunbarcfb8a1b2009-07-19 01:38:38 +0000362 return "k8-sse3";
Stefanus Du Toit8cf5ab12009-05-26 21:04:35 +0000363 } else {
364 switch (Model) {
365 case 1: return "opteron";
366 case 5: return "athlon-fx"; // also opteron
367 default: return "athlon64";
368 }
369 }
370 case 16:
Daniel Dunbarcfb8a1b2009-07-19 01:38:38 +0000371 return "amdfam10";
Evan Chenga26eb5e2006-10-06 09:17:41 +0000372 default:
373 return "generic";
374 }
375 } else {
376 return "generic";
377 }
378}
379
Daniel Dunbar3be03402009-08-02 22:11:08 +0000380X86Subtarget::X86Subtarget(const std::string &TT, const std::string &FS,
381 bool is64Bit)
Chris Lattnerce914b82009-08-11 23:01:09 +0000382 : PICStyle(PICStyles::None)
Evan Cheng25ab6902006-09-08 06:48:29 +0000383 , X86SSELevel(NoMMXSSE)
Evan Chengdc008582008-04-16 19:03:02 +0000384 , X863DNowLevel(NoThreeDNow)
Chris Lattner70084162009-09-02 05:53:04 +0000385 , HasCMov(false)
Evan Cheng25ab6902006-09-08 06:48:29 +0000386 , HasX86_64(false)
David Greene343dadb2009-06-26 22:46:54 +0000387 , HasSSE4A(false)
388 , HasAVX(false)
389 , HasFMA3(false)
390 , HasFMA4(false)
Evan Chengccb69762009-01-02 05:35:45 +0000391 , IsBTMemSlow(false)
Chris Lattner7ad92d82008-01-02 19:44:55 +0000392 , DarwinVers(0)
Dan Gohman94bbdc82008-05-05 18:43:07 +0000393 , IsLinux(false)
Evan Cheng25ab6902006-09-08 06:48:29 +0000394 , stackAlignment(8)
395 // FIXME: this is a known good value for Yonah. How about others?
Rafael Espindolafc05f402007-10-31 11:52:06 +0000396 , MaxInlineSizeThreshold(128)
Evan Cheng25ab6902006-09-08 06:48:29 +0000397 , Is64Bit(is64Bit)
398 , TargetType(isELF) { // Default to ELF unless otherwise specified.
Anton Korobeynikov0eebf652009-06-08 22:53:56 +0000399
400 // default to hard float ABI
401 if (FloatABIType == FloatABI::Default)
402 FloatABIType = FloatABI::Hard;
Mon P Wang63307c32008-05-05 19:05:59 +0000403
Evan Cheng97c7fc32006-01-26 09:53:06 +0000404 // Determine default and user specified characteristics
Evan Chenga26eb5e2006-10-06 09:17:41 +0000405 if (!FS.empty()) {
406 // If feature string is not empty, parse features string.
407 std::string CPU = GetCurrentX86CPU();
408 ParseSubtargetFeatures(FS, CPU);
Torok Edwinb68a88b2009-02-02 21:57:34 +0000409 // All X86-64 CPUs also have SSE2, however user might request no SSE via
410 // -mattr, so don't force SSELevel here.
Chris Lattner3b6f4972006-11-20 18:16:05 +0000411 } else {
412 // Otherwise, use CPUID to auto-detect feature set.
413 AutoDetectSubtargetFeatures();
Dan Gohmanf75e5b42009-02-03 00:04:43 +0000414 // Make sure SSE2 is enabled; it is available on all X86-64 CPUs.
415 if (Is64Bit && X86SSELevel < SSE2)
416 X86SSELevel = SSE2;
Evan Cheng25ab6902006-09-08 06:48:29 +0000417 }
Dan Gohmanf75e5b42009-02-03 00:04:43 +0000418
Dan Gohman605679f2009-02-03 18:53:21 +0000419 // If requesting codegen for X86-64, make sure that 64-bit features
420 // are enabled.
421 if (Is64Bit)
422 HasX86_64 = true;
423
Bill Wendling0ea8bf32009-08-03 00:11:34 +0000424 DEBUG(errs() << "Subtarget features: SSELevel " << X86SSELevel
425 << ", 3DNowLevel " << X863DNowLevel
426 << ", 64bit " << HasX86_64 << "\n");
Dan Gohmanf75e5b42009-02-03 00:04:43 +0000427 assert((!Is64Bit || HasX86_64) &&
428 "64-bit code requested on a subtarget that doesn't support it!");
Evan Cheng25ab6902006-09-08 06:48:29 +0000429
Nate Begemanfb5792f2005-07-12 01:41:54 +0000430 // Set the boolean corresponding to the current target triple, or the default
431 // if one cannot be determined, to true.
Nate Begemanfb5792f2005-07-12 01:41:54 +0000432 if (TT.length() > 5) {
Duncan Sandse51775d2008-01-08 10:06:15 +0000433 size_t Pos;
Chris Lattner7ad92d82008-01-02 19:44:55 +0000434 if ((Pos = TT.find("-darwin")) != std::string::npos) {
Chris Lattnere5600e52005-11-21 22:31:58 +0000435 TargetType = isDarwin;
Chris Lattner7ad92d82008-01-02 19:44:55 +0000436
437 // Compute the darwin version number.
438 if (isdigit(TT[Pos+7]))
439 DarwinVers = atoi(&TT[Pos+7]);
440 else
441 DarwinVers = 8; // Minimum supported darwin is Tiger.
Dan Gohmana779a982008-05-05 00:28:39 +0000442 } else if (TT.find("linux") != std::string::npos) {
Dan Gohman600bf162008-05-05 16:11:31 +0000443 // Linux doesn't imply ELF, but we don't currently support anything else.
444 TargetType = isELF;
445 IsLinux = true;
Chris Lattner7ad92d82008-01-02 19:44:55 +0000446 } else if (TT.find("cygwin") != std::string::npos) {
447 TargetType = isCygwin;
448 } else if (TT.find("mingw") != std::string::npos) {
449 TargetType = isMingw;
450 } else if (TT.find("win32") != std::string::npos) {
Chris Lattnere5600e52005-11-21 22:31:58 +0000451 TargetType = isWindows;
Anton Korobeynikov508f0fd2008-03-22 21:12:53 +0000452 } else if (TT.find("windows") != std::string::npos) {
453 TargetType = isWindows;
Daniel Dunbare22f4da2009-08-05 18:12:37 +0000454 } else if (TT.find("-cl") != std::string::npos) {
Mon P Wang9feb5dd2009-02-28 00:25:30 +0000455 TargetType = isDarwin;
456 DarwinVers = 9;
457 }
Nate Begemanfb5792f2005-07-12 01:41:54 +0000458 }
459
Anton Korobeynikov890fe882008-04-23 18:16:16 +0000460 // Stack alignment is 16 bytes on Darwin (both 32 and 64 bit) and for all 64
461 // bit targets.
462 if (TargetType == isDarwin || Is64Bit)
Nate Begemanfb5792f2005-07-12 01:41:54 +0000463 stackAlignment = 16;
Anton Korobeynikov78c80fd2008-04-12 22:12:22 +0000464
465 if (StackAlignment)
466 stackAlignment = StackAlignment;
Nate Begemanfb5792f2005-07-12 01:41:54 +0000467}