X86Subtarget.h revision e2c920845a407957b8ae2600feae1f4c85a0d4d0
1//=====---- X86Subtarget.h - Define Subtarget for the X86 -----*- C++ -*--====//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file declares the X86 specific subclass of TargetSubtarget.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef X86SUBTARGET_H
15#define X86SUBTARGET_H
16
17#include "llvm/Target/TargetSubtarget.h"
18#include <string>
19
20namespace llvm {
21class Module;
22class GlobalValue;
23class TargetMachine;
24
25/// PICStyles - The X86 backend supports a number of different styles of PIC.
26///
27namespace PICStyles {
28enum Style {
29  StubPIC,          // Used on i386-darwin in -fPIC mode.
30  StubDynamicNoPIC, // Used on i386-darwin in -mdynamic-no-pic mode.
31  GOT,              // Used on many 32-bit unices in -fPIC mode.
32  RIPRel,           // Used on X86-64 when not in -static mode.
33  None              // Set when in -static mode (not PIC or DynamicNoPIC mode).
34};
35}
36
37class X86Subtarget : public TargetSubtarget {
38public:
39  enum AsmWriterFlavorTy {
40    // Note: This numbering has to match the GCC assembler dialects for inline
41    // asm alternatives to work right.
42    ATT = 0, Intel = 1, Unset
43  };
44protected:
45  enum X86SSEEnum {
46    NoMMXSSE, MMX, SSE1, SSE2, SSE3, SSSE3, SSE41, SSE42
47  };
48
49  enum X863DNowEnum {
50    NoThreeDNow, ThreeDNow, ThreeDNowA
51  };
52
53  /// AsmFlavor - Which x86 asm dialect to use.
54  ///
55  AsmWriterFlavorTy AsmFlavor;
56
57  /// PICStyle - Which PIC style to use
58  ///
59  PICStyles::Style PICStyle;
60
61  /// X86SSELevel - MMX, SSE1, SSE2, SSE3, SSSE3, SSE41, SSE42, or
62  /// none supported.
63  X86SSEEnum X86SSELevel;
64
65  /// X863DNowLevel - 3DNow or 3DNow Athlon, or none supported.
66  ///
67  X863DNowEnum X863DNowLevel;
68
69  /// HasX86_64 - True if the processor supports X86-64 instructions.
70  ///
71  bool HasX86_64;
72
73  /// HasSSE4A - True if the processor supports SSE4A instructions.
74  bool HasSSE4A;
75
76  /// HasAVX - Target has AVX instructions
77  bool HasAVX;
78
79  /// HasFMA3 - Target has 3-operand fused multiply-add
80  bool HasFMA3;
81
82  /// HasFMA4 - Target has 4-operand fused multiply-add
83  bool HasFMA4;
84
85  /// IsBTMemSlow - True if BT (bit test) of memory instructions are slow.
86  bool IsBTMemSlow;
87
88  /// DarwinVers - Nonzero if this is a darwin platform: the numeric
89  /// version of the platform, e.g. 8 = 10.4 (Tiger), 9 = 10.5 (Leopard), etc.
90  unsigned char DarwinVers; // Is any darwin-x86 platform.
91
92  /// isLinux - true if this is a "linux" platform.
93  bool IsLinux;
94
95  /// stackAlignment - The minimum alignment known to hold of the stack frame on
96  /// entry to the function and which must be maintained by every function.
97  unsigned stackAlignment;
98
99  /// Max. memset / memcpy size that is turned into rep/movs, rep/stos ops.
100  ///
101  unsigned MaxInlineSizeThreshold;
102
103private:
104  /// Is64Bit - True if the processor supports 64-bit instructions and module
105  /// pointer size is 64 bit.
106  bool Is64Bit;
107
108public:
109  enum {
110    isELF, isCygwin, isDarwin, isWindows, isMingw
111  } TargetType;
112
113  /// This constructor initializes the data members to match that
114  /// of the specified module.
115  ///
116  X86Subtarget(const Module &M, const std::string &FS, bool is64Bit);
117
118  /// getStackAlignment - Returns the minimum alignment known to hold of the
119  /// stack frame on entry to the function and which must be maintained by every
120  /// function for this subtarget.
121  unsigned getStackAlignment() const { return stackAlignment; }
122
123  /// getMaxInlineSizeThreshold - Returns the maximum memset / memcpy size
124  /// that still makes it profitable to inline the call.
125  unsigned getMaxInlineSizeThreshold() const { return MaxInlineSizeThreshold; }
126
127  /// ParseSubtargetFeatures - Parses features string setting specified
128  /// subtarget options.  Definition of function is auto generated by tblgen.
129  std::string ParseSubtargetFeatures(const std::string &FS,
130                                     const std::string &CPU);
131
132  /// AutoDetectSubtargetFeatures - Auto-detect CPU features using CPUID
133  /// instruction.
134  void AutoDetectSubtargetFeatures();
135
136  bool is64Bit() const { return Is64Bit; }
137
138  PICStyles::Style getPICStyle() const { return PICStyle; }
139  void setPICStyle(PICStyles::Style Style)  { PICStyle = Style; }
140
141  bool hasMMX() const { return X86SSELevel >= MMX; }
142  bool hasSSE1() const { return X86SSELevel >= SSE1; }
143  bool hasSSE2() const { return X86SSELevel >= SSE2; }
144  bool hasSSE3() const { return X86SSELevel >= SSE3; }
145  bool hasSSSE3() const { return X86SSELevel >= SSSE3; }
146  bool hasSSE41() const { return X86SSELevel >= SSE41; }
147  bool hasSSE42() const { return X86SSELevel >= SSE42; }
148  bool hasSSE4A() const { return HasSSE4A; }
149  bool has3DNow() const { return X863DNowLevel >= ThreeDNow; }
150  bool has3DNowA() const { return X863DNowLevel >= ThreeDNowA; }
151  bool hasAVX() const { return HasAVX; }
152  bool hasFMA3() const { return HasFMA3; }
153  bool hasFMA4() const { return HasFMA4; }
154  bool isBTMemSlow() const { return IsBTMemSlow; }
155
156  unsigned getAsmFlavor() const {
157    return AsmFlavor != Unset ? unsigned(AsmFlavor) : 0;
158  }
159
160  bool isFlavorAtt() const { return AsmFlavor == ATT; }
161  bool isFlavorIntel() const { return AsmFlavor == Intel; }
162
163  bool isTargetDarwin() const { return TargetType == isDarwin; }
164  bool isTargetELF() const { return TargetType == isELF; }
165  bool isTargetWindows() const { return TargetType == isWindows; }
166  bool isTargetMingw() const { return TargetType == isMingw; }
167  bool isTargetCygMing() const {
168    return TargetType == isMingw || TargetType == isCygwin;
169  }
170  bool isTargetCygwin() const { return TargetType == isCygwin; }
171  bool isTargetWin64() const {
172    return Is64Bit && (TargetType == isMingw || TargetType == isWindows);
173  }
174
175  std::string getDataLayout() const {
176    const char *p;
177    if (is64Bit())
178      p = "e-p:64:64-s:64-f64:64:64-i64:64:64-f80:128:128";
179    else if (isTargetDarwin())
180      p = "e-p:32:32-f64:32:64-i64:32:64-f80:128:128";
181    else
182      p = "e-p:32:32-f64:32:64-i64:32:64-f80:32:32";
183    return std::string(p);
184  }
185
186  bool isPICStyleSet() const { return PICStyle != PICStyles::None; }
187  bool isPICStyleGOT() const { return PICStyle == PICStyles::GOT; }
188  bool isPICStyleRIPRel() const { return PICStyle == PICStyles::RIPRel; }
189
190  bool isPICStyleStubPIC() const {
191    return PICStyle == PICStyles::StubPIC;
192  }
193
194  bool isPICStyleStubNoDynamic() const {
195    return PICStyle == PICStyles::StubDynamicNoPIC;
196  }
197  bool isPICStyleStubAny() const {
198    return PICStyle == PICStyles::StubDynamicNoPIC ||
199           PICStyle == PICStyles::StubPIC; }
200
201  /// getDarwinVers - Return the darwin version number, 8 = Tiger, 9 = Leopard,
202  /// 10 = Snow Leopard, etc.
203  unsigned getDarwinVers() const { return DarwinVers; }
204
205  /// isLinux - Return true if the target is "Linux".
206  bool isLinux() const { return IsLinux; }
207
208
209  /// ClassifyGlobalReference - Classify a global variable reference for the
210  /// current subtarget according to how we should reference it in a non-pcrel
211  /// context.
212  unsigned char ClassifyGlobalReference(const GlobalValue *GV,
213                                        const TargetMachine &TM)const;
214
215  /// IsLegalToCallImmediateAddr - Return true if the subtarget allows calls
216  /// to immediate address.
217  bool IsLegalToCallImmediateAddr(const TargetMachine &TM) const;
218
219  /// This function returns the name of a function which has an interface
220  /// like the non-standard bzero function, if such a function exists on
221  /// the current subtarget and it is considered prefereable over
222  /// memset with zero passed as the second argument. Otherwise it
223  /// returns null.
224  const char *getBZeroEntry() const;
225
226  /// getSpecialAddressLatency - For targets where it is beneficial to
227  /// backschedule instructions that compute addresses, return a value
228  /// indicating the number of scheduling cycles of backscheduling that
229  /// should be attempted.
230  unsigned getSpecialAddressLatency() const;
231};
232
233namespace X86 {
234  /// GetCpuIDAndInfo - Execute the specified cpuid and return the 4 values in
235  /// the specified arguments.  If we can't run cpuid on the host, return true.
236  bool GetCpuIDAndInfo(unsigned value, unsigned *rEAX, unsigned *rEBX,
237                       unsigned *rECX, unsigned *rEDX);
238}
239
240} // End llvm namespace
241
242#endif
243