mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-01 00:33:09 +00:00
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
This commit is contained in:
parent
2df01c60e6
commit
e1c0863d74
@ -232,7 +232,6 @@ class GCOVFile {
|
||||
public:
|
||||
GCOVFile() : GCNOInitialized(false), Checksum(0), Functions(), RunCount(0),
|
||||
ProgramCount(0) {}
|
||||
~GCOVFile();
|
||||
bool readGCNO(GCOVBuffer &Buffer);
|
||||
bool readGCDA(GCOVBuffer &Buffer);
|
||||
uint32_t getChecksum() const { return Checksum; }
|
||||
@ -242,27 +241,27 @@ private:
|
||||
bool GCNOInitialized;
|
||||
GCOV::GCOVVersion Version;
|
||||
uint32_t Checksum;
|
||||
SmallVector<GCOVFunction *, 16> Functions;
|
||||
SmallVector<std::unique_ptr<GCOVFunction>, 16> Functions;
|
||||
uint32_t RunCount;
|
||||
uint32_t ProgramCount;
|
||||
};
|
||||
|
||||
/// GCOVEdge - Collects edge information.
|
||||
struct GCOVEdge {
|
||||
GCOVEdge(GCOVBlock *S, GCOVBlock *D): Src(S), Dst(D), Count(0) {}
|
||||
GCOVEdge(GCOVBlock &S, GCOVBlock &D) : Src(S), Dst(D), Count(0) {}
|
||||
|
||||
GCOVBlock *Src;
|
||||
GCOVBlock *Dst;
|
||||
GCOVBlock &Src;
|
||||
GCOVBlock &Dst;
|
||||
uint64_t Count;
|
||||
};
|
||||
|
||||
/// GCOVFunction - Collects function information.
|
||||
class GCOVFunction {
|
||||
public:
|
||||
typedef SmallVectorImpl<GCOVBlock *>::const_iterator BlockIterator;
|
||||
typedef SmallVectorImpl<std::unique_ptr<GCOVBlock>>::const_iterator
|
||||
BlockIterator;
|
||||
|
||||
GCOVFunction(GCOVFile &P) : Parent(P), Ident(0), LineNumber(0) {}
|
||||
~GCOVFunction();
|
||||
bool readGCNO(GCOVBuffer &Buffer, GCOV::GCOVVersion Version);
|
||||
bool readGCDA(GCOVBuffer &Buffer, GCOV::GCOVVersion Version);
|
||||
StringRef getName() const { return Name; }
|
||||
@ -283,8 +282,8 @@ private:
|
||||
uint32_t LineNumber;
|
||||
StringRef Name;
|
||||
StringRef Filename;
|
||||
SmallVector<GCOVBlock *, 16> Blocks;
|
||||
SmallVector<GCOVEdge *, 16> Edges;
|
||||
SmallVector<std::unique_ptr<GCOVBlock>, 16> Blocks;
|
||||
SmallVector<std::unique_ptr<GCOVEdge>, 16> Edges;
|
||||
};
|
||||
|
||||
/// GCOVBlock - Collects block information.
|
||||
@ -298,7 +297,7 @@ class GCOVBlock {
|
||||
|
||||
struct SortDstEdgesFunctor {
|
||||
bool operator()(const GCOVEdge *E1, const GCOVEdge *E2) {
|
||||
return E1->Dst->Number < E2->Dst->Number;
|
||||
return E1->Dst.Number < E2->Dst.Number;
|
||||
}
|
||||
};
|
||||
public:
|
||||
@ -314,13 +313,13 @@ public:
|
||||
uint64_t getCount() const { return Counter; }
|
||||
|
||||
void addSrcEdge(GCOVEdge *Edge) {
|
||||
assert(Edge->Dst == this); // up to caller to ensure edge is valid
|
||||
assert(&Edge->Dst == this); // up to caller to ensure edge is valid
|
||||
SrcEdges.push_back(Edge);
|
||||
}
|
||||
void addDstEdge(GCOVEdge *Edge) {
|
||||
assert(Edge->Src == this); // up to caller to ensure edge is valid
|
||||
assert(&Edge->Src == this); // up to caller to ensure edge is valid
|
||||
// Check if adding this edge causes list to become unsorted.
|
||||
if (DstEdges.size() && DstEdges.back()->Dst->Number > Edge->Dst->Number)
|
||||
if (DstEdges.size() && DstEdges.back()->Dst.Number > Edge->Dst.Number)
|
||||
DstEdgesAreSorted = false;
|
||||
DstEdges.push_back(Edge);
|
||||
}
|
||||
|
@ -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<GCOVFunction>(*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<GCOVFunction *>::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<GCOVFunction *>::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<GCOVBlock>(*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<GCOVEdge>(*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<GCOVBlock *>::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<GCOVBlock *>::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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user