-
Notifications
You must be signed in to change notification settings - Fork 10.9k
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
[memprof] Move getFullSchema and getHotColdSchema outside PortableMemInfoBlock #90103
[memprof] Move getFullSchema and getHotColdSchema outside PortableMemInfoBlock #90103
Conversation
…InfoBlock These functions do not operate on PortableMemInfoBlock. This patch moves them outside the class.
@llvm/pr-subscribers-pgo Author: Kazu Hirata (kazutakahirata) ChangesThese functions do not operate on PortableMemInfoBlock. This patch Full diff: https://github.com/llvm/llvm-project/pull/90103.diff 4 Files Affected:
diff --git a/llvm/include/llvm/ProfileData/MemProf.h b/llvm/include/llvm/ProfileData/MemProf.h
index a8e98f8bb13861..c5585e4e06af5f 100644
--- a/llvm/include/llvm/ProfileData/MemProf.h
+++ b/llvm/include/llvm/ProfileData/MemProf.h
@@ -44,6 +44,13 @@ enum class Meta : uint64_t {
using MemProfSchema = llvm::SmallVector<Meta, static_cast<int>(Meta::Size)>;
+// Returns the full schema currently in use.
+MemProfSchema getFullSchema();
+
+// Returns the schema consisting of the fields currently consumed by the
+// compiler.
+MemProfSchema getHotColdSchema();
+
// Holds the actual MemInfoBlock data with all fields. Contents may be read or
// written partially by providing an appropriate schema to the serialize and
// deserialize methods.
@@ -116,22 +123,6 @@ struct PortableMemInfoBlock {
void clear() { *this = PortableMemInfoBlock(); }
- // Returns the full schema currently in use.
- static MemProfSchema getFullSchema() {
- MemProfSchema List;
-#define MIBEntryDef(NameTag, Name, Type) List.push_back(Meta::Name);
-#include "llvm/ProfileData/MIBEntryDef.inc"
-#undef MIBEntryDef
- return List;
- }
-
- // Returns the schema consisting of the fields currently consumed by the
- // compiler.
- static MemProfSchema getHotColdSchema() {
- return {Meta::AllocCount, Meta::TotalSize, Meta::TotalLifetime,
- Meta::TotalLifetimeAccessDensity};
- }
-
bool operator==(const PortableMemInfoBlock &Other) const {
#define MIBEntryDef(NameTag, Name, Type) \
if (Other.get##Name() != get##Name()) \
diff --git a/llvm/lib/ProfileData/InstrProfWriter.cpp b/llvm/lib/ProfileData/InstrProfWriter.cpp
index 70ae57f77daef7..e1846fcbffee52 100644
--- a/llvm/lib/ProfileData/InstrProfWriter.cpp
+++ b/llvm/lib/ProfileData/InstrProfWriter.cpp
@@ -508,7 +508,7 @@ static Error writeMemProfV0(
OS.write(0ULL); // Reserve space for the memprof frame payload offset.
OS.write(0ULL); // Reserve space for the memprof frame table offset.
- auto Schema = memprof::PortableMemInfoBlock::getFullSchema();
+ auto Schema = memprof::getFullSchema();
writeMemProfSchema(OS, Schema);
uint64_t RecordTableOffset =
@@ -534,7 +534,7 @@ static Error writeMemProfV1(
OS.write(0ULL); // Reserve space for the memprof frame payload offset.
OS.write(0ULL); // Reserve space for the memprof frame table offset.
- auto Schema = memprof::PortableMemInfoBlock::getFullSchema();
+ auto Schema = memprof::getFullSchema();
writeMemProfSchema(OS, Schema);
uint64_t RecordTableOffset =
@@ -565,9 +565,9 @@ static Error writeMemProfV2(
OS.write(0ULL); // Reserve space for the memprof call stack payload offset.
OS.write(0ULL); // Reserve space for the memprof call stack table offset.
- auto Schema = memprof::PortableMemInfoBlock::getHotColdSchema();
+ auto Schema = memprof::getHotColdSchema();
if (MemProfFullSchema)
- Schema = memprof::PortableMemInfoBlock::getFullSchema();
+ Schema = memprof::getFullSchema();
writeMemProfSchema(OS, Schema);
uint64_t RecordTableOffset =
diff --git a/llvm/lib/ProfileData/MemProf.cpp b/llvm/lib/ProfileData/MemProf.cpp
index 9a46d1151311f4..4667778ca11dd0 100644
--- a/llvm/lib/ProfileData/MemProf.cpp
+++ b/llvm/lib/ProfileData/MemProf.cpp
@@ -10,6 +10,19 @@
namespace llvm {
namespace memprof {
+MemProfSchema getFullSchema() {
+ MemProfSchema List;
+#define MIBEntryDef(NameTag, Name, Type) List.push_back(Meta::Name);
+#include "llvm/ProfileData/MIBEntryDef.inc"
+#undef MIBEntryDef
+ return List;
+}
+
+MemProfSchema getHotColdSchema() {
+ return {Meta::AllocCount, Meta::TotalSize, Meta::TotalLifetime,
+ Meta::TotalLifetimeAccessDensity};
+}
+
static size_t serializedSizeV0(const IndexedAllocationInfo &IAI,
const MemProfSchema &Schema) {
size_t Size = 0;
diff --git a/llvm/unittests/ProfileData/MemProfTest.cpp b/llvm/unittests/ProfileData/MemProfTest.cpp
index 5e72b3a11f8ed2..503901094ba9a5 100644
--- a/llvm/unittests/ProfileData/MemProfTest.cpp
+++ b/llvm/unittests/ProfileData/MemProfTest.cpp
@@ -240,7 +240,7 @@ TEST(MemProf, PortableWrapper) {
/*dealloc_timestamp=*/2000, /*alloc_cpu=*/3,
/*dealloc_cpu=*/4);
- const auto Schema = llvm::memprof::PortableMemInfoBlock::getFullSchema();
+ const auto Schema = llvm::memprof::getFullSchema();
PortableMemInfoBlock WriteBlock(Info);
std::string Buffer;
@@ -263,7 +263,7 @@ TEST(MemProf, PortableWrapper) {
// Version0 and Version1 serialize IndexedMemProfRecord in the same format, so
// we share one test.
TEST(MemProf, RecordSerializationRoundTripVersion0And1) {
- const auto Schema = llvm::memprof::PortableMemInfoBlock::getFullSchema();
+ const auto Schema = llvm::memprof::getFullSchema();
MemInfoBlock Info(/*size=*/16, /*access_count=*/7, /*alloc_timestamp=*/1000,
/*dealloc_timestamp=*/2000, /*alloc_cpu=*/3,
@@ -297,7 +297,7 @@ TEST(MemProf, RecordSerializationRoundTripVersion0And1) {
}
TEST(MemProf, RecordSerializationRoundTripVerion2) {
- const auto Schema = llvm::memprof::PortableMemInfoBlock::getFullSchema();
+ const auto Schema = llvm::memprof::getFullSchema();
MemInfoBlock Info(/*size=*/16, /*access_count=*/7, /*alloc_timestamp=*/1000,
/*dealloc_timestamp=*/2000, /*alloc_cpu=*/3,
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
// Returns the full schema currently in use. | ||
MemProfSchema getFullSchema(); | ||
|
||
// Returns the schema consisting of the fields currently consumed by the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets make this comment a little more future proof, how about "Returns the schema consisting of the fields used for hot cold memory hinting."
These functions do not operate on PortableMemInfoBlock. This patch
moves them outside the class.