26#define EXPECT_OR_RET(LHS, RHS) \
29 return LHS.takeError();
31#define RET_ON_ERR(EXPR) \
32 if (auto Err = (EXPR)) \
42 "Duplicate GUID for same callsite.");
49 for (
const auto &[
_, Callsite] : Callsites)
50 for (
const auto &[
_, Callee] : Callsite)
51 Callee.getContainedGuids(Guids);
58Error PGOCtxProfileReader::wrongValue(
const Twine &Msg) {
62Error PGOCtxProfileReader::unsupported(
const Twine &Msg) {
66bool PGOCtxProfileReader::canReadContext() {
77PGOCtxProfileReader::readContext(
bool ExpectIndex) {
80 std::optional<ctx_profile::GUID>
Guid;
81 std::optional<SmallVector<uint64_t, 16>>
Counters;
82 std::optional<uint32_t> CallsiteIndex;
89 auto GotAllWeNeed = [&]() {
91 (!ExpectIndex || CallsiteIndex.has_value());
93 while (!GotAllWeNeed()) {
98 "Expected records before encountering more subcontexts");
101 switch (*ReadRecord) {
103 if (RecordValues.
size() != 1)
104 return wrongValue(
"The GUID record should have exactly one value");
105 Guid = RecordValues[0];
110 return wrongValue(
"Empty counters. At least the entry counter (one "
111 "value) was expected");
115 return wrongValue(
"The root context should not have a callee index");
116 if (RecordValues.
size() != 1)
117 return wrongValue(
"The callee index should have exactly one value");
118 CallsiteIndex = RecordValues[0];
129 while (canReadContext()) {
131 auto &Targets =
Ret.callsites()[*
SC->first];
133 Targets.insert({
SC->second.guid(), std::move(
SC->second)});
136 "Unexpected duplicate target (callee) at the same callsite.");
138 return std::make_pair(CallsiteIndex, std::move(Ret));
141Error PGOCtxProfileReader::readMetadata() {
144 return unsupported(
"Expected Version record");
149 return unsupported(
"Expected Version record");
154 return unsupported(
"Expected Version record");
156 return unsupported(
"Version " +
Twine(*Code) +
157 " is higher than supported version " +
164 std::map<GlobalValue::GUID, PGOContextualProfile> Ret;
166 while (canReadContext()) {
168 auto Key = E->second.guid();
169 if (!Ret.insert({Key, std::move(E->second)}).second)
170 return wrongValue(
"Duplicate roots");
172 return std::move(Ret);
#define EXPECT_OR_RET(LHS, RHS)
Reader for contextual iFDO profile, which comes in bitstream format.
@ AF_DontAutoprocessAbbrevs
If this flag is used, abbrev entries are returned just like normal records.
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.
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.
The loaded contextual profile, suitable for mutation during IPO passes.
void getContainedGuids(DenseSet< GlobalValue::GUID > &Guids) const
Expected< std::map< GlobalValue::GUID, PGOContextualProfile > > loadContexts()
static constexpr uint32_t CurrentVersion
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.
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.
This is an optimization pass for GlobalISel generic memory operations.
void consumeError(Error Err)
Consume a Error without doing anything.