Skip to content

[memprof] Add a new constructor to MemProfReader (NFC) #116918

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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions llvm/include/llvm/ProfileData/MemProfReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,24 @@ class MemProfReader {

// Initialize the MemProfReader with the frame mappings, call stack mappings,
// and profile contents.
LLVM_DEPRECATED("Construct MemProfReader with IndexedMemProfData",
"MemProfReader")
MemProfReader(
llvm::DenseMap<FrameId, Frame> FrameIdMap,
llvm::DenseMap<CallStackId, llvm::SmallVector<FrameId>> CSIdMap,
llvm::MapVector<GlobalValue::GUID, IndexedMemProfRecord> ProfData)
: IdToFrame(std::move(FrameIdMap)), CSIdToCallStack(std::move(CSIdMap)),
FunctionProfileData(std::move(ProfData)) {}

// Initialize the MemProfReader with the given MemProf profile.
MemProfReader(IndexedMemProfData MemProfData) {
for (const auto &[FrameId, F] : MemProfData.Frames)
IdToFrame.try_emplace(FrameId, F);
for (const auto &[CSId, CS] : MemProfData.CallStacks)
CSIdToCallStack.try_emplace(CSId, CS);
FunctionProfileData = std::move(MemProfData.Records);
}

protected:
// A helper method to extract the frame from the IdToFrame map.
const Frame &idToFrame(const FrameId Id) const {
Expand Down
14 changes: 6 additions & 8 deletions llvm/unittests/ProfileData/MemProfTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -490,30 +490,28 @@ TEST(MemProf, BaseMemProfReader) {
}

TEST(MemProf, BaseMemProfReaderWithCSIdMap) {
llvm::DenseMap<FrameId, Frame> FrameIdMap;
llvm::memprof::IndexedMemProfData MemProfData;
Frame F1(/*Hash=*/IndexedMemProfRecord::getGUID("foo"), /*LineOffset=*/20,
/*Column=*/5, /*IsInlineFrame=*/true);
Frame F2(/*Hash=*/IndexedMemProfRecord::getGUID("bar"), /*LineOffset=*/10,
/*Column=*/2, /*IsInlineFrame=*/false);
FrameIdMap.insert({F1.hash(), F1});
FrameIdMap.insert({F2.hash(), F2});
MemProfData.Frames.insert({F1.hash(), F1});
MemProfData.Frames.insert({F2.hash(), F2});

llvm::DenseMap<CallStackId, llvm::SmallVector<FrameId>> CSIdMap;
llvm::SmallVector<FrameId> CallStack = {F1.hash(), F2.hash()};
CallStackId CSId = llvm::memprof::hashCallStack(CallStack);
CSIdMap.insert({CSId, CallStack});
MemProfData.CallStacks.insert({CSId, CallStack});

llvm::MapVector<llvm::GlobalValue::GUID, IndexedMemProfRecord> ProfData;
IndexedMemProfRecord FakeRecord;
MemInfoBlock Block;
Block.AllocCount = 1U, Block.TotalAccessDensity = 4,
Block.TotalLifetime = 200001;
FakeRecord.AllocSites.emplace_back(
/*CSId=*/llvm::memprof::hashCallStack(CallStack),
/*MB=*/Block);
ProfData.insert({F1.hash(), FakeRecord});
MemProfData.Records.insert({F1.hash(), FakeRecord});

MemProfReader Reader(FrameIdMap, CSIdMap, ProfData);
MemProfReader Reader(MemProfData);

llvm::SmallVector<MemProfRecord, 1> Records;
for (const auto &KeyRecordPair : Reader) {
Expand Down
Loading