]> granicus.if.org Git - llvm/commitdiff
[libFuzzer] simplify the value profiling callback further: don't use (idx MOD prime...
authorKostya Serebryany <kcc@google.com>
Fri, 27 Jan 2017 00:39:12 +0000 (00:39 +0000)
committerKostya Serebryany <kcc@google.com>
Fri, 27 Jan 2017 00:39:12 +0000 (00:39 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293239 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Fuzzer/FuzzerTracePC.cpp
lib/Fuzzer/FuzzerTracePC.h
lib/Fuzzer/FuzzerValueBitMap.h

index 6c1d1ffaf7d258c1910f21fd7a7211e576c63fa0..9981fc3459dc3ec7ffd43165800376198a72a617 100644 (file)
@@ -73,7 +73,7 @@ void TracePC::HandleCallerCallee(uintptr_t Caller, uintptr_t Callee) {
   const uintptr_t kBits = 12;
   const uintptr_t kMask = (1 << kBits) - 1;
   uintptr_t Idx = (Caller & kMask) | ((Callee & kMask) << kBits);
-  ValueProfileMap.AddValue(Idx);
+  ValueProfileMap.AddValueModPrime(Idx);
 }
 
 void TracePC::InitializePrintNewPCs() {
index b94aa63df62574a409a079d73d94ed2b6ad1ed01..0b666e1963d990539c9755c3af7a2fbeca97e86f 100644 (file)
@@ -47,7 +47,6 @@ struct TableOfRecentCompares {
 
 class TracePC {
  public:
-  static const size_t kFeatureSetSize = ValueBitMap::kNumberOfItems;
 
   void HandleTrace(uint32_t *guard, uintptr_t PC);
   void HandleInit(uint32_t *start, uint32_t *stop);
@@ -58,9 +57,6 @@ class TracePC {
   void SetUseValueProfile(bool VP) { UseValueProfile = VP; }
   void SetPrintNewPCs(bool P) { DoPrintNewPCs = P; }
   template <class Callback> size_t CollectFeatures(Callback CB);
-  bool UpdateValueProfileMap(ValueBitMap *MaxValueProfileMap) {
-    return UseValueProfile && MaxValueProfileMap->MergeFrom(ValueProfileMap);
-  }
 
   void ResetMaps() {
     ValueProfileMap.Reset();
index 22e06641fa170e629f231a77ff77582c294f07c4..68dc3a9fc3ac10589a69ce253b2afc0e385750fc 100644 (file)
@@ -18,12 +18,12 @@ namespace fuzzer {
 
 // A bit map containing kMapSizeInWords bits.
 struct ValueBitMap {
-  static const size_t kMapSizeInBits = 65371;        // Prime.
-  static const size_t kMapSizeInBitsAligned = 1 << 16; // 2^16
+  static const size_t kMapSizeInBits = 1 << 16;
+  static const size_t kMapPrimeMod = 65371;  // Largest Prime < kMapSizeInBits;
   static const size_t kBitsInWord = (sizeof(uintptr_t) * 8);
-  static const size_t kMapSizeInWords = kMapSizeInBitsAligned / kBitsInWord;
+  static const size_t kMapSizeInWords = kMapSizeInBits / kBitsInWord;
  public:
-  static const size_t kNumberOfItems = kMapSizeInBits;
+
   // Clears all bits.
   void Reset() { memset(Map, 0, sizeof(Map)); }
 
@@ -31,7 +31,7 @@ struct ValueBitMap {
   // Returns true if the bit was changed from 0 to 1.
   ATTRIBUTE_NO_SANITIZE_ALL
   inline bool AddValue(uintptr_t Value) {
-    uintptr_t Idx = Value < kMapSizeInBits ? Value : Value % kMapSizeInBits;
+    uintptr_t Idx = Value % kMapSizeInBits;
     uintptr_t WordIdx = Idx / kBitsInWord;
     uintptr_t BitIdx = Idx % kBitsInWord;
     uintptr_t Old = Map[WordIdx];
@@ -40,6 +40,11 @@ struct ValueBitMap {
     return New != Old;
   }
 
+  ATTRIBUTE_NO_SANITIZE_ALL
+  inline bool AddValueModPrime(uintptr_t Value) {
+    return AddValue(Value % kMapPrimeMod);
+  }
+
   inline bool Get(uintptr_t Idx) {
     assert(Idx < kMapSizeInBits);
     uintptr_t WordIdx = Idx / kBitsInWord;