9#ifndef LLVM_ANALYSIS_CTXPROFANALYSIS_H
10#define LLVM_ANALYSIS_CTXPROFANALYSIS_H
30class PGOContextualProfile {
36 const std::string Name;
38 FunctionInfo(
StringRef Name) : Name(Name) {}
40 PGOCtxProfile Profiles;
44 bool IsInSpecializedModule =
false;
48 std::map<GlobalValue::GUID, FunctionInfo> FuncInfo;
52 PGOContextualProfile() =
default;
61 return Profiles.Contexts;
71 auto It = FuncInfo.
find(GUID);
72 if (It == FuncInfo.end())
74 return It->second.Name;
79 return FuncInfo.find(
F.getGUID())->second.NextCounterIndex;
84 return FuncInfo.find(
F.getGUID())->second.NextCallsiteIndex;
89 return FuncInfo.find(
F.getGUID())->second.NextCounterIndex++;
94 return FuncInfo.find(
F.getGUID())->second.NextCallsiteIndex++;
107 ModuleAnalysisManager::Invalidator &) {
111 return !PAC.preservedWhenStateless();
116 const std::optional<StringRef> Profile;
121 std::optional<StringRef> Profile = std::nullopt);
141 SetVector<std::pair<CallBase *, Function *>> &Candidates);
161class ProfileAnnotatorImpl;
163 std::unique_ptr<ProfileAnnotatorImpl> PImpl;
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This header defines various interfaces for pass management in LLVM.
Reader for contextual iFDO profile, which comes in bitstream format.
ModuleAnalysisManager MAM
static cl::opt< RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode > Mode("regalloc-enable-advisor", cl::Hidden, cl::init(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default), cl::desc("Enable regalloc advisor mode"), cl::values(clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default, "default", "Default"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Release, "release", "precompiled"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Development, "development", "for training")))
This file implements a set that has insertion order iteration characteristics.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
LLVM Basic Block Representation.
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
LLVM_ABI PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM)
LLVM_ABI CtxProfAnalysisPrinterPass(raw_ostream &OS)
LLVM_ABI PGOContextualProfile run(Module &M, ModuleAnalysisManager &MAM)
static LLVM_ABI InstrProfIncrementInst * getBBInstrumentation(BasicBlock &BB)
Get the instruction instrumenting a BB, or nullptr if not present.
static LLVM_ABI InstrProfIncrementInstStep * getSelectInstrumentation(SelectInst &SI)
Get the step instrumentation associated with a select
static LLVM_ABI void collectIndirectCallPromotionList(CallBase &IC, Result &Profile, SetVector< std::pair< CallBase *, Function * > > &Candidates)
static LLVM_ABI InstrProfCallsite * getCallsiteInstrumentation(CallBase &CB)
Get the instruction instrumenting a callsite, or nullptr if that cannot be found.
static LLVM_ABI AnalysisKey Key
PGOContextualProfile Result
LLVM_ABI CtxProfAnalysis(std::optional< StringRef > Profile=std::nullopt)
uint64_t GUID
Declare a type to represent a global unique identifier for a global value.
This represents the llvm.instrprof.callsite intrinsic.
This represents the llvm.instrprof.increment.step intrinsic.
This represents the llvm.instrprof.increment intrinsic.
A Module instance is used to store all the information related to an LLVM module.
The instrumented contextual profile, produced by the CtxProfAnalysis.
LLVM_ABI void visit(ConstVisitor, const Function *F=nullptr) const
friend class CtxProfAnalysisPrinterPass
PGOContextualProfile(PGOContextualProfile &&)=default
LLVM_ABI const CtxProfFlatProfile flatten() const
LLVM_ABI bool isInSpecializedModule() const
LLVM_ABI void update(Visitor, const Function &F)
StringRef getFunctionName(GlobalValue::GUID GUID) const
bool invalidate(Module &, const PreservedAnalyses &PA, ModuleAnalysisManager::Invalidator &)
friend class CtxProfAnalysis
uint32_t getNumCounters(const Function &F) const
function_ref< void(PGOCtxProfContext &)> Visitor
uint32_t allocateNextCounterIndex(const Function &F)
const PGOCtxProfile & profiles() const
function_ref< void(const PGOCtxProfContext &)> ConstVisitor
const CtxProfContextualProfiles & contexts() const
PGOContextualProfile(const PGOContextualProfile &)=delete
uint32_t getNumCallsites(const Function &F) const
uint32_t allocateNextCallsiteIndex(const Function &F)
LLVM_ABI const CtxProfFlatIndirectCallProfile flattenVirtCalls() const
bool isFunctionKnown(const Function &F) const
A node (context) in the loaded contextual profile, suitable for mutation during IPO passes.
A set of analyses that are preserved following a run of a transformation pass.
PreservedAnalysisChecker getChecker() const
Build a checker for this PreservedAnalyses and the specified analysis type.
LLVM_ABI ~ProfileAnnotator()
LLVM_ABI bool getSelectInstrProfile(SelectInst &SI, uint64_t &TrueCount, uint64_t &FalseCount) const
LLVM_ABI bool getOutgoingBranchWeights(BasicBlock &BB, SmallVectorImpl< uint64_t > &Profile, uint64_t &MaxCount) const
LLVM_ABI uint64_t getBBCount(const BasicBlock &BB) const
LLVM_ABI ProfileAnnotator(const Function &F, ArrayRef< uint64_t > RawCounters)
This class represents the LLVM 'select' instruction.
A vector that has set insertion semantics.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Represent a constant reference to a string, i.e.
size_t find(char C, size_t From=0) const
Search for the first character C in the string.
An efficient, type-erasing, non-owning reference to a callable.
This class implements an extremely fast bulk output stream that can only output to a stream.
This is an optimization pass for GlobalISel generic memory operations.
std::map< GlobalValue::GUID, SmallVector< uint64_t, 1 > > CtxProfFlatProfile
DenseMap< GlobalValue::GUID, uint64_t > FlatIndirectTargets
std::map< GlobalValue::GUID, PGOCtxProfContext > CtxProfContextualProfiles
DenseMap< GlobalValue::GUID, DenseMap< uint32_t, FlatIndirectTargets > > CtxProfFlatIndirectCallProfile
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.
A CRTP mix-in that provides informational APIs needed for analysis passes.
A special type used by analysis passes to provide an address that identifies that particular analysis...
A CRTP mix-in for passes that should not be skipped.