Changeset View
Changeset View
Standalone View
Standalone View
lib/esan/cache_frag.cpp
Show All 23 Lines | |||||
//===-- Struct field access counter runtime -------------------------------===// | //===-- Struct field access counter runtime -------------------------------===// | ||||
// This should be kept consistent with LLVM's EfficiencySanitizer StructInfo. | // This should be kept consistent with LLVM's EfficiencySanitizer StructInfo. | ||||
struct StructInfo { | struct StructInfo { | ||||
const char *StructName; | const char *StructName; | ||||
u32 Size; | u32 Size; | ||||
u32 NumFields; | u32 NumFields; | ||||
u32 *FieldOffsets; | u32 *FieldOffsets; | ||||
u32 *FieldSize; | |||||
u64 *FieldCounters; | u64 *FieldCounters; | ||||
const char **FieldTypeNames; | const char **FieldTypeNames; | ||||
}; | }; | ||||
// This should be kept consistent with LLVM's EfficiencySanitizer CacheFragInfo. | // This should be kept consistent with LLVM's EfficiencySanitizer CacheFragInfo. | ||||
// The tool-specific information per compilation unit (module). | // The tool-specific information per compilation unit (module). | ||||
struct CacheFragInfo { | struct CacheFragInfo { | ||||
const char *UnitName; | const char *UnitName; | ||||
▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | static void reportStructCounter(StructHashMap::Handle &Handle) { | ||||
} | } | ||||
// Remove the suffixes with '#' during print. | // Remove the suffixes with '#' during print. | ||||
end = strchr(start, '#'); | end = strchr(start, '#'); | ||||
CHECK(end != nullptr); | CHECK(end != nullptr); | ||||
Report(" %s %.*s\n", type, end - start, start); | Report(" %s %.*s\n", type, end - start, start); | ||||
Report(" size = %u, count = %llu, ratio = %llu\n", | Report(" size = %u, count = %llu, ratio = %llu\n", | ||||
Struct->Size, Handle->Count, Handle->Ratio); | Struct->Size, Handle->Count, Handle->Ratio); | ||||
for (u32 i = 0; i < Struct->NumFields; ++i) { | for (u32 i = 0; i < Struct->NumFields; ++i) { | ||||
Report(" #%2u: offset = %u,\t count = %llu,\t type = %s\n", i, | Report(" #%2u: offset = %u,\t size = %u,\t count = %llu,\t type = %s\n", i, | ||||
Struct->FieldOffsets[i], Struct->FieldCounters[i], | Struct->FieldOffsets[i], Struct->FieldSize[i], | ||||
Struct->FieldTypeNames[i]); | Struct->FieldCounters[i], Struct->FieldTypeNames[i]); | ||||
} | } | ||||
} | } | ||||
static void computeStructRatio(StructHashMap::Handle &Handle) { | static void computeStructRatio(StructHashMap::Handle &Handle) { | ||||
Handle->Ratio = 0; | Handle->Ratio = 0; | ||||
Handle->Count = Handle->Struct->FieldCounters[0]; | Handle->Count = Handle->Struct->FieldCounters[0]; | ||||
for (u32 i = 1; i < Handle->Struct->NumFields; ++i) { | for (u32 i = 1; i < Handle->Struct->NumFields; ++i) { | ||||
Handle->Count += Handle->Struct->FieldCounters[i]; | Handle->Count += Handle->Struct->FieldCounters[i]; | ||||
▲ Show 20 Lines • Show All 80 Lines • Show Last 20 Lines |