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 | // |
Evan Cheng | 5b1b4489 | 2011-07-01 21:01:15 +0000 | [diff] [blame] | 10 | // This file implements the X86 specific subclass of TargetSubtargetInfo. |
Nate Begeman | fb5792f | 2005-07-12 01:41:54 +0000 | [diff] [blame] | 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" |
Daniel Dunbar | 3be0340 | 2009-08-02 22:11:08 +0000 | [diff] [blame] | 17 | #include "llvm/GlobalValue.h" |
Evan Cheng | 5b925c0 | 2009-01-03 04:04:46 +0000 | [diff] [blame] | 18 | #include "llvm/Support/Debug.h" |
Bill Wendling | 0ea8bf3 | 2009-08-03 00:11:34 +0000 | [diff] [blame] | 19 | #include "llvm/Support/raw_ostream.h" |
Michael J. Spencer | 1f6efa3 | 2010-11-29 18:16:10 +0000 | [diff] [blame] | 20 | #include "llvm/Support/Host.h" |
Anton Korobeynikov | 2b2bc68 | 2006-12-22 22:29:05 +0000 | [diff] [blame] | 21 | #include "llvm/Target/TargetMachine.h" |
David Goodwin | c2e8a7e | 2009-11-10 00:48:55 +0000 | [diff] [blame] | 22 | #include "llvm/ADT/SmallVector.h" |
Evan Cheng | 9421470 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 23 | |
Evan Cheng | ebdeeab | 2011-07-08 01:53:10 +0000 | [diff] [blame] | 24 | #define GET_SUBTARGETINFO_ENUM |
Evan Cheng | 9421470 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 25 | #define GET_SUBTARGETINFO_MC_DESC |
| 26 | #define GET_SUBTARGETINFO_TARGET_DESC |
Evan Cheng | ebdeeab | 2011-07-08 01:53:10 +0000 | [diff] [blame] | 27 | #define GET_SUBTARGETINFO_CTOR |
Evan Cheng | 385e930 | 2011-07-01 22:36:09 +0000 | [diff] [blame] | 28 | #include "X86GenSubtargetInfo.inc" |
Evan Cheng | 9421470 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 29 | |
Nate Begeman | fb5792f | 2005-07-12 01:41:54 +0000 | [diff] [blame] | 30 | using namespace llvm; |
| 31 | |
Chris Lattner | bc58322 | 2009-04-25 18:27:23 +0000 | [diff] [blame] | 32 | #if defined(_MSC_VER) |
Bill Wendling | 0ea8bf3 | 2009-08-03 00:11:34 +0000 | [diff] [blame] | 33 | #include <intrin.h> |
Chris Lattner | bc58322 | 2009-04-25 18:27:23 +0000 | [diff] [blame] | 34 | #endif |
| 35 | |
Dan Gohman | 29cbade | 2009-11-20 23:18:13 +0000 | [diff] [blame] | 36 | /// ClassifyBlockAddressReference - Classify a blockaddress reference for the |
| 37 | /// current subtarget according to how we should reference it in a non-pcrel |
| 38 | /// context. |
| 39 | unsigned char X86Subtarget:: |
| 40 | ClassifyBlockAddressReference() const { |
| 41 | if (isPICStyleGOT()) // 32-bit ELF targets. |
| 42 | return X86II::MO_GOTOFF; |
| 43 | |
| 44 | if (isPICStyleStubPIC()) // Darwin/32 in PIC mode. |
| 45 | return X86II::MO_PIC_BASE_OFFSET; |
| 46 | |
| 47 | // Direct static reference to label. |
| 48 | return X86II::MO_NO_FLAG; |
| 49 | } |
| 50 | |
Chris Lattner | d392bd9 | 2009-07-10 07:20:05 +0000 | [diff] [blame] | 51 | /// ClassifyGlobalReference - Classify a global variable reference for the |
| 52 | /// current subtarget according to how we should reference it in a non-pcrel |
| 53 | /// context. |
| 54 | unsigned char X86Subtarget:: |
| 55 | ClassifyGlobalReference(const GlobalValue *GV, const TargetMachine &TM) const { |
| 56 | // DLLImport only exists on windows, it is implemented as a load from a |
| 57 | // DLLIMPORT stub. |
| 58 | if (GV->hasDLLImportLinkage()) |
| 59 | return X86II::MO_DLLIMPORT; |
| 60 | |
Chris Lattner | 6b60153 | 2010-06-14 20:11:56 +0000 | [diff] [blame] | 61 | // Determine whether this is a reference to a definition or a declaration. |
| 62 | // Materializable GVs (in JIT lazy compilation mode) do not require an extra |
| 63 | // load from stub. |
| 64 | bool isDecl = GV->hasAvailableExternallyLinkage(); |
| 65 | if (GV->isDeclaration() && !GV->isMaterializable()) |
| 66 | isDecl = true; |
Evan Cheng | a82b22c | 2009-07-16 22:53:10 +0000 | [diff] [blame] | 67 | |
Chris Lattner | d392bd9 | 2009-07-10 07:20:05 +0000 | [diff] [blame] | 68 | // X86-64 in PIC mode. |
| 69 | if (isPICStyleRIPRel()) { |
| 70 | // Large model never uses stubs. |
| 71 | if (TM.getCodeModel() == CodeModel::Large) |
| 72 | return X86II::MO_NO_FLAG; |
| 73 | |
Chris Lattner | c782232 | 2009-07-10 21:01:59 +0000 | [diff] [blame] | 74 | if (isTargetDarwin()) { |
| 75 | // If symbol visibility is hidden, the extra load is not needed if |
| 76 | // target is x86-64 or the symbol is definitely defined in the current |
| 77 | // translation unit. |
| 78 | if (GV->hasDefaultVisibility() && |
Evan Cheng | a82b22c | 2009-07-16 22:53:10 +0000 | [diff] [blame] | 79 | (isDecl || GV->isWeakForLinker())) |
Chris Lattner | c782232 | 2009-07-10 21:01:59 +0000 | [diff] [blame] | 80 | return X86II::MO_GOTPCREL; |
Anton Korobeynikov | 699647c | 2010-08-21 17:21:11 +0000 | [diff] [blame] | 81 | } else if (!isTargetWin64()) { |
Chris Lattner | c782232 | 2009-07-10 21:01:59 +0000 | [diff] [blame] | 82 | assert(isTargetELF() && "Unknown rip-relative target"); |
Chris Lattner | d392bd9 | 2009-07-10 07:20:05 +0000 | [diff] [blame] | 83 | |
Chris Lattner | c782232 | 2009-07-10 21:01:59 +0000 | [diff] [blame] | 84 | // Extra load is needed for all externally visible. |
| 85 | if (!GV->hasLocalLinkage() && GV->hasDefaultVisibility()) |
| 86 | return X86II::MO_GOTPCREL; |
| 87 | } |
Chris Lattner | d392bd9 | 2009-07-10 07:20:05 +0000 | [diff] [blame] | 88 | |
| 89 | return X86II::MO_NO_FLAG; |
| 90 | } |
| 91 | |
| 92 | if (isPICStyleGOT()) { // 32-bit ELF targets. |
| 93 | // Extra load is needed for all externally visible. |
| 94 | if (GV->hasLocalLinkage() || GV->hasHiddenVisibility()) |
| 95 | return X86II::MO_GOTOFF; |
| 96 | return X86II::MO_GOT; |
| 97 | } |
| 98 | |
Chris Lattner | e2c9208 | 2009-07-10 21:00:45 +0000 | [diff] [blame] | 99 | if (isPICStyleStubPIC()) { // Darwin/32 in PIC mode. |
Chris Lattner | 84853a1 | 2009-07-10 20:53:38 +0000 | [diff] [blame] | 100 | // Determine whether we have a stub reference and/or whether the reference |
| 101 | // is relative to the PIC base or not. |
Chris Lattner | d392bd9 | 2009-07-10 07:20:05 +0000 | [diff] [blame] | 102 | |
| 103 | // If this is a strong reference to a definition, it is definitely not |
| 104 | // through a stub. |
Evan Cheng | a82b22c | 2009-07-16 22:53:10 +0000 | [diff] [blame] | 105 | if (!isDecl && !GV->isWeakForLinker()) |
Chris Lattner | 84853a1 | 2009-07-10 20:53:38 +0000 | [diff] [blame] | 106 | return X86II::MO_PIC_BASE_OFFSET; |
Chris Lattner | d392bd9 | 2009-07-10 07:20:05 +0000 | [diff] [blame] | 107 | |
| 108 | // Unless we have a symbol with hidden visibility, we have to go through a |
| 109 | // normal $non_lazy_ptr stub because this symbol might be resolved late. |
Chris Lattner | 84853a1 | 2009-07-10 20:53:38 +0000 | [diff] [blame] | 110 | if (!GV->hasHiddenVisibility()) // Non-hidden $non_lazy_ptr reference. |
| 111 | return X86II::MO_DARWIN_NONLAZY_PIC_BASE; |
Chris Lattner | d392bd9 | 2009-07-10 07:20:05 +0000 | [diff] [blame] | 112 | |
| 113 | // If symbol visibility is hidden, we have a stub for common symbol |
| 114 | // references and external declarations. |
Evan Cheng | a82b22c | 2009-07-16 22:53:10 +0000 | [diff] [blame] | 115 | if (isDecl || GV->hasCommonLinkage()) { |
Chris Lattner | d392bd9 | 2009-07-10 07:20:05 +0000 | [diff] [blame] | 116 | // Hidden $non_lazy_ptr reference. |
Chris Lattner | 84853a1 | 2009-07-10 20:53:38 +0000 | [diff] [blame] | 117 | return X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE; |
Chris Lattner | d392bd9 | 2009-07-10 07:20:05 +0000 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | // Otherwise, no stub. |
Chris Lattner | 84853a1 | 2009-07-10 20:53:38 +0000 | [diff] [blame] | 121 | return X86II::MO_PIC_BASE_OFFSET; |
| 122 | } |
| 123 | |
Chris Lattner | e2c9208 | 2009-07-10 21:00:45 +0000 | [diff] [blame] | 124 | if (isPICStyleStubNoDynamic()) { // Darwin/32 in -mdynamic-no-pic mode. |
Chris Lattner | 84853a1 | 2009-07-10 20:53:38 +0000 | [diff] [blame] | 125 | // Determine whether we have a stub reference. |
| 126 | |
| 127 | // If this is a strong reference to a definition, it is definitely not |
| 128 | // through a stub. |
Evan Cheng | a82b22c | 2009-07-16 22:53:10 +0000 | [diff] [blame] | 129 | if (!isDecl && !GV->isWeakForLinker()) |
Chris Lattner | 84853a1 | 2009-07-10 20:53:38 +0000 | [diff] [blame] | 130 | return X86II::MO_NO_FLAG; |
| 131 | |
| 132 | // Unless we have a symbol with hidden visibility, we have to go through a |
| 133 | // normal $non_lazy_ptr stub because this symbol might be resolved late. |
| 134 | if (!GV->hasHiddenVisibility()) // Non-hidden $non_lazy_ptr reference. |
| 135 | return X86II::MO_DARWIN_NONLAZY; |
Evan Cheng | 63476a8 | 2009-09-03 07:04:02 +0000 | [diff] [blame] | 136 | |
Chris Lattner | 84853a1 | 2009-07-10 20:53:38 +0000 | [diff] [blame] | 137 | // Otherwise, no stub. |
| 138 | return X86II::MO_NO_FLAG; |
Chris Lattner | d392bd9 | 2009-07-10 07:20:05 +0000 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | // Direct static reference to global. |
| 142 | return X86II::MO_NO_FLAG; |
| 143 | } |
| 144 | |
Anton Korobeynikov | 7784ebc | 2006-11-30 22:42:55 +0000 | [diff] [blame] | 145 | |
Bill Wendling | 6f287b2 | 2008-09-30 21:22:07 +0000 | [diff] [blame] | 146 | /// getBZeroEntry - This function returns the name of a function which has an |
| 147 | /// interface like the non-standard bzero function, if such a function exists on |
| 148 | /// the current subtarget and it is considered prefereable over memset with zero |
| 149 | /// passed as the second argument. Otherwise it returns null. |
Bill Wendling | 6e08738 | 2008-09-30 22:05:33 +0000 | [diff] [blame] | 150 | const char *X86Subtarget::getBZeroEntry() const { |
Dan Gohman | 68d599d | 2008-04-01 20:38:36 +0000 | [diff] [blame] | 151 | // Darwin 10 has a __bzero entry point for this purpose. |
Daniel Dunbar | 558692f | 2011-04-20 00:14:25 +0000 | [diff] [blame] | 152 | if (getTargetTriple().isMacOSX() && |
| 153 | !getTargetTriple().isMacOSXVersionLT(10, 6)) |
Bill Wendling | 6e08738 | 2008-09-30 22:05:33 +0000 | [diff] [blame] | 154 | return "__bzero"; |
Dan Gohman | 68d599d | 2008-04-01 20:38:36 +0000 | [diff] [blame] | 155 | |
| 156 | return 0; |
| 157 | } |
| 158 | |
Evan Cheng | d7f666a | 2009-05-20 04:53:57 +0000 | [diff] [blame] | 159 | /// IsLegalToCallImmediateAddr - Return true if the subtarget allows calls |
| 160 | /// to immediate address. |
| 161 | bool X86Subtarget::IsLegalToCallImmediateAddr(const TargetMachine &TM) const { |
Evan Cheng | 18fb1d3 | 2011-07-07 21:06:52 +0000 | [diff] [blame] | 162 | if (In64BitMode) |
Evan Cheng | d7f666a | 2009-05-20 04:53:57 +0000 | [diff] [blame] | 163 | return false; |
| 164 | return isTargetELF() || TM.getRelocationModel() == Reloc::Static; |
| 165 | } |
| 166 | |
Dan Gohman | 8749b61 | 2008-12-16 03:35:01 +0000 | [diff] [blame] | 167 | /// getSpecialAddressLatency - For targets where it is beneficial to |
| 168 | /// backschedule instructions that compute addresses, return a value |
| 169 | /// indicating the number of scheduling cycles of backscheduling that |
| 170 | /// should be attempted. |
| 171 | unsigned X86Subtarget::getSpecialAddressLatency() const { |
| 172 | // For x86 out-of-order targets, back-schedule address computations so |
| 173 | // that loads and stores aren't blocked. |
| 174 | // This value was chosen arbitrarily. |
| 175 | return 200; |
| 176 | } |
| 177 | |
Evan Cheng | a26eb5e | 2006-10-06 09:17:41 +0000 | [diff] [blame] | 178 | void X86Subtarget::AutoDetectSubtargetFeatures() { |
Evan Cheng | b3a7e21 | 2006-01-27 19:30:30 +0000 | [diff] [blame] | 179 | unsigned EAX = 0, EBX = 0, ECX = 0, EDX = 0; |
Jeff Cohen | a349640 | 2006-01-28 18:47:32 +0000 | [diff] [blame] | 180 | union { |
Jeff Cohen | 216d281 | 2006-01-28 19:48:34 +0000 | [diff] [blame] | 181 | unsigned u[3]; |
| 182 | char c[12]; |
Jeff Cohen | a349640 | 2006-01-28 18:47:32 +0000 | [diff] [blame] | 183 | } text; |
Chris Lattner | 3b6f497 | 2006-11-20 18:16:05 +0000 | [diff] [blame] | 184 | |
Evan Cheng | 18fb1d3 | 2011-07-07 21:06:52 +0000 | [diff] [blame] | 185 | if (X86_MC::GetCpuIDAndInfo(0, &EAX, text.u+0, text.u+2, text.u+1)) |
Evan Cheng | abc346c | 2006-10-06 08:21:07 +0000 | [diff] [blame] | 186 | return; |
Anton Korobeynikov | 3b5ee73 | 2007-03-23 23:46:48 +0000 | [diff] [blame] | 187 | |
Evan Cheng | 18fb1d3 | 2011-07-07 21:06:52 +0000 | [diff] [blame] | 188 | X86_MC::GetCpuIDAndInfo(0x1, &EAX, &EBX, &ECX, &EDX); |
Chris Lattner | 3b6f497 | 2006-11-20 18:16:05 +0000 | [diff] [blame] | 189 | |
Chris Lattner | 7008416 | 2009-09-02 05:53:04 +0000 | [diff] [blame] | 190 | if ((EDX >> 15) & 1) HasCMov = true; |
| 191 | if ((EDX >> 23) & 1) X86SSELevel = MMX; |
| 192 | if ((EDX >> 25) & 1) X86SSELevel = SSE1; |
| 193 | if ((EDX >> 26) & 1) X86SSELevel = SSE2; |
Daniel Dunbar | 8481138 | 2009-09-03 05:47:34 +0000 | [diff] [blame] | 194 | if (ECX & 0x1) X86SSELevel = SSE3; |
Chris Lattner | 7008416 | 2009-09-02 05:53:04 +0000 | [diff] [blame] | 195 | if ((ECX >> 9) & 1) X86SSELevel = SSSE3; |
| 196 | if ((ECX >> 19) & 1) X86SSELevel = SSE41; |
| 197 | if ((ECX >> 20) & 1) X86SSELevel = SSE42; |
Evan Cheng | de7f920 | 2010-12-13 04:23:53 +0000 | [diff] [blame] | 198 | // FIXME: AVX codegen support is not ready. |
| 199 | //if ((ECX >> 28) & 1) { HasAVX = true; X86SSELevel = NoMMXSSE; } |
Anton Korobeynikov | 3b5ee73 | 2007-03-23 23:46:48 +0000 | [diff] [blame] | 200 | |
Evan Cheng | ccb6976 | 2009-01-02 05:35:45 +0000 | [diff] [blame] | 201 | bool IsIntel = memcmp(text.c, "GenuineIntel", 12) == 0; |
| 202 | bool IsAMD = !IsIntel && memcmp(text.c, "AuthenticAMD", 12) == 0; |
David Greene | 343dadb | 2009-06-26 22:46:54 +0000 | [diff] [blame] | 203 | |
Bruno Cardoso Lopes | cdae7e8 | 2010-07-23 01:17:51 +0000 | [diff] [blame] | 204 | HasCLMUL = IsIntel && ((ECX >> 1) & 0x1); |
| 205 | HasFMA3 = IsIntel && ((ECX >> 12) & 0x1); |
Mon P Wang | fee2286 | 2011-05-17 18:33:37 +0000 | [diff] [blame] | 206 | HasPOPCNT = IsIntel && ((ECX >> 23) & 0x1); |
Bruno Cardoso Lopes | cdae7e8 | 2010-07-23 01:17:51 +0000 | [diff] [blame] | 207 | HasAES = IsIntel && ((ECX >> 25) & 0x1); |
David Greene | 343dadb | 2009-06-26 22:46:54 +0000 | [diff] [blame] | 208 | |
Evan Cheng | ccb6976 | 2009-01-02 05:35:45 +0000 | [diff] [blame] | 209 | if (IsIntel || IsAMD) { |
| 210 | // Determine if bit test memory instructions are slow. |
| 211 | unsigned Family = 0; |
| 212 | unsigned Model = 0; |
Evan Cheng | 18fb1d3 | 2011-07-07 21:06:52 +0000 | [diff] [blame] | 213 | X86_MC::DetectFamilyModel(EAX, Family, Model); |
Evan Cheng | ccb6976 | 2009-01-02 05:35:45 +0000 | [diff] [blame] | 214 | IsBTMemSlow = IsAMD || (Family == 6 && Model >= 13); |
Evan Cheng | 48c58bb | 2010-04-01 05:58:17 +0000 | [diff] [blame] | 215 | // If it's Nehalem, unaligned memory access is fast. |
| 216 | if (Family == 15 && Model == 26) |
| 217 | IsUAMemFast = true; |
Evan Cheng | ccb6976 | 2009-01-02 05:35:45 +0000 | [diff] [blame] | 218 | |
Evan Cheng | 18fb1d3 | 2011-07-07 21:06:52 +0000 | [diff] [blame] | 219 | X86_MC::GetCpuIDAndInfo(0x80000001, &EAX, &EBX, &ECX, &EDX); |
Jeff Cohen | c398709 | 2007-04-16 21:59:44 +0000 | [diff] [blame] | 220 | HasX86_64 = (EDX >> 29) & 0x1; |
Stefanus Du Toit | 8cf5ab1 | 2009-05-26 21:04:35 +0000 | [diff] [blame] | 221 | HasSSE4A = IsAMD && ((ECX >> 6) & 0x1); |
David Greene | 343dadb | 2009-06-26 22:46:54 +0000 | [diff] [blame] | 222 | HasFMA4 = IsAMD && ((ECX >> 16) & 0x1); |
Jeff Cohen | c398709 | 2007-04-16 21:59:44 +0000 | [diff] [blame] | 223 | } |
Evan Cheng | 559806f | 2006-01-27 08:10:46 +0000 | [diff] [blame] | 224 | } |
Evan Cheng | 97c7fc3 | 2006-01-26 09:53:06 +0000 | [diff] [blame] | 225 | |
Evan Cheng | 276365d | 2011-06-30 01:53:36 +0000 | [diff] [blame] | 226 | X86Subtarget::X86Subtarget(const std::string &TT, const std::string &CPU, |
| 227 | const std::string &FS, |
Evan Cheng | 4d1a8dd | 2011-07-08 22:30:25 +0000 | [diff] [blame] | 228 | unsigned StackAlignOverride, bool is64Bit) |
Evan Cheng | 0ddff1b | 2011-07-07 07:07:08 +0000 | [diff] [blame] | 229 | : X86GenSubtargetInfo(TT, CPU, FS) |
Evan Cheng | 9421470 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 230 | , PICStyle(PICStyles::None) |
Evan Cheng | 25ab690 | 2006-09-08 06:48:29 +0000 | [diff] [blame] | 231 | , X86SSELevel(NoMMXSSE) |
Evan Cheng | dc00858 | 2008-04-16 19:03:02 +0000 | [diff] [blame] | 232 | , X863DNowLevel(NoThreeDNow) |
Chris Lattner | 7008416 | 2009-09-02 05:53:04 +0000 | [diff] [blame] | 233 | , HasCMov(false) |
Evan Cheng | 25ab690 | 2006-09-08 06:48:29 +0000 | [diff] [blame] | 234 | , HasX86_64(false) |
Bill Wendling | d643486 | 2010-12-04 23:57:24 +0000 | [diff] [blame] | 235 | , HasPOPCNT(false) |
David Greene | 343dadb | 2009-06-26 22:46:54 +0000 | [diff] [blame] | 236 | , HasSSE4A(false) |
| 237 | , HasAVX(false) |
Eric Christopher | 6d1cd1c | 2010-04-02 21:54:27 +0000 | [diff] [blame] | 238 | , HasAES(false) |
Bruno Cardoso Lopes | cdae7e8 | 2010-07-23 01:17:51 +0000 | [diff] [blame] | 239 | , HasCLMUL(false) |
David Greene | 343dadb | 2009-06-26 22:46:54 +0000 | [diff] [blame] | 240 | , HasFMA3(false) |
| 241 | , HasFMA4(false) |
Evan Cheng | ccb6976 | 2009-01-02 05:35:45 +0000 | [diff] [blame] | 242 | , IsBTMemSlow(false) |
Evan Cheng | 48c58bb | 2010-04-01 05:58:17 +0000 | [diff] [blame] | 243 | , IsUAMemFast(false) |
David Greene | 95eb2ee | 2010-01-11 16:29:42 +0000 | [diff] [blame] | 244 | , HasVectorUAMem(false) |
Evan Cheng | 25ab690 | 2006-09-08 06:48:29 +0000 | [diff] [blame] | 245 | , stackAlignment(8) |
| 246 | // FIXME: this is a known good value for Yonah. How about others? |
Rafael Espindola | fc05f40 | 2007-10-31 11:52:06 +0000 | [diff] [blame] | 247 | , MaxInlineSizeThreshold(128) |
Eric Christopher | 62f35a2 | 2010-07-05 19:26:33 +0000 | [diff] [blame] | 248 | , TargetTriple(TT) |
Evan Cheng | 4d1a8dd | 2011-07-08 22:30:25 +0000 | [diff] [blame] | 249 | , In64BitMode(is64Bit) { |
Evan Cheng | 97c7fc3 | 2006-01-26 09:53:06 +0000 | [diff] [blame] | 250 | // Determine default and user specified characteristics |
Evan Cheng | 4d1a8dd | 2011-07-08 22:30:25 +0000 | [diff] [blame] | 251 | if (!FS.empty() || !CPU.empty()) { |
Evan Cheng | cc0ddc7 | 2011-07-08 21:14:14 +0000 | [diff] [blame] | 252 | std::string CPUName = CPU; |
| 253 | if (CPUName.empty()) { |
| 254 | #if defined (__x86_64__) || defined(__i386__) |
| 255 | CPUName = sys::getHostCPUName(); |
| 256 | #else |
| 257 | CPUName = "generic"; |
| 258 | #endif |
| 259 | } |
| 260 | |
Eli Friedman | 439d05d | 2011-07-08 23:43:01 +0000 | [diff] [blame^] | 261 | // Make sure 64-bit features are available in 64-bit mode. (But make sure |
| 262 | // SSE2 can be turned off explicitly.) |
| 263 | std::string FullFS = FS; |
| 264 | if (In64BitMode) { |
| 265 | if (!FullFS.empty()) |
| 266 | FullFS = "+64bit,+sse2," + FullFS; |
| 267 | else |
| 268 | FullFS = "+64bit,+sse2"; |
| 269 | } |
Evan Cheng | 4d1a8dd | 2011-07-08 22:30:25 +0000 | [diff] [blame] | 270 | |
Eli Friedman | 439d05d | 2011-07-08 23:43:01 +0000 | [diff] [blame^] | 271 | // If feature string is not empty, parse features string. |
| 272 | ParseSubtargetFeatures(CPUName, FullFS); |
| 273 | |
Nate Begeman | 2ea8ee7 | 2010-12-10 00:26:57 +0000 | [diff] [blame] | 274 | if (HasAVX) |
| 275 | X86SSELevel = NoMMXSSE; |
Chris Lattner | 3b6f497 | 2006-11-20 18:16:05 +0000 | [diff] [blame] | 276 | } else { |
| 277 | // Otherwise, use CPUID to auto-detect feature set. |
| 278 | AutoDetectSubtargetFeatures(); |
Evan Cheng | 18fb1d3 | 2011-07-07 21:06:52 +0000 | [diff] [blame] | 279 | |
Eli Friedman | 6dfef66 | 2011-07-08 23:07:42 +0000 | [diff] [blame] | 280 | // Make sure 64-bit features are available in 64-bit mode. |
| 281 | if (In64BitMode) { |
| 282 | HasX86_64 = true; |
| 283 | HasCMov = true; |
| 284 | |
| 285 | if (!HasAVX && X86SSELevel < SSE2) |
| 286 | X86SSELevel = SSE2; |
| 287 | } |
Evan Cheng | 25ab690 | 2006-09-08 06:48:29 +0000 | [diff] [blame] | 288 | } |
Chris Lattner | 1c436d0 | 2010-03-14 22:39:35 +0000 | [diff] [blame] | 289 | |
David Greene | bd7b845 | 2010-01-05 01:29:13 +0000 | [diff] [blame] | 290 | DEBUG(dbgs() << "Subtarget features: SSELevel " << X86SSELevel |
Bill Wendling | 0ea8bf3 | 2009-08-03 00:11:34 +0000 | [diff] [blame] | 291 | << ", 3DNowLevel " << X863DNowLevel |
| 292 | << ", 64bit " << HasX86_64 << "\n"); |
Evan Cheng | 18fb1d3 | 2011-07-07 21:06:52 +0000 | [diff] [blame] | 293 | assert((!In64BitMode || HasX86_64) && |
Dan Gohman | f75e5b4 | 2009-02-03 00:04:43 +0000 | [diff] [blame] | 294 | "64-bit code requested on a subtarget that doesn't support it!"); |
Evan Cheng | 25ab690 | 2006-09-08 06:48:29 +0000 | [diff] [blame] | 295 | |
Roman Divacky | 4c3ab58 | 2011-02-22 17:30:05 +0000 | [diff] [blame] | 296 | // Stack alignment is 16 bytes on Darwin, FreeBSD, Linux and Solaris (both |
| 297 | // 32 and 64 bit) and for all 64-bit targets. |
Evan Cheng | ef41ff6 | 2011-06-23 17:54:54 +0000 | [diff] [blame] | 298 | if (StackAlignOverride) |
| 299 | stackAlignment = StackAlignOverride; |
| 300 | else if (isTargetDarwin() || isTargetFreeBSD() || isTargetLinux() || |
Evan Cheng | 18fb1d3 | 2011-07-07 21:06:52 +0000 | [diff] [blame] | 301 | isTargetSolaris() || In64BitMode) |
Nate Begeman | fb5792f | 2005-07-12 01:41:54 +0000 | [diff] [blame] | 302 | stackAlignment = 16; |
Dan Gohman | 4d3d6e1 | 2010-05-27 18:43:40 +0000 | [diff] [blame] | 303 | } |