26 if (MangledName.
empty())
27 return ParseRet::Error;
31 ISA = VFISAKind::LLVM;
34 .
Case(
"n", VFISAKind::AdvancedSIMD)
35 .
Case(
"s", VFISAKind::SVE)
36 .
Case(
"b", VFISAKind::SSE)
37 .
Case(
"c", VFISAKind::AVX)
38 .
Case(
"d", VFISAKind::AVX2)
39 .
Case(
"e", VFISAKind::AVX512)
50ParseRet tryParseMask(
StringRef &MangledName,
bool &IsMasked) {
61 return ParseRet::Error;
69ParseRet tryParseVLEN(
StringRef &ParseString,
unsigned &VF,
bool &IsScalable) {
80 return ParseRet::Error;
84 return ParseRet::Error;
102ParseRet tryParseLinearTokenWithRuntimeStep(
StringRef &ParseString,
108 return ParseRet::Error;
112 return ParseRet::None;
126ParseRet tryParseLinearWithRuntimeStep(
StringRef &ParseString,
131 Ret = tryParseLinearTokenWithRuntimeStep(ParseString, PKind, StepOrPos,
"ls");
132 if (Ret != ParseRet::None)
136 Ret = tryParseLinearTokenWithRuntimeStep(ParseString, PKind, StepOrPos,
"Rs");
137 if (Ret != ParseRet::None)
141 Ret = tryParseLinearTokenWithRuntimeStep(ParseString, PKind, StepOrPos,
"Ls");
142 if (Ret != ParseRet::None)
146 Ret = tryParseLinearTokenWithRuntimeStep(ParseString, PKind, StepOrPos,
"Us");
147 if (Ret != ParseRet::None)
150 return ParseRet::None;
165ParseRet tryParseCompileTimeLinearToken(
StringRef &ParseString,
178 return ParseRet::None;
190ParseRet tryParseLinearWithCompileTimeStep(
StringRef &ParseString,
193 if (tryParseCompileTimeLinearToken(ParseString, PKind, StepOrPos,
"l") ==
198 if (tryParseCompileTimeLinearToken(ParseString, PKind, StepOrPos,
"R") ==
203 if (tryParseCompileTimeLinearToken(ParseString, PKind, StepOrPos,
"L") ==
208 if (tryParseCompileTimeLinearToken(ParseString, PKind, StepOrPos,
"U") ==
212 return ParseRet::None;
226 PKind = VFParamKind::Vector;
232 PKind = VFParamKind::OMP_Uniform;
237 const ParseRet HasLinearRuntime =
238 tryParseLinearWithRuntimeStep(ParseString, PKind, StepOrPos);
239 if (HasLinearRuntime != ParseRet::None)
240 return HasLinearRuntime;
242 const ParseRet HasLinearCompileTime =
243 tryParseLinearWithCompileTimeStep(ParseString, PKind, StepOrPos);
244 if (HasLinearCompileTime != ParseRet::None)
245 return HasLinearCompileTime;
247 return ParseRet::None;
263 return ParseRet::Error;
266 return ParseRet::Error;
268 Alignment =
Align(Val);
273 return ParseRet::None;
279bool verifyAllVectorsHaveSameWidth(
FunctionType *Signature) {
281 if (
auto *
RetTy = dyn_cast<VectorType>(Signature->getReturnType()))
283 for (
auto *Ty : Signature->params())
284 if (
auto *VTy = dyn_cast<VectorType>(Ty))
287 if (VecTys.
size() <= 1)
290 assert(VecTys.
size() > 1 &&
"Invalid number of elements.");
293 return (EC == VTy->getElementCount());
302 assert(verifyAllVectorsHaveSameWidth(Signature) &&
303 "Invalid vector signature.");
305 if (
auto *
RetTy = dyn_cast<VectorType>(Signature->getReturnType()))
306 return RetTy->getElementCount();
307 for (
auto *Ty : Signature->params())
308 if (
auto *VTy = dyn_cast<VectorType>(Ty))
309 return VTy->getElementCount();
319 const StringRef OriginalName = MangledName;
332 if (tryParseISA(MangledName, ISA) != ParseRet::OK)
337 if (tryParseMask(MangledName, IsMasked) != ParseRet::OK)
343 if (tryParseVLEN(MangledName, VF, IsScalable) != ParseRet::OK)
350 const unsigned ParameterPos = Parameters.
size();
353 ParamFound = tryParseParameter(MangledName, PKind, StepOrPos);
356 if (ParamFound == ParseRet::Error)
359 if (ParamFound == ParseRet::OK) {
362 const ParseRet AlignFound = tryParseAlign(MangledName, Alignment);
364 if (AlignFound == ParseRet::Error)
368 Parameters.
push_back({ParameterPos, PKind, StepOrPos, Alignment});
370 }
while (ParamFound == ParseRet::OK);
374 if (Parameters.
empty())
385 MangledName.
take_while([](
char In) {
return In !=
'('; });
387 if (ScalarName.
empty())
391 MangledName = MangledName.
ltrim(ScalarName);
397 VectorName = MangledName;
399 if (VectorName.
empty())
405 if (ISA == VFISAKind::LLVM && VectorName == OriginalName)
411 const unsigned Pos = Parameters.
size();
412 Parameters.
push_back({Pos, VFParamKind::GlobalPredicate});
420 const auto NGlobalPreds =
422 return PK.
ParamKind == VFParamKind::GlobalPredicate;
424 assert(NGlobalPreds < 2 &&
"Cannot have more than one global predicate.");
426 assert(Parameters.
back().ParamKind == VFParamKind::GlobalPredicate &&
427 "The global predicate must be the last parameter");
437 const Function *
F = M.getFunction(VectorName);
442 const ElementCount EC = getECFromSignature(
F->getFunctionType());
443 VF = EC.getKnownMinValue();
451 if (!M.getFunction(VectorName))
455 return VFInfo({Shape, std::string(ScalarName), std::string(VectorName), ISA});
460 .
Case(
"v", VFParamKind::Vector)
461 .
Case(
"l", VFParamKind::OMP_Linear)
462 .
Case(
"R", VFParamKind::OMP_LinearRef)
463 .
Case(
"L", VFParamKind::OMP_LinearVal)
464 .
Case(
"U", VFParamKind::OMP_LinearUVal)
465 .
Case(
"ls", VFParamKind::OMP_LinearPos)
466 .
Case(
"Ls", VFParamKind::OMP_LinearValPos)
467 .
Case(
"Rs", VFParamKind::OMP_LinearRefPos)
468 .
Case(
"Us", VFParamKind::OMP_LinearUValPos)
469 .
Case(
"u", VFParamKind::OMP_Uniform)
470 .
Default(VFParamKind::Unknown);
472 if (ParamKind != VFParamKind::Unknown)
477 " that have a textual representation in the mangled name"
478 " of the Vector Function ABI");
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static constexpr ElementCount getFixed(ScalarTy MinVal)
static constexpr ElementCount get(ScalarTy MinVal, bool Scalable)
Lightweight error class with error context and mandatory checking.
A Module instance is used to store all the information related to an LLVM module.
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.
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 startswith(StringRef Prefix) const
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)
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
std::optional< VFInfo > tryDemangleForVFABI(StringRef MangledName, const Module &M)
Function to construct a VFInfo out of a mangled names in the following format:
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.
auto drop_begin(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the first N elements excluded.
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
constexpr bool isPowerOf2_64(uint64_t Value)
Return true if the argument is a power of two > 0 (64 bit edition.)
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...
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.