llvm.org GIT mirror llvm / 798383b
llvm-cov: Use range-for (NFC) git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@226960 91177308-0d34-0410-b5e6-96231b3b80d8 Justin Bogner 5 years ago
2 changed file(s) with 34 addition(s) and 51 deletion(s). Raw diff Collapse all Expand all
1818 #include "llvm/ADT/MapVector.h"
1919 #include "llvm/ADT/SmallVector.h"
2020 #include "llvm/ADT/StringMap.h"
21 #include "llvm/ADT/iterator.h"
2122 #include "llvm/Support/MemoryBuffer.h"
2223 #include "llvm/Support/raw_ostream.h"
2324
254255 /// GCOVFunction - Collects function information.
255256 class GCOVFunction {
256257 public:
257 typedef SmallVectorImpl>::const_iterator
258 BlockIterator;
258 typedef pointee_iterator
259 std::unique_ptr>::const_iterator> BlockIterator;
259260
260261 GCOVFunction(GCOVFile &P) : Parent(P), Ident(0), LineNumber(0) {}
261262 bool readGCNO(GCOVBuffer &Buffer, GCOV::GCOVVersion Version);
268269
269270 BlockIterator block_begin() const { return Blocks.begin(); }
270271 BlockIterator block_end() const { return Blocks.end(); }
272 iterator_range blocks() const {
273 return make_range(block_begin(), block_end());
274 }
271275
272276 void dump() const;
273277 void collectLineCounts(FileInfo &FI);
328332
329333 EdgeIterator src_begin() const { return SrcEdges.begin(); }
330334 EdgeIterator src_end() const { return SrcEdges.end(); }
335 iterator_range srcs() const {
336 return make_range(src_begin(), src_end());
337 }
338
331339 EdgeIterator dst_begin() const { return DstEdges.begin(); }
332340 EdgeIterator dst_end() const { return DstEdges.end(); }
341 iterator_range dsts() const {
342 return make_range(dst_begin(), dst_end());
343 }
333344
334345 void dump() const;
335346 void collectLineCounts(FileInfo &FI);
388388 /// collectLineCounts - Collect line counts. This must be used after
389389 /// reading .gcno and .gcda files.
390390 void GCOVBlock::collectLineCounts(FileInfo &FI) {
391 for (auto I = Lines.begin(), E = Lines.end(); I != E; ++I)
392 FI.addBlockLine(Parent.getFilename(), *I, this);
391 for (uint32_t N : Lines)
392 FI.addBlockLine(Parent.getFilename(), N, this);
393393 }
394394
395395 /// dump - Dump GCOVBlock content to dbgs() for debugging purposes.
397397 dbgs() << "Block : " << Number << " Counter : " << Counter << "\n";
398398 if (!SrcEdges.empty()) {
399399 dbgs() << "\tSource Edges : ";
400 for (EdgeIterator I = SrcEdges.begin(), E = SrcEdges.end(); I != E; ++I) {
401 const GCOVEdge *Edge = *I;
400 for (const GCOVEdge *Edge : SrcEdges)
402401 dbgs() << Edge->Src.Number << " (" << Edge->Count << "), ";
403 }
404402 dbgs() << "\n";
405403 }
406404 if (!DstEdges.empty()) {
407405 dbgs() << "\tDestination Edges : ";
408 for (EdgeIterator I = DstEdges.begin(), E = DstEdges.end(); I != E; ++I) {
409 const GCOVEdge *Edge = *I;
406 for (const GCOVEdge *Edge : DstEdges)
410407 dbgs() << Edge->Dst.Number << " (" << Edge->Count << "), ";
411 }
412408 dbgs() << "\n";
413409 }
414410 if (!Lines.empty()) {
415411 dbgs() << "\tLines : ";
416 for (SmallVectorImpl::const_iterator I = Lines.begin(),
417 E = Lines.end();
418 I != E; ++I)
419 dbgs() << (*I) << ",";
412 for (uint32_t N : Lines)
413 dbgs() << (N) << ",";
420414 dbgs() << "\n";
421415 }
422416 }
569563 /// print - Print source files with collected line count information.
570564 void FileInfo::print(StringRef MainFilename, StringRef GCNOFile,
571565 StringRef GCDAFile) {
572 for (StringMap::const_iterator I = LineInfo.begin(),
573 E = LineInfo.end();
574 I != E; ++I) {
575 StringRef Filename = I->first();
566 for (const auto &LI : LineInfo) {
567 StringRef Filename = LI.first();
576568 auto AllLines = LineConsumer(Filename);
577569
578570 std::string CoveragePath = getCoveragePath(Filename, MainFilename);
585577 OS << " -: 0:Runs:" << RunCount << "\n";
586578 OS << " -: 0:Programs:" << ProgramCount << "\n";
587579
588 const LineData &Line = I->second;
580 const LineData &Line = LI.second;
589581 GCOVCoverage FileCoverage(Filename);
590582 for (uint32_t LineIndex = 0; LineIndex < Line.LastLine || !AllLines.empty();
591583 ++LineIndex) {
606598 // Add up the block counts to form line counts.
607599 DenseMap LineExecs;
608600 uint64_t LineCount = 0;
609 for (BlockVector::const_iterator I = Blocks.begin(), E = Blocks.end();
610 I != E; ++I) {
611 const GCOVBlock *Block = *I;
601 for (const GCOVBlock *Block : Blocks) {
612602 if (Options.AllBlocks) {
613603 // Only take the highest block count for that line.
614604 uint64_t BlockCount = Block->getCount();
665655
666656 uint32_t BlockNo = 0;
667657 uint32_t EdgeNo = 0;
668 for (BlockVector::const_iterator I = Blocks.begin(), E = Blocks.end();
669 I != E; ++I) {
670 const GCOVBlock *Block = *I;
671
658 for (const GCOVBlock *Block : Blocks) {
672659 // Only print block and branch information at the end of the block.
673660 if (Block->getLastLine() != LineIndex + 1)
674661 continue;
697684 /// printFunctionSummary - Print function and block summary.
698685 void FileInfo::printFunctionSummary(raw_ostream &OS,
699686 const FunctionVector &Funcs) const {
700 for (FunctionVector::const_iterator I = Funcs.begin(), E = Funcs.end();
701 I != E; ++I) {
702 const GCOVFunction *Func = *I;
687 for (const GCOVFunction *Func : Funcs) {
703688 uint64_t EntryCount = Func->getEntryCount();
704689 uint32_t BlocksExec = 0;
705 for (GCOVFunction::BlockIterator I = Func->block_begin(),
706 E = Func->block_end();
707 I != E; ++I) {
708 const GCOVBlock &Block = **I;
690 for (const GCOVBlock &Block : Func->blocks())
709691 if (Block.getNumDstEdges() && Block.getCount())
710692 ++BlocksExec;
711 }
712693
713694 OS << "function " << Func->getName() << " called " << EntryCount
714695 << " returned " << safeDiv(Func->getExitCount() * 100, EntryCount)
732713 GCOVCoverage &Coverage, uint32_t &EdgeNo) {
733714 SmallVector BranchCounts;
734715 uint64_t TotalCounts = 0;
735 for (GCOVBlock::EdgeIterator I = Block.dst_begin(), E = Block.dst_end();
736 I != E; ++I) {
737 const GCOVEdge *Edge = *I;
716 for (const GCOVEdge *Edge : Block.dsts()) {
738717 BranchCounts.push_back(Edge->Count);
739718 TotalCounts += Edge->Count;
740719 if (Block.getCount())
754733 }
755734 }
756735
757 for (SmallVectorImpl::const_iterator I = BranchCounts.begin(),
758 E = BranchCounts.end();
759 I != E; ++I) {
736 for (uint64_t N : BranchCounts)
760737 OS << format("branch %2u ", EdgeNo++)
761 << formatBranchInfo(Options, *I, TotalCounts) << "\n";
762 }
738 << formatBranchInfo(Options, N, TotalCounts) << "\n";
763739 }
764740
765741 /// printUncondBranchInfo - Print unconditional branch probabilities.
792768
793769 // printFuncCoverage - Print per-function coverage info.
794770 void FileInfo::printFuncCoverage() const {
795 for (FuncCoverageMap::const_iterator I = FuncCoverages.begin(),
796 E = FuncCoverages.end();
797 I != E; ++I) {
798 const GCOVCoverage &Coverage = I->second;
771 for (const auto &FC : FuncCoverages) {
772 const GCOVCoverage &Coverage = FC.second;
799773 outs() << "Function '" << Coverage.Name << "'\n";
800774 printCoverage(Coverage);
801775 outs() << "\n";
804778
805779 // printFileCoverage - Print per-file coverage info.
806780 void FileInfo::printFileCoverage() const {
807 for (FileCoverageList::const_iterator I = FileCoverages.begin(),
808 E = FileCoverages.end();
809 I != E; ++I) {
810 const std::string &Filename = I->first;
811 const GCOVCoverage &Coverage = I->second;
781 for (const auto &FC : FileCoverages) {
782 const std::string &Filename = FC.first;
783 const GCOVCoverage &Coverage = FC.second;
812784 outs() << "File '" << Coverage.Name << "'\n";
813785 printCoverage(Coverage);
814786 if (!Options.NoOutput)