|
6 | 6 | #include "route_common.h"
|
7 | 7 |
|
8 | 8 | #include <vector>
|
| 9 | +#include <stack> |
9 | 10 |
|
10 | 11 | std::pair<t_trace*, t_trace*> traceback_from_route_tree_recurr(t_trace* head, t_trace* tail, const RouteTreeNode& node);
|
11 |
| -bool validate_traceback_recurr(t_trace* trace, std::set<int>& seen_rr_nodes); |
12 | 12 | void free_trace_data(t_trace* tptr);
|
13 | 13 |
|
14 | 14 | /** Build a route tree from a traceback */
|
@@ -109,7 +109,7 @@ t_trace* TracebackCompat::traceback_from_route_tree(const RouteTree& tree) {
|
109 | 109 |
|
110 | 110 | std::tie(head, tail) = traceback_from_route_tree_recurr(nullptr, nullptr, tree.root());
|
111 | 111 |
|
112 |
| - VTR_ASSERT(validate_traceback(head)); |
| 112 | + VTR_ASSERT(validate_and_update_traceback(head)); |
113 | 113 |
|
114 | 114 | return head;
|
115 | 115 | }
|
@@ -141,70 +141,65 @@ void print_traceback(const t_trace* trace) {
|
141 | 141 | VTR_LOG("\n");
|
142 | 142 | }
|
143 | 143 |
|
144 |
| -bool validate_traceback(t_trace* trace) { |
145 |
| - std::set<int> seen_rr_nodes; |
146 |
| - |
147 |
| - return validate_traceback_recurr(trace, seen_rr_nodes); |
148 |
| -} |
149 |
| - |
150 |
| -bool validate_traceback_recurr(t_trace* trace, std::set<int>& seen_rr_nodes) { |
| 144 | +bool validate_and_update_traceback(t_trace* trace, bool verify_switch_id /* = true */) { |
151 | 145 | if (!trace) {
|
152 | 146 | return true;
|
153 | 147 | }
|
154 | 148 |
|
155 |
| - seen_rr_nodes.insert(trace->index); |
| 149 | + std::set<int> seen_rr_nodes; |
| 150 | + std::stack<t_trace*> trace_stack; |
| 151 | + trace_stack.push(trace); |
156 | 152 |
|
157 |
| - t_trace* next = trace->next; |
| 153 | + while (!trace_stack.empty()) { |
| 154 | + trace = trace_stack.top(); |
| 155 | + trace_stack.pop(); |
| 156 | + seen_rr_nodes.insert(trace->index); |
| 157 | + t_trace* next = trace->next; |
158 | 158 |
|
159 |
| - if (next) { |
160 |
| - if (trace->iswitch == OPEN) { //End of a branch |
| 159 | + if (next == nullptr) { |
| 160 | + continue; |
| 161 | + } |
161 | 162 |
|
162 |
| - //Verify that the next element (branch point) has been already seen in the traceback so far |
| 163 | + if (trace->iswitch == OPEN) { // End of a branch |
| 164 | + // Verify that the next element (branch point) has been already seen in the traceback so far |
163 | 165 | if (!seen_rr_nodes.count(next->index)) {
|
164 | 166 | VPR_FATAL_ERROR(VPR_ERROR_ROUTE, "Traceback branch point %d not found", next->index);
|
165 |
| - } else { |
166 |
| - //Recurse along the new branch |
167 |
| - return validate_traceback_recurr(next, seen_rr_nodes); |
168 | 167 | }
|
169 |
| - } else { //Midway along branch |
170 |
| - |
171 |
| - //Check there is an edge connecting trace and next |
172 |
| - |
173 |
| - auto& device_ctx = g_vpr_ctx.device(); |
174 |
| - const auto& rr_graph = device_ctx.rr_graph; |
| 168 | + } else { // Midway along branch |
| 169 | + // Check there is an edge connecting trace and next |
| 170 | + const auto& rr_graph = g_vpr_ctx.device().rr_graph; |
175 | 171 | bool found = false;
|
176 | 172 | for (t_edge_size iedge = 0; iedge < rr_graph.num_edges(RRNodeId(trace->index)); ++iedge) {
|
177 | 173 | int to_node = size_t(rr_graph.edge_sink_node(RRNodeId(trace->index), iedge));
|
178 |
| - |
179 | 174 | if (to_node == next->index) {
|
180 | 175 | found = true;
|
181 |
| - |
182 |
| - //Verify that the switch matches |
183 | 176 | int rr_iswitch = rr_graph.edge_switch(RRNodeId(trace->index), iedge);
|
184 |
| - if (trace->iswitch != rr_iswitch) { |
185 |
| - VPR_FATAL_ERROR(VPR_ERROR_ROUTE, "Traceback mismatched switch type: traceback %d rr_graph %d (RR nodes %d -> %d)\n", |
186 |
| - trace->iswitch, rr_iswitch, |
187 |
| - trace->index, to_node); |
| 177 | + if (verify_switch_id) { |
| 178 | + // Verify that the switch matches |
| 179 | + if (trace->iswitch != rr_iswitch) { |
| 180 | + VPR_FATAL_ERROR(VPR_ERROR_ROUTE, "Traceback mismatched switch type: traceback %d rr_graph %d (RR nodes %d -> %d)\n", |
| 181 | + trace->iswitch, rr_iswitch, |
| 182 | + trace->index, to_node); |
| 183 | + } |
| 184 | + } else { |
| 185 | + // Update the switch ID in the traceback to match the RR Graph |
| 186 | + trace->iswitch = rr_iswitch; |
188 | 187 | }
|
189 | 188 | break;
|
190 | 189 | }
|
191 | 190 | }
|
192 |
| - |
193 | 191 | if (!found) {
|
194 | 192 | VPR_FATAL_ERROR(VPR_ERROR_ROUTE, "Traceback no RR edge between RR nodes %d -> %d\n", trace->index, next->index);
|
195 | 193 | }
|
196 |
| - |
197 |
| - //Recurse |
198 |
| - return validate_traceback_recurr(next, seen_rr_nodes); |
199 | 194 | }
|
| 195 | + // Recurse |
| 196 | + trace_stack.push(next); |
200 | 197 | }
|
201 | 198 |
|
202 |
| - VTR_ASSERT(!next); |
203 |
| - return true; //End of traceback |
| 199 | + return true; |
204 | 200 | }
|
205 | 201 |
|
206 |
| -t_trace* |
207 |
| -alloc_trace_data() { |
| 202 | +t_trace* alloc_trace_data() { |
208 | 203 | return (t_trace*)malloc(sizeof(t_trace));
|
209 | 204 | }
|
210 | 205 |
|
|
0 commit comments