121
|
1 //===- X86LegalizerInfo.cpp --------------------------------------*- 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 /// \file
|
|
10 /// This file implements the targeting of the Machinelegalizer class for X86.
|
|
11 /// \todo This should be generated by TableGen.
|
|
12 //===----------------------------------------------------------------------===//
|
|
13
|
|
14 #include "X86LegalizerInfo.h"
|
|
15 #include "X86Subtarget.h"
|
|
16 #include "X86TargetMachine.h"
|
|
17 #include "llvm/CodeGen/ValueTypes.h"
|
|
18 #include "llvm/IR/DerivedTypes.h"
|
|
19 #include "llvm/IR/Type.h"
|
|
20 #include "llvm/Target/TargetOpcodes.h"
|
|
21
|
|
22 using namespace llvm;
|
|
23 using namespace TargetOpcode;
|
|
24
|
|
25 X86LegalizerInfo::X86LegalizerInfo(const X86Subtarget &STI,
|
|
26 const X86TargetMachine &TM)
|
|
27 : Subtarget(STI), TM(TM) {
|
|
28
|
|
29 setLegalizerInfo32bit();
|
|
30 setLegalizerInfo64bit();
|
|
31 setLegalizerInfoSSE1();
|
|
32 setLegalizerInfoSSE2();
|
|
33 setLegalizerInfoSSE41();
|
|
34 setLegalizerInfoAVX();
|
|
35 setLegalizerInfoAVX2();
|
|
36 setLegalizerInfoAVX512();
|
|
37 setLegalizerInfoAVX512DQ();
|
|
38 setLegalizerInfoAVX512BW();
|
|
39
|
|
40 computeTables();
|
|
41 }
|
|
42
|
|
43 void X86LegalizerInfo::setLegalizerInfo32bit() {
|
|
44
|
|
45 const LLT p0 = LLT::pointer(0, TM.getPointerSize() * 8);
|
|
46 const LLT s1 = LLT::scalar(1);
|
|
47 const LLT s8 = LLT::scalar(8);
|
|
48 const LLT s16 = LLT::scalar(16);
|
|
49 const LLT s32 = LLT::scalar(32);
|
|
50 const LLT s64 = LLT::scalar(64);
|
|
51
|
|
52 for (auto Ty : {p0, s1, s8, s16, s32})
|
|
53 setAction({G_IMPLICIT_DEF, Ty}, Legal);
|
|
54
|
|
55 for (auto Ty : {s8, s16, s32, p0})
|
|
56 setAction({G_PHI, Ty}, Legal);
|
|
57
|
|
58 setAction({G_PHI, s1}, WidenScalar);
|
|
59
|
|
60 for (unsigned BinOp : {G_ADD, G_SUB, G_MUL, G_AND, G_OR, G_XOR}) {
|
|
61 for (auto Ty : {s8, s16, s32})
|
|
62 setAction({BinOp, Ty}, Legal);
|
|
63
|
|
64 setAction({BinOp, s1}, WidenScalar);
|
|
65 }
|
|
66
|
|
67 for (unsigned Op : {G_UADDE}) {
|
|
68 setAction({Op, s32}, Legal);
|
|
69 setAction({Op, 1, s1}, Legal);
|
|
70 }
|
|
71
|
|
72 for (unsigned MemOp : {G_LOAD, G_STORE}) {
|
|
73 for (auto Ty : {s8, s16, s32, p0})
|
|
74 setAction({MemOp, Ty}, Legal);
|
|
75
|
|
76 setAction({MemOp, s1}, WidenScalar);
|
|
77 // And everything's fine in addrspace 0.
|
|
78 setAction({MemOp, 1, p0}, Legal);
|
|
79 }
|
|
80
|
|
81 // Pointer-handling
|
|
82 setAction({G_FRAME_INDEX, p0}, Legal);
|
|
83 setAction({G_GLOBAL_VALUE, p0}, Legal);
|
|
84
|
|
85 setAction({G_GEP, p0}, Legal);
|
|
86 setAction({G_GEP, 1, s32}, Legal);
|
|
87
|
|
88 for (auto Ty : {s1, s8, s16})
|
|
89 setAction({G_GEP, 1, Ty}, WidenScalar);
|
|
90
|
|
91 // Control-flow
|
|
92 setAction({G_BRCOND, s1}, Legal);
|
|
93
|
|
94 // Constants
|
|
95 for (auto Ty : {s8, s16, s32, p0})
|
|
96 setAction({TargetOpcode::G_CONSTANT, Ty}, Legal);
|
|
97
|
|
98 setAction({TargetOpcode::G_CONSTANT, s1}, WidenScalar);
|
|
99 setAction({TargetOpcode::G_CONSTANT, s64}, NarrowScalar);
|
|
100
|
|
101 // Extensions
|
|
102 for (auto Ty : {s8, s16, s32}) {
|
|
103 setAction({G_ZEXT, Ty}, Legal);
|
|
104 setAction({G_SEXT, Ty}, Legal);
|
|
105 setAction({G_ANYEXT, Ty}, Legal);
|
|
106 }
|
|
107
|
|
108 for (auto Ty : {s1, s8, s16}) {
|
|
109 setAction({G_ZEXT, 1, Ty}, Legal);
|
|
110 setAction({G_SEXT, 1, Ty}, Legal);
|
|
111 setAction({G_ANYEXT, 1, Ty}, Legal);
|
|
112 }
|
|
113
|
|
114 // Comparison
|
|
115 setAction({G_ICMP, s1}, Legal);
|
|
116
|
|
117 for (auto Ty : {s8, s16, s32, p0})
|
|
118 setAction({G_ICMP, 1, Ty}, Legal);
|
|
119 }
|
|
120
|
|
121 void X86LegalizerInfo::setLegalizerInfo64bit() {
|
|
122
|
|
123 if (!Subtarget.is64Bit())
|
|
124 return;
|
|
125
|
|
126 const LLT s32 = LLT::scalar(32);
|
|
127 const LLT s64 = LLT::scalar(64);
|
|
128
|
|
129 setAction({G_IMPLICIT_DEF, s64}, Legal);
|
|
130
|
|
131 setAction({G_PHI, s64}, Legal);
|
|
132
|
|
133 for (unsigned BinOp : {G_ADD, G_SUB, G_MUL, G_AND, G_OR, G_XOR})
|
|
134 setAction({BinOp, s64}, Legal);
|
|
135
|
|
136 for (unsigned MemOp : {G_LOAD, G_STORE})
|
|
137 setAction({MemOp, s64}, Legal);
|
|
138
|
|
139 // Pointer-handling
|
|
140 setAction({G_GEP, 1, s64}, Legal);
|
|
141
|
|
142 // Constants
|
|
143 setAction({TargetOpcode::G_CONSTANT, s64}, Legal);
|
|
144
|
|
145 // Extensions
|
|
146 for (unsigned extOp : {G_ZEXT, G_SEXT, G_ANYEXT}) {
|
|
147 setAction({extOp, s64}, Legal);
|
|
148 setAction({extOp, 1, s32}, Legal);
|
|
149 }
|
|
150
|
|
151 // Comparison
|
|
152 setAction({G_ICMP, 1, s64}, Legal);
|
|
153 }
|
|
154
|
|
155 void X86LegalizerInfo::setLegalizerInfoSSE1() {
|
|
156 if (!Subtarget.hasSSE1())
|
|
157 return;
|
|
158
|
|
159 const LLT s32 = LLT::scalar(32);
|
|
160 const LLT v4s32 = LLT::vector(4, 32);
|
|
161 const LLT v2s64 = LLT::vector(2, 64);
|
|
162
|
|
163 for (unsigned BinOp : {G_FADD, G_FSUB, G_FMUL, G_FDIV})
|
|
164 for (auto Ty : {s32, v4s32})
|
|
165 setAction({BinOp, Ty}, Legal);
|
|
166
|
|
167 for (unsigned MemOp : {G_LOAD, G_STORE})
|
|
168 for (auto Ty : {v4s32, v2s64})
|
|
169 setAction({MemOp, Ty}, Legal);
|
|
170
|
|
171 // Constants
|
|
172 setAction({TargetOpcode::G_FCONSTANT, s32}, Legal);
|
|
173 }
|
|
174
|
|
175 void X86LegalizerInfo::setLegalizerInfoSSE2() {
|
|
176 if (!Subtarget.hasSSE2())
|
|
177 return;
|
|
178
|
|
179 const LLT s32 = LLT::scalar(32);
|
|
180 const LLT s64 = LLT::scalar(64);
|
|
181 const LLT v16s8 = LLT::vector(16, 8);
|
|
182 const LLT v8s16 = LLT::vector(8, 16);
|
|
183 const LLT v4s32 = LLT::vector(4, 32);
|
|
184 const LLT v2s64 = LLT::vector(2, 64);
|
|
185
|
|
186 for (unsigned BinOp : {G_FADD, G_FSUB, G_FMUL, G_FDIV})
|
|
187 for (auto Ty : {s64, v2s64})
|
|
188 setAction({BinOp, Ty}, Legal);
|
|
189
|
|
190 for (unsigned BinOp : {G_ADD, G_SUB})
|
|
191 for (auto Ty : {v16s8, v8s16, v4s32, v2s64})
|
|
192 setAction({BinOp, Ty}, Legal);
|
|
193
|
|
194 setAction({G_MUL, v8s16}, Legal);
|
|
195
|
|
196 setAction({G_FPEXT, s64}, Legal);
|
|
197 setAction({G_FPEXT, 1, s32}, Legal);
|
|
198
|
|
199 // Constants
|
|
200 setAction({TargetOpcode::G_FCONSTANT, s64}, Legal);
|
|
201 }
|
|
202
|
|
203 void X86LegalizerInfo::setLegalizerInfoSSE41() {
|
|
204 if (!Subtarget.hasSSE41())
|
|
205 return;
|
|
206
|
|
207 const LLT v4s32 = LLT::vector(4, 32);
|
|
208
|
|
209 setAction({G_MUL, v4s32}, Legal);
|
|
210 }
|
|
211
|
|
212 void X86LegalizerInfo::setLegalizerInfoAVX() {
|
|
213 if (!Subtarget.hasAVX())
|
|
214 return;
|
|
215
|
|
216 const LLT v16s8 = LLT::vector(16, 8);
|
|
217 const LLT v8s16 = LLT::vector(8, 16);
|
|
218 const LLT v4s32 = LLT::vector(4, 32);
|
|
219 const LLT v2s64 = LLT::vector(2, 64);
|
|
220
|
|
221 const LLT v32s8 = LLT::vector(32, 8);
|
|
222 const LLT v16s16 = LLT::vector(16, 16);
|
|
223 const LLT v8s32 = LLT::vector(8, 32);
|
|
224 const LLT v4s64 = LLT::vector(4, 64);
|
|
225
|
|
226 for (unsigned MemOp : {G_LOAD, G_STORE})
|
|
227 for (auto Ty : {v8s32, v4s64})
|
|
228 setAction({MemOp, Ty}, Legal);
|
|
229
|
|
230 for (auto Ty : {v32s8, v16s16, v8s32, v4s64}) {
|
|
231 setAction({G_INSERT, Ty}, Legal);
|
|
232 setAction({G_EXTRACT, 1, Ty}, Legal);
|
|
233 }
|
|
234 for (auto Ty : {v16s8, v8s16, v4s32, v2s64}) {
|
|
235 setAction({G_INSERT, 1, Ty}, Legal);
|
|
236 setAction({G_EXTRACT, Ty}, Legal);
|
|
237 }
|
|
238 }
|
|
239
|
|
240 void X86LegalizerInfo::setLegalizerInfoAVX2() {
|
|
241 if (!Subtarget.hasAVX2())
|
|
242 return;
|
|
243
|
|
244 const LLT v32s8 = LLT::vector(32, 8);
|
|
245 const LLT v16s16 = LLT::vector(16, 16);
|
|
246 const LLT v8s32 = LLT::vector(8, 32);
|
|
247 const LLT v4s64 = LLT::vector(4, 64);
|
|
248
|
|
249 for (unsigned BinOp : {G_ADD, G_SUB})
|
|
250 for (auto Ty : {v32s8, v16s16, v8s32, v4s64})
|
|
251 setAction({BinOp, Ty}, Legal);
|
|
252
|
|
253 for (auto Ty : {v16s16, v8s32})
|
|
254 setAction({G_MUL, Ty}, Legal);
|
|
255 }
|
|
256
|
|
257 void X86LegalizerInfo::setLegalizerInfoAVX512() {
|
|
258 if (!Subtarget.hasAVX512())
|
|
259 return;
|
|
260
|
|
261 const LLT v16s8 = LLT::vector(16, 8);
|
|
262 const LLT v8s16 = LLT::vector(8, 16);
|
|
263 const LLT v4s32 = LLT::vector(4, 32);
|
|
264 const LLT v2s64 = LLT::vector(2, 64);
|
|
265
|
|
266 const LLT v32s8 = LLT::vector(32, 8);
|
|
267 const LLT v16s16 = LLT::vector(16, 16);
|
|
268 const LLT v8s32 = LLT::vector(8, 32);
|
|
269 const LLT v4s64 = LLT::vector(4, 64);
|
|
270
|
|
271 const LLT v64s8 = LLT::vector(64, 8);
|
|
272 const LLT v32s16 = LLT::vector(32, 16);
|
|
273 const LLT v16s32 = LLT::vector(16, 32);
|
|
274 const LLT v8s64 = LLT::vector(8, 64);
|
|
275
|
|
276 for (unsigned BinOp : {G_ADD, G_SUB})
|
|
277 for (auto Ty : {v16s32, v8s64})
|
|
278 setAction({BinOp, Ty}, Legal);
|
|
279
|
|
280 setAction({G_MUL, v16s32}, Legal);
|
|
281
|
|
282 for (unsigned MemOp : {G_LOAD, G_STORE})
|
|
283 for (auto Ty : {v16s32, v8s64})
|
|
284 setAction({MemOp, Ty}, Legal);
|
|
285
|
|
286 for (auto Ty : {v64s8, v32s16, v16s32, v8s64}) {
|
|
287 setAction({G_INSERT, Ty}, Legal);
|
|
288 setAction({G_EXTRACT, 1, Ty}, Legal);
|
|
289 }
|
|
290 for (auto Ty : {v32s8, v16s16, v8s32, v4s64, v16s8, v8s16, v4s32, v2s64}) {
|
|
291 setAction({G_INSERT, 1, Ty}, Legal);
|
|
292 setAction({G_EXTRACT, Ty}, Legal);
|
|
293 }
|
|
294
|
|
295 /************ VLX *******************/
|
|
296 if (!Subtarget.hasVLX())
|
|
297 return;
|
|
298
|
|
299 for (auto Ty : {v4s32, v8s32})
|
|
300 setAction({G_MUL, Ty}, Legal);
|
|
301 }
|
|
302
|
|
303 void X86LegalizerInfo::setLegalizerInfoAVX512DQ() {
|
|
304 if (!(Subtarget.hasAVX512() && Subtarget.hasDQI()))
|
|
305 return;
|
|
306
|
|
307 const LLT v8s64 = LLT::vector(8, 64);
|
|
308
|
|
309 setAction({G_MUL, v8s64}, Legal);
|
|
310
|
|
311 /************ VLX *******************/
|
|
312 if (!Subtarget.hasVLX())
|
|
313 return;
|
|
314
|
|
315 const LLT v2s64 = LLT::vector(2, 64);
|
|
316 const LLT v4s64 = LLT::vector(4, 64);
|
|
317
|
|
318 for (auto Ty : {v2s64, v4s64})
|
|
319 setAction({G_MUL, Ty}, Legal);
|
|
320 }
|
|
321
|
|
322 void X86LegalizerInfo::setLegalizerInfoAVX512BW() {
|
|
323 if (!(Subtarget.hasAVX512() && Subtarget.hasBWI()))
|
|
324 return;
|
|
325
|
|
326 const LLT v64s8 = LLT::vector(64, 8);
|
|
327 const LLT v32s16 = LLT::vector(32, 16);
|
|
328
|
|
329 for (unsigned BinOp : {G_ADD, G_SUB})
|
|
330 for (auto Ty : {v64s8, v32s16})
|
|
331 setAction({BinOp, Ty}, Legal);
|
|
332
|
|
333 setAction({G_MUL, v32s16}, Legal);
|
|
334
|
|
335 /************ VLX *******************/
|
|
336 if (!Subtarget.hasVLX())
|
|
337 return;
|
|
338
|
|
339 const LLT v8s16 = LLT::vector(8, 16);
|
|
340 const LLT v16s16 = LLT::vector(16, 16);
|
|
341
|
|
342 for (auto Ty : {v8s16, v16s16})
|
|
343 setAction({G_MUL, Ty}, Legal);
|
|
344 }
|