necessary since gcov counts transitions between blocks. It can't see if you've
run every line in a straight-line function, so we add an edge for it to notice.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@129905
91177308-0d34-0410-b5e6-
96231b3b80d8
for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB) {
blocks[BB] = new GCOVBlock(i++, os);
}
for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB) {
blocks[BB] = new GCOVBlock(i++, os);
}
+ return_block = new GCOVBlock(i++, os);
WriteBytes(function_tag, 4);
uint32_t block_len = 1 + 1 + 1 + LengthOfGCOVString(SP.getName()) +
WriteBytes(function_tag, 4);
uint32_t block_len = 1 + 1 + 1 + LengthOfGCOVString(SP.getName()) +
~GCOVFunction() {
DeleteContainerSeconds(blocks);
~GCOVFunction() {
DeleteContainerSeconds(blocks);
}
GCOVBlock &GetBlock(BasicBlock *BB) {
return *blocks[BB];
}
}
GCOVBlock &GetBlock(BasicBlock *BB) {
return *blocks[BB];
}
+ GCOVBlock &GetReturnBlock() {
+ return *return_block;
+ }
+
void WriteOut() {
// Emit count of blocks.
WriteBytes(block_tag, 4);
void WriteOut() {
// Emit count of blocks.
WriteBytes(block_tag, 4);
- Write(blocks.size());
- for (int i = 0, e = blocks.size(); i != e; ++i) {
+ Write(blocks.size() + 1);
+ for (int i = 0, e = blocks.size() + 1; i != e; ++i) {
Write(0); // No flags on our blocks.
}
Write(0); // No flags on our blocks.
}
private:
DenseMap<BasicBlock *, GCOVBlock *> blocks;
private:
DenseMap<BasicBlock *, GCOVBlock *> blocks;
+ GCOVBlock *return_block;
for (int i = 0; i != successors; ++i) {
block.AddEdge(function.GetBlock(TI->getSuccessor(i)));
}
for (int i = 0; i != successors; ++i) {
block.AddEdge(function.GetBlock(TI->getSuccessor(i)));
}
+ } else if (isa<ReturnInst>(TI)) {
+ block.AddEdge(function.GetReturnBlock());
DISubprogram SP(*SPI);
Function *F = SP.getFunction();
DISubprogram SP(*SPI);
Function *F = SP.getFunction();
- // TODO: GCOV format requires a distinct unified exit block.
unsigned edges = 0;
for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB) {
TerminatorInst *TI = BB->getTerminator();
unsigned edges = 0;
for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB) {
TerminatorInst *TI = BB->getTerminator();
- edges += TI->getNumSuccessors();
+ if (isa<ReturnInst>(TI))
+ ++edges;
+ else
+ edges += TI->getNumSuccessors();
}
const ArrayType *counter_type =
}
const ArrayType *counter_type =
unsigned edge_num = 0;
for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB) {
TerminatorInst *TI = BB->getTerminator();
unsigned edge_num = 0;
for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB) {
TerminatorInst *TI = BB->getTerminator();
- if (int successors = TI->getNumSuccessors()) {
+ int successors = isa<ReturnInst>(TI) ? 1 : TI->getNumSuccessors();
+ if (successors) {
IRBuilder<> builder(TI);
if (successors == 1) {
IRBuilder<> builder(TI);
if (successors == 1) {