@@ -5050,6 +5050,45 @@ bool MemProfContextDisambiguation::initializeIndirectCallPromotionInfo(
50505050 return true ;
50515051}
50525052
5053+ #ifndef NDEBUG
5054+ // Sanity check that the MIB stack ids match between the summary and
5055+ // instruction metadata.
5056+ static void checkAllocContextIds (
5057+ const AllocInfo &AllocNode, const MDNode *MemProfMD,
5058+ const CallStack<MDNode, MDNode::op_iterator> &CallsiteContext,
5059+ const ModuleSummaryIndex *ImportSummary) {
5060+ auto MIBIter = AllocNode.MIBs .begin ();
5061+ for (auto &MDOp : MemProfMD->operands ()) {
5062+ assert (MIBIter != AllocNode.MIBs .end ());
5063+ auto StackIdIndexIter = MIBIter->StackIdIndices .begin ();
5064+ auto *MIBMD = cast<const MDNode>(MDOp);
5065+ MDNode *StackMDNode = getMIBStackNode (MIBMD);
5066+ assert (StackMDNode);
5067+ CallStack<MDNode, MDNode::op_iterator> StackContext (StackMDNode);
5068+ auto ContextIterBegin =
5069+ StackContext.beginAfterSharedPrefix (CallsiteContext);
5070+ // Skip the checking on the first iteration.
5071+ uint64_t LastStackContextId =
5072+ (ContextIterBegin != StackContext.end () && *ContextIterBegin == 0 ) ? 1
5073+ : 0 ;
5074+ for (auto ContextIter = ContextIterBegin; ContextIter != StackContext.end ();
5075+ ++ContextIter) {
5076+ // If this is a direct recursion, simply skip the duplicate
5077+ // entries, to be consistent with how the summary ids were
5078+ // generated during ModuleSummaryAnalysis.
5079+ if (LastStackContextId == *ContextIter)
5080+ continue ;
5081+ LastStackContextId = *ContextIter;
5082+ assert (StackIdIndexIter != MIBIter->StackIdIndices .end ());
5083+ assert (ImportSummary->getStackIdAtIndex (*StackIdIndexIter) ==
5084+ *ContextIter);
5085+ StackIdIndexIter++;
5086+ }
5087+ MIBIter++;
5088+ }
5089+ }
5090+ #endif
5091+
50535092bool MemProfContextDisambiguation::applyImport (Module &M) {
50545093 assert (ImportSummary);
50555094 bool Changed = false ;
@@ -5242,40 +5281,10 @@ bool MemProfContextDisambiguation::applyImport(Module &M) {
52425281 assert (AI != FS->allocs ().end ());
52435282 auto &AllocNode = *(AI++);
52445283
5245- // Sanity check that the MIB stack ids match between the summary and
5246- // instruction metadata.
5247- auto MIBIter = AllocNode.MIBs .begin ();
5248- for (auto &MDOp : MemProfMD->operands ()) {
5249- assert (MIBIter != AllocNode.MIBs .end ());
5250- LLVM_ATTRIBUTE_UNUSED auto StackIdIndexIter =
5251- MIBIter->StackIdIndices .begin ();
5252- auto *MIBMD = cast<const MDNode>(MDOp);
5253- MDNode *StackMDNode = getMIBStackNode (MIBMD);
5254- assert (StackMDNode);
5255- CallStack<MDNode, MDNode::op_iterator> StackContext (StackMDNode);
5256- auto ContextIterBegin =
5257- StackContext.beginAfterSharedPrefix (CallsiteContext);
5258- // Skip the checking on the first iteration.
5259- uint64_t LastStackContextId =
5260- (ContextIterBegin != StackContext.end () &&
5261- *ContextIterBegin == 0 )
5262- ? 1
5263- : 0 ;
5264- for (auto ContextIter = ContextIterBegin;
5265- ContextIter != StackContext.end (); ++ContextIter) {
5266- // If this is a direct recursion, simply skip the duplicate
5267- // entries, to be consistent with how the summary ids were
5268- // generated during ModuleSummaryAnalysis.
5269- if (LastStackContextId == *ContextIter)
5270- continue ;
5271- LastStackContextId = *ContextIter;
5272- assert (StackIdIndexIter != MIBIter->StackIdIndices .end ());
5273- assert (ImportSummary->getStackIdAtIndex (*StackIdIndexIter) ==
5274- *ContextIter);
5275- StackIdIndexIter++;
5276- }
5277- MIBIter++;
5278- }
5284+ #ifndef NDEBUG
5285+ checkAllocContextIds (AllocNode, MemProfMD, CallsiteContext,
5286+ ImportSummary);
5287+ #endif
52795288
52805289 // Perform cloning if not yet done.
52815290 CloneFuncIfNeeded (/* NumClones=*/ AllocNode.Versions .size ());
0 commit comments