Nate Begeman | 8c00f8c | 2005-08-04 07:12:09 +0000 | [diff] [blame] | 1 | //===-- X86Subtarget.cpp - X86 Subtarget Information ------------*- C++ -*-===// |
Nate Begeman | fb5792f | 2005-07-12 01:41:54 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 4ee451d | 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. |
Nate Begeman | fb5792f | 2005-07-12 01:41:54 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the X86 specific subclass of TargetSubtarget. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Evan Cheng | 5b925c0 | 2009-01-03 04:04:46 +0000 | [diff] [blame] | 14 | #define DEBUG_TYPE "subtarget" |
Nate Begeman | fb5792f | 2005-07-12 01:41:54 +0000 | [diff] [blame] | 15 | #include "X86Subtarget.h" |
Chris Lattner | d392bd9 | 2009-07-10 07:20:05 +0000 | [diff] [blame] | 16 | #include "X86InstrInfo.h" |
Evan Cheng | a26eb5e | 2006-10-06 09:17:41 +0000 | [diff] [blame] | 17 | #include "X86GenSubtarget.inc" |
Daniel Dunbar | 3be0340 | 2009-08-02 22:11:08 +0000 | [diff] [blame] | 18 | #include "llvm/GlobalValue.h" |
Evan Cheng | 5b925c0 | 2009-01-03 04:04:46 +0000 | [diff] [blame] | 19 | #include "llvm/Support/Debug.h" |
Bill Wendling | 0ea8bf3 | 2009-08-03 00:11:34 +0000 | [diff] [blame] | 20 | #include "llvm/Support/raw_ostream.h" |
Daniel Dunbar | 067d024 | 2009-11-14 10:09:12 +0000 | [diff] [blame] | 21 | #include "llvm/System/Host.h" |
Anton Korobeynikov | 2b2bc68 | 2006-12-22 22:29:05 +0000 | [diff] [blame] | 22 | #include "llvm/Target/TargetMachine.h" |
Anton Korobeynikov | 45709ae | 2008-04-23 18:18:10 +0000 | [diff] [blame] | 23 | #include "llvm/Target/TargetOptions.h" |
David Goodwin | c2e8a7e | 2009-11-10 00:48:55 +0000 | [diff] [blame] | 24 | #include "llvm/ADT/SmallVector.h" |
Nate Begeman | fb5792f | 2005-07-12 01:41:54 +0000 | [diff] [blame] | 25 | using namespace llvm; |
| 26 | |
Chris Lattner | bc58322 | 2009-04-25 18:27:23 +0000 | [diff] [blame] | 27 | #if defined(_MSC_VER) |
Bill Wendling | 0ea8bf3 | 2009-08-03 00:11:34 +0000 | [diff] [blame] | 28 | #include <intrin.h> |
Chris Lattner | bc58322 | 2009-04-25 18:27:23 +0000 | [diff] [blame] | 29 | #endif |
| 30 | |
Dan Gohman | 29cbade | 2009-11-20 23:18:13 +0000 | [diff] [blame] | 31 | /// ClassifyBlockAddressReference - Classify a blockaddress reference for the |
| 32 | /// current subtarget according to how we should reference it in a non-pcrel |
| 33 | /// context. |
| 34 | unsigned char X86Subtarget:: |
| 35 | ClassifyBlockAddressReference() const { |
| 36 | if (isPICStyleGOT()) // 32-bit ELF targets. |
| 37 | return X86II::MO_GOTOFF; |
| 38 | |
| 39 | if (isPICStyleStubPIC()) // Darwin/32 in PIC mode. |
| 40 | return X86II::MO_PIC_BASE_OFFSET; |
| 41 | |
| 42 | // Direct static reference to label. |
| 43 | return X86II::MO_NO_FLAG; |
| 44 | } |
| 45 | |
Chris Lattner | d392bd9 | 2009-07-10 07:20:05 +0000 | [diff] [blame] | 46 | /// ClassifyGlobalReference - Classify a global variable reference for the |
| 47 | /// current subtarget according to how we should reference it in a non-pcrel |
| 48 | /// context. |
| 49 | unsigned char X86Subtarget:: |
| 50 | ClassifyGlobalReference(const GlobalValue *GV, const TargetMachine &TM) const { |
| 51 | // DLLImport only exists on windows, it is implemented as a load from a |
| 52 | // DLLIMPORT stub. |
| 53 | if (GV->hasDLLImportLinkage()) |
| 54 | return X86II::MO_DLLIMPORT; |
| 55 | |
Evan Cheng | a82b22c | 2009-07-16 22:53:10 +0000 | [diff] [blame] | 56 | // GV with ghost linkage (in JIT lazy compilation mode) do not require an |
| 57 | // extra load from stub. |
| 58 | bool isDecl = GV->isDeclaration() && !GV->hasNotBeenReadFromBitcode(); |
| 59 | |
Chris Lattner | d392bd9 | 2009-07-10 07:20:05 +0000 | [diff] [blame] | 60 | // X86-64 in PIC mode. |
| 61 | if (isPICStyleRIPRel()) { |
| 62 | // Large model never uses stubs. |
| 63 | if (TM.getCodeModel() == CodeModel::Large) |
| 64 | return X86II::MO_NO_FLAG; |
| 65 | |
Chris Lattner | c782232 | 2009-07-10 21:01:59 +0000 | [diff] [blame] | 66 | if (isTargetDarwin()) { |
| 67 | // If symbol visibility is hidden, the extra load is not needed if |
| 68 | // target is x86-64 or the symbol is definitely defined in the current |
| 69 | // translation unit. |
| 70 | if (GV->hasDefaultVisibility() && |
Evan Cheng | a82b22c | 2009-07-16 22:53:10 +0000 | [diff] [blame] | 71 | (isDecl || GV->isWeakForLinker())) |
Chris Lattner | c782232 | 2009-07-10 21:01:59 +0000 | [diff] [blame] | 72 | return X86II::MO_GOTPCREL; |
| 73 | } else { |
| 74 | assert(isTargetELF() && "Unknown rip-relative target"); |
Chris Lattner | d392bd9 | 2009-07-10 07:20:05 +0000 | [diff] [blame] | 75 | |
Chris Lattner | c782232 | 2009-07-10 21:01:59 +0000 | [diff] [blame] | 76 | // Extra load is needed for all externally visible. |
| 77 | if (!GV->hasLocalLinkage() && GV->hasDefaultVisibility()) |
| 78 | return X86II::MO_GOTPCREL; |
| 79 | } |
Chris Lattner | d392bd9 | 2009-07-10 07:20:05 +0000 | [diff] [blame] | 80 | |
| 81 | return X86II::MO_NO_FLAG; |
| 82 | } |
| 83 | |
| 84 | if (isPICStyleGOT()) { // 32-bit ELF targets. |
| 85 | // Extra load is needed for all externally visible. |
| 86 | if (GV->hasLocalLinkage() || GV->hasHiddenVisibility()) |
| 87 | return X86II::MO_GOTOFF; |
| 88 | return X86II::MO_GOT; |
| 89 | } |
| 90 | |
Chris Lattner | e2c9208 | 2009-07-10 21:00:45 +0000 | [diff] [blame] | 91 | if (isPICStyleStubPIC()) { // Darwin/32 in PIC mode. |
Chris Lattner | 84853a1 | 2009-07-10 20:53:38 +0000 | [diff] [blame] | 92 | // Determine whether we have a stub reference and/or whether the reference |
| 93 | // is relative to the PIC base or not. |
Chris Lattner | d392bd9 | 2009-07-10 07:20:05 +0000 | [diff] [blame] | 94 | |
| 95 | // If this is a strong reference to a definition, it is definitely not |
| 96 | // through a stub. |
Evan Cheng | a82b22c | 2009-07-16 22:53:10 +0000 | [diff] [blame] | 97 | if (!isDecl && !GV->isWeakForLinker()) |
Chris Lattner | 84853a1 | 2009-07-10 20:53:38 +0000 | [diff] [blame] | 98 | return X86II::MO_PIC_BASE_OFFSET; |
Chris Lattner | d392bd9 | 2009-07-10 07:20:05 +0000 | [diff] [blame] | 99 | |
| 100 | // Unless we have a symbol with hidden visibility, we have to go through a |
| 101 | // normal $non_lazy_ptr stub because this symbol might be resolved late. |
Chris Lattner | 84853a1 | 2009-07-10 20:53:38 +0000 | [diff] [blame] | 102 | if (!GV->hasHiddenVisibility()) // Non-hidden $non_lazy_ptr reference. |
| 103 | return X86II::MO_DARWIN_NONLAZY_PIC_BASE; |
Chris Lattner | d392bd9 | 2009-07-10 07:20:05 +0000 | [diff] [blame] | 104 | |
| 105 | // If symbol visibility is hidden, we have a stub for common symbol |
| 106 | // references and external declarations. |
Evan Cheng | a82b22c | 2009-07-16 22:53:10 +0000 | [diff] [blame] | 107 | if (isDecl || GV->hasCommonLinkage()) { |
Chris Lattner | d392bd9 | 2009-07-10 07:20:05 +0000 | [diff] [blame] | 108 | // Hidden $non_lazy_ptr reference. |
Chris Lattner | 84853a1 | 2009-07-10 20:53:38 +0000 | [diff] [blame] | 109 | return X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE; |
Chris Lattner | d392bd9 | 2009-07-10 07:20:05 +0000 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | // Otherwise, no stub. |
Chris Lattner | 84853a1 | 2009-07-10 20:53:38 +0000 | [diff] [blame] | 113 | return X86II::MO_PIC_BASE_OFFSET; |
| 114 | } |
| 115 | |
Chris Lattner | e2c9208 | 2009-07-10 21:00:45 +0000 | [diff] [blame] | 116 | if (isPICStyleStubNoDynamic()) { // Darwin/32 in -mdynamic-no-pic mode. |
Chris Lattner | 84853a1 | 2009-07-10 20:53:38 +0000 | [diff] [blame] | 117 | // Determine whether we have a stub reference. |
| 118 | |
| 119 | // If this is a strong reference to a definition, it is definitely not |
| 120 | // through a stub. |
Evan Cheng | a82b22c | 2009-07-16 22:53:10 +0000 | [diff] [blame] | 121 | if (!isDecl && !GV->isWeakForLinker()) |
Chris Lattner | 84853a1 | 2009-07-10 20:53:38 +0000 | [diff] [blame] | 122 | return X86II::MO_NO_FLAG; |
| 123 | |
| 124 | // Unless we have a symbol with hidden visibility, we have to go through a |
| 125 | // normal $non_lazy_ptr stub because this symbol might be resolved late. |
| 126 | if (!GV->hasHiddenVisibility()) // Non-hidden $non_lazy_ptr reference. |
| 127 | return X86II::MO_DARWIN_NONLAZY; |
Evan Cheng | 63476a8 | 2009-09-03 07:04:02 +0000 | [diff] [blame] | 128 | |
Chris Lattner | 84853a1 | 2009-07-10 20:53:38 +0000 | [diff] [blame] | 129 | // Otherwise, no stub. |
| 130 | return X86II::MO_NO_FLAG; |
Chris Lattner | d392bd9 | 2009-07-10 07:20:05 +0000 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | // Direct static reference to global. |
| 134 | return X86II::MO_NO_FLAG; |
| 135 | } |
| 136 | |
Anton Korobeynikov | 7784ebc | 2006-11-30 22:42:55 +0000 | [diff] [blame] | 137 | |
Bill Wendling | 6f287b2 | 2008-09-30 21:22:07 +0000 | [diff] [blame] | 138 | /// getBZeroEntry - This function returns the name of a function which has an |
| 139 | /// interface like the non-standard bzero function, if such a function exists on |
| 140 | /// the current subtarget and it is considered prefereable over memset with zero |
| 141 | /// passed as the second argument. Otherwise it returns null. |
Bill Wendling | 6e08738 | 2008-09-30 22:05:33 +0000 | [diff] [blame] | 142 | const char *X86Subtarget::getBZeroEntry() const { |
Dan Gohman | 68d599d | 2008-04-01 20:38:36 +0000 | [diff] [blame] | 143 | // Darwin 10 has a __bzero entry point for this purpose. |
| 144 | if (getDarwinVers() >= 10) |
Bill Wendling | 6e08738 | 2008-09-30 22:05:33 +0000 | [diff] [blame] | 145 | return "__bzero"; |
Dan Gohman | 68d599d | 2008-04-01 20:38:36 +0000 | [diff] [blame] | 146 | |
| 147 | return 0; |
| 148 | } |
| 149 | |
Evan Cheng | d7f666a | 2009-05-20 04:53:57 +0000 | [diff] [blame] | 150 | /// IsLegalToCallImmediateAddr - Return true if the subtarget allows calls |
| 151 | /// to immediate address. |
| 152 | bool X86Subtarget::IsLegalToCallImmediateAddr(const TargetMachine &TM) const { |
| 153 | if (Is64Bit) |
| 154 | return false; |
| 155 | return isTargetELF() || TM.getRelocationModel() == Reloc::Static; |
| 156 | } |
| 157 | |
Dan Gohman | 8749b61 | 2008-12-16 03:35:01 +0000 | [diff] [blame] | 158 | /// getSpecialAddressLatency - For targets where it is beneficial to |
| 159 | /// backschedule instructions that compute addresses, return a value |
| 160 | /// indicating the number of scheduling cycles of backscheduling that |
| 161 | /// should be attempted. |
| 162 | unsigned X86Subtarget::getSpecialAddressLatency() const { |
| 163 | // For x86 out-of-order targets, back-schedule address computations so |
| 164 | // that loads and stores aren't blocked. |
| 165 | // This value was chosen arbitrarily. |
| 166 | return 200; |
| 167 | } |
| 168 | |
Chris Lattner | 1e39a15 | 2006-01-28 06:05:41 +0000 | [diff] [blame] | 169 | /// GetCpuIDAndInfo - Execute the specified cpuid and return the 4 values in the |
| 170 | /// specified arguments. If we can't run cpuid on the host, return true. |
Daniel Dunbar | 8481138 | 2009-09-03 05:47:34 +0000 | [diff] [blame] | 171 | static bool GetCpuIDAndInfo(unsigned value, unsigned *rEAX, |
| 172 | unsigned *rEBX, unsigned *rECX, unsigned *rEDX) { |
Anton Korobeynikov | 6f9bb6f | 2009-08-28 16:06:41 +0000 | [diff] [blame] | 173 | #if defined(__x86_64__) || defined(_M_AMD64) || defined (_M_X64) |
Chris Lattner | bc58322 | 2009-04-25 18:27:23 +0000 | [diff] [blame] | 174 | #if defined(__GNUC__) |
| 175 | // gcc doesn't know cpuid would clobber ebx/rbx. Preseve it manually. |
| 176 | asm ("movq\t%%rbx, %%rsi\n\t" |
| 177 | "cpuid\n\t" |
| 178 | "xchgq\t%%rbx, %%rsi\n\t" |
| 179 | : "=a" (*rEAX), |
| 180 | "=S" (*rEBX), |
| 181 | "=c" (*rECX), |
| 182 | "=d" (*rEDX) |
| 183 | : "a" (value)); |
| 184 | return false; |
| 185 | #elif defined(_MSC_VER) |
| 186 | int registers[4]; |
| 187 | __cpuid(registers, value); |
| 188 | *rEAX = registers[0]; |
| 189 | *rEBX = registers[1]; |
| 190 | *rECX = registers[2]; |
| 191 | *rEDX = registers[3]; |
| 192 | return false; |
| 193 | #endif |
Evan Cheng | 25ab690 | 2006-09-08 06:48:29 +0000 | [diff] [blame] | 194 | #elif defined(i386) || defined(__i386__) || defined(__x86__) || defined(_M_IX86) |
Chris Lattner | bc58322 | 2009-04-25 18:27:23 +0000 | [diff] [blame] | 195 | #if defined(__GNUC__) |
| 196 | asm ("movl\t%%ebx, %%esi\n\t" |
| 197 | "cpuid\n\t" |
| 198 | "xchgl\t%%ebx, %%esi\n\t" |
| 199 | : "=a" (*rEAX), |
| 200 | "=S" (*rEBX), |
| 201 | "=c" (*rECX), |
| 202 | "=d" (*rEDX) |
| 203 | : "a" (value)); |
| 204 | return false; |
| 205 | #elif defined(_MSC_VER) |
| 206 | __asm { |
| 207 | mov eax,value |
| 208 | cpuid |
| 209 | mov esi,rEAX |
| 210 | mov dword ptr [esi],eax |
| 211 | mov esi,rEBX |
| 212 | mov dword ptr [esi],ebx |
| 213 | mov esi,rECX |
| 214 | mov dword ptr [esi],ecx |
| 215 | mov esi,rEDX |
| 216 | mov dword ptr [esi],edx |
| 217 | } |
| 218 | return false; |
| 219 | #endif |
Evan Cheng | 559806f | 2006-01-27 08:10:46 +0000 | [diff] [blame] | 220 | #endif |
Chris Lattner | 1e39a15 | 2006-01-28 06:05:41 +0000 | [diff] [blame] | 221 | return true; |
Evan Cheng | 559806f | 2006-01-27 08:10:46 +0000 | [diff] [blame] | 222 | } |
| 223 | |
Evan Cheng | ccb6976 | 2009-01-02 05:35:45 +0000 | [diff] [blame] | 224 | static void DetectFamilyModel(unsigned EAX, unsigned &Family, unsigned &Model) { |
| 225 | Family = (EAX >> 8) & 0xf; // Bits 8 - 11 |
| 226 | Model = (EAX >> 4) & 0xf; // Bits 4 - 7 |
| 227 | if (Family == 6 || Family == 0xf) { |
| 228 | if (Family == 0xf) |
| 229 | // Examine extended family ID if family ID is F. |
| 230 | Family += (EAX >> 20) & 0xff; // Bits 20 - 27 |
| 231 | // Examine extended model ID if family ID is 6 or F. |
| 232 | Model += ((EAX >> 16) & 0xf) << 4; // Bits 16 - 19 |
| 233 | } |
| 234 | } |
| 235 | |
Evan Cheng | a26eb5e | 2006-10-06 09:17:41 +0000 | [diff] [blame] | 236 | void X86Subtarget::AutoDetectSubtargetFeatures() { |
Evan Cheng | b3a7e21 | 2006-01-27 19:30:30 +0000 | [diff] [blame] | 237 | unsigned EAX = 0, EBX = 0, ECX = 0, EDX = 0; |
Jeff Cohen | a349640 | 2006-01-28 18:47:32 +0000 | [diff] [blame] | 238 | union { |
Jeff Cohen | 216d281 | 2006-01-28 19:48:34 +0000 | [diff] [blame] | 239 | unsigned u[3]; |
| 240 | char c[12]; |
Jeff Cohen | a349640 | 2006-01-28 18:47:32 +0000 | [diff] [blame] | 241 | } text; |
Chris Lattner | 3b6f497 | 2006-11-20 18:16:05 +0000 | [diff] [blame] | 242 | |
Evan Cheng | d0da6ff | 2009-09-03 04:37:05 +0000 | [diff] [blame] | 243 | if (GetCpuIDAndInfo(0, &EAX, text.u+0, text.u+2, text.u+1)) |
Evan Cheng | abc346c | 2006-10-06 08:21:07 +0000 | [diff] [blame] | 244 | return; |
Anton Korobeynikov | 3b5ee73 | 2007-03-23 23:46:48 +0000 | [diff] [blame] | 245 | |
Evan Cheng | d0da6ff | 2009-09-03 04:37:05 +0000 | [diff] [blame] | 246 | GetCpuIDAndInfo(0x1, &EAX, &EBX, &ECX, &EDX); |
Chris Lattner | 3b6f497 | 2006-11-20 18:16:05 +0000 | [diff] [blame] | 247 | |
Chris Lattner | 7008416 | 2009-09-02 05:53:04 +0000 | [diff] [blame] | 248 | if ((EDX >> 15) & 1) HasCMov = true; |
| 249 | if ((EDX >> 23) & 1) X86SSELevel = MMX; |
| 250 | if ((EDX >> 25) & 1) X86SSELevel = SSE1; |
| 251 | if ((EDX >> 26) & 1) X86SSELevel = SSE2; |
Daniel Dunbar | 8481138 | 2009-09-03 05:47:34 +0000 | [diff] [blame] | 252 | if (ECX & 0x1) X86SSELevel = SSE3; |
Chris Lattner | 7008416 | 2009-09-02 05:53:04 +0000 | [diff] [blame] | 253 | if ((ECX >> 9) & 1) X86SSELevel = SSSE3; |
| 254 | if ((ECX >> 19) & 1) X86SSELevel = SSE41; |
| 255 | if ((ECX >> 20) & 1) X86SSELevel = SSE42; |
Anton Korobeynikov | 3b5ee73 | 2007-03-23 23:46:48 +0000 | [diff] [blame] | 256 | |
Evan Cheng | ccb6976 | 2009-01-02 05:35:45 +0000 | [diff] [blame] | 257 | bool IsIntel = memcmp(text.c, "GenuineIntel", 12) == 0; |
| 258 | bool IsAMD = !IsIntel && memcmp(text.c, "AuthenticAMD", 12) == 0; |
David Greene | 343dadb | 2009-06-26 22:46:54 +0000 | [diff] [blame] | 259 | |
| 260 | HasFMA3 = IsIntel && ((ECX >> 12) & 0x1); |
| 261 | HasAVX = ((ECX >> 28) & 0x1); |
| 262 | |
Evan Cheng | ccb6976 | 2009-01-02 05:35:45 +0000 | [diff] [blame] | 263 | if (IsIntel || IsAMD) { |
| 264 | // Determine if bit test memory instructions are slow. |
| 265 | unsigned Family = 0; |
| 266 | unsigned Model = 0; |
| 267 | DetectFamilyModel(EAX, Family, Model); |
| 268 | IsBTMemSlow = IsAMD || (Family == 6 && Model >= 13); |
| 269 | |
Evan Cheng | d0da6ff | 2009-09-03 04:37:05 +0000 | [diff] [blame] | 270 | GetCpuIDAndInfo(0x80000001, &EAX, &EBX, &ECX, &EDX); |
Jeff Cohen | c398709 | 2007-04-16 21:59:44 +0000 | [diff] [blame] | 271 | HasX86_64 = (EDX >> 29) & 0x1; |
Stefanus Du Toit | 8cf5ab1 | 2009-05-26 21:04:35 +0000 | [diff] [blame] | 272 | HasSSE4A = IsAMD && ((ECX >> 6) & 0x1); |
David Greene | 343dadb | 2009-06-26 22:46:54 +0000 | [diff] [blame] | 273 | HasFMA4 = IsAMD && ((ECX >> 16) & 0x1); |
Jeff Cohen | c398709 | 2007-04-16 21:59:44 +0000 | [diff] [blame] | 274 | } |
Evan Cheng | 559806f | 2006-01-27 08:10:46 +0000 | [diff] [blame] | 275 | } |
Evan Cheng | 97c7fc3 | 2006-01-26 09:53:06 +0000 | [diff] [blame] | 276 | |
Daniel Dunbar | 3be0340 | 2009-08-02 22:11:08 +0000 | [diff] [blame] | 277 | X86Subtarget::X86Subtarget(const std::string &TT, const std::string &FS, |
| 278 | bool is64Bit) |
Chris Lattner | ce914b8 | 2009-08-11 23:01:09 +0000 | [diff] [blame] | 279 | : PICStyle(PICStyles::None) |
Evan Cheng | 25ab690 | 2006-09-08 06:48:29 +0000 | [diff] [blame] | 280 | , X86SSELevel(NoMMXSSE) |
Evan Cheng | dc00858 | 2008-04-16 19:03:02 +0000 | [diff] [blame] | 281 | , X863DNowLevel(NoThreeDNow) |
Chris Lattner | 7008416 | 2009-09-02 05:53:04 +0000 | [diff] [blame] | 282 | , HasCMov(false) |
Evan Cheng | 25ab690 | 2006-09-08 06:48:29 +0000 | [diff] [blame] | 283 | , HasX86_64(false) |
David Greene | 343dadb | 2009-06-26 22:46:54 +0000 | [diff] [blame] | 284 | , HasSSE4A(false) |
| 285 | , HasAVX(false) |
| 286 | , HasFMA3(false) |
| 287 | , HasFMA4(false) |
Evan Cheng | ccb6976 | 2009-01-02 05:35:45 +0000 | [diff] [blame] | 288 | , IsBTMemSlow(false) |
Chris Lattner | 7ad92d8 | 2008-01-02 19:44:55 +0000 | [diff] [blame] | 289 | , DarwinVers(0) |
Evan Cheng | 25ab690 | 2006-09-08 06:48:29 +0000 | [diff] [blame] | 290 | , stackAlignment(8) |
| 291 | // FIXME: this is a known good value for Yonah. How about others? |
Rafael Espindola | fc05f40 | 2007-10-31 11:52:06 +0000 | [diff] [blame] | 292 | , MaxInlineSizeThreshold(128) |
Evan Cheng | 25ab690 | 2006-09-08 06:48:29 +0000 | [diff] [blame] | 293 | , Is64Bit(is64Bit) |
| 294 | , TargetType(isELF) { // Default to ELF unless otherwise specified. |
Anton Korobeynikov | 0eebf65 | 2009-06-08 22:53:56 +0000 | [diff] [blame] | 295 | |
| 296 | // default to hard float ABI |
| 297 | if (FloatABIType == FloatABI::Default) |
| 298 | FloatABIType = FloatABI::Hard; |
Mon P Wang | 63307c3 | 2008-05-05 19:05:59 +0000 | [diff] [blame] | 299 | |
Evan Cheng | 97c7fc3 | 2006-01-26 09:53:06 +0000 | [diff] [blame] | 300 | // Determine default and user specified characteristics |
Evan Cheng | a26eb5e | 2006-10-06 09:17:41 +0000 | [diff] [blame] | 301 | if (!FS.empty()) { |
| 302 | // If feature string is not empty, parse features string. |
Daniel Dunbar | 067d024 | 2009-11-14 10:09:12 +0000 | [diff] [blame] | 303 | std::string CPU = sys::getHostCPUName(); |
Evan Cheng | a26eb5e | 2006-10-06 09:17:41 +0000 | [diff] [blame] | 304 | ParseSubtargetFeatures(FS, CPU); |
Torok Edwin | b68a88b | 2009-02-02 21:57:34 +0000 | [diff] [blame] | 305 | // All X86-64 CPUs also have SSE2, however user might request no SSE via |
| 306 | // -mattr, so don't force SSELevel here. |
Chris Lattner | 3b6f497 | 2006-11-20 18:16:05 +0000 | [diff] [blame] | 307 | } else { |
| 308 | // Otherwise, use CPUID to auto-detect feature set. |
| 309 | AutoDetectSubtargetFeatures(); |
Dan Gohman | f75e5b4 | 2009-02-03 00:04:43 +0000 | [diff] [blame] | 310 | // Make sure SSE2 is enabled; it is available on all X86-64 CPUs. |
| 311 | if (Is64Bit && X86SSELevel < SSE2) |
| 312 | X86SSELevel = SSE2; |
Evan Cheng | 25ab690 | 2006-09-08 06:48:29 +0000 | [diff] [blame] | 313 | } |
Dan Gohman | f75e5b4 | 2009-02-03 00:04:43 +0000 | [diff] [blame] | 314 | |
Dan Gohman | 605679f | 2009-02-03 18:53:21 +0000 | [diff] [blame] | 315 | // If requesting codegen for X86-64, make sure that 64-bit features |
| 316 | // are enabled. |
| 317 | if (Is64Bit) |
| 318 | HasX86_64 = true; |
| 319 | |
David Greene | bd7b845 | 2010-01-05 01:29:13 +0000 | [diff] [blame] | 320 | DEBUG(dbgs() << "Subtarget features: SSELevel " << X86SSELevel |
Bill Wendling | 0ea8bf3 | 2009-08-03 00:11:34 +0000 | [diff] [blame] | 321 | << ", 3DNowLevel " << X863DNowLevel |
| 322 | << ", 64bit " << HasX86_64 << "\n"); |
Dan Gohman | f75e5b4 | 2009-02-03 00:04:43 +0000 | [diff] [blame] | 323 | assert((!Is64Bit || HasX86_64) && |
| 324 | "64-bit code requested on a subtarget that doesn't support it!"); |
Evan Cheng | 25ab690 | 2006-09-08 06:48:29 +0000 | [diff] [blame] | 325 | |
Nate Begeman | fb5792f | 2005-07-12 01:41:54 +0000 | [diff] [blame] | 326 | // Set the boolean corresponding to the current target triple, or the default |
| 327 | // if one cannot be determined, to true. |
Nate Begeman | fb5792f | 2005-07-12 01:41:54 +0000 | [diff] [blame] | 328 | if (TT.length() > 5) { |
Duncan Sands | e51775d | 2008-01-08 10:06:15 +0000 | [diff] [blame] | 329 | size_t Pos; |
Chris Lattner | 7ad92d8 | 2008-01-02 19:44:55 +0000 | [diff] [blame] | 330 | if ((Pos = TT.find("-darwin")) != std::string::npos) { |
Chris Lattner | e5600e5 | 2005-11-21 22:31:58 +0000 | [diff] [blame] | 331 | TargetType = isDarwin; |
Chris Lattner | 7ad92d8 | 2008-01-02 19:44:55 +0000 | [diff] [blame] | 332 | |
| 333 | // Compute the darwin version number. |
| 334 | if (isdigit(TT[Pos+7])) |
| 335 | DarwinVers = atoi(&TT[Pos+7]); |
| 336 | else |
| 337 | DarwinVers = 8; // Minimum supported darwin is Tiger. |
Dan Gohman | a779a98 | 2008-05-05 00:28:39 +0000 | [diff] [blame] | 338 | } else if (TT.find("linux") != std::string::npos) { |
Dan Gohman | 600bf16 | 2008-05-05 16:11:31 +0000 | [diff] [blame] | 339 | // Linux doesn't imply ELF, but we don't currently support anything else. |
| 340 | TargetType = isELF; |
Chris Lattner | 7ad92d8 | 2008-01-02 19:44:55 +0000 | [diff] [blame] | 341 | } else if (TT.find("cygwin") != std::string::npos) { |
| 342 | TargetType = isCygwin; |
| 343 | } else if (TT.find("mingw") != std::string::npos) { |
| 344 | TargetType = isMingw; |
| 345 | } else if (TT.find("win32") != std::string::npos) { |
Chris Lattner | e5600e5 | 2005-11-21 22:31:58 +0000 | [diff] [blame] | 346 | TargetType = isWindows; |
Anton Korobeynikov | 508f0fd | 2008-03-22 21:12:53 +0000 | [diff] [blame] | 347 | } else if (TT.find("windows") != std::string::npos) { |
| 348 | TargetType = isWindows; |
Daniel Dunbar | e22f4da | 2009-08-05 18:12:37 +0000 | [diff] [blame] | 349 | } else if (TT.find("-cl") != std::string::npos) { |
Mon P Wang | 9feb5dd | 2009-02-28 00:25:30 +0000 | [diff] [blame] | 350 | TargetType = isDarwin; |
| 351 | DarwinVers = 9; |
| 352 | } |
Nate Begeman | fb5792f | 2005-07-12 01:41:54 +0000 | [diff] [blame] | 353 | } |
| 354 | |
Anton Korobeynikov | 890fe88 | 2008-04-23 18:16:16 +0000 | [diff] [blame] | 355 | // Stack alignment is 16 bytes on Darwin (both 32 and 64 bit) and for all 64 |
| 356 | // bit targets. |
| 357 | if (TargetType == isDarwin || Is64Bit) |
Nate Begeman | fb5792f | 2005-07-12 01:41:54 +0000 | [diff] [blame] | 358 | stackAlignment = 16; |
Anton Korobeynikov | 78c80fd | 2008-04-12 22:12:22 +0000 | [diff] [blame] | 359 | |
| 360 | if (StackAlignment) |
| 361 | stackAlignment = StackAlignment; |
Nate Begeman | fb5792f | 2005-07-12 01:41:54 +0000 | [diff] [blame] | 362 | } |
David Goodwin | c2e8a7e | 2009-11-10 00:48:55 +0000 | [diff] [blame] | 363 | |
| 364 | bool X86Subtarget::enablePostRAScheduler( |
| 365 | CodeGenOpt::Level OptLevel, |
| 366 | TargetSubtarget::AntiDepBreakMode& Mode, |
David Goodwin | 87d21b9 | 2009-11-13 19:52:48 +0000 | [diff] [blame] | 367 | RegClassVector& CriticalPathRCs) const { |
David Goodwin | c2e8a7e | 2009-11-10 00:48:55 +0000 | [diff] [blame] | 368 | Mode = TargetSubtarget::ANTIDEP_CRITICAL; |
David Goodwin | 87d21b9 | 2009-11-13 19:52:48 +0000 | [diff] [blame] | 369 | CriticalPathRCs.clear(); |
Dan Gohman | d84ea47 | 2009-12-07 19:04:31 +0000 | [diff] [blame] | 370 | return OptLevel >= CodeGenOpt::Aggressive; |
David Goodwin | c2e8a7e | 2009-11-10 00:48:55 +0000 | [diff] [blame] | 371 | } |