Skip to content

Commit

Permalink
[X86] Cleanup ShuffleDecode implementations. NFCI.
Browse files Browse the repository at this point in the history
 - 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
  • Loading branch information
RKSimon committed Mar 2, 2020
1 parent dc8680e commit f5ad93d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 51 deletions.
37 changes: 10 additions & 27 deletions llvm/lib/Target/X86/Utils/X86ShuffleDecode.cpp
Expand Up @@ -12,7 +12,9 @@
//===----------------------------------------------------------------------===//

#include "X86ShuffleDecode.h"
#include "llvm/ADT/APInt.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/SmallVector.h"

//===----------------------------------------------------------------------===//
// Vector Mask Decoding
Expand Down Expand Up @@ -141,9 +143,6 @@ void DecodeVALIGNMask(unsigned NumElts, unsigned Imm,
ShuffleMask.push_back(i + Imm);
}

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

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

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

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

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

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

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

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

void DecodeZeroExtendMask(unsigned SrcScalarBits, unsigned DstScalarBits,
unsigned NumDstElts, bool IsAnyExtend,
SmallVectorImpl<int> &Mask) {
SmallVectorImpl<int> &ShuffleMask) {
unsigned Scale = DstScalarBits / SrcScalarBits;
assert(SrcScalarBits < DstScalarBits &&
"Expected zero extension mask to increase scalar size");

int Sentinel = IsAnyExtend ? SM_SentinelUndef : SM_SentinelZero;
for (unsigned i = 0; i != NumDstElts; i++) {
Mask.push_back(i);
for (unsigned j = 1; j != Scale; j++)
Mask.push_back(IsAnyExtend ? SM_SentinelUndef : SM_SentinelZero);
ShuffleMask.push_back(i);
ShuffleMask.append(Scale - 1, Sentinel);
}
}

void DecodeZeroMoveLowMask(unsigned NumElts,
SmallVectorImpl<int> &ShuffleMask) {
ShuffleMask.push_back(0);
for (unsigned i = 1; i < NumElts; i++)
ShuffleMask.push_back(SM_SentinelZero);
ShuffleMask.append(NumElts - 1, SM_SentinelZero);
}

void DecodeScalarMoveMask(unsigned NumElts, bool IsLoad,
SmallVectorImpl<int> &Mask) {
SmallVectorImpl<int> &ShuffleMask) {
// First element comes from the first element of second source.
// Remaining elements: Load zero extends / Move copies from first source.
Mask.push_back(NumElts);
ShuffleMask.push_back(NumElts);
for (unsigned i = 1; i < NumElts; i++)
Mask.push_back(IsLoad ? static_cast<int>(SM_SentinelZero) : i);
ShuffleMask.push_back(IsLoad ? static_cast<int>(SM_SentinelZero) : i);
}

void DecodeEXTRQIMask(unsigned NumElts, unsigned EltSize, int Len, int Idx,
Expand Down
18 changes: 4 additions & 14 deletions llvm/lib/Target/X86/Utils/X86ShuffleDecode.h
Expand Up @@ -14,15 +14,16 @@
#ifndef LLVM_LIB_TARGET_X86_UTILS_X86SHUFFLEDECODE_H
#define LLVM_LIB_TARGET_X86_UTILS_X86SHUFFLEDECODE_H

#include "llvm/ADT/APInt.h"
#include "llvm/ADT/SmallVector.h"
#include <cstdint>

//===----------------------------------------------------------------------===//
// Vector Mask Decoding
//===----------------------------------------------------------------------===//

namespace llvm {
class APInt;
template <typename T> class ArrayRef;
template <typename T> class SmallVectorImpl;

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

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

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

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

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

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

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

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

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

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

/// Decode a shuffle packed values at 128-bit granularity
/// (SHUFF32x4/SHUFF64x2/SHUFI32x4/SHUFI64x2)
/// immediate mask into a shuffle mask.
void decodeVSHUF64x2FamilyMask(unsigned NumElts, unsigned ScalarSize,
unsigned Imm, SmallVectorImpl<int> &ShuffleMask);
Expand Down
9 changes: 5 additions & 4 deletions llvm/lib/Target/X86/X86ShuffleDecodeConstantPool.cpp
Expand Up @@ -11,8 +11,10 @@
//
//===----------------------------------------------------------------------===//

#include "X86ShuffleDecodeConstantPool.h"
#include "Utils/X86ShuffleDecode.h"
#include "llvm/ADT/APInt.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/IR/Constants.h"

//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -185,13 +187,12 @@ void DecodeVPERMILPMask(const Constant *C, unsigned ElSize, unsigned Width,
}

void DecodeVPERMIL2PMask(const Constant *C, unsigned M2Z, unsigned ElSize,
unsigned Width,
SmallVectorImpl<int> &ShuffleMask) {
unsigned Width, SmallVectorImpl<int> &ShuffleMask) {
Type *MaskTy = C->getType();
unsigned MaskTySize = MaskTy->getPrimitiveSizeInBits();
(void)MaskTySize;
assert((MaskTySize == 128 || MaskTySize == 256) &&
Width >= MaskTySize && "Unexpected vector size.");
assert((MaskTySize == 128 || MaskTySize == 256) && Width >= MaskTySize &&
"Unexpected vector size.");

// The shuffle mask requires elements the same size as the target.
APInt UndefElts;
Expand Down
9 changes: 3 additions & 6 deletions llvm/lib/Target/X86/X86ShuffleDecodeConstantPool.h
Expand Up @@ -14,15 +14,13 @@
#ifndef LLVM_LIB_TARGET_X86_X86SHUFFLEDECODECONSTANTPOOL_H
#define LLVM_LIB_TARGET_X86_X86SHUFFLEDECODECONSTANTPOOL_H

#include "llvm/ADT/SmallVector.h"

//===----------------------------------------------------------------------===//
// Vector Mask Decoding
//===----------------------------------------------------------------------===//

namespace llvm {
class Constant;
class MVT;
template <typename T> class SmallVectorImpl;

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

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

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

0 comments on commit f5ad93d

Please sign in to comment.