LLVM API Documentation
00001 //=====---- X86Subtarget.h - Define Subtarget for the X86 -----*- C++ -*--====// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file declares the X86 specific subclass of TargetSubtarget. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #ifndef X86SUBTARGET_H 00015 #define X86SUBTARGET_H 00016 00017 #include "llvm/Target/TargetSubtarget.h" 00018 #include <string> 00019 00020 namespace llvm { 00021 class GlobalValue; 00022 class TargetMachine; 00023 00024 /// PICStyles - The X86 backend supports a number of different styles of PIC. 00025 /// 00026 namespace PICStyles { 00027 enum Style { 00028 StubPIC, // Used on i386-darwin in -fPIC mode. 00029 StubDynamicNoPIC, // Used on i386-darwin in -mdynamic-no-pic mode. 00030 GOT, // Used on many 32-bit unices in -fPIC mode. 00031 RIPRel, // Used on X86-64 when not in -static mode. 00032 None // Set when in -static mode (not PIC or DynamicNoPIC mode). 00033 }; 00034 } 00035 00036 class X86Subtarget : public TargetSubtarget { 00037 protected: 00038 enum X86SSEEnum { 00039 NoMMXSSE, MMX, SSE1, SSE2, SSE3, SSSE3, SSE41, SSE42 00040 }; 00041 00042 enum X863DNowEnum { 00043 NoThreeDNow, ThreeDNow, ThreeDNowA 00044 }; 00045 00046 /// PICStyle - Which PIC style to use 00047 /// 00048 PICStyles::Style PICStyle; 00049 00050 /// X86SSELevel - MMX, SSE1, SSE2, SSE3, SSSE3, SSE41, SSE42, or 00051 /// none supported. 00052 X86SSEEnum X86SSELevel; 00053 00054 /// X863DNowLevel - 3DNow or 3DNow Athlon, or none supported. 00055 /// 00056 X863DNowEnum X863DNowLevel; 00057 00058 /// HasX86_64 - True if the processor supports X86-64 instructions. 00059 /// 00060 bool HasX86_64; 00061 00062 /// HasSSE4A - True if the processor supports SSE4A instructions. 00063 bool HasSSE4A; 00064 00065 /// HasAVX - Target has AVX instructions 00066 bool HasAVX; 00067 00068 /// HasFMA3 - Target has 3-operand fused multiply-add 00069 bool HasFMA3; 00070 00071 /// HasFMA4 - Target has 4-operand fused multiply-add 00072 bool HasFMA4; 00073 00074 /// IsBTMemSlow - True if BT (bit test) of memory instructions are slow. 00075 bool IsBTMemSlow; 00076 00077 /// DarwinVers - Nonzero if this is a darwin platform: the numeric 00078 /// version of the platform, e.g. 8 = 10.4 (Tiger), 9 = 10.5 (Leopard), etc. 00079 unsigned char DarwinVers; // Is any darwin-x86 platform. 00080 00081 /// isLinux - true if this is a "linux" platform. 00082 bool IsLinux; 00083 00084 /// stackAlignment - The minimum alignment known to hold of the stack frame on 00085 /// entry to the function and which must be maintained by every function. 00086 unsigned stackAlignment; 00087 00088 /// Max. memset / memcpy size that is turned into rep/movs, rep/stos ops. 00089 /// 00090 unsigned MaxInlineSizeThreshold; 00091 00092 private: 00093 /// Is64Bit - True if the processor supports 64-bit instructions and 00094 /// pointer size is 64 bit. 00095 bool Is64Bit; 00096 00097 public: 00098 enum { 00099 isELF, isCygwin, isDarwin, isWindows, isMingw 00100 } TargetType; 00101 00102 /// This constructor initializes the data members to match that 00103 /// of the specified triple. 00104 /// 00105 X86Subtarget(const std::string &TT, const std::string &FS, bool is64Bit); 00106 00107 /// getStackAlignment - Returns the minimum alignment known to hold of the 00108 /// stack frame on entry to the function and which must be maintained by every 00109 /// function for this subtarget. 00110 unsigned getStackAlignment() const { return stackAlignment; } 00111 00112 /// getMaxInlineSizeThreshold - Returns the maximum memset / memcpy size 00113 /// that still makes it profitable to inline the call. 00114 unsigned getMaxInlineSizeThreshold() const { return MaxInlineSizeThreshold; } 00115 00116 /// ParseSubtargetFeatures - Parses features string setting specified 00117 /// subtarget options. Definition of function is auto generated by tblgen. 00118 std::string ParseSubtargetFeatures(const std::string &FS, 00119 const std::string &CPU); 00120 00121 /// AutoDetectSubtargetFeatures - Auto-detect CPU features using CPUID 00122 /// instruction. 00123 void AutoDetectSubtargetFeatures(); 00124 00125 bool is64Bit() const { return Is64Bit; } 00126 00127 PICStyles::Style getPICStyle() const { return PICStyle; } 00128 void setPICStyle(PICStyles::Style Style) { PICStyle = Style; } 00129 00130 bool hasMMX() const { return X86SSELevel >= MMX; } 00131 bool hasSSE1() const { return X86SSELevel >= SSE1; } 00132 bool hasSSE2() const { return X86SSELevel >= SSE2; } 00133 bool hasSSE3() const { return X86SSELevel >= SSE3; } 00134 bool hasSSSE3() const { return X86SSELevel >= SSSE3; } 00135 bool hasSSE41() const { return X86SSELevel >= SSE41; } 00136 bool hasSSE42() const { return X86SSELevel >= SSE42; } 00137 bool hasSSE4A() const { return HasSSE4A; } 00138 bool has3DNow() const { return X863DNowLevel >= ThreeDNow; } 00139 bool has3DNowA() const { return X863DNowLevel >= ThreeDNowA; } 00140 bool hasAVX() const { return HasAVX; } 00141 bool hasFMA3() const { return HasFMA3; } 00142 bool hasFMA4() const { return HasFMA4; } 00143 bool isBTMemSlow() const { return IsBTMemSlow; } 00144 00145 bool isTargetDarwin() const { return TargetType == isDarwin; } 00146 bool isTargetELF() const { return TargetType == isELF; } 00147 bool isTargetWindows() const { return TargetType == isWindows; } 00148 bool isTargetMingw() const { return TargetType == isMingw; } 00149 bool isTargetCygMing() const { 00150 return TargetType == isMingw || TargetType == isCygwin; 00151 } 00152 bool isTargetCygwin() const { return TargetType == isCygwin; } 00153 bool isTargetWin64() const { 00154 return Is64Bit && (TargetType == isMingw || TargetType == isWindows); 00155 } 00156 00157 std::string getDataLayout() const { 00158 const char *p; 00159 if (is64Bit()) 00160 p = "e-p:64:64-s:64-f64:64:64-i64:64:64-f80:128:128"; 00161 else if (isTargetDarwin()) 00162 p = "e-p:32:32-f64:32:64-i64:32:64-f80:128:128"; 00163 else 00164 p = "e-p:32:32-f64:32:64-i64:32:64-f80:32:32"; 00165 return std::string(p); 00166 } 00167 00168 bool isPICStyleSet() const { return PICStyle != PICStyles::None; } 00169 bool isPICStyleGOT() const { return PICStyle == PICStyles::GOT; } 00170 bool isPICStyleRIPRel() const { return PICStyle == PICStyles::RIPRel; } 00171 00172 bool isPICStyleStubPIC() const { 00173 return PICStyle == PICStyles::StubPIC; 00174 } 00175 00176 bool isPICStyleStubNoDynamic() const { 00177 return PICStyle == PICStyles::StubDynamicNoPIC; 00178 } 00179 bool isPICStyleStubAny() const { 00180 return PICStyle == PICStyles::StubDynamicNoPIC || 00181 PICStyle == PICStyles::StubPIC; } 00182 00183 /// getDarwinVers - Return the darwin version number, 8 = Tiger, 9 = Leopard, 00184 /// 10 = Snow Leopard, etc. 00185 unsigned getDarwinVers() const { return DarwinVers; } 00186 00187 /// isLinux - Return true if the target is "Linux". 00188 bool isLinux() const { return IsLinux; } 00189 00190 00191 /// ClassifyGlobalReference - Classify a global variable reference for the 00192 /// current subtarget according to how we should reference it in a non-pcrel 00193 /// context. 00194 unsigned char ClassifyGlobalReference(const GlobalValue *GV, 00195 const TargetMachine &TM)const; 00196 00197 /// IsLegalToCallImmediateAddr - Return true if the subtarget allows calls 00198 /// to immediate address. 00199 bool IsLegalToCallImmediateAddr(const TargetMachine &TM) const; 00200 00201 /// This function returns the name of a function which has an interface 00202 /// like the non-standard bzero function, if such a function exists on 00203 /// the current subtarget and it is considered prefereable over 00204 /// memset with zero passed as the second argument. Otherwise it 00205 /// returns null. 00206 const char *getBZeroEntry() const; 00207 00208 /// getSpecialAddressLatency - For targets where it is beneficial to 00209 /// backschedule instructions that compute addresses, return a value 00210 /// indicating the number of scheduling cycles of backscheduling that 00211 /// should be attempted. 00212 unsigned getSpecialAddressLatency() const; 00213 }; 00214 00215 namespace X86 { 00216 /// GetCpuIDAndInfo - Execute the specified cpuid and return the 4 values in 00217 /// the specified arguments. If we can't run cpuid on the host, return true. 00218 bool GetCpuIDAndInfo(unsigned value, unsigned *rEAX, unsigned *rEBX, 00219 unsigned *rECX, unsigned *rEDX); 00220 } 00221 00222 } // End llvm namespace 00223 00224 #endif