[all-commits] [llvm/llvm-project] 18839b: [ADT] Remove StatisticBase and make NoopStatistic ...

Fangrui Song via All-commits all-commits at lists.llvm.org
Mon Apr 26 16:47:50 PDT 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 18839be9c5c8b9f882dd241769784035b082d4e1
      https://github.com/llvm/llvm-project/commit/18839be9c5c8b9f882dd241769784035b082d4e1
  Author: Fangrui Song <i at maskray.me>
  Date:   2021-04-26 (Mon, 26 Apr 2021)

  Changed paths:
    M llvm/include/llvm/ADT/Statistic.h
    M llvm/lib/Transforms/Scalar/LoopFuse.cpp
    M mlir/include/mlir/Pass/Pass.h
    M mlir/lib/Pass/PassStatistics.cpp
    M mlir/test/Pass/pipeline-stats.mlir

  Log Message:
  -----------
  [ADT] Remove StatisticBase and make NoopStatistic empty

In LLVM_ENABLE_STATS=0 builds, `llvm::Statistic` maps to `llvm::NoopStatistic`
but has 3 mostly unused pointers. GlobalOpt considers that the pointers can
potentially retain allocated objects, so GlobalOpt cannot optimize out the
`NoopStatistic` variables (see D69428 for more context), wasting 23KiB for stage
2 clang.

This patch makes `NoopStatistic` empty and thus reclaims the wasted space.  The
clang size is even smaller than applying D69428 (slightly smaller in both .bss and
.text).
```
# This means the D69428 optimization on clang is mostly nullified by this patch.
HEAD+D69428: size(.bss) = 0x0725a8
HEAD+D101211: size(.bss) = 0x072238

# bloaty - HEAD+D69428 vs HEAD+D101211
# With D101211, we also save a lot of string table space (.rodata).
    FILE SIZE        VM SIZE
 --------------  --------------
  -0.0%     -32  -0.0%     -24    .eh_frame
  -0.0%    -336  [ = ]       0    .symtab
  -0.0%    -360  [ = ]       0    .strtab
  [ = ]       0  -0.2%    -880    .bss
  -0.0% -2.11Ki  -0.0% -2.11Ki    .rodata
  -0.0% -2.89Ki  -0.0% -2.89Ki    .text
  -0.0% -5.71Ki  -0.0% -5.88Ki    TOTAL
```

Note: LoopFuse is a disabled pass. For now this patch adds
`#if LLVM_ENABLE_STATS` so `OptimizationRemarkMissed` is skipped in
LLVM_ENABLE_STATS==0 builds.  If these `OptimizationRemarkMissed` are useful in
LLVM_ENABLE_STATS==0 builds, we can replace `llvm::Statistic` with
`llvm::TrackingStatistic`, or use a different abstraction to keep track of the strings.

Similarly, skip the code in `mlir/lib/Pass/PassStatistics.cpp` which
calls `getName`/`getDesc`/`getValue`.

Reviewed By: lattner

Differential Revision: https://reviews.llvm.org/D101211




More information about the All-commits mailing list