kernel: optimise Module::remove(const pool<RTLIL::Wire*>()
authorEddie Hung <eddie@fpgeh.com>
Thu, 12 Mar 2020 22:55:54 +0000 (15:55 -0700)
committerEddie Hung <eddie@fpgeh.com>
Thu, 12 Mar 2020 23:00:34 +0000 (16:00 -0700)
kernel/rtlil.cc
kernel/rtlil.h

index 06181b763a5ba9cfce83f1d0c9975d6acb1d7bcc..4ba66f26bdce4f53624d7c8d08c4bbb74ffbb3ab 100644 (file)
@@ -1586,30 +1586,25 @@ void RTLIL::Module::remove(const pool<RTLIL::Wire*> &wires)
                const pool<RTLIL::Wire*> *wires_p;
 
                void operator()(RTLIL::SigSpec &sig) {
-                       std::vector<RTLIL::SigChunk> chunks = sig;
-                       for (auto &c : chunks)
+                       for (auto &c : sig.chunks_)
                                if (c.wire != NULL && wires_p->count(c.wire)) {
                                        c.wire = module->addWire(NEW_ID, c.width);
                                        c.offset = 0;
                                }
-                       sig = chunks;
                }
 
                void operator()(RTLIL::SigSpec &lhs, RTLIL::SigSpec &rhs) {
                        log_assert(GetSize(lhs) == GetSize(rhs));
-                       RTLIL::SigSpec new_lhs, new_rhs;
+                       lhs.unpack();
+                       rhs.unpack();
                        for (int i = 0; i < GetSize(lhs); i++) {
-                               RTLIL::SigBit lhs_bit = lhs[i];
+                               RTLIL::SigBit &lhs_bit = lhs.bits_[i];
                                if (lhs_bit.wire != nullptr && wires_p->count(lhs_bit.wire))
                                        continue;
-                               RTLIL::SigBit rhs_bit = rhs[i];
+                               RTLIL::SigBit &rhs_bit = rhs.bits_[i];
                                if (rhs_bit.wire != nullptr && wires_p->count(rhs_bit.wire))
                                        continue;
-                               new_lhs.append(lhs_bit);
-                               new_rhs.append(rhs_bit);
                        }
-                       lhs = new_lhs;
-                       rhs = new_rhs;
                }
        };
 
index 58c5d9674b247c52eb818eafaf57d3fa84753c27..451bdd7b6b0125fb5404076fbf1968250ec005f7 100644 (file)
@@ -758,6 +758,10 @@ private:
                        unpack();
        }
 
+       // Only used by Module::remove(const pool<Wire*> &wires)
+       // but cannot be more specific as it isn't yet declared
+       friend struct RTLIL::Module;
+
 public:
        SigSpec();
        SigSpec(const RTLIL::SigSpec &other);