blob: c6ebaef587d9588752ba80a0299816efe433057d [file] [log] [blame]
Bill Wendling2bce78e2010-12-04 23:57:24 +00001//===-- X86Subtarget.cpp - X86 Subtarget Information ----------------------===//
Nate Begemanf26625e2005-07-12 01:41:54 +00002//
3// The LLVM Compiler Infrastructure
4//
Chris Lattnerf3ebc3f2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Nate Begemanf26625e2005-07-12 01:41:54 +00007//
8//===----------------------------------------------------------------------===//
9//
Evan Cheng0d639a22011-07-01 21:01:15 +000010// This file implements the X86 specific subclass of TargetSubtargetInfo.
Nate Begemanf26625e2005-07-12 01:41:54 +000011//
12//===----------------------------------------------------------------------===//
13
Quentin Colombet8cf805a2017-07-01 00:45:50 +000014#include "X86.h"
15
Quentin Colombet8cf805a2017-07-01 00:45:50 +000016#include "X86CallLowering.h"
17#include "X86LegalizerInfo.h"
18#include "X86RegisterBankInfo.h"
Nate Begemanf26625e2005-07-12 01:41:54 +000019#include "X86Subtarget.h"
Chandler Carruth6bda14b2017-06-06 11:49:48 +000020#include "MCTargetDesc/X86BaseInfo.h"
Eric Christopher4629ed72014-08-09 01:07:25 +000021#include "X86TargetMachine.h"
Eugene Zelenkofbd13c52017-02-02 22:55:55 +000022#include "llvm/ADT/Triple.h"
Quentin Colombet8cf805a2017-07-01 00:45:50 +000023#include "llvm/CodeGen/GlobalISel/CallLowering.h"
24#include "llvm/CodeGen/GlobalISel/InstructionSelect.h"
Bill Wendlingaef9c372013-02-15 22:31:27 +000025#include "llvm/IR/Attributes.h"
Peter Collingbournedc5e5832017-02-02 00:32:03 +000026#include "llvm/IR/ConstantRange.h"
Bill Wendlingaef9c372013-02-15 22:31:27 +000027#include "llvm/IR/Function.h"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000028#include "llvm/IR/GlobalValue.h"
Eugene Zelenkofbd13c52017-02-02 22:55:55 +000029#include "llvm/Support/Casting.h"
30#include "llvm/Support/CodeGen.h"
Eric Christopher3470bbb2014-05-21 23:51:57 +000031#include "llvm/Support/CommandLine.h"
Evan Cheng9a3ec1b2009-01-03 04:04:46 +000032#include "llvm/Support/Debug.h"
Rafael Espindola65596562011-09-07 16:10:57 +000033#include "llvm/Support/ErrorHandling.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000034#include "llvm/Support/raw_ostream.h"
Anton Korobeynikov430e68a12006-12-22 22:29:05 +000035#include "llvm/Target/TargetMachine.h"
Evan Cheng54b68e32011-07-01 20:45:01 +000036
Chris Lattner3ad60b12009-04-25 18:27:23 +000037#if defined(_MSC_VER)
Bill Wendling6eecd562009-08-03 00:11:34 +000038#include <intrin.h>
Chris Lattner3ad60b12009-04-25 18:27:23 +000039#endif
40
Chandler Carruth84e68b22014-04-22 02:41:26 +000041using namespace llvm;
42
43#define DEBUG_TYPE "subtarget"
44
Chandler Carruthd174b722014-04-22 02:03:14 +000045#define GET_SUBTARGETINFO_TARGET_DESC
46#define GET_SUBTARGETINFO_CTOR
47#include "X86GenSubtargetInfo.inc"
48
Eric Christopher6b0fcfe2014-05-21 23:40:26 +000049// Temporary option to control early if-conversion for x86 while adding machine
50// models.
51static cl::opt<bool>
52X86EarlyIfConv("x86-early-ifcvt", cl::Hidden,
53 cl::desc("Enable early if-conversion on X86"));
54
55
Sanjay Patel2e753412015-08-14 15:11:42 +000056/// Classify a blockaddress reference for the current subtarget according to how
57/// we should reference it in a non-pcrel context.
Rafael Espindolacb2d2662016-05-19 18:34:20 +000058unsigned char X86Subtarget::classifyBlockAddressReference() const {
Rafael Espindolac7e98132016-05-20 12:20:10 +000059 return classifyLocalReference(nullptr);
60}
Chad Rosier24c19d22012-08-01 18:39:17 +000061
Sanjay Patel2e753412015-08-14 15:11:42 +000062/// Classify a global variable reference for the current subtarget according to
63/// how we should reference it in a non-pcrel context.
Rafael Espindolaab03eb02016-05-19 22:07:57 +000064unsigned char
65X86Subtarget::classifyGlobalReference(const GlobalValue *GV) const {
Rafael Espindolac7e98132016-05-20 12:20:10 +000066 return classifyGlobalReference(GV, *GV->getParent());
67}
Chris Lattnerdc842c02009-07-10 07:20:05 +000068
Rafael Espindolac7e98132016-05-20 12:20:10 +000069unsigned char
70X86Subtarget::classifyLocalReference(const GlobalValue *GV) const {
71 // 64 bits can use %rip addressing for anything local.
72 if (is64Bit())
Chris Lattnerdc842c02009-07-10 07:20:05 +000073 return X86II::MO_NO_FLAG;
Chad Rosier24c19d22012-08-01 18:39:17 +000074
Rafael Espindolac7e98132016-05-20 12:20:10 +000075 // If this is for a position dependent executable, the static linker can
76 // figure it out.
Davide Italianoef5d8be2016-06-18 00:03:20 +000077 if (!isPositionIndependent())
Rafael Espindolac7e98132016-05-20 12:20:10 +000078 return X86II::MO_NO_FLAG;
Sriraman Tallam3cb77342016-04-22 21:41:58 +000079
Rafael Espindolac7e98132016-05-20 12:20:10 +000080 // The COFF dynamic linker just patches the executable sections.
81 if (isTargetCOFF())
82 return X86II::MO_NO_FLAG;
Chad Rosier24c19d22012-08-01 18:39:17 +000083
Rafael Espindolac7e98132016-05-20 12:20:10 +000084 if (isTargetDarwin()) {
85 // 32 bit macho has no relocation for a-b if a is undefined, even if
86 // b is in the section that is being relocated.
87 // This means we have to use o load even for GVs that are known to be
88 // local to the dso.
89 if (GV && (GV->isDeclarationForLinker() || GV->hasCommonLinkage()))
Chris Lattnerbd3e5602009-07-10 20:53:38 +000090 return X86II::MO_DARWIN_NONLAZY_PIC_BASE;
Chad Rosier24c19d22012-08-01 18:39:17 +000091
Chris Lattnerbd3e5602009-07-10 20:53:38 +000092 return X86II::MO_PIC_BASE_OFFSET;
93 }
Chad Rosier24c19d22012-08-01 18:39:17 +000094
Rafael Espindolac7e98132016-05-20 12:20:10 +000095 return X86II::MO_GOTOFF;
96}
Chad Rosier24c19d22012-08-01 18:39:17 +000097
Rafael Espindolac7e98132016-05-20 12:20:10 +000098unsigned char X86Subtarget::classifyGlobalReference(const GlobalValue *GV,
99 const Module &M) const {
100 // Large model never uses stubs.
101 if (TM.getCodeModel() == CodeModel::Large)
Chris Lattnerbd3e5602009-07-10 20:53:38 +0000102 return X86II::MO_NO_FLAG;
Rafael Espindolac7e98132016-05-20 12:20:10 +0000103
Peter Collingbourne235c2752016-12-08 19:01:00 +0000104 // Absolute symbols can be referenced directly.
Peter Collingbournedc5e5832017-02-02 00:32:03 +0000105 if (GV) {
106 if (Optional<ConstantRange> CR = GV->getAbsoluteSymbolRange()) {
107 // See if we can use the 8-bit immediate form. Note that some instructions
108 // will sign extend the immediate operand, so to be conservative we only
109 // accept the range [0,128).
110 if (CR->getUnsignedMax().ult(128))
111 return X86II::MO_ABS8;
112 else
113 return X86II::MO_NO_FLAG;
114 }
115 }
Peter Collingbourne235c2752016-12-08 19:01:00 +0000116
Rafael Espindola2393c3b2017-10-27 21:18:48 +0000117 if (TM.shouldAssumeDSOLocal(M, GV))
Rafael Espindolac7e98132016-05-20 12:20:10 +0000118 return classifyLocalReference(GV);
119
120 if (isTargetCOFF())
121 return X86II::MO_DLLIMPORT;
122
123 if (is64Bit())
124 return X86II::MO_GOTPCREL;
125
126 if (isTargetDarwin()) {
Davide Italianoef5d8be2016-06-18 00:03:20 +0000127 if (!isPositionIndependent())
Rafael Espindolac7e98132016-05-20 12:20:10 +0000128 return X86II::MO_DARWIN_NONLAZY;
129 return X86II::MO_DARWIN_NONLAZY_PIC_BASE;
Chris Lattnerdc842c02009-07-10 07:20:05 +0000130 }
Chad Rosier24c19d22012-08-01 18:39:17 +0000131
Rafael Espindolac7e98132016-05-20 12:20:10 +0000132 return X86II::MO_GOT;
Chris Lattnerdc842c02009-07-10 07:20:05 +0000133}
134
Rafael Espindola46107b92016-05-19 18:49:29 +0000135unsigned char
136X86Subtarget::classifyGlobalFunctionReference(const GlobalValue *GV) const {
Rafael Espindolac7e98132016-05-20 12:20:10 +0000137 return classifyGlobalFunctionReference(GV, *GV->getParent());
138}
139
140unsigned char
141X86Subtarget::classifyGlobalFunctionReference(const GlobalValue *GV,
142 const Module &M) const {
Rafael Espindola3beef8d2016-06-27 23:15:57 +0000143 if (TM.shouldAssumeDSOLocal(M, GV))
Rafael Espindolac7e98132016-05-20 12:20:10 +0000144 return X86II::MO_NO_FLAG;
145
Reid Kleckner7662d502017-08-05 00:10:43 +0000146 if (isTargetCOFF()) {
147 assert(GV->hasDLLImportStorageClass() &&
148 "shouldAssumeDSOLocal gave inconsistent answer");
149 return X86II::MO_DLLIMPORT;
150 }
151
Sriraman Tallam056b3fd2017-11-08 00:01:05 +0000152 const Function *F = dyn_cast_or_null<Function>(GV);
153
Oren Ben Simhon51de0332017-05-04 07:22:49 +0000154 if (isTargetELF()) {
155 if (is64Bit() && F && (CallingConv::X86_RegCall == F->getCallingConv()))
156 // According to psABI, PLT stub clobbers XMM8-XMM15.
157 // In Regcall calling convention those registers are used for passing
158 // parameters. Thus we need to prevent lazy binding in Regcall.
159 return X86II::MO_GOTPCREL;
Sriraman Tallam609f8c02018-02-23 21:32:06 +0000160 // If PLT must be avoided then the call should be via GOTPCREL.
161 if (((F && F->hasFnAttribute(Attribute::NonLazyBind)) ||
162 (!F && M.getRtLibUseGOT())) &&
163 is64Bit())
164 return X86II::MO_GOTPCREL;
Asaf Badouh89406d12016-04-20 08:32:57 +0000165 return X86II::MO_PLT;
Oren Ben Simhon51de0332017-05-04 07:22:49 +0000166 }
Rafael Espindolac7e98132016-05-20 12:20:10 +0000167
168 if (is64Bit()) {
Rafael Espindolac7e98132016-05-20 12:20:10 +0000169 if (F && F->hasFnAttribute(Attribute::NonLazyBind))
170 // If the function is marked as non-lazy, generate an indirect call
171 // which loads from the GOT directly. This avoids runtime overhead
172 // at the cost of eager binding (and one extra byte of encoding).
173 return X86II::MO_GOTPCREL;
174 return X86II::MO_NO_FLAG;
Asaf Badouh89406d12016-04-20 08:32:57 +0000175 }
176
177 return X86II::MO_NO_FLAG;
178}
Anton Korobeynikov6dbdfe22006-11-30 22:42:55 +0000179
Sanjay Patel2e753412015-08-14 15:11:42 +0000180/// Return true if the subtarget allows calls to immediate address.
Rafael Espindola46107b92016-05-19 18:49:29 +0000181bool X86Subtarget::isLegalToCallImmediateAddr() const {
David Majnemer02f21882014-03-28 21:40:47 +0000182 // FIXME: I386 PE/COFF supports PC relative calls using IMAGE_REL_I386_REL32
183 // but WinCOFFObjectWriter::RecordRelocation cannot emit them. Once it does,
184 // the following check for Win32 should be removed.
185 if (In64BitMode || isTargetWin32())
Evan Cheng96098332009-05-20 04:53:57 +0000186 return false;
Rafael Espindolaab03eb02016-05-19 22:07:57 +0000187 return isTargetELF() || TM.getRelocationModel() == Reloc::Static;
Evan Cheng96098332009-05-20 04:53:57 +0000188}
189
Eric Christopherb68e2532014-09-03 20:36:31 +0000190void X86Subtarget::initSubtargetFeatures(StringRef CPU, StringRef FS) {
Nadav Rotem08ab8772013-02-27 05:56:20 +0000191 std::string CPUName = CPU;
Jim Grosbach48551fb2014-04-12 01:34:29 +0000192 if (CPUName.empty())
193 CPUName = "generic";
Evan Cheng964cb5f2011-07-08 21:14:14 +0000194
Jim Grosbach48551fb2014-04-12 01:34:29 +0000195 // Make sure 64-bit features are available in 64-bit mode. (But make sure
196 // SSE2 can be turned off explicitly.)
197 std::string FullFS = FS;
198 if (In64BitMode) {
199 if (!FullFS.empty())
200 FullFS = "+64bit,+sse2," + FullFS;
201 else
202 FullFS = "+64bit,+sse2";
Evan Cheng11b0a5d2006-09-08 06:48:29 +0000203 }
Evan Chengc5e6d2f2011-07-11 03:57:24 +0000204
Hans Wennborg5000ce82015-12-04 23:00:33 +0000205 // LAHF/SAHF are always supported in non-64-bit mode.
206 if (!In64BitMode) {
207 if (!FullFS.empty())
208 FullFS = "+sahf," + FullFS;
209 else
210 FullFS = "+sahf";
211 }
212
Duncan P. N. Exon Smithbb57d732015-07-10 22:33:01 +0000213 // Parse features string and set the CPU.
Jim Grosbach48551fb2014-04-12 01:34:29 +0000214 ParseSubtargetFeatures(CPUName, FullFS);
215
Sanjay Pateldeb8f822015-08-25 16:29:21 +0000216 // All CPUs that implement SSE4.2 or SSE4A support unaligned accesses of
217 // 16-bytes and under that are reasonably fast. These features were
218 // introduced with Intel's Nehalem/Silvermont and AMD's Family10h
219 // micro-architectures respectively.
220 if (hasSSE42() || hasSSE4A())
Sanjay Patel30145672015-09-01 20:51:51 +0000221 IsUAMem16Slow = false;
Sanjay Pateldeb8f822015-08-25 16:29:21 +0000222
Andrew Tricke0c83b12012-08-07 00:25:30 +0000223 InstrItins = getInstrItineraryForCPU(CPUName);
Andrew Trick8523b162012-02-01 23:20:51 +0000224
Evan Chengc5e6d2f2011-07-11 03:57:24 +0000225 // It's important to keep the MCSubtargetInfo feature bits in sync with
226 // target data structure which is shared with MC code emitter, etc.
227 if (In64BitMode)
228 ToggleFeature(X86::Mode64Bit);
Craig Topper3c80d622014-01-06 04:55:54 +0000229 else if (In32BitMode)
230 ToggleFeature(X86::Mode32Bit);
231 else if (In16BitMode)
232 ToggleFeature(X86::Mode16Bit);
233 else
234 llvm_unreachable("Not 16-bit, 32-bit or 64-bit mode!");
Evan Chengc5e6d2f2011-07-11 03:57:24 +0000235
David Greene00411812010-01-05 01:29:13 +0000236 DEBUG(dbgs() << "Subtarget features: SSELevel " << X86SSELevel
Bill Wendling6eecd562009-08-03 00:11:34 +0000237 << ", 3DNowLevel " << X863DNowLevel
238 << ", 64bit " << HasX86_64 << "\n");
Evan Cheng13bcc6c2011-07-07 21:06:52 +0000239 assert((!In64BitMode || HasX86_64) &&
Dan Gohman74037512009-02-03 00:04:43 +0000240 "64-bit code requested on a subtarget that doesn't support it!");
Evan Cheng11b0a5d2006-09-08 06:48:29 +0000241
Marcin Koscielnicki0275fac2016-05-05 11:35:51 +0000242 // Stack alignment is 16 bytes on Darwin, Linux, kFreeBSD and Solaris (both
Roman Divackye8a93fe82011-02-22 17:30:05 +0000243 // 32 and 64 bit) and for all 64-bit targets.
Evan Cheng3a0c5e52011-06-23 17:54:54 +0000244 if (StackAlignOverride)
245 stackAlignment = StackAlignOverride;
Roman Divacky22135672012-11-09 20:10:44 +0000246 else if (isTargetDarwin() || isTargetLinux() || isTargetSolaris() ||
Marcin Koscielnicki0275fac2016-05-05 11:35:51 +0000247 isTargetKFreeBSD() || In64BitMode)
Nate Begemanf26625e2005-07-12 01:41:54 +0000248 stackAlignment = 16;
Craig Topper17078ff2017-11-19 01:11:58 +0000249
Craig Topperea37e202017-11-25 18:09:37 +0000250 // Some CPUs have more overhead for gather. The specified overhead is relative
251 // to the Load operation. "2" is the number provided by Intel architects. This
Craig Topper17078ff2017-11-19 01:11:58 +0000252 // parameter is used for cost estimation of Gather Op and comparison with
253 // other alternatives.
Craig Topperea37e202017-11-25 18:09:37 +0000254 // TODO: Remove the explicit hasAVX512()?, That would mean we would only
255 // enable gather with a -march.
256 if (hasAVX512() || (hasAVX2() && hasFastGather()))
Mohammed Agabariae9aebf22017-09-13 09:00:27 +0000257 GatherOverhead = 2;
258 if (hasAVX512())
259 ScatterOverhead = 2;
Craig Topper0d797a32018-01-20 00:26:08 +0000260
261 // Consume the vector width attribute or apply any target specific limit.
262 if (PreferVectorWidthOverride)
263 PreferVectorWidth = PreferVectorWidthOverride;
264 else if (Prefer256Bit)
265 PreferVectorWidth = 256;
Dan Gohmandc53f1c2010-05-27 18:43:40 +0000266}
Andrew Trick8523b162012-02-01 23:20:51 +0000267
Bill Wendling61375d82013-02-16 01:36:26 +0000268void X86Subtarget::initializeEnvironment() {
Eric Christopher11e59832015-10-08 20:10:06 +0000269 X86SSELevel = NoSSE;
Bill Wendling61375d82013-02-16 01:36:26 +0000270 X863DNowLevel = NoThreeDNow;
Andrey Turetskiy6a3d5612016-03-23 11:13:54 +0000271 HasX87 = false;
Craig Topper505f38a2018-01-10 22:07:16 +0000272 HasNOPL = false;
Bill Wendling61375d82013-02-16 01:36:26 +0000273 HasCMov = false;
274 HasX86_64 = false;
275 HasPOPCNT = false;
276 HasSSE4A = false;
277 HasAES = false;
Coby Tayree2a1c02f2017-11-21 09:11:41 +0000278 HasVAES = false;
Craig Topper09b65982015-10-16 06:03:09 +0000279 HasFXSR = false;
Amjad Aboud1db6d7a2015-10-12 11:47:46 +0000280 HasXSAVE = false;
281 HasXSAVEOPT = false;
282 HasXSAVEC = false;
283 HasXSAVES = false;
Bill Wendling61375d82013-02-16 01:36:26 +0000284 HasPCLMUL = false;
Coby Tayree7ca5e5872017-11-21 09:30:33 +0000285 HasVPCLMULQDQ = false;
Coby Tayreed8b17be2017-11-26 09:36:41 +0000286 HasGFNI = false;
Bill Wendling61375d82013-02-16 01:36:26 +0000287 HasFMA = false;
288 HasFMA4 = false;
289 HasXOP = false;
Yunzhong Gaodd36e932013-09-24 18:21:52 +0000290 HasTBM = false;
Simon Pilgrim99b925b2017-05-03 15:51:39 +0000291 HasLWP = false;
Bill Wendling61375d82013-02-16 01:36:26 +0000292 HasMOVBE = false;
293 HasRDRAND = false;
294 HasF16C = false;
295 HasFSGSBase = false;
296 HasLZCNT = false;
297 HasBMI = false;
298 HasBMI2 = false;
Michael Zuckerman97b6a6922016-01-17 13:42:12 +0000299 HasVBMI = false;
Coby Tayree71e37cc2017-11-21 09:48:44 +0000300 HasVBMI2 = false;
Elena Demikhovsky29cde352016-01-24 10:41:28 +0000301 HasIFMA = false;
Bill Wendling61375d82013-02-16 01:36:26 +0000302 HasRTM = false;
Elena Demikhovsky003e7d72013-07-28 08:28:38 +0000303 HasERI = false;
304 HasCDI = false;
Craig Topper7a8cf012013-08-20 05:23:59 +0000305 HasPFI = false;
Robert Khasanovbfa01312014-07-21 14:54:21 +0000306 HasDQI = false;
Oren Ben Simhon7bf27f02017-05-25 13:45:23 +0000307 HasVPOPCNTDQ = false;
Robert Khasanovbfa01312014-07-21 14:54:21 +0000308 HasBWI = false;
309 HasVLX = false;
Bill Wendling61375d82013-02-16 01:36:26 +0000310 HasADX = false;
Asaf Badouh5acf66f2015-12-15 13:35:29 +0000311 HasPKU = false;
Coby Tayree3880f2a2017-11-21 10:04:28 +0000312 HasVNNI = false;
Coby Tayree5c7fe5d2017-11-21 10:32:42 +0000313 HasBITALG = false;
Ben Langmuir16501752013-09-12 15:51:31 +0000314 HasSHA = false;
Craig Toppere2873a12017-12-22 03:53:14 +0000315 HasPREFETCHWT1 = false;
Michael Liao5173ee02013-03-26 17:47:11 +0000316 HasPRFCHW = false;
Michael Liaoa486a112013-03-28 23:41:26 +0000317 HasRDSEED = false;
Hans Wennborg5000ce82015-12-04 23:00:33 +0000318 HasLAHFSAHF = false;
Ashutosh Nema348af9c2016-05-18 11:59:12 +0000319 HasMWAITX = false;
Craig Topper50f3d142017-02-09 04:27:34 +0000320 HasCLZERO = false;
Elena Demikhovskyf7e641c2015-06-03 10:30:57 +0000321 HasMPX = false;
Oren Ben Simhonfa582b02017-11-26 13:02:45 +0000322 HasSHSTK = false;
323 HasIBT = false;
Tim Northover9bb69312017-05-01 17:50:15 +0000324 HasSGX = false;
325 HasCLFLUSHOPT = false;
326 HasCLWB = false;
Craig Topper84b26b92018-01-18 23:52:31 +0000327 HasRDPID = false;
Chandler Carruthc58f2162018-01-22 22:05:25 +0000328 UseRetpoline = false;
329 UseRetpolineExternalThunk = false;
Zvi Rackover8bc7e4d2016-12-06 19:35:20 +0000330 IsPMULLDSlow = false;
Ekaterina Romanovad5fa5542013-11-21 23:21:26 +0000331 IsSHLDSlow = false;
Sanjay Patel30145672015-09-01 20:51:51 +0000332 IsUAMem16Slow = false;
Sanjay Patel501890e2014-11-21 17:40:04 +0000333 IsUAMem32Slow = false;
Sanjay Patelffd039b2015-02-03 17:13:04 +0000334 HasSSEUnalignedMem = false;
Bill Wendling61375d82013-02-16 01:36:26 +0000335 HasCmpxchg16b = false;
336 UseLeaForSP = false;
Marina Yatsina77a21db2018-01-22 10:07:01 +0000337 HasPOPCNTFalseDeps = false;
338 HasLZCNTFalseDeps = false;
Simon Pilgrim3feaf2a2017-12-19 14:34:35 +0000339 HasFastVariableShuffle = false;
Amjad Aboud4f977512017-03-03 09:03:24 +0000340 HasFastPartialYMMorZMMWrite = false;
Simon Pilgrim02bdac52018-01-29 21:24:31 +0000341 HasFast11ByteNOP = false;
342 HasFast15ByteNOP = false;
Craig Topperea37e202017-11-25 18:09:37 +0000343 HasFastGather = false;
Nikolai Bozhenovf6795302016-08-04 12:47:28 +0000344 HasFastScalarFSQRT = false;
345 HasFastVectorFSQRT = false;
Pierre Gousseaub6d652a2016-10-14 16:41:38 +0000346 HasFastLZCNT = false;
Craig Topperd88389a2017-02-21 06:39:13 +0000347 HasFastSHLDRotate = false;
Craig Topper641e2af2017-08-30 04:34:48 +0000348 HasMacroFusion = false;
Clement Courbet203fc172017-04-21 09:20:50 +0000349 HasERMSB = false;
Alexey Volkovfd1731d2014-11-21 11:19:34 +0000350 HasSlowDivide32 = false;
351 HasSlowDivide64 = false;
Bill Wendling61375d82013-02-16 01:36:26 +0000352 PadShortFunctions = false;
Craig Topper62c47a22017-08-29 05:14:27 +0000353 SlowTwoMemOps = false;
Preston Gurd8b7ab4b2013-04-25 20:29:37 +0000354 LEAUsesAG = false;
Alexey Volkov6226de62014-05-20 08:55:50 +0000355 SlowLEA = false;
Lama Saba2ea271b2017-05-18 08:11:50 +0000356 Slow3OpsLEA = false;
Alexey Volkov5260dba2014-06-09 11:40:41 +0000357 SlowIncDec = false;
Bill Wendling61375d82013-02-16 01:36:26 +0000358 stackAlignment = 4;
359 // FIXME: this is a known good value for Yonah. How about others?
360 MaxInlineSizeThreshold = 128;
Eric Christopher824f42f2015-05-12 01:26:05 +0000361 UseSoftFloat = false;
Mohammed Agabariae9aebf22017-09-13 09:00:27 +0000362 X86ProcFamily = Others;
363 GatherOverhead = 1024;
364 ScatterOverhead = 1024;
Craig Topper0d797a32018-01-20 00:26:08 +0000365 PreferVectorWidth = UINT32_MAX;
366 Prefer256Bit = false;
Bill Wendling61375d82013-02-16 01:36:26 +0000367}
368
Eric Christopher1a212032014-06-11 00:25:19 +0000369X86Subtarget &X86Subtarget::initializeSubtargetDependencies(StringRef CPU,
370 StringRef FS) {
371 initializeEnvironment();
Eric Christopherb68e2532014-09-03 20:36:31 +0000372 initSubtargetFeatures(CPU, FS);
Eric Christopher1a212032014-06-11 00:25:19 +0000373 return *this;
374}
375
David Majnemerca290232016-05-20 18:16:06 +0000376X86Subtarget::X86Subtarget(const Triple &TT, StringRef CPU, StringRef FS,
377 const X86TargetMachine &TM,
Craig Topper0d797a32018-01-20 00:26:08 +0000378 unsigned StackAlignOverride,
Craig Topper24d3b282018-02-11 08:06:27 +0000379 unsigned PreferVectorWidthOverride,
380 unsigned RequiredVectorWidth)
Daniel Sanders50f17232015-09-15 16:17:27 +0000381 : X86GenSubtargetInfo(TT, CPU, FS), X86ProcFamily(Others),
Rafael Espindolaab03eb02016-05-19 22:07:57 +0000382 PICStyle(PICStyles::None), TM(TM), TargetTriple(TT),
Eric Christopherb8f97682014-05-07 21:05:47 +0000383 StackAlignOverride(StackAlignOverride),
Craig Topper0d797a32018-01-20 00:26:08 +0000384 PreferVectorWidthOverride(PreferVectorWidthOverride),
Craig Topper24d3b282018-02-11 08:06:27 +0000385 RequiredVectorWidth(RequiredVectorWidth),
Eric Christopherb8f97682014-05-07 21:05:47 +0000386 In64BitMode(TargetTriple.getArch() == Triple::x86_64),
387 In32BitMode(TargetTriple.getArch() == Triple::x86 &&
388 TargetTriple.getEnvironment() != Triple::CODE16),
389 In16BitMode(TargetTriple.getArch() == Triple::x86 &&
Eric Christophera08f30b2014-06-09 17:08:19 +0000390 TargetTriple.getEnvironment() == Triple::CODE16),
Daniel Sanderse9fdba32017-04-29 17:30:09 +0000391 InstrInfo(initializeSubtargetDependencies(CPU, FS)), TLInfo(TM, *this),
Daniel Sandersa1b2db792017-05-19 11:08:33 +0000392 FrameLowering(*this, getStackAlignment()) {
Eric Christopher4629ed72014-08-09 01:07:25 +0000393 // Determine the PICStyle based on the target selected.
Rafael Espindola0d348262016-06-20 23:41:56 +0000394 if (!isPositionIndependent())
Eric Christopher4629ed72014-08-09 01:07:25 +0000395 setPICStyle(PICStyles::None);
Rafael Espindola0d348262016-06-20 23:41:56 +0000396 else if (is64Bit())
Eric Christopher4629ed72014-08-09 01:07:25 +0000397 setPICStyle(PICStyles::RIPRel);
Rafael Espindola0d348262016-06-20 23:41:56 +0000398 else if (isTargetCOFF())
Eric Christopher4629ed72014-08-09 01:07:25 +0000399 setPICStyle(PICStyles::None);
Rafael Espindola0d348262016-06-20 23:41:56 +0000400 else if (isTargetDarwin())
401 setPICStyle(PICStyles::StubPIC);
402 else if (isTargetELF())
Eric Christopher4629ed72014-08-09 01:07:25 +0000403 setPICStyle(PICStyles::GOT);
Quentin Colombet8cf805a2017-07-01 00:45:50 +0000404
Quentin Colombet61d71a12017-08-15 22:31:51 +0000405 CallLoweringInfo.reset(new X86CallLowering(*getTargetLowering()));
406 Legalizer.reset(new X86LegalizerInfo(*this, TM));
Quentin Colombet8cf805a2017-07-01 00:45:50 +0000407
408 auto *RBI = new X86RegisterBankInfo(*getRegisterInfo());
Quentin Colombet61d71a12017-08-15 22:31:51 +0000409 RegBankInfo.reset(RBI);
410 InstSelector.reset(createX86InstructionSelector(TM, *this, *RBI));
Eric Christopher4629ed72014-08-09 01:07:25 +0000411}
Bill Wendlingaef9c372013-02-15 22:31:27 +0000412
Zvi Rackover76dbf262016-11-15 06:34:33 +0000413const CallLowering *X86Subtarget::getCallLowering() const {
Quentin Colombet61d71a12017-08-15 22:31:51 +0000414 return CallLoweringInfo.get();
Zvi Rackover76dbf262016-11-15 06:34:33 +0000415}
416
417const InstructionSelector *X86Subtarget::getInstructionSelector() const {
Quentin Colombet61d71a12017-08-15 22:31:51 +0000418 return InstSelector.get();
Zvi Rackover76dbf262016-11-15 06:34:33 +0000419}
420
421const LegalizerInfo *X86Subtarget::getLegalizerInfo() const {
Quentin Colombet61d71a12017-08-15 22:31:51 +0000422 return Legalizer.get();
Zvi Rackover76dbf262016-11-15 06:34:33 +0000423}
424
425const RegisterBankInfo *X86Subtarget::getRegBankInfo() const {
Quentin Colombet61d71a12017-08-15 22:31:51 +0000426 return RegBankInfo.get();
Zvi Rackover76dbf262016-11-15 06:34:33 +0000427}
428
Sanjay Patela2f658d2014-07-15 22:39:58 +0000429bool X86Subtarget::enableEarlyIfConversion() const {
Eric Christopher3470bbb2014-05-21 23:51:57 +0000430 return hasCMov() && X86EarlyIfConv;
Eric Christopher6b0fcfe2014-05-21 23:40:26 +0000431}