Skip to content

Commit 94b4c9c

Browse files
use a global map for edge type color instead of initializing it in a function
1 parent 21a57fd commit 94b4c9c

File tree

2 files changed

+24
-30
lines changed

2 files changed

+24
-30
lines changed

vpr/src/draw/draw_rr.cpp

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -233,14 +233,11 @@ void draw_rr_chan(RRNodeId inode, const ezgl::color color, ezgl::renderer* g) {
233233
g->set_color(color, transparency_factor); //Ensure color is still set correctly if we drew any arrows/text
234234
}
235235

236-
/* Draws all the edges that the user wants shown between inode and what it
237-
* connects to. inode is assumed to be a CHANX, CHANY, or IPIN. */
238236
void draw_rr_edges(RRNodeId inode, ezgl::renderer* g) {
239237
t_draw_state* draw_state = get_draw_state_vars();
240238
const DeviceContext& device_ctx = g_vpr_ctx.device();
241239
const RRGraphView& rr_graph = device_ctx.rr_graph;
242240

243-
e_rr_type to_type;
244241
e_rr_type from_type = rr_graph.node_type(inode);
245242

246243
// Currently don't visualize source or sinks.
@@ -250,7 +247,7 @@ void draw_rr_edges(RRNodeId inode, ezgl::renderer* g) {
250247

251248
for (t_edge_size iedge = 0, l = rr_graph.num_edges(inode); iedge < l; iedge++) {
252249
RRNodeId to_node = rr_graph.edge_sink_node(inode, iedge);
253-
to_type = rr_graph.node_type(to_node);
250+
e_rr_type to_type = rr_graph.node_type(to_node);
254251
bool edge_configurable = rr_graph.edge_is_configurable(inode, iedge);
255252

256253
// Currently don't visualize source or sinks.
@@ -259,36 +256,14 @@ void draw_rr_edges(RRNodeId inode, ezgl::renderer* g) {
259256
}
260257

261258
ezgl::color color = DEFAULT_RR_NODE_COLOR;
262-
e_edge_type edge_type;
263259
bool draw_edge = true;
264260
bool inode_inter_cluster = is_inter_cluster_node(rr_graph, inode);
265261
bool to_node_inter_cluster = is_inter_cluster_node(rr_graph, to_node);
266262

267-
// Color map for edges based on {from_type, to_type}
268-
const std::map<std::pair<e_rr_type, e_rr_type>, e_edge_type> edge_type_map = {
269-
// Pin to pin connections
270-
{{e_rr_type::IPIN, e_rr_type::IPIN}, e_edge_type::PIN_TO_IPIN},
271-
{{e_rr_type::OPIN, e_rr_type::IPIN}, e_edge_type::PIN_TO_IPIN},
272-
{{e_rr_type::OPIN, e_rr_type::OPIN}, e_edge_type::PIN_TO_OPIN},
273-
{{e_rr_type::IPIN, e_rr_type::OPIN}, e_edge_type::PIN_TO_OPIN},
274-
275-
// Channel to pin connections
276-
{{e_rr_type::OPIN, e_rr_type::CHANX}, e_edge_type::OPIN_TO_CHAN},
277-
{{e_rr_type::OPIN, e_rr_type::CHANY}, e_edge_type::OPIN_TO_CHAN},
278-
{{e_rr_type::CHANX, e_rr_type::IPIN}, e_edge_type::CHAN_TO_IPIN},
279-
{{e_rr_type::CHANY, e_rr_type::IPIN}, e_edge_type::CHAN_TO_IPIN},
280-
281-
// Channel to channel connections
282-
{{e_rr_type::CHANX, e_rr_type::CHANX}, e_edge_type::CHAN_TO_CHAN},
283-
{{e_rr_type::CHANX, e_rr_type::CHANY}, e_edge_type::CHAN_TO_CHAN},
284-
{{e_rr_type::CHANY, e_rr_type::CHANY}, e_edge_type::CHAN_TO_CHAN},
285-
{{e_rr_type::CHANY, e_rr_type::CHANX}, e_edge_type::CHAN_TO_CHAN},
286-
};
287-
288-
if (edge_type_map.find({from_type, to_type}) == edge_type_map.end()) {
263+
if (EDGE_TYPE_COLOR_MAP.find({from_type, to_type}) == EDGE_TYPE_COLOR_MAP.end()) {
289264
continue; // Unsupported edge type
290265
}
291-
edge_type = edge_type_map.at({from_type, to_type});
266+
e_edge_type edge_type = EDGE_TYPE_COLOR_MAP.at({from_type, to_type});
292267

293268
// Determine whether to draw the edge based on user options
294269

vpr/src/draw/draw_rr.h

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,29 @@
2323
*/
2424
void draw_rr(ezgl::renderer* g);
2525

26-
/* Draws all the edges that the user wants shown between inode and what it
27-
* connects to. inode is assumed to be a CHANX, CHANY, or IPIN. */
26+
/// @brief Draws all the edges that the user wants shown between @p from_node and what it
27+
/// connects to. @p from_node is assumed to be a CHANX, CHANY, or IPIN.
2828
void draw_rr_edges(RRNodeId from_node, ezgl::renderer* g);
2929

30+
/// Color map for edges based on {from_type, to_type}
31+
inline const std::map<std::pair<e_rr_type, e_rr_type>, e_edge_type> EDGE_TYPE_COLOR_MAP = {
32+
// Pin to pin connections
33+
{{e_rr_type::IPIN, e_rr_type::IPIN}, e_edge_type::PIN_TO_IPIN},
34+
{{e_rr_type::OPIN, e_rr_type::IPIN}, e_edge_type::PIN_TO_IPIN},
35+
{{e_rr_type::OPIN, e_rr_type::OPIN}, e_edge_type::PIN_TO_OPIN},
36+
{{e_rr_type::IPIN, e_rr_type::OPIN}, e_edge_type::PIN_TO_OPIN},
37+
// Channel to pin connections
38+
{{e_rr_type::OPIN, e_rr_type::CHANX}, e_edge_type::OPIN_TO_CHAN},
39+
{{e_rr_type::OPIN, e_rr_type::CHANY}, e_edge_type::OPIN_TO_CHAN},
40+
{{e_rr_type::CHANX, e_rr_type::IPIN}, e_edge_type::CHAN_TO_IPIN},
41+
{{e_rr_type::CHANY, e_rr_type::IPIN}, e_edge_type::CHAN_TO_IPIN},
42+
// Channel to channel connections
43+
{{e_rr_type::CHANX, e_rr_type::CHANX}, e_edge_type::CHAN_TO_CHAN},
44+
{{e_rr_type::CHANX, e_rr_type::CHANY}, e_edge_type::CHAN_TO_CHAN},
45+
{{e_rr_type::CHANY, e_rr_type::CHANY}, e_edge_type::CHAN_TO_CHAN},
46+
{{e_rr_type::CHANY, e_rr_type::CHANX}, e_edge_type::CHAN_TO_CHAN},
47+
};
48+
3049
void draw_rr_chan(RRNodeId inode, const ezgl::color color, ezgl::renderer* g);
3150

3251
/**

0 commit comments

Comments
 (0)