Skip to content

Commit 42ccf87

Browse files
Merge pull request #3296 from verilog-to-routing/temp_draw_edges_cleanup
Move std::map initialization outside of draw_rr_edges() to avoid redundant reinitialization.
2 parents 21a57fd + 60628a3 commit 42ccf87

File tree

11 files changed

+60
-72
lines changed

11 files changed

+60
-72
lines changed

libs/libarchfpga/src/physical_types.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1543,11 +1543,11 @@ enum class e_stat {
15431543
/// @note If detailed routing is performed, only a uniform (all channels in a given direction are the same width)
15441544
/// distribution is supported.
15451545
struct t_chan {
1546-
e_stat type; ///< Distribution type
1547-
float peak; ///< Peak value. For a UNIFORM distribution, this is the value for all channels (in a given direction).
1548-
float width; ///< Standard deviation (Gaussian)
1549-
float xpeak; ///< Peak location (Gaussian)
1550-
float dc; ///< DC offset (Gaussian, pulse)
1546+
e_stat type; ///< Distribution type
1547+
float peak; ///< Peak value. For a UNIFORM distribution, this is the value for all channels (in a given direction).
1548+
float width; ///< Standard deviation (Gaussian)
1549+
float xpeak; ///< Peak location (Gaussian)
1550+
float dc; ///< DC offset (Gaussian, pulse)
15511551
};
15521552

15531553
/* chan_x_dist: Describes the x-directed channel width distribution. *

vpr/src/base/read_blif.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,10 +244,10 @@ struct BlifAllocCallback : public blifparse::Callback {
244244
VTR_ASSERT(ports.size() == nets.size());
245245

246246
LogicalModelId blk_model_id = models_.get_model_by_name(subckt_model);
247-
if(!blk_model_id.is_valid()) {
247+
if (!blk_model_id.is_valid()) {
248248
vpr_throw(VPR_ERROR_BLIF_F, filename_.c_str(), lineno_,
249-
"Subckt instantiates model '%s', but no such model exists in the architecture file.",
250-
subckt_model.c_str());
249+
"Subckt instantiates model '%s', but no such model exists in the architecture file.",
250+
subckt_model.c_str());
251251
}
252252
const t_model& blk_model = models_.get_model(blk_model_id);
253253

vpr/src/draw/draw_basic.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,7 @@ void drawplace(ezgl::renderer* g) {
165165
if (draw_state->draw_block_text) {
166166
/* Draw text if the space has parts of the netlist */
167167
if (bnum) {
168-
std::string name = cluster_ctx.clb_nlist.block_name(
169-
bnum)
170-
+ vtr::string_fmt(" (#%zu)", size_t(bnum));
168+
std::string name = cluster_ctx.clb_nlist.block_name(bnum) + vtr::string_fmt(" (#%zu)", size_t(bnum));
171169

172170
g->draw_text(center, name.c_str(), abs_clb_bbox.width(),
173171
abs_clb_bbox.height());

vpr/src/draw/draw_debug.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,7 @@ bool valid_expression(std::string exp) {
772772
vtr::t_formula_data dummy;
773773
try {
774774
int result = fp.parse_formula(exp, dummy, true);
775-
(void)result;
775+
(void)result;
776776
} catch (const vtr::VtrError& e) {
777777
return false;
778778
}

vpr/src/draw/draw_mux.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,31 +19,32 @@
1919
//Draws a mux, height/width define the bounding box, scale [0.,1.] controls the slope of the muxes sides
2020
ezgl::rectangle draw_mux(ezgl::point2d origin, e_side orientation, float height, float width, float scale, ezgl::renderer* g) {
2121
std::vector<ezgl::point2d> mux_polygon;
22+
mux_polygon.reserve(4);
2223

2324
switch (orientation) {
2425
case TOP:
25-
//Clock-wise from bottom left
26+
// Clock-wise from bottom left
2627
mux_polygon.emplace_back(origin.x - height / 2, origin.y - width / 2);
2728
mux_polygon.emplace_back(origin.x - (scale * height) / 2, origin.y + width / 2);
2829
mux_polygon.emplace_back(origin.x + (scale * height) / 2, origin.y + width / 2);
2930
mux_polygon.emplace_back(origin.x + height / 2, origin.y - width / 2);
3031
break;
3132
case BOTTOM:
32-
//Clock-wise from bottom left
33+
// Clock-wise from bottom left
3334
mux_polygon.emplace_back(origin.x - (scale * height) / 2, origin.y - width / 2);
3435
mux_polygon.emplace_back(origin.x - height / 2, origin.y + width / 2);
3536
mux_polygon.emplace_back(origin.x + height / 2, origin.y + width / 2);
3637
mux_polygon.emplace_back(origin.x + (scale * height) / 2, origin.y - width / 2);
3738
break;
3839
case LEFT:
39-
//Clock-wise from bottom left
40+
// Clock-wise from bottom left
4041
mux_polygon.emplace_back(origin.x - width / 2, origin.y - (scale * height) / 2);
4142
mux_polygon.emplace_back(origin.x - width / 2, origin.y + (scale * height) / 2);
4243
mux_polygon.emplace_back(origin.x + width / 2, origin.y + height / 2);
4344
mux_polygon.emplace_back(origin.x + width / 2, origin.y - height / 2);
4445
break;
4546
case RIGHT:
46-
//Clock-wise from bottom left
47+
// Clock-wise from bottom left
4748
mux_polygon.emplace_back(origin.x - width / 2, origin.y - height / 2);
4849
mux_polygon.emplace_back(origin.x - width / 2, origin.y + height / 2);
4950
mux_polygon.emplace_back(origin.x + width / 2, origin.y + (scale * height) / 2);
@@ -57,7 +58,7 @@ ezgl::rectangle draw_mux(ezgl::point2d origin, e_side orientation, float height,
5758

5859
ezgl::point2d min((float)mux_polygon[0].x, (float)mux_polygon[0].y);
5960
ezgl::point2d max((float)mux_polygon[0].x, (float)mux_polygon[0].y);
60-
for (const auto& point : mux_polygon) {
61+
for (const ezgl::point2d& point : mux_polygon) {
6162
min.x = std::min((float)min.x, (float)point.x);
6263
min.y = std::min((float)min.y, (float)point.y);
6364
max.x = std::max((float)max.x, (float)point.x);

vpr/src/draw/draw_mux.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,6 @@
77

88
#ifndef NO_GRAPHICS
99

10-
#include <cstdio>
11-
#include <cfloat>
12-
#include <cstring>
13-
#include <cmath>
14-
1510
#include "ezgl/point.hpp"
1611
#include "ezgl/graphics.hpp"
1712
#include "physical_types.h"

vpr/src/draw/draw_rr.cpp

Lines changed: 7 additions & 39 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,45 +247,22 @@ 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.
257254
if (to_type == e_rr_type::SOURCE || to_type == e_rr_type::SINK) {
258255
continue;
259256
}
260257

261-
ezgl::color color = DEFAULT_RR_NODE_COLOR;
262-
e_edge_type edge_type;
263258
bool draw_edge = true;
264259
bool inode_inter_cluster = is_inter_cluster_node(rr_graph, inode);
265260
bool to_node_inter_cluster = is_inter_cluster_node(rr_graph, to_node);
266261

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()) {
262+
if (EDGE_TYPE_MAP.find({from_type, to_type}) == EDGE_TYPE_MAP.end()) {
289263
continue; // Unsupported edge type
290264
}
291-
edge_type = edge_type_map.at({from_type, to_type});
265+
e_edge_type edge_type = EDGE_TYPE_MAP.at({from_type, to_type});
292266

293267
// Determine whether to draw the edge based on user options
294268

@@ -309,17 +283,11 @@ void draw_rr_edges(RRNodeId inode, ezgl::renderer* g) {
309283
draw_edge = draw_state->draw_connection_box_edges;
310284
}
311285

312-
// Select edge colors
313-
const std::map<e_edge_type, ezgl::color> edge_color_map = {
314-
{e_edge_type::PIN_TO_OPIN, ezgl::LIGHT_PINK},
315-
{e_edge_type::PIN_TO_IPIN, ezgl::MEDIUM_PURPLE},
316-
{e_edge_type::OPIN_TO_CHAN, ezgl::PINK},
317-
{e_edge_type::CHAN_TO_IPIN, ezgl::PURPLE},
318-
{e_edge_type::CHAN_TO_CHAN, blk_DARKGREEN}};
286+
ezgl::color color = EDGE_COLOR_MAP.at(edge_type);
319287

320-
color = edge_color_map.at(edge_type);
321-
322-
if (!edge_configurable) color = blk_DARKGREY;
288+
if (!edge_configurable) {
289+
color = blk_DARKGREY;
290+
}
323291

324292
if ((from_type == e_rr_type::CHANX || from_type == e_rr_type::CHANY)
325293
&& (to_type == e_rr_type::IPIN)

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+
/// Maps (from_type, to_type) pairs to an edge type used for drawing or classification.
31+
inline const std::map<std::pair<e_rr_type, e_rr_type>, e_edge_type> EDGE_TYPE_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
/**

vpr/src/draw/draw_types.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "ezgl/rectangle.hpp"
3232
#include "ezgl/color.hpp"
3333
#include "ezgl/application.hpp"
34+
#include "draw_color.h"
3435

3536
/// @brief Whether to draw routed nets or flylines (direct lines between sources and sinks).
3637
enum e_draw_nets {
@@ -124,6 +125,14 @@ enum class e_edge_type {
124125
NUM_EDGE_TYPES
125126
};
126127

128+
/// Maps edge types to the color with which they are visualized
129+
inline const vtr::array<e_edge_type, ezgl::color, (size_t)e_edge_type::NUM_EDGE_TYPES> EDGE_COLOR_MAP{
130+
ezgl::LIGHT_PINK,
131+
ezgl::MEDIUM_PURPLE,
132+
ezgl::PINK,
133+
ezgl::PURPLE,
134+
blk_DARKGREEN};
135+
127136
/**
128137
* @brief Structure used to hold data passed into the toggle checkbox callback function.
129138
*/

vpr/src/route/rr_graph_generation/build_scatter_gathers.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -210,12 +210,11 @@ std::vector<t_bottleneck_link> alloc_and_load_scatter_gather_connections(const s
210210
scatter_loc.y = gather_loc.y + sg_link.y_offset;
211211
scatter_loc.layer_num = gather_loc.layer_num + sg_link.z_offset;
212212

213-
const std::vector<t_segment_inf>& segment_inf = (sg_link.x_offset != 0) ? segment_inf_x :
214-
(sg_link.y_offset != 0) ? segment_inf_y : segment_inf_z;
215-
216-
const e_rr_type chan_type = (sg_link.x_offset != 0) ? e_rr_type::CHANX :
217-
(sg_link.y_offset != 0) ? e_rr_type::CHANY : e_rr_type::CHANZ;
213+
const std::vector<t_segment_inf>& segment_inf = (sg_link.x_offset != 0) ? segment_inf_x : (sg_link.y_offset != 0) ? segment_inf_y
214+
: segment_inf_z;
218215

216+
const e_rr_type chan_type = (sg_link.x_offset != 0) ? e_rr_type::CHANX : (sg_link.y_offset != 0) ? e_rr_type::CHANY
217+
: e_rr_type::CHANZ;
219218

220219
auto seg_it = std::ranges::find_if(segment_inf,
221220
[&](const t_segment_inf& seg) noexcept {
@@ -225,7 +224,6 @@ std::vector<t_bottleneck_link> alloc_and_load_scatter_gather_connections(const s
225224
VTR_ASSERT(seg_it != segment_inf.end());
226225
const t_segment_inf& wire_segment = *seg_it;
227226

228-
229227
index_to_correct_sg_channels(sg_pattern.gather_pattern, gather_loc, chan_details_x, chan_details_y, gather_channels);
230228
index_to_correct_sg_channels(sg_pattern.scatter_pattern, scatter_loc, chan_details_x, chan_details_y, scatter_channels);
231229

0 commit comments

Comments
 (0)