#include "CtxInstrProfiling.h"
#include "sanitizer_common/sanitizer_allocator_internal.h"
#include "sanitizer_common/sanitizer_common.h"
#include "sanitizer_common/sanitizer_dense_map.h"
#include "sanitizer_common/sanitizer_libc.h"
#include "sanitizer_common/sanitizer_mutex.h"
#include "sanitizer_common/sanitizer_placement_new.h"
#include "sanitizer_common/sanitizer_thread_safety.h"
#include "sanitizer_common/sanitizer_vector.h"
#include <assert.h>
usingnamespace__ctx_profile;
namespace {
__sanitizer::SpinMutex AllContextsMutex;
SANITIZER_GUARDED_BY(AllContextsMutex)
__sanitizer::Vector<ContextRoot *> AllContextRoots;
ContextNode *markAsScratch(const ContextNode *Ctx) { … }
template <typename T> inline T consume(T &V) { … }
constexpr size_t kPower = …;
constexpr size_t kBuffSize = …;
size_t getArenaAllocSize(size_t Needed) { … }
bool validate(const ContextRoot *Root) { … }
inline ContextNode *allocContextNode(char *Place, GUID Guid,
uint32_t NrCounters, uint32_t NrCallsites,
ContextNode *Next = nullptr) { … }
void resetContextNode(ContextNode &Node) { … }
void onContextEnter(ContextNode &Node) { … }
}
__thread char __Buffer[kBuffSize] = …;
#define TheScratchContext …
__thread void *volatile __llvm_ctx_profile_expected_callee[2] = …;
__thread ContextNode **volatile __llvm_ctx_profile_callsite[2] = …;
__thread ContextRoot *volatile __llvm_ctx_profile_current_context_root = …;
Arena::Arena(uint32_t Size) : … { … }
Arena *Arena::allocateNewArena(size_t Size, Arena *Prev) { … }
void Arena::freeArenaList(Arena *&A) { … }
ContextNode *getCallsiteSlow(GUID Guid, ContextNode **InsertionPoint,
uint32_t NrCounters, uint32_t NrCallsites) { … }
ContextNode *__llvm_ctx_profile_get_context(void *Callee, GUID Guid,
uint32_t NrCounters,
uint32_t NrCallsites) { … }
void setupContext(ContextRoot *Root, GUID Guid, uint32_t NrCounters,
uint32_t NrCallsites) { … }
ContextNode *__llvm_ctx_profile_start_context(
ContextRoot *Root, GUID Guid, uint32_t Counters,
uint32_t Callsites) SANITIZER_NO_THREAD_SAFETY_ANALYSIS { … }
void __llvm_ctx_profile_release_context(ContextRoot *Root)
SANITIZER_NO_THREAD_SAFETY_ANALYSIS { … }
void __llvm_ctx_profile_start_collection() { … }
bool __llvm_ctx_profile_fetch(void *Data,
bool (*Writer)(void *W, const ContextNode &)) { … }
void __llvm_ctx_profile_free() { … }