[llvm] [VFABI] Improve VFABI unit tests (PR #73907)

Maciej Gabka via llvm-commits llvm-commits at lists.llvm.org
Sun Dec 3 07:38:30 PST 2023


================
@@ -40,61 +38,45 @@ class VFABIParserTest : public ::testing::Test {
   LLVMContext Ctx;
   SMDiagnostic Err;
   std::unique_ptr<Module> M;
-  FunctionType *FTy;
+  FunctionType *ScalarFTy = nullptr;
   FunctionCallee F;
 
 protected:
-  // Referencies to the parser output field.
+  // References to the parser output field.
   ElementCount &VF = Info.Shape.VF;
   VFISAKind &ISA = Info.ISA;
-  SmallVector<VFParameter, 8> &Parameters = Info.Shape.Parameters;
+  SmallVector<VFParameter, 8> &VecFuncParameters = 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. 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 string the parser has to demangle.
+  ///
+  /// \p ScalarFTyStr FunctionType string to be used to get the signature of
+  /// the Scalar function. Used 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);
+                    const StringRef ScalarFTyStr = "void()") {
+    // Reset the VFInfo and the Module to be able to invoke `invokeParser`
+    // multiple times in the same test.
+    reset(ScalarFTyStr);
 
     // 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.get()));
+    const auto OptInfo = VFABI::tryDemangleForVFABI(MangledName, ScalarFTy);
     if (OptInfo) {
       Info = *OptInfo;
       return true;
     }
-
     return false;
   }
 
   // Checks that 1. the last Parameter in the Shape is of type
----------------
mgabka wrote:

I think that this function needs to be a bit more specific, i.e name changed to IsAArch64Masked() as looking at the https://software.intel.com/content/www/us/en/develop/download/vector-simd-function-abi.html specification for X86 the rules are different, i.e it says:
`"The total number of mask bits is equal to VLEN. The number of
mask parameters is equal to the number of parameters for the vector of characteristic data type"
....
"Mask parameters are passed after all other parameters in the same order of parameters that they apply to." `
If I am correct then some non aarch64 tests will need to be adjusted.

@huntergr-arm what is your understanding?


nit:If we want to keep this comment as enumeration, I think it would be nicer to refactor it as:

/// Checks if the function contains a vector mask compatible with AArch64 VFABI, i.e:
/// 1. The last parameter in the Shape is of type VFParamKind::GlobalPredicate.
/// 2. The function has only one  mask.


https://github.com/llvm/llvm-project/pull/73907


More information about the llvm-commits mailing list