Skip to content
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
19 changes: 17 additions & 2 deletions llvm/include/llvm/ProfileData/MemProf.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef LLVM_PROFILEDATA_MEMPROF_H_
#define LLVM_PROFILEDATA_MEMPROF_H_

#include "llvm/ADT/BitVector.h"
#include "llvm/ADT/MapVector.h"
#include "llvm/ADT/STLForwardCompat.h"
#include "llvm/ADT/STLFunctionalExtras.h"
Expand Down Expand Up @@ -971,11 +972,16 @@ struct CallerCalleePairExtractor {
// A map from caller GUIDs to lists of call sites in respective callers.
DenseMap<uint64_t, SmallVector<CallEdgeTy, 0>> CallerCalleePairs;

// The set of linear call stack IDs that we've visited.
BitVector Visited;

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

void operator()(LinearCallStackId LinearCSId) {
const unsigned char *Ptr =
Expand Down Expand Up @@ -1004,6 +1010,15 @@ struct CallerCalleePairExtractor {
LineLocation Loc(F.LineOffset, F.Column);
CallerCalleePairs[CallerGUID].emplace_back(Loc, CalleeGUID);

// Keep track of the indices we've visited. If we've already visited the
// current one, terminate the traversal. We will not discover any new
// caller-callee pair by continuing the traversal.
unsigned Offset =
std::distance(CallStackBase, Ptr) / sizeof(LinearFrameId);
if (Visited.test(Offset))
break;
Visited.set(Offset);

Ptr += sizeof(LinearFrameId);
CalleeGUID = CallerGUID;
}
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 @@ -1678,7 +1678,8 @@ IndexedMemProfReader::getMemProfCallerCalleePairs() const {
assert(Version == memprof::Version3);

memprof::LinearFrameIdConverter FrameIdConv(FrameBase);
memprof::CallerCalleePairExtractor Extractor(CallStackBase, FrameIdConv);
memprof::CallerCalleePairExtractor Extractor(CallStackBase, FrameIdConv,
RadixTreeSize);

// The set of linear call stack IDs that we need to traverse from. We expect
// the set to be dense, so we use a BitVector.
Expand Down
Loading