From e1c0863d74f7995dd0890e35b585526457d118d5 Mon Sep 17 00:00:00 2001 From: David Blaikie Date: Mon, 21 Apr 2014 21:40:16 +0000 Subject: Use unique_ptr to manage ownership of GCOVFunctions, Blocks, and Edges. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@206796 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/IR/GCOV.cpp | 57 +++++++++++++++++++++------------------------------------ 1 file changed, 21 insertions(+), 36 deletions(-) (limited to 'lib/IR/GCOV.cpp') diff --git a/lib/IR/GCOV.cpp b/lib/IR/GCOV.cpp index f69bdc4f8c..0e344ddfea 100644 --- a/lib/IR/GCOV.cpp +++ b/lib/IR/GCOV.cpp @@ -26,11 +26,6 @@ using namespace llvm; //===----------------------------------------------------------------------===// // GCOVFile implementation. -/// ~GCOVFile - Delete GCOVFile and its content. -GCOVFile::~GCOVFile() { - DeleteContainerPointers(Functions); -} - /// readGCNO - Read GCNO buffer. bool GCOVFile::readGCNO(GCOVBuffer &Buffer) { if (!Buffer.readGCNOFormat()) return false; @@ -39,10 +34,10 @@ bool GCOVFile::readGCNO(GCOVBuffer &Buffer) { if (!Buffer.readInt(Checksum)) return false; while (true) { if (!Buffer.readFunctionTag()) break; - GCOVFunction *GFun = new GCOVFunction(*this); + auto GFun = make_unique(*this); if (!GFun->readGCNO(Buffer, Version)) return false; - Functions.push_back(GFun); + Functions.push_back(std::move(GFun)); } GCNOInitialized = true; @@ -97,17 +92,15 @@ bool GCOVFile::readGCDA(GCOVBuffer &Buffer) { /// dump - Dump GCOVFile content to dbgs() for debugging purposes. void GCOVFile::dump() const { - for (SmallVectorImpl::const_iterator I = Functions.begin(), - E = Functions.end(); I != E; ++I) - (*I)->dump(); + for (const auto &FPtr : Functions) + FPtr->dump(); } /// collectLineCounts - Collect line counts. This must be used after /// reading .gcno and .gcda files. void GCOVFile::collectLineCounts(FileInfo &FI) { - for (SmallVectorImpl::iterator I = Functions.begin(), - E = Functions.end(); I != E; ++I) - (*I)->collectLineCounts(FI); + for (const auto &FPtr : Functions) + FPtr->collectLineCounts(FI); FI.setRunCount(RunCount); FI.setProgramCount(ProgramCount); } @@ -115,12 +108,6 @@ void GCOVFile::collectLineCounts(FileInfo &FI) { //===----------------------------------------------------------------------===// // GCOVFunction implementation. -/// ~GCOVFunction - Delete GCOVFunction and its content. -GCOVFunction::~GCOVFunction() { - DeleteContainerPointers(Blocks); - DeleteContainerPointers(Edges); -} - /// readGCNO - Read a function from the GCNO buffer. Return false if an error /// occurs. bool GCOVFunction::readGCNO(GCOVBuffer &Buff, GCOV::GCOVVersion Version) { @@ -150,7 +137,7 @@ bool GCOVFunction::readGCNO(GCOVBuffer &Buff, GCOV::GCOVVersion Version) { if (!Buff.readInt(BlockCount)) return false; for (uint32_t i = 0, e = BlockCount; i != e; ++i) { if (!Buff.readInt(Dummy)) return false; // Block flags; - Blocks.push_back(new GCOVBlock(*this, i)); + Blocks.push_back(make_unique(*this, i)); } // read edges. @@ -168,8 +155,8 @@ bool GCOVFunction::readGCNO(GCOVBuffer &Buff, GCOV::GCOVVersion Version) { for (uint32_t i = 0, e = EdgeCount; i != e; ++i) { uint32_t Dst; if (!Buff.readInt(Dst)) return false; - GCOVEdge *Edge = new GCOVEdge(Blocks[BlockNo], Blocks[Dst]); - Edges.push_back(Edge); + Edges.push_back(make_unique(*Blocks[BlockNo], *Blocks[Dst])); + GCOVEdge *Edge = Edges.back().get(); Blocks[BlockNo]->addDstEdge(Edge); Blocks[Dst]->addSrcEdge(Edge); if (!Buff.readInt(Dummy)) return false; // Edge flag @@ -188,7 +175,7 @@ bool GCOVFunction::readGCNO(GCOVBuffer &Buff, GCOV::GCOVVersion Version) { << ").\n"; return false; } - GCOVBlock *Block = Blocks[BlockNo]; + GCOVBlock &Block = *Blocks[BlockNo]; if (!Buff.readInt(Dummy)) return false; // flag while (Buff.getCursor() != (EndPos - 4)) { StringRef F; @@ -203,7 +190,7 @@ bool GCOVFunction::readGCNO(GCOVBuffer &Buff, GCOV::GCOVVersion Version) { uint32_t Line; if (!Buff.readInt(Line)) return false; if (!Line) break; - Block->addLine(Line); + Block.addLine(Line); } } if (!Buff.readInt(Dummy)) return false; // flag @@ -300,9 +287,8 @@ uint64_t GCOVFunction::getExitCount() const { /// dump - Dump GCOVFunction content to dbgs() for debugging purposes. void GCOVFunction::dump() const { dbgs() << "===== " << Name << " @ " << Filename << ":" << LineNumber << "\n"; - for (SmallVectorImpl::const_iterator I = Blocks.begin(), - E = Blocks.end(); I != E; ++I) - (*I)->dump(); + for (const auto &Block : Blocks) + Block->dump(); } /// collectLineCounts - Collect line counts. This must be used after @@ -313,9 +299,8 @@ void GCOVFunction::collectLineCounts(FileInfo &FI) { if (LineNumber == 0) return; - for (SmallVectorImpl::iterator I = Blocks.begin(), - E = Blocks.end(); I != E; ++I) - (*I)->collectLineCounts(FI); + for (const auto &Block : Blocks) + Block->collectLineCounts(FI); FI.addFunctionLine(Filename, LineNumber, this); } @@ -335,8 +320,8 @@ void GCOVBlock::addCount(size_t DstEdgeNo, uint64_t N) { assert(DstEdgeNo < DstEdges.size()); // up to caller to ensure EdgeNo is valid DstEdges[DstEdgeNo]->Count = N; Counter += N; - if (!DstEdges[DstEdgeNo]->Dst->getNumDstEdges()) - DstEdges[DstEdgeNo]->Dst->Counter += N; + if (!DstEdges[DstEdgeNo]->Dst.getNumDstEdges()) + DstEdges[DstEdgeNo]->Dst.Counter += N; } /// sortDstEdges - Sort destination edges by block number, nop if already @@ -363,7 +348,7 @@ void GCOVBlock::dump() const { dbgs() << "\tSource Edges : "; for (EdgeIterator I = SrcEdges.begin(), E = SrcEdges.end(); I != E; ++I) { const GCOVEdge *Edge = *I; - dbgs() << Edge->Src->Number << " (" << Edge->Count << "), "; + dbgs() << Edge->Src.Number << " (" << Edge->Count << "), "; } dbgs() << "\n"; } @@ -371,7 +356,7 @@ void GCOVBlock::dump() const { dbgs() << "\tDestination Edges : "; for (EdgeIterator I = DstEdges.begin(), E = DstEdges.end(); I != E; ++I) { const GCOVEdge *Edge = *I; - dbgs() << Edge->Dst->Number << " (" << Edge->Count << "), "; + dbgs() << Edge->Dst.Number << " (" << Edge->Count << "), "; } dbgs() << "\n"; } @@ -617,8 +602,8 @@ void FileInfo::printFunctionSummary(raw_fd_ostream &OS, uint32_t BlocksExec = 0; for (GCOVFunction::BlockIterator I = Func->block_begin(), E = Func->block_end(); I != E; ++I) { - const GCOVBlock *Block = *I; - if (Block->getNumDstEdges() && Block->getCount()) + const GCOVBlock &Block = **I; + if (Block.getNumDstEdges() && Block.getCount()) ++BlocksExec; } -- cgit v1.2.3