@@ -725,8 +725,7 @@ static uint64_t computeStackId(const memprof::Frame &Frame) {
725
725
726
726
// Helper to generate a single hash id for a given callstack, used for emitting
727
727
// matching statistics and useful for uniquing such statistics across modules.
728
- static uint64_t
729
- computeFullStackId (const std::vector<memprof::Frame> &CallStack) {
728
+ static uint64_t computeFullStackId (ArrayRef<Frame> CallStack) {
730
729
llvm::HashBuilder<llvm::TruncatedBLAKE3<8 >, llvm::endianness::little>
731
730
HashBuilder;
732
731
for (auto &F : CallStack)
@@ -763,9 +762,8 @@ static AllocationType addCallStack(CallStackTrie &AllocTrie,
763
762
// non-zero.
764
763
static bool
765
764
stackFrameIncludesInlinedCallStack (ArrayRef<Frame> ProfileCallStack,
766
- ArrayRef<uint64_t > InlinedCallStack,
767
- unsigned StartIndex = 0 ) {
768
- auto StackFrame = ProfileCallStack.begin () + StartIndex;
765
+ ArrayRef<uint64_t > InlinedCallStack) {
766
+ auto StackFrame = ProfileCallStack.begin ();
769
767
auto InlCallStackIter = InlinedCallStack.begin ();
770
768
for (; StackFrame != ProfileCallStack.end () &&
771
769
InlCallStackIter != InlinedCallStack.end ();
@@ -969,9 +967,15 @@ readMemprof(Module &M, Function &F, IndexedInstrProfReader *MemProfReader,
969
967
// Build maps of the location hash to all profile data with that leaf location
970
968
// (allocation info and the callsites).
971
969
std::map<uint64_t , std::set<const AllocationInfo *>> LocHashToAllocInfo;
972
- // For the callsites we need to record the index of the associated frame in
973
- // the frame array (see comments below where the map entries are added).
974
- std::map<uint64_t , std::set<std::pair<const std::vector<Frame> *, unsigned >>>
970
+ // A hash function for std::unordered_set<ArrayRef<Frame>> to work.
971
+ struct CallStackHash {
972
+ size_t operator ()(ArrayRef<Frame> CS) const {
973
+ return computeFullStackId (CS);
974
+ }
975
+ };
976
+ // For the callsites we need to record slices of the frame array (see comments
977
+ // below where the map entries are added).
978
+ std::map<uint64_t , std::unordered_set<ArrayRef<Frame>, CallStackHash>>
975
979
LocHashToCallSites;
976
980
for (auto &AI : MemProfRec->AllocSites ) {
977
981
NumOfMemProfAllocContextProfiles++;
@@ -989,7 +993,7 @@ readMemprof(Module &M, Function &F, IndexedInstrProfReader *MemProfReader,
989
993
unsigned Idx = 0 ;
990
994
for (auto &StackFrame : CS) {
991
995
uint64_t StackId = computeStackId (StackFrame);
992
- LocHashToCallSites[StackId].insert (std::make_pair (&CS, Idx++));
996
+ LocHashToCallSites[StackId].insert (ArrayRef<Frame>(CS). drop_front ( Idx++));
993
997
ProfileHasColumns |= StackFrame.Column ;
994
998
// Once we find this function, we can stop recording.
995
999
if (StackFrame.Function == FuncGUID)
@@ -1029,8 +1033,7 @@ readMemprof(Module &M, Function &F, IndexedInstrProfReader *MemProfReader,
1029
1033
// and another callsite).
1030
1034
std::map<uint64_t , std::set<const AllocationInfo *>>::iterator
1031
1035
AllocInfoIter;
1032
- std::map<uint64_t , std::set<std::pair<const std::vector<Frame> *,
1033
- unsigned >>>::iterator CallSitesIter;
1036
+ decltype (LocHashToCallSites)::iterator CallSitesIter;
1034
1037
for (const DILocation *DIL = I.getDebugLoc (); DIL != nullptr ;
1035
1038
DIL = DIL->getInlinedAt ()) {
1036
1039
// Use C++ linkage name if possible. Need to compile with
@@ -1121,8 +1124,8 @@ readMemprof(Module &M, Function &F, IndexedInstrProfReader *MemProfReader,
1121
1124
for (auto CallStackIdx : CallSitesIter->second ) {
1122
1125
// If we found and thus matched all frames on the call, create and
1123
1126
// attach call stack metadata.
1124
- if (stackFrameIncludesInlinedCallStack (
1125
- *CallStackIdx. first , InlinedCallStack, CallStackIdx. second )) {
1127
+ if (stackFrameIncludesInlinedCallStack (CallStackIdx,
1128
+ InlinedCallStack )) {
1126
1129
NumOfMemProfMatchedCallSites++;
1127
1130
addCallsiteMetadata (I, InlinedCallStack, Ctx);
1128
1131
// Only need to find one with a matching call stack and add a single
0 commit comments