]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/lib/Target/X86/X86LegalizerInfo.cpp
Merge llvm, clang, lld, lldb, compiler-rt and libc++ r302418, 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 MemOp : {G_LOAD, G_STORE}) {
63     for (auto Ty : {s8, s16, s32, p0})
64       setAction({MemOp, Ty}, Legal);
65
66     // And everything's fine in addrspace 0.
67     setAction({MemOp, 1, p0}, Legal);
68   }
69
70   // Pointer-handling
71   setAction({G_FRAME_INDEX, p0}, Legal);
72
73   setAction({G_GEP, p0}, Legal);
74   setAction({G_GEP, 1, s32}, Legal);
75
76   for (auto Ty : {s1, s8, s16})
77     setAction({G_GEP, 1, Ty}, WidenScalar);
78
79   // Constants
80   for (auto Ty : {s8, s16, s32, p0})
81     setAction({TargetOpcode::G_CONSTANT, Ty}, Legal);
82
83   setAction({TargetOpcode::G_CONSTANT, s1}, WidenScalar);
84   setAction({TargetOpcode::G_CONSTANT, s64}, NarrowScalar);
85
86   // Extensions
87   setAction({G_ZEXT, s32}, Legal);
88   setAction({G_SEXT, s32}, Legal);
89
90   for (auto Ty : {s8, s16}) {
91     setAction({G_ZEXT, 1, Ty}, Legal);
92     setAction({G_SEXT, 1, Ty}, Legal);
93   }
94 }
95
96 void X86LegalizerInfo::setLegalizerInfo64bit() {
97
98   if (!Subtarget.is64Bit())
99     return;
100
101   const LLT p0 = LLT::pointer(0, TM.getPointerSize() * 8);
102   const LLT s1 = LLT::scalar(1);
103   const LLT s8 = LLT::scalar(8);
104   const LLT s16 = LLT::scalar(16);
105   const LLT s32 = LLT::scalar(32);
106   const LLT s64 = LLT::scalar(64);
107
108   for (unsigned BinOp : {G_ADD, G_SUB, G_MUL})
109     for (auto Ty : {s8, s16, s32, s64})
110       setAction({BinOp, Ty}, Legal);
111
112   for (unsigned MemOp : {G_LOAD, G_STORE}) {
113     for (auto Ty : {s8, s16, s32, s64, p0})
114       setAction({MemOp, Ty}, Legal);
115
116     // And everything's fine in addrspace 0.
117     setAction({MemOp, 1, p0}, Legal);
118   }
119
120   // Pointer-handling
121   setAction({G_FRAME_INDEX, p0}, Legal);
122
123   setAction({G_GEP, p0}, Legal);
124   setAction({G_GEP, 1, s32}, Legal);
125   setAction({G_GEP, 1, s64}, Legal);
126
127   for (auto Ty : {s1, s8, s16})
128     setAction({G_GEP, 1, Ty}, WidenScalar);
129
130   // Constants
131   for (auto Ty : {s8, s16, s32, s64, p0})
132     setAction({TargetOpcode::G_CONSTANT, Ty}, Legal);
133
134   setAction({TargetOpcode::G_CONSTANT, s1}, WidenScalar);
135
136   // Extensions
137   for (auto Ty : {s32, s64}) {
138     setAction({G_ZEXT, Ty}, Legal);
139     setAction({G_SEXT, Ty}, Legal);
140   }
141
142   for (auto Ty : {s8, s16, s32}) {
143     setAction({G_ZEXT, 1, Ty}, Legal);
144     setAction({G_SEXT, 1, Ty}, Legal);
145   }
146 }
147
148 void X86LegalizerInfo::setLegalizerInfoSSE1() {
149   if (!Subtarget.hasSSE1())
150     return;
151
152   const LLT s32 = LLT::scalar(32);
153   const LLT v4s32 = LLT::vector(4, 32);
154   const LLT v2s64 = LLT::vector(2, 64);
155
156   for (unsigned BinOp : {G_FADD, G_FSUB, G_FMUL, G_FDIV})
157     for (auto Ty : {s32, v4s32})
158       setAction({BinOp, Ty}, Legal);
159
160   for (unsigned MemOp : {G_LOAD, G_STORE})
161     for (auto Ty : {v4s32, v2s64})
162       setAction({MemOp, Ty}, Legal);
163 }
164
165 void X86LegalizerInfo::setLegalizerInfoSSE2() {
166   if (!Subtarget.hasSSE2())
167     return;
168
169   const LLT s64 = LLT::scalar(64);
170   const LLT v8s16 = LLT::vector(8, 16);
171   const LLT v4s32 = LLT::vector(4, 32);
172   const LLT v2s64 = LLT::vector(2, 64);
173
174   for (unsigned BinOp : {G_FADD, G_FSUB, G_FMUL, G_FDIV})
175     for (auto Ty : {s64, v2s64})
176       setAction({BinOp, Ty}, Legal);
177
178   for (unsigned BinOp : {G_ADD, G_SUB})
179     for (auto Ty : {v4s32})
180       setAction({BinOp, Ty}, Legal);
181
182   setAction({G_MUL, v8s16}, Legal);
183 }
184
185 void X86LegalizerInfo::setLegalizerInfoSSE41() {
186   if (!Subtarget.hasSSE41())
187     return;
188
189   const LLT v4s32 = LLT::vector(4, 32);
190
191   setAction({G_MUL, v4s32}, Legal);
192 }
193
194 void X86LegalizerInfo::setLegalizerInfoAVX2() {
195   if (!Subtarget.hasAVX2())
196     return;
197
198   const LLT v16s16 = LLT::vector(16, 16);
199   const LLT v8s32 = LLT::vector(8, 32);
200
201   for (auto Ty : {v16s16, v8s32})
202     setAction({G_MUL, Ty}, Legal);
203 }
204
205 void X86LegalizerInfo::setLegalizerInfoAVX512() {
206   if (!Subtarget.hasAVX512())
207     return;
208
209   const LLT v16s32 = LLT::vector(16, 32);
210
211   setAction({G_MUL, v16s32}, Legal);
212
213   /************ VLX *******************/
214   if (!Subtarget.hasVLX())
215     return;
216
217   const LLT v4s32 = LLT::vector(4, 32);
218   const LLT v8s32 = LLT::vector(8, 32);
219
220   for (auto Ty : {v4s32, v8s32})
221     setAction({G_MUL, Ty}, Legal);
222 }
223
224 void X86LegalizerInfo::setLegalizerInfoAVX512DQ() {
225   if (!(Subtarget.hasAVX512() && Subtarget.hasDQI()))
226     return;
227
228   const LLT v8s64 = LLT::vector(8, 64);
229
230   setAction({G_MUL, v8s64}, Legal);
231
232   /************ VLX *******************/
233   if (!Subtarget.hasVLX())
234     return;
235
236   const LLT v2s64 = LLT::vector(2, 64);
237   const LLT v4s64 = LLT::vector(4, 64);
238
239   for (auto Ty : {v2s64, v4s64})
240     setAction({G_MUL, Ty}, Legal);
241 }
242
243 void X86LegalizerInfo::setLegalizerInfoAVX512BW() {
244   if (!(Subtarget.hasAVX512() && Subtarget.hasBWI()))
245     return;
246
247   const LLT v32s16 = LLT::vector(32, 16);
248
249   setAction({G_MUL, v32s16}, Legal);
250
251   /************ VLX *******************/
252   if (!Subtarget.hasVLX())
253     return;
254
255   const LLT v8s16 = LLT::vector(8, 16);
256   const LLT v16s16 = LLT::vector(16, 16);
257
258   for (auto Ty : {v8s16, v16s16})
259     setAction({G_MUL, Ty}, Legal);
260 }