From 57bd61f2a20b933184e4940c74d38b44d4c52a6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20H=C3=BCck?= Date: Mon, 3 Jan 2022 21:31:23 +0100 Subject: [PATCH] LLVM Statistics handling (#107) --- lib/passes/CMakeLists.txt | 2 +- lib/passes/TypeARTPass.cpp | 12 ++++++------ lib/passes/analysis/CMakeLists.txt | 5 ++++- lib/passes/analysis/MemInstFinder.cpp | 20 ++++++++++---------- 4 files changed, 21 insertions(+), 18 deletions(-) diff --git a/lib/passes/CMakeLists.txt b/lib/passes/CMakeLists.txt index 39163ed7..11a9ceae 100644 --- a/lib/passes/CMakeLists.txt +++ b/lib/passes/CMakeLists.txt @@ -34,7 +34,7 @@ add_library(typeart::TransformPass ALIAS ${TYPEART_PREFIX}_TransformPass) target_compile_definitions( ${TYPEART_PREFIX}_TransformPass PRIVATE LOG_LEVEL=${LOG_LEVEL} - $<$:LLVM_ENABLE_STATS> + $<$:LLVM_FORCE_ENABLE_STATS=1> ) target_project_compile_options(${TYPEART_PREFIX}_TransformPass) diff --git a/lib/passes/TypeARTPass.cpp b/lib/passes/TypeARTPass.cpp index aa7b1ed0..4c11cc0c 100644 --- a/lib/passes/TypeARTPass.cpp +++ b/lib/passes/TypeARTPass.cpp @@ -94,10 +94,10 @@ cl::opt ClCallFilterDeep("call-filter-deep", cl::opt ClFilterPointerStack("typeart-filter-pointer-alloca", cl::desc("Filter allocas of pointers."), cl::Hidden, cl::init(true)); -STATISTIC(NumInstrumentedMallocs, "Number of instrumented mallocs"); -STATISTIC(NumInstrumentedFrees, "Number of instrumented frees"); -STATISTIC(NumInstrumentedAlloca, "Number of instrumented (stack) allocas"); -STATISTIC(NumInstrumentedGlobal, "Number of instrumented globals"); +ALWAYS_ENABLED_STATISTIC(NumInstrumentedMallocs, "Number of instrumented mallocs"); +ALWAYS_ENABLED_STATISTIC(NumInstrumentedFrees, "Number of instrumented frees"); +ALWAYS_ENABLED_STATISTIC(NumInstrumentedAlloca, "Number of instrumented (stack) allocas"); +ALWAYS_ENABLED_STATISTIC(NumInstrumentedGlobal, "Number of instrumented globals"); namespace typeart::pass { @@ -120,7 +120,7 @@ TypeArtPass::TypeArtPass() : llvm::ModulePass(ID) { ClCallFilterCGFile}}; meminst_finder = analysis::create_finder(conf); - EnableStatistics(); + EnableStatistics(false); } void TypeArtPass::getAnalysisUsage(llvm::AnalysisUsage& info) const { @@ -228,7 +228,7 @@ bool TypeArtPass::doFinalization(Module&) { } else { LOG_FATAL("Failed writing type config to " << ClTypeFile.getValue() << ". Reason: " << error.message()); } - if (ClTypeArtStats && AreStatisticsEnabled()) { + if (ClTypeArtStats) { auto& out = llvm::errs(); printStats(out); } diff --git a/lib/passes/analysis/CMakeLists.txt b/lib/passes/analysis/CMakeLists.txt index b294ae7d..3b79acdc 100644 --- a/lib/passes/analysis/CMakeLists.txt +++ b/lib/passes/analysis/CMakeLists.txt @@ -18,7 +18,10 @@ target_link_libraries(${TYPEART_PREFIX}_MemInstFinder PUBLIC typeart::MemOpFilte target_compile_options(${TYPEART_PREFIX}_MemInstFinder PRIVATE "-fno-rtti") -target_compile_definitions(${TYPEART_PREFIX}_MemInstFinder PRIVATE LOG_LEVEL=${LOG_LEVEL}) +target_compile_definitions( + ${TYPEART_PREFIX}_MemInstFinder PRIVATE LOG_LEVEL=${LOG_LEVEL} + $<$:LLVM_FORCE_ENABLE_STATS=1> +) set_target_properties(${TYPEART_PREFIX}_MemInstFinder PROPERTIES POSITION_INDEPENDENT_CODE ON) diff --git a/lib/passes/analysis/MemInstFinder.cpp b/lib/passes/analysis/MemInstFinder.cpp index e9049c20..55d5603a 100644 --- a/lib/passes/analysis/MemInstFinder.cpp +++ b/lib/passes/analysis/MemInstFinder.cpp @@ -46,16 +46,16 @@ using namespace llvm; #define DEBUG_TYPE "MemInstFinder" -STATISTIC(NumDetectedHeap, "Number of detected heap allocs"); -STATISTIC(NumFilteredDetectedHeap, "Number of filtered heap allocs"); -STATISTIC(NumDetectedAllocs, "Number of detected allocs"); -STATISTIC(NumFilteredPointerAllocs, "Number of filtered pointer allocs"); -STATISTIC(NumCallFilteredAllocs, "Number of call filtered allocs"); -STATISTIC(NumFilteredMallocAllocs, "Number of filtered malloc-related allocs"); -STATISTIC(NumFilteredNonArrayAllocs, "Number of filtered non-array allocs"); -STATISTIC(NumDetectedGlobals, "Number of detected globals"); -STATISTIC(NumFilteredGlobals, "Number of filtered globals"); -STATISTIC(NumCallFilteredGlobals, "Number of filtered globals"); +ALWAYS_ENABLED_STATISTIC(NumDetectedHeap, "Number of detected heap allocs"); +ALWAYS_ENABLED_STATISTIC(NumFilteredDetectedHeap, "Number of filtered heap allocs"); +ALWAYS_ENABLED_STATISTIC(NumDetectedAllocs, "Number of detected allocs"); +ALWAYS_ENABLED_STATISTIC(NumFilteredPointerAllocs, "Number of filtered pointer allocs"); +ALWAYS_ENABLED_STATISTIC(NumCallFilteredAllocs, "Number of call filtered allocs"); +ALWAYS_ENABLED_STATISTIC(NumFilteredMallocAllocs, "Number of filtered malloc-related allocs"); +ALWAYS_ENABLED_STATISTIC(NumFilteredNonArrayAllocs, "Number of filtered non-array allocs"); +ALWAYS_ENABLED_STATISTIC(NumDetectedGlobals, "Number of detected globals"); +ALWAYS_ENABLED_STATISTIC(NumFilteredGlobals, "Number of filtered globals"); +ALWAYS_ENABLED_STATISTIC(NumCallFilteredGlobals, "Number of filtered globals"); namespace typeart::analysis {