3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2025-09-10 11:41:26 +00:00

Merge pull request #5323 from rocallahan/IdString-references

Pass `IdString` by reference in more places
This commit is contained in:
Jannis Harder 2025-09-08 20:40:24 +02:00 committed by GitHub
commit 3d14108a96
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 15 additions and 9 deletions

View file

@ -303,24 +303,24 @@ struct CellTypes
cell_types.clear(); cell_types.clear();
} }
bool cell_known(RTLIL::IdString type) const bool cell_known(const RTLIL::IdString &type) const
{ {
return cell_types.count(type) != 0; return cell_types.count(type) != 0;
} }
bool cell_output(RTLIL::IdString type, RTLIL::IdString port) const bool cell_output(const RTLIL::IdString &type, const RTLIL::IdString &port) const
{ {
auto it = cell_types.find(type); auto it = cell_types.find(type);
return it != cell_types.end() && it->second.outputs.count(port) != 0; return it != cell_types.end() && it->second.outputs.count(port) != 0;
} }
bool cell_input(RTLIL::IdString type, RTLIL::IdString port) const bool cell_input(const RTLIL::IdString &type, const RTLIL::IdString &port) const
{ {
auto it = cell_types.find(type); auto it = cell_types.find(type);
return it != cell_types.end() && it->second.inputs.count(port) != 0; return it != cell_types.end() && it->second.inputs.count(port) != 0;
} }
bool cell_evaluable(RTLIL::IdString type) const bool cell_evaluable(const RTLIL::IdString &type) const
{ {
auto it = cell_types.find(type); auto it = cell_types.find(type);
return it != cell_types.end() && it->second.is_evaluable; return it != cell_types.end() && it->second.is_evaluable;

View file

@ -188,6 +188,12 @@ template<typename P, typename Q> struct hash_ops<std::pair<P, Q>> {
return h; return h;
} }
HASH_TOP_LOOP_FST (const std::pair<P, Q> &a) HASH_TOP_LOOP_SND HASH_TOP_LOOP_FST (const std::pair<P, Q> &a) HASH_TOP_LOOP_SND
[[nodiscard]] static inline Hasher hash(const P &p, const Q &q) {
Hasher h;
h = hash_ops<P>::hash_into(p, h);
h = hash_ops<Q>::hash_into(q, h);
return h;
}
}; };
template<typename... T> struct hash_ops<std::tuple<T...>> { template<typename... T> struct hash_ops<std::tuple<T...>> {

View file

@ -411,7 +411,7 @@ struct RTLIL::IdString
// often one needs to check if a given IdString is part of a list (for example a list // often one needs to check if a given IdString is part of a list (for example a list
// of cell types). the following functions helps with that. // of cell types). the following functions helps with that.
template<typename... Args> template<typename... Args>
bool in(Args... args) const { bool in(const Args &... args) const {
return (... || in(args)); return (... || in(args));
} }
@ -430,10 +430,10 @@ namespace hashlib {
static inline bool cmp(const RTLIL::IdString &a, const RTLIL::IdString &b) { static inline bool cmp(const RTLIL::IdString &a, const RTLIL::IdString &b) {
return a == b; return a == b;
} }
[[nodiscard]] static inline Hasher hash(const RTLIL::IdString id) { [[nodiscard]] static inline Hasher hash(const RTLIL::IdString &id) {
return id.hash_top(); return id.hash_top();
} }
[[nodiscard]] static inline Hasher hash_into(const RTLIL::IdString id, Hasher h) { [[nodiscard]] static inline Hasher hash_into(const RTLIL::IdString &id, Hasher h) {
return id.hash_into(h); return id.hash_into(h);
} }
}; };

View file

@ -285,7 +285,7 @@ RTLIL::IdString new_id_suffix(std::string file, int line, std::string func, std:
// //
// sed -i.orig -r 's/"\\\\([a-zA-Z0-9_]+)"/ID(\1)/g; s/"(\$[a-zA-Z0-9_]+)"/ID(\1)/g;' <filename> // sed -i.orig -r 's/"\\\\([a-zA-Z0-9_]+)"/ID(\1)/g; s/"(\$[a-zA-Z0-9_]+)"/ID(\1)/g;' <filename>
// //
#define ID(_id) ([]() { const char *p = "\\" #_id, *q = p[1] == '$' ? p+1 : p; \ #define ID(_id) ([]() -> const RTLIL::IdString & { const char *p = "\\" #_id, *q = p[1] == '$' ? p+1 : p; \
static const YOSYS_NAMESPACE_PREFIX RTLIL::IdString id(q); return id; })() static const YOSYS_NAMESPACE_PREFIX RTLIL::IdString id(q); return id; })()
namespace ID = RTLIL::ID; namespace ID = RTLIL::ID;

View file

@ -107,7 +107,7 @@ struct OptMergeWorker
for (const auto& [port, sig] : cell->connections()) { for (const auto& [port, sig] : cell->connections()) {
if (cell->output(port)) if (cell->output(port))
continue; continue;
comm.eat(hash_ops<std::pair<IdString, SigSpec>>::hash({port, assign_map(sig)})); comm.eat(hash_ops<std::pair<IdString, SigSpec>>::hash(port, assign_map(sig)));
} }
h = comm.hash_into(h); h = comm.hash_into(h);
if (RTLIL::builtin_ff_cell_types().count(cell->type)) if (RTLIL::builtin_ff_cell_types().count(cell->type))