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 OutEdges; + private: friend class GCOVFunction; GCOVBlock(GCOVProfiler *P, uint32_t Number) : GCOVRecord(P), Number(Number) {} - uint32_t Number; StringMap LinesByFile; - SmallVector 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 EdgeDestinations; Endian = M->getDataLayout().isLittleEndian() ? support::endianness::little : support::endianness::big; @@ -774,6 +764,11 @@ void GCOVProfiler::emitProfileNotes() { } else if (isa(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(hash_value(EdgeDestinations)); + uint32_t Stamp = JC.getCRC(); FileChecksums.push_back(Stamp); if (Endian == support::endianness::big) { out.write("gcno", 4);