[llvm] fae221e - [gcov] Simplify/speed up CFG hash calculation
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sun Jul 26 21:15:42 PDT 2020
Author: Fangrui Song
Date: 2020-07-26T21:15:33-07:00
New Revision: fae221e7ad5a94ed7697c13d169db18d253f5f15
URL: https://github.com/llvm/llvm-project/commit/fae221e7ad5a94ed7697c13d169db18d253f5f15
DIFF: https://github.com/llvm/llvm-project/commit/fae221e7ad5a94ed7697c13d169db18d253f5f15.diff
LOG: [gcov] Simplify/speed up CFG hash calculation
Added:
Modified:
llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp b/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp
index cd2ea8d5e4ed..53a89f7348de 100644
--- a/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp
+++ b/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp
@@ -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"
@@ -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
@@ -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;
}
@@ -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;
@@ -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
@@ -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);
More information about the llvm-commits
mailing list