diff --git a/Changelog.Debian b/Changelog.Debian index 8cea81741..4f8419b5b 100644 --- a/Changelog.Debian +++ b/Changelog.Debian @@ -2,7 +2,63 @@ klayout (0.27-1) unstable; urgency=low * NOT RELEASED YET - -- Matthias Köfferlein Sun, 05 Apr 2020 13:30:58 +0200 + -- Matthias Köfferlein Wed, 21 Apr 2021 21:39:50 +0200 + +klayout (0.26.12-1) unstable; urgency=low + + * New features and bugfixes + - See changelog + + -- Matthias Köfferlein Wed, 21 Apr 2021 21:39:50 +0200 + +klayout (0.26.11-1) unstable; urgency=low + + * New features and bugfixes + - See changelog + + -- Matthias Köfferlein Thu, 25 Feb 2021 22:06:53 +0100 + +klayout (0.26.10-1) unstable; urgency=low + + * New features and bugfixes + - See changelog + + -- Matthias Köfferlein Tue, 02 Feb 2021 22:54:19 +0100 + +klayout (0.26.9-1) unstable; urgency=low + + * New features and bugfixes + - See changelog + + -- Matthias Köfferlein Fri, 27 Nov 2020 18:38:20 +0100 + +klayout (0.26.8-1) unstable; urgency=low + + * New features and bugfixes + - See changelog + + -- Matthias Köfferlein Mon, 14 Sep 2020 20:30:57 +0200 + +klayout (0.26.7-1) unstable; urgency=low + + * New features and bugfixes + - See changelog + + -- Matthias Köfferlein Tue, 07 Jul 2020 18:27:53 +0200 + +klayout (0.26.6-1) unstable; urgency=low + + * New features and bugfixes + - See changelog + + -- Matthias Köfferlein Thu, 28 May 2020 00:39:24 +0200 + +klayout (0.26.5-1) unstable; urgency=low + + * New features and bugfixes + - See changelog + + -- Matthias Köfferlein Sat, 02 May 2020 13:26:24 +0200 klayout (0.26.4-1) unstable; urgency=low diff --git a/src/db/db/dbCell.cc b/src/db/db/dbCell.cc index c2e362906..c4a81f4f5 100644 --- a/src/db/db/dbCell.cc +++ b/src/db/db/dbCell.cc @@ -598,15 +598,7 @@ Cell::mem_stat (MemStatistics *stat, MemStatistics::purpose_t purpose, int cat, } db::mem_stat (stat, purpose, cat, m_bboxes, true, (void *) this); db::mem_stat (stat, MemStatistics::Instances, cat, m_instances, true, (void *) this); - - // iterate the shapes separately so we can use the layer for the category - for (shapes_map::const_iterator i = m_shapes_map.begin (); i != m_shapes_map.end (); ++i) { - db::mem_stat (stat, MemStatistics::ShapesInfo, (int) i->first, i->first, false, (void *) this); - db::mem_stat (stat, MemStatistics::ShapesInfo, (int) i->first, i->second, false, (void *) this); -#ifdef __GNUCC__ - stat->add (std::_Rb_tree_node_base, (void *) &i->first, sizeof (std::_Rb_tree_node_base), sizeof (std::_Rb_tree_node_base), (void *) &v, purpose, cat); -#endif - } + db::mem_stat (stat, MemStatistics::ShapesInfo, cat, m_shapes_map, true, (void *) this); } void diff --git a/src/db/db/dbCircuit.h b/src/db/db/dbCircuit.h index a33be121f..b1124a6cf 100644 --- a/src/db/db/dbCircuit.h +++ b/src/db/db/dbCircuit.h @@ -31,6 +31,7 @@ #include "dbSubCircuit.h" #include "dbNetlistUtils.h" #include "dbPolygon.h" +#include "dbMemStatistics.h" #include "tlObject.h" #include "tlObjectCollection.h" @@ -749,6 +750,32 @@ public: */ void blank (); + /** + * @brief Generate memory statistics + */ + void mem_stat (MemStatistics *stat, MemStatistics::purpose_t purpose, int cat, bool no_self = false, void *parent = 0) const + { + if (! no_self) { + stat->add (typeid (*this), (void *) this, sizeof (*this), sizeof (*this), parent, purpose, cat); + } + + db::mem_stat (stat, purpose, cat, m_name, true, (void *) this); + db::mem_stat (stat, purpose, cat, m_boundary, true, (void *) this); + db::mem_stat (stat, purpose, cat, m_nets, true, (void *) this); + db::mem_stat (stat, purpose, cat, m_pins, true, (void *) this); + db::mem_stat (stat, purpose, cat, m_pin_by_id, true, (void *) this); + db::mem_stat (stat, purpose, cat, m_devices, true, (void *) this); + db::mem_stat (stat, purpose, cat, m_subcircuits, true, (void *) this); + db::mem_stat (stat, purpose, cat, m_pin_refs, true, (void *) this); + db::mem_stat (stat, purpose, cat, m_device_by_id, true, (void *) this); + db::mem_stat (stat, purpose, cat, m_subcircuit_by_id, true, (void *) this); + db::mem_stat (stat, purpose, cat, m_net_by_cluster_id, true, (void *) this); + db::mem_stat (stat, purpose, cat, m_device_by_name, true, (void *) this); + db::mem_stat (stat, purpose, cat, m_subcircuit_by_name, true, (void *) this); + db::mem_stat (stat, purpose, cat, m_net_by_name, true, (void *) this); + db::mem_stat (stat, purpose, cat, m_refs, true, (void *) this); + } + private: friend class Netlist; friend class Net; @@ -798,6 +825,14 @@ private: void nets_changed (); }; +/** + * @brief Memory statistics for Circuit + */ +inline void mem_stat (MemStatistics *stat, MemStatistics::purpose_t purpose, int cat, const Circuit &x, bool no_self, void *parent) +{ + x.mem_stat (stat, purpose, cat, no_self, parent); +} + } #endif diff --git a/src/db/db/dbDevice.h b/src/db/db/dbDevice.h index 8746fbe8e..336411b1b 100644 --- a/src/db/db/dbDevice.h +++ b/src/db/db/dbDevice.h @@ -28,6 +28,7 @@ #include "dbPoint.h" #include "dbVector.h" #include "dbTrans.h" +#include "dbMemStatistics.h" #include "tlObject.h" @@ -349,6 +350,23 @@ public: return m_other_abstracts; } + /** + * @brief Generate memory statistics + */ + void mem_stat (MemStatistics *stat, MemStatistics::purpose_t purpose, int cat, bool no_self = false, void *parent = 0) const + { + if (! no_self) { + stat->add (typeid (*this), (void *) this, sizeof (*this), sizeof (*this), parent, purpose, cat); + } + + db::mem_stat (stat, purpose, cat, m_name, true, (void *) this); + db::mem_stat (stat, purpose, cat, m_trans, true, (void *) this); + db::mem_stat (stat, purpose, cat, m_terminal_refs, true, (void *) this); + db::mem_stat (stat, purpose, cat, m_parameters, true, (void *) this); + db::mem_stat (stat, purpose, cat, m_other_abstracts, true, (void *) this); + db::mem_stat (stat, purpose, cat, m_reconnected_terminals, true, (void *) this); + } + private: friend class Circuit; friend class Net; @@ -396,6 +414,14 @@ private: void init_terminal_routes (); }; +/** + * @brief Memory statistics for Device + */ +inline void mem_stat (MemStatistics *stat, MemStatistics::purpose_t purpose, int cat, const Device &x, bool no_self, void *parent) +{ + x.mem_stat (stat, purpose, cat, no_self, parent); +} + } #endif diff --git a/src/db/db/dbDeviceAbstract.h b/src/db/db/dbDeviceAbstract.h index 00cbc45cc..d6ba95713 100644 --- a/src/db/db/dbDeviceAbstract.h +++ b/src/db/db/dbDeviceAbstract.h @@ -26,6 +26,7 @@ #include "dbCommon.h" #include "dbNet.h" #include "dbPoint.h" +#include "dbMemStatistics.h" #include "tlObject.h" @@ -144,6 +145,19 @@ public: */ void set_cluster_id_for_terminal (size_t terminal_id, size_t cluster_id); + /** + * @brief Generate memory statistics + */ + void mem_stat (MemStatistics *stat, MemStatistics::purpose_t purpose, int cat, bool no_self = false, void *parent = 0) const + { + if (! no_self) { + stat->add (typeid (*this), (void *) this, sizeof (*this), sizeof (*this), parent, purpose, cat); + } + + db::mem_stat (stat, purpose, cat, m_name, true, (void *) this); + db::mem_stat (stat, purpose, cat, m_terminal_cluster_ids, true, (void *) this); + } + private: friend class Netlist; @@ -159,6 +173,14 @@ private: void set_netlist (Netlist *netlist); }; +/** + * @brief Memory statistics for LayoutToNetlist + */ +inline void mem_stat (MemStatistics *stat, MemStatistics::purpose_t purpose, int cat, const DeviceAbstract &x, bool no_self, void *parent) +{ + x.mem_stat (stat, purpose, cat, no_self, parent); +} + } #endif diff --git a/src/db/db/dbDeviceClass.h b/src/db/db/dbDeviceClass.h index d77048e2b..66ba8d5f6 100644 --- a/src/db/db/dbDeviceClass.h +++ b/src/db/db/dbDeviceClass.h @@ -24,6 +24,7 @@ #define _HDR_dbDeviceClass #include "dbCommon.h" +#include "dbMemStatistics.h" #include "gsiObject.h" #include "tlObject.h" @@ -102,6 +103,19 @@ public: return m_id; } + /** + * @brief Generate memory statistics + */ + void mem_stat (MemStatistics *stat, MemStatistics::purpose_t purpose, int cat, bool no_self = false, void *parent = 0) const + { + if (! no_self) { + stat->add (typeid (*this), (void *) this, sizeof (*this), sizeof (*this), parent, purpose, cat); + } + + db::mem_stat (stat, purpose, cat, m_name, true, (void *) this); + db::mem_stat (stat, purpose, cat, m_description, true, (void *) this); + } + private: friend class DeviceClass; @@ -114,6 +128,14 @@ private: } }; +/** + * @brief Memory statistics for DeviceTerminalDefinition + */ +inline void mem_stat (MemStatistics *stat, MemStatistics::purpose_t purpose, int cat, const DeviceTerminalDefinition &x, bool no_self, void *parent) +{ + x.mem_stat (stat, purpose, cat, no_self, parent); +} + /** * @brief A device parameter definition */ @@ -224,6 +246,19 @@ public: return m_id; } + /** + * @brief Generate memory statistics + */ + void mem_stat (MemStatistics *stat, MemStatistics::purpose_t purpose, int cat, bool no_self = false, void *parent = 0) const + { + if (! no_self) { + stat->add (typeid (*this), (void *) this, sizeof (*this), sizeof (*this), parent, purpose, cat); + } + + db::mem_stat (stat, purpose, cat, m_name, true, (void *) this); + db::mem_stat (stat, purpose, cat, m_description, true, (void *) this); + } + private: friend class DeviceClass; @@ -239,6 +274,14 @@ private: } }; +/** + * @brief Memory statistics for DeviceParameterDefinition + */ +inline void mem_stat (MemStatistics *stat, MemStatistics::purpose_t purpose, int cat, const DeviceParameterDefinition &x, bool no_self, void *parent) +{ + x.mem_stat (stat, purpose, cat, no_self, parent); +} + /** * @brief A device parameter compare delegate * @@ -598,6 +641,21 @@ public: return mp_pc_delegate.get (); } + /** + * @brief Generate memory statistics + */ + void mem_stat (MemStatistics *stat, MemStatistics::purpose_t purpose, int cat, bool no_self = false, void *parent = 0) const + { + if (! no_self) { + stat->add (typeid (*this), (void *) this, sizeof (*this), sizeof (*this), parent, purpose, cat); + } + + db::mem_stat (stat, purpose, cat, m_name, true, (void *) this); + db::mem_stat (stat, purpose, cat, m_description, true, (void *) this); + db::mem_stat (stat, purpose, cat, m_terminal_definitions, true, (void *) this); + db::mem_stat (stat, purpose, cat, m_parameter_definitions, true, (void *) this); + } + private: friend class Netlist; @@ -614,6 +672,14 @@ private: } }; +/** + * @brief Memory statistics for DeviceClass + */ +inline void mem_stat (MemStatistics *stat, MemStatistics::purpose_t purpose, int cat, const DeviceClass &x, bool no_self, void *parent) +{ + x.mem_stat (stat, purpose, cat, no_self, parent); +} + /** * @brief A device class template * diff --git a/src/db/db/dbHierNetworkProcessor.cc b/src/db/db/dbHierNetworkProcessor.cc index 07b88bf11..d3eac046f 100644 --- a/src/db/db/dbHierNetworkProcessor.cc +++ b/src/db/db/dbHierNetworkProcessor.cc @@ -414,6 +414,19 @@ local_cluster::ensure_sorted () m_needs_update = false; } +template +void +local_cluster::mem_stat (MemStatistics *stat, MemStatistics::purpose_t purpose, int cat, bool no_self, void *parent) const +{ + if (! no_self) { + stat->add (typeid (*this), (void *) this, sizeof (*this), sizeof (*this), parent, purpose, cat); + } + + db::mem_stat (stat, purpose, cat, m_shapes, true, (void *) this); + db::mem_stat (stat, purpose, cat, m_attrs, true, (void *) this); + db::mem_stat (stat, purpose, cat, m_global_nets, true, (void *) this); +} + template class DB_PUBLIC hnp_interaction_receiver : public box_scanner_receiver2 @@ -786,6 +799,20 @@ local_clusters::ensure_sorted () m_needs_update = false; } +template +void +local_clusters::mem_stat (MemStatistics *stat, MemStatistics::purpose_t purpose, int cat, bool no_self, void *parent) const +{ + if (! no_self) { + stat->add (typeid (*this), (void *) this, sizeof (*this), sizeof (*this), parent, purpose, cat); + } + + db::mem_stat (stat, purpose, cat, m_needs_update, true, (void *) this); + db::mem_stat (stat, purpose, cat, m_bbox, true, (void *) this); + db::mem_stat (stat, purpose, cat, m_clusters, true, (void *) this); + db::mem_stat (stat, purpose, cat, m_next_dummy_id, true, (void *) this); +} + namespace { @@ -1210,6 +1237,21 @@ connected_clusters::find_cluster_with_connection (const ClusterInstance &inst } } +template +void +connected_clusters::mem_stat (MemStatistics *stat, MemStatistics::purpose_t purpose, int cat, bool no_self, void *parent) const +{ + if (! no_self) { + stat->add (typeid (*this), (void *) this, sizeof (*this), sizeof (*this), parent, purpose, cat); + } + + local_clusters::mem_stat (stat, purpose, cat, true, parent); + + db::mem_stat (stat, purpose, cat, m_connections, true, (void *) this); + db::mem_stat (stat, purpose, cat, m_rev_connections, true, (void *) this); + db::mem_stat (stat, purpose, cat, m_connected_clusters, true, (void *) this); +} + // explicit instantiations template class DB_PUBLIC connected_clusters; template class DB_PUBLIC connected_clusters; @@ -1290,6 +1332,17 @@ void hier_clusters::clear () m_per_cell_clusters.clear (); } +template +void +hier_clusters::mem_stat (MemStatistics *stat, MemStatistics::purpose_t purpose, int cat, bool no_self, void *parent) const +{ + if (! no_self) { + stat->add (typeid (*this), (void *) this, sizeof (*this), sizeof (*this), parent, purpose, cat); + } + + db::mem_stat (stat, purpose, cat, m_per_cell_clusters, true, (void *) this); +} + template void hier_clusters::build (const db::Layout &layout, const db::Cell &cell, const db::Connectivity &conn, const std::map > *attr_equivalence, const std::set *breakout_cells) @@ -1467,7 +1520,7 @@ private: join_set_list m_cm2join_sets; std::list m_ci_interactions; std::map > > m_interaction_cache_for_clusters; - instance_interaction_cache_type *mp_instance_interaction_cache; + typename hier_clusters::instance_interaction_cache_type *mp_instance_interaction_cache; /** * @brief Investigate a pair of instances @@ -1488,7 +1541,7 @@ private: void consider_instance_pair (const box_type &common, const db::Instance &i1, const db::ICplxTrans &t1, const db::CellInstArray::iterator &i1element, const db::Instance &i2, const db::ICplxTrans &t2, const db::CellInstArray::iterator &i2element, - std::list > &interacting_clusters) + cluster_instance_pair_list_type &interacting_clusters) { if (is_breakout_cell (mp_breakout_cells, i1.cell_index ()) || is_breakout_cell (mp_breakout_cells, i2.cell_index ())) { return; @@ -1510,7 +1563,7 @@ private: db::ICplxTrans i1t, i2t; bool fill_cache = false; - // Cache is only used for single instances, non-iterated, simple or regular arrays. + // Cache is only used for single instances or simple and regular arrays. if ((! i1element.at_end () || i1.size () == 1 || ! i1.is_iterated_array ()) && (! i2element.at_end () || i2.size () == 1 || ! i2.is_iterated_array ())) { @@ -1525,12 +1578,12 @@ private: i2.cell_index (), (! i2element.at_end () || i2.size () == 1) ? 0 : i2.cell_inst ().delegate (), cache_norm, cache_norm * tt2); - instance_interaction_cache_type::iterator ii = mp_instance_interaction_cache->find (ii_key); - if (ii != mp_instance_interaction_cache->end ()) { + const cluster_instance_pair_list_type *cached = mp_instance_interaction_cache->find (ii_key); + if (cached) { // use cached interactions - interacting_clusters = ii->second; - for (std::list >::iterator i = interacting_clusters.begin (); i != interacting_clusters.end (); ++i) { + interacting_clusters = *cached; + for (cluster_instance_pair_list_type::iterator i = interacting_clusters.begin (); i != interacting_clusters.end (); ++i) { // translate the property IDs i->first.set_inst_prop_id (i1.prop_id ()); i->first.transform (i1t); @@ -1596,6 +1649,22 @@ private: } + // dive into cell of ii1 + const db::Cell &cell1 = mp_layout->cell (i1.cell_index ()); + for (db::Cell::touching_iterator jj1 = cell1.begin_touching (common12.transformed (tt1.inverted ())); ! jj1.at_end (); ++jj1) { + + std::list > ii_interactions; + consider_instance_pair (common12, *jj1, tt1, db::CellInstArray::iterator (), i2, t2, ii2, ii_interactions); + + for (std::list >::iterator i = ii_interactions.begin (); i != ii_interactions.end (); ++i) { + propagate_cluster_inst (i->first, i1.cell_index (), i1t, i1.prop_id ()); + } + + ii_interactions.unique (); + interacting_clusters.splice (interacting_clusters.end (), ii_interactions, ii_interactions.begin (), ii_interactions.end ()); + + } + } if (! i2element.at_end ()) { @@ -1604,27 +1673,6 @@ private: } - box_type common1 = ib1 & b2 & common; - if (! common1.empty ()) { - - // dive into cell of ii1 - const db::Cell &cell1 = mp_layout->cell (i1.cell_index ()); - for (db::Cell::touching_iterator jj1 = cell1.begin_touching (common1.transformed (tt1.inverted ())); ! jj1.at_end (); ++jj1) { - - std::list > ii_interactions; - consider_instance_pair (common1, *jj1, tt1, db::CellInstArray::iterator (), i2, t2, i2element, ii_interactions); - - for (std::list >::iterator i = ii_interactions.begin (); i != ii_interactions.end (); ++i) { - propagate_cluster_inst (i->first, i1.cell_index (), i1t, i1.prop_id ()); - } - - ii_interactions.unique (); - interacting_clusters.splice (interacting_clusters.end (), ii_interactions, ii_interactions.begin (), ii_interactions.end ()); - - } - - } - if (! i1element.at_end ()) { break; } @@ -1653,7 +1701,7 @@ private: i->second.transform (i2ti); } - cluster_instance_pair_list_type &cached = (*mp_instance_interaction_cache) [ii_key]; + cluster_instance_pair_list_type &cached = mp_instance_interaction_cache->insert (ii_key); cached.insert (cached.end (), sorted_interactions.begin (), sorted_interactions.end ()); } @@ -2187,6 +2235,10 @@ hier_clusters::do_build (cell_clusters_box_converter &cbc, const db::Layou build_hier_connections_for_cells (cbc, layout, todo, conn, breakout_cells, progress, instance_interaction_cache); } + + if (tl::verbosity () >= 51) { + tl::info << "Cluster build cache statistics: size=" << instance_interaction_cache.size () << ", hits=" << instance_interaction_cache.hits () << ", misses=" << instance_interaction_cache.misses (); + } } template diff --git a/src/db/db/dbHierNetworkProcessor.h b/src/db/db/dbHierNetworkProcessor.h index 75455440b..aeb41b006 100644 --- a/src/db/db/dbHierNetworkProcessor.h +++ b/src/db/db/dbHierNetworkProcessor.h @@ -365,6 +365,11 @@ public: */ void set_global_nets (const global_nets &gn); + /** + * @brief Collect memory statistics + */ + void mem_stat (MemStatistics *stat, MemStatistics::purpose_t purpose, int cat, bool no_self, void *parent) const; + private: template friend class local_clusters; template friend class hnp_interaction_receiver; @@ -392,6 +397,15 @@ private: size_t m_size; }; +/** + * @brief Memory statistics for local_cluster + */ +template +inline void mem_stat (MemStatistics *stat, MemStatistics::purpose_t purpose, int cat, const local_cluster &x, bool no_self, void *parent) +{ + x.mem_stat (stat, purpose, cat, no_self, parent); +} + /** * @brief A box converter for the local_cluster class */ @@ -533,6 +547,19 @@ public: return id > m_clusters.size (); } + /** + * @brief Gets the number of clusters + */ + size_t size () const + { + return m_clusters.size (); + } + + /** + * @brief Collect memory statistics + */ + void mem_stat (MemStatistics *stat, MemStatistics::purpose_t purpose, int cat, bool no_self, void *parent) const; + private: void ensure_sorted (); @@ -544,6 +571,15 @@ private: void apply_attr_equivalences (const tl::equivalence_clusters &attr_equivalence); }; +/** + * @brief Memory statistics for local_clusters + */ +template +inline void mem_stat (MemStatistics *stat, MemStatistics::purpose_t purpose, int cat, const local_clusters &x, bool no_self, void *parent) +{ + x.mem_stat (stat, purpose, cat, no_self, parent); +} + /** * @brief The instance information for a cluster */ @@ -859,8 +895,6 @@ struct InstanceToInstanceInteraction db::ICplxTrans t21; }; -typedef std::map instance_interaction_cache_type; - template class hier_clusters; template class connected_clusters; @@ -1013,6 +1047,11 @@ public: m_connected_clusters.insert (id); } + /** + * @brief Collect memory statistics + */ + void mem_stat (MemStatistics *stat, MemStatistics::purpose_t purpose, int cat, bool no_self, void *parent) const; + private: template friend class connected_clusters_iterator; @@ -1021,6 +1060,15 @@ private: std::set m_connected_clusters; }; +/** + * @brief Memory statistics for connected_clusters + */ +template +inline void mem_stat (MemStatistics *stat, MemStatistics::purpose_t purpose, int cat, const connected_clusters &x, bool no_self, void *parent) +{ + x.mem_stat (stat, purpose, cat, no_self, parent); +} + template class cell_clusters_box_converter; /** @@ -1034,7 +1082,55 @@ class DB_PUBLIC_TEMPLATE hier_clusters { public: typedef typename local_cluster::box_type box_type; - typedef std::map instance_interaction_cache_type; + + /** + * @brief An object representing the instance interaction cache + */ + class instance_interaction_cache + { + public: + instance_interaction_cache () + : m_hits (0), m_misses (0) + { } + + size_t size () const + { + return m_map.size (); + } + + size_t hits () const + { + return m_hits; + } + + size_t misses () const + { + return m_misses; + } + + const cluster_instance_pair_list_type *find (const InstanceToInstanceInteraction &key) const + { + std::map::const_iterator i = m_map.find (key); + if (i == m_map.end ()) { + ++m_misses; + return 0; + } else { + ++m_hits; + return &i->second; + } + } + + cluster_instance_pair_list_type &insert (const InstanceToInstanceInteraction &key) + { + return m_map [key]; + } + + private: + mutable size_t m_hits, m_misses; + std::map m_map; + }; + + typedef instance_interaction_cache instance_interaction_cache_type; /** * @brief Creates an empty set of clusters @@ -1094,6 +1190,11 @@ public: */ size_t propagate_cluster_inst (const db::Layout &layout, const Cell &cell, const ClusterInstance &ci, db::cell_index_type parent_ci, bool with_self); + /** + * @brief Collect memory statistics + */ + void mem_stat (MemStatistics *stat, MemStatistics::purpose_t purpose, int cat, bool no_self, void *parent) const; + private: void build_local_cluster (const db::Layout &layout, const db::Cell &cell, const db::Connectivity &conn, const tl::equivalence_clusters *attr_equivalence); void build_hier_connections (cell_clusters_box_converter &cbc, const db::Layout &layout, const db::Cell &cell, const db::Connectivity &conn, const std::set *breakout_cells, instance_interaction_cache_type &instance_interaction_cache); diff --git a/src/db/db/dbLayoutToNetlist.cc b/src/db/db/dbLayoutToNetlist.cc index 4f3331992..ac8d0adfe 100644 --- a/src/db/db/dbLayoutToNetlist.cc +++ b/src/db/db/dbLayoutToNetlist.cc @@ -397,9 +397,41 @@ void LayoutToNetlist::extract_netlist () netex.set_include_floating_subcircuits (m_include_floating_subcircuits); netex.extract_nets (dss (), m_layout_index, m_conn, *mp_netlist, m_net_clusters); + if (tl::verbosity () >= 41) { + MemStatisticsCollector m (false); + mem_stat (&m, db::MemStatistics::None, 0); + m.print (); + } + m_netlist_extracted = true; } +void LayoutToNetlist::mem_stat (MemStatistics *stat, MemStatistics::purpose_t purpose, int cat, bool no_self, void *parent) const +{ + if (! no_self) { + stat->add (typeid (*this), (void *) this, sizeof (*this), sizeof (*this), parent, purpose, cat); + } + + db::mem_stat (stat, purpose, cat, m_description, true, (void *) this); + db::mem_stat (stat, purpose, cat, m_name, true, (void *) this); + db::mem_stat (stat, purpose, cat, m_original_file, true, (void *) this); + db::mem_stat (stat, purpose, cat, m_filename, true, (void *) this); + db::mem_stat (stat, purpose, cat, m_net_clusters, true, (void *) this); + db::mem_stat (stat, purpose, cat, mp_netlist, true, (void *) this); + db::mem_stat (stat, purpose, cat, m_dlrefs, true, (void *) this); + db::mem_stat (stat, purpose, cat, m_named_regions, true, (void *) this); + db::mem_stat (stat, purpose, cat, m_name_of_layer, true, (void *) this); + db::mem_stat (stat, purpose, cat, m_joined_net_names, true, (void *) this); + db::mem_stat (stat, purpose, cat, m_joined_net_names_per_cell, true, (void *) this); + db::mem_stat (stat, purpose, cat, m_joined_nets, true, (void *) this); + db::mem_stat (stat, purpose, cat, m_joined_nets_per_cell, true, (void *) this); + + m_net_clusters.mem_stat (stat, MemStatistics::LayoutToNetlist, cat, true, (void *) this); + if (mp_netlist.get ()) { + db::mem_stat (stat, MemStatistics::Netlist, cat, *mp_netlist, false, (void *) this); + } +} + void LayoutToNetlist::set_netlist_extracted () { m_netlist_extracted = true; diff --git a/src/db/db/dbLayoutToNetlist.h b/src/db/db/dbLayoutToNetlist.h index a1bf8716f..08cb3eb46 100644 --- a/src/db/db/dbLayoutToNetlist.h +++ b/src/db/db/dbLayoutToNetlist.h @@ -893,6 +893,11 @@ public: */ static db::LayoutToNetlist *create_from_file (const std::string &path); + /** + * @brief Generate memory statistics + */ + void mem_stat (MemStatistics *stat, MemStatistics::purpose_t purpose, int cat, bool no_self = false, void *parent = 0) const; + private: // no copying LayoutToNetlist (const db::LayoutToNetlist &other); @@ -971,6 +976,14 @@ private: virtual void link_nets (const db::Net *net, const db::Net *with); }; +/** + * @brief Memory statistics for LayoutToNetlist + */ +inline void mem_stat (MemStatistics *stat, MemStatistics::purpose_t purpose, int cat, const LayoutToNetlist &x, bool no_self, void *parent) +{ + x.mem_stat (stat, purpose, cat, no_self, parent); +} + } namespace tl diff --git a/src/db/db/dbMemStatistics.cc b/src/db/db/dbMemStatistics.cc index 1160f0b10..0995c01b8 100644 --- a/src/db/db/dbMemStatistics.cc +++ b/src/db/db/dbMemStatistics.cc @@ -100,14 +100,16 @@ void MemStatisticsCollector::print () { std::map p2s; - p2s[None] = "(none) "; - p2s[LayoutInfo] = "Layout info "; - p2s[CellInfo] = "Cell info "; - p2s[Instances] = "Instances "; - p2s[InstTrees] = "Instance trees "; - p2s[ShapesInfo] = "Shapes info "; - p2s[ShapesCache] = "Shapes cache "; - p2s[ShapeTrees] = "Shape trees "; + p2s[None] = "(none) "; + p2s[LayoutInfo] = "Layout info "; + p2s[CellInfo] = "Cell info "; + p2s[Instances] = "Instances "; + p2s[InstTrees] = "Instance trees "; + p2s[ShapesInfo] = "Shapes info "; + p2s[ShapesCache] = "Shapes cache "; + p2s[ShapeTrees] = "Shape trees "; + p2s[Netlist] = "Netlist "; + p2s[LayoutToNetlist] = "Netlist layout "; if (m_detailed) { diff --git a/src/db/db/dbMemStatistics.h b/src/db/db/dbMemStatistics.h index 72dfc85f8..8293c85bf 100644 --- a/src/db/db/dbMemStatistics.h +++ b/src/db/db/dbMemStatistics.h @@ -26,6 +26,7 @@ #define HDR_dbMemStatistics #include "dbCommon.h" +#include "tlObjectCollection.h" #include #include @@ -33,6 +34,8 @@ #include #include #include +#include +#include #include #include "tlReuseVector.h" @@ -64,7 +67,9 @@ public: InstTrees, ShapesInfo, ShapesCache, - ShapeTrees + ShapeTrees, + Netlist, + LayoutToNetlist }; /** @@ -120,7 +125,7 @@ template void mem_stat (MemStatistics *stat, MemStatistics::purpose_t purpose, int cat, const tl::reuse_vector &v, bool no_self = false, void *parent = 0) { if (! no_self) { - stat->add (typeid (tl::reuse_vector), (void *) &v, sizeof (tl::reuse_vector), sizeof (tl::reuse_vector), parent, purpose, cat); + stat->add (typeid (v), (void *) &v, sizeof (v), sizeof (v), parent, purpose, cat); } if (! v.empty ()) { stat->add (typeid (X[]), (void *) v.begin ().operator-> (), sizeof (X) * v.capacity (), sizeof (X) * v.size (), (void *) &v, purpose, cat); @@ -137,7 +142,7 @@ template void mem_stat (MemStatistics *stat, MemStatistics::purpose_t purpose, int cat, const tl::vector &v, bool no_self = false, void *parent = 0) { if (! no_self) { - stat->add (typeid (tl::vector), (void *) &v, sizeof (tl::vector), sizeof (tl::vector), parent, purpose, cat); + stat->add (typeid (v), (void *) &v, sizeof (v), sizeof (v), parent, purpose, cat); } if (! v.empty ()) { stat->add (typeid (X[]), (void *) &v.front (), sizeof (X) * v.capacity (), sizeof (X) * v.size (), (void *) &v, purpose, cat); @@ -151,7 +156,7 @@ template void mem_stat (MemStatistics *stat, MemStatistics::purpose_t purpose, int cat, const std::vector &v, bool no_self = false, void *parent = 0) { if (! no_self) { - stat->add (typeid (std::vector), (void *) &v, sizeof (std::vector), sizeof (std::vector), parent, purpose, cat); + stat->add (typeid (v), (void *) &v, sizeof (v), sizeof (v), parent, purpose, cat); } if (! v.empty ()) { stat->add (typeid (X[]), (void *) &v.front (), sizeof (X) * v.capacity (), sizeof (X) * v.size (), (void *) &v, purpose, cat); @@ -167,41 +172,68 @@ template void mem_stat (MemStatistics *stat, MemStatistics::purpose_t purpose, int cat, const std::map &v, bool no_self = false, void *parent = 0) { if (! no_self) { - stat->add (typeid (std::map), (void *) &v, sizeof (std::map), sizeof (std::map), parent, purpose, cat); + stat->add (typeid (v), (void *) &v, sizeof (v), sizeof (v), parent, purpose, cat); } for (typename std::map::const_iterator i = v.begin (); i != v.end (); ++i) { mem_stat (stat, purpose, cat, i->first, false, (void *) &v); mem_stat (stat, purpose, cat, i->second, false, (void *) &v); -#ifdef __GNUCC__ - stat->add (std::_Rb_tree_node_base, (void *) &i->first, sizeof (std::_Rb_tree_node_base), sizeof (std::_Rb_tree_node_base), (void *) &v, purpose, cat); +#ifdef __GLIBCXX__ + stat->add (typeid (std::_Rb_tree_node_base), (void *) &i->first, sizeof (std::_Rb_tree_node_base), sizeof (std::_Rb_tree_node_base), (void *) &v, purpose, cat); #endif } } +template +void mem_stat (MemStatistics *stat, MemStatistics::purpose_t purpose, int cat, const std::unordered_map &v, bool no_self = false, void *parent = 0) +{ + if (! no_self) { + stat->add (typeid (v), (void *) &v, sizeof (v), sizeof (v), parent, purpose, cat); + } + for (typename std::unordered_map::const_iterator i = v.begin (); i != v.end (); ++i) { + mem_stat (stat, purpose, cat, i->first, false, (void *) &v); + mem_stat (stat, purpose, cat, i->second, false, (void *) &v); + // TODO: add intrinsic overhead + } +} + template void mem_stat (MemStatistics *stat, MemStatistics::purpose_t purpose, int cat, const std::set &v, bool no_self = false, void *parent = 0) { if (! no_self) { - stat->add (typeid (std::set), (void *) &v, sizeof (std::set), sizeof (std::set), parent, purpose, cat); + stat->add (typeid (v), (void *) &v, sizeof (v), sizeof (v), parent, purpose, cat); } for (typename std::set::const_iterator i = v.begin (); i != v.end (); ++i) { mem_stat (stat, purpose, cat, *i, false, (void *) &v); -#ifdef __GNUCC__ - stat->add (std::_Rb_tree_node_base, (void *) &i.operator-> (), sizeof (std::_Rb_tree_node_base), sizeof (std::_Rb_tree_node_base), (void *) &v, purpose, cat); +#ifdef __GLIBCXX__ + // NOTE: the pointer is only an approximation + stat->add (typeid (std::_Rb_tree_node_base), (void *) i.operator-> (), sizeof (std::_Rb_tree_node_base), sizeof (std::_Rb_tree_node_base), (void *) &v, purpose, cat); #endif } } +template +void mem_stat (MemStatistics *stat, MemStatistics::purpose_t purpose, int cat, const std::unordered_set &v, bool no_self = false, void *parent = 0) +{ + if (! no_self) { + stat->add (typeid (v), (void *) &v, sizeof (v), sizeof (v), parent, purpose, cat); + } + for (typename std::unordered_set::const_iterator i = v.begin (); i != v.end (); ++i) { + mem_stat (stat, purpose, cat, *i, false, (void *) &v); + // TODO: add intrinsic overhead + } +} + template void mem_stat (MemStatistics *stat, MemStatistics::purpose_t purpose, int cat, const std::list &v, bool no_self = false, void *parent = 0) { if (! no_self) { - stat->add (typeid (std::list), (void *) &v, sizeof (std::list), sizeof (std::list), parent, purpose, cat); + stat->add (typeid (v), (void *) &v, sizeof (v), sizeof (v), parent, purpose, cat); } for (typename std::list::const_iterator i = v.begin (); i != v.end (); ++i) { mem_stat (stat, purpose, cat, *i, false, (void *) &v); -#ifdef __GNUCC__ - stat->add (std::_List_node_base, (void *) &i.operator-> (), sizeof (std::_List_node_base), sizeof (std::_List_node_base), (void *) &v, purpose, cat); +#ifdef __GLIBCXX__ + // NOTE: the pointer is only an approximation + stat->add (typeid (std::__detail::_List_node_base), (void *) i.operator-> (), sizeof (std::__detail::_List_node_base), sizeof (std::__detail::_List_node_base), (void *) &v, purpose, cat); #endif } } @@ -210,12 +242,35 @@ template void mem_stat (MemStatistics *stat, MemStatistics::purpose_t purpose, int cat, const std::pair &v, bool no_self = false, void *parent = 0) { if (! no_self) { - stat->add (typeid (std::pair), (void *) &v, sizeof (std::pair), sizeof (std::pair), parent, purpose, cat); + stat->add (typeid (v), (void *) &v, sizeof (v), sizeof (v), parent, purpose, cat); } mem_stat (stat, purpose, cat, v.first, true, (void *) &v); mem_stat (stat, purpose, cat, v.second, true, (void *) &v); } +template +void mem_stat (MemStatistics *stat, MemStatistics::purpose_t purpose, int cat, const tl::shared_collection &v, bool no_self = false, void *parent = 0) +{ + if (! no_self) { + stat->add (typeid (v), (void *) &v, sizeof (v), sizeof (v), parent, purpose, cat); + } + size_t intrinsic = sizeof (typename tl::shared_collection::holder_type) * v.size (); + stat->add (typeid (typename tl::shared_collection::holder_type), (void *) &v, intrinsic, intrinsic, (void *) &v, purpose, cat); + for (typename tl::shared_collection::const_iterator i = v.begin (); i != v.end (); ++i) { + mem_stat (stat, purpose, cat, *i, false, (void *) &v); + } +} + +template +void mem_stat (MemStatistics *stat, MemStatistics::purpose_t purpose, int cat, const tl::weak_collection &v, bool no_self = false, void *parent = 0) +{ + if (! no_self) { + stat->add (typeid (v), (void *) &v, sizeof (v), sizeof (v), parent, purpose, cat); + } + size_t intrinsic = sizeof (typename tl::weak_collection::holder_type) * v.size (); + stat->add (typeid (typename tl::weak_collection::holder_type), (void *) &v, intrinsic, intrinsic, (void *) &v, purpose, cat); +} + } #endif diff --git a/src/db/db/dbNet.h b/src/db/db/dbNet.h index 66cf97d36..f2e97c373 100644 --- a/src/db/db/dbNet.h +++ b/src/db/db/dbNet.h @@ -25,6 +25,7 @@ #include "dbCommon.h" #include "dbNetlistObject.h" +#include "dbMemStatistics.h" #include "tlObject.h" @@ -664,6 +665,21 @@ public: return m_terminals.size (); } + /** + * @brief Generate memory statistics + */ + void mem_stat (MemStatistics *stat, MemStatistics::purpose_t purpose, int cat, bool no_self = false, void *parent = 0) const + { + if (! no_self) { + stat->add (typeid (*this), (void *) this, sizeof (*this), sizeof (*this), parent, purpose, cat); + } + + db::mem_stat (stat, purpose, cat, m_name, true, (void *) this); + db::mem_stat (stat, purpose, cat, m_terminals, true, (void *) this); + db::mem_stat (stat, purpose, cat, m_pins, true, (void *) this); + db::mem_stat (stat, purpose, cat, m_subcircuit_pins, true, (void *) this); + } + private: friend class Circuit; @@ -677,6 +693,14 @@ private: void set_circuit (Circuit *circuit); }; +/** + * @brief Memory statistics for Net + */ +inline void mem_stat (MemStatistics *stat, MemStatistics::purpose_t purpose, int cat, const Net &x, bool no_self, void *parent) +{ + x.mem_stat (stat, purpose, cat, no_self, parent); +} + } #endif diff --git a/src/db/db/dbNetlist.cc b/src/db/db/dbNetlist.cc index c369b4c47..47a226961 100644 --- a/src/db/db/dbNetlist.cc +++ b/src/db/db/dbNetlist.cc @@ -103,6 +103,24 @@ Netlist &Netlist::operator= (const Netlist &other) return *this; } +void Netlist::mem_stat (MemStatistics *stat, MemStatistics::purpose_t purpose, int cat, bool no_self, void *parent) const +{ + if (! no_self) { + stat->add (typeid (*this), (void *) this, sizeof (*this), sizeof (*this), parent, purpose, cat); + } + + db::mem_stat (stat, purpose, cat, m_circuits, true, (void *) this); + db::mem_stat (stat, purpose, cat, m_device_classes, true, (void *) this); + db::mem_stat (stat, purpose, cat, m_device_abstracts, true, (void *) this); + db::mem_stat (stat, purpose, cat, m_top_down_circuits, true, (void *) this); + db::mem_stat (stat, purpose, cat, m_child_circuits, true, (void *) this); + db::mem_stat (stat, purpose, cat, m_parent_circuits, true, (void *) this); + db::mem_stat (stat, purpose, cat, m_circuit_by_name, true, (void *) this); + db::mem_stat (stat, purpose, cat, m_circuit_by_cell_index, true, (void *) this); + db::mem_stat (stat, purpose, cat, m_device_abstract_by_name, true, (void *) this); + db::mem_stat (stat, purpose, cat, m_device_abstract_by_cell_index, true, (void *) this); +} + void Netlist::set_case_sensitive (bool f) { m_case_sensitive = f; diff --git a/src/db/db/dbNetlist.h b/src/db/db/dbNetlist.h index bfac2d402..20a714d06 100644 --- a/src/db/db/dbNetlist.h +++ b/src/db/db/dbNetlist.h @@ -533,6 +533,11 @@ public: return normalize_name (is_case_sensitive (), n); } + /** + * @brief Generate memory statistics + */ + void mem_stat (MemStatistics *stat, MemStatistics::purpose_t purpose, int cat, bool no_self = false, void *parent = 0) const; + private: friend class Circuit; friend class DeviceAbstract; @@ -567,6 +572,14 @@ private: const tl::vector &parent_circuits (Circuit *circuit); }; +/** + * @brief Memory statistics for LayoutToNetlist + */ +inline void mem_stat (MemStatistics *stat, MemStatistics::purpose_t purpose, int cat, const Netlist &x, bool no_self, void *parent) +{ + x.mem_stat (stat, purpose, cat, no_self, parent); +} + /** * @brief A helper class using RAII for safe locking/unlocking */ diff --git a/src/db/db/dbNetlistUtils.h b/src/db/db/dbNetlistUtils.h index da35bb546..aeb00961e 100644 --- a/src/db/db/dbNetlistUtils.h +++ b/src/db/db/dbNetlistUtils.h @@ -24,6 +24,12 @@ #define _HDR_dbNetlistUtils #include "dbCommon.h" +#include "dbTypes.h" +#include "dbMemStatistics.h" + +#include +#include +#include namespace db { @@ -102,6 +108,22 @@ public: return m == m_map.end () ? 0 : m->second; } + /** + * @brief Generate memory statistics + */ + void mem_stat (MemStatistics *stat, MemStatistics::purpose_t purpose, int cat, bool no_self = false, void *parent = 0) const + { + if (! no_self) { + stat->add (typeid (*this), (void *) this, sizeof (*this), sizeof (*this), parent, purpose, cat); + } + + db::mem_stat (stat, purpose, cat, m_map, true, (void *) this); + + for (typename std::map::const_iterator i = m_map.begin (); i != m_map.end (); ++i) { + db::mem_stat (stat, purpose, cat, *i->second, false, (void *) this); + } + } + private: T *mp_self; I (T::*m_bi) (); @@ -122,6 +144,15 @@ private: } }; +/** + * @brief Memory statistics for object_by_attr + */ +template +inline void mem_stat (MemStatistics *stat, MemStatistics::purpose_t purpose, int cat, const object_by_attr &x, bool no_self, void *parent) +{ + x.mem_stat (stat, purpose, cat, no_self, parent); +} + } #endif diff --git a/src/db/db/dbPin.h b/src/db/db/dbPin.h index c07371046..c95c9966b 100644 --- a/src/db/db/dbPin.h +++ b/src/db/db/dbPin.h @@ -25,6 +25,7 @@ #include "dbCommon.h" #include "dbNetlistObject.h" +#include "dbMemStatistics.h" #include @@ -81,6 +82,18 @@ public: m_name = name; } + /** + * @brief Generate memory statistics + */ + void mem_stat (MemStatistics *stat, MemStatistics::purpose_t purpose, int cat, bool no_self = false, void *parent = 0) const + { + if (! no_self) { + stat->add (typeid (*this), (void *) this, sizeof (*this), sizeof (*this), parent, purpose, cat); + } + + db::mem_stat (stat, purpose, cat, m_name, true, (void *) this); + } + private: friend class Circuit; @@ -93,6 +106,14 @@ private: } }; +/** + * @brief Memory statistics for Pin + */ +inline void mem_stat (MemStatistics *stat, MemStatistics::purpose_t purpose, int cat, const Pin &x, bool no_self, void *parent) +{ + x.mem_stat (stat, purpose, cat, no_self, parent); +} + } #endif diff --git a/src/db/db/dbSubCircuit.h b/src/db/db/dbSubCircuit.h index 7a5cfaa29..af9e561c7 100644 --- a/src/db/db/dbSubCircuit.h +++ b/src/db/db/dbSubCircuit.h @@ -26,6 +26,7 @@ #include "dbCommon.h" #include "dbTrans.h" #include "dbNet.h" +#include "dbMemStatistics.h" #include "tlObject.h" @@ -194,6 +195,20 @@ public: */ void connect_pin (size_t pin_id, Net *net); + /** + * @brief Generate memory statistics + */ + void mem_stat (MemStatistics *stat, MemStatistics::purpose_t purpose, int cat, bool no_self = false, void *parent = 0) const + { + if (! no_self) { + stat->add (typeid (*this), (void *) this, sizeof (*this), sizeof (*this), parent, purpose, cat); + } + + db::mem_stat (stat, purpose, cat, m_name, true, (void *) this); + db::mem_stat (stat, purpose, cat, m_trans, true, (void *) this); + db::mem_stat (stat, purpose, cat, m_pin_refs, true, (void *) this); + } + private: friend class Circuit; friend class Net; @@ -232,6 +247,14 @@ private: } }; +/** + * @brief Memory statistics for SubCircuit + */ +inline void mem_stat (MemStatistics *stat, MemStatistics::purpose_t purpose, int cat, const SubCircuit &x, bool no_self, void *parent) +{ + x.mem_stat (stat, purpose, cat, no_self, parent); +} + } #endif diff --git a/testdata/algo/device_extract_au1_dup_inst_with_rec_nets.gds b/testdata/algo/device_extract_au1_dup_inst_with_rec_nets.gds index 639924e76..8df8f4374 100644 Binary files a/testdata/algo/device_extract_au1_dup_inst_with_rec_nets.gds and b/testdata/algo/device_extract_au1_dup_inst_with_rec_nets.gds differ