xref: /minix3/external/bsd/llvm/dist/llvm/lib/Target/X86/X86Subtarget.cpp (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1f4a2713aSLionel Sambuc //===-- X86Subtarget.cpp - X86 Subtarget Information ----------------------===//
2f4a2713aSLionel Sambuc //
3f4a2713aSLionel Sambuc //                     The LLVM Compiler Infrastructure
4f4a2713aSLionel Sambuc //
5f4a2713aSLionel Sambuc // This file is distributed under the University of Illinois Open Source
6f4a2713aSLionel Sambuc // License. See LICENSE.TXT for details.
7f4a2713aSLionel Sambuc //
8f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
9f4a2713aSLionel Sambuc //
10f4a2713aSLionel Sambuc // This file implements the X86 specific subclass of TargetSubtargetInfo.
11f4a2713aSLionel Sambuc //
12f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
13f4a2713aSLionel Sambuc 
14f4a2713aSLionel Sambuc #include "X86Subtarget.h"
15f4a2713aSLionel Sambuc #include "X86InstrInfo.h"
16*0a6a1f1dSLionel Sambuc #include "X86TargetMachine.h"
17f4a2713aSLionel Sambuc #include "llvm/IR/Attributes.h"
18f4a2713aSLionel Sambuc #include "llvm/IR/Function.h"
19f4a2713aSLionel Sambuc #include "llvm/IR/GlobalValue.h"
20*0a6a1f1dSLionel Sambuc #include "llvm/Support/CommandLine.h"
21f4a2713aSLionel Sambuc #include "llvm/Support/Debug.h"
22f4a2713aSLionel Sambuc #include "llvm/Support/ErrorHandling.h"
23f4a2713aSLionel Sambuc #include "llvm/Support/Host.h"
24f4a2713aSLionel Sambuc #include "llvm/Support/raw_ostream.h"
25f4a2713aSLionel Sambuc #include "llvm/Target/TargetMachine.h"
26f4a2713aSLionel Sambuc #include "llvm/Target/TargetOptions.h"
27f4a2713aSLionel Sambuc 
28*0a6a1f1dSLionel Sambuc #if defined(_MSC_VER)
29*0a6a1f1dSLionel Sambuc #include <intrin.h>
30*0a6a1f1dSLionel Sambuc #endif
31*0a6a1f1dSLionel Sambuc 
32*0a6a1f1dSLionel Sambuc using namespace llvm;
33*0a6a1f1dSLionel Sambuc 
34*0a6a1f1dSLionel Sambuc #define DEBUG_TYPE "subtarget"
35*0a6a1f1dSLionel Sambuc 
36f4a2713aSLionel Sambuc #define GET_SUBTARGETINFO_TARGET_DESC
37f4a2713aSLionel Sambuc #define GET_SUBTARGETINFO_CTOR
38f4a2713aSLionel Sambuc #include "X86GenSubtargetInfo.inc"
39f4a2713aSLionel Sambuc 
40*0a6a1f1dSLionel Sambuc // Temporary option to control early if-conversion for x86 while adding machine
41*0a6a1f1dSLionel Sambuc // models.
42*0a6a1f1dSLionel Sambuc static cl::opt<bool>
43*0a6a1f1dSLionel Sambuc X86EarlyIfConv("x86-early-ifcvt", cl::Hidden,
44*0a6a1f1dSLionel Sambuc                cl::desc("Enable early if-conversion on X86"));
45f4a2713aSLionel Sambuc 
46f4a2713aSLionel Sambuc 
47f4a2713aSLionel Sambuc /// ClassifyBlockAddressReference - Classify a blockaddress reference for the
48f4a2713aSLionel Sambuc /// current subtarget according to how we should reference it in a non-pcrel
49f4a2713aSLionel Sambuc /// context.
ClassifyBlockAddressReference() const50f4a2713aSLionel Sambuc unsigned char X86Subtarget::ClassifyBlockAddressReference() const {
51f4a2713aSLionel Sambuc   if (isPICStyleGOT())    // 32-bit ELF targets.
52f4a2713aSLionel Sambuc     return X86II::MO_GOTOFF;
53f4a2713aSLionel Sambuc 
54f4a2713aSLionel Sambuc   if (isPICStyleStubPIC())   // Darwin/32 in PIC mode.
55f4a2713aSLionel Sambuc     return X86II::MO_PIC_BASE_OFFSET;
56f4a2713aSLionel Sambuc 
57f4a2713aSLionel Sambuc   // Direct static reference to label.
58f4a2713aSLionel Sambuc   return X86II::MO_NO_FLAG;
59f4a2713aSLionel Sambuc }
60f4a2713aSLionel Sambuc 
61f4a2713aSLionel Sambuc /// ClassifyGlobalReference - Classify a global variable reference for the
62f4a2713aSLionel Sambuc /// current subtarget according to how we should reference it in a non-pcrel
63f4a2713aSLionel Sambuc /// context.
64f4a2713aSLionel Sambuc unsigned char X86Subtarget::
ClassifyGlobalReference(const GlobalValue * GV,const TargetMachine & TM) const65f4a2713aSLionel Sambuc ClassifyGlobalReference(const GlobalValue *GV, const TargetMachine &TM) const {
66f4a2713aSLionel Sambuc   // DLLImport only exists on windows, it is implemented as a load from a
67f4a2713aSLionel Sambuc   // DLLIMPORT stub.
68*0a6a1f1dSLionel Sambuc   if (GV->hasDLLImportStorageClass())
69f4a2713aSLionel Sambuc     return X86II::MO_DLLIMPORT;
70f4a2713aSLionel Sambuc 
71*0a6a1f1dSLionel Sambuc   bool isDecl = GV->isDeclarationForLinker();
72f4a2713aSLionel Sambuc 
73f4a2713aSLionel Sambuc   // X86-64 in PIC mode.
74f4a2713aSLionel Sambuc   if (isPICStyleRIPRel()) {
75f4a2713aSLionel Sambuc     // Large model never uses stubs.
76f4a2713aSLionel Sambuc     if (TM.getCodeModel() == CodeModel::Large)
77f4a2713aSLionel Sambuc       return X86II::MO_NO_FLAG;
78f4a2713aSLionel Sambuc 
79f4a2713aSLionel Sambuc     if (isTargetDarwin()) {
80f4a2713aSLionel Sambuc       // If symbol visibility is hidden, the extra load is not needed if
81f4a2713aSLionel Sambuc       // target is x86-64 or the symbol is definitely defined in the current
82f4a2713aSLionel Sambuc       // translation unit.
83f4a2713aSLionel Sambuc       if (GV->hasDefaultVisibility() &&
84f4a2713aSLionel Sambuc           (isDecl || GV->isWeakForLinker()))
85f4a2713aSLionel Sambuc         return X86II::MO_GOTPCREL;
86f4a2713aSLionel Sambuc     } else if (!isTargetWin64()) {
87f4a2713aSLionel Sambuc       assert(isTargetELF() && "Unknown rip-relative target");
88f4a2713aSLionel Sambuc 
89f4a2713aSLionel Sambuc       // Extra load is needed for all externally visible.
90f4a2713aSLionel Sambuc       if (!GV->hasLocalLinkage() && GV->hasDefaultVisibility())
91f4a2713aSLionel Sambuc         return X86II::MO_GOTPCREL;
92f4a2713aSLionel Sambuc     }
93f4a2713aSLionel Sambuc 
94f4a2713aSLionel Sambuc     return X86II::MO_NO_FLAG;
95f4a2713aSLionel Sambuc   }
96f4a2713aSLionel Sambuc 
97f4a2713aSLionel Sambuc   if (isPICStyleGOT()) {   // 32-bit ELF targets.
98f4a2713aSLionel Sambuc     // Extra load is needed for all externally visible.
99f4a2713aSLionel Sambuc     if (GV->hasLocalLinkage() || GV->hasHiddenVisibility())
100f4a2713aSLionel Sambuc       return X86II::MO_GOTOFF;
101f4a2713aSLionel Sambuc     return X86II::MO_GOT;
102f4a2713aSLionel Sambuc   }
103f4a2713aSLionel Sambuc 
104f4a2713aSLionel Sambuc   if (isPICStyleStubPIC()) {  // Darwin/32 in PIC mode.
105f4a2713aSLionel Sambuc     // Determine whether we have a stub reference and/or whether the reference
106f4a2713aSLionel Sambuc     // is relative to the PIC base or not.
107f4a2713aSLionel Sambuc 
108f4a2713aSLionel Sambuc     // If this is a strong reference to a definition, it is definitely not
109f4a2713aSLionel Sambuc     // through a stub.
110f4a2713aSLionel Sambuc     if (!isDecl && !GV->isWeakForLinker())
111f4a2713aSLionel Sambuc       return X86II::MO_PIC_BASE_OFFSET;
112f4a2713aSLionel Sambuc 
113f4a2713aSLionel Sambuc     // Unless we have a symbol with hidden visibility, we have to go through a
114f4a2713aSLionel Sambuc     // normal $non_lazy_ptr stub because this symbol might be resolved late.
115f4a2713aSLionel Sambuc     if (!GV->hasHiddenVisibility())  // Non-hidden $non_lazy_ptr reference.
116f4a2713aSLionel Sambuc       return X86II::MO_DARWIN_NONLAZY_PIC_BASE;
117f4a2713aSLionel Sambuc 
118f4a2713aSLionel Sambuc     // If symbol visibility is hidden, we have a stub for common symbol
119f4a2713aSLionel Sambuc     // references and external declarations.
120f4a2713aSLionel Sambuc     if (isDecl || GV->hasCommonLinkage()) {
121f4a2713aSLionel Sambuc       // Hidden $non_lazy_ptr reference.
122f4a2713aSLionel Sambuc       return X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE;
123f4a2713aSLionel Sambuc     }
124f4a2713aSLionel Sambuc 
125f4a2713aSLionel Sambuc     // Otherwise, no stub.
126f4a2713aSLionel Sambuc     return X86II::MO_PIC_BASE_OFFSET;
127f4a2713aSLionel Sambuc   }
128f4a2713aSLionel Sambuc 
129f4a2713aSLionel Sambuc   if (isPICStyleStubNoDynamic()) {  // Darwin/32 in -mdynamic-no-pic mode.
130f4a2713aSLionel Sambuc     // Determine whether we have a stub reference.
131f4a2713aSLionel Sambuc 
132f4a2713aSLionel Sambuc     // If this is a strong reference to a definition, it is definitely not
133f4a2713aSLionel Sambuc     // through a stub.
134f4a2713aSLionel Sambuc     if (!isDecl && !GV->isWeakForLinker())
135f4a2713aSLionel Sambuc       return X86II::MO_NO_FLAG;
136f4a2713aSLionel Sambuc 
137f4a2713aSLionel Sambuc     // Unless we have a symbol with hidden visibility, we have to go through a
138f4a2713aSLionel Sambuc     // normal $non_lazy_ptr stub because this symbol might be resolved late.
139f4a2713aSLionel Sambuc     if (!GV->hasHiddenVisibility())  // Non-hidden $non_lazy_ptr reference.
140f4a2713aSLionel Sambuc       return X86II::MO_DARWIN_NONLAZY;
141f4a2713aSLionel Sambuc 
142f4a2713aSLionel Sambuc     // Otherwise, no stub.
143f4a2713aSLionel Sambuc     return X86II::MO_NO_FLAG;
144f4a2713aSLionel Sambuc   }
145f4a2713aSLionel Sambuc 
146f4a2713aSLionel Sambuc   // Direct static reference to global.
147f4a2713aSLionel Sambuc   return X86II::MO_NO_FLAG;
148f4a2713aSLionel Sambuc }
149f4a2713aSLionel Sambuc 
150f4a2713aSLionel Sambuc 
151f4a2713aSLionel Sambuc /// getBZeroEntry - This function returns the name of a function which has an
152f4a2713aSLionel Sambuc /// interface like the non-standard bzero function, if such a function exists on
153f4a2713aSLionel Sambuc /// the current subtarget and it is considered prefereable over memset with zero
154f4a2713aSLionel Sambuc /// passed as the second argument. Otherwise it returns null.
getBZeroEntry() const155f4a2713aSLionel Sambuc const char *X86Subtarget::getBZeroEntry() const {
156f4a2713aSLionel Sambuc   // Darwin 10 has a __bzero entry point for this purpose.
157f4a2713aSLionel Sambuc   if (getTargetTriple().isMacOSX() &&
158f4a2713aSLionel Sambuc       !getTargetTriple().isMacOSXVersionLT(10, 6))
159f4a2713aSLionel Sambuc     return "__bzero";
160f4a2713aSLionel Sambuc 
161*0a6a1f1dSLionel Sambuc   return nullptr;
162f4a2713aSLionel Sambuc }
163f4a2713aSLionel Sambuc 
hasSinCos() const164f4a2713aSLionel Sambuc bool X86Subtarget::hasSinCos() const {
165f4a2713aSLionel Sambuc   return getTargetTriple().isMacOSX() &&
166f4a2713aSLionel Sambuc     !getTargetTriple().isMacOSXVersionLT(10, 9) &&
167f4a2713aSLionel Sambuc     is64Bit();
168f4a2713aSLionel Sambuc }
169f4a2713aSLionel Sambuc 
170f4a2713aSLionel Sambuc /// IsLegalToCallImmediateAddr - Return true if the subtarget allows calls
171f4a2713aSLionel Sambuc /// to immediate address.
IsLegalToCallImmediateAddr(const TargetMachine & TM) const172f4a2713aSLionel Sambuc bool X86Subtarget::IsLegalToCallImmediateAddr(const TargetMachine &TM) const {
173*0a6a1f1dSLionel Sambuc   // FIXME: I386 PE/COFF supports PC relative calls using IMAGE_REL_I386_REL32
174*0a6a1f1dSLionel Sambuc   // but WinCOFFObjectWriter::RecordRelocation cannot emit them.  Once it does,
175*0a6a1f1dSLionel Sambuc   // the following check for Win32 should be removed.
176*0a6a1f1dSLionel Sambuc   if (In64BitMode || isTargetWin32())
177f4a2713aSLionel Sambuc     return false;
178f4a2713aSLionel Sambuc   return isTargetELF() || TM.getRelocationModel() == Reloc::Static;
179f4a2713aSLionel Sambuc }
180f4a2713aSLionel Sambuc 
initSubtargetFeatures(StringRef CPU,StringRef FS)181*0a6a1f1dSLionel Sambuc void X86Subtarget::initSubtargetFeatures(StringRef CPU, StringRef FS) {
182f4a2713aSLionel Sambuc   std::string CPUName = CPU;
183*0a6a1f1dSLionel Sambuc   if (CPUName.empty())
184f4a2713aSLionel Sambuc     CPUName = "generic";
185f4a2713aSLionel Sambuc 
186f4a2713aSLionel Sambuc   // Make sure 64-bit features are available in 64-bit mode. (But make sure
187f4a2713aSLionel Sambuc   // SSE2 can be turned off explicitly.)
188f4a2713aSLionel Sambuc   std::string FullFS = FS;
189f4a2713aSLionel Sambuc   if (In64BitMode) {
190f4a2713aSLionel Sambuc     if (!FullFS.empty())
191f4a2713aSLionel Sambuc       FullFS = "+64bit,+sse2," + FullFS;
192f4a2713aSLionel Sambuc     else
193f4a2713aSLionel Sambuc       FullFS = "+64bit,+sse2";
194f4a2713aSLionel Sambuc   }
195f4a2713aSLionel Sambuc 
196f4a2713aSLionel Sambuc   // If feature string is not empty, parse features string.
197f4a2713aSLionel Sambuc   ParseSubtargetFeatures(CPUName, FullFS);
198f4a2713aSLionel Sambuc 
199*0a6a1f1dSLionel Sambuc   // Make sure the right MCSchedModel is used.
200f4a2713aSLionel Sambuc   InitCPUSchedModel(CPUName);
201f4a2713aSLionel Sambuc 
202f4a2713aSLionel Sambuc   InstrItins = getInstrItineraryForCPU(CPUName);
203f4a2713aSLionel Sambuc 
204f4a2713aSLionel Sambuc   // It's important to keep the MCSubtargetInfo feature bits in sync with
205f4a2713aSLionel Sambuc   // target data structure which is shared with MC code emitter, etc.
206f4a2713aSLionel Sambuc   if (In64BitMode)
207f4a2713aSLionel Sambuc     ToggleFeature(X86::Mode64Bit);
208*0a6a1f1dSLionel Sambuc   else if (In32BitMode)
209*0a6a1f1dSLionel Sambuc     ToggleFeature(X86::Mode32Bit);
210*0a6a1f1dSLionel Sambuc   else if (In16BitMode)
211*0a6a1f1dSLionel Sambuc     ToggleFeature(X86::Mode16Bit);
212*0a6a1f1dSLionel Sambuc   else
213*0a6a1f1dSLionel Sambuc     llvm_unreachable("Not 16-bit, 32-bit or 64-bit mode!");
214f4a2713aSLionel Sambuc 
215f4a2713aSLionel Sambuc   DEBUG(dbgs() << "Subtarget features: SSELevel " << X86SSELevel
216f4a2713aSLionel Sambuc                << ", 3DNowLevel " << X863DNowLevel
217f4a2713aSLionel Sambuc                << ", 64bit " << HasX86_64 << "\n");
218f4a2713aSLionel Sambuc   assert((!In64BitMode || HasX86_64) &&
219f4a2713aSLionel Sambuc          "64-bit code requested on a subtarget that doesn't support it!");
220f4a2713aSLionel Sambuc 
221f4a2713aSLionel Sambuc   // Stack alignment is 16 bytes on Darwin, Linux and Solaris (both
222f4a2713aSLionel Sambuc   // 32 and 64 bit) and for all 64-bit targets.
223f4a2713aSLionel Sambuc   if (StackAlignOverride)
224f4a2713aSLionel Sambuc     stackAlignment = StackAlignOverride;
225f4a2713aSLionel Sambuc   else if (isTargetDarwin() || isTargetLinux() || isTargetSolaris() ||
226f4a2713aSLionel Sambuc            In64BitMode)
227f4a2713aSLionel Sambuc     stackAlignment = 16;
228f4a2713aSLionel Sambuc }
229f4a2713aSLionel Sambuc 
initializeEnvironment()230f4a2713aSLionel Sambuc void X86Subtarget::initializeEnvironment() {
231f4a2713aSLionel Sambuc   X86SSELevel = NoMMXSSE;
232f4a2713aSLionel Sambuc   X863DNowLevel = NoThreeDNow;
233f4a2713aSLionel Sambuc   HasCMov = false;
234f4a2713aSLionel Sambuc   HasX86_64 = false;
235f4a2713aSLionel Sambuc   HasPOPCNT = false;
236f4a2713aSLionel Sambuc   HasSSE4A = false;
237f4a2713aSLionel Sambuc   HasAES = false;
238f4a2713aSLionel Sambuc   HasPCLMUL = false;
239f4a2713aSLionel Sambuc   HasFMA = false;
240f4a2713aSLionel Sambuc   HasFMA4 = false;
241f4a2713aSLionel Sambuc   HasXOP = false;
242f4a2713aSLionel Sambuc   HasTBM = false;
243f4a2713aSLionel Sambuc   HasMOVBE = false;
244f4a2713aSLionel Sambuc   HasRDRAND = false;
245f4a2713aSLionel Sambuc   HasF16C = false;
246f4a2713aSLionel Sambuc   HasFSGSBase = false;
247f4a2713aSLionel Sambuc   HasLZCNT = false;
248f4a2713aSLionel Sambuc   HasBMI = false;
249f4a2713aSLionel Sambuc   HasBMI2 = false;
250f4a2713aSLionel Sambuc   HasRTM = false;
251f4a2713aSLionel Sambuc   HasHLE = false;
252f4a2713aSLionel Sambuc   HasERI = false;
253f4a2713aSLionel Sambuc   HasCDI = false;
254f4a2713aSLionel Sambuc   HasPFI = false;
255*0a6a1f1dSLionel Sambuc   HasDQI = false;
256*0a6a1f1dSLionel Sambuc   HasBWI = false;
257*0a6a1f1dSLionel Sambuc   HasVLX = false;
258f4a2713aSLionel Sambuc   HasADX = false;
259f4a2713aSLionel Sambuc   HasSHA = false;
260*0a6a1f1dSLionel Sambuc   HasSGX = false;
261f4a2713aSLionel Sambuc   HasPRFCHW = false;
262f4a2713aSLionel Sambuc   HasRDSEED = false;
263*0a6a1f1dSLionel Sambuc   HasSMAP = false;
264f4a2713aSLionel Sambuc   IsBTMemSlow = false;
265*0a6a1f1dSLionel Sambuc   IsSHLDSlow = false;
266f4a2713aSLionel Sambuc   IsUAMemFast = false;
267*0a6a1f1dSLionel Sambuc   IsUAMem32Slow = false;
268*0a6a1f1dSLionel Sambuc   HasSSEUnalignedMem = false;
269f4a2713aSLionel Sambuc   HasCmpxchg16b = false;
270f4a2713aSLionel Sambuc   UseLeaForSP = false;
271*0a6a1f1dSLionel Sambuc   HasSlowDivide32 = false;
272*0a6a1f1dSLionel Sambuc   HasSlowDivide64 = false;
273f4a2713aSLionel Sambuc   PadShortFunctions = false;
274f4a2713aSLionel Sambuc   CallRegIndirect = false;
275f4a2713aSLionel Sambuc   LEAUsesAG = false;
276*0a6a1f1dSLionel Sambuc   SlowLEA = false;
277*0a6a1f1dSLionel Sambuc   SlowIncDec = false;
278*0a6a1f1dSLionel Sambuc   UseSqrtEst = false;
279*0a6a1f1dSLionel Sambuc   UseReciprocalEst = false;
280f4a2713aSLionel Sambuc   stackAlignment = 4;
281f4a2713aSLionel Sambuc   // FIXME: this is a known good value for Yonah. How about others?
282f4a2713aSLionel Sambuc   MaxInlineSizeThreshold = 128;
283f4a2713aSLionel Sambuc }
284f4a2713aSLionel Sambuc 
computeDataLayout(const Triple & TT)285*0a6a1f1dSLionel Sambuc static std::string computeDataLayout(const Triple &TT) {
286*0a6a1f1dSLionel Sambuc   // X86 is little endian
287*0a6a1f1dSLionel Sambuc   std::string Ret = "e";
288*0a6a1f1dSLionel Sambuc 
289*0a6a1f1dSLionel Sambuc   Ret += DataLayout::getManglingComponent(TT);
290*0a6a1f1dSLionel Sambuc   // X86 and x32 have 32 bit pointers.
291*0a6a1f1dSLionel Sambuc   if ((TT.isArch64Bit() &&
292*0a6a1f1dSLionel Sambuc        (TT.getEnvironment() == Triple::GNUX32 || TT.isOSNaCl())) ||
293*0a6a1f1dSLionel Sambuc       !TT.isArch64Bit())
294*0a6a1f1dSLionel Sambuc     Ret += "-p:32:32";
295*0a6a1f1dSLionel Sambuc 
296*0a6a1f1dSLionel Sambuc   // Some ABIs align 64 bit integers and doubles to 64 bits, others to 32.
297*0a6a1f1dSLionel Sambuc   if (TT.isArch64Bit() || TT.isOSWindows() || TT.isOSNaCl())
298*0a6a1f1dSLionel Sambuc     Ret += "-i64:64";
299*0a6a1f1dSLionel Sambuc   else
300*0a6a1f1dSLionel Sambuc     Ret += "-f64:32:64";
301*0a6a1f1dSLionel Sambuc 
302*0a6a1f1dSLionel Sambuc   // Some ABIs align long double to 128 bits, others to 32.
303*0a6a1f1dSLionel Sambuc   if (TT.isOSNaCl())
304*0a6a1f1dSLionel Sambuc     ; // No f80
305*0a6a1f1dSLionel Sambuc   else if (TT.isArch64Bit() || TT.isOSDarwin())
306*0a6a1f1dSLionel Sambuc     Ret += "-f80:128";
307*0a6a1f1dSLionel Sambuc   else
308*0a6a1f1dSLionel Sambuc     Ret += "-f80:32";
309*0a6a1f1dSLionel Sambuc 
310*0a6a1f1dSLionel Sambuc   // The registers can hold 8, 16, 32 or, in x86-64, 64 bits.
311*0a6a1f1dSLionel Sambuc   if (TT.isArch64Bit())
312*0a6a1f1dSLionel Sambuc     Ret += "-n8:16:32:64";
313*0a6a1f1dSLionel Sambuc   else
314*0a6a1f1dSLionel Sambuc     Ret += "-n8:16:32";
315*0a6a1f1dSLionel Sambuc 
316*0a6a1f1dSLionel Sambuc   // The stack is aligned to 32 bits on some ABIs and 128 bits on others.
317*0a6a1f1dSLionel Sambuc   if (!TT.isArch64Bit() && TT.isOSWindows())
318*0a6a1f1dSLionel Sambuc     Ret += "-S32";
319*0a6a1f1dSLionel Sambuc   else
320*0a6a1f1dSLionel Sambuc     Ret += "-S128";
321*0a6a1f1dSLionel Sambuc 
322*0a6a1f1dSLionel Sambuc   return Ret;
323f4a2713aSLionel Sambuc }
324f4a2713aSLionel Sambuc 
initializeSubtargetDependencies(StringRef CPU,StringRef FS)325*0a6a1f1dSLionel Sambuc X86Subtarget &X86Subtarget::initializeSubtargetDependencies(StringRef CPU,
326*0a6a1f1dSLionel Sambuc                                                             StringRef FS) {
327*0a6a1f1dSLionel Sambuc   initializeEnvironment();
328*0a6a1f1dSLionel Sambuc   initSubtargetFeatures(CPU, FS);
329*0a6a1f1dSLionel Sambuc   return *this;
330f4a2713aSLionel Sambuc }
331*0a6a1f1dSLionel Sambuc 
X86Subtarget(const std::string & TT,const std::string & CPU,const std::string & FS,const X86TargetMachine & TM,unsigned StackAlignOverride)332*0a6a1f1dSLionel Sambuc X86Subtarget::X86Subtarget(const std::string &TT, const std::string &CPU,
333*0a6a1f1dSLionel Sambuc                            const std::string &FS, const X86TargetMachine &TM,
334*0a6a1f1dSLionel Sambuc                            unsigned StackAlignOverride)
335*0a6a1f1dSLionel Sambuc     : X86GenSubtargetInfo(TT, CPU, FS), X86ProcFamily(Others),
336*0a6a1f1dSLionel Sambuc       PICStyle(PICStyles::None), TargetTriple(TT),
337*0a6a1f1dSLionel Sambuc       DL(computeDataLayout(TargetTriple)),
338*0a6a1f1dSLionel Sambuc       StackAlignOverride(StackAlignOverride),
339*0a6a1f1dSLionel Sambuc       In64BitMode(TargetTriple.getArch() == Triple::x86_64),
340*0a6a1f1dSLionel Sambuc       In32BitMode(TargetTriple.getArch() == Triple::x86 &&
341*0a6a1f1dSLionel Sambuc                   TargetTriple.getEnvironment() != Triple::CODE16),
342*0a6a1f1dSLionel Sambuc       In16BitMode(TargetTriple.getArch() == Triple::x86 &&
343*0a6a1f1dSLionel Sambuc                   TargetTriple.getEnvironment() == Triple::CODE16),
344*0a6a1f1dSLionel Sambuc       TSInfo(DL), InstrInfo(initializeSubtargetDependencies(CPU, FS)),
345*0a6a1f1dSLionel Sambuc       TLInfo(TM), FrameLowering(TargetFrameLowering::StackGrowsDown,
346*0a6a1f1dSLionel Sambuc                                 getStackAlignment(), is64Bit() ? -8 : -4) {
347*0a6a1f1dSLionel Sambuc   // Determine the PICStyle based on the target selected.
348*0a6a1f1dSLionel Sambuc   if (TM.getRelocationModel() == Reloc::Static) {
349*0a6a1f1dSLionel Sambuc     // Unless we're in PIC or DynamicNoPIC mode, set the PIC style to None.
350*0a6a1f1dSLionel Sambuc     setPICStyle(PICStyles::None);
351*0a6a1f1dSLionel Sambuc   } else if (is64Bit()) {
352*0a6a1f1dSLionel Sambuc     // PIC in 64 bit mode is always rip-rel.
353*0a6a1f1dSLionel Sambuc     setPICStyle(PICStyles::RIPRel);
354*0a6a1f1dSLionel Sambuc   } else if (isTargetCOFF()) {
355*0a6a1f1dSLionel Sambuc     setPICStyle(PICStyles::None);
356*0a6a1f1dSLionel Sambuc   } else if (isTargetDarwin()) {
357*0a6a1f1dSLionel Sambuc     if (TM.getRelocationModel() == Reloc::PIC_)
358*0a6a1f1dSLionel Sambuc       setPICStyle(PICStyles::StubPIC);
359*0a6a1f1dSLionel Sambuc     else {
360*0a6a1f1dSLionel Sambuc       assert(TM.getRelocationModel() == Reloc::DynamicNoPIC);
361*0a6a1f1dSLionel Sambuc       setPICStyle(PICStyles::StubDynamicNoPIC);
362*0a6a1f1dSLionel Sambuc     }
363*0a6a1f1dSLionel Sambuc   } else if (isTargetELF()) {
364*0a6a1f1dSLionel Sambuc     setPICStyle(PICStyles::GOT);
365*0a6a1f1dSLionel Sambuc   }
366*0a6a1f1dSLionel Sambuc }
367*0a6a1f1dSLionel Sambuc 
enableEarlyIfConversion() const368*0a6a1f1dSLionel Sambuc bool X86Subtarget::enableEarlyIfConversion() const {
369*0a6a1f1dSLionel Sambuc   return hasCMov() && X86EarlyIfConv;
370*0a6a1f1dSLionel Sambuc }
371*0a6a1f1dSLionel Sambuc 
372