From b3f3f425771c1cc0c401528b067b9b7b33983ebb Mon Sep 17 00:00:00 2001 From: Robert O'Callahan Date: Tue, 14 Oct 2025 01:00:20 +0000 Subject: [PATCH] Remove StaticIdString and just use IdString now that we can make it constexpr --- kernel/rtlil.cc | 4 ---- kernel/rtlil.h | 45 +++++++++------------------------------------ 2 files changed, 9 insertions(+), 40 deletions(-) diff --git a/kernel/rtlil.cc b/kernel/rtlil.cc index 466ed0a74..6084dd03e 100644 --- a/kernel/rtlil.cc +++ b/kernel/rtlil.cc @@ -42,10 +42,6 @@ std::unordered_map RTLIL::IdString::global_refcount_storage_; std::vector RTLIL::IdString::global_free_idx_list_; #endif -#define X(_id) const RTLIL::OwningIdString RTLIL::IDInternal::_id(RTLIL::StaticId::_id); -#include "kernel/constids.inc" -#undef X - static void populate(std::string_view name) { if (name[1] == '$') { diff --git a/kernel/rtlil.h b/kernel/rtlil.h index a081762c9..2f7319d4a 100644 --- a/kernel/rtlil.h +++ b/kernel/rtlil.h @@ -121,20 +121,9 @@ namespace RTLIL struct Process; struct Binding; struct IdString; - struct StaticIdString; struct OwningIdString; typedef std::pair SigSig; - - struct StaticIdString { - constexpr StaticIdString(StaticId id, const OwningIdString &id_str) : id_str(id_str), id(id) {} - constexpr inline operator const OwningIdString &() const { return id_str; } - constexpr inline int index() const { return static_cast(id); } - constexpr inline const OwningIdString &id_string() const { return id_str; } - - const OwningIdString &id_str; - const StaticId id; - }; }; struct RTLIL::IdString @@ -247,13 +236,13 @@ struct RTLIL::IdString int index_; - inline IdString() : index_(0) { } + constexpr inline IdString() : index_(0) { } inline IdString(const char *str) : index_(insert(std::string_view(str))) { } - inline IdString(const IdString &str) : index_(str.index_) { } + constexpr inline IdString(const IdString &str) : index_(str.index_) { } inline IdString(IdString &&str) : index_(str.index_) { str.index_ = 0; } inline IdString(const std::string &str) : index_(insert(std::string_view(str))) { } inline IdString(std::string_view str) : index_(insert(str)) { } - inline IdString(StaticId id) : index_(static_cast(id)) {} + constexpr inline IdString(StaticId id) : index_(static_cast(id)) {} IdString &operator=(const IdString &rhs) = default; @@ -289,8 +278,6 @@ struct RTLIL::IdString inline bool operator==(const IdString &rhs) const { return index_ == rhs.index_; } inline bool operator!=(const IdString &rhs) const { return index_ != rhs.index_; } - inline bool operator==(const StaticIdString &rhs) const; - inline bool operator!=(const StaticIdString &rhs) const; // The methods below are just convenience functions for better compatibility with std::string. @@ -375,7 +362,6 @@ struct RTLIL::IdString } bool in(const IdString &rhs) const { return *this == rhs; } - bool in(const StaticIdString &rhs) const { return *this == rhs; } bool in(const char *rhs) const { return *this == rhs; } bool in(const std::string &rhs) const { return *this == rhs; } inline bool in(const pool &rhs) const; @@ -395,7 +381,6 @@ public: struct RTLIL::OwningIdString : public RTLIL::IdString { inline OwningIdString() { } - inline OwningIdString(const StaticIdString &str) : IdString(str) { } inline OwningIdString(const OwningIdString &str) : IdString(str) { get_reference(); } inline OwningIdString(const char *str) : IdString(str) { get_reference(); } inline OwningIdString(const IdString &str) : IdString(str) { get_reference(); } @@ -503,21 +488,9 @@ inline bool RTLIL::IdString::in(const pool &rhs) const { return rhs.co [[deprecated]] inline bool RTLIL::IdString::in(const pool &&rhs) const { return rhs.count(*this) != 0; } -inline bool RTLIL::IdString::operator==(const RTLIL::StaticIdString &rhs) const { - return index_ == rhs.index(); -} -inline bool RTLIL::IdString::operator!=(const RTLIL::StaticIdString &rhs) const { - return index_ != rhs.index(); -} - namespace RTLIL { - namespace IDInternal { -#define X(_id) extern const OwningIdString _id; -#include "kernel/constids.inc" -#undef X - } namespace ID { -#define X(_id) constexpr StaticIdString _id(StaticId::_id, IDInternal::_id); +#define X(_id) constexpr IdString _id(StaticId::_id); #include "kernel/constids.inc" #undef X } @@ -525,7 +498,7 @@ namespace RTLIL { struct IdTableEntry { const std::string_view name; - const RTLIL::StaticIdString static_id; + const RTLIL::IdString static_id; }; constexpr IdTableEntry IdTable[] = { @@ -558,15 +531,15 @@ constexpr int lookup_well_known_id(std::string_view name) // // sed -i.orig -r 's/"\\\\([a-zA-Z0-9_]+)"/ID(\1)/g; s/"(\$[a-zA-Z0-9_]+)"/ID(\1)/g;' // -typedef const RTLIL::IdString &IDMacroHelperFunc(); +typedef RTLIL::IdString IDMacroHelperFunc(); template struct IDMacroHelper { - static constexpr RTLIL::StaticIdString eval(IDMacroHelperFunc) { + static constexpr RTLIL::IdString eval(IDMacroHelperFunc) { return IdTable[IdTableIndex].static_id; } }; template <> struct IDMacroHelper<-1> { - static constexpr const RTLIL::IdString &eval(IDMacroHelperFunc func) { + static constexpr RTLIL::IdString eval(IDMacroHelperFunc func) { return func(); } }; @@ -576,7 +549,7 @@ template <> struct IDMacroHelper<-1> { YOSYS_NAMESPACE_PREFIX IDMacroHelper< \ YOSYS_NAMESPACE_PREFIX lookup_well_known_id(#_id) \ >::eval([]() \ - -> const YOSYS_NAMESPACE_PREFIX RTLIL::IdString & { \ + -> YOSYS_NAMESPACE_PREFIX RTLIL::IdString { \ const char *p = "\\" #_id, *q = p[1] == '$' ? p+1 : p; \ static const YOSYS_NAMESPACE_PREFIX RTLIL::IdString id = \ YOSYS_NAMESPACE_PREFIX RTLIL::OwningIdString::immortal(q); \