12 #ifndef LLVM_FUZZER_TRACE_PC
13 #define LLVM_FUZZER_TRACE_PC
28 template<
class T,
size_t kSizeT>
30 static const size_t kSize = kSizeT;
60 return UseValueProfile && MaxValueProfileMap->
MergeFrom(ValueProfileMap);
64 ValueProfileMap.
Reset();
65 memset(Counters, 0,
sizeof(Counters));
96 bool UseCounters =
false;
97 bool UseValueProfile =
false;
98 bool DoPrintNewPCs =
false;
104 Module Modules[4096];
108 static const size_t kNumCounters = 1 << 14;
109 alignas(8) uint8_t Counters[kNumCounters];
111 static const size_t kNumPCs = 1 << 24;
112 uintptr_t PCs[kNumPCs];
114 std::set<uintptr_t> *PrintedPCs;
116 ValueBitMap ValueProfileMap;
119 template <
class Callback>
123 const size_t Step = 8;
124 assert(reinterpret_cast<uintptr_t>(Counters) % Step == 0);
125 size_t N =
Min(kNumCounters, NumGuards + 1);
126 N = (N + Step - 1) & ~(Step - 1);
127 for (
size_t Idx = 0; Idx <
N; Idx += Step) {
128 uint64_t Bundle = *
reinterpret_cast<uint64_t*
>(&Counters[Idx]);
129 if (!Bundle)
continue;
130 for (
size_t i = Idx;
i < Idx + Step;
i++) {
131 uint8_t
Counter = (Bundle >> ((
i - Idx) * 8)) & 0xff;
132 if (!Counter)
continue;
135 if (Counter >= 128) Bit = 7;
136 else if (Counter >= 32) Bit = 6;
137 else if (Counter >= 16) Bit = 5;
138 else if (Counter >= 8) Bit = 4;
139 else if (Counter >= 4) Bit = 3;
140 else if (Counter >= 3) Bit = 2;
141 else if (Counter >= 2) Bit = 1;
142 size_t Feature = (
i * 8 +
Bit);
148 ValueProfileMap.
ForEach([&](
size_t Idx) {
149 if (CB(NumGuards * 8 + Idx))
159 #endif // LLVM_FUZZER_TRACE_PC
void AddValueForStrcmp(void *caller_pc, const char *s1, const char *s2, size_t n)
void SetPrintNewPCs(bool P)
TableOfRecentCompares< uint32_t, kTORCSize > TORC4
void AddValueForMemcmp(void *caller_pc, const void *s1, const void *s2, size_t n)
void ForEach(Callback CB)
void HandleCallerCallee(uintptr_t Caller, uintptr_t Callee)
void HandleTrace(uint32_t *guard, uintptr_t PC)
static const size_t kSize
uintptr_t GetPC(size_t Idx)
bool AddValue(uintptr_t Value)
static const size_t kNumberOfItems
void UpdateFeatureSet(size_t CurrentElementIdx, size_t CurrentElementSize)
bool UpdateValueProfileMap(ValueBitMap *MaxValueProfileMap)
void HandleValueProfile(size_t Value)
size_t GetTotalPCCoverage()
void HandleCmp(void *PC, T Arg1, T Arg2)
void SetUseCounters(bool UC)
void HandleInit(uint32_t *start, uint32_t *stop)
void Insert(size_t Idx, T Arg1, T Arg2)
static const size_t kFeatureSetSize
bool UsingTracePcGuard() const
void InitializePrintNewPCs()
TableOfRecentCompares< uint64_t, kTORCSize > TORC8
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
void SetUseValueProfile(bool VP)
ATTRIBUTE_TARGET_POPCNT bool MergeFrom(ValueBitMap &Other)
size_t CollectFeatures(Callback CB)
static const size_t kTORCSize