Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1 | //===-- X86Subtarget.cpp - X86 Subtarget Information ------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 081ce94 | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the X86 specific subclass of TargetSubtarget. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Evan Cheng | 5211b42 | 2009-01-03 04:04:46 +0000 | [diff] [blame] | 14 | #define DEBUG_TYPE "subtarget" |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 15 | #include "X86Subtarget.h" |
| 16 | #include "X86GenSubtarget.inc" |
| 17 | #include "llvm/Module.h" |
| 18 | #include "llvm/Support/CommandLine.h" |
Evan Cheng | 5211b42 | 2009-01-03 04:04:46 +0000 | [diff] [blame] | 19 | #include "llvm/Support/Debug.h" |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 20 | #include "llvm/Target/TargetMachine.h" |
Anton Korobeynikov | b214a52 | 2008-04-23 18:18:10 +0000 | [diff] [blame] | 21 | #include "llvm/Target/TargetOptions.h" |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 22 | using namespace llvm; |
| 23 | |
Dan Gohman | 089efff | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 24 | static cl::opt<X86Subtarget::AsmWriterFlavorTy> |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 25 | AsmWriterFlavor("x86-asm-syntax", cl::init(X86Subtarget::Unset), |
| 26 | cl::desc("Choose style of code to emit from X86 backend:"), |
| 27 | cl::values( |
Dan Gohman | 669b9bf | 2008-10-14 20:25:08 +0000 | [diff] [blame] | 28 | clEnumValN(X86Subtarget::ATT, "att", "Emit AT&T-style assembly"), |
| 29 | clEnumValN(X86Subtarget::Intel, "intel", "Emit Intel-style assembly"), |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 30 | clEnumValEnd)); |
| 31 | |
| 32 | |
| 33 | /// True if accessing the GV requires an extra load. For Windows, dllimported |
| 34 | /// symbols are indirect, loading the value at address GV rather then the |
| 35 | /// value of GV itself. This means that the GlobalAddress must be in the base |
| 36 | /// or index register of the address, not the GV offset field. |
| 37 | bool X86Subtarget::GVRequiresExtraLoad(const GlobalValue* GV, |
| 38 | const TargetMachine& TM, |
| 39 | bool isDirectCall) const |
| 40 | { |
| 41 | // FIXME: PIC |
Evan Cheng | 1f28220 | 2008-07-16 01:34:02 +0000 | [diff] [blame] | 42 | if (TM.getRelocationModel() != Reloc::Static && |
| 43 | TM.getCodeModel() != CodeModel::Large) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 44 | if (isTargetDarwin()) { |
Evan Cheng | 17cc795 | 2008-12-08 19:29:03 +0000 | [diff] [blame] | 45 | if (isDirectCall) |
| 46 | return false; |
Evan Cheng | a65854f | 2008-12-05 01:06:39 +0000 | [diff] [blame] | 47 | bool isDecl = GV->isDeclaration() && !GV->hasNotBeenReadFromBitcode(); |
| 48 | if (GV->hasHiddenVisibility() && |
| 49 | (Is64Bit || (!isDecl && !GV->hasCommonLinkage()))) |
| 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 | return false; |
Dan Gohman | 653cc45 | 2008-12-08 17:38:02 +0000 | [diff] [blame] | 54 | return !isDirectCall && (isDecl || GV->mayBeOverridden()); |
Anton Korobeynikov | 6835eb6 | 2008-01-20 13:58:16 +0000 | [diff] [blame] | 55 | } else if (isTargetELF()) { |
Rafael Espindola | ae289c1 | 2008-06-02 07:52:43 +0000 | [diff] [blame] | 56 | // Extra load is needed for all externally visible. |
| 57 | if (isDirectCall) |
| 58 | return false; |
Rafael Espindola | a168fc9 | 2009-01-15 20:18:42 +0000 | [diff] [blame] | 59 | if (GV->hasLocalLinkage() || GV->hasHiddenVisibility()) |
Rafael Espindola | ae289c1 | 2008-06-02 07:52:43 +0000 | [diff] [blame] | 60 | return false; |
| 61 | return true; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 62 | } else if (isTargetCygMing() || isTargetWindows()) { |
| 63 | return (GV->hasDLLImportLinkage()); |
| 64 | } |
Anton Korobeynikov | 8c90d2a | 2008-02-20 11:22:39 +0000 | [diff] [blame] | 65 | } |
Dale Johannesen | 64660e9 | 2008-12-05 21:47:27 +0000 | [diff] [blame] | 66 | return false; |
| 67 | } |
| 68 | |
| 69 | /// True if accessing the GV requires a register. This is a superset of the |
| 70 | /// cases where GVRequiresExtraLoad is true. Some variations of PIC require |
| 71 | /// a register, but not an extra load. |
| 72 | bool X86Subtarget::GVRequiresRegister(const GlobalValue *GV, |
| 73 | const TargetMachine& TM, |
| 74 | bool isDirectCall) const |
| 75 | { |
| 76 | if (GVRequiresExtraLoad(GV, TM, isDirectCall)) |
| 77 | return true; |
| 78 | // Code below here need only consider cases where GVRequiresExtraLoad |
| 79 | // returns false. |
| 80 | if (TM.getRelocationModel() == Reloc::PIC_) |
| 81 | return !isDirectCall && |
Rafael Espindola | a168fc9 | 2009-01-15 20:18:42 +0000 | [diff] [blame] | 82 | (GV->hasLocalLinkage() || GV->hasExternalLinkage()); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 83 | return false; |
| 84 | } |
| 85 | |
Bill Wendling | 5db7ffb | 2008-09-30 21:22:07 +0000 | [diff] [blame] | 86 | /// getBZeroEntry - This function returns the name of a function which has an |
| 87 | /// interface like the non-standard bzero function, if such a function exists on |
| 88 | /// the current subtarget and it is considered prefereable over memset with zero |
| 89 | /// passed as the second argument. Otherwise it returns null. |
Bill Wendling | d375203 | 2008-09-30 22:05:33 +0000 | [diff] [blame] | 90 | const char *X86Subtarget::getBZeroEntry() const { |
Dan Gohman | f95c2bf | 2008-04-01 20:38:36 +0000 | [diff] [blame] | 91 | // Darwin 10 has a __bzero entry point for this purpose. |
| 92 | if (getDarwinVers() >= 10) |
Bill Wendling | d375203 | 2008-09-30 22:05:33 +0000 | [diff] [blame] | 93 | return "__bzero"; |
Dan Gohman | f95c2bf | 2008-04-01 20:38:36 +0000 | [diff] [blame] | 94 | |
| 95 | return 0; |
| 96 | } |
| 97 | |
Dan Gohman | 4717099 | 2008-12-16 03:35:01 +0000 | [diff] [blame] | 98 | /// getSpecialAddressLatency - For targets where it is beneficial to |
| 99 | /// backschedule instructions that compute addresses, return a value |
| 100 | /// indicating the number of scheduling cycles of backscheduling that |
| 101 | /// should be attempted. |
| 102 | unsigned X86Subtarget::getSpecialAddressLatency() const { |
| 103 | // For x86 out-of-order targets, back-schedule address computations so |
| 104 | // that loads and stores aren't blocked. |
| 105 | // This value was chosen arbitrarily. |
| 106 | return 200; |
| 107 | } |
| 108 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 109 | /// GetCpuIDAndInfo - Execute the specified cpuid and return the 4 values in the |
| 110 | /// specified arguments. If we can't run cpuid on the host, return true. |
| 111 | bool X86::GetCpuIDAndInfo(unsigned value, unsigned *rEAX, unsigned *rEBX, |
| 112 | unsigned *rECX, unsigned *rEDX) { |
| 113 | #if defined(__x86_64__) |
| 114 | // gcc doesn't know cpuid would clobber ebx/rbx. Preseve it manually. |
| 115 | asm ("movq\t%%rbx, %%rsi\n\t" |
| 116 | "cpuid\n\t" |
| 117 | "xchgq\t%%rbx, %%rsi\n\t" |
| 118 | : "=a" (*rEAX), |
| 119 | "=S" (*rEBX), |
| 120 | "=c" (*rECX), |
| 121 | "=d" (*rEDX) |
| 122 | : "a" (value)); |
| 123 | return false; |
| 124 | #elif defined(i386) || defined(__i386__) || defined(__x86__) || defined(_M_IX86) |
| 125 | #if defined(__GNUC__) |
| 126 | asm ("movl\t%%ebx, %%esi\n\t" |
| 127 | "cpuid\n\t" |
| 128 | "xchgl\t%%ebx, %%esi\n\t" |
| 129 | : "=a" (*rEAX), |
| 130 | "=S" (*rEBX), |
| 131 | "=c" (*rECX), |
| 132 | "=d" (*rEDX) |
| 133 | : "a" (value)); |
| 134 | return false; |
| 135 | #elif defined(_MSC_VER) |
| 136 | __asm { |
| 137 | mov eax,value |
| 138 | cpuid |
| 139 | mov esi,rEAX |
| 140 | mov dword ptr [esi],eax |
| 141 | mov esi,rEBX |
| 142 | mov dword ptr [esi],ebx |
| 143 | mov esi,rECX |
| 144 | mov dword ptr [esi],ecx |
| 145 | mov esi,rEDX |
| 146 | mov dword ptr [esi],edx |
| 147 | } |
| 148 | return false; |
| 149 | #endif |
| 150 | #endif |
| 151 | return true; |
| 152 | } |
| 153 | |
Evan Cheng | 95a77fd | 2009-01-02 05:35:45 +0000 | [diff] [blame] | 154 | static void DetectFamilyModel(unsigned EAX, unsigned &Family, unsigned &Model) { |
| 155 | Family = (EAX >> 8) & 0xf; // Bits 8 - 11 |
| 156 | Model = (EAX >> 4) & 0xf; // Bits 4 - 7 |
| 157 | if (Family == 6 || Family == 0xf) { |
| 158 | if (Family == 0xf) |
| 159 | // Examine extended family ID if family ID is F. |
| 160 | Family += (EAX >> 20) & 0xff; // Bits 20 - 27 |
| 161 | // Examine extended model ID if family ID is 6 or F. |
| 162 | Model += ((EAX >> 16) & 0xf) << 4; // Bits 16 - 19 |
| 163 | } |
| 164 | } |
| 165 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 166 | void X86Subtarget::AutoDetectSubtargetFeatures() { |
| 167 | unsigned EAX = 0, EBX = 0, ECX = 0, EDX = 0; |
| 168 | union { |
| 169 | unsigned u[3]; |
| 170 | char c[12]; |
| 171 | } text; |
| 172 | |
| 173 | if (X86::GetCpuIDAndInfo(0, &EAX, text.u+0, text.u+2, text.u+1)) |
| 174 | return; |
| 175 | |
| 176 | X86::GetCpuIDAndInfo(0x1, &EAX, &EBX, &ECX, &EDX); |
| 177 | |
| 178 | if ((EDX >> 23) & 0x1) X86SSELevel = MMX; |
| 179 | if ((EDX >> 25) & 0x1) X86SSELevel = SSE1; |
| 180 | if ((EDX >> 26) & 0x1) X86SSELevel = SSE2; |
| 181 | if (ECX & 0x1) X86SSELevel = SSE3; |
| 182 | if ((ECX >> 9) & 0x1) X86SSELevel = SSSE3; |
Nate Begeman | b297556 | 2008-02-03 07:18:54 +0000 | [diff] [blame] | 183 | if ((ECX >> 19) & 0x1) X86SSELevel = SSE41; |
| 184 | if ((ECX >> 20) & 0x1) X86SSELevel = SSE42; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 185 | |
Evan Cheng | 95a77fd | 2009-01-02 05:35:45 +0000 | [diff] [blame] | 186 | bool IsIntel = memcmp(text.c, "GenuineIntel", 12) == 0; |
| 187 | bool IsAMD = !IsIntel && memcmp(text.c, "AuthenticAMD", 12) == 0; |
| 188 | if (IsIntel || IsAMD) { |
| 189 | // Determine if bit test memory instructions are slow. |
| 190 | unsigned Family = 0; |
| 191 | unsigned Model = 0; |
| 192 | DetectFamilyModel(EAX, Family, Model); |
| 193 | IsBTMemSlow = IsAMD || (Family == 6 && Model >= 13); |
| 194 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 195 | X86::GetCpuIDAndInfo(0x80000001, &EAX, &EBX, &ECX, &EDX); |
| 196 | HasX86_64 = (EDX >> 29) & 0x1; |
| 197 | } |
| 198 | } |
| 199 | |
| 200 | static const char *GetCurrentX86CPU() { |
| 201 | unsigned EAX = 0, EBX = 0, ECX = 0, EDX = 0; |
| 202 | if (X86::GetCpuIDAndInfo(0x1, &EAX, &EBX, &ECX, &EDX)) |
| 203 | return "generic"; |
Evan Cheng | 95a77fd | 2009-01-02 05:35:45 +0000 | [diff] [blame] | 204 | unsigned Family = 0; |
| 205 | unsigned Model = 0; |
| 206 | DetectFamilyModel(EAX, Family, Model); |
Evan Cheng | edde684 | 2009-01-02 05:29:20 +0000 | [diff] [blame] | 207 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 208 | X86::GetCpuIDAndInfo(0x80000001, &EAX, &EBX, &ECX, &EDX); |
| 209 | bool Em64T = (EDX >> 29) & 0x1; |
| 210 | |
| 211 | union { |
| 212 | unsigned u[3]; |
| 213 | char c[12]; |
| 214 | } text; |
| 215 | |
| 216 | X86::GetCpuIDAndInfo(0, &EAX, text.u+0, text.u+2, text.u+1); |
| 217 | if (memcmp(text.c, "GenuineIntel", 12) == 0) { |
| 218 | switch (Family) { |
| 219 | case 3: |
| 220 | return "i386"; |
| 221 | case 4: |
| 222 | return "i486"; |
| 223 | case 5: |
| 224 | switch (Model) { |
| 225 | case 4: return "pentium-mmx"; |
| 226 | default: return "pentium"; |
| 227 | } |
| 228 | case 6: |
| 229 | switch (Model) { |
| 230 | case 1: return "pentiumpro"; |
| 231 | case 3: |
| 232 | case 5: |
| 233 | case 6: return "pentium2"; |
| 234 | case 7: |
| 235 | case 8: |
| 236 | case 10: |
| 237 | case 11: return "pentium3"; |
| 238 | case 9: |
| 239 | case 13: return "pentium-m"; |
| 240 | case 14: return "yonah"; |
Evan Cheng | 5211b42 | 2009-01-03 04:04:46 +0000 | [diff] [blame] | 241 | case 15: |
| 242 | case 22: // Celeron M 540 |
| 243 | return "core2"; |
| 244 | case 23: // 45nm: Penryn , Wolfdale, Yorkfield (XE) |
| 245 | return "penryn"; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 246 | default: return "i686"; |
| 247 | } |
| 248 | case 15: { |
| 249 | switch (Model) { |
| 250 | case 3: |
| 251 | case 4: |
Evan Cheng | 5211b42 | 2009-01-03 04:04:46 +0000 | [diff] [blame] | 252 | case 6: // same as 4, but 65nm |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 253 | return (Em64T) ? "nocona" : "prescott"; |
Evan Cheng | cfadd3b | 2009-01-05 08:45:01 +0000 | [diff] [blame] | 254 | case 26: |
| 255 | return "corei7"; |
Evan Cheng | 5211b42 | 2009-01-03 04:04:46 +0000 | [diff] [blame] | 256 | case 28: |
Evan Cheng | cfadd3b | 2009-01-05 08:45:01 +0000 | [diff] [blame] | 257 | return "atom"; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 258 | default: |
| 259 | return (Em64T) ? "x86-64" : "pentium4"; |
| 260 | } |
| 261 | } |
| 262 | |
| 263 | default: |
| 264 | return "generic"; |
| 265 | } |
| 266 | } else if (memcmp(text.c, "AuthenticAMD", 12) == 0) { |
| 267 | // FIXME: this poorly matches the generated SubtargetFeatureKV table. There |
| 268 | // appears to be no way to generate the wide variety of AMD-specific targets |
| 269 | // from the information returned from CPUID. |
| 270 | switch (Family) { |
| 271 | case 4: |
| 272 | return "i486"; |
| 273 | case 5: |
| 274 | switch (Model) { |
| 275 | case 6: |
| 276 | case 7: return "k6"; |
| 277 | case 8: return "k6-2"; |
| 278 | case 9: |
| 279 | case 13: return "k6-3"; |
| 280 | default: return "pentium"; |
| 281 | } |
| 282 | case 6: |
| 283 | switch (Model) { |
| 284 | case 4: return "athlon-tbird"; |
| 285 | case 6: |
| 286 | case 7: |
| 287 | case 8: return "athlon-mp"; |
| 288 | case 10: return "athlon-xp"; |
| 289 | default: return "athlon"; |
| 290 | } |
| 291 | case 15: |
| 292 | switch (Model) { |
| 293 | case 1: return "opteron"; |
| 294 | case 5: return "athlon-fx"; // also opteron |
| 295 | default: return "athlon64"; |
| 296 | } |
| 297 | default: |
| 298 | return "generic"; |
| 299 | } |
| 300 | } else { |
| 301 | return "generic"; |
| 302 | } |
| 303 | } |
| 304 | |
| 305 | X86Subtarget::X86Subtarget(const Module &M, const std::string &FS, bool is64Bit) |
| 306 | : AsmFlavor(AsmWriterFlavor) |
Duncan Sands | de5f95f | 2008-11-28 09:29:37 +0000 | [diff] [blame] | 307 | , PICStyle(PICStyles::None) |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 308 | , X86SSELevel(NoMMXSSE) |
Evan Cheng | b6992de | 2008-04-16 19:03:02 +0000 | [diff] [blame] | 309 | , X863DNowLevel(NoThreeDNow) |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 310 | , HasX86_64(false) |
Evan Cheng | 95a77fd | 2009-01-02 05:35:45 +0000 | [diff] [blame] | 311 | , IsBTMemSlow(false) |
Chris Lattner | 93a2d43 | 2008-01-02 19:44:55 +0000 | [diff] [blame] | 312 | , DarwinVers(0) |
Dan Gohman | de22f24 | 2008-05-05 18:43:07 +0000 | [diff] [blame] | 313 | , IsLinux(false) |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 314 | , stackAlignment(8) |
| 315 | // FIXME: this is a known good value for Yonah. How about others? |
Rafael Espindola | 7afa9b1 | 2007-10-31 11:52:06 +0000 | [diff] [blame] | 316 | , MaxInlineSizeThreshold(128) |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 317 | , Is64Bit(is64Bit) |
| 318 | , TargetType(isELF) { // Default to ELF unless otherwise specified. |
Mon P Wang | 078a62d | 2008-05-05 19:05:59 +0000 | [diff] [blame] | 319 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 320 | // Determine default and user specified characteristics |
| 321 | if (!FS.empty()) { |
| 322 | // If feature string is not empty, parse features string. |
| 323 | std::string CPU = GetCurrentX86CPU(); |
| 324 | ParseSubtargetFeatures(FS, CPU); |
Edwin Török | 4031b79 | 2009-02-02 21:57:34 +0000 | [diff] [blame] | 325 | // All X86-64 CPUs also have SSE2, however user might request no SSE via |
| 326 | // -mattr, so don't force SSELevel here. |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 327 | } else { |
| 328 | // Otherwise, use CPUID to auto-detect feature set. |
| 329 | AutoDetectSubtargetFeatures(); |
Dan Gohman | 4092bbc | 2009-02-03 00:04:43 +0000 | [diff] [blame] | 330 | // If requesting codegen for X86-64, make sure that 64-bit features |
| 331 | // are enabled. |
| 332 | if (Is64Bit) |
Edwin Török | 4031b79 | 2009-02-02 21:57:34 +0000 | [diff] [blame] | 333 | HasX86_64 = true; |
Dan Gohman | 4092bbc | 2009-02-03 00:04:43 +0000 | [diff] [blame] | 334 | // Make sure SSE2 is enabled; it is available on all X86-64 CPUs. |
| 335 | if (Is64Bit && X86SSELevel < SSE2) |
| 336 | X86SSELevel = SSE2; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 337 | } |
Dan Gohman | 4092bbc | 2009-02-03 00:04:43 +0000 | [diff] [blame] | 338 | |
Evan Cheng | 5211b42 | 2009-01-03 04:04:46 +0000 | [diff] [blame] | 339 | DOUT << "Subtarget features: SSELevel " << X86SSELevel |
| 340 | << ", 3DNowLevel " << X863DNowLevel |
| 341 | << ", 64bit " << HasX86_64 << "\n"; |
Dan Gohman | 4092bbc | 2009-02-03 00:04:43 +0000 | [diff] [blame] | 342 | assert((!Is64Bit || HasX86_64) && |
| 343 | "64-bit code requested on a subtarget that doesn't support it!"); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 344 | |
| 345 | // Set the boolean corresponding to the current target triple, or the default |
| 346 | // if one cannot be determined, to true. |
| 347 | const std::string& TT = M.getTargetTriple(); |
| 348 | if (TT.length() > 5) { |
Duncan Sands | dfd9458 | 2008-01-08 10:06:15 +0000 | [diff] [blame] | 349 | size_t Pos; |
Chris Lattner | 93a2d43 | 2008-01-02 19:44:55 +0000 | [diff] [blame] | 350 | if ((Pos = TT.find("-darwin")) != std::string::npos) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 351 | TargetType = isDarwin; |
Chris Lattner | 93a2d43 | 2008-01-02 19:44:55 +0000 | [diff] [blame] | 352 | |
| 353 | // Compute the darwin version number. |
| 354 | if (isdigit(TT[Pos+7])) |
| 355 | DarwinVers = atoi(&TT[Pos+7]); |
| 356 | else |
| 357 | DarwinVers = 8; // Minimum supported darwin is Tiger. |
Dan Gohman | a65530a | 2008-05-05 00:28:39 +0000 | [diff] [blame] | 358 | } else if (TT.find("linux") != std::string::npos) { |
Dan Gohman | 2593e2b | 2008-05-05 16:11:31 +0000 | [diff] [blame] | 359 | // Linux doesn't imply ELF, but we don't currently support anything else. |
| 360 | TargetType = isELF; |
| 361 | IsLinux = true; |
Chris Lattner | 93a2d43 | 2008-01-02 19:44:55 +0000 | [diff] [blame] | 362 | } else if (TT.find("cygwin") != std::string::npos) { |
| 363 | TargetType = isCygwin; |
| 364 | } else if (TT.find("mingw") != std::string::npos) { |
| 365 | TargetType = isMingw; |
| 366 | } else if (TT.find("win32") != std::string::npos) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 367 | TargetType = isWindows; |
Anton Korobeynikov | f0ce64b | 2008-03-22 21:12:53 +0000 | [diff] [blame] | 368 | } else if (TT.find("windows") != std::string::npos) { |
| 369 | TargetType = isWindows; |
Chris Lattner | 93a2d43 | 2008-01-02 19:44:55 +0000 | [diff] [blame] | 370 | } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 371 | } else if (TT.empty()) { |
| 372 | #if defined(__CYGWIN__) |
| 373 | TargetType = isCygwin; |
Anton Korobeynikov | 62a51e4 | 2008-03-22 21:18:22 +0000 | [diff] [blame] | 374 | #elif defined(__MINGW32__) || defined(__MINGW64__) |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 375 | TargetType = isMingw; |
| 376 | #elif defined(__APPLE__) |
| 377 | TargetType = isDarwin; |
Chris Lattner | 93a2d43 | 2008-01-02 19:44:55 +0000 | [diff] [blame] | 378 | #if __APPLE_CC__ > 5400 |
| 379 | DarwinVers = 9; // GCC 5400+ is Leopard. |
| 380 | #else |
| 381 | DarwinVers = 8; // Minimum supported darwin is Tiger. |
| 382 | #endif |
| 383 | |
Anton Korobeynikov | 62a51e4 | 2008-03-22 21:18:22 +0000 | [diff] [blame] | 384 | #elif defined(_WIN32) || defined(_WIN64) |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 385 | TargetType = isWindows; |
Dan Gohman | a65530a | 2008-05-05 00:28:39 +0000 | [diff] [blame] | 386 | #elif defined(__linux__) |
| 387 | // Linux doesn't imply ELF, but we don't currently support anything else. |
Dan Gohman | 2593e2b | 2008-05-05 16:11:31 +0000 | [diff] [blame] | 388 | TargetType = isELF; |
| 389 | IsLinux = true; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 390 | #endif |
| 391 | } |
| 392 | |
| 393 | // If the asm syntax hasn't been overridden on the command line, use whatever |
| 394 | // the target wants. |
| 395 | if (AsmFlavor == X86Subtarget::Unset) { |
Chris Lattner | 93a2d43 | 2008-01-02 19:44:55 +0000 | [diff] [blame] | 396 | AsmFlavor = (TargetType == isWindows) |
| 397 | ? X86Subtarget::Intel : X86Subtarget::ATT; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 398 | } |
| 399 | |
Anton Korobeynikov | cdd9381 | 2008-04-23 18:16:16 +0000 | [diff] [blame] | 400 | // Stack alignment is 16 bytes on Darwin (both 32 and 64 bit) and for all 64 |
| 401 | // bit targets. |
| 402 | if (TargetType == isDarwin || Is64Bit) |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 403 | stackAlignment = 16; |
Anton Korobeynikov | 06c4240 | 2008-04-12 22:12:22 +0000 | [diff] [blame] | 404 | |
| 405 | if (StackAlignment) |
| 406 | stackAlignment = StackAlignment; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 407 | } |