Skip to content

Commit f5ad93d

Browse files
committed
[X86] Cleanup ShuffleDecode implementations. NFCI.
- Remove unnecessary includes from the headers - Fix cppcheck definition/declaration arg mismatch warnings - Tidyup old comments (MVT usage was removed a long time ago) - Use SmallVector::append for repeated mask entries
1 parent dc8680e commit f5ad93d

File tree

4 files changed

+22
-51
lines changed

4 files changed

+22
-51
lines changed

llvm/lib/Target/X86/Utils/X86ShuffleDecode.cpp

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
//===----------------------------------------------------------------------===//
1313

1414
#include "X86ShuffleDecode.h"
15+
#include "llvm/ADT/APInt.h"
1516
#include "llvm/ADT/ArrayRef.h"
17+
#include "llvm/ADT/SmallVector.h"
1618

1719
//===----------------------------------------------------------------------===//
1820
// Vector Mask Decoding
@@ -141,9 +143,6 @@ void DecodeVALIGNMask(unsigned NumElts, unsigned Imm,
141143
ShuffleMask.push_back(i + Imm);
142144
}
143145

144-
/// DecodePSHUFMask - This decodes the shuffle masks for pshufw, pshufd, and vpermilp*.
145-
/// VT indicates the type of the vector allowing it to handle different
146-
/// datatypes and vector widths.
147146
void DecodePSHUFMask(unsigned NumElts, unsigned ScalarBits, unsigned Imm,
148147
SmallVectorImpl<int> &ShuffleMask) {
149148
unsigned Size = NumElts * ScalarBits;
@@ -197,9 +196,6 @@ void DecodePSWAPMask(unsigned NumElts, SmallVectorImpl<int> &ShuffleMask) {
197196
ShuffleMask.push_back(h);
198197
}
199198

200-
/// DecodeSHUFPMask - This decodes the shuffle masks for shufp*. VT indicates
201-
/// the type of the vector allowing it to handle different datatypes and vector
202-
/// widths.
203199
void DecodeSHUFPMask(unsigned NumElts, unsigned ScalarBits,
204200
unsigned Imm, SmallVectorImpl<int> &ShuffleMask) {
205201
unsigned NumLaneElts = 128 / ScalarBits;
@@ -217,9 +213,6 @@ void DecodeSHUFPMask(unsigned NumElts, unsigned ScalarBits,
217213
}
218214
}
219215

220-
/// DecodeUNPCKHMask - This decodes the shuffle masks for unpckhps/unpckhpd
221-
/// and punpckh*. VT indicates the type of the vector allowing it to handle
222-
/// different datatypes and vector widths.
223216
void DecodeUNPCKHMask(unsigned NumElts, unsigned ScalarBits,
224217
SmallVectorImpl<int> &ShuffleMask) {
225218
// Handle 128 and 256-bit vector lengths. AVX defines UNPCK* to operate
@@ -236,9 +229,6 @@ void DecodeUNPCKHMask(unsigned NumElts, unsigned ScalarBits,
236229
}
237230
}
238231

239-
/// DecodeUNPCKLMask - This decodes the shuffle masks for unpcklps/unpcklpd
240-
/// and punpckl*. VT indicates the type of the vector allowing it to handle
241-
/// different datatypes and vector widths.
242232
void DecodeUNPCKLMask(unsigned NumElts, unsigned ScalarBits,
243233
SmallVectorImpl<int> &ShuffleMask) {
244234
// Handle 128 and 256-bit vector lengths. AVX defines UNPCK* to operate
@@ -255,13 +245,11 @@ void DecodeUNPCKLMask(unsigned NumElts, unsigned ScalarBits,
255245
}
256246
}
257247

258-
/// Decodes a broadcast of the first element of a vector.
259248
void DecodeVectorBroadcast(unsigned NumElts,
260249
SmallVectorImpl<int> &ShuffleMask) {
261250
ShuffleMask.append(NumElts, 0);
262251
}
263252

264-
/// Decodes a broadcast of a subvector to a larger vector type.
265253
void DecodeSubVectorBroadcast(unsigned DstNumElts, unsigned SrcNumElts,
266254
SmallVectorImpl<int> &ShuffleMask) {
267255
unsigned Scale = DstNumElts / SrcNumElts;
@@ -271,9 +259,6 @@ void DecodeSubVectorBroadcast(unsigned DstNumElts, unsigned SrcNumElts,
271259
ShuffleMask.push_back(j);
272260
}
273261

274-
/// Decode a shuffle packed values at 128-bit granularity
275-
/// (SHUFF32x4/SHUFF64x2/SHUFI32x4/SHUFI64x2)
276-
/// immediate mask into a shuffle mask.
277262
void decodeVSHUF64x2FamilyMask(unsigned NumElts, unsigned ScalarSize,
278263
unsigned Imm,
279264
SmallVectorImpl<int> &ShuffleMask) {
@@ -374,7 +359,6 @@ void DecodeVPPERMMask(ArrayRef<uint64_t> RawMask, const APInt &UndefElts,
374359
}
375360
}
376361

377-
/// DecodeVPERMMask - this decodes the shuffle masks for VPERMQ/VPERMPD.
378362
void DecodeVPERMMask(unsigned NumElts, unsigned Imm,
379363
SmallVectorImpl<int> &ShuffleMask) {
380364
for (unsigned l = 0; l != NumElts; l += 4)
@@ -384,32 +368,31 @@ void DecodeVPERMMask(unsigned NumElts, unsigned Imm,
384368

385369
void DecodeZeroExtendMask(unsigned SrcScalarBits, unsigned DstScalarBits,
386370
unsigned NumDstElts, bool IsAnyExtend,
387-
SmallVectorImpl<int> &Mask) {
371+
SmallVectorImpl<int> &ShuffleMask) {
388372
unsigned Scale = DstScalarBits / SrcScalarBits;
389373
assert(SrcScalarBits < DstScalarBits &&
390374
"Expected zero extension mask to increase scalar size");
391375

376+
int Sentinel = IsAnyExtend ? SM_SentinelUndef : SM_SentinelZero;
392377
for (unsigned i = 0; i != NumDstElts; i++) {
393-
Mask.push_back(i);
394-
for (unsigned j = 1; j != Scale; j++)
395-
Mask.push_back(IsAnyExtend ? SM_SentinelUndef : SM_SentinelZero);
378+
ShuffleMask.push_back(i);
379+
ShuffleMask.append(Scale - 1, Sentinel);
396380
}
397381
}
398382

399383
void DecodeZeroMoveLowMask(unsigned NumElts,
400384
SmallVectorImpl<int> &ShuffleMask) {
401385
ShuffleMask.push_back(0);
402-
for (unsigned i = 1; i < NumElts; i++)
403-
ShuffleMask.push_back(SM_SentinelZero);
386+
ShuffleMask.append(NumElts - 1, SM_SentinelZero);
404387
}
405388

406389
void DecodeScalarMoveMask(unsigned NumElts, bool IsLoad,
407-
SmallVectorImpl<int> &Mask) {
390+
SmallVectorImpl<int> &ShuffleMask) {
408391
// First element comes from the first element of second source.
409392
// Remaining elements: Load zero extends / Move copies from first source.
410-
Mask.push_back(NumElts);
393+
ShuffleMask.push_back(NumElts);
411394
for (unsigned i = 1; i < NumElts; i++)
412-
Mask.push_back(IsLoad ? static_cast<int>(SM_SentinelZero) : i);
395+
ShuffleMask.push_back(IsLoad ? static_cast<int>(SM_SentinelZero) : i);
413396
}
414397

415398
void DecodeEXTRQIMask(unsigned NumElts, unsigned EltSize, int Len, int Idx,

llvm/lib/Target/X86/Utils/X86ShuffleDecode.h

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,16 @@
1414
#ifndef LLVM_LIB_TARGET_X86_UTILS_X86SHUFFLEDECODE_H
1515
#define LLVM_LIB_TARGET_X86_UTILS_X86SHUFFLEDECODE_H
1616

17-
#include "llvm/ADT/APInt.h"
18-
#include "llvm/ADT/SmallVector.h"
17+
#include <cstdint>
1918

2019
//===----------------------------------------------------------------------===//
2120
// Vector Mask Decoding
2221
//===----------------------------------------------------------------------===//
2322

2423
namespace llvm {
24+
class APInt;
2525
template <typename T> class ArrayRef;
26+
template <typename T> class SmallVectorImpl;
2627

2728
enum { SM_SentinelUndef = -1, SM_SentinelZero = -2 };
2829

@@ -61,41 +62,29 @@ void DecodeVALIGNMask(unsigned NumElts, unsigned Imm,
6162
SmallVectorImpl<int> &ShuffleMask);
6263

6364
/// Decodes the shuffle masks for pshufd/pshufw/vpermilpd/vpermilps.
64-
/// VT indicates the type of the vector allowing it to handle different
65-
/// datatypes and vector widths.
6665
void DecodePSHUFMask(unsigned NumElts, unsigned ScalarBits, unsigned Imm,
6766
SmallVectorImpl<int> &ShuffleMask);
6867

6968
/// Decodes the shuffle masks for pshufhw.
70-
/// VT indicates the type of the vector allowing it to handle different
71-
/// datatypes and vector widths.
7269
void DecodePSHUFHWMask(unsigned NumElts, unsigned Imm,
7370
SmallVectorImpl<int> &ShuffleMask);
7471

7572
/// Decodes the shuffle masks for pshuflw.
76-
/// VT indicates the type of the vector allowing it to handle different
77-
/// datatypes and vector widths.
7873
void DecodePSHUFLWMask(unsigned NumElts, unsigned Imm,
7974
SmallVectorImpl<int> &ShuffleMask);
8075

8176
/// Decodes a PSWAPD 3DNow! instruction.
8277
void DecodePSWAPMask(unsigned NumElts, SmallVectorImpl<int> &ShuffleMask);
8378

8479
/// Decodes the shuffle masks for shufp*.
85-
/// VT indicates the type of the vector allowing it to handle different
86-
/// datatypes and vector widths.
8780
void DecodeSHUFPMask(unsigned NumElts, unsigned ScalarBits, unsigned Imm,
8881
SmallVectorImpl<int> &ShuffleMask);
8982

9083
/// Decodes the shuffle masks for unpckhps/unpckhpd and punpckh*.
91-
/// VT indicates the type of the vector allowing it to handle different
92-
/// datatypes and vector widths.
9384
void DecodeUNPCKHMask(unsigned NumElts, unsigned ScalarBits,
9485
SmallVectorImpl<int> &ShuffleMask);
9586

9687
/// Decodes the shuffle masks for unpcklps/unpcklpd and punpckl*.
97-
/// VT indicates the type of the vector allowing it to handle different
98-
/// datatypes and vector widths.
9988
void DecodeUNPCKLMask(unsigned NumElts, unsigned ScalarBits,
10089
SmallVectorImpl<int> &ShuffleMask);
10190

@@ -119,6 +108,7 @@ void DecodeVPERM2X128Mask(unsigned NumElts, unsigned Imm,
119108
SmallVectorImpl<int> &ShuffleMask);
120109

121110
/// Decode a shuffle packed values at 128-bit granularity
111+
/// (SHUFF32x4/SHUFF64x2/SHUFI32x4/SHUFI64x2)
122112
/// immediate mask into a shuffle mask.
123113
void decodeVSHUF64x2FamilyMask(unsigned NumElts, unsigned ScalarSize,
124114
unsigned Imm, SmallVectorImpl<int> &ShuffleMask);

llvm/lib/Target/X86/X86ShuffleDecodeConstantPool.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111
//
1212
//===----------------------------------------------------------------------===//
1313

14+
#include "X86ShuffleDecodeConstantPool.h"
1415
#include "Utils/X86ShuffleDecode.h"
1516
#include "llvm/ADT/APInt.h"
17+
#include "llvm/ADT/SmallVector.h"
1618
#include "llvm/IR/Constants.h"
1719

1820
//===----------------------------------------------------------------------===//
@@ -185,13 +187,12 @@ void DecodeVPERMILPMask(const Constant *C, unsigned ElSize, unsigned Width,
185187
}
186188

187189
void DecodeVPERMIL2PMask(const Constant *C, unsigned M2Z, unsigned ElSize,
188-
unsigned Width,
189-
SmallVectorImpl<int> &ShuffleMask) {
190+
unsigned Width, SmallVectorImpl<int> &ShuffleMask) {
190191
Type *MaskTy = C->getType();
191192
unsigned MaskTySize = MaskTy->getPrimitiveSizeInBits();
192193
(void)MaskTySize;
193-
assert((MaskTySize == 128 || MaskTySize == 256) &&
194-
Width >= MaskTySize && "Unexpected vector size.");
194+
assert((MaskTySize == 128 || MaskTySize == 256) && Width >= MaskTySize &&
195+
"Unexpected vector size.");
195196

196197
// The shuffle mask requires elements the same size as the target.
197198
APInt UndefElts;

llvm/lib/Target/X86/X86ShuffleDecodeConstantPool.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,13 @@
1414
#ifndef LLVM_LIB_TARGET_X86_X86SHUFFLEDECODECONSTANTPOOL_H
1515
#define LLVM_LIB_TARGET_X86_X86SHUFFLEDECODECONSTANTPOOL_H
1616

17-
#include "llvm/ADT/SmallVector.h"
18-
1917
//===----------------------------------------------------------------------===//
2018
// Vector Mask Decoding
2119
//===----------------------------------------------------------------------===//
2220

2321
namespace llvm {
2422
class Constant;
25-
class MVT;
23+
template <typename T> class SmallVectorImpl;
2624

2725
/// Decode a PSHUFB mask from an IR-level vector constant.
2826
void DecodePSHUFBMask(const Constant *C, unsigned Width,
@@ -33,9 +31,8 @@ void DecodeVPERMILPMask(const Constant *C, unsigned ElSize, unsigned Width,
3331
SmallVectorImpl<int> &ShuffleMask);
3432

3533
/// Decode a VPERMILP2 variable mask from an IR-level vector constant.
36-
void DecodeVPERMIL2PMask(const Constant *C, unsigned MatchImm, unsigned ElSize,
37-
unsigned Width,
38-
SmallVectorImpl<int> &ShuffleMask);
34+
void DecodeVPERMIL2PMask(const Constant *C, unsigned M2Z, unsigned ElSize,
35+
unsigned Width, SmallVectorImpl<int> &ShuffleMask);
3936

4037
/// Decode a VPPERM variable mask from an IR-level vector constant.
4138
void DecodeVPPERMMask(const Constant *C, unsigned Width,

0 commit comments

Comments
 (0)