diff options
| author | Max Moroz <mmoroz@chromium.org> | 2018-08-08 14:32:46 +0000 |
|---|---|---|
| committer | Max Moroz <mmoroz@chromium.org> | 2018-08-08 14:32:46 +0000 |
| commit | cd02f3147b16bce48b7973725e98005e141925a2 (patch) | |
| tree | 3bdbc9126e1c1692d5ee0cff1be13c76a7487f4e /compiler-rt/lib/fuzzer/FuzzerTracePC.cpp | |
| parent | a194b2d2ffdd4c8400324fb5e105edd1f7a8d698 (diff) | |
| download | bcm5719-llvm-cd02f3147b16bce48b7973725e98005e141925a2.tar.gz bcm5719-llvm-cd02f3147b16bce48b7973725e98005e141925a2.zip | |
[libFuzzer] Optimize handle unstable checks by reducing iterations
Summary:
We only run the 3rd check if 2nd check finds unstable edges.
3rd UpdateUnstableCounters is now merged with ApplyUnstableCounters to only run 1 iteration.
Patch by Kyungtak Woo (@kevinwkt).
Reviewers: Dor1s, metzman, morehouse
Reviewed By: Dor1s, morehouse
Subscribers: delcypher, #sanitizers, llvm-commits, kcc
Differential Revision: https://reviews.llvm.org/D50411
llvm-svn: 339249
Diffstat (limited to 'compiler-rt/lib/fuzzer/FuzzerTracePC.cpp')
| -rw-r--r-- | compiler-rt/lib/fuzzer/FuzzerTracePC.cpp | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/compiler-rt/lib/fuzzer/FuzzerTracePC.cpp b/compiler-rt/lib/fuzzer/FuzzerTracePC.cpp index 7874f1315aa..1aba816e832 100644 --- a/compiler-rt/lib/fuzzer/FuzzerTracePC.cpp +++ b/compiler-rt/lib/fuzzer/FuzzerTracePC.cpp @@ -81,9 +81,11 @@ void TracePC::InitializeUnstableCounters() { // Compares the current counters with counters from previous runs // and records differences as unstable edges. -void TracePC::UpdateUnstableCounters(int UnstableMode) { +bool TracePC::UpdateUnstableCounters(int UnstableMode) { + bool Updated = false; IterateInline8bitCounters([&](int i, int j, int UnstableIdx) { if (ModuleCounters[i].Start[j] != UnstableCounters[UnstableIdx].Counter) { + Updated = true; UnstableCounters[UnstableIdx].IsUnstable = true; if (UnstableMode == ZeroUnstable) UnstableCounters[UnstableIdx].Counter = 0; @@ -92,12 +94,20 @@ void TracePC::UpdateUnstableCounters(int UnstableMode) { ModuleCounters[i].Start[j], UnstableCounters[UnstableIdx].Counter); } }); + return Updated; } -// Moves the minimum hit counts to ModuleCounters. -void TracePC::ApplyUnstableCounters() { +// Updates and applies unstable counters to ModuleCounters in single iteration +void TracePC::UpdateAndApplyUnstableCounters(int UnstableMode) { IterateInline8bitCounters([&](int i, int j, int UnstableIdx) { - ModuleCounters[i].Start[j] = UnstableCounters[UnstableIdx].Counter; + if (ModuleCounters[i].Start[j] != UnstableCounters[UnstableIdx].Counter) { + UnstableCounters[UnstableIdx].IsUnstable = true; + if (UnstableMode == ZeroUnstable) + ModuleCounters[i].Start[j] = 0; + else if (UnstableMode == MinUnstable) + ModuleCounters[i].Start[j] = std::min( + ModuleCounters[i].Start[j], UnstableCounters[UnstableIdx].Counter); + } }); } |

