@@ -48,6 +48,7 @@ static void alloc_and_load_pb_graph(t_pb_graph_node* pb_graph_node,
4848 t_pb_graph_node* parent_pb_graph_node,
4949 t_pb_type* pb_type,
5050 const int index,
51+ const int flat_index,
5152 bool load_power_structures,
5253 int & pin_count_in_cluster);
5354
@@ -134,6 +135,11 @@ static bool check_input_pins_equivalence(const t_pb_graph_pin* cur_pin,
134135 std::map<int , int >& edges_map,
135136 int * line_num);
136137
138+ /* computes the index of a pb graph node at its level of the pb hierarchy */
139+ static int compute_flat_index_for_child_node (int num_children_of_type,
140+ int parent_flat_index,
141+ int child_index);
142+
137143/* *
138144 * Allocate memory into types and load the pb graph with interconnect edges
139145 */
@@ -151,6 +157,7 @@ void alloc_and_load_all_pb_graphs(bool load_power_structures, bool is_flat) {
151157 nullptr ,
152158 type.pb_type ,
153159 0 ,
160+ 0 ,
154161 load_power_structures,
155162 pin_count_in_cluster);
156163 type.pb_graph_head ->total_pb_pins = pin_count_in_cluster;
@@ -224,6 +231,7 @@ static void alloc_and_load_pb_graph(t_pb_graph_node* pb_graph_node,
224231 t_pb_graph_node* parent_pb_graph_node,
225232 t_pb_type* pb_type,
226233 const int index,
234+ const int flat_index,
227235 bool load_power_structures,
228236 int & pin_count_in_cluster) {
229237 int i, j, k, i_input, i_output, i_clockport;
@@ -237,6 +245,7 @@ static void alloc_and_load_pb_graph(t_pb_graph_node* pb_graph_node,
237245 pb_graph_node->num_clock_ports = 0 ;
238246
239247 pb_graph_node->total_primitive_count = 0 ;
248+ pb_graph_node->flat_site_index = 0 ;
240249
241250 /* Generate ports for pb graph node */
242251 for (i = 0 ; i < pb_type->num_ports ; i++) {
@@ -349,11 +358,15 @@ static void alloc_and_load_pb_graph(t_pb_graph_node* pb_graph_node,
349358 sizeof (t_pb_graph_node*));
350359 for (j = 0 ; j < pb_type->modes [i].num_pb_type_children ; j++) {
351360 pb_graph_node->child_pb_graph_nodes [i][j] = (t_pb_graph_node*)vtr::calloc (pb_type->modes [i].pb_type_children [j].num_pb , sizeof (t_pb_graph_node));
352- for (k = 0 ; k < pb_type->modes [i].pb_type_children [j].num_pb ; k++) {
361+ int num_children_of_type = pb_type->modes [i].pb_type_children [j].num_pb ;
362+
363+ for (k = 0 ; k < num_children_of_type; k++) {
364+ int child_flat_index = compute_flat_index_for_child_node (num_children_of_type, flat_index, k);
353365 alloc_and_load_pb_graph (&pb_graph_node->child_pb_graph_nodes [i][j][k],
354366 pb_graph_node,
355367 &pb_type->modes [i].pb_type_children [j],
356368 k,
369+ child_flat_index,
357370 load_power_structures,
358371 pin_count_in_cluster);
359372 }
@@ -380,6 +393,10 @@ static void alloc_and_load_pb_graph(t_pb_graph_node* pb_graph_node,
380393 pb_node = pb_node->parent_pb_graph_node ;
381394 }
382395 pb_graph_node->total_primitive_count = total_count;
396+
397+ // if this is a primitive, then flat_index corresponds
398+ // to its index within all primitives of this type
399+ pb_graph_node->flat_site_index = flat_index;
383400 }
384401}
385402
@@ -1914,3 +1931,22 @@ const t_pb_graph_edge* get_edge_between_pins(const t_pb_graph_pin* driver_pin, c
19141931
19151932 return nullptr ;
19161933}
1934+
1935+ /* Date:June 8th, 2024
1936+ * Author: Kate Thurmer
1937+ * Purpose: This subroutine computes the index of a pb graph node at its
1938+ level of the pb hierarchy; it is computed by the parent and
1939+ passed to each child of each child pb type. When the child is
1940+ a primitive, the computed indes is its flat site index.
1941+ For example, if there are 10 ALMs, each with 2 FFs and 2 LUTs,
1942+ then the ALM at index N, when calling this function for
1943+ its FF child at index M, would compute the child's index as:
1944+ N*(FFs per ALM) + M
1945+ e.g. for FF[1] in ALM[5], this returns
1946+ 5*(2 FFS per ALM) + 1 = 11
1947+ */
1948+ static int compute_flat_index_for_child_node (int num_children_of_type,
1949+ int parent_flat_index,
1950+ int child_index) {
1951+ return parent_flat_index*num_children_of_type + child_index;
1952+ }
0 commit comments