@@ -33,37 +33,37 @@ STATISTIC(NumVFDeclAdded,
33
33
STATISTIC (NumCompUsedAdded,
34
34
" Number of `@llvm.compiler.used` operands that have been added." );
35
35
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.
41
40
static void addVariantDeclaration (CallInst &CI, const ElementCount &VF,
42
- bool Predicate, const StringRef VFName ) {
41
+ const VecDesc *VD ) {
43
42
Module *M = CI.getModule ();
43
+ FunctionType *ScalarFTy = CI.getFunctionType ();
44
44
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 ());
58
58
++NumVFDeclAdded;
59
59
LLVM_DEBUG (dbgs () << DEBUG_TYPE << " : Added to the module: `" << VFName
60
- << " ` of type " << *(VectorF-> getType ()) << " \n " );
60
+ << " ` of type " << *VectorFTy << " \n " );
61
61
62
62
// Make function declaration (without a body) "sticky" in the IR by
63
63
// 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` "
65
65
" only on declarations." );
66
- appendToCompilerUsed (*M, {VectorF });
66
+ appendToCompilerUsed (*M, {VecFunc });
67
67
LLVM_DEBUG (dbgs () << DEBUG_TYPE << " : Adding `" << VFName
68
68
<< " ` to `@llvm.compiler.used`.\n " );
69
69
++NumCompUsedAdded;
@@ -100,7 +100,7 @@ static void addMappingsFromTLI(const TargetLibraryInfo &TLI, CallInst &CI) {
100
100
}
101
101
Function *VariantF = M->getFunction (VD->getVectorFnName ());
102
102
if (!VariantF)
103
- addVariantDeclaration (CI, VF, Predicate, VD-> getVectorFnName () );
103
+ addVariantDeclaration (CI, VF, VD );
104
104
}
105
105
};
106
106
0 commit comments