Skip to content

Commit 576c5c3

Browse files
Merge pull request verilog-to-routing#3007 from verilog-to-routing/pack_pattern_root_block
[Pack] Pack Pattern Root IPIN
2 parents 8fdbe93 + 2c8b2c5 commit 576c5c3

File tree

1 file changed

+74
-5
lines changed

1 file changed

+74
-5
lines changed

vpr/src/pack/prepack.cpp

Lines changed: 74 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,17 @@ static void find_all_equivalent_chains(t_pack_patterns* chain_pattern, const t_p
9999
static void update_chain_root_pins(t_pack_patterns* chain_pattern,
100100
const std::vector<t_pb_graph_pin*>& chain_input_pins);
101101

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);
103113

104114
static void init_molecule_chain_info(const AtomBlockId blk_id,
105115
t_pack_molecule& molecule,
@@ -117,6 +127,14 @@ static AtomBlockId get_driving_block(const AtomBlockId block_id,
117127
const t_pack_pattern_connections& connections,
118128
const AtomNetlist& atom_nlist);
119129

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+
120138
static void print_chain_starting_points(t_pack_patterns* chain_pattern);
121139

122140
/*****************************************/
@@ -1172,6 +1190,51 @@ static AtomBlockId get_driving_block(const AtomBlockId block_id,
11721190
return AtomBlockId::INVALID();
11731191
}
11741192

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+
11751238
static void print_pack_molecules(const char* fname,
11761239
const std::vector<t_pack_patterns>& list_of_pack_patterns,
11771240
const int num_pack_patterns,
@@ -1564,9 +1627,10 @@ static void update_chain_root_pins(t_pack_patterns* chain_pattern,
15641627
const std::vector<t_pb_graph_pin*>& chain_input_pins) {
15651628
std::vector<std::vector<t_pb_graph_pin*>> primitive_input_pins;
15661629

1630+
std::unordered_set<t_pb_type*> pattern_blocks = get_pattern_blocks(*chain_pattern);
15671631
for (const auto pin_ptr : chain_input_pins) {
15681632
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);
15701634

15711635
/**
15721636
* 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,
15901654
* the Cin pin of all the adder primitives connected to this pin. Which is for typical architectures
15911655
* will be only one pin connected to the very first adder in the cluster.
15921656
*/
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) {
15941660
/* Skip pins for modes that are disabled for packing*/
15951661
if ((nullptr != cluster_input_pin->parent_node->pb_type->parent_mode)
15961662
&& (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
16011667
const auto& output_edge = cluster_input_pin->output_edges[iedge];
16021668
for (int ipin = 0; ipin < output_edge->num_output_pins; ipin++) {
16031669
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+
}
16051674
} 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);
16071676
}
16081677
}
16091678
}

0 commit comments

Comments
 (0)