[PATCH] D101211: [ADT] Remove StatisticBase and make NoopStatistic empty

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 23 17:05:19 PDT 2021


MaskRay created this revision.
MaskRay added reviewers: bkramer, lattner, evgeny777, jyknight, reames, rupprecht, saugustine.
Herald added subscribers: dexonsmith, hiraditya.
MaskRay requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

In LLVM_ENABLE_STATS=0 builds, `Statistic` is `NoopStatistic` but has 3 unused
pointers. GlobalOpt considers that the pointers can potentially retain allocated
objects, so GlobalOpt cannot optimize out the `NoopStatistic` variables (see
D69428 <https://reviews.llvm.org/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 <https://reviews.llvm.org/D69428> (slightly smaller in both .bss and
.text).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D101211

Files:
  llvm/include/llvm/ADT/Statistic.h
  llvm/lib/Transforms/Scalar/LoopFuse.cpp


Index: llvm/lib/Transforms/Scalar/LoopFuse.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/LoopFuse.cpp
+++ llvm/lib/Transforms/Scalar/LoopFuse.cpp
@@ -372,11 +372,13 @@
   bool reportInvalidCandidate(llvm::Statistic &Stat) const {
     using namespace ore;
     assert(L && Preheader && "Fusion candidate not initialized properly!");
+#if LLVM_ENABLE_STATS
     ++Stat;
     ORE.emit(OptimizationRemarkAnalysis(DEBUG_TYPE, Stat.getName(),
                                         L->getStartLoc(), Preheader)
              << "[" << Preheader->getParent()->getName() << "]: "
              << "Loop is not a candidate for fusion: " << Stat.getDesc());
+#endif
     return false;
   }
 };
@@ -1533,6 +1535,7 @@
     assert(FC0.Preheader && FC1.Preheader &&
            "Expecting valid fusion candidates");
     using namespace ore;
+#if LLVM_ENABLE_STATS
     ++Stat;
     ORE.emit(RemarkKind(DEBUG_TYPE, Stat.getName(), FC0.L->getStartLoc(),
                         FC0.Preheader)
@@ -1540,6 +1543,7 @@
              << "]: " << NV("Cand1", StringRef(FC0.Preheader->getName()))
              << " and " << NV("Cand2", StringRef(FC1.Preheader->getName()))
              << ": " << Stat.getDesc());
+#endif
   }
 
   /// Fuse two guarded fusion candidates, creating a new fused loop.
Index: llvm/include/llvm/ADT/Statistic.h
===================================================================
--- llvm/include/llvm/ADT/Statistic.h
+++ llvm/include/llvm/ADT/Statistic.h
@@ -46,27 +46,22 @@
 class raw_fd_ostream;
 class StringRef;
 
-class StatisticBase {
+class TrackingStatistic {
 public:
-  const char *DebugType;
-  const char *Name;
-  const char *Desc;
+  const char *const DebugType;
+  const char *const Name;
+  const char *const Desc;
 
-  StatisticBase(const char *DebugType, const char *Name, const char *Desc)
-      : DebugType(DebugType), Name(Name), Desc(Desc) {}
-
-  const char *getDebugType() const { return DebugType; }
-  const char *getName() const { return Name; }
-  const char *getDesc() const { return Desc; }
-};
-
-class TrackingStatistic : public StatisticBase {
-public:
   std::atomic<unsigned> Value;
   std::atomic<bool> Initialized;
 
   TrackingStatistic(const char *DebugType, const char *Name, const char *Desc)
-      : StatisticBase(DebugType, Name, Desc), Value(0), Initialized(false) {}
+      : DebugType(DebugType), Name(Name), Desc(Desc), Value(0),
+        Initialized(false) {}
+
+  const char *getDebugType() const { return DebugType; }
+  const char *getName() const { return Name; }
+  const char *getDesc() const { return Desc; }
 
   unsigned getValue() const { return Value.load(std::memory_order_relaxed); }
 
@@ -132,9 +127,10 @@
   void RegisterStatistic();
 };
 
-class NoopStatistic : public StatisticBase {
+class NoopStatistic {
 public:
-  using StatisticBase::StatisticBase;
+  NoopStatistic(const char * /*DebugType*/, const char * /*Name*/,
+                const char * /*Desc*/) {}
 
   unsigned getValue() const { return 0; }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D101211.340205.patch
Type: text/x-patch
Size: 3050 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210424/683e4c32/attachment.bin>


More information about the llvm-commits mailing list