diff --git a/llvm/include/llvm/ADT/Statistic.h b/llvm/include/llvm/ADT/Statistic.h index de7dabc382c37..aa338ccff19a6 100644 --- a/llvm/include/llvm/ADT/Statistic.h +++ b/llvm/include/llvm/ADT/Statistic.h @@ -46,22 +46,27 @@ class raw_ostream; class raw_fd_ostream; class StringRef; -class TrackingStatistic { +class StatisticBase { public: - const char *const DebugType; - const char *const Name; - const char *const Desc; + const char *DebugType; + const char *Name; + const char *Desc; - std::atomic Value; - std::atomic Initialized; - - TrackingStatistic(const char *DebugType, const char *Name, const char *Desc) - : DebugType(DebugType), Name(Name), Desc(Desc), Value(0), - Initialized(false) {} + 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 Value; + std::atomic Initialized; + + TrackingStatistic(const char *DebugType, const char *Name, const char *Desc) + : StatisticBase(DebugType, Name, Desc), Value(0), Initialized(false) {} unsigned getValue() const { return Value.load(std::memory_order_relaxed); } @@ -127,10 +132,9 @@ class TrackingStatistic { void RegisterStatistic(); }; -class NoopStatistic { +class NoopStatistic : public StatisticBase { public: - NoopStatistic(const char * /*DebugType*/, const char * /*Name*/, - const char * /*Desc*/) {} + using StatisticBase::StatisticBase; unsigned getValue() const { return 0; } diff --git a/llvm/lib/Transforms/Scalar/LoopFuse.cpp b/llvm/lib/Transforms/Scalar/LoopFuse.cpp index ca19913e37ee1..63f02d0269160 100644 --- a/llvm/lib/Transforms/Scalar/LoopFuse.cpp +++ b/llvm/lib/Transforms/Scalar/LoopFuse.cpp @@ -372,13 +372,11 @@ struct FusionCandidate { 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; } }; @@ -1535,7 +1533,6 @@ struct LoopFuser { 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) @@ -1543,7 +1540,6 @@ struct LoopFuser { << "]: " << 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.