[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.");
+
+    ArrayRef<Type *> ParamTys = Signature->params();
+    if (ParamTys.empty()) {
+      return ParseRet::Error;
+    }
----------------
paulwalker-arm wrote:

It's likely more complicated than this because I believe we support the case where there's a return value but no parameters.

Also, now I can see the code, I think I've given you an incomplete steer because in order to support things like "uniform" and "linear" we cannot pick just any parameter, we first need to know which of the parameters are required to be a vector types.   This means `tryParseVLEN` likely needs to be called last after we constructed the `VFParameter`'s.

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


More information about the llvm-commits mailing list