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