003 File Manager
Current Path:
/usr/src/contrib/llvm-project/llvm/lib/Analysis
usr
/
src
/
contrib
/
llvm-project
/
llvm
/
lib
/
Analysis
/
📁
..
📄
AliasAnalysis.cpp
(33.55 KB)
📄
AliasAnalysisEvaluator.cpp
(15.64 KB)
📄
AliasAnalysisSummary.cpp
(3.49 KB)
📄
AliasAnalysisSummary.h
(10.17 KB)
📄
AliasSetTracker.cpp
(25.86 KB)
📄
Analysis.cpp
(5.29 KB)
📄
AssumeBundleQueries.cpp
(7.96 KB)
📄
AssumptionCache.cpp
(10.94 KB)
📄
BasicAliasAnalysis.cpp
(85.81 KB)
📄
BlockFrequencyInfo.cpp
(12.39 KB)
📄
BlockFrequencyInfoImpl.cpp
(28.6 KB)
📄
BranchProbabilityInfo.cpp
(43.48 KB)
📄
CFG.cpp
(9.9 KB)
📄
CFGPrinter.cpp
(11.2 KB)
📄
CFLAndersAliasAnalysis.cpp
(33.01 KB)
📄
CFLGraph.h
(21.23 KB)
📄
CFLSteensAliasAnalysis.cpp
(13.24 KB)
📄
CGSCCPassManager.cpp
(31.2 KB)
📄
CallGraph.cpp
(12.86 KB)
📄
CallGraphSCCPass.cpp
(26.31 KB)
📄
CallPrinter.cpp
(9.48 KB)
📄
CaptureTracking.cpp
(15.38 KB)
📄
CmpInstAnalysis.cpp
(4.63 KB)
📄
CodeMetrics.cpp
(6.99 KB)
📄
ConstantFolding.cpp
(105.15 KB)
📄
CostModel.cpp
(3.87 KB)
📄
DDG.cpp
(11.29 KB)
📄
Delinearization.cpp
(4.49 KB)
📄
DemandedBits.cpp
(16.27 KB)
📄
DependenceAnalysis.cpp
(150.78 KB)
📄
DependenceGraphBuilder.cpp
(19.24 KB)
📄
DivergenceAnalysis.cpp
(15.59 KB)
📄
DomPrinter.cpp
(9.67 KB)
📄
DomTreeUpdater.cpp
(15.21 KB)
📄
DominanceFrontier.cpp
(3.2 KB)
📄
EHPersonalities.cpp
(5.89 KB)
📄
GlobalsModRef.cpp
(41 KB)
📄
GuardUtils.cpp
(3.27 KB)
📄
HeatUtils.cpp
(2.85 KB)
📄
IVDescriptors.cpp
(42.28 KB)
📄
IVUsers.cpp
(16.12 KB)
📄
IndirectCallPromotionAnalysis.cpp
(4.33 KB)
📄
InlineAdvisor.cpp
(15.28 KB)
📄
InlineCost.cpp
(99.47 KB)
📄
InlineFeaturesAnalysis.cpp
(1.59 KB)
📄
InlineSizeEstimatorAnalysis.cpp
(10.95 KB)
📄
InstCount.cpp
(2.45 KB)
📄
InstructionPrecedenceTracking.cpp
(4.8 KB)
📄
InstructionSimplify.cpp
(216.91 KB)
📄
Interval.cpp
(1.78 KB)
📄
IntervalPartition.cpp
(4.5 KB)
📄
LazyBlockFrequencyInfo.cpp
(2.81 KB)
📄
LazyBranchProbabilityInfo.cpp
(2.96 KB)
📄
LazyCallGraph.cpp
(67.33 KB)
📄
LazyValueInfo.cpp
(76.38 KB)
📄
LegacyDivergenceAnalysis.cpp
(14.82 KB)
📄
Lint.cpp
(29.07 KB)
📄
Loads.cpp
(20.6 KB)
📄
LoopAccessAnalysis.cpp
(88.02 KB)
📄
LoopAnalysisManager.cpp
(6.6 KB)
📄
LoopCacheAnalysis.cpp
(23.53 KB)
📄
LoopInfo.cpp
(37.15 KB)
📄
LoopNestAnalysis.cpp
(10.62 KB)
📄
LoopPass.cpp
(12.89 KB)
📄
LoopUnrollAnalyzer.cpp
(7.26 KB)
📄
MLInlineAdvisor.cpp
(11.36 KB)
📄
MemDepPrinter.cpp
(5.13 KB)
📄
MemDerefPrinter.cpp
(2.53 KB)
📄
MemoryBuiltins.cpp
(41.14 KB)
📄
MemoryDependenceAnalysis.cpp
(69.89 KB)
📄
MemoryLocation.cpp
(7.92 KB)
📄
MemorySSA.cpp
(90.16 KB)
📄
MemorySSAUpdater.cpp
(57.9 KB)
📄
ModuleDebugInfoPrinter.cpp
(4.02 KB)
📄
ModuleSummaryAnalysis.cpp
(38.13 KB)
📄
MustExecute.cpp
(31.18 KB)
📄
ObjCARCAliasAnalysis.cpp
(5.81 KB)
📄
ObjCARCAnalysisUtils.cpp
(1.07 KB)
📄
ObjCARCInstKind.cpp
(23.15 KB)
📄
OptimizationRemarkEmitter.cpp
(4.23 KB)
📄
PHITransAddr.cpp
(16.05 KB)
📄
PhiValues.cpp
(8.4 KB)
📄
PostDominators.cpp
(3.59 KB)
📄
ProfileSummaryInfo.cpp
(18.07 KB)
📄
PtrUseVisitor.cpp
(1.28 KB)
📄
RegionInfo.cpp
(6.5 KB)
📄
RegionPass.cpp
(9.23 KB)
📄
RegionPrinter.cpp
(8.61 KB)
📄
ReleaseModeModelRunner.cpp
(2.83 KB)
📄
ScalarEvolution.cpp
(475.26 KB)
📄
ScalarEvolutionAliasAnalysis.cpp
(5.96 KB)
📄
ScalarEvolutionDivision.cpp
(7.51 KB)
📄
ScalarEvolutionNormalization.cpp
(4.59 KB)
📄
ScopedNoAliasAA.cpp
(7.38 KB)
📄
StackLifetime.cpp
(12.22 KB)
📄
StackSafetyAnalysis.cpp
(31.81 KB)
📄
StratifiedSets.h
(18.67 KB)
📄
SyncDependenceAnalysis.cpp
(12.97 KB)
📄
SyntheticCountsUtils.cpp
(3.81 KB)
📄
TFUtils.cpp
(8.99 KB)
📄
TargetLibraryInfo.cpp
(58.98 KB)
📄
TargetTransformInfo.cpp
(48.15 KB)
📄
Trace.cpp
(1.8 KB)
📄
TypeBasedAliasAnalysis.cpp
(26.04 KB)
📄
TypeMetadataUtils.cpp
(5.93 KB)
📄
VFABIDemangling.cpp
(16.46 KB)
📄
ValueLattice.cpp
(1.19 KB)
📄
ValueLatticeUtils.cpp
(1.53 KB)
📄
ValueTracking.cpp
(243.08 KB)
📄
VectorUtils.cpp
(48.57 KB)
📁
models
Editing: VFABIDemangling.cpp
//===- VFABIDemangling.cpp - Vector Function ABI demangling utilities. ---===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// #include "llvm/ADT/SmallSet.h" #include "llvm/ADT/SmallString.h" #include "llvm/Analysis/VectorUtils.h" using namespace llvm; namespace { /// Utilities for the Vector Function ABI name parser. /// Return types for the parser functions. enum class ParseRet { OK, // Found. None, // Not found. Error // Syntax error. }; /// Extracts the `<isa>` information from the mangled string, and /// sets the `ISA` accordingly. ParseRet tryParseISA(StringRef &MangledName, VFISAKind &ISA) { if (MangledName.empty()) return ParseRet::Error; if (MangledName.startswith(VFABI::_LLVM_)) { MangledName = MangledName.drop_front(strlen(VFABI::_LLVM_)); ISA = VFISAKind::LLVM; } else { ISA = StringSwitch<VFISAKind>(MangledName.take_front(1)) .Case("n", VFISAKind::AdvancedSIMD) .Case("s", VFISAKind::SVE) .Case("b", VFISAKind::SSE) .Case("c", VFISAKind::AVX) .Case("d", VFISAKind::AVX2) .Case("e", VFISAKind::AVX512) .Default(VFISAKind::Unknown); MangledName = MangledName.drop_front(1); } return ParseRet::OK; } /// Extracts the `<mask>` information from the mangled string, and /// sets `IsMasked` accordingly. The input string `MangledName` is /// left unmodified. ParseRet tryParseMask(StringRef &MangledName, bool &IsMasked) { if (MangledName.consume_front("M")) { IsMasked = true; return ParseRet::OK; } if (MangledName.consume_front("N")) { IsMasked = false; return ParseRet::OK; } return ParseRet::Error; } /// Extract the `<vlen>` information from the mangled string, and /// sets `VF` accordingly. A `<vlen> == "x"` token is interpreted as a scalable /// vector length. On success, the `<vlen>` token is removed from /// the input string `ParseString`. /// ParseRet tryParseVLEN(StringRef &ParseString, unsigned &VF, bool &IsScalable) { if (ParseString.consume_front("x")) { // Set VF to 0, to be later adjusted to a value grater than zero // by looking at the signature of the vector function with // `getECFromSignature`. VF = 0; IsScalable = true; return ParseRet::OK; } if (ParseString.consumeInteger(10, VF)) return ParseRet::Error; // The token `0` is invalid for VLEN. if (VF == 0) return ParseRet::Error; IsScalable = false; return ParseRet::OK; } /// The function looks for the following strings at the beginning of /// the input string `ParseString`: /// /// <token> <number> /// /// On success, it removes the parsed parameter from `ParseString`, /// sets `PKind` to the correspondent enum value, sets `Pos` to /// <number>, and return success. On a syntax error, it return a /// parsing error. If nothing is parsed, it returns None. /// /// The function expects <token> to be one of "ls", "Rs", "Us" or /// "Ls". ParseRet tryParseLinearTokenWithRuntimeStep(StringRef &ParseString, VFParamKind &PKind, int &Pos, const StringRef Token) { if (ParseString.consume_front(Token)) { PKind = VFABI::getVFParamKindFromString(Token); if (ParseString.consumeInteger(10, Pos)) return ParseRet::Error; return ParseRet::OK; } return ParseRet::None; } /// The function looks for the following stringt at the beginning of /// the input string `ParseString`: /// /// <token> <number> /// /// <token> is one of "ls", "Rs", "Us" or "Ls". /// /// On success, it removes the parsed parameter from `ParseString`, /// sets `PKind` to the correspondent enum value, sets `StepOrPos` to /// <number>, and return success. On a syntax error, it return a /// parsing error. If nothing is parsed, it returns None. ParseRet tryParseLinearWithRuntimeStep(StringRef &ParseString, VFParamKind &PKind, int &StepOrPos) { ParseRet Ret; // "ls" <RuntimeStepPos> Ret = tryParseLinearTokenWithRuntimeStep(ParseString, PKind, StepOrPos, "ls"); if (Ret != ParseRet::None) return Ret; // "Rs" <RuntimeStepPos> Ret = tryParseLinearTokenWithRuntimeStep(ParseString, PKind, StepOrPos, "Rs"); if (Ret != ParseRet::None) return Ret; // "Ls" <RuntimeStepPos> Ret = tryParseLinearTokenWithRuntimeStep(ParseString, PKind, StepOrPos, "Ls"); if (Ret != ParseRet::None) return Ret; // "Us" <RuntimeStepPos> Ret = tryParseLinearTokenWithRuntimeStep(ParseString, PKind, StepOrPos, "Us"); if (Ret != ParseRet::None) return Ret; return ParseRet::None; } /// The function looks for the following strings at the beginning of /// the input string `ParseString`: /// /// <token> {"n"} <number> /// /// On success, it removes the parsed parameter from `ParseString`, /// sets `PKind` to the correspondent enum value, sets `LinearStep` to /// <number>, and return success. On a syntax error, it return a /// parsing error. If nothing is parsed, it returns None. /// /// The function expects <token> to be one of "l", "R", "U" or /// "L". ParseRet tryParseCompileTimeLinearToken(StringRef &ParseString, VFParamKind &PKind, int &LinearStep, const StringRef Token) { if (ParseString.consume_front(Token)) { PKind = VFABI::getVFParamKindFromString(Token); const bool Negate = ParseString.consume_front("n"); if (ParseString.consumeInteger(10, LinearStep)) LinearStep = 1; if (Negate) LinearStep *= -1; return ParseRet::OK; } return ParseRet::None; } /// The function looks for the following strings at the beginning of /// the input string `ParseString`: /// /// ["l" | "R" | "U" | "L"] {"n"} <number> /// /// On success, it removes the parsed parameter from `ParseString`, /// sets `PKind` to the correspondent enum value, sets `LinearStep` to /// <number>, and return success. On a syntax error, it return a /// parsing error. If nothing is parsed, it returns None. ParseRet tryParseLinearWithCompileTimeStep(StringRef &ParseString, VFParamKind &PKind, int &StepOrPos) { // "l" {"n"} <CompileTimeStep> if (tryParseCompileTimeLinearToken(ParseString, PKind, StepOrPos, "l") == ParseRet::OK) return ParseRet::OK; // "R" {"n"} <CompileTimeStep> if (tryParseCompileTimeLinearToken(ParseString, PKind, StepOrPos, "R") == ParseRet::OK) return ParseRet::OK; // "L" {"n"} <CompileTimeStep> if (tryParseCompileTimeLinearToken(ParseString, PKind, StepOrPos, "L") == ParseRet::OK) return ParseRet::OK; // "U" {"n"} <CompileTimeStep> if (tryParseCompileTimeLinearToken(ParseString, PKind, StepOrPos, "U") == ParseRet::OK) return ParseRet::OK; return ParseRet::None; } /// Looks into the <parameters> part of the mangled name in search /// for valid paramaters at the beginning of the string /// `ParseString`. /// /// On success, it removes the parsed parameter from `ParseString`, /// sets `PKind` to the correspondent enum value, sets `StepOrPos` /// accordingly, and return success. On a syntax error, it return a /// parsing error. If nothing is parsed, it returns None. ParseRet tryParseParameter(StringRef &ParseString, VFParamKind &PKind, int &StepOrPos) { if (ParseString.consume_front("v")) { PKind = VFParamKind::Vector; StepOrPos = 0; return ParseRet::OK; } if (ParseString.consume_front("u")) { PKind = VFParamKind::OMP_Uniform; StepOrPos = 0; return ParseRet::OK; } const ParseRet HasLinearRuntime = tryParseLinearWithRuntimeStep(ParseString, PKind, StepOrPos); if (HasLinearRuntime != ParseRet::None) return HasLinearRuntime; const ParseRet HasLinearCompileTime = tryParseLinearWithCompileTimeStep(ParseString, PKind, StepOrPos); if (HasLinearCompileTime != ParseRet::None) return HasLinearCompileTime; return ParseRet::None; } /// Looks into the <parameters> part of the mangled name in search /// of a valid 'aligned' clause. The function should be invoked /// after parsing a parameter via `tryParseParameter`. /// /// On success, it removes the parsed parameter from `ParseString`, /// sets `PKind` to the correspondent enum value, sets `StepOrPos` /// accordingly, and return success. On a syntax error, it return a /// parsing error. If nothing is parsed, it returns None. ParseRet tryParseAlign(StringRef &ParseString, Align &Alignment) { uint64_t Val; // "a" <number> if (ParseString.consume_front("a")) { if (ParseString.consumeInteger(10, Val)) return ParseRet::Error; if (!isPowerOf2_64(Val)) return ParseRet::Error; Alignment = Align(Val); return ParseRet::OK; } return ParseRet::None; } #ifndef NDEBUG // Verify the assumtion that all vectors in the signature of a vector // function have the same number of elements. bool verifyAllVectorsHaveSameWidth(FunctionType *Signature) { SmallVector<VectorType *, 2> VecTys; if (auto *RetTy = dyn_cast<VectorType>(Signature->getReturnType())) VecTys.push_back(RetTy); for (auto *Ty : Signature->params()) if (auto *VTy = dyn_cast<VectorType>(Ty)) VecTys.push_back(VTy); if (VecTys.size() <= 1) return true; assert(VecTys.size() > 1 && "Invalid number of elements."); const ElementCount EC = VecTys[0]->getElementCount(); return llvm::all_of( llvm::make_range(VecTys.begin() + 1, VecTys.end()), [&EC](VectorType *VTy) { return (EC == VTy->getElementCount()); }); } #endif // NDEBUG // Extract the VectorizationFactor from a given function signature, // under the assumtion that all vectors have the same number of // elements, i.e. same ElementCount.Min. ElementCount getECFromSignature(FunctionType *Signature) { assert(verifyAllVectorsHaveSameWidth(Signature) && "Invalid vector signature."); if (auto *RetTy = dyn_cast<VectorType>(Signature->getReturnType())) return RetTy->getElementCount(); for (auto *Ty : Signature->params()) if (auto *VTy = dyn_cast<VectorType>(Ty)) return VTy->getElementCount(); return ElementCount(/*Min=*/1, /*Scalable=*/false); } } // namespace // Format of the ABI name: // _ZGV<isa><mask><vlen><parameters>_<scalarname>[(<redirection>)] Optional<VFInfo> VFABI::tryDemangleForVFABI(StringRef MangledName, const Module &M) { const StringRef OriginalName = MangledName; // Assume there is no custom name <redirection>, and therefore the // vector name consists of // _ZGV<isa><mask><vlen><parameters>_<scalarname>. StringRef VectorName = MangledName; // Parse the fixed size part of the manled name if (!MangledName.consume_front("_ZGV")) return None; // Extract ISA. An unknow ISA is also supported, so we accept all // values. VFISAKind ISA; if (tryParseISA(MangledName, ISA) != ParseRet::OK) return None; // Extract <mask>. bool IsMasked; if (tryParseMask(MangledName, IsMasked) != ParseRet::OK) return None; // Parse the variable size, starting from <vlen>. unsigned VF; bool IsScalable; if (tryParseVLEN(MangledName, VF, IsScalable) != ParseRet::OK) return None; // Parse the <parameters>. ParseRet ParamFound; SmallVector<VFParameter, 8> Parameters; do { const unsigned ParameterPos = Parameters.size(); VFParamKind PKind; int StepOrPos; ParamFound = tryParseParameter(MangledName, PKind, StepOrPos); // Bail off if there is a parsing error in the parsing of the parameter. if (ParamFound == ParseRet::Error) return None; if (ParamFound == ParseRet::OK) { Align Alignment; // Look for the alignment token "a <number>". const ParseRet AlignFound = tryParseAlign(MangledName, Alignment); // Bail off if there is a syntax error in the align token. if (AlignFound == ParseRet::Error) return None; // Add the parameter. Parameters.push_back({ParameterPos, PKind, StepOrPos, Alignment}); } } while (ParamFound == ParseRet::OK); // A valid MangledName must have at least one valid entry in the // <parameters>. if (Parameters.empty()) return None; // Check for the <scalarname> and the optional <redirection>, which // are separated from the prefix with "_" if (!MangledName.consume_front("_")) return None; // The rest of the string must be in the format: // <scalarname>[(<redirection>)] const StringRef ScalarName = MangledName.take_while([](char In) { return In != '('; }); if (ScalarName.empty()) return None; // Reduce MangledName to [(<redirection>)]. MangledName = MangledName.ltrim(ScalarName); // Find the optional custom name redirection. if (MangledName.consume_front("(")) { if (!MangledName.consume_back(")")) return None; // Update the vector variant with the one specified by the user. VectorName = MangledName; // If the vector name is missing, bail out. if (VectorName.empty()) return None; } // LLVM internal mapping via the TargetLibraryInfo (TLI) must be // redirected to an existing name. if (ISA == VFISAKind::LLVM && VectorName == OriginalName) return None; // When <mask> is "M", we need to add a parameter that is used as // global predicate for the function. if (IsMasked) { const unsigned Pos = Parameters.size(); Parameters.push_back({Pos, VFParamKind::GlobalPredicate}); } // Asserts for parameters of type `VFParamKind::GlobalPredicate`, as // prescribed by the Vector Function ABI specifications supported by // this parser: // 1. Uniqueness. // 2. Must be the last in the parameter list. const auto NGlobalPreds = std::count_if( Parameters.begin(), Parameters.end(), [](const VFParameter PK) { return PK.ParamKind == VFParamKind::GlobalPredicate; }); assert(NGlobalPreds < 2 && "Cannot have more than one global predicate."); if (NGlobalPreds) assert(Parameters.back().ParamKind == VFParamKind::GlobalPredicate && "The global predicate must be the last parameter"); // Adjust the VF for scalable signatures. The EC.Min is not encoded // in the name of the function, but it is encoded in the IR // signature of the function. We need to extract this information // because it is needed by the loop vectorizer, which reasons in // terms of VectorizationFactor or ElementCount. In particular, we // need to make sure that the VF field of the VFShape class is never // set to 0. if (IsScalable) { const Function *F = M.getFunction(VectorName); // The declaration of the function must be present in the module // to be able to retrieve its signature. if (!F) return None; const ElementCount EC = getECFromSignature(F->getFunctionType()); VF = EC.Min; } // Sanity checks. // 1. We don't accept a zero lanes vectorization factor. // 2. We don't accept the demangling if the vector function is not // present in the module. if (VF == 0) return None; if (!M.getFunction(VectorName)) return None; const VFShape Shape({VF, IsScalable, Parameters}); return VFInfo({Shape, std::string(ScalarName), std::string(VectorName), ISA}); } VFParamKind VFABI::getVFParamKindFromString(const StringRef Token) { const VFParamKind ParamKind = StringSwitch<VFParamKind>(Token) .Case("v", VFParamKind::Vector) .Case("l", VFParamKind::OMP_Linear) .Case("R", VFParamKind::OMP_LinearRef) .Case("L", VFParamKind::OMP_LinearVal) .Case("U", VFParamKind::OMP_LinearUVal) .Case("ls", VFParamKind::OMP_LinearPos) .Case("Ls", VFParamKind::OMP_LinearValPos) .Case("Rs", VFParamKind::OMP_LinearRefPos) .Case("Us", VFParamKind::OMP_LinearUValPos) .Case("u", VFParamKind::OMP_Uniform) .Default(VFParamKind::Unknown); if (ParamKind != VFParamKind::Unknown) return ParamKind; // This function should never be invoked with an invalid input. llvm_unreachable("This fuction should be invoken only on parameters" " that have a textual representation in the mangled name" " of the Vector Function ABI"); }
Upload File
Create Folder