LLVM: lib/Target/X86/X86ShuffleDecodeConstantPool.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
19
20
21
22
23
24namespace llvm {
25
29
30
31
32
33
34
35
36
37
38
40 if (!CstTy)
41 return false;
42
43 Type *CstEltTy = CstTy->getElementType();
45 return false;
46
48 unsigned CstEltSizeInBits = CstTy->getScalarSizeInBits();
49 unsigned NumCstElts = CstTy->getNumElements();
50
51 assert((CstSizeInBits % MaskEltSizeInBits) == 0 &&
52 "Unaligned shuffle mask size");
53
54 unsigned NumMaskElts = CstSizeInBits / MaskEltSizeInBits;
55 UndefElts = APInt(NumMaskElts, 0);
56 RawMask.resize(NumMaskElts, 0);
57
58
59 if (MaskEltSizeInBits == CstEltSizeInBits) {
60 assert(NumCstElts == NumMaskElts && "Unaligned shuffle mask size");
61 for (unsigned i = 0; i != NumMaskElts; ++i) {
62 Constant *COp = C->getAggregateElement(i);
64 return false;
65
68 RawMask[i] = 0;
69 continue;
70 }
71
73 RawMask[i] = Elt->getValue().getZExtValue();
74 }
75 return true;
76 }
77
78
79 APInt UndefBits(CstSizeInBits, 0);
80 APInt MaskBits(CstSizeInBits, 0);
81 for (unsigned i = 0; i != NumCstElts; ++i) {
82 Constant *COp = C->getAggregateElement(i);
84 return false;
85
86 unsigned BitOffset = i * CstEltSizeInBits;
87
89 UndefBits.setBits(BitOffset, BitOffset + CstEltSizeInBits);
90 continue;
91 }
92
94 }
95
96
97 for (unsigned i = 0; i != NumMaskElts; ++i) {
98 unsigned BitOffset = i * MaskEltSizeInBits;
99 APInt EltUndef = UndefBits.extractBits(MaskEltSizeInBits, BitOffset);
100
101
102
105 RawMask[i] = 0;
106 continue;
107 }
108
109 APInt EltBits = MaskBits.extractBits(MaskEltSizeInBits, BitOffset);
111 }
112
113 return true;
114}
115
118 assert((Width == 128 || Width == 256 || Width == 512) &&
119 C->getType()->getPrimitiveSizeInBits() >= Width &&
120 "Unexpected vector size.");
121
122
126 return;
127
128 unsigned NumElts = Width / 8;
129 assert((NumElts == 16 || NumElts == 32 || NumElts == 64) &&
130 "Unexpected number of vector elements.");
131
132 for (unsigned i = 0; i != NumElts; ++i) {
133 if (UndefElts[i]) {
135 continue;
136 }
137
138 uint64_t Element = RawMask[i];
139
140 if (Element & (1 << 7))
142 else {
143
144
145 unsigned Base = i & ~0xf;
146
147
148 int Index = Base + (Element & 0xf);
149 ShuffleMask.push_back(Index);
150 }
151 }
152}
153
156 assert((Width == 128 || Width == 256 || Width == 512) &&
157 C->getType()->getPrimitiveSizeInBits() >= Width &&
158 "Unexpected vector size.");
159 assert((ElSize == 32 || ElSize == 64) && "Unexpected vector element size.");
160
161
165 return;
166
167 unsigned NumElts = Width / ElSize;
168 unsigned NumEltsPerLane = 128 / ElSize;
169 assert((NumElts == 2 || NumElts == 4 || NumElts == 8 || NumElts == 16) &&
170 "Unexpected number of vector elements.");
171
172 for (unsigned i = 0; i != NumElts; ++i) {
173 if (UndefElts[i]) {
175 continue;
176 }
177
178 int Index = i & ~(NumEltsPerLane - 1);
179 uint64_t Element = RawMask[i];
180 if (ElSize == 64)
181 Index += (Element >> 1) & 0x1;
182 else
183 Index += Element & 0x3;
184
185 ShuffleMask.push_back(Index);
186 }
187}
188
191 Type *MaskTy = C->getType();
193 (void)MaskTySize;
194 assert((MaskTySize == 128 || MaskTySize == 256) && Width >= MaskTySize &&
195 "Unexpected vector size.");
196
197
201 return;
202
203 unsigned NumElts = Width / ElSize;
204 unsigned NumEltsPerLane = 128 / ElSize;
205 assert((NumElts == 2 || NumElts == 4 || NumElts == 8) &&
206 "Unexpected number of vector elements.");
207
208 for (unsigned i = 0; i != NumElts; ++i) {
209 if (UndefElts[i]) {
211 continue;
212 }
213
214
215
216
217
218 uint64_t Selector = RawMask[i];
219 unsigned MatchBit = (Selector >> 3) & 0x1;
220
221
222
223
224
225
226
227 if ((M2Z & 0x2) != 0u && MatchBit != (M2Z & 0x1)) {
229 continue;
230 }
231
232 int Index = i & ~(NumEltsPerLane - 1);
233 if (ElSize == 64)
234 Index += (Selector >> 1) & 0x1;
235 else
236 Index += Selector & 0x3;
237
238 int Src = (Selector >> 2) & 0x1;
239 Index += Src * NumElts;
240 ShuffleMask.push_back(Index);
241 }
242}
243
246 Type *MaskTy = C->getType();
248 (void)MaskTySize;
249 assert(Width == 128 && Width >= MaskTySize && "Unexpected vector size.");
250
251
255 return;
256
257 unsigned NumElts = Width / 8;
258 assert(NumElts == 16 && "Unexpected number of vector elements.");
259
260 for (unsigned i = 0; i != NumElts; ++i) {
261 if (UndefElts[i]) {
263 continue;
264 }
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280 uint64_t Element = RawMask[i];
281 uint64_t Index = Element & 0x1F;
282 uint64_t PermuteOp = (Element >> 5) & 0x7;
283
284 if (PermuteOp == 4) {
286 continue;
287 }
288 if (PermuteOp != 0) {
289 ShuffleMask.clear();
290 return;
291 }
292 ShuffleMask.push_back((int)Index);
293 }
294}
295
296}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file implements a class to represent arbitrary precision integral constant values and operations...
This file contains the declarations for the subclasses of Constant, which represent the different fla...
This file defines the SmallVector class.
Class for arbitrary precision integers.
uint64_t getZExtValue() const
Get zero extended value.
void setBit(unsigned BitPosition)
Set the given bit to 1 whose position is given as "bitPosition".
bool isAllOnes() const
Determine if all bits are set. This is true for zero-width values.
LLVM_ABI void insertBits(const APInt &SubBits, unsigned bitPosition)
Insert the bits from a smaller APInt starting at bitPosition.
void setBits(unsigned loBit, unsigned hiBit)
Set the bits from loBit (inclusive) to hiBit (exclusive) to 1.
LLVM_ABI APInt extractBits(unsigned numBits, unsigned bitPosition) const
Return an APInt with the extracted bits [bitPosition,bitPosition+numBits).
This is an important base class in LLVM.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
The instances of the Type class are immutable: once they are created, they are never changed.
LLVM_ABI TypeSize getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
bool isIntegerTy() const
True if this is an instance of IntegerType.
@ C
The default llvm calling convention, compatible with C.
This is an optimization pass for GlobalISel generic memory operations.
void DecodeVPERMILPMask(unsigned NumElts, unsigned ScalarBits, ArrayRef< uint64_t > RawMask, const APInt &UndefElts, SmallVectorImpl< int > &ShuffleMask)
Decode a VPERMILPD/VPERMILPS variable mask from a raw array of constants.
decltype(auto) dyn_cast(const From &Val)
dyn_cast - Return the argument parameter cast to the specified type.
void DecodeVPERMIL2PMask(unsigned NumElts, unsigned ScalarBits, unsigned M2Z, ArrayRef< uint64_t > RawMask, const APInt &UndefElts, SmallVectorImpl< int > &ShuffleMask)
Decode a VPERMIL2PD/VPERMIL2PS variable mask from a raw array of constants.
static bool extractConstantMask(const Constant *C, unsigned MaskEltSizeInBits, APInt &UndefElts, SmallVectorImpl< uint64_t > &RawMask)
Definition X86ShuffleDecodeConstantPool.cpp:26
bool isa(const From &Val)
isa - Return true if the parameter to the template is an instance of one of the template type argu...
void DecodeVPPERMMask(ArrayRef< uint64_t > RawMask, const APInt &UndefElts, SmallVectorImpl< int > &ShuffleMask)
Decode a VPPERM mask from a raw array of constants such as from BUILD_VECTOR.
decltype(auto) cast(const From &Val)
cast - Return the argument parameter cast to the specified type.
void DecodePSHUFBMask(ArrayRef< uint64_t > RawMask, const APInt &UndefElts, SmallVectorImpl< int > &ShuffleMask)
Decode a PSHUFB mask from a raw array of constants such as from BUILD_VECTOR.