aboutsummaryrefslogtreecommitdiffstats
path: root/kernel
diff options
context:
space:
mode:
authorRupert Swarbrick <rswarbrick@gmail.com>2020-05-26 15:19:39 +0100
committerRupert Swarbrick <rswarbrick@gmail.com>2020-05-26 16:07:36 +0100
commit7ff306ccdb47415e3a483adad87076327399434f (patch)
treeae3cf4771f7ba9174e48e0978fcedd36c1dff814 /kernel
parenta7f2ef6d34c4b336a910b3c6f3d2cc11da8a82b4 (diff)
downloadyosys-7ff306ccdb47415e3a483adad87076327399434f.tar.gz
yosys-7ff306ccdb47415e3a483adad87076327399434f.tar.bz2
yosys-7ff306ccdb47415e3a483adad87076327399434f.zip
Minor optimisation in Module::wire() and Module::cell()
The existing code does a search to figure out whether id is in the dict (with the call to count()), and then looks it up again to get the result (with the call to at()). This version calls find() instead, avoiding the double lookup. Code size increases slightly (6kb). I think this is because the contents of find() are getting inlined, and then inlined into lots of the callsites for cell() and wire(). Looking at the compiled code before this patch, you just get a (non-inlined) call to count() followed by a call to at(). After the patch, the contents of find() have been inlined (so you see do_hash, then do_lookup). The result for each function is about 30 bytes / 40% bigger, which presumably also enlarges call-sites that inline it.
Diffstat (limited to 'kernel')
-rw-r--r--kernel/rtlil.h10
1 files changed, 8 insertions, 2 deletions
diff --git a/kernel/rtlil.h b/kernel/rtlil.h
index 11c45bbec..76c5b5304 100644
--- a/kernel/rtlil.h
+++ b/kernel/rtlil.h
@@ -1134,8 +1134,14 @@ public:
return design->selected_member(name, member->name);
}
- RTLIL::Wire* wire(RTLIL::IdString id) { return wires_.count(id) ? wires_.at(id) : nullptr; }
- RTLIL::Cell* cell(RTLIL::IdString id) { return cells_.count(id) ? cells_.at(id) : nullptr; }
+ RTLIL::Wire* wire(RTLIL::IdString id) {
+ auto it = wires_.find(id);
+ return it == wires_.end() ? nullptr : it->second;
+ }
+ RTLIL::Cell* cell(RTLIL::IdString id) {
+ auto it = cells_.find(id);
+ return it == cells_.end() ? nullptr : it->second;
+ }
RTLIL::ObjRange<RTLIL::Wire*> wires() { return RTLIL::ObjRange<RTLIL::Wire*>(&wires_, &refcount_wires_); }
RTLIL::ObjRange<RTLIL::Cell*> cells() { return RTLIL::ObjRange<RTLIL::Cell*>(&cells_, &refcount_cells_); }