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
4 changes: 2 additions & 2 deletions llvm/include/llvm/Analysis/MemoryProfileInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ template <class NodeT, class IteratorT> class CallStack {

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:
Expand Down Expand Up @@ -236,7 +236,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)
Expand Down
77 changes: 43 additions & 34 deletions llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5050,6 +5050,45 @@ bool MemProfContextDisambiguation::initializeIndirectCallPromotionInfo(
return true;
}

#ifndef NDEBUG

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can drop the ifndef around the function definition in favour of a LLVM_ATTRIBUTE_UNUSED function attribute?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could, but then I need to put that attribute back on the StackIdIndexIter def in this code that I had removed it from. My sense is that the #ifdef is simpler overall, wdyt?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good to me

// 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;
Expand Down Expand Up @@ -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());
Expand Down
Loading