Skip to content

Commit edbb9f4

Browse files
some cleanups
1 parent 037f1b5 commit edbb9f4

File tree

4 files changed

+39
-47
lines changed

4 files changed

+39
-47
lines changed

libs/libarchfpga/src/physical_types_util.cpp

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -236,10 +236,9 @@ static int get_logical_block_physical_pin_num_offset(t_physical_tile_type_ptr ph
236236
const t_sub_tile* curr_sub_tile,
237237
t_logical_block_type_ptr curr_logical_block,
238238
const int curr_relative_cap) {
239-
int offset;
240-
offset = get_sub_tile_inst_physical_pin_num_offset(physical_tile, curr_sub_tile, curr_relative_cap);
239+
int offset = get_sub_tile_inst_physical_pin_num_offset(physical_tile, curr_sub_tile, curr_relative_cap);
241240

242-
for (auto eq_site : curr_sub_tile->equivalent_sites) {
241+
for (t_logical_block_type_ptr eq_site : curr_sub_tile->equivalent_sites) {
243242
if (eq_site == curr_logical_block)
244243
break;
245244
offset += (int)eq_site->pin_logical_num_to_pb_pin_mapping.size();
@@ -255,13 +254,11 @@ static int get_pin_logical_num_from_pin_physical_num(t_physical_tile_type_ptr ph
255254
VTR_ASSERT(sub_tile_cap != -1);
256255
auto logical_block = get_logical_block_from_pin_physical_num(physical_tile, physical_num);
257256

258-
int pin_logical_num;
259-
260257
int offset = get_logical_block_physical_pin_num_offset(physical_tile,
261258
sub_tile,
262259
logical_block,
263260
sub_tile_cap);
264-
pin_logical_num = physical_num - offset;
261+
int pin_logical_num = physical_num - offset;
265262

266263
return pin_logical_num;
267264
}
@@ -273,7 +270,6 @@ static std::vector<int> get_pb_pin_src_pins(t_physical_tile_type_ptr physical_ty
273270
const t_pb_graph_pin* pin) {
274271
std::vector<int> driving_pins;
275272
const auto& edges = pin->input_edges;
276-
t_pb_graph_pin** connected_pins_ptr;
277273
int num_edges = pin->num_input_edges;
278274
int num_pins = 0;
279275

@@ -285,7 +281,7 @@ static std::vector<int> get_pb_pin_src_pins(t_physical_tile_type_ptr physical_ty
285281

286282
for (int edge_idx = 0; edge_idx < num_edges; edge_idx++) {
287283
const t_pb_graph_edge* pb_graph_edge = edges[edge_idx];
288-
connected_pins_ptr = pb_graph_edge->input_pins;
284+
t_pb_graph_pin** connected_pins_ptr = pb_graph_edge->input_pins;
289285
num_pins = pb_graph_edge->num_input_pins;
290286

291287
for (int pin_idx = 0; pin_idx < num_pins; pin_idx++) {
@@ -315,7 +311,6 @@ static std::vector<int> get_pb_pin_sink_pins(t_physical_tile_type_ptr physical_t
315311
const t_pb_graph_pin* pin) {
316312
std::vector<int> sink_pins;
317313
const auto& edges = pin->output_edges;
318-
t_pb_graph_pin** connected_pins_ptr;
319314
int num_edges = pin->num_output_edges;
320315
int num_pins = 0;
321316

@@ -327,7 +322,7 @@ static std::vector<int> get_pb_pin_sink_pins(t_physical_tile_type_ptr physical_t
327322

328323
for (int edge_idx = 0; edge_idx < num_edges; edge_idx++) {
329324
const t_pb_graph_edge* pb_graph_edge = edges[edge_idx];
330-
connected_pins_ptr = pb_graph_edge->output_pins;
325+
t_pb_graph_pin** connected_pins_ptr = pb_graph_edge->output_pins;
331326
num_pins = pb_graph_edge->num_output_pins;
332327

333328
for (int pin_idx = 0; pin_idx < num_pins; pin_idx++) {
@@ -392,12 +387,12 @@ static int get_num_reachable_sinks(t_physical_tile_type_ptr physical_tile,
392387
const auto& connected_sinks = pb_pin->connected_sinks_ptc;
393388

394389
// If ref_sink_num is not reachable by pin_physical_num return 0
395-
if (connected_sinks.find(ref_sink_num) == connected_sinks.end()) {
390+
if (!connected_sinks.contains(ref_sink_num)) {
396391
return 0;
397392
}
398393

399394
for (auto sink_num : sink_grp) {
400-
if (connected_sinks.find(sink_num) != connected_sinks.end()) {
395+
if (connected_sinks.contains(sink_num)) {
401396
num_reachable_sinks++;
402397
}
403398
}
@@ -431,7 +426,7 @@ int get_logical_block_physical_sub_tile_index(t_physical_tile_type_ptr physical_
431426
int sub_tile_index = ARCH_FPGA_UNDEFINED_VAL;
432427
for (const auto& sub_tile : physical_tile->sub_tiles) {
433428
auto eq_sites = sub_tile.equivalent_sites;
434-
auto it = std::find(eq_sites.begin(), eq_sites.end(), logical_block);
429+
auto it = std::ranges::find(eq_sites, logical_block);
435430
if (it != eq_sites.end()) {
436431
sub_tile_index = sub_tile.index;
437432
}
@@ -467,7 +462,7 @@ int get_logical_block_physical_sub_tile_index(t_physical_tile_type_ptr physical_
467462
int sub_tile_index = ARCH_FPGA_UNDEFINED_VAL;
468463
for (const auto& sub_tile : physical_tile->sub_tiles) {
469464
auto eq_sites = sub_tile.equivalent_sites;
470-
auto it = std::find(eq_sites.begin(), eq_sites.end(), logical_block);
465+
auto it = std::ranges::find(eq_sites, logical_block);
471466
if (it != eq_sites.end()
472467
&& (sub_tile.capacity.is_in_range(sub_tile_capacity))) {
473468
sub_tile_index = sub_tile.index;
@@ -497,13 +492,13 @@ t_logical_block_type_ptr pick_logical_type(t_physical_tile_type_ptr physical_til
497492

498493
bool is_tile_compatible(t_physical_tile_type_ptr physical_tile, t_logical_block_type_ptr logical_block) {
499494
const auto& equivalent_tiles = logical_block->equivalent_tiles;
500-
return std::find(equivalent_tiles.begin(), equivalent_tiles.end(), physical_tile) != equivalent_tiles.end();
495+
return std::ranges::find(equivalent_tiles, physical_tile) != equivalent_tiles.end();
501496
}
502497

503498
bool is_sub_tile_compatible(t_physical_tile_type_ptr physical_tile, t_logical_block_type_ptr logical_block, int sub_tile_loc) {
504499
bool capacity_compatible = false;
505-
for (auto& sub_tile : physical_tile->sub_tiles) {
506-
auto result = std::find(sub_tile.equivalent_sites.begin(), sub_tile.equivalent_sites.end(), logical_block);
500+
for (const t_sub_tile& sub_tile : physical_tile->sub_tiles) {
501+
auto result = std::ranges::find(sub_tile.equivalent_sites, logical_block);
507502

508503
if (sub_tile.capacity.is_in_range(sub_tile_loc) && result != sub_tile.equivalent_sites.end()) {
509504
capacity_compatible = true;
@@ -691,14 +686,14 @@ std::vector<std::string> block_type_class_index_to_pin_names(t_physical_tile_typ
691686
return lhs.pin_physical_num < rhs.pin_physical_num;
692687
};
693688

694-
//Ensure all the pins are in order
695-
std::sort(pin_info.begin(), pin_info.end(), cmp);
689+
// Ensure all the pins are in order
690+
std::ranges::sort(pin_info, cmp);
696691

697-
//Determine ranges for each capacity instance and port pair
692+
// Determine ranges for each capacity instance and port pair
698693
std::map<std::tuple<int, int, int, int, int>, std::array<int, 4>> pin_ranges;
699694
for (const auto& pin_inf : pin_info) {
700695
auto key = std::make_tuple(pin_inf.sub_tile_index, pin_inf.capacity_instance, pin_inf.logical_block_index, pin_inf.pb_type_idx, pin_inf.port_index);
701-
if (!pin_ranges.count(key)) {
696+
if (!pin_ranges.contains(key)) {
702697
pin_ranges[key][0] = pin_inf.pin_index_in_port;
703698
pin_ranges[key][1] = pin_inf.pin_index_in_port;
704699
pin_ranges[key][2] = pin_inf.pin_physical_num;
@@ -1304,7 +1299,7 @@ float get_pin_primitive_comb_delay(t_physical_tile_type_ptr physical_type,
13041299
pin_physical_num);
13051300
VTR_ASSERT(pb_pin->is_primitive_pin());
13061301

1307-
auto it = std::max_element(pb_pin->pin_timing_del_max.begin(), pb_pin->pin_timing_del_max.end());
1302+
auto it = std::ranges::max_element(pb_pin->pin_timing_del_max);
13081303

13091304
if (it == pb_pin->pin_timing_del_max.end()) {
13101305
return 0.;
@@ -1323,9 +1318,9 @@ bool classes_in_same_block(t_physical_tile_type_ptr physical_tile,
13231318
}
13241319

13251320
// Two functions are considered to be in the same group if share at least two level of blocks
1326-
const int NUM_SIMILAR_PB_NODE_THRESHOLD = 2;
1327-
auto first_class_pin_list = get_pin_list_from_class_physical_num(physical_tile, first_class_ptc_num);
1328-
auto second_class_pin_list = get_pin_list_from_class_physical_num(physical_tile, second_class_ptc_num);
1321+
constexpr int NUM_SIMILAR_PB_NODE_THRESHOLD = 2;
1322+
std::vector<int> first_class_pin_list = get_pin_list_from_class_physical_num(physical_tile, first_class_ptc_num);
1323+
std::vector<int> second_class_pin_list = get_pin_list_from_class_physical_num(physical_tile, second_class_ptc_num);
13291324

13301325
auto first_pb_graph_pin = get_pb_pin_from_pin_physical_num(physical_tile, first_class_pin_list[0]);
13311326
auto second_pb_graph_pin = get_pb_pin_from_pin_physical_num(physical_tile, second_class_pin_list[0]);
@@ -1340,7 +1335,7 @@ bool classes_in_same_block(t_physical_tile_type_ptr physical_tile,
13401335
int num_shared_pb_graph_node = 0;
13411336
curr_pb_graph_node = second_pb_graph_pin->parent_node;
13421337
while (curr_pb_graph_node != nullptr) {
1343-
auto find_res = std::find(first_pb_graph_node_chain.begin(), first_pb_graph_node_chain.end(), curr_pb_graph_node);
1338+
auto find_res = std::ranges::find(first_pb_graph_node_chain, curr_pb_graph_node);
13441339
if (find_res != first_pb_graph_node_chain.end()) {
13451340
num_shared_pb_graph_node++;
13461341
if (num_shared_pb_graph_node >= NUM_SIMILAR_PB_NODE_THRESHOLD)

libs/librrgraph/src/base/rr_graph_utils.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ void rr_set_sink_locs(const RRGraphView& rr_graph, RRGraphBuilder& rr_graph_buil
180180

181181
// See if we have encountered this tile type/ptc combo before, and used saved offset if so
182182
vtr::Point<int> new_loc(-1, -1);
183-
if ((physical_type_offsets.find(tile_type) != physical_type_offsets.end()) && (physical_type_offsets[tile_type].find(node_ptc) != physical_type_offsets[tile_type].end())) {
183+
if (physical_type_offsets.contains(tile_type) && physical_type_offsets[tile_type].contains(node_ptc)) {
184184
new_loc = tile_bb.bottom_left() + physical_type_offsets[tile_type].at(node_ptc);
185185
} else { /* We have not seen this tile type/ptc combo before */
186186
// The IPINs of the current SINK node
@@ -197,7 +197,7 @@ void rr_set_sink_locs(const RRGraphView& rr_graph, RRGraphBuilder& rr_graph_buil
197197
std::vector<float> y_coords;
198198

199199
// Add coordinates of each "cluster-edge" pin to vectors
200-
for (const auto& pin : sink_ipins) {
200+
for (const RRNodeId pin : sink_ipins) {
201201
int pin_x = rr_graph.node_xlow(pin);
202202
int pin_y = rr_graph.node_ylow(pin);
203203

@@ -212,7 +212,7 @@ void rr_set_sink_locs(const RRGraphView& rr_graph, RRGraphBuilder& rr_graph_buil
212212
(int)round(std::accumulate(y_coords.begin(), y_coords.end(), 0.f) / (double)y_coords.size())};
213213

214214
// Save offset for this tile/ptc combo
215-
if (physical_type_offsets.find(tile_type) == physical_type_offsets.end())
215+
if (!physical_type_offsets.contains(tile_type))
216216
physical_type_offsets[tile_type] = {};
217217

218218
physical_type_offsets[tile_type].insert({node_ptc, new_loc - tile_bb.bottom_left()});

vpr/src/route/rr_graph_generation/build_switchblocks.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ static void compute_wire_connections(const t_physical_tile_loc& sb_loc,
390390
}
391391

392392
// Check that the permutation map has an entry for this side combination
393-
if (sb.permutation_map.count(side_conn) == 0) {
393+
if (!sb.permutation_map.contains(side_conn)) {
394394
// The specified switchblock does not have any permutation funcs for `from_side` to `to_side` connection
395395
return;
396396
}

vpr/src/util/vpr_utils.cpp

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <regex>
33
#include <algorithm>
44
#include <sstream>
5+
#include <ranges>
56

67
#include "pack_types.h"
78
#include "vpr_types.h"
@@ -415,7 +416,7 @@ int get_sub_tile_index(ClusterBlockId blk,
415416

416417
for (const auto& sub_tile : type->sub_tiles) {
417418
if (sub_tile.capacity.is_in_range(sub_tile_coordinate)) {
418-
auto result = std::find(sub_tile.equivalent_sites.begin(), sub_tile.equivalent_sites.end(), logical_block);
419+
auto result = std::ranges::find(sub_tile.equivalent_sites, logical_block);
419420
if (result == sub_tile.equivalent_sites.end()) {
420421
VPR_THROW(VPR_ERROR_PLACE, "The Block Id %d has been placed in an incompatible sub tile location.\n", blk);
421422
}
@@ -596,7 +597,7 @@ t_logical_block_type_ptr infer_logic_block_type(const DeviceGrid& grid) {
596597
rhs_num_instances += grid.num_instances(type, -1);
597598
return lhs_num_instances > rhs_num_instances;
598599
};
599-
std::stable_sort(logic_block_candidates.begin(), logic_block_candidates.end(), by_desc_grid_count);
600+
std::ranges::stable_sort(logic_block_candidates, by_desc_grid_count);
600601

601602
if (!logic_block_candidates.empty()) {
602603
return logic_block_candidates.front();
@@ -1061,7 +1062,7 @@ vtr::vector<ClusterBlockId, t_pb**> alloc_and_load_pin_id_to_pb_mapping() {
10611062
auto& cluster_ctx = g_vpr_ctx.clustering();
10621063

10631064
vtr::vector<ClusterBlockId, t_pb**> pin_id_to_pb_mapping(cluster_ctx.clb_nlist.blocks().size());
1064-
for (auto blk_id : cluster_ctx.clb_nlist.blocks()) {
1065+
for (ClusterBlockId blk_id : cluster_ctx.clb_nlist.blocks()) {
10651066
pin_id_to_pb_mapping[blk_id] = new t_pb*[cluster_ctx.clb_nlist.block_type(blk_id)->pb_graph_head->total_pb_pins];
10661067
for (int j = 0; j < cluster_ctx.clb_nlist.block_type(blk_id)->pb_graph_head->total_pb_pins; j++) {
10671068
pin_id_to_pb_mapping[blk_id][j] = nullptr;
@@ -1248,7 +1249,7 @@ int num_ext_inputs_atom_block(AtomBlockId blk_id) {
12481249
//Look through the output nets for any duplicates of the input nets
12491250
for (auto pin_id : atom_ctx.netlist().block_output_pins(blk_id)) {
12501251
auto net_id = atom_ctx.netlist().pin_net(pin_id);
1251-
if (input_nets.count(net_id)) {
1252+
if (input_nets.contains(net_id)) {
12521253
--ext_inps;
12531254
}
12541255
}
@@ -1273,20 +1274,17 @@ void free_pb(t_pb* pb, AtomPBBimap& atom_pb_bimap) {
12731274
return;
12741275
}
12751276

1276-
const t_pb_type* pb_type;
1277-
int i, j, mode;
1278-
1279-
pb_type = pb->pb_graph_node->pb_type;
1277+
const t_pb_type* pb_type = pb->pb_graph_node->pb_type;
12801278

12811279
if (pb->name) {
12821280
free(pb->name);
12831281
pb->name = nullptr;
12841282
}
12851283

12861284
if (pb_type->blif_model == nullptr) {
1287-
mode = pb->mode;
1288-
for (i = 0; i < pb_type->modes[mode].num_pb_type_children && pb->child_pbs != nullptr; i++) {
1289-
for (j = 0; j < pb_type->modes[mode].pb_type_children[i].num_pb && pb->child_pbs[i] != nullptr; j++) {
1285+
int mode = pb->mode;
1286+
for (int i = 0; i < pb_type->modes[mode].num_pb_type_children && pb->child_pbs != nullptr; i++) {
1287+
for (int j = 0; j < pb_type->modes[mode].pb_type_children[i].num_pb && pb->child_pbs[i] != nullptr; j++) {
12901288
if (pb->child_pbs[i][j].name != nullptr || pb->child_pbs[i][j].child_pbs != nullptr) {
12911289
free_pb(&pb->child_pbs[i][j], atom_pb_bimap);
12921290
}
@@ -1354,7 +1352,7 @@ std::tuple<int, int, std::string, std::string> parse_direct_pin_name(std::string
13541352

13551353
std::string source_string{src_string};
13561354
// replace '.' characters with space
1357-
std::replace(source_string.begin(), source_string.end(), '.', ' ');
1355+
std::ranges::replace(source_string, '.', ' ');
13581356

13591357
std::istringstream source_iss(source_string);
13601358
std::string pb_type_name, port_name;
@@ -1374,8 +1372,7 @@ std::tuple<int, int, std::string, std::string> parse_direct_pin_name(std::string
13741372
std::string source_string{src_string};
13751373

13761374
// Replace '.' and '[' characters with ' '
1377-
std::replace_if(
1378-
source_string.begin(), source_string.end(),
1375+
std::ranges::replace_if(source_string,
13791376
[](char c) { return c == '.' || c == '[' || c == ':' || c == ']'; },
13801377
' ');
13811378

@@ -1479,18 +1476,18 @@ void print_switch_usage() {
14791476
// Assumption: suppose for a L4 wire (bi-directional): ----+----+----+----, it can be driven from any point (0, 1, 2, 3).
14801477
// physically, the switch driving from point 1 & 3 should be the same. But we will assign then different switch
14811478
// index; or there is no way to differentiate them after abstracting a 2D wire into a 1D node
1482-
if (inward_switch_inf[to_node_index].count(switch_index) == 0)
1479+
if (!inward_switch_inf[to_node_index].contains(switch_index))
14831480
inward_switch_inf[to_node_index][switch_index] = 0;
14841481
//VTR_ASSERT(from_node.type != OPIN);
14851482
inward_switch_inf[to_node_index][switch_index]++;
14861483
}
14871484
}
14881485

14891486
for (const RRNodeId rr_id : device_ctx.rr_graph.nodes()) {
1490-
for (const auto [rr_switch_id, node_switch_fanin] : inward_switch_inf[rr_id]) {
1487+
for (const RRSwitchId rr_switch_id : inward_switch_inf[rr_id] | std::views::keys) {
14911488
float Tdel = rr_graph.rr_switch_inf(rr_switch_id).Tdel;
14921489
const auto [arch_switch_id, fanin] = convert_switch_index(rr_switch_id);
1493-
if (switch_fanin_count[arch_switch_id].count(fanin) == 0) {
1490+
if (!switch_fanin_count[arch_switch_id].contains(fanin)) {
14941491
switch_fanin_count[arch_switch_id][fanin] = 0;
14951492
}
14961493
switch_fanin_count[arch_switch_id][fanin]++;

0 commit comments

Comments
 (0)