[llvm] r226960 - llvm-cov: Use range-for (NFC)
Justin Bogner
mail at justinbogner.com
Fri Jan 23 14:57:02 PST 2015
Author: bogner
Date: Fri Jan 23 16:57:02 2015
New Revision: 226960
URL: http://llvm.org/viewvc/llvm-project?rev=226960&view=rev
Log:
llvm-cov: Use range-for (NFC)
Modified:
llvm/trunk/include/llvm/Support/GCOV.h
llvm/trunk/lib/IR/GCOV.cpp
Modified: llvm/trunk/include/llvm/Support/GCOV.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/GCOV.h?rev=226960&r1=226959&r2=226960&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/GCOV.h (original)
+++ llvm/trunk/include/llvm/Support/GCOV.h Fri Jan 23 16:57:02 2015
@@ -19,6 +19,7 @@
#include "llvm/ADT/MapVector.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringMap.h"
+#include "llvm/ADT/iterator.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/raw_ostream.h"
@@ -255,8 +256,8 @@ struct GCOVEdge {
/// GCOVFunction - Collects function information.
class GCOVFunction {
public:
- typedef SmallVectorImpl<std::unique_ptr<GCOVBlock>>::const_iterator
- BlockIterator;
+ typedef pointee_iterator<SmallVectorImpl<
+ std::unique_ptr<GCOVBlock>>::const_iterator> BlockIterator;
GCOVFunction(GCOVFile &P) : Parent(P), Ident(0), LineNumber(0) {}
bool readGCNO(GCOVBuffer &Buffer, GCOV::GCOVVersion Version);
@@ -269,6 +270,9 @@ public:
BlockIterator block_begin() const { return Blocks.begin(); }
BlockIterator block_end() const { return Blocks.end(); }
+ iterator_range<BlockIterator> blocks() const {
+ return make_range(block_begin(), block_end());
+ }
void dump() const;
void collectLineCounts(FileInfo &FI);
@@ -329,8 +333,15 @@ public:
EdgeIterator src_begin() const { return SrcEdges.begin(); }
EdgeIterator src_end() const { return SrcEdges.end(); }
+ iterator_range<EdgeIterator> srcs() const {
+ return make_range(src_begin(), src_end());
+ }
+
EdgeIterator dst_begin() const { return DstEdges.begin(); }
EdgeIterator dst_end() const { return DstEdges.end(); }
+ iterator_range<EdgeIterator> dsts() const {
+ return make_range(dst_begin(), dst_end());
+ }
void dump() const;
void collectLineCounts(FileInfo &FI);
Modified: llvm/trunk/lib/IR/GCOV.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/GCOV.cpp?rev=226960&r1=226959&r2=226960&view=diff
==============================================================================
--- llvm/trunk/lib/IR/GCOV.cpp (original)
+++ llvm/trunk/lib/IR/GCOV.cpp Fri Jan 23 16:57:02 2015
@@ -389,8 +389,8 @@ void GCOVBlock::sortDstEdges() {
/// collectLineCounts - Collect line counts. This must be used after
/// reading .gcno and .gcda files.
void GCOVBlock::collectLineCounts(FileInfo &FI) {
- for (auto I = Lines.begin(), E = Lines.end(); I != E; ++I)
- FI.addBlockLine(Parent.getFilename(), *I, this);
+ for (uint32_t N : Lines)
+ FI.addBlockLine(Parent.getFilename(), N, this);
}
/// dump - Dump GCOVBlock content to dbgs() for debugging purposes.
@@ -398,26 +398,20 @@ void GCOVBlock::dump() const {
dbgs() << "Block : " << Number << " Counter : " << Counter << "\n";
if (!SrcEdges.empty()) {
dbgs() << "\tSource Edges : ";
- for (EdgeIterator I = SrcEdges.begin(), E = SrcEdges.end(); I != E; ++I) {
- const GCOVEdge *Edge = *I;
+ for (const GCOVEdge *Edge : SrcEdges)
dbgs() << Edge->Src.Number << " (" << Edge->Count << "), ";
- }
dbgs() << "\n";
}
if (!DstEdges.empty()) {
dbgs() << "\tDestination Edges : ";
- for (EdgeIterator I = DstEdges.begin(), E = DstEdges.end(); I != E; ++I) {
- const GCOVEdge *Edge = *I;
+ for (const GCOVEdge *Edge : DstEdges)
dbgs() << Edge->Dst.Number << " (" << Edge->Count << "), ";
- }
dbgs() << "\n";
}
if (!Lines.empty()) {
dbgs() << "\tLines : ";
- for (SmallVectorImpl<uint32_t>::const_iterator I = Lines.begin(),
- E = Lines.end();
- I != E; ++I)
- dbgs() << (*I) << ",";
+ for (uint32_t N : Lines)
+ dbgs() << (N) << ",";
dbgs() << "\n";
}
}
@@ -570,10 +564,8 @@ FileInfo::openCoveragePath(StringRef Cov
/// print - Print source files with collected line count information.
void FileInfo::print(StringRef MainFilename, StringRef GCNOFile,
StringRef GCDAFile) {
- for (StringMap<LineData>::const_iterator I = LineInfo.begin(),
- E = LineInfo.end();
- I != E; ++I) {
- StringRef Filename = I->first();
+ for (const auto &LI : LineInfo) {
+ StringRef Filename = LI.first();
auto AllLines = LineConsumer(Filename);
std::string CoveragePath = getCoveragePath(Filename, MainFilename);
@@ -586,7 +578,7 @@ void FileInfo::print(StringRef MainFilen
OS << " -: 0:Runs:" << RunCount << "\n";
OS << " -: 0:Programs:" << ProgramCount << "\n";
- const LineData &Line = I->second;
+ const LineData &Line = LI.second;
GCOVCoverage FileCoverage(Filename);
for (uint32_t LineIndex = 0; LineIndex < Line.LastLine || !AllLines.empty();
++LineIndex) {
@@ -607,9 +599,7 @@ void FileInfo::print(StringRef MainFilen
// Add up the block counts to form line counts.
DenseMap<const GCOVFunction *, bool> LineExecs;
uint64_t LineCount = 0;
- for (BlockVector::const_iterator I = Blocks.begin(), E = Blocks.end();
- I != E; ++I) {
- const GCOVBlock *Block = *I;
+ for (const GCOVBlock *Block : Blocks) {
if (Options.AllBlocks) {
// Only take the highest block count for that line.
uint64_t BlockCount = Block->getCount();
@@ -666,10 +656,7 @@ void FileInfo::print(StringRef MainFilen
uint32_t BlockNo = 0;
uint32_t EdgeNo = 0;
- for (BlockVector::const_iterator I = Blocks.begin(), E = Blocks.end();
- I != E; ++I) {
- const GCOVBlock *Block = *I;
-
+ for (const GCOVBlock *Block : Blocks) {
// Only print block and branch information at the end of the block.
if (Block->getLastLine() != LineIndex + 1)
continue;
@@ -698,18 +685,12 @@ void FileInfo::print(StringRef MainFilen
/// printFunctionSummary - Print function and block summary.
void FileInfo::printFunctionSummary(raw_ostream &OS,
const FunctionVector &Funcs) const {
- for (FunctionVector::const_iterator I = Funcs.begin(), E = Funcs.end();
- I != E; ++I) {
- const GCOVFunction *Func = *I;
+ for (const GCOVFunction *Func : Funcs) {
uint64_t EntryCount = Func->getEntryCount();
uint32_t BlocksExec = 0;
- for (GCOVFunction::BlockIterator I = Func->block_begin(),
- E = Func->block_end();
- I != E; ++I) {
- const GCOVBlock &Block = **I;
+ for (const GCOVBlock &Block : Func->blocks())
if (Block.getNumDstEdges() && Block.getCount())
++BlocksExec;
- }
OS << "function " << Func->getName() << " called " << EntryCount
<< " returned " << safeDiv(Func->getExitCount() * 100, EntryCount)
@@ -733,9 +714,7 @@ void FileInfo::printBranchInfo(raw_ostre
GCOVCoverage &Coverage, uint32_t &EdgeNo) {
SmallVector<uint64_t, 16> BranchCounts;
uint64_t TotalCounts = 0;
- for (GCOVBlock::EdgeIterator I = Block.dst_begin(), E = Block.dst_end();
- I != E; ++I) {
- const GCOVEdge *Edge = *I;
+ for (const GCOVEdge *Edge : Block.dsts()) {
BranchCounts.push_back(Edge->Count);
TotalCounts += Edge->Count;
if (Block.getCount())
@@ -755,12 +734,9 @@ void FileInfo::printBranchInfo(raw_ostre
}
}
- for (SmallVectorImpl<uint64_t>::const_iterator I = BranchCounts.begin(),
- E = BranchCounts.end();
- I != E; ++I) {
+ for (uint64_t N : BranchCounts)
OS << format("branch %2u ", EdgeNo++)
- << formatBranchInfo(Options, *I, TotalCounts) << "\n";
- }
+ << formatBranchInfo(Options, N, TotalCounts) << "\n";
}
/// printUncondBranchInfo - Print unconditional branch probabilities.
@@ -793,10 +769,8 @@ void FileInfo::printCoverage(const GCOVC
// printFuncCoverage - Print per-function coverage info.
void FileInfo::printFuncCoverage() const {
- for (FuncCoverageMap::const_iterator I = FuncCoverages.begin(),
- E = FuncCoverages.end();
- I != E; ++I) {
- const GCOVCoverage &Coverage = I->second;
+ for (const auto &FC : FuncCoverages) {
+ const GCOVCoverage &Coverage = FC.second;
outs() << "Function '" << Coverage.Name << "'\n";
printCoverage(Coverage);
outs() << "\n";
@@ -805,11 +779,9 @@ void FileInfo::printFuncCoverage() const
// printFileCoverage - Print per-file coverage info.
void FileInfo::printFileCoverage() const {
- for (FileCoverageList::const_iterator I = FileCoverages.begin(),
- E = FileCoverages.end();
- I != E; ++I) {
- const std::string &Filename = I->first;
- const GCOVCoverage &Coverage = I->second;
+ for (const auto &FC : FileCoverages) {
+ const std::string &Filename = FC.first;
+ const GCOVCoverage &Coverage = FC.second;
outs() << "File '" << Coverage.Name << "'\n";
printCoverage(Coverage);
if (!Options.NoOutput)
More information about the llvm-commits
mailing list