blob: 597f5653a30829cadcfc0a789b0abdac04d5177c [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
Chris Lattnerd392bd92009-07-10 07:20:05 +000037/// ClassifyGlobalReference - Classify a global variable reference for the
38/// current subtarget according to how we should reference it in a non-pcrel
39/// context.
40unsigned char X86Subtarget::
41ClassifyGlobalReference(const GlobalValue *GV, const TargetMachine &TM) const {
42 // DLLImport only exists on windows, it is implemented as a load from a
43 // DLLIMPORT stub.
44 if (GV->hasDLLImportLinkage())
45 return X86II::MO_DLLIMPORT;
46
47 // X86-64 in PIC mode.
48 if (isPICStyleRIPRel()) {
49 // Large model never uses stubs.
50 if (TM.getCodeModel() == CodeModel::Large)
51 return X86II::MO_NO_FLAG;
52
Chris Lattnerc7822322009-07-10 21:01:59 +000053 if (isTargetDarwin()) {
54 // If symbol visibility is hidden, the extra load is not needed if
55 // target is x86-64 or the symbol is definitely defined in the current
56 // translation unit.
57 if (GV->hasDefaultVisibility() &&
58 (GV->isDeclaration() || GV->isWeakForLinker()))
59 return X86II::MO_GOTPCREL;
60 } else {
61 assert(isTargetELF() && "Unknown rip-relative target");
Chris Lattnerd392bd92009-07-10 07:20:05 +000062
Chris Lattnerc7822322009-07-10 21:01:59 +000063 // Extra load is needed for all externally visible.
64 if (!GV->hasLocalLinkage() && GV->hasDefaultVisibility())
65 return X86II::MO_GOTPCREL;
66 }
Chris Lattnerd392bd92009-07-10 07:20:05 +000067
68 return X86II::MO_NO_FLAG;
69 }
70
71 if (isPICStyleGOT()) { // 32-bit ELF targets.
72 // Extra load is needed for all externally visible.
73 if (GV->hasLocalLinkage() || GV->hasHiddenVisibility())
74 return X86II::MO_GOTOFF;
75 return X86II::MO_GOT;
76 }
77
Chris Lattnere2c92082009-07-10 21:00:45 +000078 if (isPICStyleStubPIC()) { // Darwin/32 in PIC mode.
Chris Lattner84853a12009-07-10 20:53:38 +000079 // Determine whether we have a stub reference and/or whether the reference
80 // is relative to the PIC base or not.
Chris Lattnerd392bd92009-07-10 07:20:05 +000081
82 // If this is a strong reference to a definition, it is definitely not
83 // through a stub.
84 if (!GV->isDeclaration() && !GV->isWeakForLinker())
Chris Lattner84853a12009-07-10 20:53:38 +000085 return X86II::MO_PIC_BASE_OFFSET;
Chris Lattnerd392bd92009-07-10 07:20:05 +000086
87 // Unless we have a symbol with hidden visibility, we have to go through a
88 // normal $non_lazy_ptr stub because this symbol might be resolved late.
Chris Lattner84853a12009-07-10 20:53:38 +000089 if (!GV->hasHiddenVisibility()) // Non-hidden $non_lazy_ptr reference.
90 return X86II::MO_DARWIN_NONLAZY_PIC_BASE;
Chris Lattnerd392bd92009-07-10 07:20:05 +000091
92 // If symbol visibility is hidden, we have a stub for common symbol
93 // references and external declarations.
94 if (GV->isDeclaration() || GV->hasCommonLinkage()) {
95 // Hidden $non_lazy_ptr reference.
Chris Lattner84853a12009-07-10 20:53:38 +000096 return X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE;
Chris Lattnerd392bd92009-07-10 07:20:05 +000097 }
98
99 // Otherwise, no stub.
Chris Lattner84853a12009-07-10 20:53:38 +0000100 return X86II::MO_PIC_BASE_OFFSET;
101 }
102
Chris Lattnere2c92082009-07-10 21:00:45 +0000103 if (isPICStyleStubNoDynamic()) { // Darwin/32 in -mdynamic-no-pic mode.
Chris Lattner84853a12009-07-10 20:53:38 +0000104 // Determine whether we have a stub reference.
105
106 // If this is a strong reference to a definition, it is definitely not
107 // through a stub.
108 if (!GV->isDeclaration() && !GV->isWeakForLinker())
109 return X86II::MO_NO_FLAG;
110
111 // Unless we have a symbol with hidden visibility, we have to go through a
112 // normal $non_lazy_ptr stub because this symbol might be resolved late.
113 if (!GV->hasHiddenVisibility()) // Non-hidden $non_lazy_ptr reference.
114 return X86II::MO_DARWIN_NONLAZY;
115
116 // If symbol visibility is hidden, we have a stub for common symbol
117 // references and external declarations.
118 if (GV->isDeclaration() || GV->hasCommonLinkage()) {
119 // Hidden $non_lazy_ptr reference.
120 return X86II::MO_DARWIN_HIDDEN_NONLAZY;
121 }
122
123 // Otherwise, no stub.
124 return X86II::MO_NO_FLAG;
Chris Lattnerd392bd92009-07-10 07:20:05 +0000125 }
126
127 // Direct static reference to global.
128 return X86II::MO_NO_FLAG;
129}
130
Anton Korobeynikov7784ebc2006-11-30 22:42:55 +0000131
Bill Wendling6f287b22008-09-30 21:22:07 +0000132/// getBZeroEntry - This function returns the name of a function which has an
133/// interface like the non-standard bzero function, if such a function exists on
134/// the current subtarget and it is considered prefereable over memset with zero
135/// passed as the second argument. Otherwise it returns null.
Bill Wendling6e087382008-09-30 22:05:33 +0000136const char *X86Subtarget::getBZeroEntry() const {
Dan Gohman68d599d2008-04-01 20:38:36 +0000137 // Darwin 10 has a __bzero entry point for this purpose.
138 if (getDarwinVers() >= 10)
Bill Wendling6e087382008-09-30 22:05:33 +0000139 return "__bzero";
Dan Gohman68d599d2008-04-01 20:38:36 +0000140
141 return 0;
142}
143
Evan Chengd7f666a2009-05-20 04:53:57 +0000144/// IsLegalToCallImmediateAddr - Return true if the subtarget allows calls
145/// to immediate address.
146bool X86Subtarget::IsLegalToCallImmediateAddr(const TargetMachine &TM) const {
147 if (Is64Bit)
148 return false;
149 return isTargetELF() || TM.getRelocationModel() == Reloc::Static;
150}
151
Dan Gohman8749b612008-12-16 03:35:01 +0000152/// getSpecialAddressLatency - For targets where it is beneficial to
153/// backschedule instructions that compute addresses, return a value
154/// indicating the number of scheduling cycles of backscheduling that
155/// should be attempted.
156unsigned X86Subtarget::getSpecialAddressLatency() const {
157 // For x86 out-of-order targets, back-schedule address computations so
158 // that loads and stores aren't blocked.
159 // This value was chosen arbitrarily.
160 return 200;
161}
162
Chris Lattner1e39a152006-01-28 06:05:41 +0000163/// GetCpuIDAndInfo - Execute the specified cpuid and return the 4 values in the
164/// specified arguments. If we can't run cpuid on the host, return true.
Evan Cheng751c0e12006-10-16 21:00:37 +0000165bool X86::GetCpuIDAndInfo(unsigned value, unsigned *rEAX, unsigned *rEBX,
166 unsigned *rECX, unsigned *rEDX) {
Chris Lattnerbc583222009-04-25 18:27:23 +0000167#if defined(__x86_64__) || defined(_M_AMD64)
168 #if defined(__GNUC__)
169 // gcc doesn't know cpuid would clobber ebx/rbx. Preseve it manually.
170 asm ("movq\t%%rbx, %%rsi\n\t"
171 "cpuid\n\t"
172 "xchgq\t%%rbx, %%rsi\n\t"
173 : "=a" (*rEAX),
174 "=S" (*rEBX),
175 "=c" (*rECX),
176 "=d" (*rEDX)
177 : "a" (value));
178 return false;
179 #elif defined(_MSC_VER)
180 int registers[4];
181 __cpuid(registers, value);
182 *rEAX = registers[0];
183 *rEBX = registers[1];
184 *rECX = registers[2];
185 *rEDX = registers[3];
186 return false;
187 #endif
Evan Cheng25ab6902006-09-08 06:48:29 +0000188#elif defined(i386) || defined(__i386__) || defined(__x86__) || defined(_M_IX86)
Chris Lattnerbc583222009-04-25 18:27:23 +0000189 #if defined(__GNUC__)
190 asm ("movl\t%%ebx, %%esi\n\t"
191 "cpuid\n\t"
192 "xchgl\t%%ebx, %%esi\n\t"
193 : "=a" (*rEAX),
194 "=S" (*rEBX),
195 "=c" (*rECX),
196 "=d" (*rEDX)
197 : "a" (value));
198 return false;
199 #elif defined(_MSC_VER)
200 __asm {
201 mov eax,value
202 cpuid
203 mov esi,rEAX
204 mov dword ptr [esi],eax
205 mov esi,rEBX
206 mov dword ptr [esi],ebx
207 mov esi,rECX
208 mov dword ptr [esi],ecx
209 mov esi,rEDX
210 mov dword ptr [esi],edx
211 }
212 return false;
213 #endif
Evan Cheng559806f2006-01-27 08:10:46 +0000214#endif
Chris Lattner1e39a152006-01-28 06:05:41 +0000215 return true;
Evan Cheng559806f2006-01-27 08:10:46 +0000216}
217
Evan Chengccb69762009-01-02 05:35:45 +0000218static void DetectFamilyModel(unsigned EAX, unsigned &Family, unsigned &Model) {
219 Family = (EAX >> 8) & 0xf; // Bits 8 - 11
220 Model = (EAX >> 4) & 0xf; // Bits 4 - 7
221 if (Family == 6 || Family == 0xf) {
222 if (Family == 0xf)
223 // Examine extended family ID if family ID is F.
224 Family += (EAX >> 20) & 0xff; // Bits 20 - 27
225 // Examine extended model ID if family ID is 6 or F.
226 Model += ((EAX >> 16) & 0xf) << 4; // Bits 16 - 19
227 }
228}
229
Evan Chenga26eb5e2006-10-06 09:17:41 +0000230void X86Subtarget::AutoDetectSubtargetFeatures() {
Evan Chengb3a7e212006-01-27 19:30:30 +0000231 unsigned EAX = 0, EBX = 0, ECX = 0, EDX = 0;
Jeff Cohena3496402006-01-28 18:47:32 +0000232 union {
Jeff Cohen216d2812006-01-28 19:48:34 +0000233 unsigned u[3];
234 char c[12];
Jeff Cohena3496402006-01-28 18:47:32 +0000235 } text;
Chris Lattner3b6f4972006-11-20 18:16:05 +0000236
Evan Cheng751c0e12006-10-16 21:00:37 +0000237 if (X86::GetCpuIDAndInfo(0, &EAX, text.u+0, text.u+2, text.u+1))
Evan Chengabc346c2006-10-06 08:21:07 +0000238 return;
Anton Korobeynikov3b5ee732007-03-23 23:46:48 +0000239
240 X86::GetCpuIDAndInfo(0x1, &EAX, &EBX, &ECX, &EDX);
Chris Lattner3b6f4972006-11-20 18:16:05 +0000241
Anton Korobeynikov3b5ee732007-03-23 23:46:48 +0000242 if ((EDX >> 23) & 0x1) X86SSELevel = MMX;
243 if ((EDX >> 25) & 0x1) X86SSELevel = SSE1;
244 if ((EDX >> 26) & 0x1) X86SSELevel = SSE2;
245 if (ECX & 0x1) X86SSELevel = SSE3;
Bill Wendlingbb1ee052007-04-10 22:10:25 +0000246 if ((ECX >> 9) & 0x1) X86SSELevel = SSSE3;
Nate Begeman63ec90a2008-02-03 07:18:54 +0000247 if ((ECX >> 19) & 0x1) X86SSELevel = SSE41;
248 if ((ECX >> 20) & 0x1) X86SSELevel = SSE42;
Anton Korobeynikov3b5ee732007-03-23 23:46:48 +0000249
Evan Chengccb69762009-01-02 05:35:45 +0000250 bool IsIntel = memcmp(text.c, "GenuineIntel", 12) == 0;
251 bool IsAMD = !IsIntel && memcmp(text.c, "AuthenticAMD", 12) == 0;
David Greene343dadb2009-06-26 22:46:54 +0000252
253 HasFMA3 = IsIntel && ((ECX >> 12) & 0x1);
254 HasAVX = ((ECX >> 28) & 0x1);
255
Evan Chengccb69762009-01-02 05:35:45 +0000256 if (IsIntel || IsAMD) {
257 // Determine if bit test memory instructions are slow.
258 unsigned Family = 0;
259 unsigned Model = 0;
260 DetectFamilyModel(EAX, Family, Model);
261 IsBTMemSlow = IsAMD || (Family == 6 && Model >= 13);
262
Jeff Cohenc3987092007-04-16 21:59:44 +0000263 X86::GetCpuIDAndInfo(0x80000001, &EAX, &EBX, &ECX, &EDX);
264 HasX86_64 = (EDX >> 29) & 0x1;
Stefanus Du Toit8cf5ab12009-05-26 21:04:35 +0000265 HasSSE4A = IsAMD && ((ECX >> 6) & 0x1);
David Greene343dadb2009-06-26 22:46:54 +0000266 HasFMA4 = IsAMD && ((ECX >> 16) & 0x1);
Jeff Cohenc3987092007-04-16 21:59:44 +0000267 }
Evan Cheng559806f2006-01-27 08:10:46 +0000268}
Evan Cheng97c7fc32006-01-26 09:53:06 +0000269
Evan Chenga26eb5e2006-10-06 09:17:41 +0000270static const char *GetCurrentX86CPU() {
271 unsigned EAX = 0, EBX = 0, ECX = 0, EDX = 0;
Evan Cheng751c0e12006-10-16 21:00:37 +0000272 if (X86::GetCpuIDAndInfo(0x1, &EAX, &EBX, &ECX, &EDX))
Evan Chenga26eb5e2006-10-06 09:17:41 +0000273 return "generic";
Evan Chengccb69762009-01-02 05:35:45 +0000274 unsigned Family = 0;
275 unsigned Model = 0;
276 DetectFamilyModel(EAX, Family, Model);
Evan Cheng018b7ee2009-01-02 05:29:20 +0000277
Evan Cheng751c0e12006-10-16 21:00:37 +0000278 X86::GetCpuIDAndInfo(0x80000001, &EAX, &EBX, &ECX, &EDX);
Evan Cheng3cff9f82006-10-06 18:57:51 +0000279 bool Em64T = (EDX >> 29) & 0x1;
Stefanus Du Toit8cf5ab12009-05-26 21:04:35 +0000280 bool HasSSE3 = (ECX & 0x1);
Evan Chenga26eb5e2006-10-06 09:17:41 +0000281
282 union {
283 unsigned u[3];
284 char c[12];
285 } text;
286
Evan Cheng751c0e12006-10-16 21:00:37 +0000287 X86::GetCpuIDAndInfo(0, &EAX, text.u+0, text.u+2, text.u+1);
Evan Chenga26eb5e2006-10-06 09:17:41 +0000288 if (memcmp(text.c, "GenuineIntel", 12) == 0) {
289 switch (Family) {
290 case 3:
291 return "i386";
292 case 4:
293 return "i486";
294 case 5:
295 switch (Model) {
296 case 4: return "pentium-mmx";
297 default: return "pentium";
298 }
299 case 6:
300 switch (Model) {
301 case 1: return "pentiumpro";
302 case 3:
303 case 5:
304 case 6: return "pentium2";
305 case 7:
306 case 8:
307 case 10:
308 case 11: return "pentium3";
309 case 9:
310 case 13: return "pentium-m";
311 case 14: return "yonah";
Evan Cheng5b925c02009-01-03 04:04:46 +0000312 case 15:
313 case 22: // Celeron M 540
314 return "core2";
315 case 23: // 45nm: Penryn , Wolfdale, Yorkfield (XE)
316 return "penryn";
Evan Chenga26eb5e2006-10-06 09:17:41 +0000317 default: return "i686";
318 }
319 case 15: {
320 switch (Model) {
321 case 3:
322 case 4:
Evan Cheng5b925c02009-01-03 04:04:46 +0000323 case 6: // same as 4, but 65nm
Evan Chenga26eb5e2006-10-06 09:17:41 +0000324 return (Em64T) ? "nocona" : "prescott";
Evan Cheng78771122009-01-05 08:45:01 +0000325 case 26:
326 return "corei7";
Evan Cheng5b925c02009-01-03 04:04:46 +0000327 case 28:
Evan Cheng78771122009-01-05 08:45:01 +0000328 return "atom";
Evan Chenga26eb5e2006-10-06 09:17:41 +0000329 default:
330 return (Em64T) ? "x86-64" : "pentium4";
331 }
332 }
333
334 default:
335 return "generic";
336 }
337 } else if (memcmp(text.c, "AuthenticAMD", 12) == 0) {
338 // FIXME: this poorly matches the generated SubtargetFeatureKV table. There
339 // appears to be no way to generate the wide variety of AMD-specific targets
340 // from the information returned from CPUID.
341 switch (Family) {
342 case 4:
343 return "i486";
344 case 5:
345 switch (Model) {
346 case 6:
347 case 7: return "k6";
348 case 8: return "k6-2";
349 case 9:
350 case 13: return "k6-3";
351 default: return "pentium";
352 }
353 case 6:
354 switch (Model) {
355 case 4: return "athlon-tbird";
356 case 6:
357 case 7:
358 case 8: return "athlon-mp";
359 case 10: return "athlon-xp";
360 default: return "athlon";
361 }
362 case 15:
Stefanus Du Toit8cf5ab12009-05-26 21:04:35 +0000363 if (HasSSE3) {
364 switch (Model) {
365 default: return "k8-sse3";
366 }
367 } else {
368 switch (Model) {
369 case 1: return "opteron";
370 case 5: return "athlon-fx"; // also opteron
371 default: return "athlon64";
372 }
373 }
374 case 16:
Evan Chenga26eb5e2006-10-06 09:17:41 +0000375 switch (Model) {
Stefanus Du Toit8cf5ab12009-05-26 21:04:35 +0000376 default: return "amdfam10";
Evan Chenga26eb5e2006-10-06 09:17:41 +0000377 }
Evan Chenga26eb5e2006-10-06 09:17:41 +0000378 default:
379 return "generic";
380 }
381 } else {
382 return "generic";
383 }
384}
385
Evan Cheng25ab6902006-09-08 06:48:29 +0000386X86Subtarget::X86Subtarget(const Module &M, const std::string &FS, bool is64Bit)
Evan Cheng8e0055d2006-10-04 18:33:00 +0000387 : AsmFlavor(AsmWriterFlavor)
Duncan Sandsf9a67a82008-11-28 09:29:37 +0000388 , PICStyle(PICStyles::None)
Evan Cheng25ab6902006-09-08 06:48:29 +0000389 , X86SSELevel(NoMMXSSE)
Evan Chengdc008582008-04-16 19:03:02 +0000390 , X863DNowLevel(NoThreeDNow)
Evan Cheng25ab6902006-09-08 06:48:29 +0000391 , HasX86_64(false)
David Greene343dadb2009-06-26 22:46:54 +0000392 , HasSSE4A(false)
393 , HasAVX(false)
394 , HasFMA3(false)
395 , HasFMA4(false)
Evan Chengccb69762009-01-02 05:35:45 +0000396 , IsBTMemSlow(false)
Chris Lattner7ad92d82008-01-02 19:44:55 +0000397 , DarwinVers(0)
Dan Gohman94bbdc82008-05-05 18:43:07 +0000398 , IsLinux(false)
Evan Cheng25ab6902006-09-08 06:48:29 +0000399 , stackAlignment(8)
400 // FIXME: this is a known good value for Yonah. How about others?
Rafael Espindolafc05f402007-10-31 11:52:06 +0000401 , MaxInlineSizeThreshold(128)
Evan Cheng25ab6902006-09-08 06:48:29 +0000402 , Is64Bit(is64Bit)
403 , TargetType(isELF) { // Default to ELF unless otherwise specified.
Anton Korobeynikov0eebf652009-06-08 22:53:56 +0000404
405 // default to hard float ABI
406 if (FloatABIType == FloatABI::Default)
407 FloatABIType = FloatABI::Hard;
Mon P Wang63307c32008-05-05 19:05:59 +0000408
Evan Cheng97c7fc32006-01-26 09:53:06 +0000409 // Determine default and user specified characteristics
Evan Chenga26eb5e2006-10-06 09:17:41 +0000410 if (!FS.empty()) {
411 // If feature string is not empty, parse features string.
412 std::string CPU = GetCurrentX86CPU();
413 ParseSubtargetFeatures(FS, CPU);
Torok Edwinb68a88b2009-02-02 21:57:34 +0000414 // All X86-64 CPUs also have SSE2, however user might request no SSE via
415 // -mattr, so don't force SSELevel here.
Chris Lattner3b6f4972006-11-20 18:16:05 +0000416 } else {
417 // Otherwise, use CPUID to auto-detect feature set.
418 AutoDetectSubtargetFeatures();
Dan Gohmanf75e5b42009-02-03 00:04:43 +0000419 // Make sure SSE2 is enabled; it is available on all X86-64 CPUs.
420 if (Is64Bit && X86SSELevel < SSE2)
421 X86SSELevel = SSE2;
Evan Cheng25ab6902006-09-08 06:48:29 +0000422 }
Dan Gohmanf75e5b42009-02-03 00:04:43 +0000423
Dan Gohman605679f2009-02-03 18:53:21 +0000424 // If requesting codegen for X86-64, make sure that 64-bit features
425 // are enabled.
426 if (Is64Bit)
427 HasX86_64 = true;
428
Evan Cheng5b925c02009-01-03 04:04:46 +0000429 DOUT << "Subtarget features: SSELevel " << X86SSELevel
430 << ", 3DNowLevel " << X863DNowLevel
431 << ", 64bit " << HasX86_64 << "\n";
Dan Gohmanf75e5b42009-02-03 00:04:43 +0000432 assert((!Is64Bit || HasX86_64) &&
433 "64-bit code requested on a subtarget that doesn't support it!");
Evan Cheng25ab6902006-09-08 06:48:29 +0000434
Nate Begemanfb5792f2005-07-12 01:41:54 +0000435 // Set the boolean corresponding to the current target triple, or the default
436 // if one cannot be determined, to true.
437 const std::string& TT = M.getTargetTriple();
438 if (TT.length() > 5) {
Duncan Sandse51775d2008-01-08 10:06:15 +0000439 size_t Pos;
Chris Lattner7ad92d82008-01-02 19:44:55 +0000440 if ((Pos = TT.find("-darwin")) != std::string::npos) {
Chris Lattnere5600e52005-11-21 22:31:58 +0000441 TargetType = isDarwin;
Chris Lattner7ad92d82008-01-02 19:44:55 +0000442
443 // Compute the darwin version number.
444 if (isdigit(TT[Pos+7]))
445 DarwinVers = atoi(&TT[Pos+7]);
446 else
447 DarwinVers = 8; // Minimum supported darwin is Tiger.
Dan Gohmana779a982008-05-05 00:28:39 +0000448 } else if (TT.find("linux") != std::string::npos) {
Dan Gohman600bf162008-05-05 16:11:31 +0000449 // Linux doesn't imply ELF, but we don't currently support anything else.
450 TargetType = isELF;
451 IsLinux = true;
Chris Lattner7ad92d82008-01-02 19:44:55 +0000452 } else if (TT.find("cygwin") != std::string::npos) {
453 TargetType = isCygwin;
454 } else if (TT.find("mingw") != std::string::npos) {
455 TargetType = isMingw;
456 } else if (TT.find("win32") != std::string::npos) {
Chris Lattnere5600e52005-11-21 22:31:58 +0000457 TargetType = isWindows;
Anton Korobeynikov508f0fd2008-03-22 21:12:53 +0000458 } else if (TT.find("windows") != std::string::npos) {
459 TargetType = isWindows;
Chris Lattner7ad92d82008-01-02 19:44:55 +0000460 }
Mon P Wang9feb5dd2009-02-28 00:25:30 +0000461 else if (TT.find("-cl") != std::string::npos) {
462 TargetType = isDarwin;
463 DarwinVers = 9;
464 }
Nate Begemanfb5792f2005-07-12 01:41:54 +0000465 } else if (TT.empty()) {
Anton Korobeynikov317848f2007-01-03 11:43:14 +0000466#if defined(__CYGWIN__)
Chris Lattnere5600e52005-11-21 22:31:58 +0000467 TargetType = isCygwin;
Anton Korobeynikov2b4f7802008-03-22 21:18:22 +0000468#elif defined(__MINGW32__) || defined(__MINGW64__)
Anton Korobeynikov317848f2007-01-03 11:43:14 +0000469 TargetType = isMingw;
Nate Begemanfb5792f2005-07-12 01:41:54 +0000470#elif defined(__APPLE__)
Chris Lattnere5600e52005-11-21 22:31:58 +0000471 TargetType = isDarwin;
Chris Lattner7ad92d82008-01-02 19:44:55 +0000472#if __APPLE_CC__ > 5400
473 DarwinVers = 9; // GCC 5400+ is Leopard.
474#else
475 DarwinVers = 8; // Minimum supported darwin is Tiger.
476#endif
477
Anton Korobeynikov2b4f7802008-03-22 21:18:22 +0000478#elif defined(_WIN32) || defined(_WIN64)
Chris Lattnere5600e52005-11-21 22:31:58 +0000479 TargetType = isWindows;
Dan Gohmana779a982008-05-05 00:28:39 +0000480#elif defined(__linux__)
481 // Linux doesn't imply ELF, but we don't currently support anything else.
Dan Gohman600bf162008-05-05 16:11:31 +0000482 TargetType = isELF;
483 IsLinux = true;
Nate Begemanfb5792f2005-07-12 01:41:54 +0000484#endif
485 }
486
Chris Lattnercdb341d2006-09-07 22:29:41 +0000487 // If the asm syntax hasn't been overridden on the command line, use whatever
488 // the target wants.
Anton Korobeynikov7f705592007-01-12 19:20:47 +0000489 if (AsmFlavor == X86Subtarget::Unset) {
Chris Lattner7ad92d82008-01-02 19:44:55 +0000490 AsmFlavor = (TargetType == isWindows)
491 ? X86Subtarget::Intel : X86Subtarget::ATT;
Chris Lattnercdb341d2006-09-07 22:29:41 +0000492 }
493
Anton Korobeynikov890fe882008-04-23 18:16:16 +0000494 // Stack alignment is 16 bytes on Darwin (both 32 and 64 bit) and for all 64
495 // bit targets.
496 if (TargetType == isDarwin || Is64Bit)
Nate Begemanfb5792f2005-07-12 01:41:54 +0000497 stackAlignment = 16;
Anton Korobeynikov78c80fd2008-04-12 22:12:22 +0000498
499 if (StackAlignment)
500 stackAlignment = StackAlignment;
Nate Begemanfb5792f2005-07-12 01:41:54 +0000501}