diff --git a/llvm/lib/Target/X86/Utils/X86ShuffleDecode.cpp b/llvm/lib/Target/X86/Utils/X86ShuffleDecode.cpp index 48fd3e0b7ab9f..62c1c399a606e 100644 --- a/llvm/lib/Target/X86/Utils/X86ShuffleDecode.cpp +++ b/llvm/lib/Target/X86/Utils/X86ShuffleDecode.cpp @@ -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 @@ -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 &ShuffleMask) { unsigned Size = NumElts * ScalarBits; @@ -197,9 +196,6 @@ void DecodePSWAPMask(unsigned NumElts, SmallVectorImpl &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 &ShuffleMask) { unsigned NumLaneElts = 128 / ScalarBits; @@ -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 &ShuffleMask) { // Handle 128 and 256-bit vector lengths. AVX defines UNPCK* to operate @@ -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 &ShuffleMask) { // Handle 128 and 256-bit vector lengths. AVX defines UNPCK* to operate @@ -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 &ShuffleMask) { ShuffleMask.append(NumElts, 0); } -/// Decodes a broadcast of a subvector to a larger vector type. void DecodeSubVectorBroadcast(unsigned DstNumElts, unsigned SrcNumElts, SmallVectorImpl &ShuffleMask) { unsigned Scale = DstNumElts / SrcNumElts; @@ -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 &ShuffleMask) { @@ -374,7 +359,6 @@ void DecodeVPPERMMask(ArrayRef RawMask, const APInt &UndefElts, } } -/// DecodeVPERMMask - this decodes the shuffle masks for VPERMQ/VPERMPD. void DecodeVPERMMask(unsigned NumElts, unsigned Imm, SmallVectorImpl &ShuffleMask) { for (unsigned l = 0; l != NumElts; l += 4) @@ -384,32 +368,31 @@ void DecodeVPERMMask(unsigned NumElts, unsigned Imm, void DecodeZeroExtendMask(unsigned SrcScalarBits, unsigned DstScalarBits, unsigned NumDstElts, bool IsAnyExtend, - SmallVectorImpl &Mask) { + SmallVectorImpl &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 &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 &Mask) { + SmallVectorImpl &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(SM_SentinelZero) : i); + ShuffleMask.push_back(IsLoad ? static_cast(SM_SentinelZero) : i); } void DecodeEXTRQIMask(unsigned NumElts, unsigned EltSize, int Len, int Idx, diff --git a/llvm/lib/Target/X86/Utils/X86ShuffleDecode.h b/llvm/lib/Target/X86/Utils/X86ShuffleDecode.h index f52785063071a..4ef9959f7a278 100644 --- a/llvm/lib/Target/X86/Utils/X86ShuffleDecode.h +++ b/llvm/lib/Target/X86/Utils/X86ShuffleDecode.h @@ -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 //===----------------------------------------------------------------------===// // Vector Mask Decoding //===----------------------------------------------------------------------===// namespace llvm { +class APInt; template class ArrayRef; +template class SmallVectorImpl; enum { SM_SentinelUndef = -1, SM_SentinelZero = -2 }; @@ -61,20 +62,14 @@ void DecodeVALIGNMask(unsigned NumElts, unsigned Imm, SmallVectorImpl &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 &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 &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 &ShuffleMask); @@ -82,20 +77,14 @@ void DecodePSHUFLWMask(unsigned NumElts, unsigned Imm, void DecodePSWAPMask(unsigned NumElts, SmallVectorImpl &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 &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 &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 &ShuffleMask); @@ -119,6 +108,7 @@ void DecodeVPERM2X128Mask(unsigned NumElts, unsigned Imm, SmallVectorImpl &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 &ShuffleMask); diff --git a/llvm/lib/Target/X86/X86ShuffleDecodeConstantPool.cpp b/llvm/lib/Target/X86/X86ShuffleDecodeConstantPool.cpp index a202fc63637b9..5da1ca275cd4d 100644 --- a/llvm/lib/Target/X86/X86ShuffleDecodeConstantPool.cpp +++ b/llvm/lib/Target/X86/X86ShuffleDecodeConstantPool.cpp @@ -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" //===----------------------------------------------------------------------===// @@ -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 &ShuffleMask) { + unsigned Width, SmallVectorImpl &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; diff --git a/llvm/lib/Target/X86/X86ShuffleDecodeConstantPool.h b/llvm/lib/Target/X86/X86ShuffleDecodeConstantPool.h index 2963415175795..51229a69a6263 100644 --- a/llvm/lib/Target/X86/X86ShuffleDecodeConstantPool.h +++ b/llvm/lib/Target/X86/X86ShuffleDecodeConstantPool.h @@ -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 class SmallVectorImpl; /// Decode a PSHUFB mask from an IR-level vector constant. void DecodePSHUFBMask(const Constant *C, unsigned Width, @@ -33,9 +31,8 @@ void DecodeVPERMILPMask(const Constant *C, unsigned ElSize, unsigned Width, SmallVectorImpl &ShuffleMask); /// Decode a VPERMILP2 variable mask from an IR-level vector constant. -void DecodeVPERMIL2PMask(const Constant *C, unsigned MatchImm, unsigned ElSize, - unsigned Width, - SmallVectorImpl &ShuffleMask); +void DecodeVPERMIL2PMask(const Constant *C, unsigned M2Z, unsigned ElSize, + unsigned Width, SmallVectorImpl &ShuffleMask); /// Decode a VPPERM variable mask from an IR-level vector constant. void DecodeVPPERMMask(const Constant *C, unsigned Width,