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