LLVM API Documentation

X86Subtarget.h

Go to the documentation of this file.
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 Module;
00022 class GlobalValue;
00023 class TargetMachine;
00024   
00025 namespace PICStyles {
00026 enum Style {
00027   Stub, GOT, RIPRel, WinPIC, None
00028 };
00029 }
00030 
00031 class X86Subtarget : public TargetSubtarget {
00032 public:
00033   enum AsmWriterFlavorTy {
00034     // Note: This numbering has to match the GCC assembler dialects for inline
00035     // asm alternatives to work right.
00036     ATT = 0, Intel = 1, Unset
00037   };
00038 protected:
00039   enum X86SSEEnum {
00040     NoMMXSSE, MMX, SSE1, SSE2, SSE3, SSSE3, SSE41, SSE42
00041   };
00042 
00043   enum X863DNowEnum {
00044     NoThreeDNow, ThreeDNow, ThreeDNowA
00045   };
00046 
00047   /// AsmFlavor - Which x86 asm dialect to use.
00048   ///
00049   AsmWriterFlavorTy AsmFlavor;
00050 
00051   /// PICStyle - Which PIC style to use
00052   ///
00053   PICStyles::Style PICStyle;
00054   
00055   /// X86SSELevel - MMX, SSE1, SSE2, SSE3, SSSE3, SSE41, SSE42, or
00056   /// none supported.
00057   X86SSEEnum X86SSELevel;
00058 
00059   /// X863DNowLevel - 3DNow or 3DNow Athlon, or none supported.
00060   ///
00061   X863DNowEnum X863DNowLevel;
00062 
00063   /// HasX86_64 - True if the processor supports X86-64 instructions.
00064   ///
00065   bool HasX86_64;
00066 
00067   /// IsBTMemSlow - True if BT (bit test) of memory instructions are slow.
00068   bool IsBTMemSlow;
00069   
00070   /// DarwinVers - Nonzero if this is a darwin platform: the numeric
00071   /// version of the platform, e.g. 8 = 10.4 (Tiger), 9 = 10.5 (Leopard), etc.
00072   unsigned char DarwinVers; // Is any darwin-x86 platform.
00073 
00074   /// isLinux - true if this is a "linux" platform.
00075   bool IsLinux;
00076 
00077   /// stackAlignment - The minimum alignment known to hold of the stack frame on
00078   /// entry to the function and which must be maintained by every function.
00079   unsigned stackAlignment;
00080 
00081   /// Max. memset / memcpy size that is turned into rep/movs, rep/stos ops.
00082   ///
00083   unsigned MaxInlineSizeThreshold;
00084 
00085 private:
00086   /// Is64Bit - True if the processor supports 64-bit instructions and module
00087   /// pointer size is 64 bit.
00088   bool Is64Bit;
00089 
00090 public:
00091   enum {
00092     isELF, isCygwin, isDarwin, isWindows, isMingw
00093   } TargetType;
00094 
00095   /// This constructor initializes the data members to match that
00096   /// of the specified module.
00097   ///
00098   X86Subtarget(const Module &M, const std::string &FS, bool is64Bit);
00099 
00100   /// getStackAlignment - Returns the minimum alignment known to hold of the
00101   /// stack frame on entry to the function and which must be maintained by every
00102   /// function for this subtarget.
00103   unsigned getStackAlignment() const { return stackAlignment; }
00104 
00105   /// getMaxInlineSizeThreshold - Returns the maximum memset / memcpy size
00106   /// that still makes it profitable to inline the call.
00107   unsigned getMaxInlineSizeThreshold() const { return MaxInlineSizeThreshold; }
00108 
00109   /// ParseSubtargetFeatures - Parses features string setting specified
00110   /// subtarget options.  Definition of function is auto generated by tblgen.
00111   void ParseSubtargetFeatures(const std::string &FS, const std::string &CPU);
00112 
00113   /// AutoDetectSubtargetFeatures - Auto-detect CPU features using CPUID
00114   /// instruction.
00115   void AutoDetectSubtargetFeatures();
00116 
00117   bool is64Bit() const { return Is64Bit; }
00118 
00119   PICStyles::Style getPICStyle() const { return PICStyle; }
00120   void setPICStyle(PICStyles::Style Style)  { PICStyle = Style; }
00121 
00122   bool hasMMX() const { return X86SSELevel >= MMX; }
00123   bool hasSSE1() const { return X86SSELevel >= SSE1; }
00124   bool hasSSE2() const { return X86SSELevel >= SSE2; }
00125   bool hasSSE3() const { return X86SSELevel >= SSE3; }
00126   bool hasSSSE3() const { return X86SSELevel >= SSSE3; }
00127   bool hasSSE41() const { return X86SSELevel >= SSE41; }
00128   bool hasSSE42() const { return X86SSELevel >= SSE42; }
00129   bool has3DNow() const { return X863DNowLevel >= ThreeDNow; }
00130   bool has3DNowA() const { return X863DNowLevel >= ThreeDNowA; }
00131 
00132   bool isBTMemSlow() const { return IsBTMemSlow; }
00133 
00134   unsigned getAsmFlavor() const {
00135     return AsmFlavor != Unset ? unsigned(AsmFlavor) : 0;
00136   }
00137 
00138   bool isFlavorAtt() const { return AsmFlavor == ATT; }
00139   bool isFlavorIntel() const { return AsmFlavor == Intel; }
00140 
00141   bool isTargetDarwin() const { return TargetType == isDarwin; }
00142   bool isTargetELF() const {
00143     return TargetType == isELF;
00144   }
00145   bool isTargetWindows() const { return TargetType == isWindows; }
00146   bool isTargetMingw() const { return TargetType == isMingw; }
00147   bool isTargetCygMing() const { return (TargetType == isMingw ||
00148                                          TargetType == isCygwin); }
00149   bool isTargetCygwin() const { return TargetType == isCygwin; }
00150   bool isTargetWin64() const {
00151     return (Is64Bit && (TargetType == isMingw || TargetType == isWindows));
00152   }
00153 
00154   std::string getDataLayout() const {
00155     const char *p;
00156     if (is64Bit())
00157       p = "e-p:64:64-s:64-f64:64:64-i64:64:64-f80:128:128";
00158     else {
00159       if (isTargetDarwin())
00160         p = "e-p:32:32-f64:32:64-i64:32:64-f80:128:128";
00161       else
00162         p = "e-p:32:32-f64:32:64-i64:32:64-f80:32:32";
00163     }
00164     return std::string(p);
00165   }
00166 
00167   bool isPICStyleSet() const { return PICStyle != PICStyles::None; }
00168   bool isPICStyleGOT() const { return PICStyle == PICStyles::GOT; }
00169   bool isPICStyleStub() const { return PICStyle == PICStyles::Stub; }
00170   bool isPICStyleRIPRel() const { return PICStyle == PICStyles::RIPRel; }
00171   bool isPICStyleWinPIC() const { return PICStyle == PICStyles:: WinPIC; }
00172   
00173   /// getDarwinVers - Return the darwin version number, 8 = tiger, 9 = leopard.
00174   unsigned getDarwinVers() const { return DarwinVers; }
00175   
00176   /// isLinux - Return true if the target is "Linux".
00177   bool isLinux() const { return IsLinux; }
00178 
00179   /// True if accessing the GV requires an extra load. For Windows, dllimported
00180   /// symbols are indirect, loading the value at address GV rather then the
00181   /// value of GV itself. This means that the GlobalAddress must be in the base
00182   /// or index register of the address, not the GV offset field.
00183   bool GVRequiresExtraLoad(const GlobalValue* GV, const TargetMachine& TM,
00184                            bool isDirectCall) const;
00185 
00186   /// True if accessing the GV requires a register.  This is a superset of the
00187   /// cases where GVRequiresExtraLoad is true.  Some variations of PIC require
00188   /// a register, but not an extra load.
00189   bool GVRequiresRegister(const GlobalValue* GV, const TargetMachine& TM,
00190                            bool isDirectCall) const;
00191 
00192   /// This function returns the name of a function which has an interface
00193   /// like the non-standard bzero function, if such a function exists on
00194   /// the current subtarget and it is considered prefereable over
00195   /// memset with zero passed as the second argument. Otherwise it
00196   /// returns null.
00197   const char *getBZeroEntry() const;
00198 
00199   /// getSpecialAddressLatency - For targets where it is beneficial to
00200   /// backschedule instructions that compute addresses, return a value
00201   /// indicating the number of scheduling cycles of backscheduling that
00202   /// should be attempted.
00203   unsigned getSpecialAddressLatency() const;
00204 };
00205 
00206 namespace X86 {
00207   /// GetCpuIDAndInfo - Execute the specified cpuid and return the 4 values in
00208   /// the specified arguments.  If we can't run cpuid on the host, return true.
00209   bool GetCpuIDAndInfo(unsigned value, unsigned *rEAX, unsigned *rEBX,
00210                        unsigned *rECX, unsigned *rEDX);
00211 }
00212 
00213 } // End llvm namespace
00214 
00215 #endif



This web site is hosted by the Computer Science Department at the University of Illinois at Urbana-Champaign.