| 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 |  | 
| Quentin Colombet | 8cf805a | 2017-07-01 00:45:50 +0000 | [diff] [blame] | 14 | #include "X86.h" | 
|  | 15 |  | 
| Quentin Colombet | 8cf805a | 2017-07-01 00:45:50 +0000 | [diff] [blame] | 16 | #include "X86CallLowering.h" | 
|  | 17 | #include "X86LegalizerInfo.h" | 
|  | 18 | #include "X86RegisterBankInfo.h" | 
| Nate Begeman | f26625e | 2005-07-12 01:41:54 +0000 | [diff] [blame] | 19 | #include "X86Subtarget.h" | 
| Chandler Carruth | 6bda14b | 2017-06-06 11:49:48 +0000 | [diff] [blame] | 20 | #include "MCTargetDesc/X86BaseInfo.h" | 
| Eric Christopher | 4629ed7 | 2014-08-09 01:07:25 +0000 | [diff] [blame] | 21 | #include "X86TargetMachine.h" | 
| Eugene Zelenko | fbd13c5 | 2017-02-02 22:55:55 +0000 | [diff] [blame] | 22 | #include "llvm/ADT/Triple.h" | 
| Quentin Colombet | 8cf805a | 2017-07-01 00:45:50 +0000 | [diff] [blame] | 23 | #include "llvm/CodeGen/GlobalISel/CallLowering.h" | 
|  | 24 | #include "llvm/CodeGen/GlobalISel/InstructionSelect.h" | 
|  | 25 | #include "llvm/CodeGen/GlobalISel/Legalizer.h" | 
|  | 26 | #include "llvm/CodeGen/GlobalISel/RegBankSelect.h" | 
| Bill Wendling | aef9c37 | 2013-02-15 22:31:27 +0000 | [diff] [blame] | 27 | #include "llvm/IR/Attributes.h" | 
| Peter Collingbourne | dc5e583 | 2017-02-02 00:32:03 +0000 | [diff] [blame] | 28 | #include "llvm/IR/ConstantRange.h" | 
| Bill Wendling | aef9c37 | 2013-02-15 22:31:27 +0000 | [diff] [blame] | 29 | #include "llvm/IR/Function.h" | 
| Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 30 | #include "llvm/IR/GlobalValue.h" | 
| Eugene Zelenko | fbd13c5 | 2017-02-02 22:55:55 +0000 | [diff] [blame] | 31 | #include "llvm/Support/Casting.h" | 
|  | 32 | #include "llvm/Support/CodeGen.h" | 
| Eric Christopher | 3470bbb | 2014-05-21 23:51:57 +0000 | [diff] [blame] | 33 | #include "llvm/Support/CommandLine.h" | 
| Evan Cheng | 9a3ec1b | 2009-01-03 04:04:46 +0000 | [diff] [blame] | 34 | #include "llvm/Support/Debug.h" | 
| Rafael Espindola | 6559656 | 2011-09-07 16:10:57 +0000 | [diff] [blame] | 35 | #include "llvm/Support/ErrorHandling.h" | 
| Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 36 | #include "llvm/Support/raw_ostream.h" | 
| Anton Korobeynikov | 430e68a1 | 2006-12-22 22:29:05 +0000 | [diff] [blame] | 37 | #include "llvm/Target/TargetMachine.h" | 
| Eugene Zelenko | fbd13c5 | 2017-02-02 22:55:55 +0000 | [diff] [blame] | 38 | #include <cassert> | 
|  | 39 | #include <string> | 
| Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 40 |  | 
| Chris Lattner | 3ad60b1 | 2009-04-25 18:27:23 +0000 | [diff] [blame] | 41 | #if defined(_MSC_VER) | 
| Bill Wendling | 6eecd56 | 2009-08-03 00:11:34 +0000 | [diff] [blame] | 42 | #include <intrin.h> | 
| Chris Lattner | 3ad60b1 | 2009-04-25 18:27:23 +0000 | [diff] [blame] | 43 | #endif | 
|  | 44 |  | 
| Chandler Carruth | 84e68b2 | 2014-04-22 02:41:26 +0000 | [diff] [blame] | 45 | using namespace llvm; | 
|  | 46 |  | 
|  | 47 | #define DEBUG_TYPE "subtarget" | 
|  | 48 |  | 
| Chandler Carruth | d174b72 | 2014-04-22 02:03:14 +0000 | [diff] [blame] | 49 | #define GET_SUBTARGETINFO_TARGET_DESC | 
|  | 50 | #define GET_SUBTARGETINFO_CTOR | 
|  | 51 | #include "X86GenSubtargetInfo.inc" | 
|  | 52 |  | 
| Eric Christopher | 6b0fcfe | 2014-05-21 23:40:26 +0000 | [diff] [blame] | 53 | // Temporary option to control early if-conversion for x86 while adding machine | 
|  | 54 | // models. | 
|  | 55 | static cl::opt<bool> | 
|  | 56 | X86EarlyIfConv("x86-early-ifcvt", cl::Hidden, | 
|  | 57 | cl::desc("Enable early if-conversion on X86")); | 
|  | 58 |  | 
|  | 59 |  | 
| Sanjay Patel | 2e75341 | 2015-08-14 15:11:42 +0000 | [diff] [blame] | 60 | /// Classify a blockaddress reference for the current subtarget according to how | 
|  | 61 | /// we should reference it in a non-pcrel context. | 
| Rafael Espindola | cb2d266 | 2016-05-19 18:34:20 +0000 | [diff] [blame] | 62 | unsigned char X86Subtarget::classifyBlockAddressReference() const { | 
| Rafael Espindola | c7e9813 | 2016-05-20 12:20:10 +0000 | [diff] [blame] | 63 | return classifyLocalReference(nullptr); | 
|  | 64 | } | 
| Chad Rosier | 24c19d2 | 2012-08-01 18:39:17 +0000 | [diff] [blame] | 65 |  | 
| Sanjay Patel | 2e75341 | 2015-08-14 15:11:42 +0000 | [diff] [blame] | 66 | /// Classify a global variable reference for the current subtarget according to | 
|  | 67 | /// how we should reference it in a non-pcrel context. | 
| Rafael Espindola | ab03eb0 | 2016-05-19 22:07:57 +0000 | [diff] [blame] | 68 | unsigned char | 
|  | 69 | X86Subtarget::classifyGlobalReference(const GlobalValue *GV) const { | 
| Rafael Espindola | c7e9813 | 2016-05-20 12:20:10 +0000 | [diff] [blame] | 70 | return classifyGlobalReference(GV, *GV->getParent()); | 
|  | 71 | } | 
| Chris Lattner | dc842c0 | 2009-07-10 07:20:05 +0000 | [diff] [blame] | 72 |  | 
| Rafael Espindola | c7e9813 | 2016-05-20 12:20:10 +0000 | [diff] [blame] | 73 | unsigned char | 
|  | 74 | X86Subtarget::classifyLocalReference(const GlobalValue *GV) const { | 
|  | 75 | // 64 bits can use %rip addressing for anything local. | 
|  | 76 | if (is64Bit()) | 
| Chris Lattner | dc842c0 | 2009-07-10 07:20:05 +0000 | [diff] [blame] | 77 | return X86II::MO_NO_FLAG; | 
| Chad Rosier | 24c19d2 | 2012-08-01 18:39:17 +0000 | [diff] [blame] | 78 |  | 
| Rafael Espindola | c7e9813 | 2016-05-20 12:20:10 +0000 | [diff] [blame] | 79 | // If this is for a position dependent executable, the static linker can | 
|  | 80 | // figure it out. | 
| Davide Italiano | ef5d8be | 2016-06-18 00:03:20 +0000 | [diff] [blame] | 81 | if (!isPositionIndependent()) | 
| Rafael Espindola | c7e9813 | 2016-05-20 12:20:10 +0000 | [diff] [blame] | 82 | return X86II::MO_NO_FLAG; | 
| Sriraman Tallam | 3cb7734 | 2016-04-22 21:41:58 +0000 | [diff] [blame] | 83 |  | 
| Rafael Espindola | c7e9813 | 2016-05-20 12:20:10 +0000 | [diff] [blame] | 84 | // The COFF dynamic linker just patches the executable sections. | 
|  | 85 | if (isTargetCOFF()) | 
|  | 86 | return X86II::MO_NO_FLAG; | 
| Chad Rosier | 24c19d2 | 2012-08-01 18:39:17 +0000 | [diff] [blame] | 87 |  | 
| Rafael Espindola | c7e9813 | 2016-05-20 12:20:10 +0000 | [diff] [blame] | 88 | if (isTargetDarwin()) { | 
|  | 89 | // 32 bit macho has no relocation for a-b if a is undefined, even if | 
|  | 90 | // b is in the section that is being relocated. | 
|  | 91 | // This means we have to use o load even for GVs that are known to be | 
|  | 92 | // local to the dso. | 
|  | 93 | if (GV && (GV->isDeclarationForLinker() || GV->hasCommonLinkage())) | 
| Chris Lattner | bd3e560 | 2009-07-10 20:53:38 +0000 | [diff] [blame] | 94 | return X86II::MO_DARWIN_NONLAZY_PIC_BASE; | 
| Chad Rosier | 24c19d2 | 2012-08-01 18:39:17 +0000 | [diff] [blame] | 95 |  | 
| Chris Lattner | bd3e560 | 2009-07-10 20:53:38 +0000 | [diff] [blame] | 96 | return X86II::MO_PIC_BASE_OFFSET; | 
|  | 97 | } | 
| Chad Rosier | 24c19d2 | 2012-08-01 18:39:17 +0000 | [diff] [blame] | 98 |  | 
| Rafael Espindola | c7e9813 | 2016-05-20 12:20:10 +0000 | [diff] [blame] | 99 | return X86II::MO_GOTOFF; | 
|  | 100 | } | 
| Chad Rosier | 24c19d2 | 2012-08-01 18:39:17 +0000 | [diff] [blame] | 101 |  | 
| Rafael Espindola | c7e9813 | 2016-05-20 12:20:10 +0000 | [diff] [blame] | 102 | unsigned char X86Subtarget::classifyGlobalReference(const GlobalValue *GV, | 
|  | 103 | const Module &M) const { | 
|  | 104 | // Large model never uses stubs. | 
|  | 105 | if (TM.getCodeModel() == CodeModel::Large) | 
| Chris Lattner | bd3e560 | 2009-07-10 20:53:38 +0000 | [diff] [blame] | 106 | return X86II::MO_NO_FLAG; | 
| Rafael Espindola | c7e9813 | 2016-05-20 12:20:10 +0000 | [diff] [blame] | 107 |  | 
| Peter Collingbourne | 235c275 | 2016-12-08 19:01:00 +0000 | [diff] [blame] | 108 | // Absolute symbols can be referenced directly. | 
| Peter Collingbourne | dc5e583 | 2017-02-02 00:32:03 +0000 | [diff] [blame] | 109 | if (GV) { | 
|  | 110 | if (Optional<ConstantRange> CR = GV->getAbsoluteSymbolRange()) { | 
|  | 111 | // See if we can use the 8-bit immediate form. Note that some instructions | 
|  | 112 | // will sign extend the immediate operand, so to be conservative we only | 
|  | 113 | // accept the range [0,128). | 
|  | 114 | if (CR->getUnsignedMax().ult(128)) | 
|  | 115 | return X86II::MO_ABS8; | 
|  | 116 | else | 
|  | 117 | return X86II::MO_NO_FLAG; | 
|  | 118 | } | 
|  | 119 | } | 
| Peter Collingbourne | 235c275 | 2016-12-08 19:01:00 +0000 | [diff] [blame] | 120 |  | 
| Rafael Espindola | 2393c3b | 2017-10-27 21:18:48 +0000 | [diff] [blame^] | 121 | if (TM.shouldAssumeDSOLocal(M, GV)) | 
| Rafael Espindola | c7e9813 | 2016-05-20 12:20:10 +0000 | [diff] [blame] | 122 | return classifyLocalReference(GV); | 
|  | 123 |  | 
|  | 124 | if (isTargetCOFF()) | 
|  | 125 | return X86II::MO_DLLIMPORT; | 
|  | 126 |  | 
|  | 127 | if (is64Bit()) | 
|  | 128 | return X86II::MO_GOTPCREL; | 
|  | 129 |  | 
|  | 130 | if (isTargetDarwin()) { | 
| Davide Italiano | ef5d8be | 2016-06-18 00:03:20 +0000 | [diff] [blame] | 131 | if (!isPositionIndependent()) | 
| Rafael Espindola | c7e9813 | 2016-05-20 12:20:10 +0000 | [diff] [blame] | 132 | return X86II::MO_DARWIN_NONLAZY; | 
|  | 133 | return X86II::MO_DARWIN_NONLAZY_PIC_BASE; | 
| Chris Lattner | dc842c0 | 2009-07-10 07:20:05 +0000 | [diff] [blame] | 134 | } | 
| Chad Rosier | 24c19d2 | 2012-08-01 18:39:17 +0000 | [diff] [blame] | 135 |  | 
| Rafael Espindola | c7e9813 | 2016-05-20 12:20:10 +0000 | [diff] [blame] | 136 | return X86II::MO_GOT; | 
| Chris Lattner | dc842c0 | 2009-07-10 07:20:05 +0000 | [diff] [blame] | 137 | } | 
|  | 138 |  | 
| Rafael Espindola | 46107b9 | 2016-05-19 18:49:29 +0000 | [diff] [blame] | 139 | unsigned char | 
|  | 140 | X86Subtarget::classifyGlobalFunctionReference(const GlobalValue *GV) const { | 
| Rafael Espindola | c7e9813 | 2016-05-20 12:20:10 +0000 | [diff] [blame] | 141 | return classifyGlobalFunctionReference(GV, *GV->getParent()); | 
|  | 142 | } | 
|  | 143 |  | 
|  | 144 | unsigned char | 
|  | 145 | X86Subtarget::classifyGlobalFunctionReference(const GlobalValue *GV, | 
|  | 146 | const Module &M) const { | 
| Rafael Espindola | 3beef8d | 2016-06-27 23:15:57 +0000 | [diff] [blame] | 147 | if (TM.shouldAssumeDSOLocal(M, GV)) | 
| Rafael Espindola | c7e9813 | 2016-05-20 12:20:10 +0000 | [diff] [blame] | 148 | return X86II::MO_NO_FLAG; | 
|  | 149 |  | 
| Reid Kleckner | 7662d50 | 2017-08-05 00:10:43 +0000 | [diff] [blame] | 150 | if (isTargetCOFF()) { | 
|  | 151 | assert(GV->hasDLLImportStorageClass() && | 
|  | 152 | "shouldAssumeDSOLocal gave inconsistent answer"); | 
|  | 153 | return X86II::MO_DLLIMPORT; | 
|  | 154 | } | 
|  | 155 |  | 
| Oren Ben Simhon | 51de033 | 2017-05-04 07:22:49 +0000 | [diff] [blame] | 156 | const Function *F = dyn_cast_or_null<Function>(GV); | 
| Rafael Espindola | c7e9813 | 2016-05-20 12:20:10 +0000 | [diff] [blame] | 157 |  | 
| Oren Ben Simhon | 51de033 | 2017-05-04 07:22:49 +0000 | [diff] [blame] | 158 | if (isTargetELF()) { | 
|  | 159 | if (is64Bit() && F && (CallingConv::X86_RegCall == F->getCallingConv())) | 
|  | 160 | // According to psABI, PLT stub clobbers XMM8-XMM15. | 
|  | 161 | // In Regcall calling convention those registers are used for passing | 
|  | 162 | // parameters. Thus we need to prevent lazy binding in Regcall. | 
|  | 163 | return X86II::MO_GOTPCREL; | 
| Asaf Badouh | 89406d1 | 2016-04-20 08:32:57 +0000 | [diff] [blame] | 164 | return X86II::MO_PLT; | 
| Oren Ben Simhon | 51de033 | 2017-05-04 07:22:49 +0000 | [diff] [blame] | 165 | } | 
| Rafael Espindola | c7e9813 | 2016-05-20 12:20:10 +0000 | [diff] [blame] | 166 |  | 
|  | 167 | if (is64Bit()) { | 
| Rafael Espindola | c7e9813 | 2016-05-20 12:20:10 +0000 | [diff] [blame] | 168 | if (F && F->hasFnAttribute(Attribute::NonLazyBind)) | 
|  | 169 | // If the function is marked as non-lazy, generate an indirect call | 
|  | 170 | // which loads from the GOT directly. This avoids runtime overhead | 
|  | 171 | // at the cost of eager binding (and one extra byte of encoding). | 
|  | 172 | return X86II::MO_GOTPCREL; | 
|  | 173 | return X86II::MO_NO_FLAG; | 
| Asaf Badouh | 89406d1 | 2016-04-20 08:32:57 +0000 | [diff] [blame] | 174 | } | 
|  | 175 |  | 
|  | 176 | return X86II::MO_NO_FLAG; | 
|  | 177 | } | 
| Anton Korobeynikov | 6dbdfe2 | 2006-11-30 22:42:55 +0000 | [diff] [blame] | 178 |  | 
| Sanjay Patel | 2e75341 | 2015-08-14 15:11:42 +0000 | [diff] [blame] | 179 | /// This function returns the name of a function which has an interface like | 
|  | 180 | /// the non-standard bzero function, if such a function exists on the | 
|  | 181 | /// current subtarget and it is considered preferable over memset with zero | 
| Bill Wendling | bd09262 | 2008-09-30 21:22:07 +0000 | [diff] [blame] | 182 | /// passed as the second argument. Otherwise it returns null. | 
| Bill Wendling | 1782584 | 2008-09-30 22:05:33 +0000 | [diff] [blame] | 183 | const char *X86Subtarget::getBZeroEntry() const { | 
| Dan Gohman | 980d720 | 2008-04-01 20:38:36 +0000 | [diff] [blame] | 184 | // Darwin 10 has a __bzero entry point for this purpose. | 
| Daniel Dunbar | cd01ed5 | 2011-04-20 00:14:25 +0000 | [diff] [blame] | 185 | if (getTargetTriple().isMacOSX() && | 
|  | 186 | !getTargetTriple().isMacOSXVersionLT(10, 6)) | 
| Bill Wendling | 1782584 | 2008-09-30 22:05:33 +0000 | [diff] [blame] | 187 | return "__bzero"; | 
| Dan Gohman | 980d720 | 2008-04-01 20:38:36 +0000 | [diff] [blame] | 188 |  | 
| Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 189 | return nullptr; | 
| Dan Gohman | 980d720 | 2008-04-01 20:38:36 +0000 | [diff] [blame] | 190 | } | 
|  | 191 |  | 
| Evan Cheng | 0e88c7d | 2013-01-29 02:32:37 +0000 | [diff] [blame] | 192 | bool X86Subtarget::hasSinCos() const { | 
| Petr Hosek | 710479c | 2017-07-23 22:30:00 +0000 | [diff] [blame] | 193 | if (getTargetTriple().isMacOSX()) { | 
|  | 194 | return !getTargetTriple().isMacOSXVersionLT(10, 9) && is64Bit(); | 
|  | 195 | } else if (getTargetTriple().isOSFuchsia()) { | 
|  | 196 | return true; | 
|  | 197 | } | 
|  | 198 | return false; | 
| Evan Cheng | 0e88c7d | 2013-01-29 02:32:37 +0000 | [diff] [blame] | 199 | } | 
|  | 200 |  | 
| Sanjay Patel | 2e75341 | 2015-08-14 15:11:42 +0000 | [diff] [blame] | 201 | /// Return true if the subtarget allows calls to immediate address. | 
| Rafael Espindola | 46107b9 | 2016-05-19 18:49:29 +0000 | [diff] [blame] | 202 | bool X86Subtarget::isLegalToCallImmediateAddr() const { | 
| David Majnemer | 02f2188 | 2014-03-28 21:40:47 +0000 | [diff] [blame] | 203 | // FIXME: I386 PE/COFF supports PC relative calls using IMAGE_REL_I386_REL32 | 
|  | 204 | // but WinCOFFObjectWriter::RecordRelocation cannot emit them.  Once it does, | 
|  | 205 | // the following check for Win32 should be removed. | 
|  | 206 | if (In64BitMode || isTargetWin32()) | 
| Evan Cheng | 9609833 | 2009-05-20 04:53:57 +0000 | [diff] [blame] | 207 | return false; | 
| Rafael Espindola | ab03eb0 | 2016-05-19 22:07:57 +0000 | [diff] [blame] | 208 | return isTargetELF() || TM.getRelocationModel() == Reloc::Static; | 
| Evan Cheng | 9609833 | 2009-05-20 04:53:57 +0000 | [diff] [blame] | 209 | } | 
|  | 210 |  | 
| Eric Christopher | b68e253 | 2014-09-03 20:36:31 +0000 | [diff] [blame] | 211 | void X86Subtarget::initSubtargetFeatures(StringRef CPU, StringRef FS) { | 
| Nadav Rotem | 08ab877 | 2013-02-27 05:56:20 +0000 | [diff] [blame] | 212 | std::string CPUName = CPU; | 
| Jim Grosbach | 48551fb | 2014-04-12 01:34:29 +0000 | [diff] [blame] | 213 | if (CPUName.empty()) | 
|  | 214 | CPUName = "generic"; | 
| Evan Cheng | 964cb5f | 2011-07-08 21:14:14 +0000 | [diff] [blame] | 215 |  | 
| Jim Grosbach | 48551fb | 2014-04-12 01:34:29 +0000 | [diff] [blame] | 216 | // Make sure 64-bit features are available in 64-bit mode. (But make sure | 
|  | 217 | // SSE2 can be turned off explicitly.) | 
|  | 218 | std::string FullFS = FS; | 
|  | 219 | if (In64BitMode) { | 
|  | 220 | if (!FullFS.empty()) | 
|  | 221 | FullFS = "+64bit,+sse2," + FullFS; | 
|  | 222 | else | 
|  | 223 | FullFS = "+64bit,+sse2"; | 
| Evan Cheng | 11b0a5d | 2006-09-08 06:48:29 +0000 | [diff] [blame] | 224 | } | 
| Evan Cheng | c5e6d2f | 2011-07-11 03:57:24 +0000 | [diff] [blame] | 225 |  | 
| Hans Wennborg | 5000ce8 | 2015-12-04 23:00:33 +0000 | [diff] [blame] | 226 | // LAHF/SAHF are always supported in non-64-bit mode. | 
|  | 227 | if (!In64BitMode) { | 
|  | 228 | if (!FullFS.empty()) | 
|  | 229 | FullFS = "+sahf," + FullFS; | 
|  | 230 | else | 
|  | 231 | FullFS = "+sahf"; | 
|  | 232 | } | 
|  | 233 |  | 
| Duncan P. N. Exon Smith | bb57d73 | 2015-07-10 22:33:01 +0000 | [diff] [blame] | 234 | // Parse features string and set the CPU. | 
| Jim Grosbach | 48551fb | 2014-04-12 01:34:29 +0000 | [diff] [blame] | 235 | ParseSubtargetFeatures(CPUName, FullFS); | 
|  | 236 |  | 
| Sanjay Patel | deb8f82 | 2015-08-25 16:29:21 +0000 | [diff] [blame] | 237 | // All CPUs that implement SSE4.2 or SSE4A support unaligned accesses of | 
|  | 238 | // 16-bytes and under that are reasonably fast. These features were | 
|  | 239 | // introduced with Intel's Nehalem/Silvermont and AMD's Family10h | 
|  | 240 | // micro-architectures respectively. | 
|  | 241 | if (hasSSE42() || hasSSE4A()) | 
| Sanjay Patel | 3014567 | 2015-09-01 20:51:51 +0000 | [diff] [blame] | 242 | IsUAMem16Slow = false; | 
| Sanjay Patel | deb8f82 | 2015-08-25 16:29:21 +0000 | [diff] [blame] | 243 |  | 
| Andrew Trick | e0c83b1 | 2012-08-07 00:25:30 +0000 | [diff] [blame] | 244 | InstrItins = getInstrItineraryForCPU(CPUName); | 
| Andrew Trick | 8523b16 | 2012-02-01 23:20:51 +0000 | [diff] [blame] | 245 |  | 
| Evan Cheng | c5e6d2f | 2011-07-11 03:57:24 +0000 | [diff] [blame] | 246 | // It's important to keep the MCSubtargetInfo feature bits in sync with | 
|  | 247 | // target data structure which is shared with MC code emitter, etc. | 
|  | 248 | if (In64BitMode) | 
|  | 249 | ToggleFeature(X86::Mode64Bit); | 
| Craig Topper | 3c80d62 | 2014-01-06 04:55:54 +0000 | [diff] [blame] | 250 | else if (In32BitMode) | 
|  | 251 | ToggleFeature(X86::Mode32Bit); | 
|  | 252 | else if (In16BitMode) | 
|  | 253 | ToggleFeature(X86::Mode16Bit); | 
|  | 254 | else | 
|  | 255 | llvm_unreachable("Not 16-bit, 32-bit or 64-bit mode!"); | 
| Evan Cheng | c5e6d2f | 2011-07-11 03:57:24 +0000 | [diff] [blame] | 256 |  | 
| David Greene | 0041181 | 2010-01-05 01:29:13 +0000 | [diff] [blame] | 257 | DEBUG(dbgs() << "Subtarget features: SSELevel " << X86SSELevel | 
| Bill Wendling | 6eecd56 | 2009-08-03 00:11:34 +0000 | [diff] [blame] | 258 | << ", 3DNowLevel " << X863DNowLevel | 
|  | 259 | << ", 64bit " << HasX86_64 << "\n"); | 
| Evan Cheng | 13bcc6c | 2011-07-07 21:06:52 +0000 | [diff] [blame] | 260 | assert((!In64BitMode || HasX86_64) && | 
| Dan Gohman | 7403751 | 2009-02-03 00:04:43 +0000 | [diff] [blame] | 261 | "64-bit code requested on a subtarget that doesn't support it!"); | 
| Evan Cheng | 11b0a5d | 2006-09-08 06:48:29 +0000 | [diff] [blame] | 262 |  | 
| Marcin Koscielnicki | 0275fac | 2016-05-05 11:35:51 +0000 | [diff] [blame] | 263 | // Stack alignment is 16 bytes on Darwin, Linux, kFreeBSD and Solaris (both | 
| Roman Divacky | e8a93fe8 | 2011-02-22 17:30:05 +0000 | [diff] [blame] | 264 | // 32 and 64 bit) and for all 64-bit targets. | 
| Evan Cheng | 3a0c5e5 | 2011-06-23 17:54:54 +0000 | [diff] [blame] | 265 | if (StackAlignOverride) | 
|  | 266 | stackAlignment = StackAlignOverride; | 
| Roman Divacky | 2213567 | 2012-11-09 20:10:44 +0000 | [diff] [blame] | 267 | else if (isTargetDarwin() || isTargetLinux() || isTargetSolaris() || | 
| Marcin Koscielnicki | 0275fac | 2016-05-05 11:35:51 +0000 | [diff] [blame] | 268 | isTargetKFreeBSD() || In64BitMode) | 
| Nate Begeman | f26625e | 2005-07-12 01:41:54 +0000 | [diff] [blame] | 269 | stackAlignment = 16; | 
| Mohammed Agabaria | e9aebf2 | 2017-09-13 09:00:27 +0000 | [diff] [blame] | 270 |  | 
|  | 271 | // Gather is available since Haswell (AVX2 set). So technically, we can generate Gathers | 
|  | 272 | // on all AVX2 processors. But the overhead on HSW is high. Skylake Client processor has | 
|  | 273 | // faster Gathers than HSW and performance is similar to Skylake Server (AVX-512). | 
|  | 274 | // The specified overhead is relative to the Load operation."2" is the number provided | 
|  | 275 | // by Intel architects, This parameter is used for cost estimation of Gather Op and | 
|  | 276 | // comparison with other alternatives. | 
|  | 277 | if (X86ProcFamily == IntelSkylake || hasAVX512()) | 
|  | 278 | GatherOverhead = 2; | 
|  | 279 | if (hasAVX512()) | 
|  | 280 | ScatterOverhead = 2; | 
| Dan Gohman | dc53f1c | 2010-05-27 18:43:40 +0000 | [diff] [blame] | 281 | } | 
| Andrew Trick | 8523b16 | 2012-02-01 23:20:51 +0000 | [diff] [blame] | 282 |  | 
| Bill Wendling | 61375d8 | 2013-02-16 01:36:26 +0000 | [diff] [blame] | 283 | void X86Subtarget::initializeEnvironment() { | 
| Eric Christopher | 11e5983 | 2015-10-08 20:10:06 +0000 | [diff] [blame] | 284 | X86SSELevel = NoSSE; | 
| Bill Wendling | 61375d8 | 2013-02-16 01:36:26 +0000 | [diff] [blame] | 285 | X863DNowLevel = NoThreeDNow; | 
| Andrey Turetskiy | 6a3d561 | 2016-03-23 11:13:54 +0000 | [diff] [blame] | 286 | HasX87 = false; | 
| Bill Wendling | 61375d8 | 2013-02-16 01:36:26 +0000 | [diff] [blame] | 287 | HasCMov = false; | 
|  | 288 | HasX86_64 = false; | 
|  | 289 | HasPOPCNT = false; | 
|  | 290 | HasSSE4A = false; | 
|  | 291 | HasAES = false; | 
| Craig Topper | 09b6598 | 2015-10-16 06:03:09 +0000 | [diff] [blame] | 292 | HasFXSR = false; | 
| Amjad Aboud | 1db6d7a | 2015-10-12 11:47:46 +0000 | [diff] [blame] | 293 | HasXSAVE = false; | 
|  | 294 | HasXSAVEOPT = false; | 
|  | 295 | HasXSAVEC = false; | 
|  | 296 | HasXSAVES = false; | 
| Bill Wendling | 61375d8 | 2013-02-16 01:36:26 +0000 | [diff] [blame] | 297 | HasPCLMUL = false; | 
|  | 298 | HasFMA = false; | 
|  | 299 | HasFMA4 = false; | 
|  | 300 | HasXOP = false; | 
| Yunzhong Gao | dd36e93 | 2013-09-24 18:21:52 +0000 | [diff] [blame] | 301 | HasTBM = false; | 
| Simon Pilgrim | 99b925b | 2017-05-03 15:51:39 +0000 | [diff] [blame] | 302 | HasLWP = 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; | 
| Elena Demikhovsky | 003e7d7 | 2013-07-28 08:28:38 +0000 | [diff] [blame] | 313 | HasERI = false; | 
|  | 314 | HasCDI = false; | 
| Craig Topper | 7a8cf01 | 2013-08-20 05:23:59 +0000 | [diff] [blame] | 315 | HasPFI = false; | 
| Robert Khasanov | bfa0131 | 2014-07-21 14:54:21 +0000 | [diff] [blame] | 316 | HasDQI = false; | 
| Oren Ben Simhon | 7bf27f0 | 2017-05-25 13:45:23 +0000 | [diff] [blame] | 317 | HasVPOPCNTDQ = false; | 
| Robert Khasanov | bfa0131 | 2014-07-21 14:54:21 +0000 | [diff] [blame] | 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; | 
| Craig Topper | 50f3d14 | 2017-02-09 04:27:34 +0000 | [diff] [blame] | 327 | HasCLZERO = false; | 
| Elena Demikhovsky | f7e641c | 2015-06-03 10:30:57 +0000 | [diff] [blame] | 328 | HasMPX = false; | 
| Tim Northover | 9bb6931 | 2017-05-01 17:50:15 +0000 | [diff] [blame] | 329 | HasSGX = false; | 
|  | 330 | HasCLFLUSHOPT = false; | 
|  | 331 | HasCLWB = false; | 
| Zvi Rackover | 8bc7e4d | 2016-12-06 19:35:20 +0000 | [diff] [blame] | 332 | IsPMULLDSlow = false; | 
| Ekaterina Romanova | d5fa554 | 2013-11-21 23:21:26 +0000 | [diff] [blame] | 333 | IsSHLDSlow = false; | 
| Sanjay Patel | 3014567 | 2015-09-01 20:51:51 +0000 | [diff] [blame] | 334 | IsUAMem16Slow = false; | 
| Sanjay Patel | 501890e | 2014-11-21 17:40:04 +0000 | [diff] [blame] | 335 | IsUAMem32Slow = false; | 
| Sanjay Patel | ffd039b | 2015-02-03 17:13:04 +0000 | [diff] [blame] | 336 | HasSSEUnalignedMem = false; | 
| Bill Wendling | 61375d8 | 2013-02-16 01:36:26 +0000 | [diff] [blame] | 337 | HasCmpxchg16b = false; | 
|  | 338 | UseLeaForSP = false; | 
| Amjad Aboud | 4f97751 | 2017-03-03 09:03:24 +0000 | [diff] [blame] | 339 | HasFastPartialYMMorZMMWrite = false; | 
| Nikolai Bozhenov | f679530 | 2016-08-04 12:47:28 +0000 | [diff] [blame] | 340 | HasFastScalarFSQRT = false; | 
|  | 341 | HasFastVectorFSQRT = false; | 
| Pierre Gousseau | b6d652a | 2016-10-14 16:41:38 +0000 | [diff] [blame] | 342 | HasFastLZCNT = false; | 
| Craig Topper | d88389a | 2017-02-21 06:39:13 +0000 | [diff] [blame] | 343 | HasFastSHLDRotate = false; | 
| Craig Topper | 641e2af | 2017-08-30 04:34:48 +0000 | [diff] [blame] | 344 | HasMacroFusion = false; | 
| Clement Courbet | 203fc17 | 2017-04-21 09:20:50 +0000 | [diff] [blame] | 345 | HasERMSB = false; | 
| Alexey Volkov | fd1731d | 2014-11-21 11:19:34 +0000 | [diff] [blame] | 346 | HasSlowDivide32 = false; | 
|  | 347 | HasSlowDivide64 = false; | 
| Bill Wendling | 61375d8 | 2013-02-16 01:36:26 +0000 | [diff] [blame] | 348 | PadShortFunctions = false; | 
| Craig Topper | 62c47a2 | 2017-08-29 05:14:27 +0000 | [diff] [blame] | 349 | SlowTwoMemOps = false; | 
| Preston Gurd | 8b7ab4b | 2013-04-25 20:29:37 +0000 | [diff] [blame] | 350 | LEAUsesAG = false; | 
| Alexey Volkov | 6226de6 | 2014-05-20 08:55:50 +0000 | [diff] [blame] | 351 | SlowLEA = false; | 
| Lama Saba | 2ea271b | 2017-05-18 08:11:50 +0000 | [diff] [blame] | 352 | Slow3OpsLEA = false; | 
| Alexey Volkov | 5260dba | 2014-06-09 11:40:41 +0000 | [diff] [blame] | 353 | SlowIncDec = false; | 
| Bill Wendling | 61375d8 | 2013-02-16 01:36:26 +0000 | [diff] [blame] | 354 | stackAlignment = 4; | 
|  | 355 | // FIXME: this is a known good value for Yonah. How about others? | 
|  | 356 | MaxInlineSizeThreshold = 128; | 
| Eric Christopher | 824f42f | 2015-05-12 01:26:05 +0000 | [diff] [blame] | 357 | UseSoftFloat = false; | 
| Mohammed Agabaria | e9aebf2 | 2017-09-13 09:00:27 +0000 | [diff] [blame] | 358 | X86ProcFamily = Others; | 
|  | 359 | GatherOverhead = 1024; | 
|  | 360 | ScatterOverhead = 1024; | 
| Bill Wendling | 61375d8 | 2013-02-16 01:36:26 +0000 | [diff] [blame] | 361 | } | 
|  | 362 |  | 
| Eric Christopher | 1a21203 | 2014-06-11 00:25:19 +0000 | [diff] [blame] | 363 | X86Subtarget &X86Subtarget::initializeSubtargetDependencies(StringRef CPU, | 
|  | 364 | StringRef FS) { | 
|  | 365 | initializeEnvironment(); | 
| Eric Christopher | b68e253 | 2014-09-03 20:36:31 +0000 | [diff] [blame] | 366 | initSubtargetFeatures(CPU, FS); | 
| Eric Christopher | 1a21203 | 2014-06-11 00:25:19 +0000 | [diff] [blame] | 367 | return *this; | 
|  | 368 | } | 
|  | 369 |  | 
| David Majnemer | ca29023 | 2016-05-20 18:16:06 +0000 | [diff] [blame] | 370 | X86Subtarget::X86Subtarget(const Triple &TT, StringRef CPU, StringRef FS, | 
|  | 371 | const X86TargetMachine &TM, | 
| Daniel Sanders | a1b2db79 | 2017-05-19 11:08:33 +0000 | [diff] [blame] | 372 | unsigned StackAlignOverride) | 
| Daniel Sanders | 50f1723 | 2015-09-15 16:17:27 +0000 | [diff] [blame] | 373 | : X86GenSubtargetInfo(TT, CPU, FS), X86ProcFamily(Others), | 
| Rafael Espindola | ab03eb0 | 2016-05-19 22:07:57 +0000 | [diff] [blame] | 374 | PICStyle(PICStyles::None), TM(TM), TargetTriple(TT), | 
| Eric Christopher | b8f9768 | 2014-05-07 21:05:47 +0000 | [diff] [blame] | 375 | StackAlignOverride(StackAlignOverride), | 
|  | 376 | In64BitMode(TargetTriple.getArch() == Triple::x86_64), | 
|  | 377 | In32BitMode(TargetTriple.getArch() == Triple::x86 && | 
|  | 378 | TargetTriple.getEnvironment() != Triple::CODE16), | 
|  | 379 | In16BitMode(TargetTriple.getArch() == Triple::x86 && | 
| Eric Christopher | a08f30b | 2014-06-09 17:08:19 +0000 | [diff] [blame] | 380 | TargetTriple.getEnvironment() == Triple::CODE16), | 
| Daniel Sanders | e9fdba3 | 2017-04-29 17:30:09 +0000 | [diff] [blame] | 381 | InstrInfo(initializeSubtargetDependencies(CPU, FS)), TLInfo(TM, *this), | 
| Daniel Sanders | a1b2db79 | 2017-05-19 11:08:33 +0000 | [diff] [blame] | 382 | FrameLowering(*this, getStackAlignment()) { | 
| Eric Christopher | 4629ed7 | 2014-08-09 01:07:25 +0000 | [diff] [blame] | 383 | // Determine the PICStyle based on the target selected. | 
| Rafael Espindola | 0d34826 | 2016-06-20 23:41:56 +0000 | [diff] [blame] | 384 | if (!isPositionIndependent()) | 
| Eric Christopher | 4629ed7 | 2014-08-09 01:07:25 +0000 | [diff] [blame] | 385 | setPICStyle(PICStyles::None); | 
| Rafael Espindola | 0d34826 | 2016-06-20 23:41:56 +0000 | [diff] [blame] | 386 | else if (is64Bit()) | 
| Eric Christopher | 4629ed7 | 2014-08-09 01:07:25 +0000 | [diff] [blame] | 387 | setPICStyle(PICStyles::RIPRel); | 
| Rafael Espindola | 0d34826 | 2016-06-20 23:41:56 +0000 | [diff] [blame] | 388 | else if (isTargetCOFF()) | 
| Eric Christopher | 4629ed7 | 2014-08-09 01:07:25 +0000 | [diff] [blame] | 389 | setPICStyle(PICStyles::None); | 
| Rafael Espindola | 0d34826 | 2016-06-20 23:41:56 +0000 | [diff] [blame] | 390 | else if (isTargetDarwin()) | 
|  | 391 | setPICStyle(PICStyles::StubPIC); | 
|  | 392 | else if (isTargetELF()) | 
| Eric Christopher | 4629ed7 | 2014-08-09 01:07:25 +0000 | [diff] [blame] | 393 | setPICStyle(PICStyles::GOT); | 
| Quentin Colombet | 8cf805a | 2017-07-01 00:45:50 +0000 | [diff] [blame] | 394 |  | 
| Quentin Colombet | 61d71a1 | 2017-08-15 22:31:51 +0000 | [diff] [blame] | 395 | CallLoweringInfo.reset(new X86CallLowering(*getTargetLowering())); | 
|  | 396 | Legalizer.reset(new X86LegalizerInfo(*this, TM)); | 
| Quentin Colombet | 8cf805a | 2017-07-01 00:45:50 +0000 | [diff] [blame] | 397 |  | 
|  | 398 | auto *RBI = new X86RegisterBankInfo(*getRegisterInfo()); | 
| Quentin Colombet | 61d71a1 | 2017-08-15 22:31:51 +0000 | [diff] [blame] | 399 | RegBankInfo.reset(RBI); | 
|  | 400 | InstSelector.reset(createX86InstructionSelector(TM, *this, *RBI)); | 
| Eric Christopher | 4629ed7 | 2014-08-09 01:07:25 +0000 | [diff] [blame] | 401 | } | 
| Bill Wendling | aef9c37 | 2013-02-15 22:31:27 +0000 | [diff] [blame] | 402 |  | 
| Zvi Rackover | 76dbf26 | 2016-11-15 06:34:33 +0000 | [diff] [blame] | 403 | const CallLowering *X86Subtarget::getCallLowering() const { | 
| Quentin Colombet | 61d71a1 | 2017-08-15 22:31:51 +0000 | [diff] [blame] | 404 | return CallLoweringInfo.get(); | 
| Zvi Rackover | 76dbf26 | 2016-11-15 06:34:33 +0000 | [diff] [blame] | 405 | } | 
|  | 406 |  | 
|  | 407 | const InstructionSelector *X86Subtarget::getInstructionSelector() const { | 
| Quentin Colombet | 61d71a1 | 2017-08-15 22:31:51 +0000 | [diff] [blame] | 408 | return InstSelector.get(); | 
| Zvi Rackover | 76dbf26 | 2016-11-15 06:34:33 +0000 | [diff] [blame] | 409 | } | 
|  | 410 |  | 
|  | 411 | const LegalizerInfo *X86Subtarget::getLegalizerInfo() const { | 
| Quentin Colombet | 61d71a1 | 2017-08-15 22:31:51 +0000 | [diff] [blame] | 412 | return Legalizer.get(); | 
| Zvi Rackover | 76dbf26 | 2016-11-15 06:34:33 +0000 | [diff] [blame] | 413 | } | 
|  | 414 |  | 
|  | 415 | const RegisterBankInfo *X86Subtarget::getRegBankInfo() const { | 
| Quentin Colombet | 61d71a1 | 2017-08-15 22:31:51 +0000 | [diff] [blame] | 416 | return RegBankInfo.get(); | 
| Zvi Rackover | 76dbf26 | 2016-11-15 06:34:33 +0000 | [diff] [blame] | 417 | } | 
|  | 418 |  | 
| Sanjay Patel | a2f658d | 2014-07-15 22:39:58 +0000 | [diff] [blame] | 419 | bool X86Subtarget::enableEarlyIfConversion() const { | 
| Eric Christopher | 3470bbb | 2014-05-21 23:51:57 +0000 | [diff] [blame] | 420 | return hasCMov() && X86EarlyIfConv; | 
| Eric Christopher | 6b0fcfe | 2014-05-21 23:40:26 +0000 | [diff] [blame] | 421 | } |