]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/lib/Target/X86/X86LegalizerInfo.cpp
Merge llvm, clang, lld, lldb, compiler-rt and libc++ r303571, and update
[FreeBSD/FreeBSD.git] / contrib / llvm / lib / Target / X86 / X86LegalizerInfo.cpp
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 #ifndef LLVM_BUILD_GLOBAL_ISEL
26 #error "You shouldn't build this"
27 #endif
28
29 X86LegalizerInfo::X86LegalizerInfo(const X86Subtarget &STI,
30                                    const X86TargetMachine &TM)
31     : Subtarget(STI), TM(TM) {
32
33   setLegalizerInfo32bit();
34   setLegalizerInfo64bit();
35   setLegalizerInfoSSE1();
36   setLegalizerInfoSSE2();
37   setLegalizerInfoSSE41();
38   setLegalizerInfoAVX2();
39   setLegalizerInfoAVX512();
40   setLegalizerInfoAVX512DQ();
41   setLegalizerInfoAVX512BW();
42
43   computeTables();
44 }
45
46 void X86LegalizerInfo::setLegalizerInfo32bit() {
47
48   if (Subtarget.is64Bit())
49     return;
50
51   const LLT p0 = LLT::pointer(0, 32);
52   const LLT s1 = LLT::scalar(1);
53   const LLT s8 = LLT::scalar(8);
54   const LLT s16 = LLT::scalar(16);
55   const LLT s32 = LLT::scalar(32);
56   const LLT s64 = LLT::scalar(64);
57
58   for (unsigned BinOp : {G_ADD, G_SUB, G_MUL})
59     for (auto Ty : {s8, s16, s32})
60       setAction({BinOp, Ty}, Legal);
61
62   for (unsigned Op : {G_UADDE}) {
63     setAction({Op, s32}, Legal);
64     setAction({Op, 1, s1}, Legal);
65   }
66
67   for (unsigned MemOp : {G_LOAD, G_STORE}) {
68     for (auto Ty : {s8, s16, s32, p0})
69       setAction({MemOp, Ty}, Legal);
70
71     // And everything's fine in addrspace 0.
72     setAction({MemOp, 1, p0}, Legal);
73   }
74
75   // Pointer-handling
76   setAction({G_FRAME_INDEX, p0}, Legal);
77
78   setAction({G_GEP, p0}, Legal);
79   setAction({G_GEP, 1, s32}, Legal);
80
81   for (auto Ty : {s1, s8, s16})
82     setAction({G_GEP, 1, Ty}, WidenScalar);
83
84   // Constants
85   for (auto Ty : {s8, s16, s32, p0})
86     setAction({TargetOpcode::G_CONSTANT, Ty}, Legal);
87
88   setAction({TargetOpcode::G_CONSTANT, s1}, WidenScalar);
89   setAction({TargetOpcode::G_CONSTANT, s64}, NarrowScalar);
90
91   // Extensions
92   setAction({G_ZEXT, s32}, Legal);
93   setAction({G_SEXT, s32}, Legal);
94
95   for (auto Ty : {s1, s8, s16}) {
96     setAction({G_ZEXT, 1, Ty}, Legal);
97     setAction({G_SEXT, 1, Ty}, Legal);
98   }
99
100   // Comparison
101   setAction({G_ICMP, s1}, Legal);
102
103   for (auto Ty : {s8, s16, s32, p0})
104     setAction({G_ICMP, 1, Ty}, Legal);
105 }
106
107 void X86LegalizerInfo::setLegalizerInfo64bit() {
108
109   if (!Subtarget.is64Bit())
110     return;
111
112   const LLT p0 = LLT::pointer(0, TM.getPointerSize() * 8);
113   const LLT s1 = LLT::scalar(1);
114   const LLT s8 = LLT::scalar(8);
115   const LLT s16 = LLT::scalar(16);
116   const LLT s32 = LLT::scalar(32);
117   const LLT s64 = LLT::scalar(64);
118
119   for (unsigned BinOp : {G_ADD, G_SUB, G_MUL})
120     for (auto Ty : {s8, s16, s32, s64})
121       setAction({BinOp, Ty}, Legal);
122
123   for (unsigned MemOp : {G_LOAD, G_STORE}) {
124     for (auto Ty : {s8, s16, s32, s64, p0})
125       setAction({MemOp, Ty}, Legal);
126
127     // And everything's fine in addrspace 0.
128     setAction({MemOp, 1, p0}, Legal);
129   }
130
131   // Pointer-handling
132   setAction({G_FRAME_INDEX, p0}, Legal);
133
134   setAction({G_GEP, p0}, Legal);
135   setAction({G_GEP, 1, s32}, Legal);
136   setAction({G_GEP, 1, s64}, Legal);
137
138   for (auto Ty : {s1, s8, s16})
139     setAction({G_GEP, 1, Ty}, WidenScalar);
140
141   // Constants
142   for (auto Ty : {s8, s16, s32, s64, p0})
143     setAction({TargetOpcode::G_CONSTANT, Ty}, Legal);
144
145   setAction({TargetOpcode::G_CONSTANT, s1}, WidenScalar);
146
147   // Extensions
148   for (auto Ty : {s32, s64}) {
149     setAction({G_ZEXT, Ty}, Legal);
150     setAction({G_SEXT, Ty}, Legal);
151   }
152
153   for (auto Ty : {s1, s8, s16, s32}) {
154     setAction({G_ZEXT, 1, Ty}, Legal);
155     setAction({G_SEXT, 1, Ty}, Legal);
156   }
157
158   // Comparison
159   setAction({G_ICMP, s1}, Legal);
160
161   for (auto Ty : {s8, s16, s32, s64, p0})
162     setAction({G_ICMP, 1, Ty}, Legal);
163 }
164
165 void X86LegalizerInfo::setLegalizerInfoSSE1() {
166   if (!Subtarget.hasSSE1())
167     return;
168
169   const LLT s32 = LLT::scalar(32);
170   const LLT v4s32 = LLT::vector(4, 32);
171   const LLT v2s64 = LLT::vector(2, 64);
172
173   for (unsigned BinOp : {G_FADD, G_FSUB, G_FMUL, G_FDIV})
174     for (auto Ty : {s32, v4s32})
175       setAction({BinOp, Ty}, Legal);
176
177   for (unsigned MemOp : {G_LOAD, G_STORE})
178     for (auto Ty : {v4s32, v2s64})
179       setAction({MemOp, Ty}, Legal);
180 }
181
182 void X86LegalizerInfo::setLegalizerInfoSSE2() {
183   if (!Subtarget.hasSSE2())
184     return;
185
186   const LLT s64 = LLT::scalar(64);
187   const LLT v16s8 = LLT::vector(16, 8);
188   const LLT v8s16 = LLT::vector(8, 16);
189   const LLT v4s32 = LLT::vector(4, 32);
190   const LLT v2s64 = LLT::vector(2, 64);
191
192   for (unsigned BinOp : {G_FADD, G_FSUB, G_FMUL, G_FDIV})
193     for (auto Ty : {s64, v2s64})
194       setAction({BinOp, Ty}, Legal);
195
196   for (unsigned BinOp : {G_ADD, G_SUB})
197     for (auto Ty : {v16s8, v8s16, v4s32, v2s64})
198       setAction({BinOp, Ty}, Legal);
199
200   setAction({G_MUL, v8s16}, 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::setLegalizerInfoAVX2() {
213   if (!Subtarget.hasAVX2())
214     return;
215
216   const LLT v32s8 = LLT::vector(32, 8);
217   const LLT v16s16 = LLT::vector(16, 16);
218   const LLT v8s32 = LLT::vector(8, 32);
219   const LLT v4s64 = LLT::vector(4, 64);
220
221   for (unsigned BinOp : {G_ADD, G_SUB})
222     for (auto Ty : {v32s8, v16s16, v8s32, v4s64})
223       setAction({BinOp, Ty}, Legal);
224
225   for (auto Ty : {v16s16, v8s32})
226     setAction({G_MUL, Ty}, Legal);
227 }
228
229 void X86LegalizerInfo::setLegalizerInfoAVX512() {
230   if (!Subtarget.hasAVX512())
231     return;
232
233   const LLT v16s32 = LLT::vector(16, 32);
234   const LLT v8s64 = LLT::vector(8, 64);
235
236   for (unsigned BinOp : {G_ADD, G_SUB})
237     for (auto Ty : {v16s32, v8s64})
238       setAction({BinOp, Ty}, Legal);
239
240   setAction({G_MUL, v16s32}, Legal);
241
242   /************ VLX *******************/
243   if (!Subtarget.hasVLX())
244     return;
245
246   const LLT v4s32 = LLT::vector(4, 32);
247   const LLT v8s32 = LLT::vector(8, 32);
248
249   for (auto Ty : {v4s32, v8s32})
250     setAction({G_MUL, Ty}, Legal);
251 }
252
253 void X86LegalizerInfo::setLegalizerInfoAVX512DQ() {
254   if (!(Subtarget.hasAVX512() && Subtarget.hasDQI()))
255     return;
256
257   const LLT v8s64 = LLT::vector(8, 64);
258
259   setAction({G_MUL, v8s64}, Legal);
260
261   /************ VLX *******************/
262   if (!Subtarget.hasVLX())
263     return;
264
265   const LLT v2s64 = LLT::vector(2, 64);
266   const LLT v4s64 = LLT::vector(4, 64);
267
268   for (auto Ty : {v2s64, v4s64})
269     setAction({G_MUL, Ty}, Legal);
270 }
271
272 void X86LegalizerInfo::setLegalizerInfoAVX512BW() {
273   if (!(Subtarget.hasAVX512() && Subtarget.hasBWI()))
274     return;
275
276   const LLT v64s8 = LLT::vector(64, 8);
277   const LLT v32s16 = LLT::vector(32, 16);
278
279   for (unsigned BinOp : {G_ADD, G_SUB})
280     for (auto Ty : {v64s8, v32s16})
281       setAction({BinOp, Ty}, Legal);
282
283   setAction({G_MUL, v32s16}, Legal);
284
285   /************ VLX *******************/
286   if (!Subtarget.hasVLX())
287     return;
288
289   const LLT v8s16 = LLT::vector(8, 16);
290   const LLT v16s16 = LLT::vector(16, 16);
291
292   for (auto Ty : {v8s16, v16s16})
293     setAction({G_MUL, Ty}, Legal);
294 }