@@ -134,6 +134,9 @@ static bool check_input_pins_equivalence(const t_pb_graph_pin* cur_pin,
134134 const int i_pin,
135135 std::map<int , int >& edges_map,
136136 int * line_num);
137+ static int compute_flat_index_for_child_node (int num_children_of_type,
138+ int parent_flat_index,
139+ int child_index);
137140
138141/* *
139142 * Allocate memory into types and load the pb graph with interconnect edges
@@ -240,7 +243,7 @@ static void alloc_and_load_pb_graph(t_pb_graph_node* pb_graph_node,
240243 pb_graph_node->num_clock_ports = 0 ;
241244
242245 pb_graph_node->total_primitive_count = 0 ;
243- pb_graph_node->flat_site_index = flat_index ;
246+ pb_graph_node->flat_site_index = 0 ;
244247
245248 /* Generate ports for pb graph node */
246249 for (i = 0 ; i < pb_type->num_ports ; i++) {
@@ -353,14 +356,15 @@ static void alloc_and_load_pb_graph(t_pb_graph_node* pb_graph_node,
353356 sizeof (t_pb_graph_node*));
354357 for (j = 0 ; j < pb_type->modes [i].num_pb_type_children ; j++) {
355358 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));
356- int base = flat_index*( pb_type->modes [i].pb_type_children [j].num_pb ) ;
359+ int num_children_of_type = pb_type->modes [i].pb_type_children [j].num_pb ;
357360
358- for (k = 0 ; k < pb_type->modes [i].pb_type_children [j].num_pb ; k++) {
361+ for (k = 0 ; k < num_children_of_type; k++) {
362+ int child_flat_index = compute_flat_index_for_child_node (num_children_of_type, flat_index, k);
359363 alloc_and_load_pb_graph (&pb_graph_node->child_pb_graph_nodes [i][j][k],
360364 pb_graph_node,
361365 &pb_type->modes [i].pb_type_children [j],
362366 k,
363- base + k ,
367+ child_flat_index ,
364368 load_power_structures,
365369 pin_count_in_cluster);
366370 }
@@ -387,6 +391,10 @@ static void alloc_and_load_pb_graph(t_pb_graph_node* pb_graph_node,
387391 pb_node = pb_node->parent_pb_graph_node ;
388392 }
389393 pb_graph_node->total_primitive_count = total_count;
394+
395+ // if this is a primitive, then flat_index corresponds
396+ // to its index within all primitives of this type
397+ pb_graph_node->flat_site_index = flat_index;
390398 }
391399}
392400
@@ -1921,3 +1929,22 @@ const t_pb_graph_edge* get_edge_between_pins(const t_pb_graph_pin* driver_pin, c
19211929
19221930 return nullptr ;
19231931}
1932+
1933+ /* Date:June 8th, 2024
1934+ * Author: Kate Thurmer
1935+ * Purpose: This subroutine computes the index of a pb graph node at its
1936+ level of the pb hierarchy; it is computed by the parent and
1937+ passed to each child of each child pb type. When the child is
1938+ a primitive, the computed indes is its flat site index.
1939+ For example, if there are 10 ALMs, each with 2 FFs and 2 LUTs,
1940+ then the ALM at index N, when calling this function for
1941+ its FF child at index M, would compute the child's index as:
1942+ N*(FFs per ALM) + M
1943+ e.g. for FF[1] in ALM[5], this returns
1944+ 5*(2 FFS per ALM) + 1 = 11
1945+ */
1946+ static int compute_flat_index_for_child_node (int num_children_of_type,
1947+ int parent_flat_index,
1948+ int child_index) {
1949+ return parent_flat_index*num_children_of_type + child_index;
1950+ }
0 commit comments