Skip to content

Commit ebbdf03

Browse files
committed
Try to resolve Windows pre-commit failure. The CallSiteEntries were
passed using a std::unordered set, which defeated the MapVector's attempt at deterministic ordering. Change the unordered_set to a vector. In theory there should not be duplicated sets of call site frames within a function's profile, but even if there are, there's no harm as we only create callsite metadata for the first, and we want to include all callee guids anyway.
1 parent 2d8716d commit ebbdf03

File tree

2 files changed

+10
-26
lines changed

2 files changed

+10
-26
lines changed

llvm/lib/Transforms/Instrumentation/MemProfUse.cpp

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -504,29 +504,14 @@ struct CallSiteEntry {
504504
ArrayRef<Frame> Frames;
505505
// Potential targets for indirect calls.
506506
ArrayRef<GlobalValue::GUID> CalleeGuids;
507-
508-
// Only compare Frame contents.
509-
// Use pointer-based equality instead of ArrayRef's operator== which does
510-
// element-wise comparison. We want to check if it's the same slice of the
511-
// underlying array, not just equivalent content.
512-
bool operator==(const CallSiteEntry &Other) const {
513-
return Frames.data() == Other.Frames.data() &&
514-
Frames.size() == Other.Frames.size();
515-
}
516-
};
517-
518-
struct CallSiteEntryHash {
519-
size_t operator()(const CallSiteEntry &Entry) const {
520-
return computeFullStackId(Entry.Frames);
521-
}
522507
};
523508

524-
static void handleCallSite(
525-
Instruction &I, const Function *CalledFunction,
526-
ArrayRef<uint64_t> InlinedCallStack,
527-
const std::unordered_set<CallSiteEntry, CallSiteEntryHash> &CallSiteEntries,
528-
Module &M, std::set<std::vector<uint64_t>> &MatchedCallSites,
529-
OptimizationRemarkEmitter &ORE) {
509+
static void handleCallSite(Instruction &I, const Function *CalledFunction,
510+
ArrayRef<uint64_t> InlinedCallStack,
511+
const std::vector<CallSiteEntry> &CallSiteEntries,
512+
Module &M,
513+
std::set<std::vector<uint64_t>> &MatchedCallSites,
514+
OptimizationRemarkEmitter &ORE) {
530515
auto &Ctx = M.getContext();
531516
// Set of Callee GUIDs to attach to indirect calls. We accumulate all of them
532517
// to support cases where the instuction's inlined frames match multiple call
@@ -646,8 +631,7 @@ static void readMemprof(Module &M, Function &F,
646631

647632
// For the callsites we need to record slices of the frame array (see comments
648633
// below where the map entries are added) along with their CalleeGuids.
649-
std::map<uint64_t, std::unordered_set<CallSiteEntry, CallSiteEntryHash>>
650-
LocHashToCallSites;
634+
std::map<uint64_t, std::vector<CallSiteEntry>> LocHashToCallSites;
651635
for (auto &AI : MemProfRec->AllocSites) {
652636
NumOfMemProfAllocContextProfiles++;
653637
// Associate the allocation info with the leaf frame. The later matching
@@ -666,7 +650,7 @@ static void readMemprof(Module &M, Function &F,
666650
uint64_t StackId = computeStackId(StackFrame);
667651
ArrayRef<Frame> FrameSlice = ArrayRef<Frame>(CS.Frames).drop_front(Idx++);
668652
ArrayRef<GlobalValue::GUID> CalleeGuids(CS.CalleeGuids);
669-
LocHashToCallSites[StackId].insert({FrameSlice, CalleeGuids});
653+
LocHashToCallSites[StackId].push_back({FrameSlice, CalleeGuids});
670654

671655
ProfileHasColumns |= StackFrame.Column;
672656
// Once we find this function, we can stop recording.

llvm/test/Transforms/PGOProfile/memprof_annotate_indirect_call.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
;; Basic functionality with flag toggle
44
; RUN: llvm-profdata merge --memprof-version=4 %t/basic.yaml -o %t/basic.memprofdata
55
; RUN: opt < %t/basic.ll -passes='memprof-use<profile-filename=%t/basic.memprofdata>' -memprof-attach-calleeguids=false -S 2>&1 | FileCheck %s --check-prefix=CHECK-DISABLE
6-
; RUN: opt < %t/basic.ll -passes='memprof-use<profile-filename=%t/basic.memprofdata>' -memprof-attach-calleeguids=true -S 2>&1 | FileCheck %s --check-prefix=CHECK-ENABLE
6+
; RUN: opt < %t/basic.ll -passes='memprof-use<profile-filename=%t/basic.memprofdata>' -memprof-attach-calleeguids=true -S 2>&1 | FileCheck %s --check-prefix=CHECK-ENABLE --dump-input-filter=all
77

88
;; FDO conflict handling
99
; RUN: llvm-profdata merge --memprof-version=4 %t/fdo_conflict.yaml -o %t/fdo_conflict.memprofdata
@@ -43,7 +43,7 @@ entry:
4343
ret void
4444
}
4545

46-
; CHECK-ENABLE: !6 = !{!"VP", i32 0, i64 6, i64 13398, i64 1, i64 17767, i64 1, i64 4660, i64 1, i64 9029, i64 1, i64 1311768467463790320, i64 1, i64 2541551405711093505, i64 1}
46+
; CHECK-ENABLE: !6 = !{!"VP", i32 0, i64 6, i64 1311768467463790320, i64 1, i64 2541551405711093505, i64 1, i64 4660, i64 1, i64 9029, i64 1, i64 13398, i64 1, i64 17767, i64 1}
4747

4848
!llvm.module.flags = !{!2, !3}
4949

0 commit comments

Comments
 (0)