2727 * Date: May 16, 2012
2828 */
2929
30+ #include < unordered_map>
31+ #include < unordered_set>
3032#include < vector>
3133#include " physical_types.h"
3234#include " vtr_assert.h"
3335#include " vtr_log.h"
3436#include " vpr_types.h"
3537
36- #include " hash.h"
3738#include " cluster_feasibility_filter.h"
3839
3940/* header functions that identify pin classes */
@@ -42,18 +43,21 @@ static int get_max_depth_of_pb_graph_node(const t_pb_graph_node* pb_graph_node);
4243static void load_pin_class_by_depth (t_pb_graph_node* pb_graph_node,
4344 const int depth,
4445 int * input_count,
45- int * output_count);
46+ int * output_count,
47+ std::unordered_map<t_pb_graph_pin*, int >& pin_marker);
4648static void load_list_of_connectable_input_pin_ptrs (t_pb_graph_node* pb_graph_node);
4749static void expand_pb_graph_node_and_load_output_to_input_connections (t_pb_graph_pin* current_pb_graph_pin,
4850 t_pb_graph_pin* reference_pin,
49- const int depth);
50- static void unmark_fanout_intermediate_nodes (t_pb_graph_pin* current_pb_graph_pin);
51- static void reset_pin_class_scratch_pad_rec (t_pb_graph_node* pb_graph_node);
51+ const int depth,
52+ std::unordered_set<t_pb_graph_pin*>& seen_pins);
53+ static void unmark_fanout_intermediate_nodes (t_pb_graph_pin* current_pb_graph_pin,
54+ std::unordered_set<t_pb_graph_pin*>& seen_pins);
5255static void expand_pb_graph_node_and_load_pin_class_by_depth (t_pb_graph_pin* current_pb_graph_pin,
5356 const t_pb_graph_pin* reference_pb_graph_pin,
5457 const int depth,
5558 int * input_count,
56- int * output_count);
59+ int * output_count,
60+ std::unordered_map<t_pb_graph_pin*, int >& pin_marker);
5761static void sum_pin_class (t_pb_graph_node* pb_graph_node);
5862
5963static void discover_all_forced_connections (t_pb_graph_node* pb_graph_node);
@@ -72,12 +76,11 @@ void load_pin_classes_in_pb_graph_head(t_pb_graph_node* pb_graph_node) {
7276 depth = get_max_depth_of_pb_graph_node (pb_graph_node);
7377 for (i = 0 ; i < depth; i++) {
7478 input_count = output_count = 0 ;
75- reset_pin_class_scratch_pad_rec (pb_graph_node) ;
76- load_pin_class_by_depth (pb_graph_node, i, &input_count, &output_count);
79+ std::unordered_map<t_pb_graph_pin*, int > pin_marker ;
80+ load_pin_class_by_depth (pb_graph_node, i, &input_count, &output_count, pin_marker );
7781 }
7882
7983 /* Load internal output-to-input connections within each cluster */
80- reset_pin_class_scratch_pad_rec (pb_graph_node);
8184 load_list_of_connectable_input_pin_ptrs (pb_graph_node);
8285 discover_all_forced_connections (pb_graph_node);
8386}
@@ -156,41 +159,15 @@ static int get_max_depth_of_pb_graph_node(const t_pb_graph_node* pb_graph_node)
156159 return max_depth;
157160}
158161
159- static void reset_pin_class_scratch_pad_rec (t_pb_graph_node* pb_graph_node) {
160- int i, j, k;
161-
162- for (i = 0 ; i < pb_graph_node->num_input_ports ; i++) {
163- for (j = 0 ; j < pb_graph_node->num_input_pins [i]; j++) {
164- pb_graph_node->input_pins [i][j].scratch_pad = UNDEFINED;
165- }
166- }
167- for (i = 0 ; i < pb_graph_node->num_output_ports ; i++) {
168- for (j = 0 ; j < pb_graph_node->num_output_pins [i]; j++) {
169- pb_graph_node->output_pins [i][j].scratch_pad = UNDEFINED;
170- }
171- }
172- for (i = 0 ; i < pb_graph_node->num_clock_ports ; i++) {
173- for (j = 0 ; j < pb_graph_node->num_clock_pins [i]; j++) {
174- pb_graph_node->clock_pins [i][j].scratch_pad = UNDEFINED;
175- }
176- }
177-
178- for (i = 0 ; i < pb_graph_node->pb_type ->num_modes ; i++) {
179- for (j = 0 ; j < pb_graph_node->pb_type ->modes [i].num_pb_type_children ; j++) {
180- for (k = 0 ; k < pb_graph_node->pb_type ->modes [i].pb_type_children [j].num_pb ; k++) {
181- reset_pin_class_scratch_pad_rec (&pb_graph_node->child_pb_graph_nodes [i][j][k]);
182- }
183- }
184- }
185- }
186-
187162/* load pin class based on limited depth */
188163static void load_pin_class_by_depth (t_pb_graph_node* pb_graph_node,
189164 const int depth,
190165 int * input_count,
191- int * output_count) {
166+ int * output_count,
167+ std::unordered_map<t_pb_graph_pin*, int >& pin_marker) {
192168 int i, j, k;
193169
170+
194171 if (pb_graph_node->is_primitive ()) {
195172 if (pb_graph_node->pb_type ->depth > depth) {
196173 /* At primitive, determine which pin class each of its pins belong to */
@@ -199,7 +176,8 @@ static void load_pin_class_by_depth(t_pb_graph_node* pb_graph_node,
199176 if (pb_graph_node->input_pins [i][j].parent_pin_class [depth] == UNDEFINED) {
200177 expand_pb_graph_node_and_load_pin_class_by_depth (&pb_graph_node->input_pins [i][j],
201178 &pb_graph_node->input_pins [i][j], depth,
202- input_count, output_count);
179+ input_count, output_count,
180+ pin_marker);
203181 (*input_count)++;
204182 }
205183 }
@@ -209,7 +187,8 @@ static void load_pin_class_by_depth(t_pb_graph_node* pb_graph_node,
209187 if (pb_graph_node->output_pins [i][j].parent_pin_class [depth] == UNDEFINED) {
210188 expand_pb_graph_node_and_load_pin_class_by_depth (&pb_graph_node->output_pins [i][j],
211189 &pb_graph_node->output_pins [i][j], depth,
212- input_count, output_count);
190+ input_count, output_count,
191+ pin_marker);
213192 (*output_count)++;
214193 }
215194 }
@@ -219,7 +198,8 @@ static void load_pin_class_by_depth(t_pb_graph_node* pb_graph_node,
219198 if (pb_graph_node->clock_pins [i][j].parent_pin_class [depth] == UNDEFINED) {
220199 expand_pb_graph_node_and_load_pin_class_by_depth (&pb_graph_node->clock_pins [i][j],
221200 &pb_graph_node->clock_pins [i][j], depth,
222- input_count, output_count);
201+ input_count, output_count,
202+ pin_marker);
223203 (*input_count)++;
224204 }
225205 }
@@ -253,7 +233,7 @@ static void load_pin_class_by_depth(t_pb_graph_node* pb_graph_node,
253233 for (j = 0 ; j < pb_graph_node->pb_type ->modes [i].num_pb_type_children ; j++) {
254234 for (k = 0 ; k < pb_graph_node->pb_type ->modes [i].pb_type_children [j].num_pb ; k++) {
255235 load_pin_class_by_depth (&pb_graph_node->child_pb_graph_nodes [i][j][k], depth,
256- input_count, output_count);
236+ input_count, output_count, pin_marker );
257237 }
258238 }
259239 }
@@ -278,14 +258,18 @@ static void load_pin_class_by_depth(t_pb_graph_node* pb_graph_node,
278258static void load_list_of_connectable_input_pin_ptrs (t_pb_graph_node* pb_graph_node) {
279259 int i, j, k;
280260
261+ std::unordered_set<t_pb_graph_pin*> seen_pins;
262+
281263 if (pb_graph_node->is_primitive ()) {
282264 /* If this is a primitive, discover what input pins the output pins can connect to */
283265 for (i = 0 ; i < pb_graph_node->num_output_ports ; i++) {
284266 for (j = 0 ; j < pb_graph_node->num_output_pins [i]; j++) {
285267 for (k = 0 ; k < pb_graph_node->pb_type ->depth ; k++) {
286268 expand_pb_graph_node_and_load_output_to_input_connections (&pb_graph_node->output_pins [i][j],
287- &pb_graph_node->output_pins [i][j], k);
288- unmark_fanout_intermediate_nodes (&pb_graph_node->output_pins [i][j]);
269+ &pb_graph_node->output_pins [i][j], k,
270+ seen_pins);
271+ unmark_fanout_intermediate_nodes (&pb_graph_node->output_pins [i][j],
272+ seen_pins);
289273 }
290274 }
291275 }
@@ -305,16 +289,18 @@ static void load_list_of_connectable_input_pin_ptrs(t_pb_graph_node* pb_graph_no
305289 */
306290static void expand_pb_graph_node_and_load_output_to_input_connections (t_pb_graph_pin* current_pb_graph_pin,
307291 t_pb_graph_pin* reference_pin,
308- const int depth) {
292+ const int depth,
293+ std::unordered_set<t_pb_graph_pin*>& seen_pins) {
309294 int i;
310295
311- if (current_pb_graph_pin-> scratch_pad == UNDEFINED
296+ if (seen_pins. count ( current_pb_graph_pin) == 0
312297 && current_pb_graph_pin->parent_node ->pb_type ->depth > depth) {
313- current_pb_graph_pin-> scratch_pad = 1 ;
298+ seen_pins. insert ( current_pb_graph_pin) ;
314299 for (i = 0 ; i < current_pb_graph_pin->num_output_edges ; i++) {
315300 VTR_ASSERT (current_pb_graph_pin->output_edges [i]->num_output_pins == 1 );
316301 expand_pb_graph_node_and_load_output_to_input_connections (current_pb_graph_pin->output_edges [i]->output_pins [0 ],
317- reference_pin, depth);
302+ reference_pin, depth,
303+ seen_pins);
318304 }
319305 if (current_pb_graph_pin->is_primitive_pin ()
320306 && current_pb_graph_pin->port ->type == IN_PORT) {
@@ -343,15 +329,17 @@ static void expand_pb_graph_node_and_load_output_to_input_connections(t_pb_graph
343329}
344330
345331/* *
346- * Clear scratch_pad for all fanout of pin
332+ * Mark all fanout of pin as un-seen.
347333 */
348- static void unmark_fanout_intermediate_nodes (t_pb_graph_pin* current_pb_graph_pin) {
334+ static void unmark_fanout_intermediate_nodes (t_pb_graph_pin* current_pb_graph_pin,
335+ std::unordered_set<t_pb_graph_pin*>& seen_pins) {
349336 int i;
350- if (current_pb_graph_pin-> scratch_pad != UNDEFINED ) {
351- current_pb_graph_pin-> scratch_pad = UNDEFINED ;
337+ if (seen_pins. count ( current_pb_graph_pin) != 0 ) {
338+ seen_pins. erase ( current_pb_graph_pin) ;
352339 for (i = 0 ; i < current_pb_graph_pin->num_output_edges ; i++) {
353340 VTR_ASSERT (current_pb_graph_pin->output_edges [i]->num_output_pins == 1 );
354- unmark_fanout_intermediate_nodes (current_pb_graph_pin->output_edges [i]->output_pins [0 ]);
341+ unmark_fanout_intermediate_nodes (current_pb_graph_pin->output_edges [i]->output_pins [0 ],
342+ seen_pins);
355343 }
356344 }
357345}
@@ -363,7 +351,8 @@ static void expand_pb_graph_node_and_load_pin_class_by_depth(t_pb_graph_pin* cur
363351 const t_pb_graph_pin* reference_pb_graph_pin,
364352 const int depth,
365353 int * input_count,
366- int * output_count) {
354+ int * output_count,
355+ std::unordered_map<t_pb_graph_pin*, int >& pin_marker) {
367356 int i;
368357 int marker;
369358 int active_pin_class;
@@ -378,9 +367,9 @@ static void expand_pb_graph_node_and_load_pin_class_by_depth(t_pb_graph_pin* cur
378367 VTR_ASSERT (reference_pb_graph_pin->is_primitive_pin ());
379368 VTR_ASSERT (current_pb_graph_pin->parent_node ->pb_type ->depth >= depth);
380369 VTR_ASSERT (current_pb_graph_pin->port ->type != INOUT_PORT);
381- if (current_pb_graph_pin-> scratch_pad != marker) {
370+ if (pin_marker. count ( current_pb_graph_pin) == 0 || pin_marker[current_pb_graph_pin] != marker) {
382371 if (current_pb_graph_pin->is_primitive_pin ()) {
383- current_pb_graph_pin-> scratch_pad = marker;
372+ pin_marker[ current_pb_graph_pin] = marker;
384373 /* This is a primitive, determine what pins cans share the same pin class as the reference pin */
385374 if (current_pb_graph_pin->parent_pin_class [depth] == UNDEFINED
386375 && reference_pb_graph_pin->port ->is_clock == current_pb_graph_pin->port ->is_clock
@@ -391,16 +380,16 @@ static void expand_pb_graph_node_and_load_pin_class_by_depth(t_pb_graph_pin* cur
391380 VTR_ASSERT (current_pb_graph_pin->input_edges [i]->num_input_pins == 1 );
392381 expand_pb_graph_node_and_load_pin_class_by_depth (current_pb_graph_pin->input_edges [i]->input_pins [0 ],
393382 reference_pb_graph_pin, depth, input_count,
394- output_count);
383+ output_count, pin_marker );
395384 }
396385 for (i = 0 ; i < current_pb_graph_pin->num_output_edges ; i++) {
397386 VTR_ASSERT (current_pb_graph_pin->output_edges [i]->num_output_pins == 1 );
398387 expand_pb_graph_node_and_load_pin_class_by_depth (current_pb_graph_pin->output_edges [i]->output_pins [0 ],
399388 reference_pb_graph_pin, depth, input_count,
400- output_count);
389+ output_count, pin_marker );
401390 }
402391 } else if (current_pb_graph_pin->parent_node ->pb_type ->depth == depth) {
403- current_pb_graph_pin-> scratch_pad = marker;
392+ pin_marker[ current_pb_graph_pin] = marker;
404393 if (current_pb_graph_pin->port ->type == OUT_PORT) {
405394 if (reference_pb_graph_pin->port ->type == OUT_PORT) {
406395 /* This cluster's output pin can be driven by primitive outputs belonging to this pin class */
@@ -410,7 +399,7 @@ static void expand_pb_graph_node_and_load_pin_class_by_depth(t_pb_graph_pin* cur
410399 VTR_ASSERT (current_pb_graph_pin->input_edges [i]->num_input_pins == 1 );
411400 expand_pb_graph_node_and_load_pin_class_by_depth (current_pb_graph_pin->input_edges [i]->input_pins [0 ],
412401 reference_pb_graph_pin, depth, input_count,
413- output_count);
402+ output_count, pin_marker );
414403 }
415404 }
416405 if (current_pb_graph_pin->port ->type == IN_PORT) {
@@ -422,23 +411,23 @@ static void expand_pb_graph_node_and_load_pin_class_by_depth(t_pb_graph_pin* cur
422411 VTR_ASSERT (current_pb_graph_pin->output_edges [i]->num_output_pins == 1 );
423412 expand_pb_graph_node_and_load_pin_class_by_depth (current_pb_graph_pin->output_edges [i]->output_pins [0 ],
424413 reference_pb_graph_pin, depth, input_count,
425- output_count);
414+ output_count, pin_marker );
426415 }
427416 }
428417 } else if (current_pb_graph_pin->parent_node ->pb_type ->depth > depth) {
429418 /* Inside an intermediate cluster, traverse to either a primitive or to the cluster we're interested in populating */
430- current_pb_graph_pin-> scratch_pad = marker;
419+ pin_marker[ current_pb_graph_pin] = marker;
431420 for (i = 0 ; i < current_pb_graph_pin->num_input_edges ; i++) {
432421 VTR_ASSERT (current_pb_graph_pin->input_edges [i]->num_input_pins == 1 );
433422 expand_pb_graph_node_and_load_pin_class_by_depth (current_pb_graph_pin->input_edges [i]->input_pins [0 ],
434423 reference_pb_graph_pin, depth, input_count,
435- output_count);
424+ output_count, pin_marker );
436425 }
437426 for (i = 0 ; i < current_pb_graph_pin->num_output_edges ; i++) {
438427 VTR_ASSERT (current_pb_graph_pin->output_edges [i]->num_output_pins == 1 );
439428 expand_pb_graph_node_and_load_pin_class_by_depth (current_pb_graph_pin->output_edges [i]->output_pins [0 ],
440429 reference_pb_graph_pin, depth, input_count,
441- output_count);
430+ output_count, pin_marker );
442431 }
443432 }
444433 }
0 commit comments