c865500deb30300389e1a84dc2dbcf8dc6c33730
[oota-llvm.git] / lib / Target / X86 / X86.td
1 //===-- X86.td - Target definition file for the Intel X86 --*- tablegen -*-===//
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 is a target description file for the Intel i386 architecture, referred
11 // to here as the "X86" architecture.
12 //
13 //===----------------------------------------------------------------------===//
14
15 // Get the target-independent interfaces which we are implementing...
16 //
17 include "llvm/Target/Target.td"
18
19 //===----------------------------------------------------------------------===//
20 // X86 Subtarget state
21 //
22
23 def Mode64Bit : SubtargetFeature<"64bit-mode", "In64BitMode", "true",
24                                   "64-bit mode (x86_64)">;
25
26 //===----------------------------------------------------------------------===//
27 // X86 Subtarget features
28 //===----------------------------------------------------------------------===//
29
30 def FeatureCMOV    : SubtargetFeature<"cmov","HasCMov", "true",
31                                       "Enable conditional move instructions">;
32
33 def FeaturePOPCNT   : SubtargetFeature<"popcnt", "HasPOPCNT", "true",
34                                        "Support POPCNT instruction">;
35
36
37 def FeatureMMX     : SubtargetFeature<"mmx","X86SSELevel", "MMX",
38                                       "Enable MMX instructions">;
39 def FeatureSSE1    : SubtargetFeature<"sse", "X86SSELevel", "SSE1",
40                                       "Enable SSE instructions",
41                                       // SSE codegen depends on cmovs, and all
42                                       // SSE1+ processors support them.
43                                       [FeatureMMX, FeatureCMOV]>;
44 def FeatureSSE2    : SubtargetFeature<"sse2", "X86SSELevel", "SSE2",
45                                       "Enable SSE2 instructions",
46                                       [FeatureSSE1]>;
47 def FeatureSSE3    : SubtargetFeature<"sse3", "X86SSELevel", "SSE3",
48                                       "Enable SSE3 instructions",
49                                       [FeatureSSE2]>;
50 def FeatureSSSE3   : SubtargetFeature<"ssse3", "X86SSELevel", "SSSE3",
51                                       "Enable SSSE3 instructions",
52                                       [FeatureSSE3]>;
53 def FeatureSSE41   : SubtargetFeature<"sse41", "X86SSELevel", "SSE41",
54                                       "Enable SSE 4.1 instructions",
55                                       [FeatureSSSE3]>;
56 def FeatureSSE42   : SubtargetFeature<"sse42", "X86SSELevel", "SSE42",
57                                       "Enable SSE 4.2 instructions",
58                                       [FeatureSSE41]>;
59 def Feature3DNow   : SubtargetFeature<"3dnow", "X863DNowLevel", "ThreeDNow",
60                                       "Enable 3DNow! instructions",
61                                       [FeatureMMX]>;
62 def Feature3DNowA  : SubtargetFeature<"3dnowa", "X863DNowLevel", "ThreeDNowA",
63                                       "Enable 3DNow! Athlon instructions",
64                                       [Feature3DNow]>;
65 // All x86-64 hardware has SSE2, but we don't mark SSE2 as an implied
66 // feature, because SSE2 can be disabled (e.g. for compiling OS kernels)
67 // without disabling 64-bit mode.
68 def Feature64Bit   : SubtargetFeature<"64bit", "HasX86_64", "true",
69                                       "Support 64-bit instructions",
70                                       [FeatureCMOV]>;
71 def FeatureCMPXCHG16B : SubtargetFeature<"cmpxchg16b", "HasCmpxchg16b", "true",
72                                       "64-bit with cmpxchg16b",
73                                       [Feature64Bit]>;
74 def FeatureSlowBTMem : SubtargetFeature<"slow-bt-mem", "IsBTMemSlow", "true",
75                                        "Bit testing of memory is slow">;
76 def FeatureFastUAMem : SubtargetFeature<"fast-unaligned-mem",
77                                         "IsUAMemFast", "true",
78                                         "Fast unaligned memory access">;
79 def FeatureSSE4A   : SubtargetFeature<"sse4a", "HasSSE4A", "true",
80                                       "Support SSE 4a instructions",
81                                       [FeatureSSE3]>;
82
83 def FeatureAVX     : SubtargetFeature<"avx", "X86SSELevel", "AVX",
84                                       "Enable AVX instructions",
85                                       [FeatureSSE42]>;
86 def FeatureAVX2    : SubtargetFeature<"avx2", "X86SSELevel", "AVX2",
87                                       "Enable AVX2 instructions",
88                                       [FeatureAVX]>;
89 def FeaturePCLMUL  : SubtargetFeature<"pclmul", "HasPCLMUL", "true",
90                          "Enable packed carry-less multiplication instructions",
91                                [FeatureSSE2]>;
92 def FeatureFMA     : SubtargetFeature<"fma", "HasFMA", "true",
93                                       "Enable three-operand fused multiple-add",
94                                       [FeatureAVX]>;
95 def FeatureFMA4    : SubtargetFeature<"fma4", "HasFMA4", "true",
96                                       "Enable four-operand fused multiple-add",
97                                       [FeatureAVX, FeatureSSE4A]>;
98 def FeatureXOP     : SubtargetFeature<"xop", "HasXOP", "true",
99                                       "Enable XOP instructions",
100                                       [FeatureFMA4]>;
101 def FeatureVectorUAMem : SubtargetFeature<"vector-unaligned-mem",
102                                           "HasVectorUAMem", "true",
103                  "Allow unaligned memory operands on vector/SIMD instructions">;
104 def FeatureAES     : SubtargetFeature<"aes", "HasAES", "true",
105                                       "Enable AES instructions",
106                                       [FeatureSSE2]>;
107 def FeatureMOVBE   : SubtargetFeature<"movbe", "HasMOVBE", "true",
108                                       "Support MOVBE instruction">;
109 def FeatureRDRAND  : SubtargetFeature<"rdrand", "HasRDRAND", "true",
110                                       "Support RDRAND instruction">;
111 def FeatureF16C    : SubtargetFeature<"f16c", "HasF16C", "true",
112                        "Support 16-bit floating point conversion instructions">;
113 def FeatureFSGSBase : SubtargetFeature<"fsgsbase", "HasFSGSBase", "true",
114                                        "Support FS/GS Base instructions">;
115 def FeatureLZCNT   : SubtargetFeature<"lzcnt", "HasLZCNT", "true",
116                                       "Support LZCNT instruction">;
117 def FeatureBMI     : SubtargetFeature<"bmi", "HasBMI", "true",
118                                       "Support BMI instructions">;
119 def FeatureBMI2    : SubtargetFeature<"bmi2", "HasBMI2", "true",
120                                       "Support BMI2 instructions">;
121 def FeatureRTM     : SubtargetFeature<"rtm", "HasRTM", "true",
122                                       "Support RTM instructions">;
123 def FeatureHLE     : SubtargetFeature<"hle", "HasHLE", "true",
124                                       "Support HLE">;
125 def FeatureADX     : SubtargetFeature<"adx", "HasADX", "true",
126                                       "Support ADX instructions">;
127 def FeaturePRFCHW  : SubtargetFeature<"prfchw", "HasPRFCHW", "true",
128                                       "Support PRFCHW instructions">;
129 def FeatureRDSEED  : SubtargetFeature<"rdseed", "HasRDSEED", "true",
130                                       "Support RDSEED instruction">;
131 def FeatureLeaForSP : SubtargetFeature<"lea-sp", "UseLeaForSP", "true",
132                                      "Use LEA for adjusting the stack pointer">;
133 def FeatureSlowDivide : SubtargetFeature<"idiv-to-divb",
134                                      "HasSlowDivide", "true",
135                                      "Use small divide for positive values less than 256">;
136 def FeaturePadShortFunctions : SubtargetFeature<"pad-short-functions",
137                                      "PadShortFunctions", "true",
138                                      "Pad short functions">;
139 def FeatureCallRegIndirect : SubtargetFeature<"call-reg-indirect",
140                                      "CallRegIndirect", "true",
141                                      "Call register indirect">;
142 def FeatureLEAUsesAG : SubtargetFeature<"lea-uses-ag", "LEAUsesAG", "true",
143                                    "LEA instruction needs inputs at AG stage">;
144
145 //===----------------------------------------------------------------------===//
146 // X86 processors supported.
147 //===----------------------------------------------------------------------===//
148
149 include "X86Schedule.td"
150
151 def ProcIntelAtom : SubtargetFeature<"atom", "X86ProcFamily", "IntelAtom",
152                     "Intel Atom processors">;
153
154 class Proc<string Name, list<SubtargetFeature> Features>
155  : ProcessorModel<Name, GenericModel, Features>;
156
157 def : Proc<"generic",         []>;
158 def : Proc<"i386",            []>;
159 def : Proc<"i486",            []>;
160 def : Proc<"i586",            []>;
161 def : Proc<"pentium",         []>;
162 def : Proc<"pentium-mmx",     [FeatureMMX]>;
163 def : Proc<"i686",            []>;
164 def : Proc<"pentiumpro",      [FeatureCMOV]>;
165 def : Proc<"pentium2",        [FeatureMMX, FeatureCMOV]>;
166 def : Proc<"pentium3",        [FeatureSSE1]>;
167 def : Proc<"pentium3m",       [FeatureSSE1, FeatureSlowBTMem]>;
168 def : Proc<"pentium-m",       [FeatureSSE2, FeatureSlowBTMem]>;
169 def : Proc<"pentium4",        [FeatureSSE2]>;
170 def : Proc<"pentium4m",       [FeatureSSE2, FeatureSlowBTMem]>;
171 def : Proc<"x86-64",          [FeatureSSE2, Feature64Bit, FeatureSlowBTMem,
172                                FeatureFastUAMem]>;
173 // Intel Core Duo.
174 def : ProcessorModel<"yonah", SandyBridgeModel,
175                      [FeatureSSE3, FeatureSlowBTMem]>;
176
177 // NetBurst.
178 def : Proc<"prescott", [FeatureSSE3, FeatureSlowBTMem]>;
179 def : Proc<"nocona",   [FeatureSSE3, FeatureCMPXCHG16B, FeatureSlowBTMem]>;
180
181 // Intel Core 2 Solo/Duo.
182 def : ProcessorModel<"core2", SandyBridgeModel,
183                      [FeatureSSSE3, FeatureCMPXCHG16B, FeatureSlowBTMem]>;
184 def : ProcessorModel<"penryn", SandyBridgeModel,
185                      [FeatureSSE41, FeatureCMPXCHG16B, FeatureSlowBTMem]>;
186
187 // Atom.
188 def : ProcessorModel<"atom", AtomModel,
189                      [ProcIntelAtom, FeatureSSSE3, FeatureCMPXCHG16B,
190                       FeatureMOVBE, FeatureSlowBTMem, FeatureLeaForSP,
191                       FeatureSlowDivide,
192                       FeatureCallRegIndirect,
193                       FeatureLEAUsesAG,
194                       FeaturePadShortFunctions]>;
195
196 // "Arrandale" along with corei3 and corei5
197 def : ProcessorModel<"corei7", SandyBridgeModel,
198                      [FeatureSSE42, FeatureCMPXCHG16B, FeatureSlowBTMem,
199                       FeatureFastUAMem, FeaturePOPCNT, FeatureAES]>;
200
201 def : ProcessorModel<"nehalem", SandyBridgeModel,
202                      [FeatureSSE42,  FeatureCMPXCHG16B, FeatureSlowBTMem,
203                       FeatureFastUAMem, FeaturePOPCNT]>;
204 // Westmere is a similar machine to nehalem with some additional features.
205 // Westmere is the corei3/i5/i7 path from nehalem to sandybridge
206 def : ProcessorModel<"westmere", SandyBridgeModel,
207                      [FeatureSSE42, FeatureCMPXCHG16B, FeatureSlowBTMem,
208                       FeatureFastUAMem, FeaturePOPCNT, FeatureAES,
209                       FeaturePCLMUL]>;
210 // Sandy Bridge
211 // SSE is not listed here since llvm treats AVX as a reimplementation of SSE,
212 // rather than a superset.
213 def : ProcessorModel<"corei7-avx", SandyBridgeModel,
214                      [FeatureAVX, FeatureCMPXCHG16B, FeatureFastUAMem,
215                       FeaturePOPCNT, FeatureAES, FeaturePCLMUL]>;
216 // Ivy Bridge
217 def : ProcessorModel<"core-avx-i", SandyBridgeModel,
218                      [FeatureAVX, FeatureCMPXCHG16B, FeatureFastUAMem,
219                       FeaturePOPCNT, FeatureAES, FeaturePCLMUL, FeatureRDRAND,
220                       FeatureF16C, FeatureFSGSBase]>;
221
222 // Haswell
223 def : ProcessorModel<"core-avx2", HaswellModel,
224                      [FeatureAVX2, FeatureCMPXCHG16B, FeatureFastUAMem,
225                       FeaturePOPCNT, FeatureAES, FeaturePCLMUL, FeatureRDRAND,
226                       FeatureF16C, FeatureFSGSBase, FeatureMOVBE, FeatureLZCNT,
227                       FeatureBMI, FeatureBMI2, FeatureFMA, FeatureRTM,
228                       FeatureHLE]>;
229
230 def : Proc<"k6",              [FeatureMMX]>;
231 def : Proc<"k6-2",            [Feature3DNow]>;
232 def : Proc<"k6-3",            [Feature3DNow]>;
233 def : Proc<"athlon",          [Feature3DNowA, FeatureSlowBTMem]>;
234 def : Proc<"athlon-tbird",    [Feature3DNowA, FeatureSlowBTMem]>;
235 def : Proc<"athlon-4",        [FeatureSSE1,   Feature3DNowA, FeatureSlowBTMem]>;
236 def : Proc<"athlon-xp",       [FeatureSSE1,   Feature3DNowA, FeatureSlowBTMem]>;
237 def : Proc<"athlon-mp",       [FeatureSSE1,   Feature3DNowA, FeatureSlowBTMem]>;
238 def : Proc<"k8",              [FeatureSSE2,   Feature3DNowA, Feature64Bit,
239                                FeatureSlowBTMem]>;
240 def : Proc<"opteron",         [FeatureSSE2,   Feature3DNowA, Feature64Bit,
241                                FeatureSlowBTMem]>;
242 def : Proc<"athlon64",        [FeatureSSE2,   Feature3DNowA, Feature64Bit,
243                                FeatureSlowBTMem]>;
244 def : Proc<"athlon-fx",       [FeatureSSE2,   Feature3DNowA, Feature64Bit,
245                                FeatureSlowBTMem]>;
246 def : Proc<"k8-sse3",         [FeatureSSE3,   Feature3DNowA, FeatureCMPXCHG16B,
247                                FeatureSlowBTMem]>;
248 def : Proc<"opteron-sse3",    [FeatureSSE3,   Feature3DNowA, FeatureCMPXCHG16B,
249                                FeatureSlowBTMem]>;
250 def : Proc<"athlon64-sse3",   [FeatureSSE3,   Feature3DNowA, FeatureCMPXCHG16B,
251                                FeatureSlowBTMem]>;
252 def : Proc<"amdfam10",        [FeatureSSE4A,
253                                Feature3DNowA, FeatureCMPXCHG16B, FeatureLZCNT,
254                                FeaturePOPCNT, FeatureSlowBTMem]>;
255 // Bobcat
256 def : Proc<"btver1",          [FeatureSSSE3, FeatureSSE4A, FeatureCMPXCHG16B,
257                                FeatureLZCNT, FeaturePOPCNT]>;
258 // Jaguar
259 def : Proc<"btver2",          [FeatureAVX, FeatureSSE4A, FeatureCMPXCHG16B,
260                                FeatureAES, FeaturePCLMUL, FeatureBMI,
261                                FeatureF16C, FeatureMOVBE, FeatureLZCNT,
262                                FeaturePOPCNT]>;
263 // Bulldozer
264 def : Proc<"bdver1",          [FeatureXOP, FeatureFMA4, FeatureCMPXCHG16B,
265                                FeatureAES, FeaturePCLMUL,
266                                FeatureLZCNT, FeaturePOPCNT]>;
267 // Piledriver
268 def : Proc<"bdver2",          [FeatureXOP, FeatureFMA4, FeatureCMPXCHG16B,
269                                FeatureAES, FeaturePCLMUL,
270                                FeatureF16C, FeatureLZCNT,
271                                FeaturePOPCNT, FeatureBMI, FeatureFMA]>;
272 def : Proc<"geode",           [Feature3DNowA]>;
273
274 def : Proc<"winchip-c6",      [FeatureMMX]>;
275 def : Proc<"winchip2",        [Feature3DNow]>;
276 def : Proc<"c3",              [Feature3DNow]>;
277 def : Proc<"c3-2",            [FeatureSSE1]>;
278
279 //===----------------------------------------------------------------------===//
280 // Register File Description
281 //===----------------------------------------------------------------------===//
282
283 include "X86RegisterInfo.td"
284
285 //===----------------------------------------------------------------------===//
286 // Instruction Descriptions
287 //===----------------------------------------------------------------------===//
288
289 include "X86InstrInfo.td"
290
291 def X86InstrInfo : InstrInfo;
292
293 //===----------------------------------------------------------------------===//
294 // Calling Conventions
295 //===----------------------------------------------------------------------===//
296
297 include "X86CallingConv.td"
298
299
300 //===----------------------------------------------------------------------===//
301 // Assembly Parser
302 //===----------------------------------------------------------------------===//
303
304 def ATTAsmParser : AsmParser {
305   string AsmParserClassName = "AsmParser";
306 }
307
308 def ATTAsmParserVariant : AsmParserVariant {
309   int Variant = 0;
310
311   // Variant name.
312   string Name = "att";
313
314   // Discard comments in assembly strings.
315   string CommentDelimiter = "#";
316
317   // Recognize hard coded registers.
318   string RegisterPrefix = "%";
319 }
320
321 def IntelAsmParserVariant : AsmParserVariant {
322   int Variant = 1;
323
324   // Variant name.
325   string Name = "intel";
326
327   // Discard comments in assembly strings.
328   string CommentDelimiter = ";";
329
330   // Recognize hard coded registers.
331   string RegisterPrefix = "";
332 }
333
334 //===----------------------------------------------------------------------===//
335 // Assembly Printers
336 //===----------------------------------------------------------------------===//
337
338 // The X86 target supports two different syntaxes for emitting machine code.
339 // This is controlled by the -x86-asm-syntax={att|intel}
340 def ATTAsmWriter : AsmWriter {
341   string AsmWriterClassName  = "ATTInstPrinter";
342   int Variant = 0;
343   bit isMCAsmWriter = 1;
344 }
345 def IntelAsmWriter : AsmWriter {
346   string AsmWriterClassName  = "IntelInstPrinter";
347   int Variant = 1;
348   bit isMCAsmWriter = 1;
349 }
350
351 def X86 : Target {
352   // Information about the instructions...
353   let InstructionSet = X86InstrInfo;
354   let AssemblyParsers = [ATTAsmParser];
355   let AssemblyParserVariants = [ATTAsmParserVariant, IntelAsmParserVariant];
356   let AssemblyWriters = [ATTAsmWriter, IntelAsmWriter];
357 }