[llvm] [VFABI] Improve VFABI unit tests (PR #73907)
Paul Walker via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 7 02:59:30 PST 2023
================
@@ -40,69 +50,48 @@ class VFABIParserTest : public ::testing::Test {
LLVMContext Ctx;
SMDiagnostic Err;
std::unique_ptr<Module> M;
- FunctionType *FTy;
- FunctionCallee F;
+ FunctionType *ScalarFTy = nullptr;
protected:
- // Referencies to the parser output field.
+ // References to the parser output field.
ElementCount &VF = Info.Shape.VF;
VFISAKind &ISA = Info.ISA;
+ /// Parameters for the vectorized function
SmallVector<VFParameter, 8> &Parameters = Info.Shape.Parameters;
std::string &ScalarName = Info.ScalarName;
std::string &VectorName = Info.VectorName;
- // 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
- // is reset.
- //
- // \p MangledName -> the string the parser has to demangle.
- //
- // \p VectorName -> optional vector name that the method needs to
- // use to create the function in the module if it differs from the
- // standard mangled name.
- //
- // \p IRType -> FunctionType string to be used for the signature of
- // the vector function. The correct signature is needed by the
- // parser only for scalable functions. For the sake of testing, the
- // generic fixed-length case can use as signature `void()`.
- //
+
+ /// Invoke the parser. Every time this method is invoked the state of the test
+ /// is reset.
+ ///
+ /// \p MangledName string the parser has to demangle.
+ ///
+ /// \p ScalarFTyStr FunctionType string to be used to get the signature of
+ /// the scalar function. Needed by `tryDemangleForVFABI` to check for the
+ /// number of arguments on scalable vectors, and by `matchScalarParamNum` to
+ /// perform some additional checking in the tests in this file.
bool invokeParser(const StringRef MangledName,
- const StringRef ScalarName = "",
- const StringRef IRType = "void()") {
- StringRef Name = MangledName;
- if (!ScalarName.empty())
- Name = ScalarName;
- // Reset the VFInfo and the Module to be able to invoke
- // `invokeParser` multiple times in the same test.
- reset(Name, IRType);
-
- // Fake the arguments to the CallInst.
- SmallVector<Value *> Args;
- for (Type *ParamTy : FTy->params()) {
- Args.push_back(Constant::getNullValue(ParamTy->getScalarType()));
- }
- std::unique_ptr<CallInst> CI(CallInst::Create(F, Args));
- const auto OptInfo =
- VFABI::tryDemangleForVFABI(MangledName, CI->getFunctionType());
- if (OptInfo) {
+ const StringRef ScalarFTyStr = "void()") {
+ // Reset the VFInfo to be able to call `invokeParser` multiple times in
+ // the same test.
+ reset(ScalarFTyStr);
+
+ const auto OptInfo = VFABI::tryDemangleForVFABI(MangledName, ScalarFTy);
+ if (OptInfo)
Info = *OptInfo;
- return true;
- }
- return false;
+ return OptInfo.has_value();
}
- // Checks that 1. the last Parameter in the Shape is of type
- // VFParamKind::GlobalPredicate and 2. it is the only one of such
- // type.
- bool IsMasked() const {
- const auto NGlobalPreds =
- std::count_if(Info.Shape.Parameters.begin(),
- Info.Shape.Parameters.end(), [](const VFParameter PK) {
- return PK.ParamKind == VFParamKind::GlobalPredicate;
- });
- return NGlobalPreds == 1 && Info.Shape.Parameters.back().ParamKind ==
- VFParamKind::GlobalPredicate;
+ /// Returns whether the parsed function contains a mask
+ bool isMasked() const { return Info.isMasked(); }
+
+ /// Checks that the number of vectorized parameters matches the
+ /// scalar ones. This requires a correct scalar FunctionType string to be fed
+ /// to the 'invokeParser'. It takes into account that vectorized calls may
+ /// also have a Mask.
----------------
paulwalker-arm wrote:
Perhaps "Mask parameters that are only required by the vector function call are ignored.".
https://github.com/llvm/llvm-project/pull/73907
More information about the llvm-commits
mailing list