@@ -33,37 +33,37 @@ STATISTIC(NumVFDeclAdded,
3333STATISTIC (NumCompUsedAdded,
3434 " Number of `@llvm.compiler.used` operands that have been added." );
3535
36- // / A helper function that adds the vector function declaration that
37- // / vectorizes the CallInst CI with a vectorization factor of VF
38- // / lanes. The TLI assumes that all parameters and the return type of
39- // / CI (other than void) need to be widened to a VectorType of VF
40- // / lanes.
36+ // / A helper function that adds the vector variant declaration for vectorizing
37+ // / the CallInst \p CI with a vectorization factor of \p VF lanes. For each
38+ // / mapping, TLI provides a VABI prefix, which contains all information required
39+ // / to create vector function declaration.
4140static void addVariantDeclaration (CallInst &CI, const ElementCount &VF,
42- bool Predicate, const StringRef VFName ) {
41+ const VecDesc *VD ) {
4342 Module *M = CI.getModule ();
43+ FunctionType *ScalarFTy = CI.getFunctionType ();
4444
45- // Add function declaration.
46- Type *RetTy = ToVectorTy (CI. getType (), VF);
47- SmallVector<Type *, 4 > Tys;
48- for (Value *ArgOperand : CI. args ())
49- Tys. push_back ( ToVectorTy (ArgOperand-> getType (), VF));
50- assert (!CI. getFunctionType ()-> isVarArg () &&
51- " VarArg functions are not supported. " );
52- if (Predicate)
53- Tys. push_back ( ToVectorTy ( Type::getInt1Ty (RetTy-> getContext ()), VF) );
54- FunctionType *FTy = FunctionType::get (RetTy, Tys, /* isVarArg= */ false );
55- Function *VectorF =
56- Function::Create (FTy , Function::ExternalLinkage, VFName, M);
57- VectorF ->copyAttributesFrom (CI.getCalledFunction ());
45+ assert (!ScalarFTy-> isVarArg () && " VarArg functions are not supported. " );
46+
47+ const std::optional<VFInfo> Info = VFABI::tryDemangleForVFABI (
48+ VD-> getVectorFunctionABIVariantString (), ScalarFTy);
49+
50+ assert (Info && " Failed to demangle vector variant " );
51+ assert (Info-> Shape . VF == VF && " Mangled name does not match VF " );
52+
53+ const StringRef VFName = VD-> getVectorFnName ( );
54+ FunctionType *VectorFTy = VFABI::createFunctionType (*Info, ScalarFTy );
55+ Function *VecFunc =
56+ Function::Create (VectorFTy , Function::ExternalLinkage, VFName, M);
57+ VecFunc ->copyAttributesFrom (CI.getCalledFunction ());
5858 ++NumVFDeclAdded;
5959 LLVM_DEBUG (dbgs () << DEBUG_TYPE << " : Added to the module: `" << VFName
60- << " ` of type " << *(VectorF-> getType ()) << " \n " );
60+ << " ` of type " << *VectorFTy << " \n " );
6161
6262 // Make function declaration (without a body) "sticky" in the IR by
6363 // listing it in the @llvm.compiler.used intrinsic.
64- assert (!VectorF ->size () && " VFABI attribute requires `@llvm.compiler.used` "
64+ assert (!VecFunc ->size () && " VFABI attribute requires `@llvm.compiler.used` "
6565 " only on declarations." );
66- appendToCompilerUsed (*M, {VectorF });
66+ appendToCompilerUsed (*M, {VecFunc });
6767 LLVM_DEBUG (dbgs () << DEBUG_TYPE << " : Adding `" << VFName
6868 << " ` to `@llvm.compiler.used`.\n " );
6969 ++NumCompUsedAdded;
@@ -100,7 +100,7 @@ static void addMappingsFromTLI(const TargetLibraryInfo &TLI, CallInst &CI) {
100100 }
101101 Function *VariantF = M->getFunction (VD->getVectorFnName ());
102102 if (!VariantF)
103- addVariantDeclaration (CI, VF, Predicate, VD-> getVectorFnName () );
103+ addVariantDeclaration (CI, VF, VD );
104104 }
105105 };
106106
0 commit comments