11
11
#define PREPACK_H
12
12
13
13
#include < algorithm>
14
- #include < map>
15
- #include < unordered_map>
16
14
#include " vpr_types.h"
17
15
#include " vtr_assert.h"
18
- #include " vtr_range .h"
16
+ #include " vtr_vector .h"
19
17
20
18
class AtomNetlist ;
21
19
class AtomBlockId ;
@@ -28,7 +26,7 @@ struct t_logical_block_type;
28
26
* This class maintains the prepacking state, allowing the use of molecules
29
27
* (prepacked atoms) while this object exists. After prepacking, every atom will
30
28
* be part of a molecule (with a large number being part of single-atom
31
- * molecules.
29
+ * molecules) .
32
30
*
33
31
* Molecules currently come from pack patterns in the architecture file. For
34
32
* example, a 3-bit carry chain in most architectures would turn into a molecule
@@ -50,7 +48,6 @@ struct t_logical_block_type;
50
48
*
51
49
*/
52
50
class Prepacker {
53
- using atom_molecules_const_iterator = std::multimap<AtomBlockId, t_pack_molecule*>::const_iterator;
54
51
public:
55
52
// The constructor is default, the init method performs prepacking.
56
53
Prepacker () = default ;
@@ -72,18 +69,16 @@ class Prepacker {
72
69
void init (const AtomNetlist& atom_nlist, const std::vector<t_logical_block_type> &logical_block_types);
73
70
74
71
/* *
75
- * @brief Get the cluster molecules containing the given atom block.
72
+ * @brief Get the cluster molecule containing the given atom block.
76
73
*
77
- * @param blk_id The atom block to get the molecules of.
74
+ * @param blk_id The atom block to get the molecule of.
78
75
*/
79
76
inline t_pack_molecule* get_atom_molecule (AtomBlockId blk_id) const {
80
- // Internally the prepacker maintains multiple molecules per atom, since
81
- // some atoms may be part of multiple pack patterns; however, the
82
- // prepacker should merge these eventually into one single molecule.
83
- // TODO: If this can be 100% verified, this should be turned into a
84
- // debug assert.
85
- VTR_ASSERT (atom_molecules.count (blk_id) == 1 );
86
- return atom_molecules.find (blk_id)->second ;
77
+ // Safety debug to ensure the blk is valid and has a molecule entry.
78
+ VTR_ASSERT_SAFE (blk_id.is_valid () && (size_t )blk_id < atom_molecules.size ());
79
+ // Safety debug to ensure the molecule is valid
80
+ VTR_ASSERT_DEBUG (atom_molecules[blk_id] != nullptr );
81
+ return atom_molecules[blk_id];
87
82
}
88
83
89
84
/* *
@@ -93,11 +88,11 @@ class Prepacker {
93
88
* @param blk_id The atom block to get the pb graph node of.
94
89
*/
95
90
inline t_pb_graph_node* get_expected_lowest_cost_pb_gnode (AtomBlockId blk_id) const {
96
- auto iter = expected_lowest_cost_pb_gnode. find (blk_id);
97
- VTR_ASSERT (iter != expected_lowest_cost_pb_gnode.end ());
98
- t_pb_graph_node* pb_gnode = iter-> second ;
99
- VTR_ASSERT (pb_gnode != nullptr );
100
- return pb_gnode ;
91
+ // Safety debug to ensure the blk is valid and has an entry.
92
+ VTR_ASSERT_SAFE (blk_id. is_valid () && ( size_t )blk_id < expected_lowest_cost_pb_gnode.size ());
93
+ // Ensure the entry is valid.
94
+ VTR_ASSERT (expected_lowest_cost_pb_gnode[blk_id] != nullptr );
95
+ return expected_lowest_cost_pb_gnode[blk_id] ;
101
96
}
102
97
103
98
/* *
@@ -186,14 +181,13 @@ class Prepacker {
186
181
/* *
187
182
* @brief The molecules associated with each atom block.
188
183
*
189
- * This map is loaded in the prepacking stage and freed at the very end of
190
- * vpr flow run. The pointers in this multimap is shared with
191
- * list_of_pack_molecules.
184
+ * This vector is loaded in the init method and cleared in the reset method.
185
+ * The pointers in this vector are shared with list_of_pack_molecules.
192
186
*/
193
- std::multimap <AtomBlockId, t_pack_molecule*> atom_molecules;
187
+ vtr::vector <AtomBlockId, t_pack_molecule*> atom_molecules;
194
188
195
- // / @brief A map for the expected lowest cost physical block graph node.
196
- std::unordered_map <AtomBlockId, t_pb_graph_node*> expected_lowest_cost_pb_gnode;
189
+ // / @brief A vector of the expected lowest cost physical block graph node.
190
+ vtr::vector <AtomBlockId, t_pb_graph_node*> expected_lowest_cost_pb_gnode;
197
191
198
192
// / @brief A list of the pack patterns used for prepacking. I think the
199
193
// / molecules keep pointers to this vector, so this needs to remain
0 commit comments