Skip to content

Commit cb9589b

Browse files
[memprof] Move getFullSchema and getHotColdSchema outside PortableMemInfoBlock (llvm#90103)
These functions do not operate on PortableMemInfoBlock. This patch moves them outside the class.
1 parent f72611b commit cb9589b

File tree

4 files changed

+26
-23
lines changed

4 files changed

+26
-23
lines changed

llvm/include/llvm/ProfileData/MemProf.h

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ enum class Meta : uint64_t {
4444

4545
using MemProfSchema = llvm::SmallVector<Meta, static_cast<int>(Meta::Size)>;
4646

47+
// Returns the full schema currently in use.
48+
MemProfSchema getFullSchema();
49+
50+
// Returns the schema consisting of the fields used for hot cold memory hinting.
51+
MemProfSchema getHotColdSchema();
52+
4753
// Holds the actual MemInfoBlock data with all fields. Contents may be read or
4854
// written partially by providing an appropriate schema to the serialize and
4955
// deserialize methods.
@@ -116,22 +122,6 @@ struct PortableMemInfoBlock {
116122

117123
void clear() { *this = PortableMemInfoBlock(); }
118124

119-
// Returns the full schema currently in use.
120-
static MemProfSchema getFullSchema() {
121-
MemProfSchema List;
122-
#define MIBEntryDef(NameTag, Name, Type) List.push_back(Meta::Name);
123-
#include "llvm/ProfileData/MIBEntryDef.inc"
124-
#undef MIBEntryDef
125-
return List;
126-
}
127-
128-
// Returns the schema consisting of the fields currently consumed by the
129-
// compiler.
130-
static MemProfSchema getHotColdSchema() {
131-
return {Meta::AllocCount, Meta::TotalSize, Meta::TotalLifetime,
132-
Meta::TotalLifetimeAccessDensity};
133-
}
134-
135125
bool operator==(const PortableMemInfoBlock &Other) const {
136126
#define MIBEntryDef(NameTag, Name, Type) \
137127
if (Other.get##Name() != get##Name()) \

llvm/lib/ProfileData/InstrProfWriter.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ static Error writeMemProfV0(
508508
OS.write(0ULL); // Reserve space for the memprof frame payload offset.
509509
OS.write(0ULL); // Reserve space for the memprof frame table offset.
510510

511-
auto Schema = memprof::PortableMemInfoBlock::getFullSchema();
511+
auto Schema = memprof::getFullSchema();
512512
writeMemProfSchema(OS, Schema);
513513

514514
uint64_t RecordTableOffset =
@@ -534,7 +534,7 @@ static Error writeMemProfV1(
534534
OS.write(0ULL); // Reserve space for the memprof frame payload offset.
535535
OS.write(0ULL); // Reserve space for the memprof frame table offset.
536536

537-
auto Schema = memprof::PortableMemInfoBlock::getFullSchema();
537+
auto Schema = memprof::getFullSchema();
538538
writeMemProfSchema(OS, Schema);
539539

540540
uint64_t RecordTableOffset =
@@ -565,9 +565,9 @@ static Error writeMemProfV2(
565565
OS.write(0ULL); // Reserve space for the memprof call stack payload offset.
566566
OS.write(0ULL); // Reserve space for the memprof call stack table offset.
567567

568-
auto Schema = memprof::PortableMemInfoBlock::getHotColdSchema();
568+
auto Schema = memprof::getHotColdSchema();
569569
if (MemProfFullSchema)
570-
Schema = memprof::PortableMemInfoBlock::getFullSchema();
570+
Schema = memprof::getFullSchema();
571571
writeMemProfSchema(OS, Schema);
572572

573573
uint64_t RecordTableOffset =

llvm/lib/ProfileData/MemProf.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,19 @@
1010

1111
namespace llvm {
1212
namespace memprof {
13+
MemProfSchema getFullSchema() {
14+
MemProfSchema List;
15+
#define MIBEntryDef(NameTag, Name, Type) List.push_back(Meta::Name);
16+
#include "llvm/ProfileData/MIBEntryDef.inc"
17+
#undef MIBEntryDef
18+
return List;
19+
}
20+
21+
MemProfSchema getHotColdSchema() {
22+
return {Meta::AllocCount, Meta::TotalSize, Meta::TotalLifetime,
23+
Meta::TotalLifetimeAccessDensity};
24+
}
25+
1326
static size_t serializedSizeV0(const IndexedAllocationInfo &IAI,
1427
const MemProfSchema &Schema) {
1528
size_t Size = 0;

llvm/unittests/ProfileData/MemProfTest.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ TEST(MemProf, PortableWrapper) {
240240
/*dealloc_timestamp=*/2000, /*alloc_cpu=*/3,
241241
/*dealloc_cpu=*/4);
242242

243-
const auto Schema = llvm::memprof::PortableMemInfoBlock::getFullSchema();
243+
const auto Schema = llvm::memprof::getFullSchema();
244244
PortableMemInfoBlock WriteBlock(Info);
245245

246246
std::string Buffer;
@@ -263,7 +263,7 @@ TEST(MemProf, PortableWrapper) {
263263
// Version0 and Version1 serialize IndexedMemProfRecord in the same format, so
264264
// we share one test.
265265
TEST(MemProf, RecordSerializationRoundTripVersion0And1) {
266-
const auto Schema = llvm::memprof::PortableMemInfoBlock::getFullSchema();
266+
const auto Schema = llvm::memprof::getFullSchema();
267267

268268
MemInfoBlock Info(/*size=*/16, /*access_count=*/7, /*alloc_timestamp=*/1000,
269269
/*dealloc_timestamp=*/2000, /*alloc_cpu=*/3,
@@ -297,7 +297,7 @@ TEST(MemProf, RecordSerializationRoundTripVersion0And1) {
297297
}
298298

299299
TEST(MemProf, RecordSerializationRoundTripVerion2) {
300-
const auto Schema = llvm::memprof::PortableMemInfoBlock::getFullSchema();
300+
const auto Schema = llvm::memprof::getFullSchema();
301301

302302
MemInfoBlock Info(/*size=*/16, /*access_count=*/7, /*alloc_timestamp=*/1000,
303303
/*dealloc_timestamp=*/2000, /*alloc_cpu=*/3,

0 commit comments

Comments
 (0)