This is an archive of the discontinued LLVM Phabricator instance.

[Stats] Add ALWAYS_ENABLED_STATISTIC enabled regardless of LLVM_ENABLE_STATS.
ClosedPublic

Authored by vsapsai on Sep 30 2019, 4:09 PM.

Details

Summary

The intended usage is to measure relatively expensive operations. So the
cost of the statistic is negligible compared to the cost of a measured
operation and can be enabled all the time without impairing the
compilation time.

The change in clang is an example of where ALWAYS_ENABLED_STATISTIC can be
used. I'm also planning to add more stats for header search and modules.

rdar://problem/55715134

Diff Detail

Event Timeline

vsapsai created this revision.Sep 30 2019, 4:09 PM

On release build with assertions disabled and LLVM_ENABLE_STATS being 0 the impact on the compile time is the following

Metric: compile_time

Program                                        output0jM4H6 output_KEgWj diff  
 test-suite...tTests/2003-05-07-VarArgs.test     0.03         0.02       -25.2%
 test-suite...sts/2003-05-31-CastToBool.test     0.02         0.02       22.1% 
 test-suite...ing-flt/Equivalencing-flt.test     0.61         0.73       20.7% 
 test-suite...s/2009-12-07-StructReturn.test     0.02         0.02       17.1% 
 test-suite...ts/2003-07-06-IntOverflow.test     0.02         0.02       17.0% 
 test-suite...ts/block-copied-in-cxxobj.test     0.03         0.03       16.2% 
 test-suite...e/UnitTests/ObjC/messages.test     0.03         0.04       15.9% 
 test-suite...r-algebra/kernels/2mm/2mm.test     0.08         0.06       -14.7%
 test-suite.../instance-method-metadata.test     0.37         0.42       14.0% 
 test-suite...ource/UnitTests/printargs.test     0.02         0.02       12.4% 
 test-suite...itTests/2003-05-26-Shorts.test     0.02         0.02       -12.2%
 test-suite...-06-20-StaticBitfieldInit.test     0.02         0.02       12.2% 
 test-suite...tTests/2002-05-03-NotTest.test     0.02         0.02       11.5% 
 test-suite...tTests/C++11/stdthreadbug.test     0.28         0.26       -10.3%
 test-suite...e/Benchmarks/Misc/flops-7.test     0.03         0.02       -10.2%
 Geomean difference                                                       nan% 
       output0jM4H6  output_KEgWj        diff
count  542.000000    542.000000    424.000000
mean   0.550511      0.547688     -0.001379  
std    2.215555      2.205268      0.045026  
min    0.000000      0.000000     -0.252280  
25%    0.015875      0.016725     -0.021092  
50%    0.040950      0.040000     -0.000875  
75%    0.350750      0.355700      0.017304  
max    30.343300     30.326700     0.220588

To me it looks that the change in compile time is within the noise.

dsanders accepted this revision.Oct 1 2019, 11:39 AM

LGTM

llvm/include/llvm/ADT/Statistic.h
47

Do we actually need the common base class? I'm thinking that since NoopStatistic never registers (and can't because the interfaces to do so changed to TrackingStatistic*), then there's a good chance that nothing reads DebugType, Name, Desc, Value, Initialized and we might be able to save a little memory by eliminating them.

This revision is now accepted and ready to land.Oct 1 2019, 11:39 AM
vsapsai updated this revision to Diff 224235.Oct 9 2019, 6:59 PM
vsapsai marked an inline comment as done.
  • Address review comments.
vsapsai marked 2 inline comments as done.Oct 9 2019, 7:04 PM

Thanks for the review.

llvm/include/llvm/ADT/Statistic.h
47

Good point. I've tried to remove the common base class but we are reading Name and Desc at least in [FusionCandidate::reportInvalidCandidate](https://github.com/llvm/llvm-project/blob/d6e9e99cec95c83293c68d3b30534e34f53a1923/llvm/lib/Transforms/Scalar/LoopFuse.cpp#L339-L342) and [reportLoopFusion](https://github.com/llvm/llvm-project/blob/d6e9e99cec95c83293c68d3b30534e34f53a1923/llvm/lib/Transforms/Scalar/LoopFuse.cpp#L1326-L1331). So I've made StatisticBase to store only DebugType, Name, Desc and moved Value and Initialized to TrackingStatistic. It saves a little bit of memory and makes NoopStatistic::getValue() cheaper as we don't touch atomic.

This revision was automatically updated to reflect the committed changes.
vsapsai marked an inline comment as done.