Skip to content

Commit 907a8c3

Browse files
committed
[SILProfiler] Add debug output for {push,pop}Region operations
1 parent 98d358c commit 907a8c3

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

lib/SIL/SILProfiler.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,20 @@ class SourceMappingRegion {
430430
assert(EndLoc && "Region has no end location");
431431
return *EndLoc;
432432
}
433+
434+
void print(llvm::raw_ostream &OS, const SourceManager &SM) const {
435+
OS << "[";
436+
if (hasStartLoc())
437+
getStartLoc().print(OS, SM);
438+
else
439+
OS << "?";
440+
OS << ", ";
441+
if (hasEndLoc())
442+
getEndLoc().print(OS, SM);
443+
else
444+
OS << "?";
445+
OS << "]";
446+
}
433447
};
434448

435449
/// An ASTWalker that maps ASTNodes to profiling counters.
@@ -754,6 +768,11 @@ struct CoverageMapping : public ASTWalker {
754768
void pushRegion(ASTNode Node) {
755769
RegionStack.emplace_back(Node, getCounter(Node), Node.getStartLoc(),
756770
getEndLoc(Node));
771+
LLVM_DEBUG({
772+
llvm::dbgs() << "Pushed region: ";
773+
RegionStack.back().print(llvm::dbgs(), SM);
774+
llvm::dbgs() << "\n";
775+
});
757776
}
758777

759778
/// Replace the current region's count by pushing an incomplete region.
@@ -780,6 +799,8 @@ struct CoverageMapping : public ASTWalker {
780799
auto ParentIt = I;
781800
SourceLoc EndLoc = ParentIt->getEndLoc();
782801

802+
unsigned FirstPoppedIndex = SourceRegions.size();
803+
(void)FirstPoppedIndex;
783804
SourceRegions.push_back(std::move(*I++));
784805
for (; I != E; ++I) {
785806
if (!I->hasStartLoc())
@@ -789,6 +810,14 @@ struct CoverageMapping : public ASTWalker {
789810
SourceRegions.push_back(std::move(*I));
790811
}
791812

813+
LLVM_DEBUG({
814+
for (unsigned Idx = FirstPoppedIndex; Idx < SourceRegions.size(); ++Idx) {
815+
llvm::dbgs() << "Popped region: ";
816+
SourceRegions[Idx].print(llvm::dbgs(), SM);
817+
llvm::dbgs() << "\n";
818+
}
819+
});
820+
792821
RegionStack.erase(ParentIt, E);
793822
}
794823

0 commit comments

Comments
 (0)