21#define DEBUG_TYPE "vfabi-demangler"
38 if (MangledName.
empty())
39 return ParseRet::Error;
73 return ParseRet::Error;
82 std::pair<unsigned, bool> &ParsedVF) {
86 LLVM_DEBUG(
dbgs() <<
"Vector function variant declared with scalable VF "
87 <<
"but ISA supported for SVE and RVV only\n");
88 return ParseRet::Error;
100 return ParseRet::Error;
104 return ParseRet::Error;
106 ParsedVF = {VF,
false};
128 return ParseRet::Error;
132 return ParseRet::None;
153 if (Ret != ParseRet::None)
158 if (Ret != ParseRet::None)
163 if (Ret != ParseRet::None)
168 if (Ret != ParseRet::None)
171 return ParseRet::None;
200 return ParseRet::None;
235 return ParseRet::None;
260 const ParseRet HasLinearRuntime =
262 if (HasLinearRuntime != ParseRet::None)
263 return HasLinearRuntime;
265 const ParseRet HasLinearCompileTime =
267 if (HasLinearCompileTime != ParseRet::None)
268 return HasLinearCompileTime;
270 return ParseRet::None;
286 return ParseRet::Error;
289 return ParseRet::Error;
291 Alignment =
Align(Val);
296 return ParseRet::None;
308 "Scalable VF decoding only implemented for SVE and RVV\n");
310 if (Ty->isIntegerTy(64) || Ty->isDoubleTy() || Ty->isPointerTy())
312 if (Ty->isIntegerTy(32) || Ty->isFloatTy())
314 if (Ty->isIntegerTy(16) || Ty->is16bitFPTy())
316 if (Ty->isIntegerTy(8))
324static std::optional<ElementCount>
330 for (
auto &Param : Params) {
334 Type *PTy = Signature->getParamType(Param.ParamPos);
349 Type *RetTy = Signature->getReturnType();
381 const StringRef OriginalName = MangledName;
399 if (
tryParseMask(MangledName, IsMasked) != ParseRet::OK)
403 std::pair<unsigned, bool> ParsedVF;
404 if (
tryParseVLEN(MangledName, ISA, ParsedVF) != ParseRet::OK)
411 const unsigned ParameterPos = Parameters.size();
417 if (ParamFound == ParseRet::Error)
420 if (ParamFound == ParseRet::OK) {
423 const ParseRet AlignFound =
tryParseAlign(MangledName, Alignment);
425 if (AlignFound == ParseRet::Error)
429 Parameters.push_back({ParameterPos, PKind, StepOrPos, Alignment});
431 }
while (ParamFound == ParseRet::OK);
435 if (Parameters.empty())
448 std::optional<ElementCount> EC;
449 if (ParsedVF.second) {
464 MangledName.
take_while([](
char In) {
return In !=
'('; });
466 if (ScalarName.
empty())
470 MangledName = MangledName.
ltrim(ScalarName);
476 VectorName = MangledName;
478 if (VectorName.
empty())
490 const unsigned Pos = Parameters.size();
499 const auto NGlobalPreds =
503 assert(NGlobalPreds < 2 &&
"Cannot have more than one global predicate.");
506 "The global predicate must be the last parameter");
508 const VFShape Shape({*EC, Parameters});
509 return VFInfo({Shape, std::string(ScalarName), std::string(VectorName), ISA});
531 " that have a textual representation in the mangled name"
532 " of the Vector Function ABI");
542 S.
split(ListAttr,
",");
545 std::optional<VFInfo> Info =
548 LLVM_DEBUG(
dbgs() <<
"VFABI: Adding mapping '" << S <<
"' for " << CI
550 VariantMappings.
push_back(std::string(S));
561 int ScalarParamIndex = 0;
562 for (
auto VFParam : Info.Shape.Parameters) {
577 if (!RetTy->isVoidTy())
584 if (VariantMappings.
empty())
589 for (
const std::string &VariantMapping : VariantMappings)
590 Out << VariantMapping <<
",";
597 for (
const std::string &VariantMapping : VariantMappings) {
598 LLVM_DEBUG(
dbgs() <<
"VFABI: adding mapping '" << VariantMapping <<
"'\n");
599 std::optional<VFInfo> VI =
601 assert(VI &&
"Cannot add an invalid VFABI name.");
602 assert(M->getNamedValue(VI->VectorName) &&
603 "Cannot add variant to attribute: "
604 "vector function declaration is missing.");
612 for (
unsigned Pos = 0, NumParams =
Parameters.size(); Pos < NumParams;
633 if (
Parameters[Pos].LinearStepOrPos >=
int(NumParams))
640 if (
Parameters[Pos].LinearStepOrPos ==
int(Pos))
646 for (
unsigned NextPos = Pos + 1; NextPos < NumParams; ++NextPos)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
Module.h This file contains the declarations for the Module class.
This file implements a set that has insertion order iteration characteristics.
This file defines the SmallString class.
This file implements the StringSwitch template, which mimics a switch() statement whose cases are str...
static ParseRet tryParseVLEN(StringRef &ParseString, VFISAKind ISA, std::pair< unsigned, bool > &ParsedVF)
Extract the <vlen> information from the mangled string, and sets ParsedVF accordingly.
static ParseRet tryParseMask(StringRef &MangledName, bool &IsMasked)
Extracts the <mask> information from the mangled string, and sets IsMasked accordingly.
static ParseRet tryParseParameter(StringRef &ParseString, VFParamKind &PKind, int &StepOrPos)
Looks into the <parameters> part of the mangled name in search for valid paramaters at the beginning ...
static std::optional< ElementCount > getElementCountForTy(const VFISAKind ISA, const Type *Ty)
static std::optional< ElementCount > getScalableECFromSignature(const FunctionType *Signature, const VFISAKind ISA, const SmallVectorImpl< VFParameter > &Params)
static ParseRet tryParseLinearTokenWithRuntimeStep(StringRef &ParseString, VFParamKind &PKind, int &Pos, const StringRef Token)
The function looks for the following strings at the beginning of the input string ParseString:
static ParseRet tryParseLinearWithRuntimeStep(StringRef &ParseString, VFParamKind &PKind, int &StepOrPos)
The function looks for the following string at the beginning of the input string ParseString:
static ParseRet tryParseISA(StringRef &MangledName, VFISAKind &ISA)
Extracts the <isa> information from the mangled string, and sets the ISA accordingly.
static ParseRet tryParseCompileTimeLinearToken(StringRef &ParseString, VFParamKind &PKind, int &LinearStep, const StringRef Token)
The function looks for the following strings at the beginning of the input string ParseString:
static ParseRet tryParseAlign(StringRef &ParseString, Align &Alignment)
Looks into the <parameters> part of the mangled name in search of a valid 'aligned' clause.
static ParseRet tryParseLinearWithCompileTimeStep(StringRef &ParseString, VFParamKind &PKind, int &StepOrPos)
The function looks for the following strings at the beginning of the input string ParseString:
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
bool empty() const
empty - Check if the array is empty.
static LLVM_ABI Attribute get(LLVMContext &Context, AttrKind Kind, uint64_t Val=0)
Return a uniquified Attribute object.
LLVM_ABI StringRef getValueAsString() const
Return the attribute's value as a string.
void addFnAttr(Attribute::AttrKind Kind)
Adds the attribute to the function.
Attribute getFnAttr(StringRef Kind) const
Get the attribute of a given kind for the function.
FunctionType * getFunctionType() const
This class represents a function call, abstracting a target machine's calling convention.
static constexpr ElementCount getScalable(ScalarTy MinVal)
static constexpr ElementCount getFixed(ScalarTy MinVal)
Lightweight error class with error context and mandatory checking.
Class to represent function types.
unsigned getNumParams() const
Return the number of fixed parameters this function type requires.
Type * getParamType(unsigned i) const
Parameter type accessors.
Type * getReturnType() const
static LLVM_ABI FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
LLVM_ABI const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
A Module instance is used to store all the information related to an LLVM module.
Function * getFunction(StringRef Name) const
Look up the specified function in the module symbol table.
A vector that has set insertion semantics.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
StringRef str() const
Explicit conversion to StringRef.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
bool consume_back(StringRef Suffix)
Returns true if this StringRef has the given suffix and removes that suffix.
bool consumeInteger(unsigned Radix, T &Result)
Parse the current string as an integer of the specified radix.
constexpr bool empty() const
empty - Check if the string is empty.
StringRef take_while(function_ref< bool(char)> F) const
Return the longest prefix of 'this' such that every character in the prefix satisfies the given predi...
StringRef drop_front(size_t N=1) const
Return a StringRef equal to 'this' but with the first N elements dropped.
StringRef ltrim(char Char) const
Return string with consecutive Char characters starting from the the left removed.
bool consume_front(StringRef Prefix)
Returns true if this StringRef has the given prefix and removes that prefix.
StringRef take_front(size_t N=1) const
Return a StringRef equal to 'this' but with only the first N elements remaining.
A switch()-like statement whose cases are string literals.
StringSwitch & Case(StringLiteral S, T Value)
Class to represent struct types.
The instances of the Type class are immutable: once they are created, they are never changed.
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
static LLVM_ABI IntegerType * getInt1Ty(LLVMContext &C)
bool isVoidTy() const
Return true if this is 'void'.
Base class of all SIMD vector types.
static LLVM_ABI VectorType * get(Type *ElementType, ElementCount EC)
This static method is the primary way to construct an VectorType.
static constexpr bool isKnownLT(const FixedOrScalableQuantity &LHS, const FixedOrScalableQuantity &RHS)
constexpr ScalarTy getKnownMinValue() const
Returns the minimum value this quantity can represent.
A raw_ostream that writes to an SmallVector or SmallString.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
static constexpr char const * MappingsAttrName
LLVM_ABI std::optional< VFInfo > tryDemangleForVFABI(StringRef MangledName, const FunctionType *FTy)
Function to construct a VFInfo out of a mangled names in the following format:
LLVM_ABI FunctionType * createFunctionType(const VFInfo &Info, const FunctionType *ScalarFTy)
Constructs a FunctionType by applying vector function information to the type of a matching scalar fu...
LLVM_ABI void getVectorVariantNames(const CallInst &CI, SmallVectorImpl< std::string > &VariantMappings)
Populates a set of strings representing the Vector Function ABI variants associated to the CallInst C...
LLVM_ABI void setVectorVariantNames(CallInst *CI, ArrayRef< std::string > VariantMappings)
Overwrite the Vector Function ABI variants attribute with the names provide in VariantMappings.
LLVM_ABI VFParamKind getVFParamKindFromString(const StringRef Token)
Retrieve the VFParamKind from a string token.
static constexpr char const * _LLVM_
LLVM Internal VFABI ISA token for vector functions.
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
bool isUnpackedStructLiteral(StructType *StructTy)
constexpr from_range_t from_range
constexpr bool isPowerOf2_64(uint64_t Value)
Return true if the argument is a power of two > 0 (64 bit edition.)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Type * toVectorizedTy(Type *Ty, ElementCount EC)
A helper for converting to vectorized types.
VFISAKind
Describes the type of Instruction Set Architecture.
auto count_if(R &&Range, UnaryPredicate P)
Wrapper function around std::count_if to count the number of times an element satisfying a given pred...
ArrayRef< Type * > getContainedTypes(Type *const &Ty)
Returns the types contained in Ty.
VFParamKind
Describes the type of Parameters.
This struct is a compact representation of a valid (non-zero power of two) alignment.
Holds the VFShape for a specific scalar to vector function mapping.
Encapsulates information needed to describe a parameter.
Contains the information about the kind of vectorization available.
LLVM_ABI bool hasValidParameterList() const
Validation check on the Parameters in the VFShape.
SmallVector< VFParameter, 8 > Parameters