Skip to content

Commit 6b47772

Browse files
authored
[nfc][ctx_prof] Rename PGOContextualProfile to PGOCtxProfContext (#102209)
1 parent 4c97c52 commit 6b47772

File tree

3 files changed

+28
-29
lines changed

3 files changed

+28
-29
lines changed

llvm/include/llvm/ProfileData/PGOCtxProfReader.h

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,16 @@
2424
#include <vector>
2525

2626
namespace llvm {
27-
/// The loaded contextual profile, suitable for mutation during IPO passes. We
28-
/// generally expect a fraction of counters and of callsites to be populated.
29-
/// We continue to model counters as vectors, but callsites are modeled as a map
30-
/// of a map. The expectation is that, typically, there is a small number of
31-
/// indirect targets (usually, 1 for direct calls); but potentially a large
32-
/// number of callsites, and, as inlining progresses, the callsite count of a
33-
/// caller will grow.
34-
class PGOContextualProfile final {
27+
/// A node (context) in the loaded contextual profile, suitable for mutation
28+
/// during IPO passes. We generally expect a fraction of counters and
29+
/// callsites to be populated. We continue to model counters as vectors, but
30+
/// callsites are modeled as a map of a map. The expectation is that, typically,
31+
/// there is a small number of indirect targets (usually, 1 for direct calls);
32+
/// but potentially a large number of callsites, and, as inlining progresses,
33+
/// the callsite count of a caller will grow.
34+
class PGOCtxProfContext final {
3535
public:
36-
using CallTargetMapTy = std::map<GlobalValue::GUID, PGOContextualProfile>;
36+
using CallTargetMapTy = std::map<GlobalValue::GUID, PGOCtxProfContext>;
3737
using CallsiteMapTy = DenseMap<uint32_t, CallTargetMapTy>;
3838

3939
private:
@@ -42,19 +42,18 @@ class PGOContextualProfile final {
4242
SmallVector<uint64_t, 16> Counters;
4343
CallsiteMapTy Callsites;
4444

45-
PGOContextualProfile(GlobalValue::GUID G,
46-
SmallVectorImpl<uint64_t> &&Counters)
45+
PGOCtxProfContext(GlobalValue::GUID G, SmallVectorImpl<uint64_t> &&Counters)
4746
: GUID(G), Counters(std::move(Counters)) {}
4847

49-
Expected<PGOContextualProfile &>
48+
Expected<PGOCtxProfContext &>
5049
getOrEmplace(uint32_t Index, GlobalValue::GUID G,
5150
SmallVectorImpl<uint64_t> &&Counters);
5251

5352
public:
54-
PGOContextualProfile(const PGOContextualProfile &) = delete;
55-
PGOContextualProfile &operator=(const PGOContextualProfile &) = delete;
56-
PGOContextualProfile(PGOContextualProfile &&) = default;
57-
PGOContextualProfile &operator=(PGOContextualProfile &&) = default;
53+
PGOCtxProfContext(const PGOCtxProfContext &) = delete;
54+
PGOCtxProfContext &operator=(const PGOCtxProfContext &) = delete;
55+
PGOCtxProfContext(PGOCtxProfContext &&) = default;
56+
PGOCtxProfContext &operator=(PGOCtxProfContext &&) = default;
5857

5958
GlobalValue::GUID guid() const { return GUID; }
6059
const SmallVectorImpl<uint64_t> &counters() const { return Counters; }
@@ -80,7 +79,7 @@ class PGOCtxProfileReader final {
8079
Error wrongValue(const Twine &);
8180
Error unsupported(const Twine &);
8281

83-
Expected<std::pair<std::optional<uint32_t>, PGOContextualProfile>>
82+
Expected<std::pair<std::optional<uint32_t>, PGOCtxProfContext>>
8483
readContext(bool ExpectIndex);
8584
bool canReadContext();
8685

@@ -89,7 +88,7 @@ class PGOCtxProfileReader final {
8988
: Magic(Buffer.substr(0, PGOCtxProfileWriter::ContainerMagic.size())),
9089
Cursor(Buffer.substr(PGOCtxProfileWriter::ContainerMagic.size())) {}
9190

92-
Expected<std::map<GlobalValue::GUID, PGOContextualProfile>> loadContexts();
91+
Expected<std::map<GlobalValue::GUID, PGOCtxProfContext>> loadContexts();
9392
};
9493
} // namespace llvm
9594
#endif

llvm/lib/ProfileData/PGOCtxProfReader.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,18 @@ using namespace llvm;
3333
if (auto Err = (EXPR)) \
3434
return Err;
3535

36-
Expected<PGOContextualProfile &>
37-
PGOContextualProfile::getOrEmplace(uint32_t Index, GlobalValue::GUID G,
38-
SmallVectorImpl<uint64_t> &&Counters) {
39-
auto [Iter, Inserted] = Callsites[Index].insert(
40-
{G, PGOContextualProfile(G, std::move(Counters))});
36+
Expected<PGOCtxProfContext &>
37+
PGOCtxProfContext::getOrEmplace(uint32_t Index, GlobalValue::GUID G,
38+
SmallVectorImpl<uint64_t> &&Counters) {
39+
auto [Iter, Inserted] =
40+
Callsites[Index].insert({G, PGOCtxProfContext(G, std::move(Counters))});
4141
if (!Inserted)
4242
return make_error<InstrProfError>(instrprof_error::invalid_prof,
4343
"Duplicate GUID for same callsite.");
4444
return Iter->second;
4545
}
4646

47-
void PGOContextualProfile::getContainedGuids(
47+
void PGOCtxProfContext::getContainedGuids(
4848
DenseSet<GlobalValue::GUID> &Guids) const {
4949
Guids.insert(GUID);
5050
for (const auto &[_, Callsite] : Callsites)
@@ -74,7 +74,7 @@ bool PGOCtxProfileReader::canReadContext() {
7474
Blk->ID == PGOCtxProfileBlockIDs::ContextNodeBlockID;
7575
}
7676

77-
Expected<std::pair<std::optional<uint32_t>, PGOContextualProfile>>
77+
Expected<std::pair<std::optional<uint32_t>, PGOCtxProfContext>>
7878
PGOCtxProfileReader::readContext(bool ExpectIndex) {
7979
RET_ON_ERR(Cursor.EnterSubBlock(PGOCtxProfileBlockIDs::ContextNodeBlockID));
8080

@@ -125,7 +125,7 @@ PGOCtxProfileReader::readContext(bool ExpectIndex) {
125125
}
126126
}
127127

128-
PGOContextualProfile Ret(*Guid, std::move(*Counters));
128+
PGOCtxProfContext Ret(*Guid, std::move(*Counters));
129129

130130
while (canReadContext()) {
131131
EXPECT_OR_RET(SC, readContext(true));
@@ -174,9 +174,9 @@ Error PGOCtxProfileReader::readMetadata() {
174174
return Error::success();
175175
}
176176

177-
Expected<std::map<GlobalValue::GUID, PGOContextualProfile>>
177+
Expected<std::map<GlobalValue::GUID, PGOCtxProfContext>>
178178
PGOCtxProfileReader::loadContexts() {
179-
std::map<GlobalValue::GUID, PGOContextualProfile> Ret;
179+
std::map<GlobalValue::GUID, PGOCtxProfContext> Ret;
180180
RET_ON_ERR(readMetadata());
181181
while (canReadContext()) {
182182
EXPECT_OR_RET(E, readContext(false));

llvm/unittests/ProfileData/PGOCtxProfReaderWriterTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class PGOCtxProfRWTest : public ::testing::Test {
6464
const std::map<GUID, const ContextNode *> &roots() const { return Roots; }
6565
};
6666

67-
void checkSame(const ContextNode &Raw, const PGOContextualProfile &Profile) {
67+
void checkSame(const ContextNode &Raw, const PGOCtxProfContext &Profile) {
6868
EXPECT_EQ(Raw.guid(), Profile.guid());
6969
ASSERT_EQ(Raw.counters_size(), Profile.counters().size());
7070
for (auto I = 0U; I < Raw.counters_size(); ++I)

0 commit comments

Comments
 (0)