blob: 46476f20400a12dc64d64743f0db566f783a2d04 [file] [log] [blame]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001//=====---- X86Subtarget.h - Define Subtarget for the X86 -----*- C++ -*--====//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner081ce942007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00007//
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"
Dan Gohmanf17a25c2007-07-18 16:29:46 +000018#include <string>
19
20namespace llvm {
21class Module;
22class GlobalValue;
23class TargetMachine;
24
Duncan Sandsde5f95f2008-11-28 09:29:37 +000025namespace PICStyles {
Dan Gohmanf17a25c2007-07-18 16:29:46 +000026enum Style {
27 Stub, GOT, RIPRel, WinPIC, None
28};
29}
30
31class X86Subtarget : public TargetSubtarget {
32public:
33 enum AsmWriterFlavorTy {
34 // Note: This numbering has to match the GCC assembler dialects for inline
35 // asm alternatives to work right.
36 ATT = 0, Intel = 1, Unset
37 };
38protected:
39 enum X86SSEEnum {
Nate Begemanb2975562008-02-03 07:18:54 +000040 NoMMXSSE, MMX, SSE1, SSE2, SSE3, SSSE3, SSE41, SSE42
Dan Gohmanf17a25c2007-07-18 16:29:46 +000041 };
42
43 enum X863DNowEnum {
44 NoThreeDNow, ThreeDNow, ThreeDNowA
45 };
46
47 /// AsmFlavor - Which x86 asm dialect to use.
Evan Cheng09e13792007-08-01 23:45:51 +000048 ///
Dan Gohmanf17a25c2007-07-18 16:29:46 +000049 AsmWriterFlavorTy AsmFlavor;
50
51 /// PICStyle - Which PIC style to use
Evan Cheng09e13792007-08-01 23:45:51 +000052 ///
Duncan Sandsde5f95f2008-11-28 09:29:37 +000053 PICStyles::Style PICStyle;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000054
Evan Chenga5aa3602008-02-12 07:59:55 +000055 /// X86SSELevel - MMX, SSE1, SSE2, SSE3, SSSE3, SSE41, SSE42, or
56 /// none supported.
Dan Gohmanf17a25c2007-07-18 16:29:46 +000057 X86SSEEnum X86SSELevel;
58
59 /// X863DNowLevel - 3DNow or 3DNow Athlon, or none supported.
Evan Cheng09e13792007-08-01 23:45:51 +000060 ///
Dan Gohmanf17a25c2007-07-18 16:29:46 +000061 X863DNowEnum X863DNowLevel;
62
63 /// HasX86_64 - True if the processor supports X86-64 instructions.
Evan Cheng09e13792007-08-01 23:45:51 +000064 ///
Dan Gohmanf17a25c2007-07-18 16:29:46 +000065 bool HasX86_64;
Evan Cheng95a77fd2009-01-02 05:35:45 +000066
67 /// IsBTMemSlow - True if BT (bit test) of memory instructions are slow.
68 bool IsBTMemSlow;
Chris Lattner93a2d432008-01-02 19:44:55 +000069
Stefanus Du Toitfe086e62009-05-26 21:04:35 +000070 /// HasSSE4A - True if the processor supports SSE4A instructions.
71 bool HasSSE4A;
72
Chris Lattner93a2d432008-01-02 19:44:55 +000073 /// DarwinVers - Nonzero if this is a darwin platform: the numeric
74 /// version of the platform, e.g. 8 = 10.4 (Tiger), 9 = 10.5 (Leopard), etc.
Dan Gohman2593e2b2008-05-05 16:11:31 +000075 unsigned char DarwinVers; // Is any darwin-x86 platform.
76
77 /// isLinux - true if this is a "linux" platform.
78 bool IsLinux;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000079
80 /// stackAlignment - The minimum alignment known to hold of the stack frame on
81 /// entry to the function and which must be maintained by every function.
82 unsigned stackAlignment;
83
Rafael Espindola7afa9b12007-10-31 11:52:06 +000084 /// Max. memset / memcpy size that is turned into rep/movs, rep/stos ops.
Evan Cheng09e13792007-08-01 23:45:51 +000085 ///
Rafael Espindola7afa9b12007-10-31 11:52:06 +000086 unsigned MaxInlineSizeThreshold;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000087
88private:
89 /// Is64Bit - True if the processor supports 64-bit instructions and module
90 /// pointer size is 64 bit.
91 bool Is64Bit;
92
93public:
94 enum {
Dan Gohman2593e2b2008-05-05 16:11:31 +000095 isELF, isCygwin, isDarwin, isWindows, isMingw
Dan Gohmanf17a25c2007-07-18 16:29:46 +000096 } TargetType;
97
98 /// This constructor initializes the data members to match that
99 /// of the specified module.
100 ///
101 X86Subtarget(const Module &M, const std::string &FS, bool is64Bit);
102
103 /// getStackAlignment - Returns the minimum alignment known to hold of the
104 /// stack frame on entry to the function and which must be maintained by every
105 /// function for this subtarget.
106 unsigned getStackAlignment() const { return stackAlignment; }
107
Rafael Espindola7afa9b12007-10-31 11:52:06 +0000108 /// getMaxInlineSizeThreshold - Returns the maximum memset / memcpy size
109 /// that still makes it profitable to inline the call.
110 unsigned getMaxInlineSizeThreshold() const { return MaxInlineSizeThreshold; }
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000111
112 /// ParseSubtargetFeatures - Parses features string setting specified
113 /// subtarget options. Definition of function is auto generated by tblgen.
Anton Korobeynikov7357d8f2009-05-23 19:50:50 +0000114 std::string ParseSubtargetFeatures(const std::string &FS,
115 const std::string &CPU);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000116
117 /// AutoDetectSubtargetFeatures - Auto-detect CPU features using CPUID
118 /// instruction.
119 void AutoDetectSubtargetFeatures();
120
121 bool is64Bit() const { return Is64Bit; }
122
Duncan Sandsde5f95f2008-11-28 09:29:37 +0000123 PICStyles::Style getPICStyle() const { return PICStyle; }
124 void setPICStyle(PICStyles::Style Style) { PICStyle = Style; }
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000125
126 bool hasMMX() const { return X86SSELevel >= MMX; }
127 bool hasSSE1() const { return X86SSELevel >= SSE1; }
128 bool hasSSE2() const { return X86SSELevel >= SSE2; }
129 bool hasSSE3() const { return X86SSELevel >= SSE3; }
130 bool hasSSSE3() const { return X86SSELevel >= SSSE3; }
Evan Chengcb97ac52008-04-03 08:53:29 +0000131 bool hasSSE41() const { return X86SSELevel >= SSE41; }
132 bool hasSSE42() const { return X86SSELevel >= SSE42; }
Stefanus Du Toitfe086e62009-05-26 21:04:35 +0000133 bool hasSSE4A() const { return HasSSE4A; }
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000134 bool has3DNow() const { return X863DNowLevel >= ThreeDNow; }
135 bool has3DNowA() const { return X863DNowLevel >= ThreeDNowA; }
136
Evan Cheng95a77fd2009-01-02 05:35:45 +0000137 bool isBTMemSlow() const { return IsBTMemSlow; }
138
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000139 unsigned getAsmFlavor() const {
140 return AsmFlavor != Unset ? unsigned(AsmFlavor) : 0;
141 }
142
143 bool isFlavorAtt() const { return AsmFlavor == ATT; }
144 bool isFlavorIntel() const { return AsmFlavor == Intel; }
145
146 bool isTargetDarwin() const { return TargetType == isDarwin; }
Dan Gohmana65530a2008-05-05 00:28:39 +0000147 bool isTargetELF() const {
Dan Gohman2593e2b2008-05-05 16:11:31 +0000148 return TargetType == isELF;
Dan Gohmana65530a2008-05-05 00:28:39 +0000149 }
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000150 bool isTargetWindows() const { return TargetType == isWindows; }
151 bool isTargetMingw() const { return TargetType == isMingw; }
152 bool isTargetCygMing() const { return (TargetType == isMingw ||
153 TargetType == isCygwin); }
154 bool isTargetCygwin() const { return TargetType == isCygwin; }
Anton Korobeynikov06d49b02008-03-22 20:57:27 +0000155 bool isTargetWin64() const {
156 return (Is64Bit && (TargetType == isMingw || TargetType == isWindows));
157 }
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000158
Dale Johannesen09df34c2007-08-06 22:10:35 +0000159 std::string getDataLayout() const {
160 const char *p;
Evan Cheng12ca0ef2007-09-04 16:44:41 +0000161 if (is64Bit())
Rafael Espindolab5c5df42007-09-07 14:52:14 +0000162 p = "e-p:64:64-s:64-f64:64:64-i64:64:64-f80:128:128";
Rafael Espindola5aecf0a2007-08-31 12:23:58 +0000163 else {
164 if (isTargetDarwin())
165 p = "e-p:32:32-f64:32:64-i64:32:64-f80:128:128";
166 else
167 p = "e-p:32:32-f64:32:64-i64:32:64-f80:32:32";
168 }
Dale Johannesen09df34c2007-08-06 22:10:35 +0000169 return std::string(p);
170 }
Dale Johannesend4c671c2007-08-06 21:48:35 +0000171
Duncan Sandsde5f95f2008-11-28 09:29:37 +0000172 bool isPICStyleSet() const { return PICStyle != PICStyles::None; }
173 bool isPICStyleGOT() const { return PICStyle == PICStyles::GOT; }
174 bool isPICStyleStub() const { return PICStyle == PICStyles::Stub; }
175 bool isPICStyleRIPRel() const { return PICStyle == PICStyles::RIPRel; }
176 bool isPICStyleWinPIC() const { return PICStyle == PICStyles:: WinPIC; }
Chris Lattner93a2d432008-01-02 19:44:55 +0000177
178 /// getDarwinVers - Return the darwin version number, 8 = tiger, 9 = leopard.
179 unsigned getDarwinVers() const { return DarwinVers; }
180
Dan Gohman2593e2b2008-05-05 16:11:31 +0000181 /// isLinux - Return true if the target is "Linux".
182 bool isLinux() const { return IsLinux; }
183
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000184 /// True if accessing the GV requires an extra load. For Windows, dllimported
185 /// symbols are indirect, loading the value at address GV rather then the
186 /// value of GV itself. This means that the GlobalAddress must be in the base
187 /// or index register of the address, not the GV offset field.
188 bool GVRequiresExtraLoad(const GlobalValue* GV, const TargetMachine& TM,
189 bool isDirectCall) const;
190
Dale Johannesen69f5ba62008-12-05 21:55:35 +0000191 /// True if accessing the GV requires a register. This is a superset of the
192 /// cases where GVRequiresExtraLoad is true. Some variations of PIC require
193 /// a register, but not an extra load.
194 bool GVRequiresRegister(const GlobalValue* GV, const TargetMachine& TM,
195 bool isDirectCall) const;
196
Evan Cheng6d35a4d2009-05-20 04:53:57 +0000197 /// IsLegalToCallImmediateAddr - Return true if the subtarget allows calls
198 /// to immediate address.
199 bool IsLegalToCallImmediateAddr(const TargetMachine &TM) const;
200
Dan Gohmanf95c2bf2008-04-01 20:38:36 +0000201 /// This function returns the name of a function which has an interface
202 /// like the non-standard bzero function, if such a function exists on
203 /// the current subtarget and it is considered prefereable over
204 /// memset with zero passed as the second argument. Otherwise it
205 /// returns null.
Bill Wendlingd3752032008-09-30 22:05:33 +0000206 const char *getBZeroEntry() const;
Dan Gohman47170992008-12-16 03:35:01 +0000207
208 /// getSpecialAddressLatency - For targets where it is beneficial to
209 /// backschedule instructions that compute addresses, return a value
210 /// indicating the number of scheduling cycles of backscheduling that
211 /// should be attempted.
212 unsigned getSpecialAddressLatency() const;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000213};
214
215namespace X86 {
216 /// GetCpuIDAndInfo - Execute the specified cpuid and return the 4 values in
217 /// the specified arguments. If we can't run cpuid on the host, return true.
218 bool GetCpuIDAndInfo(unsigned value, unsigned *rEAX, unsigned *rEBX,
219 unsigned *rECX, unsigned *rEDX);
220}
221
222} // End llvm namespace
223
224#endif