Skip to content

[VFABI] Create FunctionType for vector functions #75058

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions llvm/include/llvm/Analysis/VectorUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,16 @@ static constexpr char const *MappingsAttrName = "vector-function-abi-variant";
/// the presence of the attribute (see InjectTLIMappings).
void getVectorVariantNames(const CallInst &CI,
SmallVectorImpl<std::string> &VariantMappings);

/// Constructs a FunctionType by applying vector function information to the
/// type of a matching scalar function.
/// \param Info gets the vectorization factor (VF) and the VFParamKind of the
/// parameters.
/// \param ScalarFTy gets the Type information of parameters, as it is not
/// stored in \p Info.
/// \returns a pointer to a newly created vector FunctionType
FunctionType *createFunctionType(const VFInfo &Info,
const FunctionType *ScalarFTy);
} // end namespace VFABI

/// The Vector Function Database.
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Analysis/VFABIDemangling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ std::optional<VFInfo> VFABI::tryDemangleForVFABI(StringRef MangledName,
// _ZGV<isa><mask><vlen><parameters>_<scalarname>.
StringRef VectorName = MangledName;

// Parse the fixed size part of the manled name
// Parse the fixed size part of the mangled name
if (!MangledName.consume_front("_ZGV"))
return std::nullopt;

Expand Down
28 changes: 28 additions & 0 deletions llvm/lib/Analysis/VectorUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include "llvm/Analysis/VectorUtils.h"
#include "llvm/ADT/EquivalenceClasses.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/Analysis/DemandedBits.h"
#include "llvm/Analysis/LoopInfo.h"
#include "llvm/Analysis/LoopIterator.h"
Expand All @@ -20,6 +21,7 @@
#include "llvm/Analysis/TargetTransformInfo.h"
#include "llvm/Analysis/ValueTracking.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/PatternMatch.h"
#include "llvm/IR/Value.h"
Expand Down Expand Up @@ -1477,6 +1479,32 @@ void VFABI::getVectorVariantNames(
}
}

FunctionType *VFABI::createFunctionType(const VFInfo &Info,
const FunctionType *ScalarFTy) {
// Create vector parameter types
SmallVector<Type *, 8> VecTypes;
ElementCount VF = Info.Shape.VF;
int ScalarParamIndex = 0;
for (auto VFParam : Info.Shape.Parameters) {
if (VFParam.ParamKind == VFParamKind::GlobalPredicate) {
VectorType *MaskTy =
VectorType::get(Type::getInt1Ty(ScalarFTy->getContext()), VF);
VecTypes.push_back(MaskTy);
continue;
}

Type *OperandTy = ScalarFTy->getParamType(ScalarParamIndex++);
if (VFParam.ParamKind == VFParamKind::Vector)
OperandTy = VectorType::get(OperandTy, VF);
VecTypes.push_back(OperandTy);
}

auto *RetTy = ScalarFTy->getReturnType();
if (!RetTy->isVoidTy())
RetTy = VectorType::get(RetTy, VF);
return FunctionType::get(RetTy, VecTypes, false);
}

bool VFShape::hasValidParameterList() const {
for (unsigned Pos = 0, NumParams = Parameters.size(); Pos < NumParams;
++Pos) {
Expand Down
Loading