16#define DEBUG_TYPE "vfabi-demangling"
32 if (MangledName.
empty())
33 return ParseRet::Error;
37 ISA = VFISAKind::LLVM;
40 .
Case(
"n", VFISAKind::AdvancedSIMD)
41 .
Case(
"s", VFISAKind::SVE)
42 .
Case(
"b", VFISAKind::SSE)
43 .
Case(
"c", VFISAKind::AVX)
44 .
Case(
"d", VFISAKind::AVX2)
45 .
Case(
"e", VFISAKind::AVX512)
56static ParseRet tryParseMask(
StringRef &MangledName,
bool &IsMasked) {
67 return ParseRet::Error;
76 std::pair<unsigned, bool> &ParsedVF) {
79 if (ISA != VFISAKind::SVE) {
80 LLVM_DEBUG(
dbgs() <<
"Vector function variant declared with scalable VF "
81 <<
"but ISA is not SVE\n");
82 return ParseRet::Error;
94 return ParseRet::Error;
98 return ParseRet::Error;
100 ParsedVF = {VF,
false};
116static ParseRet tryParseLinearTokenWithRuntimeStep(
StringRef &ParseString,
122 return ParseRet::Error;
126 return ParseRet::None;
140static ParseRet tryParseLinearWithRuntimeStep(
StringRef &ParseString,
146 Ret = tryParseLinearTokenWithRuntimeStep(ParseString, PKind, StepOrPos,
"ls");
147 if (Ret != ParseRet::None)
151 Ret = tryParseLinearTokenWithRuntimeStep(ParseString, PKind, StepOrPos,
"Rs");
152 if (Ret != ParseRet::None)
156 Ret = tryParseLinearTokenWithRuntimeStep(ParseString, PKind, StepOrPos,
"Ls");
157 if (Ret != ParseRet::None)
161 Ret = tryParseLinearTokenWithRuntimeStep(ParseString, PKind, StepOrPos,
"Us");
162 if (Ret != ParseRet::None)
165 return ParseRet::None;
180static ParseRet tryParseCompileTimeLinearToken(
StringRef &ParseString,
194 return ParseRet::None;
206static ParseRet tryParseLinearWithCompileTimeStep(
StringRef &ParseString,
210 if (tryParseCompileTimeLinearToken(ParseString, PKind, StepOrPos,
"l") ==
215 if (tryParseCompileTimeLinearToken(ParseString, PKind, StepOrPos,
"R") ==
220 if (tryParseCompileTimeLinearToken(ParseString, PKind, StepOrPos,
"L") ==
225 if (tryParseCompileTimeLinearToken(ParseString, PKind, StepOrPos,
"U") ==
229 return ParseRet::None;
243 PKind = VFParamKind::Vector;
249 PKind = VFParamKind::OMP_Uniform;
254 const ParseRet HasLinearRuntime =
255 tryParseLinearWithRuntimeStep(ParseString, PKind, StepOrPos);
256 if (HasLinearRuntime != ParseRet::None)
257 return HasLinearRuntime;
259 const ParseRet HasLinearCompileTime =
260 tryParseLinearWithCompileTimeStep(ParseString, PKind, StepOrPos);
261 if (HasLinearCompileTime != ParseRet::None)
262 return HasLinearCompileTime;
264 return ParseRet::None;
275static ParseRet tryParseAlign(
StringRef &ParseString,
Align &Alignment) {
280 return ParseRet::Error;
283 return ParseRet::Error;
285 Alignment =
Align(Val);
290 return ParseRet::None;
299static std::optional<ElementCount> getElementCountForTy(
const VFISAKind ISA,
302 assert(ISA == VFISAKind::SVE &&
303 "Scalable VF decoding only implemented for SVE\n");
319static std::optional<ElementCount>
325 for (
auto &Param : Params) {
328 if (Param.ParamKind == VFParamKind::Vector) {
331 if (Param.ParamPos >= Signature->getNumParams())
333 Type *PTy = Signature->getParamType(Param.ParamPos);
335 std::optional<ElementCount> EC = getElementCountForTy(ISA, PTy);
342 if (ElementCount::isKnownLT(*EC, MinEC))
348 Type *
RetTy = Signature->getReturnType();
349 if (!
RetTy->isVoidTy()) {
350 std::optional<ElementCount> ReturnEC = getElementCountForTy(ISA,
RetTy);
354 if (ElementCount::isKnownLT(*ReturnEC, MinEC))
373 const StringRef OriginalName = MangledName;
386 if (tryParseISA(MangledName, ISA) != ParseRet::OK)
391 if (tryParseMask(MangledName, IsMasked) != ParseRet::OK)
395 std::pair<unsigned, bool> ParsedVF;
396 if (tryParseVLEN(MangledName, ISA, ParsedVF) != ParseRet::OK)
403 const unsigned ParameterPos = Parameters.
size();
406 ParamFound = tryParseParameter(MangledName, PKind, StepOrPos);
409 if (ParamFound == ParseRet::Error)
412 if (ParamFound == ParseRet::OK) {
415 const ParseRet AlignFound = tryParseAlign(MangledName, Alignment);
417 if (AlignFound == ParseRet::Error)
421 Parameters.
push_back({ParameterPos, PKind, StepOrPos, Alignment});
423 }
while (ParamFound == ParseRet::OK);
427 if (Parameters.
empty())
435 std::optional<ElementCount> EC;
436 if (ParsedVF.second) {
437 EC = getScalableECFromSignature(CI.
getFunctionType(), ISA, Parameters);
451 MangledName.
take_while([](
char In) {
return In !=
'('; });
453 if (ScalarName.
empty())
457 MangledName = MangledName.
ltrim(ScalarName);
463 VectorName = MangledName;
465 if (VectorName.
empty())
471 if (ISA == VFISAKind::LLVM && VectorName == OriginalName)
477 const unsigned Pos = Parameters.
size();
478 Parameters.
push_back({Pos, VFParamKind::GlobalPredicate});
486 const auto NGlobalPreds =
488 return PK.
ParamKind == VFParamKind::GlobalPredicate;
490 assert(NGlobalPreds < 2 &&
"Cannot have more than one global predicate.");
492 assert(Parameters.
back().ParamKind == VFParamKind::GlobalPredicate &&
493 "The global predicate must be the last parameter");
495 const VFShape Shape({*EC, Parameters});
496 return VFInfo({Shape, std::string(ScalarName), std::string(VectorName), ISA});
501 .
Case(
"v", VFParamKind::Vector)
502 .
Case(
"l", VFParamKind::OMP_Linear)
503 .
Case(
"R", VFParamKind::OMP_LinearRef)
504 .
Case(
"L", VFParamKind::OMP_LinearVal)
505 .
Case(
"U", VFParamKind::OMP_LinearUVal)
506 .
Case(
"ls", VFParamKind::OMP_LinearPos)
507 .
Case(
"Ls", VFParamKind::OMP_LinearValPos)
508 .
Case(
"Rs", VFParamKind::OMP_LinearRefPos)
509 .
Case(
"Us", VFParamKind::OMP_LinearUValPos)
510 .
Case(
"u", VFParamKind::OMP_Uniform)
511 .
Default(VFParamKind::Unknown);
513 if (ParamKind != VFParamKind::Unknown)
518 " that have a textual representation in the mangled name"
519 " of the Vector Function ABI");
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
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.
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.
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)
The instances of the Type class are immutable: once they are created, they are never changed.
bool isPointerTy() const
True if this is an instance of PointerType.
bool isFloatTy() const
Return true if this is 'float', a 32-bit IEEE fp type.
bool is16bitFPTy() const
Return true if this is a 16-bit float type.
bool isDoubleTy() const
Return true if this is 'double', a 64-bit IEEE fp type.
bool isIntegerTy() const
True if this is an instance of IntegerType.
constexpr ScalarTy getKnownMinValue() const
Returns the minimum value this quantity can represent.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
std::optional< VFInfo > tryDemangleForVFABI(StringRef MangledName, const CallInst &CI)
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.
constexpr bool isPowerOf2_64(uint64_t Value)
Return true if the argument is a power of two > 0 (64 bit edition.)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
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.