[llvm] [VFABI] Create FunctionType for vector functions (PR #75058)
Paul Walker via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 15 05:53:20 PST 2023
================
@@ -91,6 +92,75 @@ class VFABIParserTest : public ::testing::Test {
bool matchParametersNum() {
return (Parameters.size() - isMasked()) == ScalarFTy->getNumParams();
}
+
+ /// Creates a mock CallInst and uses it along with VFInfo to create a
+ /// FunctionType. Then it checks that the created FunctionType matches the
+ /// number and type of arguments with both the ScalarFTy and the operands of
+ /// the call.
+ bool checkFunctionType() {
+ // For scalable ISAs, the created vector FunctionType might have a mask
+ // parameter Type, according to VFABI. Regardless, this input CallInst,
+ // despite being a vectorized call, it will not have a masked operand.
+ SmallVector<Value *, 8> Args;
+ SmallVector<Type *, 8> CallTypes;
+ for (auto [VFParam, STy] :
+ zip(Info.Shape.Parameters, ScalarFTy->params())) {
+ // use VectorType where relevant, according to VShape
+ Type *UseTy = STy;
+ if (VFParam.ParamKind == VFParamKind::Vector)
+ UseTy = VectorType::get(STy, Info.Shape.VF);
+
+ CallTypes.push_back(UseTy);
+ Args.push_back(Constant::getNullValue(UseTy));
+ }
+
+ // Mangled names do not currently encode return Type information. Generally,
+ // return types are vectors, so use one.
+ Type *VecRetTy = ScalarFTy->getReturnType();
+ if (!VecRetTy->isVoidTy())
+ VecRetTy = VectorType::get(VecRetTy, Info.Shape.VF);
+
+ FunctionCallee F = M->getOrInsertFunction(
+ VectorName, FunctionType::get(VecRetTy, CallTypes, false));
+ std::unique_ptr<CallInst> CI(CallInst::Create(F, Args));
----------------
paulwalker-arm wrote:
Is CI used anywhere?
Regardless of this, it doesn't make sense to me to verify the quality of `createFunctionType` by implementing the same algorithm again or by comparing to the input data used to create the function type. I would expect the expected result to be pass in explicitly and then compared.
Is it possible to have `EXPECT_EQ(createFunctionType(..), TwoOpMaskedFuncTy)` with a bunch of global FunctionTypes? I'm assuming there's a small subset of FunctionTypes you need, otherwise I guess they should be declared locally.
https://github.com/llvm/llvm-project/pull/75058
More information about the llvm-commits
mailing list