27#define EXPECT_OR_RET(LHS, RHS) \
30 return LHS.takeError();
32#define RET_ON_ERR(EXPR) \
33 if (auto Err = (EXPR)) \
39 auto [Iter, Inserted] =
43 "Duplicate GUID for same callsite.");
50 for (
const auto &[
_, Callsite] : Callsites)
51 for (
const auto &[
_, Callee] : Callsite)
52 Callee.getContainedGuids(Guids);
59Error PGOCtxProfileReader::wrongValue(
const Twine &Msg) {
63Error PGOCtxProfileReader::unsupported(
const Twine &Msg) {
67bool PGOCtxProfileReader::canReadContext() {
78PGOCtxProfileReader::readContext(
bool ExpectIndex) {
81 std::optional<ctx_profile::GUID>
Guid;
82 std::optional<SmallVector<uint64_t, 16>>
Counters;
83 std::optional<uint32_t> CallsiteIndex;
90 auto GotAllWeNeed = [&]() {
92 (!ExpectIndex || CallsiteIndex.has_value());
94 while (!GotAllWeNeed()) {
99 "Expected records before encountering more subcontexts");
102 switch (*ReadRecord) {
104 if (RecordValues.
size() != 1)
105 return wrongValue(
"The GUID record should have exactly one value");
106 Guid = RecordValues[0];
111 return wrongValue(
"Empty counters. At least the entry counter (one "
112 "value) was expected");
116 return wrongValue(
"The root context should not have a callee index");
117 if (RecordValues.
size() != 1)
118 return wrongValue(
"The callee index should have exactly one value");
119 CallsiteIndex = RecordValues[0];
130 while (canReadContext()) {
132 auto &Targets =
Ret.callsites()[*
SC->first];
134 Targets.insert({
SC->second.guid(), std::move(
SC->second)});
137 "Unexpected duplicate target (callee) at the same callsite.");
139 return std::make_pair(CallsiteIndex, std::move(Ret));
142Error PGOCtxProfileReader::readMetadata() {
152 return unsupported(
"Expected Block ID");
159 return unsupported(
"Expected Version record");
164 return unsupported(
"Expected Version record");
169 return unsupported(
"Expected Version record");
171 return unsupported(
"Version " +
Twine(*Code) +
172 " is higher than supported version " +
179 std::map<GlobalValue::GUID, PGOCtxProfContext> Ret;
181 while (canReadContext()) {
183 auto Key = E->second.guid();
184 if (!Ret.insert({Key, std::move(E->second)}).second)
185 return wrongValue(
"Duplicate roots");
187 return std::move(Ret);
#define EXPECT_OR_RET(LHS, RHS)
Reader for contextual iFDO profile, which comes in bitstream format.
Expected< BitstreamEntry > advance(unsigned Flags=0)
Advance the current bitstream, returning the next entry in the stream.
Expected< unsigned > readRecord(unsigned AbbrevID, SmallVectorImpl< uint64_t > &Vals, StringRef *Blob=nullptr)
Error EnterSubBlock(unsigned BlockID, unsigned *NumWordsP=nullptr)
Having read the ENTER_SUBBLOCK abbrevid, and enter the block.
@ AF_DontAutoprocessAbbrevs
If this flag is used, abbrev entries are returned just like normal records.
Error SkipBlock()
Having read the ENTER_SUBBLOCK abbrevid and a BlockID, skip over the body of this block.
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Implements a dense probed hash-table based set.
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
Tagged union holding either a T or a Error.
A node (context) in the loaded contextual profile, suitable for mutation during IPO passes.
void getContainedGuids(DenseSet< GlobalValue::GUID > &Guids) const
Expected< std::map< GlobalValue::GUID, PGOCtxProfContext > > loadContexts()
static constexpr uint32_t CurrentVersion
static constexpr StringRef ContainerMagic
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.
constexpr size_t size() const
size - Get the string size.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
std::pair< iterator, bool > insert(const ValueT &V)
@ SC
CHAIN = SC CHAIN, Imm128 - System call.
@ BLOCKINFO_BLOCK_ID
BLOCKINFO_BLOCK is used to define metadata about blocks, for example, standard abbrevs that should be...
This is an optimization pass for GlobalISel generic memory operations.
void consumeError(Error Err)
Consume a Error without doing anything.
When advancing through a bitstream cursor, each advance can discover a few different kinds of entries...