1 //===-- X86Subtarget.h - Define Subtarget for the X86 ----------*- C++ -*--===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file declares the X86 specific subclass of TargetSubtargetInfo.
12 //===----------------------------------------------------------------------===//
14 #ifndef X86SUBTARGET_H
15 #define X86SUBTARGET_H
17 #include "llvm/ADT/Triple.h"
18 #include "llvm/IR/CallingConv.h"
19 #include "llvm/Target/TargetSubtargetInfo.h"
22 #define GET_SUBTARGETINFO_HEADER
23 #include "X86GenSubtargetInfo.inc"
30 /// PICStyles - The X86 backend supports a number of different styles of PIC.
34 StubPIC, // Used on i386-darwin in -fPIC mode.
35 StubDynamicNoPIC, // Used on i386-darwin in -mdynamic-no-pic mode.
36 GOT, // Used on many 32-bit unices in -fPIC mode.
37 RIPRel, // Used on X86-64 when not in -static mode.
38 None // Set when in -static mode (not PIC or DynamicNoPIC mode).
42 class X86Subtarget : public X86GenSubtargetInfo {
45 NoMMXSSE, MMX, SSE1, SSE2, SSE3, SSSE3, SSE41, SSE42, AVX, AVX2
49 NoThreeDNow, ThreeDNow, ThreeDNowA
52 enum X86ProcFamilyEnum {
56 /// X86ProcFamily - X86 processor family: Intel Atom, and others
57 X86ProcFamilyEnum X86ProcFamily;
59 /// PICStyle - Which PIC style to use
61 PICStyles::Style PICStyle;
63 /// X86SSELevel - MMX, SSE1, SSE2, SSE3, SSSE3, SSE41, SSE42, or
65 X86SSEEnum X86SSELevel;
67 /// X863DNowLevel - 3DNow or 3DNow Athlon, or none supported.
69 X863DNowEnum X863DNowLevel;
71 /// HasCMov - True if this processor has conditional move instructions
72 /// (generally pentium pro+).
75 /// HasX86_64 - True if the processor supports X86-64 instructions.
79 /// HasPOPCNT - True if the processor supports POPCNT.
82 /// HasSSE4A - True if the processor supports SSE4A instructions.
85 /// HasAES - Target has AES instructions
88 /// HasPCLMUL - Target has carry-less multiplication
91 /// HasFMA - Target has 3-operand fused multiply-add
94 /// HasFMA4 - Target has 4-operand fused multiply-add
97 /// HasXOP - Target has XOP instructions
100 /// HasMOVBE - True if the processor has the MOVBE instruction.
103 /// HasRDRAND - True if the processor has the RDRAND instruction.
106 /// HasF16C - Processor has 16-bit floating point conversion instructions.
109 /// HasFSGSBase - Processor has FS/GS base insturctions.
112 /// HasLZCNT - Processor has LZCNT instruction.
115 /// HasBMI - Processor has BMI1 instructions.
118 /// HasBMI2 - Processor has BMI2 instructions.
121 /// HasRTM - Processor has RTM instructions.
124 /// HasADX - Processor has ADX instructions.
127 /// HasPRFCHW - Processor has PRFCHW instructions.
130 /// IsBTMemSlow - True if BT (bit test) of memory instructions are slow.
133 /// IsUAMemFast - True if unaligned memory access is fast.
136 /// HasVectorUAMem - True if SIMD operations can have unaligned memory
137 /// operands. This may require setting a feature bit in the processor.
140 /// HasCmpxchg16b - True if this processor has the CMPXCHG16B instruction;
141 /// this is true for most x86-64 chips, but not the first AMD chips.
144 /// UseLeaForSP - True if the LEA instruction should be used for adjusting
145 /// the stack pointer. This is an optimization for Intel Atom processors.
148 /// HasSlowDivide - True if smaller divides are significantly faster than
149 /// full divides and should be used when possible.
152 /// PostRAScheduler - True if using post-register-allocation scheduler.
153 bool PostRAScheduler;
155 /// PadShortFunctions - True if the short functions should be padded to prevent
156 /// a stall when returning too early.
157 bool PadShortFunctions;
159 /// stackAlignment - The minimum alignment known to hold of the stack frame on
160 /// entry to the function and which must be maintained by every function.
161 unsigned stackAlignment;
163 /// Max. memset / memcpy size that is turned into rep/movs, rep/stos ops.
165 unsigned MaxInlineSizeThreshold;
167 /// TargetTriple - What processor and OS we're targeting.
170 /// Instruction itineraries for scheduling
171 InstrItineraryData InstrItins;
174 /// StackAlignOverride - Override the stack alignment.
175 unsigned StackAlignOverride;
177 /// In64BitMode - True if compiling for 64-bit, false for 32-bit.
181 /// This constructor initializes the data members to match that
182 /// of the specified triple.
184 X86Subtarget(const std::string &TT, const std::string &CPU,
185 const std::string &FS,
186 unsigned StackAlignOverride, bool is64Bit);
188 /// getStackAlignment - Returns the minimum alignment known to hold of the
189 /// stack frame on entry to the function and which must be maintained by every
190 /// function for this subtarget.
191 unsigned getStackAlignment() const { return stackAlignment; }
193 /// getMaxInlineSizeThreshold - Returns the maximum memset / memcpy size
194 /// that still makes it profitable to inline the call.
195 unsigned getMaxInlineSizeThreshold() const { return MaxInlineSizeThreshold; }
197 /// ParseSubtargetFeatures - Parses features string setting specified
198 /// subtarget options. Definition of function is auto generated by tblgen.
199 void ParseSubtargetFeatures(StringRef CPU, StringRef FS);
201 /// AutoDetectSubtargetFeatures - Auto-detect CPU features using CPUID
203 void AutoDetectSubtargetFeatures();
205 /// \brief Reset the features for the X86 target.
206 virtual void resetSubtargetFeatures(const MachineFunction *MF);
208 void initializeEnvironment();
209 void resetSubtargetFeatures(StringRef CPU, StringRef FS);
211 /// Is this x86_64? (disregarding specific ABI / programming model)
212 bool is64Bit() const {
216 /// Is this x86_64 with the ILP32 programming model (x32 ABI)?
217 bool isTarget64BitILP32() const {
218 return In64BitMode && (TargetTriple.getEnvironment() == Triple::GNUX32);
221 /// Is this x86_64 with the LP64 programming model (standard AMD64, no x32)?
222 bool isTarget64BitLP64() const {
223 return In64BitMode && (TargetTriple.getEnvironment() != Triple::GNUX32);
226 PICStyles::Style getPICStyle() const { return PICStyle; }
227 void setPICStyle(PICStyles::Style Style) { PICStyle = Style; }
229 bool hasCMov() const { return HasCMov; }
230 bool hasMMX() const { return X86SSELevel >= MMX; }
231 bool hasSSE1() const { return X86SSELevel >= SSE1; }
232 bool hasSSE2() const { return X86SSELevel >= SSE2; }
233 bool hasSSE3() const { return X86SSELevel >= SSE3; }
234 bool hasSSSE3() const { return X86SSELevel >= SSSE3; }
235 bool hasSSE41() const { return X86SSELevel >= SSE41; }
236 bool hasSSE42() const { return X86SSELevel >= SSE42; }
237 bool hasAVX() const { return X86SSELevel >= AVX; }
238 bool hasAVX2() const { return X86SSELevel >= AVX2; }
239 bool hasFp256() const { return hasAVX(); }
240 bool hasInt256() const { return hasAVX2(); }
241 bool hasSSE4A() const { return HasSSE4A; }
242 bool has3DNow() const { return X863DNowLevel >= ThreeDNow; }
243 bool has3DNowA() const { return X863DNowLevel >= ThreeDNowA; }
244 bool hasPOPCNT() const { return HasPOPCNT; }
245 bool hasAES() const { return HasAES; }
246 bool hasPCLMUL() const { return HasPCLMUL; }
247 bool hasFMA() const { return HasFMA; }
248 // FIXME: Favor FMA when both are enabled. Is this the right thing to do?
249 bool hasFMA4() const { return HasFMA4 && !HasFMA; }
250 bool hasXOP() const { return HasXOP; }
251 bool hasMOVBE() const { return HasMOVBE; }
252 bool hasRDRAND() const { return HasRDRAND; }
253 bool hasF16C() const { return HasF16C; }
254 bool hasFSGSBase() const { return HasFSGSBase; }
255 bool hasLZCNT() const { return HasLZCNT; }
256 bool hasBMI() const { return HasBMI; }
257 bool hasBMI2() const { return HasBMI2; }
258 bool hasRTM() const { return HasRTM; }
259 bool hasADX() const { return HasADX; }
260 bool hasPRFCHW() const { return HasPRFCHW; }
261 bool isBTMemSlow() const { return IsBTMemSlow; }
262 bool isUnalignedMemAccessFast() const { return IsUAMemFast; }
263 bool hasVectorUAMem() const { return HasVectorUAMem; }
264 bool hasCmpxchg16b() const { return HasCmpxchg16b; }
265 bool useLeaForSP() const { return UseLeaForSP; }
266 bool hasSlowDivide() const { return HasSlowDivide; }
267 bool padShortFunctions() const { return PadShortFunctions; }
269 bool isAtom() const { return X86ProcFamily == IntelAtom; }
271 const Triple &getTargetTriple() const { return TargetTriple; }
273 bool isTargetDarwin() const { return TargetTriple.isOSDarwin(); }
274 bool isTargetFreeBSD() const {
275 return TargetTriple.getOS() == Triple::FreeBSD;
277 bool isTargetSolaris() const {
278 return TargetTriple.getOS() == Triple::Solaris;
280 bool isTargetELF() const {
281 return (TargetTriple.getEnvironment() == Triple::ELF ||
282 TargetTriple.isOSBinFormatELF());
284 bool isTargetLinux() const { return TargetTriple.getOS() == Triple::Linux; }
285 bool isTargetNaCl() const {
286 return TargetTriple.getOS() == Triple::NaCl;
288 bool isTargetNaCl32() const { return isTargetNaCl() && !is64Bit(); }
289 bool isTargetNaCl64() const { return isTargetNaCl() && is64Bit(); }
290 bool isTargetWindows() const { return TargetTriple.getOS() == Triple::Win32; }
291 bool isTargetMingw() const { return TargetTriple.getOS() == Triple::MinGW32; }
292 bool isTargetCygwin() const { return TargetTriple.getOS() == Triple::Cygwin; }
293 bool isTargetCygMing() const { return TargetTriple.isOSCygMing(); }
294 bool isTargetCOFF() const {
295 return (TargetTriple.getEnvironment() != Triple::ELF &&
296 TargetTriple.isOSBinFormatCOFF());
298 bool isTargetEnvMacho() const { return TargetTriple.isEnvironmentMachO(); }
300 bool isTargetWin64() const {
301 // FIXME: x86_64-cygwin has not been released yet.
302 return In64BitMode && TargetTriple.isOSWindows();
305 bool isTargetWin32() const {
306 // FIXME: Cygwin is included for isTargetWin64 -- should it be included
308 return !In64BitMode && (isTargetMingw() || isTargetWindows());
311 bool isPICStyleSet() const { return PICStyle != PICStyles::None; }
312 bool isPICStyleGOT() const { return PICStyle == PICStyles::GOT; }
313 bool isPICStyleRIPRel() const { return PICStyle == PICStyles::RIPRel; }
315 bool isPICStyleStubPIC() const {
316 return PICStyle == PICStyles::StubPIC;
319 bool isPICStyleStubNoDynamic() const {
320 return PICStyle == PICStyles::StubDynamicNoPIC;
322 bool isPICStyleStubAny() const {
323 return PICStyle == PICStyles::StubDynamicNoPIC ||
324 PICStyle == PICStyles::StubPIC; }
326 /// ClassifyGlobalReference - Classify a global variable reference for the
327 /// current subtarget according to how we should reference it in a non-pcrel
329 unsigned char ClassifyGlobalReference(const GlobalValue *GV,
330 const TargetMachine &TM)const;
332 /// ClassifyBlockAddressReference - Classify a blockaddress reference for the
333 /// current subtarget according to how we should reference it in a non-pcrel
335 unsigned char ClassifyBlockAddressReference() const;
337 /// IsLegalToCallImmediateAddr - Return true if the subtarget allows calls
338 /// to immediate address.
339 bool IsLegalToCallImmediateAddr(const TargetMachine &TM) const;
341 /// This function returns the name of a function which has an interface
342 /// like the non-standard bzero function, if such a function exists on
343 /// the current subtarget and it is considered prefereable over
344 /// memset with zero passed as the second argument. Otherwise it
346 const char *getBZeroEntry() const;
348 /// This function returns true if the target has sincos() routine in its
349 /// compiler runtime or math libraries.
350 bool hasSinCos() const;
352 /// enablePostRAScheduler - run for Atom optimization.
353 bool enablePostRAScheduler(CodeGenOpt::Level OptLevel,
354 TargetSubtargetInfo::AntiDepBreakMode& Mode,
355 RegClassVector& CriticalPathRCs) const;
357 bool postRAScheduler() const { return PostRAScheduler; }
359 /// getInstrItins = Return the instruction itineraries based on the
360 /// subtarget selection.
361 const InstrItineraryData &getInstrItineraryData() const { return InstrItins; }
364 } // End llvm namespace