Bill Wendling | 2bce78e | 2010-12-04 23:57:24 +0000 | [diff] [blame] | 1 | //===-- X86Subtarget.cpp - X86 Subtarget Information ----------------------===// |
Nate Begeman | f26625e | 2005-07-12 01:41:54 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | f3ebc3f | 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 | f26625e | 2005-07-12 01:41:54 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
Evan Cheng | 0d639a2 | 2011-07-01 21:01:15 +0000 | [diff] [blame] | 10 | // This file implements the X86 specific subclass of TargetSubtargetInfo. |
Nate Begeman | f26625e | 2005-07-12 01:41:54 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "X86Subtarget.h" |
Chris Lattner | dc842c0 | 2009-07-10 07:20:05 +0000 | [diff] [blame] | 15 | #include "X86InstrInfo.h" |
Eric Christopher | 4629ed7 | 2014-08-09 01:07:25 +0000 | [diff] [blame] | 16 | #include "X86TargetMachine.h" |
Bill Wendling | aef9c37 | 2013-02-15 22:31:27 +0000 | [diff] [blame] | 17 | #include "llvm/IR/Attributes.h" |
| 18 | #include "llvm/IR/Function.h" |
Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 19 | #include "llvm/IR/GlobalValue.h" |
Eric Christopher | 3470bbb | 2014-05-21 23:51:57 +0000 | [diff] [blame] | 20 | #include "llvm/Support/CommandLine.h" |
Evan Cheng | 9a3ec1b | 2009-01-03 04:04:46 +0000 | [diff] [blame] | 21 | #include "llvm/Support/Debug.h" |
Rafael Espindola | 6559656 | 2011-09-07 16:10:57 +0000 | [diff] [blame] | 22 | #include "llvm/Support/ErrorHandling.h" |
Michael J. Spencer | 447762d | 2010-11-29 18:16:10 +0000 | [diff] [blame] | 23 | #include "llvm/Support/Host.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 24 | #include "llvm/Support/raw_ostream.h" |
Anton Korobeynikov | 430e68a1 | 2006-12-22 22:29:05 +0000 | [diff] [blame] | 25 | #include "llvm/Target/TargetMachine.h" |
Rafael Espindola | 6559656 | 2011-09-07 16:10:57 +0000 | [diff] [blame] | 26 | #include "llvm/Target/TargetOptions.h" |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 27 | |
Chris Lattner | 3ad60b1 | 2009-04-25 18:27:23 +0000 | [diff] [blame] | 28 | #if defined(_MSC_VER) |
Bill Wendling | 6eecd56 | 2009-08-03 00:11:34 +0000 | [diff] [blame] | 29 | #include <intrin.h> |
Chris Lattner | 3ad60b1 | 2009-04-25 18:27:23 +0000 | [diff] [blame] | 30 | #endif |
| 31 | |
Chandler Carruth | 84e68b2 | 2014-04-22 02:41:26 +0000 | [diff] [blame] | 32 | using namespace llvm; |
| 33 | |
| 34 | #define DEBUG_TYPE "subtarget" |
| 35 | |
Chandler Carruth | d174b72 | 2014-04-22 02:03:14 +0000 | [diff] [blame] | 36 | #define GET_SUBTARGETINFO_TARGET_DESC |
| 37 | #define GET_SUBTARGETINFO_CTOR |
| 38 | #include "X86GenSubtargetInfo.inc" |
| 39 | |
Eric Christopher | 6b0fcfe | 2014-05-21 23:40:26 +0000 | [diff] [blame] | 40 | // Temporary option to control early if-conversion for x86 while adding machine |
| 41 | // models. |
| 42 | static cl::opt<bool> |
| 43 | X86EarlyIfConv("x86-early-ifcvt", cl::Hidden, |
| 44 | cl::desc("Enable early if-conversion on X86")); |
| 45 | |
| 46 | |
Sanjay Patel | 2e75341 | 2015-08-14 15:11:42 +0000 | [diff] [blame] | 47 | /// Classify a blockaddress reference for the current subtarget according to how |
| 48 | /// we should reference it in a non-pcrel context. |
Rafael Espindola | cb2d266 | 2016-05-19 18:34:20 +0000 | [diff] [blame] | 49 | unsigned char X86Subtarget::classifyBlockAddressReference() const { |
Rafael Espindola | c7e9813 | 2016-05-20 12:20:10 +0000 | [diff] [blame^] | 50 | return classifyLocalReference(nullptr); |
| 51 | } |
Chad Rosier | 24c19d2 | 2012-08-01 18:39:17 +0000 | [diff] [blame] | 52 | |
Rafael Espindola | c7e9813 | 2016-05-20 12:20:10 +0000 | [diff] [blame^] | 53 | // FIXME: make this a proper option |
| 54 | static bool CanUseCopyRelocWithPIE = false; |
Chad Rosier | 24c19d2 | 2012-08-01 18:39:17 +0000 | [diff] [blame] | 55 | |
Rafael Espindola | c7e9813 | 2016-05-20 12:20:10 +0000 | [diff] [blame^] | 56 | static bool shouldAssumeDSOLocal(Reloc::Model RM, const Triple &TT, |
| 57 | const Module &M, const GlobalValue *GV) { |
| 58 | // DLLImport explicitly marks the GV as external. |
| 59 | if (GV && GV->hasDLLImportStorageClass()) |
| 60 | return false; |
| 61 | |
| 62 | // Every other GV is local on COFF |
| 63 | if (TT.isOSBinFormatCOFF()) |
| 64 | return true; |
| 65 | |
| 66 | if (RM == Reloc::Static) |
| 67 | return true; |
| 68 | |
| 69 | if (GV && (GV->hasInternalLinkage() || !GV->hasDefaultVisibility())) |
| 70 | return true; |
| 71 | |
| 72 | if (TT.isOSBinFormatELF()) { |
| 73 | assert(RM != Reloc::DynamicNoPIC); |
| 74 | // Some linkers can use copy relocations with pie executables. |
| 75 | if (M.getPIELevel() != PIELevel::Default) { |
| 76 | if (CanUseCopyRelocWithPIE) |
| 77 | return true; |
| 78 | |
| 79 | // If the symbol is defined, it cannot be preempted. |
| 80 | if (GV && !GV->isDeclarationForLinker()) |
| 81 | return true; |
| 82 | return false; |
| 83 | } |
| 84 | |
| 85 | // ELF supports preemption of other symbols. |
| 86 | return false; |
| 87 | } |
| 88 | |
| 89 | assert(TT.isOSBinFormatMachO()); |
| 90 | if (GV && GV->isStrongDefinitionForLinker()) |
| 91 | return true; |
| 92 | |
| 93 | return false; |
Dan Gohman | 7a661179 | 2009-11-20 23:18:13 +0000 | [diff] [blame] | 94 | } |
| 95 | |
Sanjay Patel | 2e75341 | 2015-08-14 15:11:42 +0000 | [diff] [blame] | 96 | /// Classify a global variable reference for the current subtarget according to |
| 97 | /// how we should reference it in a non-pcrel context. |
Rafael Espindola | ab03eb0 | 2016-05-19 22:07:57 +0000 | [diff] [blame] | 98 | unsigned char |
| 99 | X86Subtarget::classifyGlobalReference(const GlobalValue *GV) const { |
Rafael Espindola | c7e9813 | 2016-05-20 12:20:10 +0000 | [diff] [blame^] | 100 | return classifyGlobalReference(GV, *GV->getParent()); |
| 101 | } |
Chris Lattner | dc842c0 | 2009-07-10 07:20:05 +0000 | [diff] [blame] | 102 | |
Rafael Espindola | c7e9813 | 2016-05-20 12:20:10 +0000 | [diff] [blame^] | 103 | unsigned char |
| 104 | X86Subtarget::classifyLocalReference(const GlobalValue *GV) const { |
| 105 | // 64 bits can use %rip addressing for anything local. |
| 106 | if (is64Bit()) |
Chris Lattner | dc842c0 | 2009-07-10 07:20:05 +0000 | [diff] [blame] | 107 | return X86II::MO_NO_FLAG; |
Chad Rosier | 24c19d2 | 2012-08-01 18:39:17 +0000 | [diff] [blame] | 108 | |
Rafael Espindola | c7e9813 | 2016-05-20 12:20:10 +0000 | [diff] [blame^] | 109 | // If this is for a position dependent executable, the static linker can |
| 110 | // figure it out. |
| 111 | if (TM.getRelocationModel() != Reloc::PIC_) |
| 112 | return X86II::MO_NO_FLAG; |
Sriraman Tallam | 3cb7734 | 2016-04-22 21:41:58 +0000 | [diff] [blame] | 113 | |
Rafael Espindola | c7e9813 | 2016-05-20 12:20:10 +0000 | [diff] [blame^] | 114 | // The COFF dynamic linker just patches the executable sections. |
| 115 | if (isTargetCOFF()) |
| 116 | return X86II::MO_NO_FLAG; |
Chad Rosier | 24c19d2 | 2012-08-01 18:39:17 +0000 | [diff] [blame] | 117 | |
Rafael Espindola | c7e9813 | 2016-05-20 12:20:10 +0000 | [diff] [blame^] | 118 | if (isTargetDarwin()) { |
| 119 | // 32 bit macho has no relocation for a-b if a is undefined, even if |
| 120 | // b is in the section that is being relocated. |
| 121 | // This means we have to use o load even for GVs that are known to be |
| 122 | // local to the dso. |
| 123 | if (GV && (GV->isDeclarationForLinker() || GV->hasCommonLinkage())) |
Chris Lattner | bd3e560 | 2009-07-10 20:53:38 +0000 | [diff] [blame] | 124 | return X86II::MO_DARWIN_NONLAZY_PIC_BASE; |
Chad Rosier | 24c19d2 | 2012-08-01 18:39:17 +0000 | [diff] [blame] | 125 | |
Chris Lattner | bd3e560 | 2009-07-10 20:53:38 +0000 | [diff] [blame] | 126 | return X86II::MO_PIC_BASE_OFFSET; |
| 127 | } |
Chad Rosier | 24c19d2 | 2012-08-01 18:39:17 +0000 | [diff] [blame] | 128 | |
Rafael Espindola | c7e9813 | 2016-05-20 12:20:10 +0000 | [diff] [blame^] | 129 | return X86II::MO_GOTOFF; |
| 130 | } |
Chad Rosier | 24c19d2 | 2012-08-01 18:39:17 +0000 | [diff] [blame] | 131 | |
Rafael Espindola | c7e9813 | 2016-05-20 12:20:10 +0000 | [diff] [blame^] | 132 | unsigned char X86Subtarget::classifyGlobalReference(const GlobalValue *GV, |
| 133 | const Module &M) const { |
| 134 | // Large model never uses stubs. |
| 135 | if (TM.getCodeModel() == CodeModel::Large) |
Chris Lattner | bd3e560 | 2009-07-10 20:53:38 +0000 | [diff] [blame] | 136 | return X86II::MO_NO_FLAG; |
Rafael Espindola | c7e9813 | 2016-05-20 12:20:10 +0000 | [diff] [blame^] | 137 | |
| 138 | Reloc::Model RM = TM.getRelocationModel(); |
| 139 | if (shouldAssumeDSOLocal(RM, TargetTriple, M, GV)) |
| 140 | return classifyLocalReference(GV); |
| 141 | |
| 142 | if (isTargetCOFF()) |
| 143 | return X86II::MO_DLLIMPORT; |
| 144 | |
| 145 | if (is64Bit()) |
| 146 | return X86II::MO_GOTPCREL; |
| 147 | |
| 148 | if (isTargetDarwin()) { |
| 149 | if (RM != Reloc::PIC_) |
| 150 | return X86II::MO_DARWIN_NONLAZY; |
| 151 | return X86II::MO_DARWIN_NONLAZY_PIC_BASE; |
Chris Lattner | dc842c0 | 2009-07-10 07:20:05 +0000 | [diff] [blame] | 152 | } |
Chad Rosier | 24c19d2 | 2012-08-01 18:39:17 +0000 | [diff] [blame] | 153 | |
Rafael Espindola | c7e9813 | 2016-05-20 12:20:10 +0000 | [diff] [blame^] | 154 | return X86II::MO_GOT; |
Chris Lattner | dc842c0 | 2009-07-10 07:20:05 +0000 | [diff] [blame] | 155 | } |
| 156 | |
Rafael Espindola | 46107b9 | 2016-05-19 18:49:29 +0000 | [diff] [blame] | 157 | unsigned char |
| 158 | X86Subtarget::classifyGlobalFunctionReference(const GlobalValue *GV) const { |
Rafael Espindola | c7e9813 | 2016-05-20 12:20:10 +0000 | [diff] [blame^] | 159 | return classifyGlobalFunctionReference(GV, *GV->getParent()); |
| 160 | } |
| 161 | |
| 162 | unsigned char |
| 163 | X86Subtarget::classifyGlobalFunctionReference(const GlobalValue *GV, |
| 164 | const Module &M) const { |
| 165 | if (shouldAssumeDSOLocal(TM.getRelocationModel(), TargetTriple, M, GV)) |
| 166 | return X86II::MO_NO_FLAG; |
| 167 | |
| 168 | assert(!isTargetCOFF()); |
| 169 | |
| 170 | if (isTargetELF()) |
Asaf Badouh | 89406d1 | 2016-04-20 08:32:57 +0000 | [diff] [blame] | 171 | return X86II::MO_PLT; |
Rafael Espindola | c7e9813 | 2016-05-20 12:20:10 +0000 | [diff] [blame^] | 172 | |
| 173 | if (is64Bit()) { |
| 174 | auto *F = dyn_cast_or_null<Function>(GV); |
| 175 | if (F && F->hasFnAttribute(Attribute::NonLazyBind)) |
| 176 | // If the function is marked as non-lazy, generate an indirect call |
| 177 | // which loads from the GOT directly. This avoids runtime overhead |
| 178 | // at the cost of eager binding (and one extra byte of encoding). |
| 179 | return X86II::MO_GOTPCREL; |
| 180 | return X86II::MO_NO_FLAG; |
Asaf Badouh | 89406d1 | 2016-04-20 08:32:57 +0000 | [diff] [blame] | 181 | } |
| 182 | |
Rafael Espindola | c7e9813 | 2016-05-20 12:20:10 +0000 | [diff] [blame^] | 183 | // PC-relative references to external symbols should go through $stub, |
| 184 | // unless we're building with the leopard linker or later, which |
| 185 | // automatically synthesizes these stubs. |
| 186 | if (!getTargetTriple().isMacOSX() || |
| 187 | getTargetTriple().isMacOSXVersionLT(10, 5)) |
| 188 | return X86II::MO_DARWIN_STUB; |
| 189 | |
Asaf Badouh | 89406d1 | 2016-04-20 08:32:57 +0000 | [diff] [blame] | 190 | return X86II::MO_NO_FLAG; |
| 191 | } |
Anton Korobeynikov | 6dbdfe2 | 2006-11-30 22:42:55 +0000 | [diff] [blame] | 192 | |
Sanjay Patel | 2e75341 | 2015-08-14 15:11:42 +0000 | [diff] [blame] | 193 | /// This function returns the name of a function which has an interface like |
| 194 | /// the non-standard bzero function, if such a function exists on the |
| 195 | /// current subtarget and it is considered preferable over memset with zero |
Bill Wendling | bd09262 | 2008-09-30 21:22:07 +0000 | [diff] [blame] | 196 | /// passed as the second argument. Otherwise it returns null. |
Bill Wendling | 1782584 | 2008-09-30 22:05:33 +0000 | [diff] [blame] | 197 | const char *X86Subtarget::getBZeroEntry() const { |
Dan Gohman | 980d720 | 2008-04-01 20:38:36 +0000 | [diff] [blame] | 198 | // Darwin 10 has a __bzero entry point for this purpose. |
Daniel Dunbar | cd01ed5 | 2011-04-20 00:14:25 +0000 | [diff] [blame] | 199 | if (getTargetTriple().isMacOSX() && |
| 200 | !getTargetTriple().isMacOSXVersionLT(10, 6)) |
Bill Wendling | 1782584 | 2008-09-30 22:05:33 +0000 | [diff] [blame] | 201 | return "__bzero"; |
Dan Gohman | 980d720 | 2008-04-01 20:38:36 +0000 | [diff] [blame] | 202 | |
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 203 | return nullptr; |
Dan Gohman | 980d720 | 2008-04-01 20:38:36 +0000 | [diff] [blame] | 204 | } |
| 205 | |
Evan Cheng | 0e88c7d | 2013-01-29 02:32:37 +0000 | [diff] [blame] | 206 | bool X86Subtarget::hasSinCos() const { |
| 207 | return getTargetTriple().isMacOSX() && |
Evan Cheng | d2ca4e2 | 2013-01-30 22:56:35 +0000 | [diff] [blame] | 208 | !getTargetTriple().isMacOSXVersionLT(10, 9) && |
| 209 | is64Bit(); |
Evan Cheng | 0e88c7d | 2013-01-29 02:32:37 +0000 | [diff] [blame] | 210 | } |
| 211 | |
Sanjay Patel | 2e75341 | 2015-08-14 15:11:42 +0000 | [diff] [blame] | 212 | /// Return true if the subtarget allows calls to immediate address. |
Rafael Espindola | 46107b9 | 2016-05-19 18:49:29 +0000 | [diff] [blame] | 213 | bool X86Subtarget::isLegalToCallImmediateAddr() const { |
David Majnemer | 02f2188 | 2014-03-28 21:40:47 +0000 | [diff] [blame] | 214 | // FIXME: I386 PE/COFF supports PC relative calls using IMAGE_REL_I386_REL32 |
| 215 | // but WinCOFFObjectWriter::RecordRelocation cannot emit them. Once it does, |
| 216 | // the following check for Win32 should be removed. |
| 217 | if (In64BitMode || isTargetWin32()) |
Evan Cheng | 9609833 | 2009-05-20 04:53:57 +0000 | [diff] [blame] | 218 | return false; |
Rafael Espindola | ab03eb0 | 2016-05-19 22:07:57 +0000 | [diff] [blame] | 219 | return isTargetELF() || TM.getRelocationModel() == Reloc::Static; |
Evan Cheng | 9609833 | 2009-05-20 04:53:57 +0000 | [diff] [blame] | 220 | } |
| 221 | |
Eric Christopher | b68e253 | 2014-09-03 20:36:31 +0000 | [diff] [blame] | 222 | void X86Subtarget::initSubtargetFeatures(StringRef CPU, StringRef FS) { |
Nadav Rotem | 08ab877 | 2013-02-27 05:56:20 +0000 | [diff] [blame] | 223 | std::string CPUName = CPU; |
Jim Grosbach | 48551fb | 2014-04-12 01:34:29 +0000 | [diff] [blame] | 224 | if (CPUName.empty()) |
| 225 | CPUName = "generic"; |
Evan Cheng | 964cb5f | 2011-07-08 21:14:14 +0000 | [diff] [blame] | 226 | |
Jim Grosbach | 48551fb | 2014-04-12 01:34:29 +0000 | [diff] [blame] | 227 | // Make sure 64-bit features are available in 64-bit mode. (But make sure |
| 228 | // SSE2 can be turned off explicitly.) |
| 229 | std::string FullFS = FS; |
| 230 | if (In64BitMode) { |
| 231 | if (!FullFS.empty()) |
| 232 | FullFS = "+64bit,+sse2," + FullFS; |
| 233 | else |
| 234 | FullFS = "+64bit,+sse2"; |
Evan Cheng | 11b0a5d | 2006-09-08 06:48:29 +0000 | [diff] [blame] | 235 | } |
Evan Cheng | c5e6d2f | 2011-07-11 03:57:24 +0000 | [diff] [blame] | 236 | |
Hans Wennborg | 5000ce8 | 2015-12-04 23:00:33 +0000 | [diff] [blame] | 237 | // LAHF/SAHF are always supported in non-64-bit mode. |
| 238 | if (!In64BitMode) { |
| 239 | if (!FullFS.empty()) |
| 240 | FullFS = "+sahf," + FullFS; |
| 241 | else |
| 242 | FullFS = "+sahf"; |
| 243 | } |
| 244 | |
| 245 | |
Duncan P. N. Exon Smith | bb57d73 | 2015-07-10 22:33:01 +0000 | [diff] [blame] | 246 | // Parse features string and set the CPU. |
Jim Grosbach | 48551fb | 2014-04-12 01:34:29 +0000 | [diff] [blame] | 247 | ParseSubtargetFeatures(CPUName, FullFS); |
| 248 | |
Sanjay Patel | deb8f82 | 2015-08-25 16:29:21 +0000 | [diff] [blame] | 249 | // All CPUs that implement SSE4.2 or SSE4A support unaligned accesses of |
| 250 | // 16-bytes and under that are reasonably fast. These features were |
| 251 | // introduced with Intel's Nehalem/Silvermont and AMD's Family10h |
| 252 | // micro-architectures respectively. |
| 253 | if (hasSSE42() || hasSSE4A()) |
Sanjay Patel | 3014567 | 2015-09-01 20:51:51 +0000 | [diff] [blame] | 254 | IsUAMem16Slow = false; |
Sanjay Patel | deb8f82 | 2015-08-25 16:29:21 +0000 | [diff] [blame] | 255 | |
Andrew Trick | e0c83b1 | 2012-08-07 00:25:30 +0000 | [diff] [blame] | 256 | InstrItins = getInstrItineraryForCPU(CPUName); |
Andrew Trick | 8523b16 | 2012-02-01 23:20:51 +0000 | [diff] [blame] | 257 | |
Evan Cheng | c5e6d2f | 2011-07-11 03:57:24 +0000 | [diff] [blame] | 258 | // It's important to keep the MCSubtargetInfo feature bits in sync with |
| 259 | // target data structure which is shared with MC code emitter, etc. |
| 260 | if (In64BitMode) |
| 261 | ToggleFeature(X86::Mode64Bit); |
Craig Topper | 3c80d62 | 2014-01-06 04:55:54 +0000 | [diff] [blame] | 262 | else if (In32BitMode) |
| 263 | ToggleFeature(X86::Mode32Bit); |
| 264 | else if (In16BitMode) |
| 265 | ToggleFeature(X86::Mode16Bit); |
| 266 | else |
| 267 | llvm_unreachable("Not 16-bit, 32-bit or 64-bit mode!"); |
Evan Cheng | c5e6d2f | 2011-07-11 03:57:24 +0000 | [diff] [blame] | 268 | |
David Greene | 0041181 | 2010-01-05 01:29:13 +0000 | [diff] [blame] | 269 | DEBUG(dbgs() << "Subtarget features: SSELevel " << X86SSELevel |
Bill Wendling | 6eecd56 | 2009-08-03 00:11:34 +0000 | [diff] [blame] | 270 | << ", 3DNowLevel " << X863DNowLevel |
| 271 | << ", 64bit " << HasX86_64 << "\n"); |
Evan Cheng | 13bcc6c | 2011-07-07 21:06:52 +0000 | [diff] [blame] | 272 | assert((!In64BitMode || HasX86_64) && |
Dan Gohman | 7403751 | 2009-02-03 00:04:43 +0000 | [diff] [blame] | 273 | "64-bit code requested on a subtarget that doesn't support it!"); |
Evan Cheng | 11b0a5d | 2006-09-08 06:48:29 +0000 | [diff] [blame] | 274 | |
Marcin Koscielnicki | 0275fac | 2016-05-05 11:35:51 +0000 | [diff] [blame] | 275 | // Stack alignment is 16 bytes on Darwin, Linux, kFreeBSD and Solaris (both |
Roman Divacky | e8a93fe8 | 2011-02-22 17:30:05 +0000 | [diff] [blame] | 276 | // 32 and 64 bit) and for all 64-bit targets. |
Evan Cheng | 3a0c5e5 | 2011-06-23 17:54:54 +0000 | [diff] [blame] | 277 | if (StackAlignOverride) |
| 278 | stackAlignment = StackAlignOverride; |
Roman Divacky | 2213567 | 2012-11-09 20:10:44 +0000 | [diff] [blame] | 279 | else if (isTargetDarwin() || isTargetLinux() || isTargetSolaris() || |
Marcin Koscielnicki | 0275fac | 2016-05-05 11:35:51 +0000 | [diff] [blame] | 280 | isTargetKFreeBSD() || In64BitMode) |
Nate Begeman | f26625e | 2005-07-12 01:41:54 +0000 | [diff] [blame] | 281 | stackAlignment = 16; |
Dan Gohman | dc53f1c | 2010-05-27 18:43:40 +0000 | [diff] [blame] | 282 | } |
Andrew Trick | 8523b16 | 2012-02-01 23:20:51 +0000 | [diff] [blame] | 283 | |
Bill Wendling | 61375d8 | 2013-02-16 01:36:26 +0000 | [diff] [blame] | 284 | void X86Subtarget::initializeEnvironment() { |
Eric Christopher | 11e5983 | 2015-10-08 20:10:06 +0000 | [diff] [blame] | 285 | X86SSELevel = NoSSE; |
Bill Wendling | 61375d8 | 2013-02-16 01:36:26 +0000 | [diff] [blame] | 286 | X863DNowLevel = NoThreeDNow; |
Andrey Turetskiy | 6a3d561 | 2016-03-23 11:13:54 +0000 | [diff] [blame] | 287 | HasX87 = false; |
Bill Wendling | 61375d8 | 2013-02-16 01:36:26 +0000 | [diff] [blame] | 288 | HasCMov = false; |
| 289 | HasX86_64 = false; |
| 290 | HasPOPCNT = false; |
| 291 | HasSSE4A = false; |
| 292 | HasAES = false; |
Craig Topper | 09b6598 | 2015-10-16 06:03:09 +0000 | [diff] [blame] | 293 | HasFXSR = false; |
Amjad Aboud | 1db6d7a | 2015-10-12 11:47:46 +0000 | [diff] [blame] | 294 | HasXSAVE = false; |
| 295 | HasXSAVEOPT = false; |
| 296 | HasXSAVEC = false; |
| 297 | HasXSAVES = false; |
Bill Wendling | 61375d8 | 2013-02-16 01:36:26 +0000 | [diff] [blame] | 298 | HasPCLMUL = false; |
| 299 | HasFMA = false; |
| 300 | HasFMA4 = false; |
| 301 | HasXOP = false; |
Yunzhong Gao | dd36e93 | 2013-09-24 18:21:52 +0000 | [diff] [blame] | 302 | HasTBM = false; |
Bill Wendling | 61375d8 | 2013-02-16 01:36:26 +0000 | [diff] [blame] | 303 | HasMOVBE = false; |
| 304 | HasRDRAND = false; |
| 305 | HasF16C = false; |
| 306 | HasFSGSBase = false; |
| 307 | HasLZCNT = false; |
| 308 | HasBMI = false; |
| 309 | HasBMI2 = false; |
Michael Zuckerman | 97b6a692 | 2016-01-17 13:42:12 +0000 | [diff] [blame] | 310 | HasVBMI = false; |
Elena Demikhovsky | 29cde35 | 2016-01-24 10:41:28 +0000 | [diff] [blame] | 311 | HasIFMA = false; |
Bill Wendling | 61375d8 | 2013-02-16 01:36:26 +0000 | [diff] [blame] | 312 | HasRTM = false; |
Michael Liao | e344ec9 | 2013-03-26 22:46:02 +0000 | [diff] [blame] | 313 | HasHLE = false; |
Elena Demikhovsky | 003e7d7 | 2013-07-28 08:28:38 +0000 | [diff] [blame] | 314 | HasERI = false; |
| 315 | HasCDI = false; |
Craig Topper | 7a8cf01 | 2013-08-20 05:23:59 +0000 | [diff] [blame] | 316 | HasPFI = false; |
Robert Khasanov | bfa0131 | 2014-07-21 14:54:21 +0000 | [diff] [blame] | 317 | HasDQI = false; |
| 318 | HasBWI = false; |
| 319 | HasVLX = false; |
Bill Wendling | 61375d8 | 2013-02-16 01:36:26 +0000 | [diff] [blame] | 320 | HasADX = false; |
Asaf Badouh | 5acf66f | 2015-12-15 13:35:29 +0000 | [diff] [blame] | 321 | HasPKU = false; |
Ben Langmuir | 1650175 | 2013-09-12 15:51:31 +0000 | [diff] [blame] | 322 | HasSHA = false; |
Michael Liao | 5173ee0 | 2013-03-26 17:47:11 +0000 | [diff] [blame] | 323 | HasPRFCHW = false; |
Michael Liao | a486a11 | 2013-03-28 23:41:26 +0000 | [diff] [blame] | 324 | HasRDSEED = false; |
Hans Wennborg | 5000ce8 | 2015-12-04 23:00:33 +0000 | [diff] [blame] | 325 | HasLAHFSAHF = false; |
Ashutosh Nema | 348af9c | 2016-05-18 11:59:12 +0000 | [diff] [blame] | 326 | HasMWAITX = false; |
Elena Demikhovsky | f7e641c | 2015-06-03 10:30:57 +0000 | [diff] [blame] | 327 | HasMPX = false; |
Bill Wendling | 61375d8 | 2013-02-16 01:36:26 +0000 | [diff] [blame] | 328 | IsBTMemSlow = false; |
Ekaterina Romanova | d5fa554 | 2013-11-21 23:21:26 +0000 | [diff] [blame] | 329 | IsSHLDSlow = false; |
Sanjay Patel | 3014567 | 2015-09-01 20:51:51 +0000 | [diff] [blame] | 330 | IsUAMem16Slow = false; |
Sanjay Patel | 501890e | 2014-11-21 17:40:04 +0000 | [diff] [blame] | 331 | IsUAMem32Slow = false; |
Sanjay Patel | ffd039b | 2015-02-03 17:13:04 +0000 | [diff] [blame] | 332 | HasSSEUnalignedMem = false; |
Bill Wendling | 61375d8 | 2013-02-16 01:36:26 +0000 | [diff] [blame] | 333 | HasCmpxchg16b = false; |
| 334 | UseLeaForSP = false; |
Yunzhong Gao | 0de36ec | 2016-02-12 23:37:57 +0000 | [diff] [blame] | 335 | HasFastPartialYMMWrite = false; |
Alexey Volkov | fd1731d | 2014-11-21 11:19:34 +0000 | [diff] [blame] | 336 | HasSlowDivide32 = false; |
| 337 | HasSlowDivide64 = false; |
Bill Wendling | 61375d8 | 2013-02-16 01:36:26 +0000 | [diff] [blame] | 338 | PadShortFunctions = false; |
Preston Gurd | 663e6f9 | 2013-03-27 19:14:02 +0000 | [diff] [blame] | 339 | CallRegIndirect = false; |
Preston Gurd | 8b7ab4b | 2013-04-25 20:29:37 +0000 | [diff] [blame] | 340 | LEAUsesAG = false; |
Alexey Volkov | 6226de6 | 2014-05-20 08:55:50 +0000 | [diff] [blame] | 341 | SlowLEA = false; |
Alexey Volkov | 5260dba | 2014-06-09 11:40:41 +0000 | [diff] [blame] | 342 | SlowIncDec = false; |
Bill Wendling | 61375d8 | 2013-02-16 01:36:26 +0000 | [diff] [blame] | 343 | stackAlignment = 4; |
| 344 | // FIXME: this is a known good value for Yonah. How about others? |
| 345 | MaxInlineSizeThreshold = 128; |
Eric Christopher | 824f42f | 2015-05-12 01:26:05 +0000 | [diff] [blame] | 346 | UseSoftFloat = false; |
Bill Wendling | 61375d8 | 2013-02-16 01:36:26 +0000 | [diff] [blame] | 347 | } |
| 348 | |
Eric Christopher | 1a21203 | 2014-06-11 00:25:19 +0000 | [diff] [blame] | 349 | X86Subtarget &X86Subtarget::initializeSubtargetDependencies(StringRef CPU, |
| 350 | StringRef FS) { |
| 351 | initializeEnvironment(); |
Eric Christopher | b68e253 | 2014-09-03 20:36:31 +0000 | [diff] [blame] | 352 | initSubtargetFeatures(CPU, FS); |
Eric Christopher | 1a21203 | 2014-06-11 00:25:19 +0000 | [diff] [blame] | 353 | return *this; |
| 354 | } |
| 355 | |
Daniel Sanders | a73f1fd | 2015-06-10 12:11:26 +0000 | [diff] [blame] | 356 | X86Subtarget::X86Subtarget(const Triple &TT, const std::string &CPU, |
Eric Christopher | 12f4a78 | 2014-10-01 20:38:22 +0000 | [diff] [blame] | 357 | const std::string &FS, const X86TargetMachine &TM, |
Eric Christopher | a08f30b | 2014-06-09 17:08:19 +0000 | [diff] [blame] | 358 | unsigned StackAlignOverride) |
Daniel Sanders | 50f1723 | 2015-09-15 16:17:27 +0000 | [diff] [blame] | 359 | : X86GenSubtargetInfo(TT, CPU, FS), X86ProcFamily(Others), |
Rafael Espindola | ab03eb0 | 2016-05-19 22:07:57 +0000 | [diff] [blame] | 360 | PICStyle(PICStyles::None), TM(TM), TargetTriple(TT), |
Eric Christopher | b8f9768 | 2014-05-07 21:05:47 +0000 | [diff] [blame] | 361 | StackAlignOverride(StackAlignOverride), |
| 362 | In64BitMode(TargetTriple.getArch() == Triple::x86_64), |
| 363 | In32BitMode(TargetTriple.getArch() == Triple::x86 && |
| 364 | TargetTriple.getEnvironment() != Triple::CODE16), |
| 365 | In16BitMode(TargetTriple.getArch() == Triple::x86 && |
Eric Christopher | a08f30b | 2014-06-09 17:08:19 +0000 | [diff] [blame] | 366 | TargetTriple.getEnvironment() == Triple::CODE16), |
Mehdi Amini | 157e5a6 | 2015-07-09 02:10:08 +0000 | [diff] [blame] | 367 | TSInfo(), InstrInfo(initializeSubtargetDependencies(CPU, FS)), |
| 368 | TLInfo(TM, *this), FrameLowering(*this, getStackAlignment()) { |
Eric Christopher | 4629ed7 | 2014-08-09 01:07:25 +0000 | [diff] [blame] | 369 | // Determine the PICStyle based on the target selected. |
| 370 | if (TM.getRelocationModel() == Reloc::Static) { |
| 371 | // Unless we're in PIC or DynamicNoPIC mode, set the PIC style to None. |
| 372 | setPICStyle(PICStyles::None); |
| 373 | } else if (is64Bit()) { |
| 374 | // PIC in 64 bit mode is always rip-rel. |
| 375 | setPICStyle(PICStyles::RIPRel); |
| 376 | } else if (isTargetCOFF()) { |
| 377 | setPICStyle(PICStyles::None); |
| 378 | } else if (isTargetDarwin()) { |
| 379 | if (TM.getRelocationModel() == Reloc::PIC_) |
| 380 | setPICStyle(PICStyles::StubPIC); |
| 381 | else { |
| 382 | assert(TM.getRelocationModel() == Reloc::DynamicNoPIC); |
| 383 | setPICStyle(PICStyles::StubDynamicNoPIC); |
| 384 | } |
| 385 | } else if (isTargetELF()) { |
| 386 | setPICStyle(PICStyles::GOT); |
| 387 | } |
| 388 | } |
Bill Wendling | aef9c37 | 2013-02-15 22:31:27 +0000 | [diff] [blame] | 389 | |
Sanjay Patel | a2f658d | 2014-07-15 22:39:58 +0000 | [diff] [blame] | 390 | bool X86Subtarget::enableEarlyIfConversion() const { |
Eric Christopher | 3470bbb | 2014-05-21 23:51:57 +0000 | [diff] [blame] | 391 | return hasCMov() && X86EarlyIfConv; |
Eric Christopher | 6b0fcfe | 2014-05-21 23:40:26 +0000 | [diff] [blame] | 392 | } |
Sanjay Patel | a2f658d | 2014-07-15 22:39:58 +0000 | [diff] [blame] | 393 | |