Revert "[gcov] emitProfileArcs: iterate over GCOVFunction's instead of Function's to avoid duplicated filtering"

This reverts commit 412c9c0bf2.
This commit is contained in:
Fangrui Song 2020-09-12 12:34:43 -07:00
parent 412c9c0bf2
commit 7d3825ed95
1 changed files with 14 additions and 9 deletions

View File

@ -322,14 +322,14 @@ namespace {
// object users can construct, the blocks and lines will be rooted here.
class GCOVFunction : public GCOVRecord {
public:
GCOVFunction(GCOVProfiler *P, Function &F, const DISubprogram *SP,
GCOVFunction(GCOVProfiler *P, Function *F, const DISubprogram *SP,
unsigned EndLine, uint32_t Ident, int Version)
: GCOVRecord(P), F(F), SP(SP), EndLine(EndLine), Ident(Ident),
: GCOVRecord(P), SP(SP), EndLine(EndLine), Ident(Ident),
Version(Version), EntryBlock(P, 0), ReturnBlock(P, 1) {
LLVM_DEBUG(dbgs() << "Function: " << getFunctionName(SP) << "\n");
bool ExitBlockBeforeBody = Version >= 48;
uint32_t i = ExitBlockBeforeBody ? 2 : 1;
for (BasicBlock &BB : F)
for (BasicBlock &BB : *F)
Blocks.insert(std::make_pair(&BB, GCOVBlock(P, i++)));
if (!ExitBlockBeforeBody)
ReturnBlock.Number = i;
@ -424,8 +424,6 @@ namespace {
getBlock(&I).writeOut();
}
Function &F;
private:
const DISubprogram *SP;
unsigned EndLine;
@ -738,7 +736,7 @@ void GCOVProfiler::emitProfileNotes(NamedMDNode *CUNode) {
// single successor, so split the entry block to make sure of that.
BasicBlock &EntryBlock = F.getEntryBlock();
Funcs.push_back(std::make_unique<GCOVFunction>(this, F, SP, EndLine,
Funcs.push_back(std::make_unique<GCOVFunction>(this, &F, SP, EndLine,
FunctionIdent++, Version));
GCOVFunction &Func = *Funcs.back();
@ -826,8 +824,15 @@ bool GCOVProfiler::emitProfileArcs(NamedMDNode *CUNode) {
bool Result = false;
for (unsigned i = 0, e = CUNode->getNumOperands(); i != e; ++i) {
SmallVector<std::pair<GlobalVariable *, MDNode *>, 8> CountersBySP;
for (const GCOVFunction &GF : make_pointee_range(Funcs)) {
Function &F = GF.F;
for (auto &F : M->functions()) {
DISubprogram *SP = F.getSubprogram();
unsigned EndLine;
if (!SP) continue;
if (!functionHasLines(F, EndLine) || !isFunctionInstrumented(F))
continue;
// TODO: Functions using scope-based EH are currently not supported.
if (isUsingScopeBasedEH(F)) continue;
DenseMap<std::pair<BasicBlock *, BasicBlock *>, unsigned> EdgeToCounter;
unsigned Edges = 0;
EdgeToCounter[{nullptr, &F.getEntryBlock()}] = Edges++;
@ -849,7 +854,7 @@ bool GCOVProfiler::emitProfileArcs(NamedMDNode *CUNode) {
GlobalValue::InternalLinkage,
Constant::getNullValue(CounterTy),
"__llvm_gcov_ctr");
CountersBySP.emplace_back(Counters, F.getSubprogram());
CountersBySP.push_back(std::make_pair(Counters, SP));
// If a BB has several predecessors, use a PHINode to select
// the correct counter.