Skip to content

Commit ec353b7

Browse files
[memprof] Use llvm::function_ref instead of std::function (#116306)
We've seen bugs where we lost track of error states stored in the functor because we passed the functor by value (that is, std::function) as opposed to reference (llvm::function_ref). This patch fixes a couple of places we pass functors by value. While we are at it, this patch adds curly braces around a "for" loop spanning multiple lines.
1 parent 3734e4c commit ec353b7

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

llvm/include/llvm/ProfileData/MemProf.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -895,11 +895,12 @@ struct LinearFrameIdConverter {
895895
// call stack array in the profile.
896896
struct LinearCallStackIdConverter {
897897
const unsigned char *CallStackBase;
898-
std::function<Frame(LinearFrameId)> FrameIdToFrame;
898+
llvm::function_ref<Frame(LinearFrameId)> FrameIdToFrame;
899899

900900
LinearCallStackIdConverter() = delete;
901-
LinearCallStackIdConverter(const unsigned char *CallStackBase,
902-
std::function<Frame(LinearFrameId)> FrameIdToFrame)
901+
LinearCallStackIdConverter(
902+
const unsigned char *CallStackBase,
903+
llvm::function_ref<Frame(LinearFrameId)> FrameIdToFrame)
903904
: CallStackBase(CallStackBase), FrameIdToFrame(FrameIdToFrame) {}
904905

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

973974
CallerCalleePairExtractor() = delete;
974-
CallerCalleePairExtractor(const unsigned char *CallStackBase,
975-
std::function<Frame(LinearFrameId)> FrameIdToFrame)
975+
CallerCalleePairExtractor(
976+
const unsigned char *CallStackBase,
977+
llvm::function_ref<Frame(LinearFrameId)> FrameIdToFrame)
976978
: CallStackBase(CallStackBase), FrameIdToFrame(FrameIdToFrame) {}
977979

978980
void operator()(LinearCallStackId LinearCSId) {

llvm/lib/ProfileData/InstrProfReader.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1688,10 +1688,11 @@ IndexedMemProfReader::getMemProfCallerCalleePairs() const {
16881688
// duplicates, we first collect them in the form of a bit vector before
16891689
// processing them.
16901690
for (const memprof::IndexedMemProfRecord &IndexedRecord :
1691-
MemProfRecordTable->data())
1691+
MemProfRecordTable->data()) {
16921692
for (const memprof::IndexedAllocationInfo &IndexedAI :
16931693
IndexedRecord.AllocSites)
16941694
Worklist.set(IndexedAI.CSId);
1695+
}
16951696

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

0 commit comments

Comments
 (0)