Skip to content

Commit 8846013

Browse files
[memprof] Use llvm::equal in stackFrameIncludesInlinedCallStack (NFC) (llvm#129372)
llvm::equal hides all the iterator manipulation behind the scenes while reducing the line count.
1 parent 70f4e6a commit 8846013

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

llvm/lib/Transforms/Instrumentation/MemProfiler.cpp

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -771,23 +771,15 @@ static AllocationType addCallStack(CallStackTrie &AllocTrie,
771771

772772
// Helper to compare the InlinedCallStack computed from an instruction's debug
773773
// info to a list of Frames from profile data (either the allocation data or a
774-
// callsite). For callsites, the StartIndex to use in the Frame array may be
775-
// non-zero.
774+
// callsite).
776775
static bool
777776
stackFrameIncludesInlinedCallStack(ArrayRef<Frame> ProfileCallStack,
778777
ArrayRef<uint64_t> InlinedCallStack) {
779-
auto StackFrame = ProfileCallStack.begin();
780-
auto InlCallStackIter = InlinedCallStack.begin();
781-
for (; StackFrame != ProfileCallStack.end() &&
782-
InlCallStackIter != InlinedCallStack.end();
783-
++StackFrame, ++InlCallStackIter) {
784-
uint64_t StackId = computeStackId(*StackFrame);
785-
if (StackId != *InlCallStackIter)
786-
return false;
787-
}
788-
// Return true if we found and matched all stack ids from the call
789-
// instruction.
790-
return InlCallStackIter == InlinedCallStack.end();
778+
return ProfileCallStack.size() >= InlinedCallStack.size() &&
779+
llvm::equal(ProfileCallStack.take_front(InlinedCallStack.size()),
780+
InlinedCallStack, [](const Frame &F, uint64_t StackId) {
781+
return computeStackId(F) == StackId;
782+
});
791783
}
792784

793785
static bool isAllocationWithHotColdVariant(const Function *Callee,

0 commit comments

Comments
 (0)