[MemProf] Avoid assertion checking loop under NDEBUG (NFC) (#138985)
Guard a loop that only exists to do assertion checking of stack ids on memprof metadata so that it isn't compiled and executed under NDEBUG. This is similar to how callsite metadata stack id verification is guarded further below.
This commit is contained in:
parent
efd805ed55
commit
7348d7eccb
@ -166,7 +166,7 @@ public:
|
||||
|
||||
CallStackIterator begin() const;
|
||||
CallStackIterator end() const { return CallStackIterator(N, /*End*/ true); }
|
||||
CallStackIterator beginAfterSharedPrefix(CallStack &Other);
|
||||
CallStackIterator beginAfterSharedPrefix(const CallStack &Other);
|
||||
uint64_t back() const;
|
||||
|
||||
private:
|
||||
@ -204,7 +204,7 @@ CallStack<NodeT, IteratorT>::begin() const {
|
||||
|
||||
template <class NodeT, class IteratorT>
|
||||
typename CallStack<NodeT, IteratorT>::CallStackIterator
|
||||
CallStack<NodeT, IteratorT>::beginAfterSharedPrefix(CallStack &Other) {
|
||||
CallStack<NodeT, IteratorT>::beginAfterSharedPrefix(const CallStack &Other) {
|
||||
CallStackIterator Cur = begin();
|
||||
for (CallStackIterator OtherCur = Other.begin();
|
||||
Cur != end() && OtherCur != Other.end(); ++Cur, ++OtherCur)
|
||||
|
@ -5050,6 +5050,45 @@ bool MemProfContextDisambiguation::initializeIndirectCallPromotionInfo(
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifndef NDEBUG
|
||||
// Sanity check that the MIB stack ids match between the summary and
|
||||
// instruction metadata.
|
||||
static void checkAllocContextIds(
|
||||
const AllocInfo &AllocNode, const MDNode *MemProfMD,
|
||||
const CallStack<MDNode, MDNode::op_iterator> &CallsiteContext,
|
||||
const ModuleSummaryIndex *ImportSummary) {
|
||||
auto MIBIter = AllocNode.MIBs.begin();
|
||||
for (auto &MDOp : MemProfMD->operands()) {
|
||||
assert(MIBIter != AllocNode.MIBs.end());
|
||||
auto StackIdIndexIter = MIBIter->StackIdIndices.begin();
|
||||
auto *MIBMD = cast<const MDNode>(MDOp);
|
||||
MDNode *StackMDNode = getMIBStackNode(MIBMD);
|
||||
assert(StackMDNode);
|
||||
CallStack<MDNode, MDNode::op_iterator> StackContext(StackMDNode);
|
||||
auto ContextIterBegin =
|
||||
StackContext.beginAfterSharedPrefix(CallsiteContext);
|
||||
// Skip the checking on the first iteration.
|
||||
uint64_t LastStackContextId =
|
||||
(ContextIterBegin != StackContext.end() && *ContextIterBegin == 0) ? 1
|
||||
: 0;
|
||||
for (auto ContextIter = ContextIterBegin; ContextIter != StackContext.end();
|
||||
++ContextIter) {
|
||||
// If this is a direct recursion, simply skip the duplicate
|
||||
// entries, to be consistent with how the summary ids were
|
||||
// generated during ModuleSummaryAnalysis.
|
||||
if (LastStackContextId == *ContextIter)
|
||||
continue;
|
||||
LastStackContextId = *ContextIter;
|
||||
assert(StackIdIndexIter != MIBIter->StackIdIndices.end());
|
||||
assert(ImportSummary->getStackIdAtIndex(*StackIdIndexIter) ==
|
||||
*ContextIter);
|
||||
StackIdIndexIter++;
|
||||
}
|
||||
MIBIter++;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
bool MemProfContextDisambiguation::applyImport(Module &M) {
|
||||
assert(ImportSummary);
|
||||
bool Changed = false;
|
||||
@ -5242,40 +5281,10 @@ bool MemProfContextDisambiguation::applyImport(Module &M) {
|
||||
assert(AI != FS->allocs().end());
|
||||
auto &AllocNode = *(AI++);
|
||||
|
||||
// Sanity check that the MIB stack ids match between the summary and
|
||||
// instruction metadata.
|
||||
auto MIBIter = AllocNode.MIBs.begin();
|
||||
for (auto &MDOp : MemProfMD->operands()) {
|
||||
assert(MIBIter != AllocNode.MIBs.end());
|
||||
LLVM_ATTRIBUTE_UNUSED auto StackIdIndexIter =
|
||||
MIBIter->StackIdIndices.begin();
|
||||
auto *MIBMD = cast<const MDNode>(MDOp);
|
||||
MDNode *StackMDNode = getMIBStackNode(MIBMD);
|
||||
assert(StackMDNode);
|
||||
CallStack<MDNode, MDNode::op_iterator> StackContext(StackMDNode);
|
||||
auto ContextIterBegin =
|
||||
StackContext.beginAfterSharedPrefix(CallsiteContext);
|
||||
// Skip the checking on the first iteration.
|
||||
uint64_t LastStackContextId =
|
||||
(ContextIterBegin != StackContext.end() &&
|
||||
*ContextIterBegin == 0)
|
||||
? 1
|
||||
: 0;
|
||||
for (auto ContextIter = ContextIterBegin;
|
||||
ContextIter != StackContext.end(); ++ContextIter) {
|
||||
// If this is a direct recursion, simply skip the duplicate
|
||||
// entries, to be consistent with how the summary ids were
|
||||
// generated during ModuleSummaryAnalysis.
|
||||
if (LastStackContextId == *ContextIter)
|
||||
continue;
|
||||
LastStackContextId = *ContextIter;
|
||||
assert(StackIdIndexIter != MIBIter->StackIdIndices.end());
|
||||
assert(ImportSummary->getStackIdAtIndex(*StackIdIndexIter) ==
|
||||
*ContextIter);
|
||||
StackIdIndexIter++;
|
||||
}
|
||||
MIBIter++;
|
||||
}
|
||||
#ifndef NDEBUG
|
||||
checkAllocContextIds(AllocNode, MemProfMD, CallsiteContext,
|
||||
ImportSummary);
|
||||
#endif
|
||||
|
||||
// Perform cloning if not yet done.
|
||||
CloneFuncIfNeeded(/*NumClones=*/AllocNode.Versions.size());
|
||||
|
Loading…
x
Reference in New Issue
Block a user