10b57cec5SDimitry Andric //===-- X86Subtarget.cpp - X86 Subtarget Information ----------------------===// 20b57cec5SDimitry Andric // 30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 60b57cec5SDimitry Andric // 70b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 80b57cec5SDimitry Andric // 90b57cec5SDimitry Andric // This file implements the X86 specific subclass of TargetSubtargetInfo. 100b57cec5SDimitry Andric // 110b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 120b57cec5SDimitry Andric 135ffd83dbSDimitry Andric #include "X86Subtarget.h" 145f757f3fSDimitry Andric #include "GISel/X86CallLowering.h" 155f757f3fSDimitry Andric #include "GISel/X86LegalizerInfo.h" 165f757f3fSDimitry Andric #include "GISel/X86RegisterBankInfo.h" 175ffd83dbSDimitry Andric #include "MCTargetDesc/X86BaseInfo.h" 180b57cec5SDimitry Andric #include "X86.h" 190b57cec5SDimitry Andric #include "X86MacroFusion.h" 200b57cec5SDimitry Andric #include "X86TargetMachine.h" 210b57cec5SDimitry Andric #include "llvm/CodeGen/GlobalISel/CallLowering.h" 220b57cec5SDimitry Andric #include "llvm/CodeGen/GlobalISel/InstructionSelect.h" 2381ad6265SDimitry Andric #include "llvm/CodeGen/GlobalISel/InstructionSelector.h" 2481ad6265SDimitry Andric #include "llvm/CodeGen/ScheduleDAGMutation.h" 250b57cec5SDimitry Andric #include "llvm/IR/Attributes.h" 260b57cec5SDimitry Andric #include "llvm/IR/ConstantRange.h" 270b57cec5SDimitry Andric #include "llvm/IR/Function.h" 280b57cec5SDimitry Andric #include "llvm/IR/GlobalValue.h" 29*0fca6ea1SDimitry Andric #include "llvm/IR/Module.h" 300b57cec5SDimitry Andric #include "llvm/Support/Casting.h" 310b57cec5SDimitry Andric #include "llvm/Support/CodeGen.h" 320b57cec5SDimitry Andric #include "llvm/Support/CommandLine.h" 330b57cec5SDimitry Andric #include "llvm/Support/Debug.h" 340b57cec5SDimitry Andric #include "llvm/Support/ErrorHandling.h" 350b57cec5SDimitry Andric #include "llvm/Support/raw_ostream.h" 360b57cec5SDimitry Andric #include "llvm/Target/TargetMachine.h" 3706c3fb27SDimitry Andric #include "llvm/TargetParser/Triple.h" 380b57cec5SDimitry Andric 390b57cec5SDimitry Andric #if defined(_MSC_VER) 400b57cec5SDimitry Andric #include <intrin.h> 410b57cec5SDimitry Andric #endif 420b57cec5SDimitry Andric 430b57cec5SDimitry Andric using namespace llvm; 440b57cec5SDimitry Andric 450b57cec5SDimitry Andric #define DEBUG_TYPE "subtarget" 460b57cec5SDimitry Andric 470b57cec5SDimitry Andric #define GET_SUBTARGETINFO_TARGET_DESC 480b57cec5SDimitry Andric #define GET_SUBTARGETINFO_CTOR 490b57cec5SDimitry Andric #include "X86GenSubtargetInfo.inc" 500b57cec5SDimitry Andric 510b57cec5SDimitry Andric // Temporary option to control early if-conversion for x86 while adding machine 520b57cec5SDimitry Andric // models. 530b57cec5SDimitry Andric static cl::opt<bool> 540b57cec5SDimitry Andric X86EarlyIfConv("x86-early-ifcvt", cl::Hidden, 550b57cec5SDimitry Andric cl::desc("Enable early if-conversion on X86")); 560b57cec5SDimitry Andric 570b57cec5SDimitry Andric 580b57cec5SDimitry Andric /// Classify a blockaddress reference for the current subtarget according to how 590b57cec5SDimitry Andric /// we should reference it in a non-pcrel context. 600b57cec5SDimitry Andric unsigned char X86Subtarget::classifyBlockAddressReference() const { 610b57cec5SDimitry Andric return classifyLocalReference(nullptr); 620b57cec5SDimitry Andric } 630b57cec5SDimitry Andric 640b57cec5SDimitry Andric /// Classify a global variable reference for the current subtarget according to 650b57cec5SDimitry Andric /// how we should reference it in a non-pcrel context. 660b57cec5SDimitry Andric unsigned char 670b57cec5SDimitry Andric X86Subtarget::classifyGlobalReference(const GlobalValue *GV) const { 680b57cec5SDimitry Andric return classifyGlobalReference(GV, *GV->getParent()); 690b57cec5SDimitry Andric } 700b57cec5SDimitry Andric 710b57cec5SDimitry Andric unsigned char 720b57cec5SDimitry Andric X86Subtarget::classifyLocalReference(const GlobalValue *GV) const { 73cb14a3feSDimitry Andric CodeModel::Model CM = TM.getCodeModel(); 74349cc55cSDimitry Andric // Tagged globals have non-zero upper bits, which makes direct references 75cb14a3feSDimitry Andric // require a 64-bit immediate. With the small/medium code models this causes 76cb14a3feSDimitry Andric // relocation errors, so we go through the GOT instead. 77cb14a3feSDimitry Andric if (AllowTaggedGlobals && CM != CodeModel::Large && GV && !isa<Function>(GV)) 78349cc55cSDimitry Andric return X86II::MO_GOTPCREL_NORELAX; 79349cc55cSDimitry Andric 800b57cec5SDimitry Andric // If we're not PIC, it's not very interesting. 810b57cec5SDimitry Andric if (!isPositionIndependent()) 820b57cec5SDimitry Andric return X86II::MO_NO_FLAG; 830b57cec5SDimitry Andric 840b57cec5SDimitry Andric if (is64Bit()) { 850b57cec5SDimitry Andric // 64-bit ELF PIC local references may use GOTOFF relocations. 860b57cec5SDimitry Andric if (isTargetELF()) { 875f757f3fSDimitry Andric assert(CM != CodeModel::Tiny && 885f757f3fSDimitry Andric "Tiny codesize model not supported on X86"); 895f757f3fSDimitry Andric // In the large code model, all text is far from any global data, so we 905f757f3fSDimitry Andric // use GOTOFF. 915f757f3fSDimitry Andric if (CM == CodeModel::Large) 920b57cec5SDimitry Andric return X86II::MO_GOTOFF; 935f757f3fSDimitry Andric // Large GlobalValues use GOTOFF, otherwise use RIP-rel access. 945f757f3fSDimitry Andric if (GV) 955f757f3fSDimitry Andric return TM.isLargeGlobalValue(GV) ? X86II::MO_GOTOFF : X86II::MO_NO_FLAG; 965f757f3fSDimitry Andric // GV == nullptr is for all other non-GlobalValue global data like the 975f757f3fSDimitry Andric // constant pool, jump tables, labels, etc. The small and medium code 985f757f3fSDimitry Andric // models treat these as accessible with a RIP-rel access. 995f757f3fSDimitry Andric return X86II::MO_NO_FLAG; 1000b57cec5SDimitry Andric } 1010b57cec5SDimitry Andric 1020b57cec5SDimitry Andric // Otherwise, this is either a RIP-relative reference or a 64-bit movabsq, 1030b57cec5SDimitry Andric // both of which use MO_NO_FLAG. 1040b57cec5SDimitry Andric return X86II::MO_NO_FLAG; 1050b57cec5SDimitry Andric } 1060b57cec5SDimitry Andric 1070b57cec5SDimitry Andric // The COFF dynamic linker just patches the executable sections. 1080b57cec5SDimitry Andric if (isTargetCOFF()) 1090b57cec5SDimitry Andric return X86II::MO_NO_FLAG; 1100b57cec5SDimitry Andric 1110b57cec5SDimitry Andric if (isTargetDarwin()) { 1120b57cec5SDimitry Andric // 32 bit macho has no relocation for a-b if a is undefined, even if 1130b57cec5SDimitry Andric // b is in the section that is being relocated. 1140b57cec5SDimitry Andric // This means we have to use o load even for GVs that are known to be 1150b57cec5SDimitry Andric // local to the dso. 1160b57cec5SDimitry Andric if (GV && (GV->isDeclarationForLinker() || GV->hasCommonLinkage())) 1170b57cec5SDimitry Andric return X86II::MO_DARWIN_NONLAZY_PIC_BASE; 1180b57cec5SDimitry Andric 1190b57cec5SDimitry Andric return X86II::MO_PIC_BASE_OFFSET; 1200b57cec5SDimitry Andric } 1210b57cec5SDimitry Andric 1220b57cec5SDimitry Andric return X86II::MO_GOTOFF; 1230b57cec5SDimitry Andric } 1240b57cec5SDimitry Andric 1250b57cec5SDimitry Andric unsigned char X86Subtarget::classifyGlobalReference(const GlobalValue *GV, 1260b57cec5SDimitry Andric const Module &M) const { 1270b57cec5SDimitry Andric // The static large model never uses stubs. 1280b57cec5SDimitry Andric if (TM.getCodeModel() == CodeModel::Large && !isPositionIndependent()) 1290b57cec5SDimitry Andric return X86II::MO_NO_FLAG; 1300b57cec5SDimitry Andric 1310b57cec5SDimitry Andric // Absolute symbols can be referenced directly. 1320b57cec5SDimitry Andric if (GV) { 133bdd1243dSDimitry Andric if (std::optional<ConstantRange> CR = GV->getAbsoluteSymbolRange()) { 1340b57cec5SDimitry Andric // See if we can use the 8-bit immediate form. Note that some instructions 1350b57cec5SDimitry Andric // will sign extend the immediate operand, so to be conservative we only 1360b57cec5SDimitry Andric // accept the range [0,128). 1370b57cec5SDimitry Andric if (CR->getUnsignedMax().ult(128)) 1380b57cec5SDimitry Andric return X86II::MO_ABS8; 1390b57cec5SDimitry Andric else 1400b57cec5SDimitry Andric return X86II::MO_NO_FLAG; 1410b57cec5SDimitry Andric } 1420b57cec5SDimitry Andric } 1430b57cec5SDimitry Andric 144*0fca6ea1SDimitry Andric if (TM.shouldAssumeDSOLocal(GV)) 1450b57cec5SDimitry Andric return classifyLocalReference(GV); 1460b57cec5SDimitry Andric 1470b57cec5SDimitry Andric if (isTargetCOFF()) { 148349cc55cSDimitry Andric // ExternalSymbolSDNode like _tls_index. 149349cc55cSDimitry Andric if (!GV) 150349cc55cSDimitry Andric return X86II::MO_NO_FLAG; 1510b57cec5SDimitry Andric if (GV->hasDLLImportStorageClass()) 1520b57cec5SDimitry Andric return X86II::MO_DLLIMPORT; 1530b57cec5SDimitry Andric return X86II::MO_COFFSTUB; 1540b57cec5SDimitry Andric } 1550b57cec5SDimitry Andric // Some JIT users use *-win32-elf triples; these shouldn't use GOT tables. 1560b57cec5SDimitry Andric if (isOSWindows()) 1570b57cec5SDimitry Andric return X86II::MO_NO_FLAG; 1580b57cec5SDimitry Andric 1590b57cec5SDimitry Andric if (is64Bit()) { 1600b57cec5SDimitry Andric // ELF supports a large, truly PIC code model with non-PC relative GOT 1610b57cec5SDimitry Andric // references. Other object file formats do not. Use the no-flag, 64-bit 1620b57cec5SDimitry Andric // reference for them. 1630b57cec5SDimitry Andric if (TM.getCodeModel() == CodeModel::Large) 1640b57cec5SDimitry Andric return isTargetELF() ? X86II::MO_GOT : X86II::MO_NO_FLAG; 165349cc55cSDimitry Andric // Tagged globals have non-zero upper bits, which makes direct references 166349cc55cSDimitry Andric // require a 64-bit immediate. So we can't let the linker relax the 167349cc55cSDimitry Andric // relocation to a 32-bit RIP-relative direct reference. 168349cc55cSDimitry Andric if (AllowTaggedGlobals && GV && !isa<Function>(GV)) 169349cc55cSDimitry Andric return X86II::MO_GOTPCREL_NORELAX; 1700b57cec5SDimitry Andric return X86II::MO_GOTPCREL; 1710b57cec5SDimitry Andric } 1720b57cec5SDimitry Andric 1730b57cec5SDimitry Andric if (isTargetDarwin()) { 1740b57cec5SDimitry Andric if (!isPositionIndependent()) 1750b57cec5SDimitry Andric return X86II::MO_DARWIN_NONLAZY; 1760b57cec5SDimitry Andric return X86II::MO_DARWIN_NONLAZY_PIC_BASE; 1770b57cec5SDimitry Andric } 1780b57cec5SDimitry Andric 179e8d8bef9SDimitry Andric // 32-bit ELF references GlobalAddress directly in static relocation model. 180e8d8bef9SDimitry Andric // We cannot use MO_GOT because EBX may not be set up. 181e8d8bef9SDimitry Andric if (TM.getRelocationModel() == Reloc::Static) 182e8d8bef9SDimitry Andric return X86II::MO_NO_FLAG; 1830b57cec5SDimitry Andric return X86II::MO_GOT; 1840b57cec5SDimitry Andric } 1850b57cec5SDimitry Andric 1860b57cec5SDimitry Andric unsigned char 1870b57cec5SDimitry Andric X86Subtarget::classifyGlobalFunctionReference(const GlobalValue *GV) const { 1880b57cec5SDimitry Andric return classifyGlobalFunctionReference(GV, *GV->getParent()); 1890b57cec5SDimitry Andric } 1900b57cec5SDimitry Andric 1910b57cec5SDimitry Andric unsigned char 1920b57cec5SDimitry Andric X86Subtarget::classifyGlobalFunctionReference(const GlobalValue *GV, 1930b57cec5SDimitry Andric const Module &M) const { 194*0fca6ea1SDimitry Andric if (TM.shouldAssumeDSOLocal(GV)) 1950b57cec5SDimitry Andric return X86II::MO_NO_FLAG; 1960b57cec5SDimitry Andric 197349cc55cSDimitry Andric // Functions on COFF can be non-DSO local for three reasons: 198349cc55cSDimitry Andric // - They are intrinsic functions (!GV) 1990b57cec5SDimitry Andric // - They are marked dllimport 2000b57cec5SDimitry Andric // - They are extern_weak, and a stub is needed 2010b57cec5SDimitry Andric if (isTargetCOFF()) { 202349cc55cSDimitry Andric if (!GV) 203349cc55cSDimitry Andric return X86II::MO_NO_FLAG; 2040b57cec5SDimitry Andric if (GV->hasDLLImportStorageClass()) 2050b57cec5SDimitry Andric return X86II::MO_DLLIMPORT; 2060b57cec5SDimitry Andric return X86II::MO_COFFSTUB; 2070b57cec5SDimitry Andric } 2080b57cec5SDimitry Andric 2090b57cec5SDimitry Andric const Function *F = dyn_cast_or_null<Function>(GV); 2100b57cec5SDimitry Andric 2110b57cec5SDimitry Andric if (isTargetELF()) { 2120b57cec5SDimitry Andric if (is64Bit() && F && (CallingConv::X86_RegCall == F->getCallingConv())) 2130b57cec5SDimitry Andric // According to psABI, PLT stub clobbers XMM8-XMM15. 2140b57cec5SDimitry Andric // In Regcall calling convention those registers are used for passing 2150b57cec5SDimitry Andric // parameters. Thus we need to prevent lazy binding in Regcall. 2160b57cec5SDimitry Andric return X86II::MO_GOTPCREL; 2170b57cec5SDimitry Andric // If PLT must be avoided then the call should be via GOTPCREL. 2180b57cec5SDimitry Andric if (((F && F->hasFnAttribute(Attribute::NonLazyBind)) || 2190b57cec5SDimitry Andric (!F && M.getRtLibUseGOT())) && 2200b57cec5SDimitry Andric is64Bit()) 2210b57cec5SDimitry Andric return X86II::MO_GOTPCREL; 222e8d8bef9SDimitry Andric // Reference ExternalSymbol directly in static relocation model. 223e8d8bef9SDimitry Andric if (!is64Bit() && !GV && TM.getRelocationModel() == Reloc::Static) 224e8d8bef9SDimitry Andric return X86II::MO_NO_FLAG; 2250b57cec5SDimitry Andric return X86II::MO_PLT; 2260b57cec5SDimitry Andric } 2270b57cec5SDimitry Andric 2280b57cec5SDimitry Andric if (is64Bit()) { 2290b57cec5SDimitry Andric if (F && F->hasFnAttribute(Attribute::NonLazyBind)) 2300b57cec5SDimitry Andric // If the function is marked as non-lazy, generate an indirect call 2310b57cec5SDimitry Andric // which loads from the GOT directly. This avoids runtime overhead 2320b57cec5SDimitry Andric // at the cost of eager binding (and one extra byte of encoding). 2330b57cec5SDimitry Andric return X86II::MO_GOTPCREL; 2340b57cec5SDimitry Andric return X86II::MO_NO_FLAG; 2350b57cec5SDimitry Andric } 2360b57cec5SDimitry Andric 2370b57cec5SDimitry Andric return X86II::MO_NO_FLAG; 2380b57cec5SDimitry Andric } 2390b57cec5SDimitry Andric 2400b57cec5SDimitry Andric /// Return true if the subtarget allows calls to immediate address. 2410b57cec5SDimitry Andric bool X86Subtarget::isLegalToCallImmediateAddr() const { 2420b57cec5SDimitry Andric // FIXME: I386 PE/COFF supports PC relative calls using IMAGE_REL_I386_REL32 2430b57cec5SDimitry Andric // but WinCOFFObjectWriter::RecordRelocation cannot emit them. Once it does, 2440b57cec5SDimitry Andric // the following check for Win32 should be removed. 24581ad6265SDimitry Andric if (Is64Bit || isTargetWin32()) 2460b57cec5SDimitry Andric return false; 2470b57cec5SDimitry Andric return isTargetELF() || TM.getRelocationModel() == Reloc::Static; 2480b57cec5SDimitry Andric } 2490b57cec5SDimitry Andric 250e8d8bef9SDimitry Andric void X86Subtarget::initSubtargetFeatures(StringRef CPU, StringRef TuneCPU, 251e8d8bef9SDimitry Andric StringRef FS) { 252e8d8bef9SDimitry Andric if (CPU.empty()) 253e8d8bef9SDimitry Andric CPU = "generic"; 2540b57cec5SDimitry Andric 255e8d8bef9SDimitry Andric if (TuneCPU.empty()) 256e8d8bef9SDimitry Andric TuneCPU = "i586"; // FIXME: "generic" is more modern than llc tests expect. 2570b57cec5SDimitry Andric 258e8d8bef9SDimitry Andric std::string FullFS = X86_MC::ParseX86Triple(TargetTriple); 259e8d8bef9SDimitry Andric assert(!FullFS.empty() && "Failed to parse X86 triple"); 2600b57cec5SDimitry Andric 261e8d8bef9SDimitry Andric if (!FS.empty()) 262e8d8bef9SDimitry Andric FullFS = (Twine(FullFS) + "," + FS).str(); 2630b57cec5SDimitry Andric 2645f757f3fSDimitry Andric // Attach EVEX512 feature when we have AVX512 features with a default CPU. 2655f757f3fSDimitry Andric // "pentium4" is default CPU for 32-bit targets. 2665f757f3fSDimitry Andric // "x86-64" is default CPU for 64-bit targets. 2675f757f3fSDimitry Andric if (CPU == "generic" || CPU == "pentium4" || CPU == "x86-64") { 2685f757f3fSDimitry Andric size_t posNoEVEX512 = FS.rfind("-evex512"); 2695f757f3fSDimitry Andric // Make sure we won't be cheated by "-avx512fp16". 2705f757f3fSDimitry Andric size_t posNoAVX512F = 2715f757f3fSDimitry Andric FS.ends_with("-avx512f") ? FS.size() - 8 : FS.rfind("-avx512f,"); 2725f757f3fSDimitry Andric size_t posEVEX512 = FS.rfind("+evex512"); 2735f757f3fSDimitry Andric // Any AVX512XXX will enable AVX512F. 2745f757f3fSDimitry Andric size_t posAVX512F = FS.rfind("+avx512"); 2755f757f3fSDimitry Andric 2765f757f3fSDimitry Andric if (posAVX512F != StringRef::npos && 2775f757f3fSDimitry Andric (posNoAVX512F == StringRef::npos || posNoAVX512F < posAVX512F)) 2785f757f3fSDimitry Andric if (posEVEX512 == StringRef::npos && posNoEVEX512 == StringRef::npos) 2795f757f3fSDimitry Andric FullFS += ",+evex512"; 2805f757f3fSDimitry Andric } 2815f757f3fSDimitry Andric 2820b57cec5SDimitry Andric // Parse features string and set the CPU. 283e8d8bef9SDimitry Andric ParseSubtargetFeatures(CPU, TuneCPU, FullFS); 2840b57cec5SDimitry Andric 2850b57cec5SDimitry Andric // All CPUs that implement SSE4.2 or SSE4A support unaligned accesses of 2860b57cec5SDimitry Andric // 16-bytes and under that are reasonably fast. These features were 2870b57cec5SDimitry Andric // introduced with Intel's Nehalem/Silvermont and AMD's Family10h 2880b57cec5SDimitry Andric // micro-architectures respectively. 2890b57cec5SDimitry Andric if (hasSSE42() || hasSSE4A()) 29081ad6265SDimitry Andric IsUnalignedMem16Slow = false; 2910b57cec5SDimitry Andric 2920b57cec5SDimitry Andric LLVM_DEBUG(dbgs() << "Subtarget features: SSELevel " << X86SSELevel 293*0fca6ea1SDimitry Andric << ", MMX " << HasMMX << ", 64bit " << HasX86_64 << "\n"); 29481ad6265SDimitry Andric if (Is64Bit && !HasX86_64) 2950b57cec5SDimitry Andric report_fatal_error("64-bit code requested on a subtarget that doesn't " 2960b57cec5SDimitry Andric "support it!"); 2970b57cec5SDimitry Andric 298fe6060f1SDimitry Andric // Stack alignment is 16 bytes on Darwin, Linux, kFreeBSD, NaCl, and for all 299e8d8bef9SDimitry Andric // 64-bit targets. On Solaris (32-bit), stack alignment is 4 bytes 300e8d8bef9SDimitry Andric // following the i386 psABI, while on Illumos it is always 16 bytes. 3010b57cec5SDimitry Andric if (StackAlignOverride) 3028bcb0991SDimitry Andric stackAlignment = *StackAlignOverride; 303e8d8bef9SDimitry Andric else if (isTargetDarwin() || isTargetLinux() || isTargetKFreeBSD() || 30481ad6265SDimitry Andric isTargetNaCl() || Is64Bit) 3058bcb0991SDimitry Andric stackAlignment = Align(16); 3060b57cec5SDimitry Andric 3070b57cec5SDimitry Andric // Consume the vector width attribute or apply any target specific limit. 3080b57cec5SDimitry Andric if (PreferVectorWidthOverride) 3090b57cec5SDimitry Andric PreferVectorWidth = PreferVectorWidthOverride; 3108bcb0991SDimitry Andric else if (Prefer128Bit) 3118bcb0991SDimitry Andric PreferVectorWidth = 128; 3120b57cec5SDimitry Andric else if (Prefer256Bit) 3130b57cec5SDimitry Andric PreferVectorWidth = 256; 3140b57cec5SDimitry Andric } 3150b57cec5SDimitry Andric 3160b57cec5SDimitry Andric X86Subtarget &X86Subtarget::initializeSubtargetDependencies(StringRef CPU, 317e8d8bef9SDimitry Andric StringRef TuneCPU, 3180b57cec5SDimitry Andric StringRef FS) { 319e8d8bef9SDimitry Andric initSubtargetFeatures(CPU, TuneCPU, FS); 3200b57cec5SDimitry Andric return *this; 3210b57cec5SDimitry Andric } 3220b57cec5SDimitry Andric 323e8d8bef9SDimitry Andric X86Subtarget::X86Subtarget(const Triple &TT, StringRef CPU, StringRef TuneCPU, 324e8d8bef9SDimitry Andric StringRef FS, const X86TargetMachine &TM, 3258bcb0991SDimitry Andric MaybeAlign StackAlignOverride, 3260b57cec5SDimitry Andric unsigned PreferVectorWidthOverride, 3270b57cec5SDimitry Andric unsigned RequiredVectorWidth) 328e8d8bef9SDimitry Andric : X86GenSubtargetInfo(TT, CPU, TuneCPU, FS), 329e8d8bef9SDimitry Andric PICStyle(PICStyles::Style::None), TM(TM), TargetTriple(TT), 330e8d8bef9SDimitry Andric StackAlignOverride(StackAlignOverride), 3310b57cec5SDimitry Andric PreferVectorWidthOverride(PreferVectorWidthOverride), 3320b57cec5SDimitry Andric RequiredVectorWidth(RequiredVectorWidth), 333e8d8bef9SDimitry Andric InstrInfo(initializeSubtargetDependencies(CPU, TuneCPU, FS)), 334e8d8bef9SDimitry Andric TLInfo(TM, *this), FrameLowering(*this, getStackAlignment()) { 3350b57cec5SDimitry Andric // Determine the PICStyle based on the target selected. 3365f757f3fSDimitry Andric if (!isPositionIndependent() || TM.getCodeModel() == CodeModel::Large) 3375f757f3fSDimitry Andric // With the large code model, None forces all memory accesses to be indirect 3385f757f3fSDimitry Andric // rather than RIP-relative. 339480093f4SDimitry Andric setPICStyle(PICStyles::Style::None); 3400b57cec5SDimitry Andric else if (is64Bit()) 341480093f4SDimitry Andric setPICStyle(PICStyles::Style::RIPRel); 3420b57cec5SDimitry Andric else if (isTargetCOFF()) 343480093f4SDimitry Andric setPICStyle(PICStyles::Style::None); 3440b57cec5SDimitry Andric else if (isTargetDarwin()) 345480093f4SDimitry Andric setPICStyle(PICStyles::Style::StubPIC); 3460b57cec5SDimitry Andric else if (isTargetELF()) 347480093f4SDimitry Andric setPICStyle(PICStyles::Style::GOT); 3480b57cec5SDimitry Andric 3490b57cec5SDimitry Andric CallLoweringInfo.reset(new X86CallLowering(*getTargetLowering())); 3500b57cec5SDimitry Andric Legalizer.reset(new X86LegalizerInfo(*this, TM)); 3510b57cec5SDimitry Andric 3520b57cec5SDimitry Andric auto *RBI = new X86RegisterBankInfo(*getRegisterInfo()); 3530b57cec5SDimitry Andric RegBankInfo.reset(RBI); 3540b57cec5SDimitry Andric InstSelector.reset(createX86InstructionSelector(TM, *this, *RBI)); 3550b57cec5SDimitry Andric } 3560b57cec5SDimitry Andric 3570b57cec5SDimitry Andric const CallLowering *X86Subtarget::getCallLowering() const { 3580b57cec5SDimitry Andric return CallLoweringInfo.get(); 3590b57cec5SDimitry Andric } 3600b57cec5SDimitry Andric 3618bcb0991SDimitry Andric InstructionSelector *X86Subtarget::getInstructionSelector() const { 3620b57cec5SDimitry Andric return InstSelector.get(); 3630b57cec5SDimitry Andric } 3640b57cec5SDimitry Andric 3650b57cec5SDimitry Andric const LegalizerInfo *X86Subtarget::getLegalizerInfo() const { 3660b57cec5SDimitry Andric return Legalizer.get(); 3670b57cec5SDimitry Andric } 3680b57cec5SDimitry Andric 3690b57cec5SDimitry Andric const RegisterBankInfo *X86Subtarget::getRegBankInfo() const { 3700b57cec5SDimitry Andric return RegBankInfo.get(); 3710b57cec5SDimitry Andric } 3720b57cec5SDimitry Andric 3730b57cec5SDimitry Andric bool X86Subtarget::enableEarlyIfConversion() const { 37481ad6265SDimitry Andric return canUseCMOV() && X86EarlyIfConv; 3750b57cec5SDimitry Andric } 3760b57cec5SDimitry Andric 3770b57cec5SDimitry Andric void X86Subtarget::getPostRAMutations( 3780b57cec5SDimitry Andric std::vector<std::unique_ptr<ScheduleDAGMutation>> &Mutations) const { 3790b57cec5SDimitry Andric Mutations.push_back(createX86MacroFusionDAGMutation()); 3800b57cec5SDimitry Andric } 3815ffd83dbSDimitry Andric 3825ffd83dbSDimitry Andric bool X86Subtarget::isPositionIndependent() const { 3835ffd83dbSDimitry Andric return TM.isPositionIndependent(); 3845ffd83dbSDimitry Andric } 385