[llvm] [TLI] Use the VFABI demangling when declaring vector variants. (PR #76753)

Paschalis Mpeis via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 3 04:26:11 PST 2024


================
@@ -35,35 +35,36 @@ STATISTIC(NumCompUsedAdded,
 
 /// A helper function that adds the vector function declaration that
 /// vectorizes the CallInst CI with a vectorization factor of VF
-/// lanes. The TLI assumes that all parameters and the return type of
-/// CI (other than void) need to be widened to a VectorType of VF
-/// lanes.
+/// lanes. For each mapping TLI contains a VABI prefix, which contains
+/// all information required to create vector function declaration.
 static void addVariantDeclaration(CallInst &CI, const ElementCount &VF,
-                                  bool Predicate, const StringRef VFName) {
+                                  const VecDesc *VD) {
   Module *M = CI.getModule();
+  FunctionType *FTy = CI.getFunctionType();
 
-  // Add function declaration.
-  Type *RetTy = ToVectorTy(CI.getType(), VF);
-  SmallVector<Type *, 4> Tys;
-  for (Value *ArgOperand : CI.args())
-    Tys.push_back(ToVectorTy(ArgOperand->getType(), VF));
-  assert(!CI.getFunctionType()->isVarArg() &&
-         "VarArg functions are not supported.");
-  if (Predicate)
-    Tys.push_back(ToVectorTy(Type::getInt1Ty(RetTy->getContext()), VF));
-  FunctionType *FTy = FunctionType::get(RetTy, Tys, /*isVarArg=*/false);
-  Function *VectorF =
-      Function::Create(FTy, Function::ExternalLinkage, VFName, M);
-  VectorF->copyAttributesFrom(CI.getCalledFunction());
+  assert(!FTy->isVarArg() && "VarArg functions are not supported.");
+
+  const std::optional<VFInfo> Info =
+      VFABI::tryDemangleForVFABI(VD->getVectorFunctionABIVariantString(), FTy);
+
+  assert(Info && "Failed to demangle vector variant");
+
+  assert(Info->Shape.VF == VF && "Mangled name does not match VF");
+
+  const StringRef VFName = VD->getVectorFnName();
+  FunctionType *VFTy = VFABI::createFunctionType(*Info, FTy);
----------------
paschalis-mpeis wrote:

nit: I would rename this to `VectorFTy` to match similar code that uses VFABI.

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


More information about the llvm-commits mailing list