[NFC] Change VFShape so it contains an ElementCount rather than seperate VF and IsScalable properties.

Differential Revision: https://reviews.llvm.org/D106750
This commit is contained in:
Paul Walker 2021-07-24 16:34:20 +01:00
parent 46c0366877
commit 8a8d01d58c
4 changed files with 39 additions and 59 deletions

View File

@ -80,13 +80,11 @@ struct VFParameter {
/// represent vector functions. in particular, it is not attached to
/// any target-specific ABI.
struct VFShape {
unsigned VF; // Vectorization factor.
bool IsScalable; // True if the function is a scalable function.
ElementCount VF; // Vectorization factor.
SmallVector<VFParameter, 8> Parameters; // List of parameter information.
// Comparison operator.
bool operator==(const VFShape &Other) const {
return std::tie(VF, IsScalable, Parameters) ==
std::tie(Other.VF, Other.IsScalable, Other.Parameters);
return std::tie(VF, Parameters) == std::tie(Other.VF, Other.Parameters);
}
/// Update the parameter in position P.ParamPos to P.
@ -115,7 +113,7 @@ struct VFShape {
Parameters.push_back(
VFParameter({CI.arg_size(), VFParamKind::GlobalPredicate}));
return {EC.getKnownMinValue(), EC.isScalable(), Parameters};
return {EC, Parameters};
}
/// Sanity check on the Parameters in the VFShape.
bool hasValidParameterList() const;

View File

@ -454,7 +454,7 @@ Optional<VFInfo> VFABI::tryDemangleForVFABI(StringRef MangledName,
if (!M.getFunction(VectorName))
return None;
const VFShape Shape({VF, IsScalable, Parameters});
const VFShape Shape({ElementCount::get(VF, IsScalable), Parameters});
return VFInfo({Shape, std::string(ScalarName), std::string(VectorName), ISA});
}

View File

@ -43,12 +43,11 @@ private:
// CallInst *CI;
protected:
// Referencies to the parser output field.
unsigned &VF = Info.Shape.VF;
ElementCount &VF = Info.Shape.VF;
VFISAKind &ISA = Info.ISA;
SmallVector<VFParameter, 8> &Parameters = Info.Shape.Parameters;
std::string &ScalarName = Info.ScalarName;
std::string &VectorName = Info.VectorName;
bool &IsScalable = Info.Shape.IsScalable;
// Invoke the parser. We need to make sure that a function exist in
// the module because the parser fails if such function don't
// exists. Every time this method is invoked the state of the test
@ -175,10 +174,9 @@ TEST_F(VFABIParserTest, ScalarNameAndVectorName_03) {
TEST_F(VFABIParserTest, Parse) {
EXPECT_TRUE(invokeParser("_ZGVnN2vls2Ls27Us4Rs5l1L10U100R1000_sin"));
EXPECT_EQ(VF, (unsigned)2);
EXPECT_EQ(VF, ElementCount::getFixed(2));
EXPECT_FALSE(IsMasked());
EXPECT_EQ(ISA, VFISAKind::AdvancedSIMD);
EXPECT_FALSE(IsScalable);
EXPECT_EQ(Parameters.size(), (unsigned)9);
EXPECT_EQ(Parameters[0], VFParameter({0, VFParamKind::Vector, 0}));
EXPECT_EQ(Parameters[1], VFParameter({1, VFParamKind::OMP_LinearPos, 2}));
@ -195,9 +193,8 @@ TEST_F(VFABIParserTest, Parse) {
TEST_F(VFABIParserTest, ParseVectorName) {
EXPECT_TRUE(invokeParser("_ZGVnN2v_sin(my_v_sin)", "my_v_sin"));
EXPECT_EQ(VF, (unsigned)2);
EXPECT_EQ(VF, ElementCount::getFixed(2));
EXPECT_FALSE(IsMasked());
EXPECT_FALSE(IsScalable);
EXPECT_EQ(ISA, VFISAKind::AdvancedSIMD);
EXPECT_EQ(Parameters.size(), (unsigned)1);
EXPECT_EQ(Parameters[0], VFParameter({0, VFParamKind::Vector, 0}));
@ -207,10 +204,9 @@ TEST_F(VFABIParserTest, ParseVectorName) {
TEST_F(VFABIParserTest, LinearWithCompileTimeNegativeStep) {
EXPECT_TRUE(invokeParser("_ZGVnN2ln1Ln10Un100Rn1000_sin"));
EXPECT_EQ(VF, (unsigned)2);
EXPECT_EQ(VF, ElementCount::getFixed(2));
EXPECT_FALSE(IsMasked());
EXPECT_EQ(ISA, VFISAKind::AdvancedSIMD);
EXPECT_FALSE(IsScalable);
EXPECT_EQ(Parameters.size(), (unsigned)4);
EXPECT_EQ(Parameters[0], VFParameter({0, VFParamKind::OMP_Linear, -1}));
EXPECT_EQ(Parameters[1], VFParameter({1, VFParamKind::OMP_LinearVal, -10}));
@ -224,9 +220,8 @@ TEST_F(VFABIParserTest, ParseScalableSVE) {
EXPECT_TRUE(invokeParser(
"_ZGVsMxv_sin(custom_vg)", "custom_vg",
"<vscale x 2 x i32>(<vscale x 2 x i32>, <vscale x 2 x i1>)"));
EXPECT_EQ(VF, (unsigned)2);
EXPECT_EQ(VF, ElementCount::getScalable(2));
EXPECT_TRUE(IsMasked());
EXPECT_TRUE(IsScalable);
EXPECT_EQ(ISA, VFISAKind::SVE);
EXPECT_EQ(ScalarName, "sin");
EXPECT_EQ(VectorName, "custom_vg");
@ -234,9 +229,8 @@ TEST_F(VFABIParserTest, ParseScalableSVE) {
TEST_F(VFABIParserTest, ParseFixedWidthSVE) {
EXPECT_TRUE(invokeParser("_ZGVsM2v_sin"));
EXPECT_EQ(VF, (unsigned)2);
EXPECT_EQ(VF, ElementCount::getFixed(2));
EXPECT_TRUE(IsMasked());
EXPECT_FALSE(IsScalable);
EXPECT_EQ(ISA, VFISAKind::SVE);
EXPECT_EQ(ScalarName, "sin");
EXPECT_EQ(VectorName, "_ZGVsM2v_sin");
@ -332,10 +326,9 @@ TEST_F(VFABIParserTest, Align) {
TEST_F(VFABIParserTest, ParseUniform) {
EXPECT_TRUE(invokeParser("_ZGVnN2u_sin"));
EXPECT_EQ(VF, (unsigned)2);
EXPECT_EQ(VF, ElementCount::getFixed(2));
EXPECT_FALSE(IsMasked());
EXPECT_EQ(ISA, VFISAKind::AdvancedSIMD);
EXPECT_FALSE(IsScalable);
EXPECT_EQ(Parameters.size(), (unsigned)1);
EXPECT_EQ(Parameters[0], VFParameter({0, VFParamKind::OMP_Uniform, 0}));
EXPECT_EQ(ScalarName, "sin");
@ -363,9 +356,8 @@ TEST_F(VFABIParserTest, ISAIndependentMangling) {
#define __COMMON_CHECKS \
do { \
EXPECT_EQ(VF, (unsigned)2); \
EXPECT_EQ(VF, ElementCount::getFixed(2)); \
EXPECT_FALSE(IsMasked()); \
EXPECT_FALSE(IsScalable); \
EXPECT_EQ(Parameters.size(), (unsigned)10); \
EXPECT_EQ(Parameters, ExpectedParams); \
EXPECT_EQ(ScalarName, "sin"); \
@ -438,9 +430,8 @@ TEST_F(VFABIParserTest, MissingVectorNameTermination) {
TEST_F(VFABIParserTest, ParseMaskingNEON) {
EXPECT_TRUE(invokeParser("_ZGVnM2v_sin"));
EXPECT_EQ(VF, (unsigned)2);
EXPECT_EQ(VF, ElementCount::getFixed(2));
EXPECT_TRUE(IsMasked());
EXPECT_FALSE(IsScalable);
EXPECT_EQ(ISA, VFISAKind::AdvancedSIMD);
EXPECT_EQ(Parameters.size(), (unsigned)2);
EXPECT_EQ(Parameters[0], VFParameter({0, VFParamKind::Vector}));
@ -450,9 +441,8 @@ TEST_F(VFABIParserTest, ParseMaskingNEON) {
TEST_F(VFABIParserTest, ParseMaskingSVE) {
EXPECT_TRUE(invokeParser("_ZGVsM2v_sin"));
EXPECT_EQ(VF, (unsigned)2);
EXPECT_EQ(VF, ElementCount::getFixed(2));
EXPECT_TRUE(IsMasked());
EXPECT_FALSE(IsScalable);
EXPECT_EQ(ISA, VFISAKind::SVE);
EXPECT_EQ(Parameters.size(), (unsigned)2);
EXPECT_EQ(Parameters[0], VFParameter({0, VFParamKind::Vector}));
@ -462,9 +452,8 @@ TEST_F(VFABIParserTest, ParseMaskingSVE) {
TEST_F(VFABIParserTest, ParseMaskingSSE) {
EXPECT_TRUE(invokeParser("_ZGVbM2v_sin"));
EXPECT_EQ(VF, (unsigned)2);
EXPECT_EQ(VF, ElementCount::getFixed(2));
EXPECT_TRUE(IsMasked());
EXPECT_FALSE(IsScalable);
EXPECT_EQ(ISA, VFISAKind::SSE);
EXPECT_EQ(Parameters.size(), (unsigned)2);
EXPECT_EQ(Parameters[0], VFParameter({0, VFParamKind::Vector}));
@ -474,9 +463,8 @@ TEST_F(VFABIParserTest, ParseMaskingSSE) {
TEST_F(VFABIParserTest, ParseMaskingAVX) {
EXPECT_TRUE(invokeParser("_ZGVcM2v_sin"));
EXPECT_EQ(VF, (unsigned)2);
EXPECT_EQ(VF, ElementCount::getFixed(2));
EXPECT_TRUE(IsMasked());
EXPECT_FALSE(IsScalable);
EXPECT_EQ(ISA, VFISAKind::AVX);
EXPECT_EQ(Parameters.size(), (unsigned)2);
EXPECT_EQ(Parameters[0], VFParameter({0, VFParamKind::Vector}));
@ -486,9 +474,8 @@ TEST_F(VFABIParserTest, ParseMaskingAVX) {
TEST_F(VFABIParserTest, ParseMaskingAVX2) {
EXPECT_TRUE(invokeParser("_ZGVdM2v_sin"));
EXPECT_EQ(VF, (unsigned)2);
EXPECT_EQ(VF, ElementCount::getFixed(2));
EXPECT_TRUE(IsMasked());
EXPECT_FALSE(IsScalable);
EXPECT_EQ(ISA, VFISAKind::AVX2);
EXPECT_EQ(Parameters.size(), (unsigned)2);
EXPECT_EQ(Parameters[0], VFParameter({0, VFParamKind::Vector}));
@ -498,9 +485,8 @@ TEST_F(VFABIParserTest, ParseMaskingAVX2) {
TEST_F(VFABIParserTest, ParseMaskingAVX512) {
EXPECT_TRUE(invokeParser("_ZGVeM2v_sin"));
EXPECT_EQ(VF, (unsigned)2);
EXPECT_EQ(VF, ElementCount::getFixed(2));
EXPECT_TRUE(IsMasked());
EXPECT_FALSE(IsScalable);
EXPECT_EQ(ISA, VFISAKind::AVX512);
EXPECT_EQ(Parameters.size(), (unsigned)2);
EXPECT_EQ(Parameters[0], VFParameter({0, VFParamKind::Vector}));
@ -511,9 +497,8 @@ TEST_F(VFABIParserTest, ParseMaskingAVX512) {
TEST_F(VFABIParserTest, ParseMaskingLLVM) {
EXPECT_TRUE(invokeParser("_ZGV_LLVM_M2v_sin(custom_vector_sin)",
"custom_vector_sin"));
EXPECT_EQ(VF, (unsigned)2);
EXPECT_EQ(VF, ElementCount::getFixed(2));
EXPECT_TRUE(IsMasked());
EXPECT_FALSE(IsScalable);
EXPECT_EQ(ISA, VFISAKind::LLVM);
EXPECT_EQ(Parameters.size(), (unsigned)2);
EXPECT_EQ(Parameters[0], VFParameter({0, VFParamKind::Vector}));
@ -527,8 +512,7 @@ TEST_F(VFABIParserTest, ParseScalableMaskingLLVM) {
"_ZGV_LLVM_Mxv_sin(custom_vector_sin)", "custom_vector_sin",
"<vscale x 2 x i32> (<vscale x 2 x i32>, <vscale x 2 x i1>)"));
EXPECT_TRUE(IsMasked());
EXPECT_EQ(VF, (unsigned)2);
EXPECT_TRUE(IsScalable);
EXPECT_EQ(VF, ElementCount::getScalable(2));
EXPECT_EQ(ISA, VFISAKind::LLVM);
EXPECT_EQ(Parameters.size(), (unsigned)2);
EXPECT_EQ(Parameters[0], VFParameter({0, VFParamKind::Vector}));
@ -541,9 +525,8 @@ TEST_F(VFABIParserTest, ParseScalableMaskingLLVMSincos) {
EXPECT_TRUE(invokeParser("_ZGV_LLVM_Mxvl8l8_sincos(custom_vector_sincos)",
"custom_vector_sincos",
"void(<vscale x 2 x double>, double *, double *)"));
EXPECT_EQ(VF, (unsigned)2);
EXPECT_EQ(VF, ElementCount::getScalable(2));
EXPECT_TRUE(IsMasked());
EXPECT_TRUE(IsScalable);
EXPECT_EQ(ISA, VFISAKind::LLVM);
EXPECT_EQ(Parameters.size(), (unsigned)4);
EXPECT_EQ(Parameters[0], VFParameter({0, VFParamKind::Vector}));
@ -597,9 +580,8 @@ TEST_F(VFABIParserTest, LLVM_InternalISA) {
TEST_F(VFABIParserTest, IntrinsicsInLLVMIsa) {
EXPECT_TRUE(invokeParser("_ZGV_LLVM_N4vv_llvm.pow.f32(__svml_powf4)",
"__svml_powf4"));
EXPECT_EQ(VF, (unsigned)4);
EXPECT_EQ(VF, ElementCount::getFixed(4));
EXPECT_FALSE(IsMasked());
EXPECT_FALSE(IsScalable);
EXPECT_EQ(ISA, VFISAKind::LLVM);
EXPECT_EQ(Parameters.size(), (unsigned)2);
EXPECT_EQ(Parameters[0], VFParameter({0, VFParamKind::Vector}));

View File

@ -498,12 +498,12 @@ protected:
std::unique_ptr<Module> M;
CallInst *CI;
// Dummy shape with no parameters, overwritten by buildShape when invoked.
VFShape Shape = {/*VF*/ 2, /*IsScalable*/ false, /*Parameters*/ {}};
VFShape Shape = {/*VF*/ ElementCount::getFixed(2), /*Parameters*/ {}};
VFShape Expected;
SmallVector<VFParameter, 8> &ExpectedParams = Expected.Parameters;
void buildShape(unsigned VF, bool IsScalable, bool HasGlobalPred) {
Shape = VFShape::get(*CI, ElementCount::get(VF, IsScalable), HasGlobalPred);
void buildShape(ElementCount VF, bool HasGlobalPred) {
Shape = VFShape::get(*CI, VF, HasGlobalPred);
}
bool validParams(ArrayRef<VFParameter> Parameters) {
@ -514,16 +514,16 @@ protected:
};
TEST_F(VFShapeAPITest, API_buildVFShape) {
buildShape(/*VF*/ 2, /*IsScalable*/ false, /*HasGlobalPred*/ false);
Expected = {/*VF*/ 2, /*IsScalable*/ false, /*Parameters*/ {
buildShape(/*VF*/ ElementCount::getFixed(2), /*HasGlobalPred*/ false);
Expected = {/*VF*/ ElementCount::getFixed(2), /*Parameters*/ {
{0, VFParamKind::Vector},
{1, VFParamKind::Vector},
{2, VFParamKind::Vector},
}};
EXPECT_EQ(Shape, Expected);
buildShape(/*VF*/ 4, /*IsScalable*/ false, /*HasGlobalPred*/ true);
Expected = {/*VF*/ 4, /*IsScalable*/ false, /*Parameters*/ {
buildShape(/*VF*/ ElementCount::getFixed(4), /*HasGlobalPred*/ true);
Expected = {/*VF*/ ElementCount::getFixed(4), /*Parameters*/ {
{0, VFParamKind::Vector},
{1, VFParamKind::Vector},
{2, VFParamKind::Vector},
@ -531,8 +531,8 @@ TEST_F(VFShapeAPITest, API_buildVFShape) {
}};
EXPECT_EQ(Shape, Expected);
buildShape(/*VF*/ 16, /*IsScalable*/ true, /*HasGlobalPred*/ false);
Expected = {/*VF*/ 16, /*IsScalable*/ true, /*Parameters*/ {
buildShape(/*VF*/ ElementCount::getScalable(16), /*HasGlobalPred*/ false);
Expected = {/*VF*/ ElementCount::getScalable(16), /*Parameters*/ {
{0, VFParamKind::Vector},
{1, VFParamKind::Vector},
{2, VFParamKind::Vector},
@ -541,7 +541,7 @@ TEST_F(VFShapeAPITest, API_buildVFShape) {
}
TEST_F(VFShapeAPITest, API_getScalarShape) {
buildShape(/*VF*/ 1, /*IsScalable*/ false, /*HasGlobalPred*/ false);
buildShape(/*VF*/ ElementCount::getFixed(1), /*HasGlobalPred*/ false);
EXPECT_EQ(VFShape::getScalarShape(*CI), Shape);
}
@ -550,19 +550,19 @@ TEST_F(VFShapeAPITest, API_getVectorizedFunction) {
EXPECT_EQ(VFDatabase(*CI).getVectorizedFunction(ScalarShape),
M->getFunction("g"));
buildShape(/*VF*/ 1, /*IsScalable*/ true, /*HasGlobalPred*/ false);
buildShape(/*VF*/ ElementCount::getScalable(1), /*HasGlobalPred*/ false);
EXPECT_EQ(VFDatabase(*CI).getVectorizedFunction(Shape), nullptr);
buildShape(/*VF*/ 1, /*IsScalable*/ false, /*HasGlobalPred*/ true);
buildShape(/*VF*/ ElementCount::getFixed(1), /*HasGlobalPred*/ true);
EXPECT_EQ(VFDatabase(*CI).getVectorizedFunction(Shape), nullptr);
buildShape(/*VF*/ 1, /*IsScalable*/ true, /*HasGlobalPred*/ true);
buildShape(/*VF*/ ElementCount::getScalable(1), /*HasGlobalPred*/ true);
EXPECT_EQ(VFDatabase(*CI).getVectorizedFunction(Shape), nullptr);
}
TEST_F(VFShapeAPITest, API_updateVFShape) {
buildShape(/*VF*/ 2, /*IsScalable*/ false, /*HasGlobalPred*/ false);
buildShape(/*VF*/ ElementCount::getFixed(2), /*HasGlobalPred*/ false);
Shape.updateParam({0 /*Pos*/, VFParamKind::OMP_Linear, 1, Align(4)});
Expected = {/*VF*/ 2, /*IsScalable*/ false, /*Parameters*/ {
Expected = {/*VF*/ ElementCount::getFixed(2), /*Parameters*/ {
{0, VFParamKind::OMP_Linear, 1, Align(4)},
{1, VFParamKind::Vector},
{2, VFParamKind::Vector},
@ -590,9 +590,9 @@ TEST_F(VFShapeAPITest, API_updateVFShape) {
TEST_F(VFShapeAPITest, API_updateVFShape_GlobalPredicate) {
buildShape(/*VF*/ 2, /*IsScalable*/ true, /*HasGlobalPred*/ true);
buildShape(/*VF*/ ElementCount::getScalable(2), /*HasGlobalPred*/ true);
Shape.updateParam({1 /*Pos*/, VFParamKind::OMP_Uniform});
Expected = {/*VF*/ 2, /*IsScalable*/ true,
Expected = {/*VF*/ ElementCount::getScalable(2),
/*Parameters*/ {{0, VFParamKind::Vector},
{1, VFParamKind::OMP_Uniform},
{2, VFParamKind::Vector},