blob: 1b02b88c18707e17250a08f0228226c9371aa5a8 [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"
25#include "llvm/CodeGen/GlobalISel/Legalizer.h"
26#include "llvm/CodeGen/GlobalISel/RegBankSelect.h"
Bill Wendlingaef9c372013-02-15 22:31:27 +000027#include "llvm/IR/Attributes.h"
Peter Collingbournedc5e5832017-02-02 00:32:03 +000028#include "llvm/IR/ConstantRange.h"
Bill Wendlingaef9c372013-02-15 22:31:27 +000029#include "llvm/IR/Function.h"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000030#include "llvm/IR/GlobalValue.h"
Eugene Zelenkofbd13c52017-02-02 22:55:55 +000031#include "llvm/Support/Casting.h"
32#include "llvm/Support/CodeGen.h"
Eric Christopher3470bbb2014-05-21 23:51:57 +000033#include "llvm/Support/CommandLine.h"
Evan Cheng9a3ec1b2009-01-03 04:04:46 +000034#include "llvm/Support/Debug.h"
Rafael Espindola65596562011-09-07 16:10:57 +000035#include "llvm/Support/ErrorHandling.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000036#include "llvm/Support/raw_ostream.h"
Anton Korobeynikov430e68a12006-12-22 22:29:05 +000037#include "llvm/Target/TargetMachine.h"
Eugene Zelenkofbd13c52017-02-02 22:55:55 +000038#include <cassert>
39#include <string>
Evan Cheng54b68e32011-07-01 20:45:01 +000040
Chris Lattner3ad60b12009-04-25 18:27:23 +000041#if defined(_MSC_VER)
Bill Wendling6eecd562009-08-03 00:11:34 +000042#include <intrin.h>
Chris Lattner3ad60b12009-04-25 18:27:23 +000043#endif
44
Chandler Carruth84e68b22014-04-22 02:41:26 +000045using namespace llvm;
46
47#define DEBUG_TYPE "subtarget"
48
Chandler Carruthd174b722014-04-22 02:03:14 +000049#define GET_SUBTARGETINFO_TARGET_DESC
50#define GET_SUBTARGETINFO_CTOR
51#include "X86GenSubtargetInfo.inc"
52
Eric Christopher6b0fcfe2014-05-21 23:40:26 +000053// Temporary option to control early if-conversion for x86 while adding machine
54// models.
55static cl::opt<bool>
56X86EarlyIfConv("x86-early-ifcvt", cl::Hidden,
57 cl::desc("Enable early if-conversion on X86"));
58
59
Sanjay Patel2e753412015-08-14 15:11:42 +000060/// Classify a blockaddress reference for the current subtarget according to how
61/// we should reference it in a non-pcrel context.
Rafael Espindolacb2d2662016-05-19 18:34:20 +000062unsigned char X86Subtarget::classifyBlockAddressReference() const {
Rafael Espindolac7e98132016-05-20 12:20:10 +000063 return classifyLocalReference(nullptr);
64}
Chad Rosier24c19d22012-08-01 18:39:17 +000065
Sanjay Patel2e753412015-08-14 15:11:42 +000066/// Classify a global variable reference for the current subtarget according to
67/// how we should reference it in a non-pcrel context.
Rafael Espindolaab03eb02016-05-19 22:07:57 +000068unsigned char
69X86Subtarget::classifyGlobalReference(const GlobalValue *GV) const {
Rafael Espindolac7e98132016-05-20 12:20:10 +000070 return classifyGlobalReference(GV, *GV->getParent());
71}
Chris Lattnerdc842c02009-07-10 07:20:05 +000072
Rafael Espindolac7e98132016-05-20 12:20:10 +000073unsigned char
74X86Subtarget::classifyLocalReference(const GlobalValue *GV) const {
75 // 64 bits can use %rip addressing for anything local.
76 if (is64Bit())
Chris Lattnerdc842c02009-07-10 07:20:05 +000077 return X86II::MO_NO_FLAG;
Chad Rosier24c19d22012-08-01 18:39:17 +000078
Rafael Espindolac7e98132016-05-20 12:20:10 +000079 // If this is for a position dependent executable, the static linker can
80 // figure it out.
Davide Italianoef5d8be2016-06-18 00:03:20 +000081 if (!isPositionIndependent())
Rafael Espindolac7e98132016-05-20 12:20:10 +000082 return X86II::MO_NO_FLAG;
Sriraman Tallam3cb77342016-04-22 21:41:58 +000083
Rafael Espindolac7e98132016-05-20 12:20:10 +000084 // The COFF dynamic linker just patches the executable sections.
85 if (isTargetCOFF())
86 return X86II::MO_NO_FLAG;
Chad Rosier24c19d22012-08-01 18:39:17 +000087
Rafael Espindolac7e98132016-05-20 12:20:10 +000088 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 Lattnerbd3e5602009-07-10 20:53:38 +000094 return X86II::MO_DARWIN_NONLAZY_PIC_BASE;
Chad Rosier24c19d22012-08-01 18:39:17 +000095
Chris Lattnerbd3e5602009-07-10 20:53:38 +000096 return X86II::MO_PIC_BASE_OFFSET;
97 }
Chad Rosier24c19d22012-08-01 18:39:17 +000098
Rafael Espindolac7e98132016-05-20 12:20:10 +000099 return X86II::MO_GOTOFF;
100}
Chad Rosier24c19d22012-08-01 18:39:17 +0000101
Rafael Espindolab8956a72017-08-11 20:49:27 +0000102static bool shouldAssumeGlobalReferenceLocal(const X86Subtarget *ST,
103 const TargetMachine &TM,
104 const Module &M,
105 const GlobalValue *GV) {
106 if (!TM.shouldAssumeDSOLocal(M, GV))
107 return false;
108 // A weak reference can end up being 0. If the code can be more that 4g away
109 // from zero and we are using the small code model we have to treat it as non
110 // local.
111 if (GV && GV->hasExternalWeakLinkage() &&
112 TM.getCodeModel() == CodeModel::Small && TM.isPositionIndependent() &&
113 ST->is64Bit() && ST->isTargetELF())
114 return false;
115 return true;
116}
117
Rafael Espindolac7e98132016-05-20 12:20:10 +0000118unsigned char X86Subtarget::classifyGlobalReference(const GlobalValue *GV,
119 const Module &M) const {
120 // Large model never uses stubs.
121 if (TM.getCodeModel() == CodeModel::Large)
Chris Lattnerbd3e5602009-07-10 20:53:38 +0000122 return X86II::MO_NO_FLAG;
Rafael Espindolac7e98132016-05-20 12:20:10 +0000123
Peter Collingbourne235c2752016-12-08 19:01:00 +0000124 // Absolute symbols can be referenced directly.
Peter Collingbournedc5e5832017-02-02 00:32:03 +0000125 if (GV) {
126 if (Optional<ConstantRange> CR = GV->getAbsoluteSymbolRange()) {
127 // See if we can use the 8-bit immediate form. Note that some instructions
128 // will sign extend the immediate operand, so to be conservative we only
129 // accept the range [0,128).
130 if (CR->getUnsignedMax().ult(128))
131 return X86II::MO_ABS8;
132 else
133 return X86II::MO_NO_FLAG;
134 }
135 }
Peter Collingbourne235c2752016-12-08 19:01:00 +0000136
Rafael Espindolab8956a72017-08-11 20:49:27 +0000137 if (shouldAssumeGlobalReferenceLocal(this, TM, M, GV))
Rafael Espindolac7e98132016-05-20 12:20:10 +0000138 return classifyLocalReference(GV);
139
140 if (isTargetCOFF())
141 return X86II::MO_DLLIMPORT;
142
143 if (is64Bit())
144 return X86II::MO_GOTPCREL;
145
146 if (isTargetDarwin()) {
Davide Italianoef5d8be2016-06-18 00:03:20 +0000147 if (!isPositionIndependent())
Rafael Espindolac7e98132016-05-20 12:20:10 +0000148 return X86II::MO_DARWIN_NONLAZY;
149 return X86II::MO_DARWIN_NONLAZY_PIC_BASE;
Chris Lattnerdc842c02009-07-10 07:20:05 +0000150 }
Chad Rosier24c19d22012-08-01 18:39:17 +0000151
Rafael Espindolac7e98132016-05-20 12:20:10 +0000152 return X86II::MO_GOT;
Chris Lattnerdc842c02009-07-10 07:20:05 +0000153}
154
Rafael Espindola46107b92016-05-19 18:49:29 +0000155unsigned char
156X86Subtarget::classifyGlobalFunctionReference(const GlobalValue *GV) const {
Rafael Espindolac7e98132016-05-20 12:20:10 +0000157 return classifyGlobalFunctionReference(GV, *GV->getParent());
158}
159
160unsigned char
161X86Subtarget::classifyGlobalFunctionReference(const GlobalValue *GV,
162 const Module &M) const {
Rafael Espindola3beef8d2016-06-27 23:15:57 +0000163 if (TM.shouldAssumeDSOLocal(M, GV))
Rafael Espindolac7e98132016-05-20 12:20:10 +0000164 return X86II::MO_NO_FLAG;
165
Reid Kleckner7662d502017-08-05 00:10:43 +0000166 if (isTargetCOFF()) {
167 assert(GV->hasDLLImportStorageClass() &&
168 "shouldAssumeDSOLocal gave inconsistent answer");
169 return X86II::MO_DLLIMPORT;
170 }
171
Oren Ben Simhon51de0332017-05-04 07:22:49 +0000172 const Function *F = dyn_cast_or_null<Function>(GV);
Rafael Espindolac7e98132016-05-20 12:20:10 +0000173
Oren Ben Simhon51de0332017-05-04 07:22:49 +0000174 if (isTargetELF()) {
175 if (is64Bit() && F && (CallingConv::X86_RegCall == F->getCallingConv()))
176 // According to psABI, PLT stub clobbers XMM8-XMM15.
177 // In Regcall calling convention those registers are used for passing
178 // parameters. Thus we need to prevent lazy binding in Regcall.
179 return X86II::MO_GOTPCREL;
Asaf Badouh89406d12016-04-20 08:32:57 +0000180 return X86II::MO_PLT;
Oren Ben Simhon51de0332017-05-04 07:22:49 +0000181 }
Rafael Espindolac7e98132016-05-20 12:20:10 +0000182
183 if (is64Bit()) {
Rafael Espindolac7e98132016-05-20 12:20:10 +0000184 if (F && F->hasFnAttribute(Attribute::NonLazyBind))
185 // If the function is marked as non-lazy, generate an indirect call
186 // which loads from the GOT directly. This avoids runtime overhead
187 // at the cost of eager binding (and one extra byte of encoding).
188 return X86II::MO_GOTPCREL;
189 return X86II::MO_NO_FLAG;
Asaf Badouh89406d12016-04-20 08:32:57 +0000190 }
191
192 return X86II::MO_NO_FLAG;
193}
Anton Korobeynikov6dbdfe22006-11-30 22:42:55 +0000194
Sanjay Patel2e753412015-08-14 15:11:42 +0000195/// This function returns the name of a function which has an interface like
196/// the non-standard bzero function, if such a function exists on the
197/// current subtarget and it is considered preferable over memset with zero
Bill Wendlingbd092622008-09-30 21:22:07 +0000198/// passed as the second argument. Otherwise it returns null.
Bill Wendling17825842008-09-30 22:05:33 +0000199const char *X86Subtarget::getBZeroEntry() const {
Dan Gohman980d7202008-04-01 20:38:36 +0000200 // Darwin 10 has a __bzero entry point for this purpose.
Daniel Dunbarcd01ed52011-04-20 00:14:25 +0000201 if (getTargetTriple().isMacOSX() &&
202 !getTargetTriple().isMacOSXVersionLT(10, 6))
Bill Wendling17825842008-09-30 22:05:33 +0000203 return "__bzero";
Dan Gohman980d7202008-04-01 20:38:36 +0000204
Craig Topper062a2ba2014-04-25 05:30:21 +0000205 return nullptr;
Dan Gohman980d7202008-04-01 20:38:36 +0000206}
207
Evan Cheng0e88c7d2013-01-29 02:32:37 +0000208bool X86Subtarget::hasSinCos() const {
Petr Hosek710479c2017-07-23 22:30:00 +0000209 if (getTargetTriple().isMacOSX()) {
210 return !getTargetTriple().isMacOSXVersionLT(10, 9) && is64Bit();
211 } else if (getTargetTriple().isOSFuchsia()) {
212 return true;
213 }
214 return false;
Evan Cheng0e88c7d2013-01-29 02:32:37 +0000215}
216
Sanjay Patel2e753412015-08-14 15:11:42 +0000217/// Return true if the subtarget allows calls to immediate address.
Rafael Espindola46107b92016-05-19 18:49:29 +0000218bool X86Subtarget::isLegalToCallImmediateAddr() const {
David Majnemer02f21882014-03-28 21:40:47 +0000219 // FIXME: I386 PE/COFF supports PC relative calls using IMAGE_REL_I386_REL32
220 // but WinCOFFObjectWriter::RecordRelocation cannot emit them. Once it does,
221 // the following check for Win32 should be removed.
222 if (In64BitMode || isTargetWin32())
Evan Cheng96098332009-05-20 04:53:57 +0000223 return false;
Rafael Espindolaab03eb02016-05-19 22:07:57 +0000224 return isTargetELF() || TM.getRelocationModel() == Reloc::Static;
Evan Cheng96098332009-05-20 04:53:57 +0000225}
226
Eric Christopherb68e2532014-09-03 20:36:31 +0000227void X86Subtarget::initSubtargetFeatures(StringRef CPU, StringRef FS) {
Nadav Rotem08ab8772013-02-27 05:56:20 +0000228 std::string CPUName = CPU;
Jim Grosbach48551fb2014-04-12 01:34:29 +0000229 if (CPUName.empty())
230 CPUName = "generic";
Evan Cheng964cb5f2011-07-08 21:14:14 +0000231
Jim Grosbach48551fb2014-04-12 01:34:29 +0000232 // Make sure 64-bit features are available in 64-bit mode. (But make sure
233 // SSE2 can be turned off explicitly.)
234 std::string FullFS = FS;
235 if (In64BitMode) {
236 if (!FullFS.empty())
237 FullFS = "+64bit,+sse2," + FullFS;
238 else
239 FullFS = "+64bit,+sse2";
Evan Cheng11b0a5d2006-09-08 06:48:29 +0000240 }
Evan Chengc5e6d2f2011-07-11 03:57:24 +0000241
Hans Wennborg5000ce82015-12-04 23:00:33 +0000242 // LAHF/SAHF are always supported in non-64-bit mode.
243 if (!In64BitMode) {
244 if (!FullFS.empty())
245 FullFS = "+sahf," + FullFS;
246 else
247 FullFS = "+sahf";
248 }
249
Duncan P. N. Exon Smithbb57d732015-07-10 22:33:01 +0000250 // Parse features string and set the CPU.
Jim Grosbach48551fb2014-04-12 01:34:29 +0000251 ParseSubtargetFeatures(CPUName, FullFS);
252
Sanjay Pateldeb8f822015-08-25 16:29:21 +0000253 // All CPUs that implement SSE4.2 or SSE4A support unaligned accesses of
254 // 16-bytes and under that are reasonably fast. These features were
255 // introduced with Intel's Nehalem/Silvermont and AMD's Family10h
256 // micro-architectures respectively.
257 if (hasSSE42() || hasSSE4A())
Sanjay Patel30145672015-09-01 20:51:51 +0000258 IsUAMem16Slow = false;
Sanjay Pateldeb8f822015-08-25 16:29:21 +0000259
Andrew Tricke0c83b12012-08-07 00:25:30 +0000260 InstrItins = getInstrItineraryForCPU(CPUName);
Andrew Trick8523b162012-02-01 23:20:51 +0000261
Evan Chengc5e6d2f2011-07-11 03:57:24 +0000262 // It's important to keep the MCSubtargetInfo feature bits in sync with
263 // target data structure which is shared with MC code emitter, etc.
264 if (In64BitMode)
265 ToggleFeature(X86::Mode64Bit);
Craig Topper3c80d622014-01-06 04:55:54 +0000266 else if (In32BitMode)
267 ToggleFeature(X86::Mode32Bit);
268 else if (In16BitMode)
269 ToggleFeature(X86::Mode16Bit);
270 else
271 llvm_unreachable("Not 16-bit, 32-bit or 64-bit mode!");
Evan Chengc5e6d2f2011-07-11 03:57:24 +0000272
David Greene00411812010-01-05 01:29:13 +0000273 DEBUG(dbgs() << "Subtarget features: SSELevel " << X86SSELevel
Bill Wendling6eecd562009-08-03 00:11:34 +0000274 << ", 3DNowLevel " << X863DNowLevel
275 << ", 64bit " << HasX86_64 << "\n");
Evan Cheng13bcc6c2011-07-07 21:06:52 +0000276 assert((!In64BitMode || HasX86_64) &&
Dan Gohman74037512009-02-03 00:04:43 +0000277 "64-bit code requested on a subtarget that doesn't support it!");
Evan Cheng11b0a5d2006-09-08 06:48:29 +0000278
Marcin Koscielnicki0275fac2016-05-05 11:35:51 +0000279 // Stack alignment is 16 bytes on Darwin, Linux, kFreeBSD and Solaris (both
Roman Divackye8a93fe82011-02-22 17:30:05 +0000280 // 32 and 64 bit) and for all 64-bit targets.
Evan Cheng3a0c5e52011-06-23 17:54:54 +0000281 if (StackAlignOverride)
282 stackAlignment = StackAlignOverride;
Roman Divacky22135672012-11-09 20:10:44 +0000283 else if (isTargetDarwin() || isTargetLinux() || isTargetSolaris() ||
Marcin Koscielnicki0275fac2016-05-05 11:35:51 +0000284 isTargetKFreeBSD() || In64BitMode)
Nate Begemanf26625e2005-07-12 01:41:54 +0000285 stackAlignment = 16;
Dan Gohmandc53f1c2010-05-27 18:43:40 +0000286}
Andrew Trick8523b162012-02-01 23:20:51 +0000287
Bill Wendling61375d82013-02-16 01:36:26 +0000288void X86Subtarget::initializeEnvironment() {
Eric Christopher11e59832015-10-08 20:10:06 +0000289 X86SSELevel = NoSSE;
Bill Wendling61375d82013-02-16 01:36:26 +0000290 X863DNowLevel = NoThreeDNow;
Andrey Turetskiy6a3d5612016-03-23 11:13:54 +0000291 HasX87 = false;
Bill Wendling61375d82013-02-16 01:36:26 +0000292 HasCMov = false;
293 HasX86_64 = false;
294 HasPOPCNT = false;
295 HasSSE4A = false;
296 HasAES = false;
Craig Topper09b65982015-10-16 06:03:09 +0000297 HasFXSR = false;
Amjad Aboud1db6d7a2015-10-12 11:47:46 +0000298 HasXSAVE = false;
299 HasXSAVEOPT = false;
300 HasXSAVEC = false;
301 HasXSAVES = false;
Bill Wendling61375d82013-02-16 01:36:26 +0000302 HasPCLMUL = false;
303 HasFMA = false;
304 HasFMA4 = false;
305 HasXOP = false;
Yunzhong Gaodd36e932013-09-24 18:21:52 +0000306 HasTBM = false;
Simon Pilgrim99b925b2017-05-03 15:51:39 +0000307 HasLWP = false;
Bill Wendling61375d82013-02-16 01:36:26 +0000308 HasMOVBE = false;
309 HasRDRAND = false;
310 HasF16C = false;
311 HasFSGSBase = false;
312 HasLZCNT = false;
313 HasBMI = false;
314 HasBMI2 = false;
Michael Zuckerman97b6a6922016-01-17 13:42:12 +0000315 HasVBMI = false;
Elena Demikhovsky29cde352016-01-24 10:41:28 +0000316 HasIFMA = false;
Bill Wendling61375d82013-02-16 01:36:26 +0000317 HasRTM = false;
Elena Demikhovsky003e7d72013-07-28 08:28:38 +0000318 HasERI = false;
319 HasCDI = false;
Craig Topper7a8cf012013-08-20 05:23:59 +0000320 HasPFI = false;
Robert Khasanovbfa01312014-07-21 14:54:21 +0000321 HasDQI = false;
Oren Ben Simhon7bf27f02017-05-25 13:45:23 +0000322 HasVPOPCNTDQ = false;
Robert Khasanovbfa01312014-07-21 14:54:21 +0000323 HasBWI = false;
324 HasVLX = false;
Bill Wendling61375d82013-02-16 01:36:26 +0000325 HasADX = false;
Asaf Badouh5acf66f2015-12-15 13:35:29 +0000326 HasPKU = false;
Ben Langmuir16501752013-09-12 15:51:31 +0000327 HasSHA = false;
Michael Liao5173ee02013-03-26 17:47:11 +0000328 HasPRFCHW = false;
Michael Liaoa486a112013-03-28 23:41:26 +0000329 HasRDSEED = false;
Hans Wennborg5000ce82015-12-04 23:00:33 +0000330 HasLAHFSAHF = false;
Ashutosh Nema348af9c2016-05-18 11:59:12 +0000331 HasMWAITX = false;
Craig Topper50f3d142017-02-09 04:27:34 +0000332 HasCLZERO = false;
Elena Demikhovskyf7e641c2015-06-03 10:30:57 +0000333 HasMPX = false;
Tim Northover9bb69312017-05-01 17:50:15 +0000334 HasSGX = false;
335 HasCLFLUSHOPT = false;
336 HasCLWB = false;
Bill Wendling61375d82013-02-16 01:36:26 +0000337 IsBTMemSlow = false;
Zvi Rackover8bc7e4d2016-12-06 19:35:20 +0000338 IsPMULLDSlow = false;
Ekaterina Romanovad5fa5542013-11-21 23:21:26 +0000339 IsSHLDSlow = false;
Sanjay Patel30145672015-09-01 20:51:51 +0000340 IsUAMem16Slow = false;
Sanjay Patel501890e2014-11-21 17:40:04 +0000341 IsUAMem32Slow = false;
Sanjay Patelffd039b2015-02-03 17:13:04 +0000342 HasSSEUnalignedMem = false;
Bill Wendling61375d82013-02-16 01:36:26 +0000343 HasCmpxchg16b = false;
344 UseLeaForSP = false;
Amjad Aboud4f977512017-03-03 09:03:24 +0000345 HasFastPartialYMMorZMMWrite = false;
Nikolai Bozhenovf6795302016-08-04 12:47:28 +0000346 HasFastScalarFSQRT = false;
347 HasFastVectorFSQRT = false;
Pierre Gousseaub6d652a2016-10-14 16:41:38 +0000348 HasFastLZCNT = false;
Craig Topperd88389a2017-02-21 06:39:13 +0000349 HasFastSHLDRotate = false;
Clement Courbet203fc172017-04-21 09:20:50 +0000350 HasERMSB = false;
Alexey Volkovfd1731d2014-11-21 11:19:34 +0000351 HasSlowDivide32 = false;
352 HasSlowDivide64 = false;
Bill Wendling61375d82013-02-16 01:36:26 +0000353 PadShortFunctions = false;
Preston Gurd663e6f92013-03-27 19:14:02 +0000354 CallRegIndirect = false;
Preston Gurd8b7ab4b2013-04-25 20:29:37 +0000355 LEAUsesAG = false;
Alexey Volkov6226de62014-05-20 08:55:50 +0000356 SlowLEA = false;
Lama Saba2ea271b2017-05-18 08:11:50 +0000357 Slow3OpsLEA = false;
Alexey Volkov5260dba2014-06-09 11:40:41 +0000358 SlowIncDec = false;
Bill Wendling61375d82013-02-16 01:36:26 +0000359 stackAlignment = 4;
360 // FIXME: this is a known good value for Yonah. How about others?
361 MaxInlineSizeThreshold = 128;
Eric Christopher824f42f2015-05-12 01:26:05 +0000362 UseSoftFloat = false;
Bill Wendling61375d82013-02-16 01:36:26 +0000363}
364
Eric Christopher1a212032014-06-11 00:25:19 +0000365X86Subtarget &X86Subtarget::initializeSubtargetDependencies(StringRef CPU,
366 StringRef FS) {
367 initializeEnvironment();
Eric Christopherb68e2532014-09-03 20:36:31 +0000368 initSubtargetFeatures(CPU, FS);
Eric Christopher1a212032014-06-11 00:25:19 +0000369 return *this;
370}
371
Quentin Colombet8dd90fb2017-08-08 22:22:30 +0000372namespace {
373
374struct X86GISelActualAccessor : public GISelAccessor {
375 std::unique_ptr<CallLowering> CallLoweringInfo;
376 std::unique_ptr<LegalizerInfo> Legalizer;
377 std::unique_ptr<RegisterBankInfo> RegBankInfo;
378 std::unique_ptr<InstructionSelector> InstSelector;
379
380 const CallLowering *getCallLowering() const override {
381 return CallLoweringInfo.get();
382 }
383
384 const InstructionSelector *getInstructionSelector() const override {
385 return InstSelector.get();
386 }
387
388 const LegalizerInfo *getLegalizerInfo() const override {
389 return Legalizer.get();
390 }
391
392 const RegisterBankInfo *getRegBankInfo() const override {
393 return RegBankInfo.get();
394 }
395};
396
397} // end anonymous namespace
398
David Majnemerca290232016-05-20 18:16:06 +0000399X86Subtarget::X86Subtarget(const Triple &TT, StringRef CPU, StringRef FS,
400 const X86TargetMachine &TM,
Daniel Sandersa1b2db792017-05-19 11:08:33 +0000401 unsigned StackAlignOverride)
Daniel Sanders50f17232015-09-15 16:17:27 +0000402 : X86GenSubtargetInfo(TT, CPU, FS), X86ProcFamily(Others),
Rafael Espindolaab03eb02016-05-19 22:07:57 +0000403 PICStyle(PICStyles::None), TM(TM), TargetTriple(TT),
Eric Christopherb8f97682014-05-07 21:05:47 +0000404 StackAlignOverride(StackAlignOverride),
405 In64BitMode(TargetTriple.getArch() == Triple::x86_64),
406 In32BitMode(TargetTriple.getArch() == Triple::x86 &&
407 TargetTriple.getEnvironment() != Triple::CODE16),
408 In16BitMode(TargetTriple.getArch() == Triple::x86 &&
Eric Christophera08f30b2014-06-09 17:08:19 +0000409 TargetTriple.getEnvironment() == Triple::CODE16),
Daniel Sanderse9fdba32017-04-29 17:30:09 +0000410 InstrInfo(initializeSubtargetDependencies(CPU, FS)), TLInfo(TM, *this),
Daniel Sandersa1b2db792017-05-19 11:08:33 +0000411 FrameLowering(*this, getStackAlignment()) {
Eric Christopher4629ed72014-08-09 01:07:25 +0000412 // Determine the PICStyle based on the target selected.
Rafael Espindola0d348262016-06-20 23:41:56 +0000413 if (!isPositionIndependent())
Eric Christopher4629ed72014-08-09 01:07:25 +0000414 setPICStyle(PICStyles::None);
Rafael Espindola0d348262016-06-20 23:41:56 +0000415 else if (is64Bit())
Eric Christopher4629ed72014-08-09 01:07:25 +0000416 setPICStyle(PICStyles::RIPRel);
Rafael Espindola0d348262016-06-20 23:41:56 +0000417 else if (isTargetCOFF())
Eric Christopher4629ed72014-08-09 01:07:25 +0000418 setPICStyle(PICStyles::None);
Rafael Espindola0d348262016-06-20 23:41:56 +0000419 else if (isTargetDarwin())
420 setPICStyle(PICStyles::StubPIC);
421 else if (isTargetELF())
Eric Christopher4629ed72014-08-09 01:07:25 +0000422 setPICStyle(PICStyles::GOT);
Quentin Colombet8dd90fb2017-08-08 22:22:30 +0000423 X86GISelActualAccessor *GISel = new X86GISelActualAccessor();
Quentin Colombet8cf805a2017-07-01 00:45:50 +0000424
Quentin Colombet8dd90fb2017-08-08 22:22:30 +0000425 GISel->CallLoweringInfo.reset(new X86CallLowering(*getTargetLowering()));
426 GISel->Legalizer.reset(new X86LegalizerInfo(*this, TM));
Quentin Colombet8cf805a2017-07-01 00:45:50 +0000427
428 auto *RBI = new X86RegisterBankInfo(*getRegisterInfo());
Quentin Colombet8dd90fb2017-08-08 22:22:30 +0000429 GISel->RegBankInfo.reset(RBI);
430 GISel->InstSelector.reset(createX86InstructionSelector(TM, *this, *RBI));
431 setGISelAccessor(*GISel);
Eric Christopher4629ed72014-08-09 01:07:25 +0000432}
Bill Wendlingaef9c372013-02-15 22:31:27 +0000433
Zvi Rackover76dbf262016-11-15 06:34:33 +0000434const CallLowering *X86Subtarget::getCallLowering() const {
Quentin Colombet8dd90fb2017-08-08 22:22:30 +0000435 assert(GISel && "Access to GlobalISel APIs not set");
436 return GISel->getCallLowering();
Zvi Rackover76dbf262016-11-15 06:34:33 +0000437}
438
439const InstructionSelector *X86Subtarget::getInstructionSelector() const {
Quentin Colombet8dd90fb2017-08-08 22:22:30 +0000440 assert(GISel && "Access to GlobalISel APIs not set");
441 return GISel->getInstructionSelector();
Zvi Rackover76dbf262016-11-15 06:34:33 +0000442}
443
444const LegalizerInfo *X86Subtarget::getLegalizerInfo() const {
Quentin Colombet8dd90fb2017-08-08 22:22:30 +0000445 assert(GISel && "Access to GlobalISel APIs not set");
446 return GISel->getLegalizerInfo();
Zvi Rackover76dbf262016-11-15 06:34:33 +0000447}
448
449const RegisterBankInfo *X86Subtarget::getRegBankInfo() const {
Quentin Colombet8dd90fb2017-08-08 22:22:30 +0000450 assert(GISel && "Access to GlobalISel APIs not set");
451 return GISel->getRegBankInfo();
Zvi Rackover76dbf262016-11-15 06:34:33 +0000452}
453
Sanjay Patela2f658d2014-07-15 22:39:58 +0000454bool X86Subtarget::enableEarlyIfConversion() const {
Eric Christopher3470bbb2014-05-21 23:51:57 +0000455 return hasCMov() && X86EarlyIfConv;
Eric Christopher6b0fcfe2014-05-21 23:40:26 +0000456}