Skip to content
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] Use llvm::function_ref instead of std::function #116306

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
14 changes: 8 additions & 6 deletions llvm/include/llvm/ProfileData/MemProf.h
Original file line number Diff line number Diff line change
Expand Up @@ -895,11 +895,12 @@ struct LinearFrameIdConverter {
// call stack array in the profile.
struct LinearCallStackIdConverter {
const unsigned char *CallStackBase;
std::function<Frame(LinearFrameId)> FrameIdToFrame;
llvm::function_ref<Frame(LinearFrameId)> FrameIdToFrame;

LinearCallStackIdConverter() = delete;
LinearCallStackIdConverter(const unsigned char *CallStackBase,
std::function<Frame(LinearFrameId)> FrameIdToFrame)
LinearCallStackIdConverter(
const unsigned char *CallStackBase,
llvm::function_ref<Frame(LinearFrameId)> FrameIdToFrame)
: CallStackBase(CallStackBase), FrameIdToFrame(FrameIdToFrame) {}

std::vector<Frame> operator()(LinearCallStackId LinearCSId) {
Expand Down Expand Up @@ -966,13 +967,14 @@ struct CallerCalleePairExtractor {
// The base address of the radix tree array.
const unsigned char *CallStackBase;
// A functor to convert a linear FrameId to a Frame.
std::function<Frame(LinearFrameId)> FrameIdToFrame;
llvm::function_ref<Frame(LinearFrameId)> FrameIdToFrame;
// A map from caller GUIDs to lists of call sites in respective callers.
DenseMap<uint64_t, SmallVector<CallEdgeTy, 0>> CallerCalleePairs;

CallerCalleePairExtractor() = delete;
CallerCalleePairExtractor(const unsigned char *CallStackBase,
std::function<Frame(LinearFrameId)> FrameIdToFrame)
CallerCalleePairExtractor(
const unsigned char *CallStackBase,
llvm::function_ref<Frame(LinearFrameId)> FrameIdToFrame)
: CallStackBase(CallStackBase), FrameIdToFrame(FrameIdToFrame) {}

void operator()(LinearCallStackId LinearCSId) {
Expand Down
3 changes: 2 additions & 1 deletion llvm/lib/ProfileData/InstrProfReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1688,10 +1688,11 @@ IndexedMemProfReader::getMemProfCallerCalleePairs() const {
// duplicates, we first collect them in the form of a bit vector before
// processing them.
for (const memprof::IndexedMemProfRecord &IndexedRecord :
MemProfRecordTable->data())
MemProfRecordTable->data()) {
for (const memprof::IndexedAllocationInfo &IndexedAI :
IndexedRecord.AllocSites)
Worklist.set(IndexedAI.CSId);
}

// Collect caller-callee pairs for each linear call stack ID in Worklist.
for (unsigned CS : Worklist.set_bits())
Expand Down
Loading