Skip to content

Commit

Permalink
[gcov] Simplify/speed up CFG hash calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
MaskRay committed Jul 27, 2020
1 parent e97aa56 commit fae221e
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp
Expand Up @@ -32,6 +32,7 @@
#include "llvm/IR/Module.h"
#include "llvm/InitializePasses.h"
#include "llvm/Pass.h"
#include "llvm/Support/CRC.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/FileSystem.h"
Expand Down Expand Up @@ -300,15 +301,16 @@ namespace {
assert(OutEdges.empty());
}

uint32_t Number;
SmallVector<GCOVBlock *, 4> OutEdges;

private:
friend class GCOVFunction;

GCOVBlock(GCOVProfiler *P, uint32_t Number)
: GCOVRecord(P), Number(Number) {}

uint32_t Number;
StringMap<GCOVLines> LinesByFile;
SmallVector<GCOVBlock *, 4> OutEdges;
};

// A function has a unique identifier, a checksum (we leave as zero) and a
Expand Down Expand Up @@ -347,18 +349,6 @@ namespace {
return ReturnBlock;
}

std::string getEdgeDestinations() {
std::string EdgeDestinations;
raw_string_ostream EDOS(EdgeDestinations);
Function *F = Blocks.begin()->first->getParent();
for (BasicBlock &I : *F) {
GCOVBlock &Block = getBlock(&I);
for (int i = 0, e = Block.OutEdges.size(); i != e; ++i)
EDOS << Block.OutEdges[i]->Number;
}
return EdgeDestinations;
}

uint32_t getFuncChecksum() const {
return FuncChecksum;
}
Expand Down Expand Up @@ -729,7 +719,7 @@ void GCOVProfiler::emitProfileNotes() {
continue;
}

std::string EdgeDestinations;
std::vector<uint8_t> EdgeDestinations;

Endian = M->getDataLayout().isLittleEndian() ? support::endianness::little
: support::endianness::big;
Expand Down Expand Up @@ -774,6 +764,11 @@ void GCOVProfiler::emitProfileNotes() {
} else if (isa<ReturnInst>(TI)) {
Block.addEdge(Func.getReturnBlock());
}
for (GCOVBlock *Succ : Block.OutEdges) {
uint32_t Idx = Succ->Number;
do EdgeDestinations.push_back(Idx & 255);
while ((Idx >>= 8) > 0);
}

for (auto &I : BB) {
// Debug intrinsic locations correspond to the location of the
Expand All @@ -798,12 +793,13 @@ void GCOVProfiler::emitProfileNotes() {
}
Line = 0;
}
EdgeDestinations += Func.getEdgeDestinations();
}

char Tmp[4];
JamCRC JC;
JC.update(EdgeDestinations);
os = &out;
auto Stamp = static_cast<uint32_t>(hash_value(EdgeDestinations));
uint32_t Stamp = JC.getCRC();
FileChecksums.push_back(Stamp);
if (Endian == support::endianness::big) {
out.write("gcno", 4);
Expand Down

0 comments on commit fae221e

Please sign in to comment.