Internals: Improve astgen type enums to be switch statement friendly (#6362)

- Remove _ENUM_END, so -Wswitch does not demand it's covered. Use the
  new NUM_TYPES constexpr member instead.
- Remove 'at' prefix. This seems historical and is not particularly  useful.
- Fix some cppcheck warts while at it
This commit is contained in:
Geza Lore
2025-09-03 13:56:11 +01:00
committed by GitHub
parent 8bf2240d40
commit 5161cea8cd
12 changed files with 119 additions and 124 deletions
+11 -9
View File
@@ -34,11 +34,11 @@ V3Mutex V3Stats::s_mutex;
class StatsVisitor final : public VNVisitorConst {
struct Counters final {
// Nodes of given type
std::array<uint64_t, VNType::_ENUM_END> m_statTypeCount = {};
std::array<uint64_t, VNType::NUM_TYPES()> m_statTypeCount{};
// Nodes of given type with given type immediate child
std::array<std::array<uint64_t, VNType::_ENUM_END>, VNType::_ENUM_END> m_statAbove = {};
std::array<std::array<uint64_t, VNType::NUM_TYPES()>, VNType::NUM_TYPES()> m_statAbove{};
// Prediction of given type
std::array<uint64_t, VBranchPred::_ENUM_END> m_statPred = {};
std::array<uint64_t, VBranchPred::_ENUM_END> m_statPred{};
};
// STATE
@@ -127,10 +127,12 @@ public:
}
// Node types (also total memory usage)
const auto typeName = [](int type) { return std::string{VNType{type}.ascii()}; };
const auto typeSize = [](int type) { return VNType{type}.typeInfo()->m_sizeof; };
const auto typeName
= [](size_t t) { return std::string{VNType{static_cast<VNType::en>(t)}.ascii()}; };
const auto typeSize
= [](size_t t) { return VNType::typeInfo(static_cast<VNType::en>(t)).m_sizeof; };
size_t totalNodeMemoryUsage = 0;
for (int t = 0; t < VNType::_ENUM_END; ++t) {
for (size_t t = 0; t < VNType::NUM_TYPES(); ++t) {
if (const uint64_t count = m_counters.m_statTypeCount[t]) {
totalNodeMemoryUsage += count * typeSize(t);
addStat("Node count, " + typeName(t), count);
@@ -139,7 +141,7 @@ public:
addStat("Node memory TOTAL (MiB)", totalNodeMemoryUsage >> 20);
// Node Memory usage
for (int t = 0; t < VNType::_ENUM_END; ++t) {
for (size_t t = 0; t < VNType::NUM_TYPES(); ++t) {
if (const uint64_t count = m_counters.m_statTypeCount[t]) {
const double share = 100.0 * count * typeSize(t) / totalNodeMemoryUsage;
addStat("Node memory share (%), " + typeName(t), share, 2);
@@ -147,8 +149,8 @@ public:
}
// Expression combinations
for (int t1 = 0; t1 < VNType::_ENUM_END; ++t1) {
for (int t2 = 0; t2 < VNType::_ENUM_END; ++t2) {
for (size_t t1 = 0; t1 < VNType::NUM_TYPES(); ++t1) {
for (size_t t2 = 0; t2 < VNType::NUM_TYPES(); ++t2) {
if (const uint64_t c = m_counters.m_statAbove[t1][t2]) {
addStat("Expr combination, " + typeName(t1) + " over " + typeName(t2), c);
}