@@ -99,7 +99,17 @@ static void find_all_equivalent_chains(t_pack_patterns* chain_pattern, const t_p
99
99
static void update_chain_root_pins (t_pack_patterns* chain_pattern,
100
100
const std::vector<t_pb_graph_pin*>& chain_input_pins);
101
101
102
- static void get_all_connected_primitive_pins (const t_pb_graph_pin* cluster_input_pin, std::vector<t_pb_graph_pin*>& connected_primitive_pins);
102
+ /* *
103
+ * @brief Get all primitive pins connected to the given cluster input pin
104
+ *
105
+ * @param cluster_input_pin Cluster input pin to get connected primitive pins from
106
+ * @param pattern_blocks Set of pb_types in the pack pattern. Pins on the blocks in this set will
107
+ * be added to the connected_primitive_pins vector
108
+ * @param connected_primitive_pins Vector to store connected primitive pins
109
+ */
110
+ static void get_all_connected_primitive_pins (const t_pb_graph_pin* cluster_input_pin,
111
+ const std::unordered_set<t_pb_type*>& pattern_blocks,
112
+ std::vector<t_pb_graph_pin*>& connected_primitive_pins);
103
113
104
114
static void init_molecule_chain_info (const AtomBlockId blk_id,
105
115
t_pack_molecule& molecule,
@@ -117,6 +127,14 @@ static AtomBlockId get_driving_block(const AtomBlockId block_id,
117
127
const t_pack_pattern_connections& connections,
118
128
const AtomNetlist& atom_nlist);
119
129
130
+ /* *
131
+ * @brief Get an unordered set of all pb_types in the given pack pattern
132
+ *
133
+ * @param pack_pattern Pack pattern to get pb_types from
134
+ * @return std::unordered_set<t_pb_type*> Set of pb_types in the pack pattern
135
+ */
136
+ static std::unordered_set<t_pb_type*> get_pattern_blocks (const t_pack_patterns& pack_pattern);
137
+
120
138
static void print_chain_starting_points (t_pack_patterns* chain_pattern);
121
139
122
140
/* ****************************************/
@@ -1172,6 +1190,51 @@ static AtomBlockId get_driving_block(const AtomBlockId block_id,
1172
1190
return AtomBlockId::INVALID ();
1173
1191
}
1174
1192
1193
+ static std::unordered_set<t_pb_type*> get_pattern_blocks (const t_pack_patterns& pack_pattern) {
1194
+ std::unordered_set<t_pb_type*> pattern_blocks;
1195
+
1196
+ t_pack_pattern_connections* connections = pack_pattern.root_block ->connections ;
1197
+ if (connections == nullptr ) {
1198
+ return pattern_blocks;
1199
+ }
1200
+ std::unordered_set<t_pb_graph_pin*> visited_from_pins;
1201
+ std::unordered_set<t_pb_graph_pin*> visited_to_pins;
1202
+ std::queue<t_pack_pattern_block*> pack_pattern_blocks;
1203
+ pack_pattern_blocks.push (connections->from_block );
1204
+
1205
+ /* * Start from the root block of the pack pattern and add the connected block to the queue */
1206
+ while (!pack_pattern_blocks.empty ()) {
1207
+ t_pack_pattern_block* current_pattern_block = pack_pattern_blocks.front ();
1208
+ pack_pattern_blocks.pop ();
1209
+ t_pack_pattern_connections* current_connenction = current_pattern_block->connections ;
1210
+ /*
1211
+ * Iterate through all the connections of the current pattern block to
1212
+ * add the connected block to the queue
1213
+ */
1214
+ while (current_connenction != nullptr ) {
1215
+ if (visited_from_pins.find (current_connenction->from_pin ) != visited_from_pins.end ()) {
1216
+ if (visited_to_pins.find (current_connenction->to_pin ) != visited_to_pins.end ()) {
1217
+ /* We've already seen this connection */
1218
+ current_connenction = current_connenction->next ;
1219
+ continue ;
1220
+ }
1221
+ }
1222
+ /*
1223
+ * To avoid visiting the same connection twice, since it is both stored in from_pin and to_pin,
1224
+ * add the from_pin and to_pin to the visited sets
1225
+ */
1226
+ visited_from_pins.insert (current_connenction->from_pin );
1227
+ visited_to_pins.insert (current_connenction->to_pin );
1228
+
1229
+ /* The from_pin block belongs to the pattern block */
1230
+ pattern_blocks.insert (current_connenction->from_pin ->port ->parent_pb_type );
1231
+ pack_pattern_blocks.push (current_connenction->to_block );
1232
+ current_connenction = current_connenction->next ;
1233
+ }
1234
+ }
1235
+ return pattern_blocks;
1236
+ }
1237
+
1175
1238
static void print_pack_molecules (const char * fname,
1176
1239
const std::vector<t_pack_patterns>& list_of_pack_patterns,
1177
1240
const int num_pack_patterns,
@@ -1564,9 +1627,10 @@ static void update_chain_root_pins(t_pack_patterns* chain_pattern,
1564
1627
const std::vector<t_pb_graph_pin*>& chain_input_pins) {
1565
1628
std::vector<std::vector<t_pb_graph_pin*>> primitive_input_pins;
1566
1629
1630
+ std::unordered_set<t_pb_type*> pattern_blocks = get_pattern_blocks (*chain_pattern);
1567
1631
for (const auto pin_ptr : chain_input_pins) {
1568
1632
std::vector<t_pb_graph_pin*> connected_primitive_pins;
1569
- get_all_connected_primitive_pins (pin_ptr, connected_primitive_pins);
1633
+ get_all_connected_primitive_pins (pin_ptr, pattern_blocks, connected_primitive_pins);
1570
1634
1571
1635
/* *
1572
1636
* It is required that the chain pins are connected inside a complex
@@ -1590,7 +1654,9 @@ static void update_chain_root_pins(t_pack_patterns* chain_pattern,
1590
1654
* the Cin pin of all the adder primitives connected to this pin. Which is for typical architectures
1591
1655
* will be only one pin connected to the very first adder in the cluster.
1592
1656
*/
1593
- static void get_all_connected_primitive_pins (const t_pb_graph_pin* cluster_input_pin, std::vector<t_pb_graph_pin*>& connected_primitive_pins) {
1657
+ static void get_all_connected_primitive_pins (const t_pb_graph_pin* cluster_input_pin,
1658
+ const std::unordered_set<t_pb_type*>& pattern_blocks,
1659
+ std::vector<t_pb_graph_pin*>& connected_primitive_pins) {
1594
1660
/* Skip pins for modes that are disabled for packing*/
1595
1661
if ((nullptr != cluster_input_pin->parent_node ->pb_type ->parent_mode )
1596
1662
&& (true == cluster_input_pin->parent_node ->pb_type ->parent_mode ->disable_packing )) {
@@ -1601,9 +1667,12 @@ static void get_all_connected_primitive_pins(const t_pb_graph_pin* cluster_input
1601
1667
const auto & output_edge = cluster_input_pin->output_edges [iedge];
1602
1668
for (int ipin = 0 ; ipin < output_edge->num_output_pins ; ipin++) {
1603
1669
if (output_edge->output_pins [ipin]->is_primitive_pin ()) {
1604
- connected_primitive_pins.push_back (output_edge->output_pins [ipin]);
1670
+ /* * Add the output pin to the vector only if it belongs to a pb_type registered in the pattern_blocks set */
1671
+ if (pattern_blocks.find (output_edge->output_pins [ipin]->parent_node ->pb_type ) != pattern_blocks.end ()) {
1672
+ connected_primitive_pins.push_back (output_edge->output_pins [ipin]);
1673
+ }
1605
1674
} else {
1606
- get_all_connected_primitive_pins (output_edge->output_pins [ipin], connected_primitive_pins);
1675
+ get_all_connected_primitive_pins (output_edge->output_pins [ipin], pattern_blocks, connected_primitive_pins);
1607
1676
}
1608
1677
}
1609
1678
}
0 commit comments