Skip to content

Commit d10f7dd

Browse files
committed
[vpr][base] use std::set instead of having update_rr_switch_id as a recursive function
1 parent 536d009 commit d10f7dd

File tree

1 file changed

+39
-35
lines changed

1 file changed

+39
-35
lines changed

vpr/src/base/read_route.cpp

Lines changed: 39 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <cstdio>
1818
#include <sstream>
1919
#include <string>
20+
#include <stack>
2021

2122
#include "physical_types_util.h"
2223
#include "vtr_assert.h"
@@ -99,13 +100,9 @@ static void process_nets(const Netlist<>& net_list,
99100
/**
100101
* @brief Update the switch IDs in the routing trace to match the RR Graph.
101102
*
102-
* @note This function is called recursively to update the switch IDs in the routing trace.
103-
*
104103
* @param trace Pointer to the head of the routing trace of the net to update.
105-
* @param seen_rr_nodes A set of seen RR nodes to avoid duplicate updates.
106104
*/
107-
static void update_rr_switch_id(t_trace* trace,
108-
std::set<int>& seen_rr_nodes);
105+
static void update_rr_switch_id(t_trace* trace);
109106

110107
/**
111108
* @brief This function goes through all the blocks in a global net and verify
@@ -522,54 +519,61 @@ static void process_nodes(const Netlist<>& net_list,
522519
if (verify_route_file_switch_id ) {
523520
VTR_ASSERT(validate_traceback(head_ptr));
524521
} else {
525-
std::set<int> seen_rr_nodes;
526-
update_rr_switch_id(head_ptr, seen_rr_nodes);
522+
update_rr_switch_id(head_ptr);
527523
}
528524

529525
/* Convert to route_tree after reading */
530526
route_ctx.route_trees[inet] = TracebackCompat::traceback_to_route_tree(head_ptr);
531527
free_traceback(head_ptr);
532528
}
533529

534-
static void update_rr_switch_id(t_trace* trace, std::set<int>& seen_rr_nodes) {
530+
static void update_rr_switch_id(t_trace* trace) {
535531
if (trace == nullptr) {
536532
return;
537533
}
538534

539-
seen_rr_nodes.insert(trace->index);
535+
std::set<int> seen_rr_nodes;
540536

541-
t_trace* next = trace->next;
537+
std::stack<t_trace*> trace_stack;
538+
trace_stack.push(trace);
542539

543-
if (next == nullptr) {
544-
return;
545-
}
546540

547-
if (trace->iswitch == OPEN) { // End of a branch
548-
// Verify that the next element (branch point) has been already seen in the traceback so far
549-
if (!seen_rr_nodes.count(next->index)) {
550-
VPR_FATAL_ERROR(VPR_ERROR_ROUTE, "Traceback branch point %d not found", next->index);
541+
while (!trace_stack.empty()) {
542+
trace = trace_stack.top();
543+
trace_stack.pop();
544+
seen_rr_nodes.insert(trace->index);
545+
t_trace* next = trace->next;
546+
547+
if (next == nullptr) {
548+
continue;
551549
}
552-
} else { // Midway along branch
553-
// Check there is an edge connecting trace and next
554-
const auto& rr_graph = g_vpr_ctx.device().rr_graph;
555-
bool found = false;
556-
for (t_edge_size iedge = 0; iedge < rr_graph.num_edges(RRNodeId(trace->index)); ++iedge) {
557-
int to_node = size_t(rr_graph.edge_sink_node(RRNodeId(trace->index), iedge));
558-
if (to_node == next->index) {
559-
found = true;
560-
561-
// Verify that the switch matches
562-
int rr_iswitch = rr_graph.edge_switch(RRNodeId(trace->index), iedge);
563-
trace->iswitch = rr_iswitch;
564-
break;
550+
551+
if (trace->iswitch == OPEN) { // End of a branch
552+
// Verify that the next element (branch point) has been already seen in the traceback so far
553+
if (!seen_rr_nodes.count(next->index)) {
554+
VPR_FATAL_ERROR(VPR_ERROR_ROUTE, "Traceback branch point %d not found", next->index);
555+
}
556+
} else { // Midway along branch
557+
// Check there is an edge connecting trace and next
558+
const auto& rr_graph = g_vpr_ctx.device().rr_graph;
559+
bool found = false;
560+
for (t_edge_size iedge = 0; iedge < rr_graph.num_edges(RRNodeId(trace->index)); ++iedge) {
561+
int to_node = size_t(rr_graph.edge_sink_node(RRNodeId(trace->index), iedge));
562+
if (to_node == next->index) {
563+
found = true;
564+
565+
// Verify that the switch matches
566+
int rr_iswitch = rr_graph.edge_switch(RRNodeId(trace->index), iedge);
567+
trace->iswitch = rr_iswitch;
568+
break;
569+
}
570+
}
571+
if (!found) {
572+
VPR_FATAL_ERROR(VPR_ERROR_ROUTE, "Traceback no RR edge between RR nodes %d -> %d\n", trace->index, next->index);
565573
}
566574
}
567-
if (!found) {
568-
VPR_FATAL_ERROR(VPR_ERROR_ROUTE, "Traceback no RR edge between RR nodes %d -> %d\n", trace->index, next->index);
569-
}
575+
trace_stack.push(next);
570576
}
571-
// Recurse
572-
update_rr_switch_id(next, seen_rr_nodes);
573577
}
574578

575579
static void process_global_blocks(const Netlist<>& net_list, std::ifstream& fp, ClusterNetId inet, const char* filename, int& lineno, bool is_flat) {

0 commit comments

Comments
 (0)