@@ -5050,6 +5050,45 @@ bool MemProfContextDisambiguation::initializeIndirectCallPromotionInfo(
5050
5050
return true ;
5051
5051
}
5052
5052
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
+
5053
5092
bool MemProfContextDisambiguation::applyImport (Module &M) {
5054
5093
assert (ImportSummary);
5055
5094
bool Changed = false ;
@@ -5242,40 +5281,10 @@ bool MemProfContextDisambiguation::applyImport(Module &M) {
5242
5281
assert (AI != FS->allocs ().end ());
5243
5282
auto &AllocNode = *(AI++);
5244
5283
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
5279
5288
5280
5289
// Perform cloning if not yet done.
5281
5290
CloneFuncIfNeeded (/* NumClones=*/ AllocNode.Versions .size ());
0 commit comments