From a6c96b986be313368b4fa03eba5cf6987448100c Mon Sep 17 00:00:00 2001 From: Clifford Wolf Date: Fri, 26 Dec 2014 10:53:21 +0100 Subject: [PATCH] Added Yosys::{dict,nodict,vector} container types --- backends/verilog/verilog_backend.cc | 2 +- frontends/ast/ast.cc | 2 +- frontends/ast/ast.h | 2 +- frontends/ilang/ilang_parser.y | 2 +- kernel/cost.h | 12 +- kernel/rtlil.cc | 100 +++-- kernel/rtlil.h | 620 ++++++++++++++++------------ kernel/yosys.h | 12 + passes/cmds/delete.cc | 8 +- passes/cmds/rename.cc | 8 +- passes/cmds/select.cc | 4 +- passes/cmds/setattr.cc | 2 +- passes/cmds/splitnets.cc | 2 +- passes/fsm/fsm_export.cc | 4 +- passes/hierarchy/hierarchy.cc | 4 +- passes/opt/opt_clean.cc | 2 +- passes/opt/opt_const.cc | 6 +- passes/opt/opt_share.cc | 18 +- passes/opt/wreduce.cc | 4 +- passes/techmap/extract.cc | 4 +- passes/techmap/techmap.cc | 8 +- 21 files changed, 495 insertions(+), 331 deletions(-) diff --git a/backends/verilog/verilog_backend.cc b/backends/verilog/verilog_backend.cc index 9e8342ab9..ffaf9ec07 100644 --- a/backends/verilog/verilog_backend.cc +++ b/backends/verilog/verilog_backend.cc @@ -246,7 +246,7 @@ void dump_sigspec(std::ostream &f, const RTLIL::SigSpec &sig) } } -void dump_attributes(std::ostream &f, std::string indent, std::map &attributes, char term = '\n') +void dump_attributes(std::ostream &f, std::string indent, dict &attributes, char term = '\n') { if (noattr) return; diff --git a/frontends/ast/ast.cc b/frontends/ast/ast.cc index 56ea64eff..0f79352f7 100644 --- a/frontends/ast/ast.cc +++ b/frontends/ast/ast.cc @@ -1018,7 +1018,7 @@ AstModule::~AstModule() } // create a new parametric module (when needed) and return the name of the generated module -RTLIL::IdString AstModule::derive(RTLIL::Design *design, std::map parameters) +RTLIL::IdString AstModule::derive(RTLIL::Design *design, dict parameters) { std::string stripped_name = name.str(); diff --git a/frontends/ast/ast.h b/frontends/ast/ast.h index 023755387..27cf0ef3d 100644 --- a/frontends/ast/ast.h +++ b/frontends/ast/ast.h @@ -268,7 +268,7 @@ namespace AST AstNode *ast; bool nolatches, nomem2reg, mem2reg, lib, noopt, icells, autowire; virtual ~AstModule(); - virtual RTLIL::IdString derive(RTLIL::Design *design, std::map parameters); + virtual RTLIL::IdString derive(RTLIL::Design *design, dict parameters); virtual RTLIL::Module *clone() const; }; diff --git a/frontends/ilang/ilang_parser.y b/frontends/ilang/ilang_parser.y index a5cc06898..4e0981b51 100644 --- a/frontends/ilang/ilang_parser.y +++ b/frontends/ilang/ilang_parser.y @@ -36,7 +36,7 @@ namespace ILANG_FRONTEND { RTLIL::Process *current_process; std::vector*> switch_stack; std::vector case_stack; - std::map attrbuf; + dict attrbuf; } using namespace ILANG_FRONTEND; YOSYS_NAMESPACE_END diff --git a/kernel/cost.h b/kernel/cost.h index 61a693b9c..1b4166e00 100644 --- a/kernel/cost.h +++ b/kernel/cost.h @@ -24,12 +24,12 @@ YOSYS_NAMESPACE_BEGIN -int get_cell_cost(RTLIL::Cell *cell, std::map *mod_cost_cache = nullptr); +int get_cell_cost(RTLIL::Cell *cell, dict *mod_cost_cache = nullptr); -int get_cell_cost(RTLIL::IdString type, const std::map ¶meters = std::map(), - RTLIL::Design *design = nullptr, std::map *mod_cost_cache = nullptr) +int get_cell_cost(RTLIL::IdString type, const dict ¶meters = dict(), + RTLIL::Design *design = nullptr, dict *mod_cost_cache = nullptr) { - static std::map gate_cost = { + static dict gate_cost = { { "$_BUF_", 1 }, { "$_NOT_", 2 }, { "$_AND_", 4 }, @@ -55,7 +55,7 @@ int get_cell_cost(RTLIL::IdString type, const std::mapattributes.count("\\cost")) return mod->attributes.at("\\cost").as_int(); - std::map local_mod_cost_cache; + dict local_mod_cost_cache; if (mod_cost_cache == nullptr) mod_cost_cache = &local_mod_cost_cache; @@ -74,7 +74,7 @@ int get_cell_cost(RTLIL::IdString type, const std::map *mod_cost_cache) +int get_cell_cost(RTLIL::Cell *cell, dict *mod_cost_cache) { return get_cell_cost(cell->type, cell->parameters, cell->module->design, mod_cost_cache); } diff --git a/kernel/rtlil.cc b/kernel/rtlil.cc index 0e8078df6..2d3d83f42 100644 --- a/kernel/rtlil.cc +++ b/kernel/rtlil.cc @@ -30,7 +30,7 @@ YOSYS_NAMESPACE_BEGIN RTLIL::IdString::destruct_guard_t RTLIL::IdString::destruct_guard; std::vector RTLIL::IdString::global_refcount_storage_; std::vector RTLIL::IdString::global_id_storage_; -std::map RTLIL::IdString::global_id_index_; +dict RTLIL::IdString::global_id_index_; std::vector RTLIL::IdString::global_free_idx_list_; RTLIL::Const::Const() @@ -464,7 +464,7 @@ RTLIL::Module::~Module() delete it->second; } -RTLIL::IdString RTLIL::Module::derive(RTLIL::Design*, std::map) +RTLIL::IdString RTLIL::Module::derive(RTLIL::Design*, dict) { log_error("Module `%s' is used with parameters but is not parametric!\n", id2cstr(name)); } @@ -480,7 +480,7 @@ namespace { { RTLIL::Module *module; RTLIL::Cell *cell; - std::set expected_params, expected_ports; + nodict expected_params, expected_ports; InternalCellChecker(RTLIL::Module *module, RTLIL::Cell *cell) : module(module), cell(cell) { } @@ -1132,7 +1132,7 @@ namespace { struct DeleteWireWorker { RTLIL::Module *module; - const std::set *wires_p; + const nodict *wires_p; void operator()(RTLIL::SigSpec &sig) { std::vector chunks = sig; @@ -1146,16 +1146,7 @@ namespace { }; } -#if 0 -void RTLIL::Module::remove(RTLIL::Wire *wire) -{ - std::setPort wires_; - wires_.insert(wire); - remove(wires_); -} -#endif - -void RTLIL::Module::remove(const std::set &wires) +void RTLIL::Module::remove(const nodict &wires) { log_assert(refcount_wires_ == 0); @@ -1811,7 +1802,7 @@ const RTLIL::SigSpec &RTLIL::Cell::getPort(RTLIL::IdString portname) const return connections_.at(portname); } -const std::map &RTLIL::Cell::connections() const +const dict &RTLIL::Cell::connections() const { return connections_; } @@ -2178,6 +2169,17 @@ RTLIL::SigSpec::SigSpec(std::vector bits) check(); } +RTLIL::SigSpec::SigSpec(nodict bits) +{ + cover("kernel.rtlil.sigspec.init.stdset_bits"); + + width_ = 0; + hash_ = 0; + for (auto &bit : bits) + append_bit(bit); + check(); +} + RTLIL::SigSpec::SigSpec(std::set bits) { cover("kernel.rtlil.sigspec.init.stdset_bits"); @@ -2306,7 +2308,7 @@ void RTLIL::SigSpec::replace(const RTLIL::SigSpec &pattern, const RTLIL::SigSpec pattern.unpack(); with.unpack(); - std::map rules; + dict rules; for (int i = 0; i < GetSize(pattern.bits_); i++) if (pattern.bits_[i].wire != NULL) @@ -2315,6 +2317,30 @@ void RTLIL::SigSpec::replace(const RTLIL::SigSpec &pattern, const RTLIL::SigSpec replace(rules, other); } +void RTLIL::SigSpec::replace(const dict &rules) +{ + replace(rules, this); +} + +void RTLIL::SigSpec::replace(const dict &rules, RTLIL::SigSpec *other) const +{ + cover("kernel.rtlil.sigspec.replace_dict"); + + log_assert(other != NULL); + log_assert(width_ == other->width_); + + unpack(); + other->unpack(); + + for (int i = 0; i < GetSize(bits_); i++) { + auto it = rules.find(bits_[i]); + if (it != rules.end()) + other->bits_[i] = it->second; + } + + other->check(); +} + void RTLIL::SigSpec::replace(const std::map &rules) { replace(rules, this); @@ -2322,7 +2348,7 @@ void RTLIL::SigSpec::replace(const std::map &rules void RTLIL::SigSpec::replace(const std::map &rules, RTLIL::SigSpec *other) const { - cover("kernel.rtlil.sigspec.replace"); + cover("kernel.rtlil.sigspec.replace_map"); log_assert(other != NULL); log_assert(width_ == other->width_); @@ -2352,22 +2378,22 @@ void RTLIL::SigSpec::remove(const RTLIL::SigSpec &pattern, RTLIL::SigSpec *other void RTLIL::SigSpec::remove2(const RTLIL::SigSpec &pattern, RTLIL::SigSpec *other) { - std::set pattern_bits = pattern.to_sigbit_set(); + nodict pattern_bits = pattern.to_sigbit_nodict(); remove2(pattern_bits, other); } -void RTLIL::SigSpec::remove(const std::set &pattern) +void RTLIL::SigSpec::remove(const nodict &pattern) { remove2(pattern, NULL); } -void RTLIL::SigSpec::remove(const std::set &pattern, RTLIL::SigSpec *other) const +void RTLIL::SigSpec::remove(const nodict &pattern, RTLIL::SigSpec *other) const { RTLIL::SigSpec tmp = *this; tmp.remove2(pattern, other); } -void RTLIL::SigSpec::remove2(const std::set &pattern, RTLIL::SigSpec *other) +void RTLIL::SigSpec::remove2(const nodict &pattern, RTLIL::SigSpec *other) { if (other) cover("kernel.rtlil.sigspec.remove_other"); @@ -2413,11 +2439,11 @@ void RTLIL::SigSpec::remove2(const std::set &pattern, RTLIL::SigS RTLIL::SigSpec RTLIL::SigSpec::extract(const RTLIL::SigSpec &pattern, const RTLIL::SigSpec *other) const { - std::set pattern_bits = pattern.to_sigbit_set(); + nodict pattern_bits = pattern.to_sigbit_nodict(); return extract(pattern_bits, other); } -RTLIL::SigSpec RTLIL::SigSpec::extract(const std::set &pattern, const RTLIL::SigSpec *other) const +RTLIL::SigSpec RTLIL::SigSpec::extract(const nodict &pattern, const RTLIL::SigSpec *other) const { if (other) cover("kernel.rtlil.sigspec.extract_other"); @@ -2917,6 +2943,18 @@ std::set RTLIL::SigSpec::to_sigbit_set() const return sigbits; } +nodict RTLIL::SigSpec::to_sigbit_nodict() const +{ + cover("kernel.rtlil.sigspec.to_sigbit_nodict"); + + pack(); + nodict sigbits; + for (auto &c : chunks_) + for (int i = 0; i < c.width; i++) + sigbits.insert(RTLIL::SigBit(c, i)); + return sigbits; +} + std::vector RTLIL::SigSpec::to_sigbit_vector() const { cover("kernel.rtlil.sigspec.to_sigbit_vector"); @@ -2941,6 +2979,22 @@ std::map RTLIL::SigSpec::to_sigbit_map(const RTLIL return new_map; } +dict RTLIL::SigSpec::to_sigbit_dict(const RTLIL::SigSpec &other) const +{ + cover("kernel.rtlil.sigspec.to_sigbit_dict"); + + unpack(); + other.unpack(); + + log_assert(width_ == other.width_); + + dict new_map; + for (int i = 0; i < width_; i++) + new_map[bits_[i]] = other.bits_[i]; + + return new_map; +} + RTLIL::SigBit RTLIL::SigSpec::to_single_sigbit() const { cover("kernel.rtlil.sigspec.to_single_sigbit"); diff --git a/kernel/rtlil.h b/kernel/rtlil.h index 99831244e..e684ba4ae 100644 --- a/kernel/rtlil.h +++ b/kernel/rtlil.h @@ -22,6 +22,27 @@ #ifndef RTLIL_H #define RTLIL_H +namespace std { + template<> struct hash { + size_t operator()(const Yosys::RTLIL::IdString &arg) const; + }; + template<> struct equal_to { + bool operator()(const Yosys::RTLIL::IdString &lhs, const Yosys::RTLIL::IdString &rhs) const; + }; + template<> struct hash { + size_t operator()(const Yosys::RTLIL::SigBit &arg) const; + }; + template<> struct equal_to { + bool operator()(const Yosys::RTLIL::SigBit &lhs, const Yosys::RTLIL::SigBit &rhs) const; + }; + template<> struct hash { + size_t operator()(const Yosys::RTLIL::SigSpec &arg) const; + }; + template<> struct equal_to { + bool operator()(const Yosys::RTLIL::SigSpec &lhs, const Yosys::RTLIL::SigSpec &rhs) const; + }; +} + YOSYS_NAMESPACE_BEGIN namespace RTLIL @@ -85,6 +106,24 @@ namespace RTLIL } }; + struct char_ptr_hash { + size_t operator()(const char *a) const { + size_t hash = 5381; + for (int c; (c = *a); a++) + hash = ((hash << 5) + hash) + c; /* hash * 33 + c */ + return hash; + } + }; + + struct char_ptr_eq { + bool operator()(const char *a, const char *b) const { + for (int i = 0; a[i] || b[i]; i++) + if (a[i] != b[i]) + return false; + return true; + } + }; + static struct destruct_guard_t { bool ok; // POD, will be initialized to zero destruct_guard_t() { ok = true; } @@ -93,7 +132,7 @@ namespace RTLIL static std::vector global_refcount_storage_; static std::vector global_id_storage_; - static std::map global_id_index_; + static dict global_id_index_; static std::vector global_free_idx_list_; static inline int get_reference(int idx) @@ -224,8 +263,8 @@ namespace RTLIL *this = IdString(); } - // The following is a helper key_compare class. Instead of for example std::set - // use std::set> if the order of cells in the + // The following is a helper key_compare class. Instead of for example nodict + // use nodict> if the order of cells in the // set has an influence on the algorithm. template struct compare_ptr_by_name { @@ -245,7 +284,7 @@ namespace RTLIL bool in(IdString rhs) { return *this == rhs; } bool in(const char *rhs) { return *this == rhs; } bool in(const std::string &rhs) { return *this == rhs; } - bool in(const std::set &rhs) { return rhs.count(*this) != 0; } + bool in(const nodict &rhs) { return rhs.count(*this) != 0; } }; static inline std::string escape_id(std::string str) { @@ -336,8 +375,8 @@ namespace RTLIL template struct ObjIterator { - typename std::map::iterator it; - std::map *list_p; + typename dict::iterator it; + dict *list_p; int *refcount_p; ObjIterator() : list_p(nullptr), refcount_p(nullptr) { @@ -401,7 +440,7 @@ namespace RTLIL template struct ObjRange { - std::map *list_p; + dict *list_p; int *refcount_p; ObjRange(decltype(list_p) list_p, int *refcount_p) : list_p(list_p), refcount_p(refcount_p) { } @@ -412,8 +451,8 @@ namespace RTLIL return list_p->size(); } - operator std::set() const { - std::set result; + operator nodict() const { + nodict result; for (auto &it : *list_p) result.insert(it.second); return result; @@ -427,7 +466,7 @@ namespace RTLIL return result; } - std::set to_set() const { return *this; } + nodict to_set() const { return *this; } std::vector to_vector() const { return *this; } }; }; @@ -457,11 +496,232 @@ struct RTLIL::Const inline int size() const { return bits.size(); } }; +struct RTLIL::SigChunk +{ + RTLIL::Wire *wire; + std::vector data; // only used if wire == NULL, LSB at index 0 + int width, offset; + + SigChunk(); + SigChunk(const RTLIL::Const &value); + SigChunk(RTLIL::Wire *wire); + SigChunk(RTLIL::Wire *wire, int offset, int width = 1); + SigChunk(const std::string &str); + SigChunk(int val, int width = 32); + SigChunk(RTLIL::State bit, int width = 1); + SigChunk(RTLIL::SigBit bit); + + RTLIL::SigChunk extract(int offset, int length) const; + + bool operator <(const RTLIL::SigChunk &other) const; + bool operator ==(const RTLIL::SigChunk &other) const; + bool operator !=(const RTLIL::SigChunk &other) const; +}; + +struct RTLIL::SigBit +{ + RTLIL::Wire *wire; + union { + RTLIL::State data; // used if wire == NULL + int offset; // used if wire != NULL + }; + + SigBit(); + SigBit(RTLIL::State bit); + SigBit(bool bit); + SigBit(RTLIL::Wire *wire); + SigBit(RTLIL::Wire *wire, int offset); + SigBit(const RTLIL::SigChunk &chunk); + SigBit(const RTLIL::SigChunk &chunk, int index); + SigBit(const RTLIL::SigSpec &sig); + + bool operator <(const RTLIL::SigBit &other) const; + bool operator ==(const RTLIL::SigBit &other) const; + bool operator !=(const RTLIL::SigBit &other) const; +}; + +struct RTLIL::SigSpecIterator : public std::iterator +{ + RTLIL::SigSpec *sig_p; + int index; + + inline RTLIL::SigBit &operator*() const; + inline bool operator!=(const RTLIL::SigSpecIterator &other) const { return index != other.index; } + inline bool operator==(const RTLIL::SigSpecIterator &other) const { return index == other.index; } + inline void operator++() { index++; } +}; + +struct RTLIL::SigSpecConstIterator : public std::iterator +{ + const RTLIL::SigSpec *sig_p; + int index; + + inline const RTLIL::SigBit &operator*() const; + inline bool operator!=(const RTLIL::SigSpecConstIterator &other) const { return index != other.index; } + inline bool operator==(const RTLIL::SigSpecIterator &other) const { return index == other.index; } + inline void operator++() { index++; } +}; + +struct RTLIL::SigSpec +{ +private: + int width_; + unsigned long hash_; + std::vector chunks_; // LSB at index 0 + std::vector bits_; // LSB at index 0 + + void pack() const; + void unpack() const; + void hash() const; + + inline bool packed() const { + return bits_.empty(); + } + + inline void inline_unpack() const { + if (!chunks_.empty()) + unpack(); + } + +public: + SigSpec(); + SigSpec(const RTLIL::SigSpec &other); + SigSpec(std::initializer_list parts); + const RTLIL::SigSpec &operator=(const RTLIL::SigSpec &other); + + SigSpec(const RTLIL::Const &value); + SigSpec(const RTLIL::SigChunk &chunk); + SigSpec(RTLIL::Wire *wire); + SigSpec(RTLIL::Wire *wire, int offset, int width = 1); + SigSpec(const std::string &str); + SigSpec(int val, int width = 32); + SigSpec(RTLIL::State bit, int width = 1); + SigSpec(RTLIL::SigBit bit, int width = 1); + SigSpec(std::vector chunks); + SigSpec(std::vector bits); + SigSpec(nodict bits); + SigSpec(std::set bits); + SigSpec(bool bit); + + SigSpec(RTLIL::SigSpec &&other) { + width_ = other.width_; + hash_ = other.hash_; + chunks_ = std::move(other.chunks_); + bits_ = std::move(other.bits_); + } + + const RTLIL::SigSpec &operator=(RTLIL::SigSpec &&other) { + width_ = other.width_; + hash_ = other.hash_; + chunks_ = std::move(other.chunks_); + bits_ = std::move(other.bits_); + return *this; + } + + size_t get_hash() const { + if (!hash_) hash(); + return hash_; + } + + inline const std::vector &chunks() const { pack(); return chunks_; } + inline const std::vector &bits() const { inline_unpack(); return bits_; } + + inline int size() const { return width_; } + inline bool empty() const { return width_ == 0; } + + inline RTLIL::SigBit &operator[](int index) { inline_unpack(); return bits_.at(index); } + inline const RTLIL::SigBit &operator[](int index) const { inline_unpack(); return bits_.at(index); } + + inline RTLIL::SigSpecIterator begin() { RTLIL::SigSpecIterator it; it.sig_p = this; it.index = 0; return it; } + inline RTLIL::SigSpecIterator end() { RTLIL::SigSpecIterator it; it.sig_p = this; it.index = width_; return it; } + + inline RTLIL::SigSpecConstIterator begin() const { RTLIL::SigSpecConstIterator it; it.sig_p = this; it.index = 0; return it; } + inline RTLIL::SigSpecConstIterator end() const { RTLIL::SigSpecConstIterator it; it.sig_p = this; it.index = width_; return it; } + + void sort(); + void sort_and_unify(); + + void replace(const RTLIL::SigSpec &pattern, const RTLIL::SigSpec &with); + void replace(const RTLIL::SigSpec &pattern, const RTLIL::SigSpec &with, RTLIL::SigSpec *other) const; + + void replace(const dict &rules); + void replace(const dict &rules, RTLIL::SigSpec *other) const; + + void replace(const std::map &rules); + void replace(const std::map &rules, RTLIL::SigSpec *other) const; + + void replace(int offset, const RTLIL::SigSpec &with); + + void remove(const RTLIL::SigSpec &pattern); + void remove(const RTLIL::SigSpec &pattern, RTLIL::SigSpec *other) const; + void remove2(const RTLIL::SigSpec &pattern, RTLIL::SigSpec *other); + + void remove(const nodict &pattern); + void remove(const nodict &pattern, RTLIL::SigSpec *other) const; + void remove2(const nodict &pattern, RTLIL::SigSpec *other); + + void remove(int offset, int length = 1); + void remove_const(); + + RTLIL::SigSpec extract(const RTLIL::SigSpec &pattern, const RTLIL::SigSpec *other = NULL) const; + RTLIL::SigSpec extract(const nodict &pattern, const RTLIL::SigSpec *other = NULL) const; + RTLIL::SigSpec extract(int offset, int length = 1) const; + + void append(const RTLIL::SigSpec &signal); + void append_bit(const RTLIL::SigBit &bit); + + void extend_xx(int width, bool is_signed = false); + void extend_u0(int width, bool is_signed = false); + + RTLIL::SigSpec repeat(int num) const; + + bool operator <(const RTLIL::SigSpec &other) const; + bool operator ==(const RTLIL::SigSpec &other) const; + inline bool operator !=(const RTLIL::SigSpec &other) const { return !(*this == other); } + + bool is_wire() const; + bool is_chunk() const; + + bool is_fully_const() const; + bool is_fully_def() const; + bool is_fully_undef() const; + bool has_marked_bits() const; + + bool as_bool() const; + int as_int(bool is_signed = false) const; + std::string as_string() const; + RTLIL::Const as_const() const; + RTLIL::Wire *as_wire() const; + RTLIL::SigChunk as_chunk() const; + + bool match(std::string pattern) const; + + std::set to_sigbit_set() const; + nodict to_sigbit_nodict() const; + std::vector to_sigbit_vector() const; + std::map to_sigbit_map(const RTLIL::SigSpec &other) const; + dict to_sigbit_dict(const RTLIL::SigSpec &other) const; + RTLIL::SigBit to_single_sigbit() const; + + static bool parse(RTLIL::SigSpec &sig, RTLIL::Module *module, std::string str); + static bool parse_sel(RTLIL::SigSpec &sig, RTLIL::Design *design, RTLIL::Module *module, std::string str); + static bool parse_rhs(const RTLIL::SigSpec &lhs, RTLIL::SigSpec &sig, RTLIL::Module *module, std::string str); + + operator std::vector() const { return chunks(); } + operator std::vector() const { return bits(); } + +#ifndef NDEBUG + void check() const; +#else + void check() const { } +#endif +}; + struct RTLIL::Selection { bool full_selection; - std::set selected_modules; - std::map> selected_members; + nodict selected_modules; + dict> selected_members; Selection(bool full = true) : full_selection(full) { } @@ -500,14 +760,14 @@ struct RTLIL::Monitor struct RTLIL::Design { - std::set monitors; - std::map scratchpad; + nodict monitors; + dict scratchpad; int refcount_modules_; - std::map modules_; + dict modules_; std::vector selection_stack; - std::map selection_vars; + dict selection_vars; std::string selected_active_module; Design(); @@ -569,7 +829,7 @@ struct RTLIL::Design }; #define RTLIL_ATTRIBUTE_MEMBERS \ - std::map attributes; \ + dict attributes; \ void set_bool_attribute(RTLIL::IdString id) { \ attributes[id] = RTLIL::Const(1); \ } \ @@ -587,24 +847,24 @@ protected: public: RTLIL::Design *design; - std::set monitors; + nodict monitors; int refcount_wires_; int refcount_cells_; - std::map wires_; - std::map cells_; + dict wires_; + dict cells_; std::vector connections_; RTLIL::IdString name; - std::set avail_parameters; - std::map memories; - std::map processes; + nodict avail_parameters; + dict memories; + dict processes; RTLIL_ATTRIBUTE_MEMBERS Module(); virtual ~Module(); - virtual RTLIL::IdString derive(RTLIL::Design *design, std::map parameters); + virtual RTLIL::IdString derive(RTLIL::Design *design, dict parameters); virtual size_t count_id(RTLIL::IdString id); virtual void check(); virtual void optimize(); @@ -641,7 +901,7 @@ public: RTLIL::ObjRange cells() { return RTLIL::ObjRange(&cells_, &refcount_cells_); } // Removing wires is expensive. If you have to remove wires, remove them all at once. - void remove(const std::set &wires); + void remove(const nodict &wires); void remove(RTLIL::Cell *cell); void rename(RTLIL::Wire *wire, RTLIL::IdString new_name); @@ -852,8 +1112,8 @@ public: RTLIL::Module *module; RTLIL::IdString name; RTLIL::IdString type; - std::map connections_; - std::map parameters; + dict connections_; + dict parameters; RTLIL_ATTRIBUTE_MEMBERS // access cell ports @@ -861,7 +1121,7 @@ public: void unsetPort(RTLIL::IdString portname); void setPort(RTLIL::IdString portname, RTLIL::SigSpec signal); const RTLIL::SigSpec &getPort(RTLIL::IdString portname) const; - const std::map &connections() const; + const dict &connections() const; // access cell parameters bool hasParam(RTLIL::IdString paramname) const; @@ -880,241 +1140,6 @@ public: template void rewrite_sigspecs(T functor); }; -struct RTLIL::SigChunk -{ - RTLIL::Wire *wire; - std::vector data; // only used if wire == NULL, LSB at index 0 - int width, offset; - - SigChunk(); - SigChunk(const RTLIL::Const &value); - SigChunk(RTLIL::Wire *wire); - SigChunk(RTLIL::Wire *wire, int offset, int width = 1); - SigChunk(const std::string &str); - SigChunk(int val, int width = 32); - SigChunk(RTLIL::State bit, int width = 1); - SigChunk(RTLIL::SigBit bit); - - RTLIL::SigChunk extract(int offset, int length) const; - - bool operator <(const RTLIL::SigChunk &other) const; - bool operator ==(const RTLIL::SigChunk &other) const; - bool operator !=(const RTLIL::SigChunk &other) const; -}; - -struct RTLIL::SigBit -{ - RTLIL::Wire *wire; - union { - RTLIL::State data; // used if wire == NULL - int offset; // used if wire != NULL - }; - - SigBit() : wire(NULL), data(RTLIL::State::S0) { } - SigBit(RTLIL::State bit) : wire(NULL), data(bit) { } - SigBit(bool bit) : wire(NULL), data(bit ? RTLIL::S1 : RTLIL::S0) { } - SigBit(RTLIL::Wire *wire) : wire(wire), offset(0) { log_assert(wire && wire->width == 1); } - SigBit(RTLIL::Wire *wire, int offset) : wire(wire), offset(offset) { log_assert(wire != nullptr); } - SigBit(const RTLIL::SigChunk &chunk) : wire(chunk.wire) { log_assert(chunk.width == 1); if (wire) offset = chunk.offset; else data = chunk.data[0]; } - SigBit(const RTLIL::SigChunk &chunk, int index) : wire(chunk.wire) { if (wire) offset = chunk.offset + index; else data = chunk.data[index]; } - SigBit(const RTLIL::SigSpec &sig); - - bool operator <(const RTLIL::SigBit &other) const { - if (wire == other.wire) - return wire ? (offset < other.offset) : (data < other.data); - if (wire != nullptr && other.wire != nullptr) - return wire->name < other.wire->name; - return wire < other.wire; - } - - bool operator ==(const RTLIL::SigBit &other) const { - return (wire == other.wire) && (wire ? (offset == other.offset) : (data == other.data)); - } - - bool operator !=(const RTLIL::SigBit &other) const { - return (wire != other.wire) || (wire ? (offset != other.offset) : (data != other.data)); - } -}; - -struct RTLIL::SigSpecIterator : public std::iterator -{ - RTLIL::SigSpec *sig_p; - int index; - - inline RTLIL::SigBit &operator*() const; - inline bool operator!=(const RTLIL::SigSpecIterator &other) const { return index != other.index; } - inline bool operator==(const RTLIL::SigSpecIterator &other) const { return index == other.index; } - inline void operator++() { index++; } -}; - -struct RTLIL::SigSpecConstIterator : public std::iterator -{ - const RTLIL::SigSpec *sig_p; - int index; - - inline const RTLIL::SigBit &operator*() const; - inline bool operator!=(const RTLIL::SigSpecConstIterator &other) const { return index != other.index; } - inline bool operator==(const RTLIL::SigSpecIterator &other) const { return index == other.index; } - inline void operator++() { index++; } -}; - -struct RTLIL::SigSpec -{ -private: - int width_; - unsigned long hash_; - std::vector chunks_; // LSB at index 0 - std::vector bits_; // LSB at index 0 - - void pack() const; - void unpack() const; - void hash() const; - - inline bool packed() const { - return bits_.empty(); - } - - inline void inline_unpack() const { - if (!chunks_.empty()) - unpack(); - } - -public: - SigSpec(); - SigSpec(const RTLIL::SigSpec &other); - SigSpec(std::initializer_list parts); - const RTLIL::SigSpec &operator=(const RTLIL::SigSpec &other); - - SigSpec(const RTLIL::Const &value); - SigSpec(const RTLIL::SigChunk &chunk); - SigSpec(RTLIL::Wire *wire); - SigSpec(RTLIL::Wire *wire, int offset, int width = 1); - SigSpec(const std::string &str); - SigSpec(int val, int width = 32); - SigSpec(RTLIL::State bit, int width = 1); - SigSpec(RTLIL::SigBit bit, int width = 1); - SigSpec(std::vector chunks); - SigSpec(std::vector bits); - SigSpec(std::set bits); - SigSpec(bool bit); - - SigSpec(RTLIL::SigSpec &&other) { - width_ = other.width_; - hash_ = other.hash_; - chunks_ = std::move(other.chunks_); - bits_ = std::move(other.bits_); - } - - const RTLIL::SigSpec &operator=(RTLIL::SigSpec &&other) { - width_ = other.width_; - hash_ = other.hash_; - chunks_ = std::move(other.chunks_); - bits_ = std::move(other.bits_); - return *this; - } - - inline const std::vector &chunks() const { pack(); return chunks_; } - inline const std::vector &bits() const { inline_unpack(); return bits_; } - - inline int size() const { return width_; } - inline bool empty() const { return width_ == 0; } - - inline RTLIL::SigBit &operator[](int index) { inline_unpack(); return bits_.at(index); } - inline const RTLIL::SigBit &operator[](int index) const { inline_unpack(); return bits_.at(index); } - - inline RTLIL::SigSpecIterator begin() { RTLIL::SigSpecIterator it; it.sig_p = this; it.index = 0; return it; } - inline RTLIL::SigSpecIterator end() { RTLIL::SigSpecIterator it; it.sig_p = this; it.index = width_; return it; } - - inline RTLIL::SigSpecConstIterator begin() const { RTLIL::SigSpecConstIterator it; it.sig_p = this; it.index = 0; return it; } - inline RTLIL::SigSpecConstIterator end() const { RTLIL::SigSpecConstIterator it; it.sig_p = this; it.index = width_; return it; } - - void sort(); - void sort_and_unify(); - - void replace(const RTLIL::SigSpec &pattern, const RTLIL::SigSpec &with); - void replace(const RTLIL::SigSpec &pattern, const RTLIL::SigSpec &with, RTLIL::SigSpec *other) const; - - void replace(const std::map &rules); - void replace(const std::map &rules, RTLIL::SigSpec *other) const; - - void replace(int offset, const RTLIL::SigSpec &with); - - void remove(const RTLIL::SigSpec &pattern); - void remove(const RTLIL::SigSpec &pattern, RTLIL::SigSpec *other) const; - void remove2(const RTLIL::SigSpec &pattern, RTLIL::SigSpec *other); - - void remove(const std::set &pattern); - void remove(const std::set &pattern, RTLIL::SigSpec *other) const; - void remove2(const std::set &pattern, RTLIL::SigSpec *other); - - void remove(int offset, int length = 1); - void remove_const(); - - RTLIL::SigSpec extract(const RTLIL::SigSpec &pattern, const RTLIL::SigSpec *other = NULL) const; - RTLIL::SigSpec extract(const std::set &pattern, const RTLIL::SigSpec *other = NULL) const; - RTLIL::SigSpec extract(int offset, int length = 1) const; - - void append(const RTLIL::SigSpec &signal); - void append_bit(const RTLIL::SigBit &bit); - - void extend_xx(int width, bool is_signed = false); - void extend_u0(int width, bool is_signed = false); - - RTLIL::SigSpec repeat(int num) const; - - bool operator <(const RTLIL::SigSpec &other) const; - bool operator ==(const RTLIL::SigSpec &other) const; - inline bool operator !=(const RTLIL::SigSpec &other) const { return !(*this == other); } - - bool is_wire() const; - bool is_chunk() const; - - bool is_fully_const() const; - bool is_fully_def() const; - bool is_fully_undef() const; - bool has_marked_bits() const; - - bool as_bool() const; - int as_int(bool is_signed = false) const; - std::string as_string() const; - RTLIL::Const as_const() const; - RTLIL::Wire *as_wire() const; - RTLIL::SigChunk as_chunk() const; - - bool match(std::string pattern) const; - - std::set to_sigbit_set() const; - std::vector to_sigbit_vector() const; - std::map to_sigbit_map(const RTLIL::SigSpec &other) const; - RTLIL::SigBit to_single_sigbit() const; - - static bool parse(RTLIL::SigSpec &sig, RTLIL::Module *module, std::string str); - static bool parse_sel(RTLIL::SigSpec &sig, RTLIL::Design *design, RTLIL::Module *module, std::string str); - static bool parse_rhs(const RTLIL::SigSpec &lhs, RTLIL::SigSpec &sig, RTLIL::Module *module, std::string str); - - operator std::vector() const { return chunks(); } - operator std::vector() const { return bits(); } - -#ifndef NDEBUG - void check() const; -#else - inline void check() const { } -#endif -}; - -inline RTLIL::SigBit &RTLIL::SigSpecIterator::operator*() const { - return (*sig_p)[index]; -} - -inline const RTLIL::SigBit &RTLIL::SigSpecConstIterator::operator*() const { - return (*sig_p)[index]; -} - -inline RTLIL::SigBit::SigBit(const RTLIL::SigSpec &sig) { - log_assert(sig.size() == 1 && sig.chunks().size() == 1); - *this = SigBit(sig.chunks().front()); -} - struct RTLIL::CaseRule { std::vector compare; @@ -1163,6 +1188,44 @@ struct RTLIL::Process RTLIL::Process *clone() const; }; + +inline RTLIL::SigBit::SigBit() : wire(NULL), data(RTLIL::State::S0) { } +inline RTLIL::SigBit::SigBit(RTLIL::State bit) : wire(NULL), data(bit) { } +inline RTLIL::SigBit::SigBit(bool bit) : wire(NULL), data(bit ? RTLIL::S1 : RTLIL::S0) { } +inline RTLIL::SigBit::SigBit(RTLIL::Wire *wire) : wire(wire), offset(0) { log_assert(wire && wire->width == 1); } +inline RTLIL::SigBit::SigBit(RTLIL::Wire *wire, int offset) : wire(wire), offset(offset) { log_assert(wire != nullptr); } +inline RTLIL::SigBit::SigBit(const RTLIL::SigChunk &chunk) : wire(chunk.wire) { log_assert(chunk.width == 1); if (wire) offset = chunk.offset; else data = chunk.data[0]; } +inline RTLIL::SigBit::SigBit(const RTLIL::SigChunk &chunk, int index) : wire(chunk.wire) { if (wire) offset = chunk.offset + index; else data = chunk.data[index]; } + +inline bool RTLIL::SigBit::operator<(const RTLIL::SigBit &other) const { + if (wire == other.wire) + return wire ? (offset < other.offset) : (data < other.data); + if (wire != nullptr && other.wire != nullptr) + return wire->name < other.wire->name; + return wire < other.wire; +} + +inline bool RTLIL::SigBit::operator==(const RTLIL::SigBit &other) const { + return (wire == other.wire) && (wire ? (offset == other.offset) : (data == other.data)); +} + +inline bool RTLIL::SigBit::operator!=(const RTLIL::SigBit &other) const { + return (wire != other.wire) || (wire ? (offset != other.offset) : (data != other.data)); +} + +inline RTLIL::SigBit &RTLIL::SigSpecIterator::operator*() const { + return (*sig_p)[index]; +} + +inline const RTLIL::SigBit &RTLIL::SigSpecConstIterator::operator*() const { + return (*sig_p)[index]; +} + +inline RTLIL::SigBit::SigBit(const RTLIL::SigSpec &sig) { + log_assert(sig.size() == 1 && sig.chunks().size() == 1); + *this = SigBit(sig.chunks().front()); +} + template void RTLIL::Module::rewrite_sigspecs(T functor) { @@ -1222,4 +1285,35 @@ void RTLIL::Process::rewrite_sigspecs(T functor) YOSYS_NAMESPACE_END +inline size_t std::hash::operator()(const Yosys::RTLIL::IdString &arg) const { + return arg.index_; +} + +inline bool std::equal_to::operator()(const Yosys::RTLIL::IdString &lhs, const Yosys::RTLIL::IdString &rhs) const { + return lhs.index_ == rhs.index_; +} + +inline size_t std::hash::operator()(const Yosys::RTLIL::SigBit &arg) const { + if (arg.wire) { + size_t hash = arg.wire->name.index_; + hash = ((hash << 5) + hash) + arg.offset; + return hash; + } + return arg.data; +} + +inline bool std::equal_to::operator()(const Yosys::RTLIL::SigBit &lhs, const Yosys::RTLIL::SigBit &rhs) const { + if (lhs.wire || rhs.wire) + return lhs.wire == rhs.wire && lhs.offset == rhs.offset; + return lhs.data == rhs.data; +} + +inline size_t std::hash::operator()(const Yosys::RTLIL::SigSpec &arg) const { + return arg.get_hash(); +} + +inline bool std::equal_to::operator()(const Yosys::RTLIL::SigSpec &lhs, const Yosys::RTLIL::SigSpec &rhs) const { + return lhs == rhs; +} + #endif diff --git a/kernel/yosys.h b/kernel/yosys.h index b64739ad4..5a6945c8f 100644 --- a/kernel/yosys.h +++ b/kernel/yosys.h @@ -45,6 +45,8 @@ #include #include #include +#include +#include #include #include @@ -122,8 +124,18 @@ YOSYS_NAMESPACE_BEGIN +template , class KeyEqual = std::equal_to> +using dict = std::unordered_map; + +template , class KeyEqual = std::equal_to> +using nodict = std::unordered_set; + +template +using vector = std::vector; + namespace RTLIL { struct IdString; + struct SigBit; struct SigSpec; struct Wire; struct Cell; diff --git a/passes/cmds/delete.cc b/passes/cmds/delete.cc index 8c3391e52..d7edcfbfc 100644 --- a/passes/cmds/delete.cc +++ b/passes/cmds/delete.cc @@ -91,10 +91,10 @@ struct DeletePass : public Pass { continue; } - std::set delete_wires; - std::set delete_cells; - std::set delete_procs; - std::set delete_mems; + nodict delete_wires; + nodict delete_cells; + nodict delete_procs; + nodict delete_mems; for (auto &it : module->wires_) if (design->selected(module, it.second)) diff --git a/passes/cmds/rename.cc b/passes/cmds/rename.cc index b2e10e557..8f24af278 100644 --- a/passes/cmds/rename.cc +++ b/passes/cmds/rename.cc @@ -118,7 +118,7 @@ struct RenamePass : public Pass { if (!design->selected(module)) continue; - std::map new_wires; + dict new_wires; for (auto &it : module->wires_) { if (it.first[0] == '$' && design->selected(module, it.second)) do it.second->name = stringf("\\%s%d%s", pattern_prefix.c_str(), counter++, pattern_suffix.c_str()); @@ -128,7 +128,7 @@ struct RenamePass : public Pass { module->wires_.swap(new_wires); module->fixup_ports(); - std::map new_cells; + dict new_cells; for (auto &it : module->cells_) { if (it.first[0] == '$' && design->selected(module, it.second)) do it.second->name = stringf("\\%s%d%s", pattern_prefix.c_str(), counter++, pattern_suffix.c_str()); @@ -149,7 +149,7 @@ struct RenamePass : public Pass { if (!design->selected(module)) continue; - std::map new_wires; + dict new_wires; for (auto &it : module->wires_) { if (design->selected(module, it.second)) if (it.first[0] == '\\' && it.second->port_id == 0) @@ -159,7 +159,7 @@ struct RenamePass : public Pass { module->wires_.swap(new_wires); module->fixup_ports(); - std::map new_cells; + dict new_cells; for (auto &it : module->cells_) { if (design->selected(module, it.second)) if (it.first[0] == '\\') diff --git a/passes/cmds/select.cc b/passes/cmds/select.cc index 7f841673f..91368f572 100644 --- a/passes/cmds/select.cc +++ b/passes/cmds/select.cc @@ -101,7 +101,7 @@ static bool match_attr_val(const RTLIL::Const &value, std::string pattern, char log_abort(); } -static bool match_attr(const std::map &attributes, std::string name_pat, std::string value_pat, char match_op) +static bool match_attr(const dict &attributes, std::string name_pat, std::string value_pat, char match_op) { if (name_pat.find('*') != std::string::npos || name_pat.find('?') != std::string::npos || name_pat.find('[') != std::string::npos) { for (auto &it : attributes) { @@ -119,7 +119,7 @@ static bool match_attr(const std::map &attributes return false; } -static bool match_attr(const std::map &attributes, std::string match_expr) +static bool match_attr(const dict &attributes, std::string match_expr) { size_t pos = match_expr.find_first_of(""); diff --git a/passes/cmds/setattr.cc b/passes/cmds/setattr.cc index 39c75c54e..9a6d8a038 100644 --- a/passes/cmds/setattr.cc +++ b/passes/cmds/setattr.cc @@ -50,7 +50,7 @@ struct setunset_t } }; -static void do_setunset(std::map &attrs, std::vector &list) +static void do_setunset(dict &attrs, std::vector &list) { for (auto &item : list) if (item.unset) diff --git a/passes/cmds/splitnets.cc b/passes/cmds/splitnets.cc index a6c9fe883..6c24a8e5f 100644 --- a/passes/cmds/splitnets.cc +++ b/passes/cmds/splitnets.cc @@ -176,7 +176,7 @@ struct SplitnetsPass : public Pass { module->rewrite_sigspecs(worker); - std::set delete_wires; + nodict delete_wires; for (auto &it : worker.splitmap) delete_wires.insert(it.first); module->remove(delete_wires); diff --git a/passes/fsm/fsm_export.cc b/passes/fsm/fsm_export.cc index 668fe8d1d..ad9270334 100644 --- a/passes/fsm/fsm_export.cc +++ b/passes/fsm/fsm_export.cc @@ -50,7 +50,7 @@ std::string kiss_convert_signal(const RTLIL::SigSpec &sig) { * @param cell pointer to the FSM cell which should be exported. */ void write_kiss2(struct RTLIL::Module *module, struct RTLIL::Cell *cell, std::string filename, bool origenc) { - std::map::iterator attr_it; + dict::iterator attr_it; FsmData fsm_data; FsmData::transition_t tr; std::ofstream kiss_file; @@ -145,7 +145,7 @@ struct FsmExportPass : public Pass { } virtual void execute(std::vector args, RTLIL::Design *design) { - std::map::iterator attr_it; + dict::iterator attr_it; std::string arg; bool flag_noauto = false; std::string filename; diff --git a/passes/hierarchy/hierarchy.cc b/passes/hierarchy/hierarchy.cc index e95947a92..66d660324 100644 --- a/passes/hierarchy/hierarchy.cc +++ b/passes/hierarchy/hierarchy.cc @@ -462,7 +462,7 @@ struct HierarchyPass : public Pass { log_cmd_error("Option -top requires an additional argument!\n"); top_mod = design->modules_.count(RTLIL::escape_id(args[argidx])) ? design->modules_.at(RTLIL::escape_id(args[argidx])) : NULL; if (top_mod == NULL && design->modules_.count("$abstract" + RTLIL::escape_id(args[argidx]))) { - std::map empty_parameters; + dict empty_parameters; design->modules_.at("$abstract" + RTLIL::escape_id(args[argidx]))->derive(design, empty_parameters); top_mod = design->modules_.count(RTLIL::escape_id(args[argidx])) ? design->modules_.at(RTLIL::escape_id(args[argidx])) : NULL; } @@ -560,7 +560,7 @@ struct HierarchyPass : public Pass { RTLIL::Cell *cell = work.second; log("Mapping positional arguments of cell %s.%s (%s).\n", RTLIL::id2cstr(module->name), RTLIL::id2cstr(cell->name), RTLIL::id2cstr(cell->type)); - std::map new_connections; + dict new_connections; for (auto &conn : cell->connections()) if (conn.first[0] == '$' && '0' <= conn.first[1] && conn.first[1] <= '9') { int id = atoi(conn.first.c_str()+1); diff --git a/passes/opt/opt_clean.cc b/passes/opt/opt_clean.cc index 8a20898cf..01acb5c04 100644 --- a/passes/opt/opt_clean.cc +++ b/passes/opt/opt_clean.cc @@ -262,7 +262,7 @@ void rmunused_module_signals(RTLIL::Module *module, bool purge_mode, bool verbos } - std::set del_wires; + nodict del_wires; int del_wires_count = 0; for (auto wire : maybe_del_wires) diff --git a/passes/opt/opt_const.cc b/passes/opt/opt_const.cc index 5bac76cf6..7f800bde9 100644 --- a/passes/opt/opt_const.cc +++ b/passes/opt/opt_const.cc @@ -196,11 +196,11 @@ void replace_const_cells(RTLIL::Design *design, RTLIL::Module *module, bool cons ct_combinational.setup_stdcells(); SigMap assign_map(module); - std::map invert_map; + dict invert_map; TopoSort> cells; - std::map> cell_to_inbit; - std::map> outbit_to_cell; + dict> cell_to_inbit; + dict> outbit_to_cell; for (auto cell : module->cells()) if (design->selected(module, cell) && cell->type[0] == '$') { diff --git a/passes/opt/opt_share.cc b/passes/opt/opt_share.cc index f8bc02205..c581b749e 100644 --- a/passes/opt/opt_share.cc +++ b/passes/opt/opt_share.cc @@ -41,7 +41,7 @@ struct OptShareWorker CellTypes ct; int total_count; #ifdef USE_CELL_HASH_CACHE - std::map cell_hash_cache; + dict cell_hash_cache; #endif #ifdef USE_CELL_HASH_CACHE @@ -67,8 +67,8 @@ struct OptShareWorker for (auto &it : cell->parameters) hash_string += "P " + it.first.str() + "=" + it.second.as_string() + "\n"; - const std::map *conn = &cell->connections(); - std::map alt_conn; + const dict *conn = &cell->connections(); + dict alt_conn; if (cell->type == "$and" || cell->type == "$or" || cell->type == "$xor" || cell->type == "$xnor" || cell->type == "$add" || cell->type == "$mul" || cell->type == "$logic_and" || cell->type == "$logic_or" || cell->type == "$_AND_" || cell->type == "$_OR_" || cell->type == "$_XOR_") { @@ -127,12 +127,14 @@ struct OptShareWorker #endif if (cell1->parameters != cell2->parameters) { - lt = cell1->parameters < cell2->parameters; + std::map p1(cell1->parameters.begin(), cell1->parameters.end()); + std::map p2(cell2->parameters.begin(), cell2->parameters.end()); + lt = p1 < p2; return true; } - std::map conn1 = cell1->connections(); - std::map conn2 = cell2->connections(); + dict conn1 = cell1->connections(); + dict conn2 = cell2->connections(); for (auto &it : conn1) { if (ct.cell_output(cell1->type, it.first)) @@ -171,7 +173,9 @@ struct OptShareWorker } if (conn1 != conn2) { - lt = conn1 < conn2; + std::map c1(conn1.begin(), conn1.end()); + std::map c2(conn2.begin(), conn2.end()); + lt = c1 < c2; return true; } diff --git a/passes/opt/wreduce.cc b/passes/opt/wreduce.cc index 8f59a041e..e8a38d212 100644 --- a/passes/opt/wreduce.cc +++ b/passes/opt/wreduce.cc @@ -28,11 +28,11 @@ PRIVATE_NAMESPACE_BEGIN struct WreduceConfig { - std::set supported_cell_types; + nodict supported_cell_types; WreduceConfig() { - supported_cell_types = std::set({ + supported_cell_types = nodict({ "$not", "$pos", "$neg", "$and", "$or", "$xor", "$xnor", "$shl", "$shr", "$sshl", "$sshr", "$shift", "$shiftx", diff --git a/passes/techmap/extract.cc b/passes/techmap/extract.cc index 994ef8f2a..ff99040e1 100644 --- a/passes/techmap/extract.cc +++ b/passes/techmap/extract.cc @@ -42,7 +42,7 @@ public: { } - bool compareAttributes(const std::set &attr, const std::map &needleAttr, const std::map &haystackAttr) + bool compareAttributes(const std::set &attr, const dict &needleAttr, const dict &haystackAttr) { for (auto &it : attr) { size_t nc = needleAttr.count(it), hc = haystackAttr.count(it); @@ -123,7 +123,7 @@ public: { RTLIL::Wire *lastNeedleWire = NULL; RTLIL::Wire *lastHaystackWire = NULL; - std::map emptyAttr; + dict emptyAttr; for (auto &conn : needleCell->connections()) { diff --git a/passes/techmap/techmap.cc b/passes/techmap/techmap.cc index 04d345d31..94dd4d42c 100644 --- a/passes/techmap/techmap.cc +++ b/passes/techmap/techmap.cc @@ -341,7 +341,7 @@ struct TechmapWorker { RTLIL::IdString derived_name = tpl_name; RTLIL::Module *tpl = map->modules_[tpl_name]; - std::map parameters = cell->parameters; + std::map parameters(cell->parameters.begin(), cell->parameters.end()); if (tpl->get_bool_attribute("\\blackbox")) continue; @@ -529,7 +529,7 @@ struct TechmapWorker tpl = techmap_cache[key]; } else { if (cell->parameters.size() != 0) { - derived_name = tpl->derive(map, parameters); + derived_name = tpl->derive(map, dict(parameters.begin(), parameters.end())); tpl = map->module(derived_name); log_continue = true; } @@ -975,7 +975,7 @@ struct TechmapPass : public Pass { Frontend::frontend_call(map, &f, fn, (fn.size() > 3 && fn.substr(fn.size()-3) == ".il") ? "ilang" : verilog_frontend); } - std::map modules_new; + dict modules_new; for (auto &it : map->modules_) { if (it.first.substr(0, 2) == "\\$") it.second->name = it.first.substr(1); @@ -1072,7 +1072,7 @@ struct FlattenPass : public Pass { log("No more expansions possible.\n"); if (top_mod != NULL) { - std::map new_modules; + dict new_modules; for (auto mod : design->modules()) if (mod == top_mod || mod->get_bool_attribute("\\blackbox")) { new_modules[mod->name] = mod; -- 2.30.2