Skip to content

Commit 15b04dd

Browse files
committed
[vpr][pack] add get_pattern_blocks
1 parent 81c3425 commit 15b04dd

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

vpr/src/pack/prepack.cpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,14 @@ static AtomBlockId get_driving_block(const AtomBlockId block_id,
117117
const t_pack_pattern_connections& connections,
118118
const AtomNetlist& atom_nlist);
119119

120+
/**
121+
* @brief Get an unordered set of all pb_types in the given pack pattern
122+
*
123+
* @param pack_pattern Pack pattern to get pb_types from
124+
* @return std::unordered_set<t_pb_type*> Set of pb_types in the pack pattern
125+
*/
126+
static std::unordered_set<t_pb_type*> get_pattern_blocks(const t_pack_patterns* pack_pattern);
127+
120128
static void print_chain_starting_points(t_pack_patterns* chain_pattern);
121129

122130
/*****************************************/
@@ -1172,6 +1180,47 @@ static AtomBlockId get_driving_block(const AtomBlockId block_id,
11721180
return AtomBlockId::INVALID();
11731181
}
11741182

1183+
static std::unordered_set<t_pb_type*> get_pattern_blocks(const t_pack_patterns* pack_pattern) {
1184+
std::unordered_set<t_pb_type*> pattern_blocks;
1185+
1186+
auto connections = pack_pattern->root_block->connections;
1187+
if (connections == nullptr) {
1188+
return pattern_blocks;
1189+
}
1190+
std::unordered_set<t_pb_graph_pin*> visited_from_pins;
1191+
std::unordered_set<t_pb_graph_pin*> visited_to_pins;
1192+
std::queue<t_pack_pattern_block*> pack_pattern_blocks;
1193+
pack_pattern_blocks.push(connections->from_block);
1194+
/** Start from the root block of the pack pattern and add the connected block to the queue */
1195+
while (!pack_pattern_blocks.empty()) {
1196+
auto current_pattern_block = pack_pattern_blocks.front();
1197+
pack_pattern_blocks.pop();
1198+
auto current_connenction = current_pattern_block->connections;
1199+
/** Iterate through all the connections of the current pattern block to
1200+
* add the connected block to the queue
1201+
*/
1202+
while (current_connenction != nullptr) {
1203+
if (visited_from_pins.count(current_connenction->from_pin)) {
1204+
if (visited_to_pins.count(current_connenction->to_pin)) {
1205+
/* We've already seen this connection */
1206+
current_connenction = current_connenction->next;
1207+
continue;
1208+
}
1209+
}
1210+
/** To avoid visiting the same connection twice, since it is both stored in from_pin and to_pin,
1211+
* add the from_pin and to_pin to the visited sets
1212+
*/
1213+
visited_from_pins.insert(current_connenction->from_pin);
1214+
visited_to_pins.insert(current_connenction->to_pin);
1215+
/** The from_pin block belongs to the pattern block */
1216+
pattern_blocks.insert(current_connenction->from_pin->port->parent_pb_type);
1217+
pack_pattern_blocks.push(current_connenction->to_block);
1218+
current_connenction = current_connenction->next;
1219+
}
1220+
}
1221+
return pattern_blocks;
1222+
}
1223+
11751224
static void print_pack_molecules(const char* fname,
11761225
const std::vector<t_pack_patterns>& list_of_pack_patterns,
11771226
const int num_pack_patterns,

0 commit comments

Comments
 (0)