diff options
author | Kostya Serebryany <kcc@google.com> | 2016-08-16 17:37:13 +0000 |
---|---|---|
committer | Kostya Serebryany <kcc@google.com> | 2016-08-16 17:37:13 +0000 |
commit | c98ef718eab85e44701a23f63c1e69eb6e43cc51 (patch) | |
tree | ca93d1c5f2de4cde517294ca6eb579797c4ed002 /llvm/lib/Fuzzer/FuzzerTracePC.cpp | |
parent | 4893aff94ed2acbef2ff91592a423195baee47dc (diff) | |
download | bcm5719-llvm-c98ef718eab85e44701a23f63c1e69eb6e43cc51.tar.gz bcm5719-llvm-c98ef718eab85e44701a23f63c1e69eb6e43cc51.zip |
[libFuzzer] refactoring around PCMap, NFC
llvm-svn: 278825
Diffstat (limited to 'llvm/lib/Fuzzer/FuzzerTracePC.cpp')
-rw-r--r-- | llvm/lib/Fuzzer/FuzzerTracePC.cpp | 41 |
1 files changed, 10 insertions, 31 deletions
diff --git a/llvm/lib/Fuzzer/FuzzerTracePC.cpp b/llvm/lib/Fuzzer/FuzzerTracePC.cpp index 46c43d0c17f..53341d3632e 100644 --- a/llvm/lib/Fuzzer/FuzzerTracePC.cpp +++ b/llvm/lib/Fuzzer/FuzzerTracePC.cpp @@ -16,43 +16,22 @@ namespace fuzzer { -void PcCoverageMap::Reset() { memset(Map, 0, sizeof(Map)); } +static size_t PreviouslyComputedPCHash; +static ValueBitMap CurrentPCMap; -void PcCoverageMap::Update(uintptr_t Addr) { - uintptr_t Idx = Addr % kMapSizeInBits; - uintptr_t WordIdx = Idx / kBitsInWord; - uintptr_t BitIdx = Idx % kBitsInWord; - Map[WordIdx] |= 1UL << BitIdx; -} - -size_t PcCoverageMap::MergeFrom(const PcCoverageMap &Other) { - uintptr_t Res = 0; - for (size_t i = 0; i < kMapSizeInWords; i++) - Res += __builtin_popcountl(Map[i] |= Other.Map[i]); - return Res; -} - -static PcCoverageMap CurrentMap; -static thread_local uintptr_t Prev; - -void PcMapResetCurrent() { - if (Prev) { - Prev = 0; - CurrentMap.Reset(); - } -} - -size_t PcMapMergeInto(PcCoverageMap *Map) { - if (!Prev) +// Merges CurrentPCMap into M, returns the number of new bits. +size_t PCMapMergeFromCurrent(ValueBitMap &M) { + if (!PreviouslyComputedPCHash) return 0; - return Map->MergeFrom(CurrentMap); + PreviouslyComputedPCHash = 0; + return M.MergeFrom(CurrentPCMap); } static void HandlePC(uint32_t PC) { // We take 12 bits of PC and mix it with the previous PCs. - uintptr_t Next = (Prev << 5) ^ (PC & 4095); - CurrentMap.Update(Next); - Prev = Next; + uintptr_t Next = (PreviouslyComputedPCHash << 5) ^ (PC & 4095); + CurrentPCMap.AddValue(Next); + PreviouslyComputedPCHash = Next; } } // namespace fuzzer |