15#ifndef LLVM_PROFILEDATA_CTXINSTRPROFILEREADER_H
16#define LLVM_PROFILEDATA_CTXINSTRPROFILEREADER_H
26class PGOContextualProfile;
27class PGOCtxProfContext;
44 friend class ::llvm::PGOCtxProfContext;
45 friend class ::llvm::PGOContextualProfile;
52 Next->Previous = Previous;
54 Previous->Next = Next;
62 Previous =
Other.Previous;
66 Other.Next->Previous =
this;
68 Other.Previous->Next =
this;
72 Other.Previous =
nullptr;
74 IndexNode() =
default;
82 std::map<GlobalValue::GUID, SmallVector<uint64_t, 1>>;
102 const std::optional<uint64_t> RootEntryCount{};
103 std::optional<CtxProfFlatProfile> Unhandled{};
108 std::optional<uint64_t> RootEntryCount = std::nullopt,
109 std::optional<CtxProfFlatProfile> &&Unhandled = std::nullopt)
110 : GUID(
G), Counters(
std::
move(Counters)), RootEntryCount(RootEntryCount),
111 Unhandled(
std::
move(Unhandled)) {
112 assert(RootEntryCount.has_value() == Unhandled.has_value());
115 Expected<PGOCtxProfContext &>
117 SmallVectorImpl<uint64_t> &&Counters);
121 PGOCtxProfContext() =
default;
133 bool isRoot()
const {
return RootEntryCount.has_value(); }
140 "Functions are expected to have at their entry BB instrumented, so "
141 "there should always be at least 1 counter.");
156 "CSId was expected to be newly created as result of e.g. inlining");
162 return Callsites.find(
I) != Callsites.end();
167 return Callsites.find(
I)->second;
172 return Callsites.find(
I)->second;
178 template <
class TSetOfGUIDs>
181 for (
const auto &[
_, Callsite] : Callsites)
182 for (
const auto &[
_, Callee] : Callsite)
183 Callee.getContainedGuids(Guids);
188 std::map<GlobalValue::GUID, PGOCtxProfContext>;
203 Error readMetadata();
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static StringRef substr(StringRef Str, uint64_t Len)
This represents a position within a bitcode file, implemented on top of a SimpleBitstreamCursor.
Lightweight error class with error context and mandatory checking.
Tagged union holding either a T or a Error.
uint64_t GUID
Declare a type to represent a global unique identifier for a global value.
The instrumented contextual profile, produced by the CtxProfAnalysis.
A node (context) in the loaded contextual profile, suitable for mutation during IPO passes.
CallTargetMapTy & callsite(uint32_t I)
SmallVectorImpl< uint64_t > & counters()
bool hasCallsite(uint32_t I) const
void resizeCounters(uint32_t Size)
GlobalValue::GUID guid() const
void ingestAllContexts(uint32_t CSId, CallTargetMapTy &&Other)
void getContainedGuids(TSetOfGUIDs &Guids) const
Insert this node's GUID as well as the GUIDs of the transitive closure of child nodes,...
PGOCtxProfContext & operator=(const PGOCtxProfContext &)=delete
const CallTargetMapTy & callsite(uint32_t I) const
PGOCtxProfContext & operator=(PGOCtxProfContext &&)=delete
uint64_t getEntrycount() const
const SmallVectorImpl< uint64_t > & counters() const
std::map< uint32_t, CallTargetMapTy > CallsiteMapTy
const CtxProfFlatProfile & getUnhandled() const
void ingestContext(uint32_t CSId, PGOCtxProfContext &&Other)
CallsiteMapTy & callsites()
PGOCtxProfContext(const PGOCtxProfContext &)=delete
uint64_t getTotalRootEntryCount() const
PGOCtxProfContext(PGOCtxProfContext &&)=default
std::map< GlobalValue::GUID, PGOCtxProfContext > CallTargetMapTy
const CallsiteMapTy & callsites() const
LLVM_ABI Expected< PGOCtxProfile > loadProfiles()
PGOCtxProfileReader(StringRef Buffer)
Write one or more ContextNodes to the provided raw_fd_stream.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
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.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
This is an optimization pass for GlobalISel generic memory operations.
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
std::map< GlobalValue::GUID, PGOCtxProfContext > CtxProfContextualProfiles
std::map< GlobalValue::GUID, SmallVector< uint64_t, 1 > > CtxProfFlatProfile
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
LLVM_ABI void convertCtxProfToYaml(raw_ostream &OS, const PGOCtxProfile &Profile)
Implement std::hash so that hash_code can be used in STL containers.
PGOCtxProfile(PGOCtxProfile &&)=default
PGOCtxProfile & operator=(PGOCtxProfile &&)=default
CtxProfFlatProfile FlatProfiles
PGOCtxProfile(const PGOCtxProfile &)=delete
CtxProfContextualProfiles Contexts