[llvm] [VFABI] Refactor try demangle for vfabi to use only the vector abi mangled names (PR #67430)

Paul Walker via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 12 04:40:24 PDT 2023


================
@@ -61,29 +61,77 @@ ParseRet tryParseMask(StringRef &MangledName, bool &IsMasked) {
   return ParseRet::Error;
 }
 
+#ifndef NDEBUG
+// Verify the assumtion that all vectors in the signature of a vector
+// function have the same number of elements.
+bool verifyAllVectorsHaveSameWidth(FunctionType *Signature) {
+  SmallVector<VectorType *, 2> VecTys;
+  if (auto *RetTy = dyn_cast<VectorType>(Signature->getReturnType()))
+    VecTys.push_back(RetTy);
+  for (auto *Ty : Signature->params())
+    if (auto *VTy = dyn_cast<VectorType>(Ty))
+      VecTys.push_back(VTy);
+
+  if (VecTys.size() <= 1)
+    return true;
+
+  assert(VecTys.size() > 1 && "Invalid number of elements.");
+  const ElementCount EC = VecTys[0]->getElementCount();
+  return llvm::all_of(llvm::drop_begin(VecTys), [&EC](VectorType *VTy) {
+    return (EC == VTy->getElementCount());
+  });
+}
+#endif // NDEBUG
+
 /// Extract the `<vlen>` information from the mangled string, and
 /// sets `VF` accordingly. A `<vlen> == "x"` token is interpreted as a scalable
 /// vector length. On success, the `<vlen>` token is removed from
 /// the input string `ParseString`.
 ///
-ParseRet tryParseVLEN(StringRef &ParseString, unsigned &VF, bool &IsScalable) {
+ParseRet tryParseVLEN(StringRef &ParseString, ElementCount &EC,
+                      const CallInst &CI, VFISAKind ISA) {
+  unsigned VF = 0;
   if (ParseString.consume_front("x")) {
-    // Set VF to 0, to be later adjusted to a value grater than zero
-    // by looking at the signature of the vector function with
-    // `getECFromSignature`.
-    VF = 0;
-    IsScalable = true;
+    if (ISA != VFISAKind::SVE)
+      return ParseRet::Error;
+    FunctionType *Signature = CI.getFunctionType();
+    assert(verifyAllVectorsHaveSameWidth(Signature) &&
+           "Invalid vector signature.");
----------------
paulwalker-arm wrote:

I'm not sure this makes much sense because isn't `CI` the call to the scalar function?  I'm thinking `verifyAllVectorsHaveSameWidth` only existed due to the bogus way  `EC` was  previously calculated.

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


More information about the llvm-commits mailing list