Skip to content

[nfc][ctx_prof] Rename PGOContextualProfile to PGOCtxProfContext #102209

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 6, 2024

Conversation

mtrofin
Copy link
Member

@mtrofin mtrofin commented Aug 6, 2024

This better captures what the class is - just a node. The profile has a bit more info - for example, we can glean how many counters and callsites each captured function have. This is good information to have when maintaining the profile during ICP, and while it can be recomputed, it fits better (and avoids extra compute) under a to-be-introduced PGOContextualProfile - which is what loadContexts() will return (effectivelly today's map + the extra info)

This better captures what the class is - just a node. The profile has a
bit more info - for example, we can glean how many counters and callsites
each captured function have. This is good information to have when
maintaining the profile during ICP, and while it can be recomputed, it
fits better (and avoids extra compute) under a to-be-introduced
`PGOContextualProfile` - which is what `loadContexts()` will return
(effectivelly today's map + the extra info)
@llvmbot llvmbot added the PGO Profile Guided Optimizations label Aug 6, 2024
@llvmbot
Copy link
Member

llvmbot commented Aug 6, 2024

@llvm/pr-subscribers-pgo

Author: Mircea Trofin (mtrofin)

Changes

This better captures what the class is - just a node. The profile has a bit more info - for example, we can glean how many counters and callsites each captured function have. This is good information to have when maintaining the profile during ICP, and while it can be recomputed, it fits better (and avoids extra compute) under a to-be-introduced PGOContextualProfile - which is what loadContexts() will return (effectivelly today's map + the extra info)


Full diff: https://github.com/llvm/llvm-project/pull/102209.diff

3 Files Affected:

  • (modified) llvm/include/llvm/ProfileData/PGOCtxProfReader.h (+17-18)
  • (modified) llvm/lib/ProfileData/PGOCtxProfReader.cpp (+10-10)
  • (modified) llvm/unittests/ProfileData/PGOCtxProfReaderWriterTest.cpp (+1-1)
diff --git a/llvm/include/llvm/ProfileData/PGOCtxProfReader.h b/llvm/include/llvm/ProfileData/PGOCtxProfReader.h
index 28f05e9073a8af..b25bf7291c9dca 100644
--- a/llvm/include/llvm/ProfileData/PGOCtxProfReader.h
+++ b/llvm/include/llvm/ProfileData/PGOCtxProfReader.h
@@ -24,16 +24,16 @@
 #include <vector>
 
 namespace llvm {
-/// The loaded contextual profile, suitable for mutation during IPO passes. We
-/// generally expect a fraction of counters and of callsites to be populated.
-/// We continue to model counters as vectors, but callsites are modeled as a map
-/// of a map. The expectation is that, typically, there is a small number of
-/// indirect targets (usually, 1 for direct calls); but potentially a large
-/// number of callsites, and, as inlining progresses, the callsite count of a
-/// caller will grow.
-class PGOContextualProfile final {
+/// A node (context) in the loaded contextual profile, suitable for mutation
+/// during IPO passes. We generally expect a fraction of counters and of
+/// callsites to be populated. We continue to model counters as vectors, but
+/// callsites are modeled as a map of a map. The expectation is that, typically,
+/// there is a small number of indirect targets (usually, 1 for direct calls);
+/// but potentially a large number of callsites, and, as inlining progresses,
+/// the callsite count of a caller will grow.
+class PGOCtxProfContext final {
 public:
-  using CallTargetMapTy = std::map<GlobalValue::GUID, PGOContextualProfile>;
+  using CallTargetMapTy = std::map<GlobalValue::GUID, PGOCtxProfContext>;
   using CallsiteMapTy = DenseMap<uint32_t, CallTargetMapTy>;
 
 private:
@@ -42,19 +42,18 @@ class PGOContextualProfile final {
   SmallVector<uint64_t, 16> Counters;
   CallsiteMapTy Callsites;
 
-  PGOContextualProfile(GlobalValue::GUID G,
-                       SmallVectorImpl<uint64_t> &&Counters)
+  PGOCtxProfContext(GlobalValue::GUID G, SmallVectorImpl<uint64_t> &&Counters)
       : GUID(G), Counters(std::move(Counters)) {}
 
-  Expected<PGOContextualProfile &>
+  Expected<PGOCtxProfContext &>
   getOrEmplace(uint32_t Index, GlobalValue::GUID G,
                SmallVectorImpl<uint64_t> &&Counters);
 
 public:
-  PGOContextualProfile(const PGOContextualProfile &) = delete;
-  PGOContextualProfile &operator=(const PGOContextualProfile &) = delete;
-  PGOContextualProfile(PGOContextualProfile &&) = default;
-  PGOContextualProfile &operator=(PGOContextualProfile &&) = default;
+  PGOCtxProfContext(const PGOCtxProfContext &) = delete;
+  PGOCtxProfContext &operator=(const PGOCtxProfContext &) = delete;
+  PGOCtxProfContext(PGOCtxProfContext &&) = default;
+  PGOCtxProfContext &operator=(PGOCtxProfContext &&) = default;
 
   GlobalValue::GUID guid() const { return GUID; }
   const SmallVectorImpl<uint64_t> &counters() const { return Counters; }
@@ -80,7 +79,7 @@ class PGOCtxProfileReader final {
   Error wrongValue(const Twine &);
   Error unsupported(const Twine &);
 
-  Expected<std::pair<std::optional<uint32_t>, PGOContextualProfile>>
+  Expected<std::pair<std::optional<uint32_t>, PGOCtxProfContext>>
   readContext(bool ExpectIndex);
   bool canReadContext();
 
@@ -89,7 +88,7 @@ class PGOCtxProfileReader final {
       : Magic(Buffer.substr(0, PGOCtxProfileWriter::ContainerMagic.size())),
         Cursor(Buffer.substr(PGOCtxProfileWriter::ContainerMagic.size())) {}
 
-  Expected<std::map<GlobalValue::GUID, PGOContextualProfile>> loadContexts();
+  Expected<std::map<GlobalValue::GUID, PGOCtxProfContext>> loadContexts();
 };
 } // namespace llvm
 #endif
diff --git a/llvm/lib/ProfileData/PGOCtxProfReader.cpp b/llvm/lib/ProfileData/PGOCtxProfReader.cpp
index 0a0e7db457fa87..8354e30bd30679 100644
--- a/llvm/lib/ProfileData/PGOCtxProfReader.cpp
+++ b/llvm/lib/ProfileData/PGOCtxProfReader.cpp
@@ -33,18 +33,18 @@ using namespace llvm;
   if (auto Err = (EXPR))                                                       \
     return Err;
 
-Expected<PGOContextualProfile &>
-PGOContextualProfile::getOrEmplace(uint32_t Index, GlobalValue::GUID G,
-                                   SmallVectorImpl<uint64_t> &&Counters) {
-  auto [Iter, Inserted] = Callsites[Index].insert(
-      {G, PGOContextualProfile(G, std::move(Counters))});
+Expected<PGOCtxProfContext &>
+PGOCtxProfContext::getOrEmplace(uint32_t Index, GlobalValue::GUID G,
+                                SmallVectorImpl<uint64_t> &&Counters) {
+  auto [Iter, Inserted] =
+      Callsites[Index].insert({G, PGOCtxProfContext(G, std::move(Counters))});
   if (!Inserted)
     return make_error<InstrProfError>(instrprof_error::invalid_prof,
                                       "Duplicate GUID for same callsite.");
   return Iter->second;
 }
 
-void PGOContextualProfile::getContainedGuids(
+void PGOCtxProfContext::getContainedGuids(
     DenseSet<GlobalValue::GUID> &Guids) const {
   Guids.insert(GUID);
   for (const auto &[_, Callsite] : Callsites)
@@ -74,7 +74,7 @@ bool PGOCtxProfileReader::canReadContext() {
          Blk->ID == PGOCtxProfileBlockIDs::ContextNodeBlockID;
 }
 
-Expected<std::pair<std::optional<uint32_t>, PGOContextualProfile>>
+Expected<std::pair<std::optional<uint32_t>, PGOCtxProfContext>>
 PGOCtxProfileReader::readContext(bool ExpectIndex) {
   RET_ON_ERR(Cursor.EnterSubBlock(PGOCtxProfileBlockIDs::ContextNodeBlockID));
 
@@ -125,7 +125,7 @@ PGOCtxProfileReader::readContext(bool ExpectIndex) {
     }
   }
 
-  PGOContextualProfile Ret(*Guid, std::move(*Counters));
+  PGOCtxProfContext Ret(*Guid, std::move(*Counters));
 
   while (canReadContext()) {
     EXPECT_OR_RET(SC, readContext(true));
@@ -174,9 +174,9 @@ Error PGOCtxProfileReader::readMetadata() {
   return Error::success();
 }
 
-Expected<std::map<GlobalValue::GUID, PGOContextualProfile>>
+Expected<std::map<GlobalValue::GUID, PGOCtxProfContext>>
 PGOCtxProfileReader::loadContexts() {
-  std::map<GlobalValue::GUID, PGOContextualProfile> Ret;
+  std::map<GlobalValue::GUID, PGOCtxProfContext> Ret;
   RET_ON_ERR(readMetadata());
   while (canReadContext()) {
     EXPECT_OR_RET(E, readContext(false));
diff --git a/llvm/unittests/ProfileData/PGOCtxProfReaderWriterTest.cpp b/llvm/unittests/ProfileData/PGOCtxProfReaderWriterTest.cpp
index 476f293780d849..7be01445558eca 100644
--- a/llvm/unittests/ProfileData/PGOCtxProfReaderWriterTest.cpp
+++ b/llvm/unittests/ProfileData/PGOCtxProfReaderWriterTest.cpp
@@ -64,7 +64,7 @@ class PGOCtxProfRWTest : public ::testing::Test {
   const std::map<GUID, const ContextNode *> &roots() const { return Roots; }
 };
 
-void checkSame(const ContextNode &Raw, const PGOContextualProfile &Profile) {
+void checkSame(const ContextNode &Raw, const PGOCtxProfContext &Profile) {
   EXPECT_EQ(Raw.guid(), Profile.guid());
   ASSERT_EQ(Raw.counters_size(), Profile.counters().size());
   for (auto I = 0U; I < Raw.counters_size(); ++I)

Copy link
Contributor

@boomanaiden154 boomanaiden154 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor comments.

Not too familiar with this area of the code, but given it's a mechanical renaming, it should be fine.

@mtrofin mtrofin merged commit 6b47772 into llvm:main Aug 6, 2024
5 of 6 checks passed
@mtrofin mtrofin deleted the refactor branch August 6, 2024 22:27
@llvm-ci
Copy link
Collaborator

llvm-ci commented Aug 8, 2024

LLVM Buildbot has detected a new failure on builder llvm-clang-x86_64-expensive-checks-debian running on gribozavr4 while building llvm at step 6 "test-build-unified-tree-check-all".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/16/builds/3015

Here is the relevant piece of the build log for the reference:

Step 6 (test-build-unified-tree-check-all) failure: test (failure)
******************** TEST 'LLVM :: TableGen/SubtargetFeatureUniqueNames.td' FAILED ********************
Exit Code: 1

Command Output (stderr):
--
RUN: at line 1: not /b/1/llvm-clang-x86_64-expensive-checks-debian/build/bin/llvm-tblgen -gen-subtarget -I /b/1/llvm-clang-x86_64-expensive-checks-debian/llvm-project/llvm/test/TableGen/../../include /b/1/llvm-clang-x86_64-expensive-checks-debian/llvm-project/llvm/test/TableGen/SubtargetFeatureUniqueNames.td 2>&1 | /b/1/llvm-clang-x86_64-expensive-checks-debian/build/bin/FileCheck /b/1/llvm-clang-x86_64-expensive-checks-debian/llvm-project/llvm/test/TableGen/SubtargetFeatureUniqueNames.td -DFILE=/b/1/llvm-clang-x86_64-expensive-checks-debian/llvm-project/llvm/test/TableGen/SubtargetFeatureUniqueNames.td
+ not /b/1/llvm-clang-x86_64-expensive-checks-debian/build/bin/llvm-tblgen -gen-subtarget -I /b/1/llvm-clang-x86_64-expensive-checks-debian/llvm-project/llvm/test/TableGen/../../include /b/1/llvm-clang-x86_64-expensive-checks-debian/llvm-project/llvm/test/TableGen/SubtargetFeatureUniqueNames.td
+ /b/1/llvm-clang-x86_64-expensive-checks-debian/build/bin/FileCheck /b/1/llvm-clang-x86_64-expensive-checks-debian/llvm-project/llvm/test/TableGen/SubtargetFeatureUniqueNames.td -DFILE=/b/1/llvm-clang-x86_64-expensive-checks-debian/llvm-project/llvm/test/TableGen/SubtargetFeatureUniqueNames.td
/b/1/llvm-clang-x86_64-expensive-checks-debian/llvm-project/llvm/test/TableGen/SubtargetFeatureUniqueNames.td:10:11: error: CHECK: expected string not found in input
// CHECK: [[FILE]]:[[@LINE+2]]:5: error: Feature `NameA` already defined.
          ^
<stdin>:1:1: note: scanning from here
/b/1/llvm-clang-x86_64-expensive-checks-debian/llvm-project/llvm/test/TableGen/SubtargetFeatureUniqueNames.td:8:5: error: Feature `NameA` already defined.
^
<stdin>:1:1: note: with "FILE" equal to "/b/1/llvm-clang-x86_64-expensive-checks-debian/llvm-project/llvm/test/TableGen/SubtargetFeatureUniqueNames\\.td"
/b/1/llvm-clang-x86_64-expensive-checks-debian/llvm-project/llvm/test/TableGen/SubtargetFeatureUniqueNames.td:8:5: error: Feature `NameA` already defined.
^
<stdin>:1:1: note: with "@LINE+2" equal to "12"
/b/1/llvm-clang-x86_64-expensive-checks-debian/llvm-project/llvm/test/TableGen/SubtargetFeatureUniqueNames.td:8:5: error: Feature `NameA` already defined.
^
<stdin>:1:110: note: possible intended match here
/b/1/llvm-clang-x86_64-expensive-checks-debian/llvm-project/llvm/test/TableGen/SubtargetFeatureUniqueNames.td:8:5: error: Feature `NameA` already defined.
                                                                                                             ^

Input file: <stdin>
Check file: /b/1/llvm-clang-x86_64-expensive-checks-debian/llvm-project/llvm/test/TableGen/SubtargetFeatureUniqueNames.td

-dump-input=help explains the following input dump.

Input was:
<<<<<<
            1: /b/1/llvm-clang-x86_64-expensive-checks-debian/llvm-project/llvm/test/TableGen/SubtargetFeatureUniqueNames.td:8:5: error: Feature `NameA` already defined. 
check:10'0     X~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: no match found
check:10'1                                                                                                                                                                 with "FILE" equal to "/b/1/llvm-clang-x86_64-expensive-checks-debian/llvm-project/llvm/test/TableGen/SubtargetFeatureUniqueNames\\.td"
check:10'2                                                                                                                                                                 with "@LINE+2" equal to "12"
check:10'3                                                                                                                  ?                                              possible intended match
            2: def FeatureA : SubtargetFeature<"NameA", "", "", "">; 
check:10'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            3:  ^ 
check:10'0     ~~~
            4: /b/1/llvm-clang-x86_64-expensive-checks-debian/llvm-project/llvm/test/TableGen/SubtargetFeatureUniqueNames.td:12:5: note: Previous definition here. 
check:10'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            5: def FeatureB : SubtargetFeature<"NameA", "", "", "">; 
check:10'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            6:  ^ 
check:10'0     ~~~
>>>>>>

--

...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PGO Profile Guided Optimizations
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants