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