Skip to content

Commit cd99514

Browse files
Addressing 2nd review round.
- Clean up duplicate ISA tests. - Added an extra test to clearly show that the mangled name becomes the VectorName, when no VectorName is specified.
1 parent c4508ba commit cd99514

File tree

1 file changed

+24
-44
lines changed

1 file changed

+24
-44
lines changed

llvm/unittests/Analysis/VectorFunctionABITest.cpp

Lines changed: 24 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,15 @@ class VFABIParserTest : public ::testing::Test {
2121
// Parser output.
2222
VFInfo Info;
2323
// Reset the data needed for the test.
24-
void reset(const StringRef Name, const StringRef IRType) {
24+
void reset(const StringRef SFunTy) {
2525
M = parseAssemblyString("declare void @dummy()", Err, Ctx);
2626
EXPECT_NE(M.get(), nullptr) << "Loading an invalid module.\n "
2727
<< Err.getMessage() << "\n";
28-
Type *Ty = parseType(IRType, Err, *(M.get()));
29-
FTy = dyn_cast<FunctionType>(Ty);
30-
EXPECT_NE(FTy, nullptr) << "Invalid function type string: " << IRType
28+
Type *Ty = parseType(SFunTy, Err, *(M.get()));
29+
ScalarFTy = dyn_cast<FunctionType>(Ty);
30+
EXPECT_NE(ScalarFTy, nullptr) << "Invalid function type string: " << SFunTy
3131
<< "\n"
3232
<< Err.getMessage() << "\n";
33-
F = M->getOrInsertFunction(Name, FTy);
34-
EXPECT_NE(F.getCallee(), nullptr)
35-
<< "The function must be present in the module\n";
3633
// Reset the VFInfo
3734
Info = VFInfo();
3835
ScalarFuncParametersNum = 0;
@@ -42,7 +39,7 @@ class VFABIParserTest : public ::testing::Test {
4239
LLVMContext Ctx;
4340
SMDiagnostic Err;
4441
std::unique_ptr<Module> M;
45-
FunctionType *FTy = nullptr;
42+
FunctionType *ScalarFTy = nullptr;
4643
FunctionCallee F;
4744

4845
protected:
@@ -64,23 +61,23 @@ class VFABIParserTest : public ::testing::Test {
6461
// use to create the function in the module if it differs from the
6562
// standard mangled name.
6663
//
67-
// \p IRType -> FunctionType string to be used for the signature of
64+
// \p STy -> FunctionType string to be used for the signature of
6865
// the vector function. The correct signature is needed by the
6966
// parser only for scalable functions. For the sake of testing, the
7067
// generic fixed-length case can use as signature `void()`.
7168
//
7269
bool invokeParser(const StringRef MangledName,
73-
const StringRef IRType = "void()") {
74-
// Reset the VFInfo and the Module to be able to invoke
75-
// `invokeParser` multiple times in the same test.
76-
reset(MangledName, IRType);
70+
const StringRef SFunTy = "void()") {
71+
// Reset the VFInfo and the Module to be able to invoke `invokeParser`
72+
// multiple times in the same test.
73+
reset(SFunTy);
7774

7875
// Fake the arguments to the CallInst.
79-
const auto OptInfo = VFABI::tryDemangleForVFABI(MangledName, FTy);
76+
const auto OptInfo = VFABI::tryDemangleForVFABI(MangledName, ScalarFTy);
8077
if (OptInfo) {
8178
Info = *OptInfo;
8279
ScalarFuncParametersNum =
83-
Info.Shape.getScalarShape(FTy).Parameters.size();
80+
Info.Shape.getScalarShape(ScalarFTy).Parameters.size();
8481
return true;
8582
}
8683
return false;
@@ -138,7 +135,7 @@ TEST_F(VFABIParserTest, OnlyValidNames) {
138135
}
139136

140137
TEST_F(VFABIParserTest, ParamListParsing) {
141-
EXPECT_TRUE(invokeParser("_ZGVnN2vl16Ls32R3l_foo(vector_foo)",
138+
EXPECT_TRUE(invokeParser("_ZGVnN2vl16Ls32R3l_foo",
142139
"void(i32, i32, i32, ptr, i32)"));
143140
EXPECT_TRUE(matchScalarParamNum()) << "Different number of Scalar parameters";
144141
EXPECT_EQ(VecFuncParameters.size(), (unsigned)5);
@@ -151,7 +148,7 @@ TEST_F(VFABIParserTest, ParamListParsing) {
151148
VFParameter({3, VFParamKind::OMP_LinearRef, 3}));
152149
EXPECT_EQ(VecFuncParameters[4], VFParameter({4, VFParamKind::OMP_Linear, 1}));
153150
EXPECT_EQ(ScalarName, "foo");
154-
EXPECT_EQ(VectorName, "vector_foo");
151+
EXPECT_EQ(VectorName, "_ZGVnN2vl16Ls32R3l_foo");
155152
}
156153

157154
TEST_F(VFABIParserTest, ScalarNameAndVectorName_01) {
@@ -172,9 +169,17 @@ TEST_F(VFABIParserTest, ScalarNameAndVectorName_03) {
172169
EXPECT_EQ(VectorName, "fooBarAbcVec");
173170
}
174171

172+
TEST_F(VFABIParserTest, ScalarNameOnly) {
173+
EXPECT_TRUE(invokeParser("_ZGVnM2v___foo_bar_abc"));
174+
EXPECT_EQ(ScalarName, "__foo_bar_abc");
175+
// no vector name specified (as it's optional), so it should have the entire
176+
// mangled name.
177+
EXPECT_EQ(VectorName, "_ZGVnM2v___foo_bar_abc");
178+
}
179+
175180
TEST_F(VFABIParserTest, Parse) {
176181
EXPECT_TRUE(
177-
invokeParser("_ZGVnN2vls2Ls27Us4Rs5l1L10U100R1000_foo(vector_foo)",
182+
invokeParser("_ZGVnN2vls2Ls27Us4Rs5l1L10U100R1000_foo",
178183
"void(i32, i32, i32, i32, ptr, i32, i32, i32, ptr)"));
179184
EXPECT_TRUE(matchScalarParamNum()) << "Different number of Scalar parameters";
180185
EXPECT_EQ(VF, ElementCount::getFixed(2));
@@ -198,7 +203,7 @@ TEST_F(VFABIParserTest, Parse) {
198203
EXPECT_EQ(VecFuncParameters[8],
199204
VFParameter({8, VFParamKind::OMP_LinearRef, 1000}));
200205
EXPECT_EQ(ScalarName, "foo");
201-
EXPECT_EQ(VectorName, "vector_foo");
206+
EXPECT_EQ(VectorName, "_ZGVnN2vls2Ls27Us4Rs5l1L10U100R1000_foo");
202207
}
203208

204209
TEST_F(VFABIParserTest, ParseVectorName) {
@@ -305,29 +310,6 @@ TEST_F(VFABIParserTest, LinearWithoutCompileTime) {
305310
EXPECT_EQ(VectorName, "vector_foo");
306311
}
307312

308-
TEST_F(VFABIParserTest, ISA) {
309-
EXPECT_TRUE(invokeParser("_ZGVqN2v_foo"));
310-
EXPECT_EQ(ISA, VFISAKind::Unknown);
311-
312-
EXPECT_TRUE(invokeParser("_ZGVnN2v_foo"));
313-
EXPECT_EQ(ISA, VFISAKind::AdvancedSIMD);
314-
315-
EXPECT_TRUE(invokeParser("_ZGVsN2v_foo"));
316-
EXPECT_EQ(ISA, VFISAKind::SVE);
317-
318-
EXPECT_TRUE(invokeParser("_ZGVbN2v_foo"));
319-
EXPECT_EQ(ISA, VFISAKind::SSE);
320-
321-
EXPECT_TRUE(invokeParser("_ZGVcN2v_foo"));
322-
EXPECT_EQ(ISA, VFISAKind::AVX);
323-
324-
EXPECT_TRUE(invokeParser("_ZGVdN2v_foo"));
325-
EXPECT_EQ(ISA, VFISAKind::AVX2);
326-
327-
EXPECT_TRUE(invokeParser("_ZGVeN2v_foo"));
328-
EXPECT_EQ(ISA, VFISAKind::AVX512);
329-
}
330-
331313
TEST_F(VFABIParserTest, LLVM_ISA) {
332314
EXPECT_FALSE(invokeParser("_ZGV_LLVM_N2v_foo"));
333315
EXPECT_TRUE(invokeParser("_ZGV_LLVM_N2v_foo(vector_foo)", "void(i32)"));
@@ -607,8 +589,6 @@ TEST_F(VFABIParserTest, IntrinsicsInLLVMIsa) {
607589

608590
TEST_F(VFABIParserTest, ParseScalableRequiresDeclaration) {
609591
const char *MangledName = "_ZGVsMxv_sin(custom_vg)";
610-
// The parser succeeds only when the correct function definition of
611-
// `custom_vg` is added to the module.
612592
EXPECT_FALSE(invokeParser(MangledName));
613593
EXPECT_TRUE(invokeParser(MangledName, "void(i32)"));
614594
EXPECT_TRUE(matchScalarParamNum()) << "Different number of Scalar parameters";

0 commit comments

Comments
 (0)