[Mlir-commits] [mlir] 67dc802 - [Support] Change TrackingStatistic and NoopStatistic to use uint64_t instead of unsigned.
Mingming Liu
llvmlistbot at llvm.org
Wed Jun 22 10:12:13 PDT 2022
Author: Mingming Liu
Date: 2022-06-22T10:11:40-07:00
New Revision: 67dc8021a1796cc84bd4c1e5983605323188ce9d
URL: https://github.com/llvm/llvm-project/commit/67dc8021a1796cc84bd4c1e5983605323188ce9d
DIFF: https://github.com/llvm/llvm-project/commit/67dc8021a1796cc84bd4c1e5983605323188ce9d.diff
LOG: [Support] Change TrackingStatistic and NoopStatistic to use uint64_t instead of unsigned.
Binary size of `clang` is trivial; namely, numerical value doesn't
change when measured in MiB, and `.data` section increases from 139Ki to
173 Ki.
Differential Revision: https://reviews.llvm.org/D128070
Added:
Modified:
llvm/include/llvm/ADT/Statistic.h
llvm/lib/Support/Statistic.cpp
llvm/lib/Transforms/Scalar/NewGVN.cpp
llvm/unittests/ADT/StatisticTest.cpp
mlir/lib/Pass/PassStatistics.cpp
polly/lib/Analysis/ScopDetection.cpp
polly/lib/Analysis/ScopInfo.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/ADT/Statistic.h b/llvm/include/llvm/ADT/Statistic.h
index c39e161bcbcdd..6c195cc44990b 100644
--- a/llvm/include/llvm/ADT/Statistic.h
+++ b/llvm/include/llvm/ADT/Statistic.h
@@ -53,7 +53,7 @@ class TrackingStatistic {
const char *const Name;
const char *const Desc;
- std::atomic<unsigned> Value;
+ std::atomic<uint64_t> Value;
std::atomic<bool> Initialized;
constexpr TrackingStatistic(const char *DebugType, const char *Name,
@@ -65,12 +65,12 @@ class TrackingStatistic {
const char *getName() const { return Name; }
const char *getDesc() const { return Desc; }
- unsigned getValue() const { return Value.load(std::memory_order_relaxed); }
+ uint64_t getValue() const { return Value.load(std::memory_order_relaxed); }
// Allow use of this class as the value itself.
- operator unsigned() const { return getValue(); }
+ operator uint64_t() const { return getValue(); }
- const TrackingStatistic &operator=(unsigned Val) {
+ const TrackingStatistic &operator=(uint64_t Val) {
Value.store(Val, std::memory_order_relaxed);
return init();
}
@@ -80,7 +80,7 @@ class TrackingStatistic {
return init();
}
- unsigned operator++(int) {
+ uint64_t operator++(int) {
init();
return Value.fetch_add(1, std::memory_order_relaxed);
}
@@ -90,27 +90,27 @@ class TrackingStatistic {
return init();
}
- unsigned operator--(int) {
+ uint64_t operator--(int) {
init();
return Value.fetch_sub(1, std::memory_order_relaxed);
}
- const TrackingStatistic &operator+=(unsigned V) {
+ const TrackingStatistic &operator+=(uint64_t V) {
if (V == 0)
return *this;
Value.fetch_add(V, std::memory_order_relaxed);
return init();
}
- const TrackingStatistic &operator-=(unsigned V) {
+ const TrackingStatistic &operator-=(uint64_t V) {
if (V == 0)
return *this;
Value.fetch_sub(V, std::memory_order_relaxed);
return init();
}
- void updateMax(unsigned V) {
- unsigned PrevMax = Value.load(std::memory_order_relaxed);
+ void updateMax(uint64_t V) {
+ uint64_t PrevMax = Value.load(std::memory_order_relaxed);
// Keep trying to update max until we succeed or another thread produces
// a bigger max than us.
while (V > PrevMax && !Value.compare_exchange_weak(
@@ -134,26 +134,26 @@ class NoopStatistic {
NoopStatistic(const char * /*DebugType*/, const char * /*Name*/,
const char * /*Desc*/) {}
- unsigned getValue() const { return 0; }
+ uint64_t getValue() const { return 0; }
// Allow use of this class as the value itself.
- operator unsigned() const { return 0; }
+ operator uint64_t() const { return 0; }
- const NoopStatistic &operator=(unsigned Val) { return *this; }
+ const NoopStatistic &operator=(uint64_t Val) { return *this; }
const NoopStatistic &operator++() { return *this; }
- unsigned operator++(int) { return 0; }
+ uint64_t operator++(int) { return 0; }
const NoopStatistic &operator--() { return *this; }
- unsigned operator--(int) { return 0; }
+ uint64_t operator--(int) { return 0; }
- const NoopStatistic &operator+=(const unsigned &V) { return *this; }
+ const NoopStatistic &operator+=(const uint64_t &V) { return *this; }
- const NoopStatistic &operator-=(const unsigned &V) { return *this; }
+ const NoopStatistic &operator-=(const uint64_t &V) { return *this; }
- void updateMax(unsigned V) {}
+ void updateMax(uint64_t V) {}
};
#if LLVM_ENABLE_STATS
@@ -200,7 +200,7 @@ void PrintStatisticsJSON(raw_ostream &OS);
/// during it's execution. It will return the value at the point that it is
/// read. However, it will prevent new statistics from registering until it
/// completes.
-const std::vector<std::pair<StringRef, unsigned>> GetStatistics();
+const std::vector<std::pair<StringRef, uint64_t>> GetStatistics();
/// Reset the statistics. This can be used to zero and de-register the
/// statistics in order to measure a compilation.
diff --git a/llvm/lib/Support/Statistic.cpp b/llvm/lib/Support/Statistic.cpp
index 95ee885d2f8f5..ec12118650c1b 100644
--- a/llvm/lib/Support/Statistic.cpp
+++ b/llvm/lib/Support/Statistic.cpp
@@ -192,7 +192,7 @@ void llvm::PrintStatistics(raw_ostream &OS) {
// Print all of the statistics.
for (TrackingStatistic *Stat : Stats.Stats)
- OS << format("%*u %-*s - %s\n", MaxValLen, Stat->getValue(),
+ OS << format("%*" PRIu64 " %-*s - %s\n", MaxValLen, Stat->getValue(),
MaxDebugTypeLen, Stat->getDebugType(), Stat->getDesc());
OS << '\n'; // Flush the output stream.
@@ -253,9 +253,9 @@ void llvm::PrintStatistics() {
#endif
}
-const std::vector<std::pair<StringRef, unsigned>> llvm::GetStatistics() {
+const std::vector<std::pair<StringRef, uint64_t>> llvm::GetStatistics() {
sys::SmartScopedLock<true> Reader(*StatLock);
- std::vector<std::pair<StringRef, unsigned>> ReturnStats;
+ std::vector<std::pair<StringRef, uint64_t>> ReturnStats;
for (const auto &Stat : StatInfo->statistics())
ReturnStats.emplace_back(Stat->getName(), Stat->getValue());
diff --git a/llvm/lib/Transforms/Scalar/NewGVN.cpp b/llvm/lib/Transforms/Scalar/NewGVN.cpp
index 302eec1bced89..703edba020562 100644
--- a/llvm/lib/Transforms/Scalar/NewGVN.cpp
+++ b/llvm/lib/Transforms/Scalar/NewGVN.cpp
@@ -3356,7 +3356,7 @@ void NewGVN::verifyStoreExpressions() const {
// instruction set, propagating value numbers, marking things touched, etc,
// until the set of touched instructions is completely empty.
void NewGVN::iterateTouchedInstructions() {
- unsigned int Iterations = 0;
+ uint64_t Iterations = 0;
// Figure out where touchedinstructions starts
int FirstInstr = TouchedInstructions.find_first();
// Nothing set, nothing to iterate, just return.
diff --git a/llvm/unittests/ADT/StatisticTest.cpp b/llvm/unittests/ADT/StatisticTest.cpp
index e5a0cad26d685..17d9911915550 100644
--- a/llvm/unittests/ADT/StatisticTest.cpp
+++ b/llvm/unittests/ADT/StatisticTest.cpp
@@ -11,7 +11,7 @@
#include "gtest/gtest.h"
using namespace llvm;
-using OptionalStatistic = Optional<std::pair<StringRef, unsigned>>;
+using OptionalStatistic = Optional<std::pair<StringRef, uint64_t>>;
namespace {
#define DEBUG_TYPE "unittest"
@@ -21,7 +21,7 @@ ALWAYS_ENABLED_STATISTIC(AlwaysCounter, "Counts things always");
#if LLVM_ENABLE_STATS
static void
-extractCounters(const std::vector<std::pair<StringRef, unsigned>> &Range,
+extractCounters(const std::vector<std::pair<StringRef, uint64_t>> &Range,
OptionalStatistic &S1, OptionalStatistic &S2) {
for (const auto &S : Range) {
if (S.first == "Counter")
@@ -36,20 +36,21 @@ TEST(StatisticTest, Count) {
EnableStatistics();
Counter = 0;
- EXPECT_EQ(Counter, 0u);
+ EXPECT_EQ(Counter, 0ull);
Counter++;
Counter++;
+ Counter += (std::numeric_limits<uint64_t>::max() - 3);
#if LLVM_ENABLE_STATS
- EXPECT_EQ(Counter, 2u);
+ EXPECT_EQ(Counter, std::numeric_limits<uint64_t>::max() - 1);
#else
- EXPECT_EQ(Counter, 0u);
+ EXPECT_EQ(Counter, UINT64_C(0));
#endif
AlwaysCounter = 0;
- EXPECT_EQ(AlwaysCounter, 0u);
+ EXPECT_EQ(AlwaysCounter, 0ull);
AlwaysCounter++;
++AlwaysCounter;
- EXPECT_EQ(AlwaysCounter, 2u);
+ EXPECT_EQ(AlwaysCounter, 2ull);
}
TEST(StatisticTest, Assign) {
diff --git a/mlir/lib/Pass/PassStatistics.cpp b/mlir/lib/Pass/PassStatistics.cpp
index 08b4a44004e57..4c14711a0a968 100644
--- a/mlir/lib/Pass/PassStatistics.cpp
+++ b/mlir/lib/Pass/PassStatistics.cpp
@@ -21,7 +21,7 @@ namespace {
/// Information pertaining to a specific statistic.
struct Statistic {
const char *name, *desc;
- unsigned value;
+ uint64_t value;
};
} // namespace
diff --git a/polly/lib/Analysis/ScopDetection.cpp b/polly/lib/Analysis/ScopDetection.cpp
index 9d7b4c44d4b88..e22f8bd41a1bf 100644
--- a/polly/lib/Analysis/ScopDetection.cpp
+++ b/polly/lib/Analysis/ScopDetection.cpp
@@ -1885,7 +1885,7 @@ static void updateLoopCountStatistic(ScopDetection::LoopStats Stats,
if (!OnlyProfitable) {
NumLoopsInScop += Stats.NumLoops;
MaxNumLoopsInScop =
- std::max(MaxNumLoopsInScop.getValue(), (unsigned)Stats.NumLoops);
+ std::max(MaxNumLoopsInScop.getValue(), (uint64_t)Stats.NumLoops);
if (Stats.MaxDepth == 0)
NumScopsDepthZero++;
else if (Stats.MaxDepth == 1)
@@ -1903,7 +1903,7 @@ static void updateLoopCountStatistic(ScopDetection::LoopStats Stats,
} else {
NumLoopsInProfScop += Stats.NumLoops;
MaxNumLoopsInProfScop =
- std::max(MaxNumLoopsInProfScop.getValue(), (unsigned)Stats.NumLoops);
+ std::max(MaxNumLoopsInProfScop.getValue(), (uint64_t)Stats.NumLoops);
if (Stats.MaxDepth == 0)
NumProfScopsDepthZero++;
else if (Stats.MaxDepth == 1)
diff --git a/polly/lib/Analysis/ScopInfo.cpp b/polly/lib/Analysis/ScopInfo.cpp
index ca81d43703a90..d8196c34a051d 100644
--- a/polly/lib/Analysis/ScopInfo.cpp
+++ b/polly/lib/Analysis/ScopInfo.cpp
@@ -2559,7 +2559,7 @@ void updateLoopCountStatistic(ScopDetection::LoopStats Stats,
NumScops++;
NumLoopsInScop += Stats.NumLoops;
MaxNumLoopsInScop =
- std::max(MaxNumLoopsInScop.getValue(), (unsigned)Stats.NumLoops);
+ std::max(MaxNumLoopsInScop.getValue(), (uint64_t)Stats.NumLoops);
if (Stats.MaxDepth == 0)
NumScopsDepthZero++;
More information about the Mlir-commits
mailing list