summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorKostya Serebryany <kcc@google.com>2016-09-28 01:16:24 +0000
committerKostya Serebryany <kcc@google.com>2016-09-28 01:16:24 +0000
commit3ee6c213d68094295e76500bad816abbbd4e0fd2 (patch)
tree2e10be03689ad6f1570225a47a65ab2192cc90a6 /llvm/lib
parent69330e0bc5db222995ce99507d8fa52450e9fdc5 (diff)
downloadbcm5719-llvm-3ee6c213d68094295e76500bad816abbbd4e0fd2.tar.gz
bcm5719-llvm-3ee6c213d68094295e76500bad816abbbd4e0fd2.zip
[libFuzzer] speedup TracePC::FinalizeTrace
llvm-svn: 282562
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Fuzzer/FuzzerTracePC.cpp35
-rw-r--r--llvm/lib/Fuzzer/FuzzerTracePC.h2
2 files changed, 22 insertions, 15 deletions
diff --git a/llvm/lib/Fuzzer/FuzzerTracePC.cpp b/llvm/lib/Fuzzer/FuzzerTracePC.cpp
index d533eac1501..9789d5df852 100644
--- a/llvm/lib/Fuzzer/FuzzerTracePC.cpp
+++ b/llvm/lib/Fuzzer/FuzzerTracePC.cpp
@@ -70,20 +70,27 @@ void TracePC::ResetGuards() {
void TracePC::FinalizeTrace() {
if (TotalPCCoverage) {
- for (size_t Idx = 1, N = Min(kNumCounters, NumGuards + 1); Idx < N;
- Idx++) {
- uint8_t Counter = Counters[Idx];
- if (!Counter) continue;
- Counters[Idx] = 0;
- unsigned Bit = 0;
- /**/ if (Counter >= 128) Bit = 7;
- else if (Counter >= 32) Bit = 6;
- else if (Counter >= 16) Bit = 5;
- else if (Counter >= 8) Bit = 4;
- else if (Counter >= 4) Bit = 3;
- else if (Counter >= 3) Bit = 2;
- else if (Counter >= 2) Bit = 1;
- CounterMap.AddValue(Idx * 8 + Bit);
+ const size_t Step = 8;
+ assert(reinterpret_cast<uintptr_t>(Counters) % Step == 0);
+ size_t N = Min(kNumCounters, NumGuards + 1);
+ N = (N + Step - 1) & ~(Step - 1); // Round up.
+ for (size_t Idx = 0; Idx < N; Idx += Step) {
+ uint64_t Bundle = *reinterpret_cast<uint64_t*>(&Counters[Idx]);
+ if (!Bundle) continue;
+ for (size_t i = Idx; i < Idx + Step; i++) {
+ uint8_t Counter = (Bundle >> (i * 8)) & 0xff;
+ if (!Counter) continue;
+ Counters[i] = 0;
+ unsigned Bit = 0;
+ /**/ if (Counter >= 128) Bit = 7;
+ else if (Counter >= 32) Bit = 6;
+ else if (Counter >= 16) Bit = 5;
+ else if (Counter >= 8) Bit = 4;
+ else if (Counter >= 4) Bit = 3;
+ else if (Counter >= 3) Bit = 2;
+ else if (Counter >= 2) Bit = 1;
+ CounterMap.AddValue(i * 8 + Bit);
+ }
}
}
}
diff --git a/llvm/lib/Fuzzer/FuzzerTracePC.h b/llvm/lib/Fuzzer/FuzzerTracePC.h
index 47ba160df92..0f2b6a878c4 100644
--- a/llvm/lib/Fuzzer/FuzzerTracePC.h
+++ b/llvm/lib/Fuzzer/FuzzerTracePC.h
@@ -79,7 +79,7 @@ private:
size_t NumGuards = 0;
static const size_t kNumCounters = 1 << 14;
- uint8_t Counters[kNumCounters];
+ alignas(8) uint8_t Counters[kNumCounters];
static const size_t kNumPCs = 1 << 20;
uintptr_t PCs[kNumPCs];
OpenPOWER on IntegriCloud