Skip to content

Commit 244e3b9

Browse files
std::ranges + declaratio and assignment, const ref
1 parent d63860f commit 244e3b9

27 files changed

+90
-104
lines changed

vpr/src/place/annealer.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ static float analyze_setup_slack_cost(const PlacerSetupSlacks* setup_slacks,
7676
proposed_setup_slacks.push_back(setup_slacks->setup_slack(net_id, ipin));
7777
}
7878

79-
//Sort in ascending order, from the worse slack value to the best
80-
std::stable_sort(original_setup_slacks.begin(), original_setup_slacks.end());
81-
std::stable_sort(proposed_setup_slacks.begin(), proposed_setup_slacks.end());
79+
// Sort in ascending order, from the worse slack value to the best
80+
std::ranges::stable_sort(original_setup_slacks);
81+
std::ranges::stable_sort(proposed_setup_slacks);
8282

8383
//Check the first pair of slack values that are different
8484
//If found, return their difference

vpr/src/place/compressed_grid.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,11 @@ static t_compressed_block_grid create_compressed_block_grid(const std::vector<st
111111
}
112112

113113
//Uniquify x/y locations
114-
std::stable_sort(layer_x_locs.begin(), layer_x_locs.end());
115-
layer_x_locs.erase(unique(layer_x_locs.begin(), layer_x_locs.end()), layer_x_locs.end());
114+
std::ranges::stable_sort(layer_x_locs);
115+
layer_x_locs.erase(std::ranges::unique(layer_x_locs).begin(), layer_x_locs.end());
116116

117-
std::stable_sort(layer_y_locs.begin(), layer_y_locs.end());
118-
layer_y_locs.erase(unique(layer_y_locs.begin(), layer_y_locs.end()), layer_y_locs.end());
117+
std::ranges::stable_sort(layer_y_locs);
118+
layer_y_locs.erase(std::ranges::unique(layer_y_locs).begin(), layer_y_locs.end());
119119

120120
//The index of an x-position in x_locs corresponds to it's compressed
121121
//x-coordinate (similarly for y)
@@ -150,10 +150,10 @@ static t_compressed_block_grid create_compressed_block_grid(const std::vector<st
150150
//it efficient to find the non-empty blocks in the y dimension
151151
for (auto point : locations[layer_num]) {
152152
//Determine the compressed indices in the x & y dimensions
153-
auto x_itr = std::lower_bound(layer_compressed_x_locs.begin(), layer_compressed_x_locs.end(), point.x());
153+
auto x_itr = std::ranges::lower_bound(layer_compressed_x_locs, point.x());
154154
int cx = std::distance(layer_compressed_x_locs.begin(), x_itr);
155155

156-
auto y_itr = std::lower_bound(layer_compressed_y_locs.begin(), layer_compressed_y_locs.end(), point.y());
156+
auto y_itr = std::ranges::lower_bound(layer_compressed_y_locs, point.y());
157157
int cy = std::distance(layer_compressed_y_locs.begin(), y_itr);
158158

159159
VTR_ASSERT(cx >= 0 && cx < (int)layer_compressed_x_locs.size());
@@ -173,8 +173,7 @@ static t_compressed_block_grid create_compressed_block_grid(const std::vector<st
173173

174174
/*Print the contents of the compressed grids to an echo file*/
175175
void echo_compressed_grids(const char* filename, const std::vector<t_compressed_block_grid>& comp_grids) {
176-
FILE* fp;
177-
fp = vtr::fopen(filename, "w");
176+
FILE* fp = vtr::fopen(filename, "w");
178177

179178
auto& device_ctx = g_vpr_ctx.device();
180179
int num_layers = device_ctx.grid.get_num_layers();

vpr/src/place/compressed_grid.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ struct t_compressed_block_grid {
4545
int cy = UNDEFINED;
4646
int layer_num = grid_loc.layer_num;
4747

48-
auto itr_x = std::lower_bound(compressed_to_grid_x[layer_num].begin(), compressed_to_grid_x[layer_num].end(), grid_loc.x);
48+
auto itr_x = std::ranges::lower_bound(compressed_to_grid_x[layer_num], grid_loc.x);
4949
VTR_ASSERT(*itr_x == grid_loc.x);
5050
cx = std::distance(compressed_to_grid_x[layer_num].begin(), itr_x);
5151

52-
auto itr_y = std::lower_bound(compressed_to_grid_y[layer_num].begin(), compressed_to_grid_y[layer_num].end(), grid_loc.y);
52+
auto itr_y = std::ranges::lower_bound(compressed_to_grid_y[layer_num], grid_loc.y);
5353
VTR_ASSERT(*itr_y == grid_loc.y);
5454
cy = std::distance(compressed_to_grid_y[layer_num].begin(), itr_y);
5555

@@ -69,7 +69,7 @@ struct t_compressed_block_grid {
6969
inline t_physical_tile_loc grid_loc_to_compressed_loc_approx_round_up(t_physical_tile_loc grid_loc) const {
7070
auto find_compressed_index = [](const std::vector<int>& compressed, int value) -> int {
7171
// Get the first element that is not less than the value
72-
auto itr = std::lower_bound(compressed.begin(), compressed.end(), value);
72+
auto itr = std::ranges::lower_bound(compressed, value);
7373
if (itr == compressed.end()) {
7474
// If all the compressed locations are less than the grid location, return the last compressed location
7575
return compressed.size() - 1;
@@ -99,7 +99,7 @@ struct t_compressed_block_grid {
9999
inline t_physical_tile_loc grid_loc_to_compressed_loc_approx_round_down(t_physical_tile_loc grid_loc) const {
100100
auto find_compressed_index = [](const std::vector<int>& compressed, int value) -> int {
101101
// Get the first element that is strictly bigger than the value
102-
auto itr = std::upper_bound(compressed.begin(), compressed.end(), value);
102+
auto itr = std::ranges::upper_bound(compressed, value);
103103
if (itr == compressed.begin()) {
104104
// If all the compressed locations are bigger than the grid location, return the first compressed location
105105
return 0;
@@ -135,7 +135,7 @@ struct t_compressed_block_grid {
135135
}
136136

137137
// Find the first element not less than loc
138-
auto itr = std::lower_bound(compressed_grid_dim.begin(), compressed_grid_dim.end(), loc);
138+
auto itr = std::ranges::lower_bound(compressed_grid_dim, loc);
139139

140140
if (itr == compressed_grid_dim.begin()) {
141141
// If all the compressed locations are bigger that or equal to loc, return the first compressed location

vpr/src/place/delay_model/compute_delta_delays_utils.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ static vtr::NdMatrix<float, 4> compute_delta_delays(RouterDelayProfiler& route_p
215215

216216
if (type != device_ctx.EMPTY_PHYSICAL_TILE_TYPE) {
217217
// check if the tile type is among the allowed types
218-
if (!allowed_types.empty() && allowed_types.find(type->name) == allowed_types.end()) {
218+
if (!allowed_types.empty() && !allowed_types.contains(type->name)) {
219219
continue;
220220
}
221221
src_type = type;
@@ -250,7 +250,7 @@ static vtr::NdMatrix<float, 4> compute_delta_delays(RouterDelayProfiler& route_p
250250

251251
if (type != device_ctx.EMPTY_PHYSICAL_TILE_TYPE) {
252252
// check if the tile type is among the allowed types
253-
if (!allowed_types.empty() && allowed_types.find(type->name) == allowed_types.end()) {
253+
if (!allowed_types.empty() && !allowed_types.contains(type->name)) {
254254
continue;
255255
}
256256
src_type = type;
@@ -441,7 +441,7 @@ static void generic_compute_matrix_iterative_astar(RouterDelayProfiler& route_pr
441441
bool src_or_target_empty = (src_type == device_ctx.EMPTY_PHYSICAL_TILE_TYPE
442442
|| sink_type == device_ctx.EMPTY_PHYSICAL_TILE_TYPE);
443443

444-
bool is_allowed_type = allowed_types.empty() || allowed_types.find(src_type->name) != allowed_types.end();
444+
bool is_allowed_type = allowed_types.empty() || allowed_types.contains(src_type->name);
445445

446446
if (src_or_target_empty || !is_allowed_type) {
447447
if (matrix[delta_x][delta_y].empty()) {
@@ -503,7 +503,7 @@ static void generic_compute_matrix_dijkstra_expansion(RouterDelayProfiler& /*rou
503503
const auto& device_ctx = g_vpr_ctx.device();
504504

505505
t_physical_tile_type_ptr src_type = device_ctx.grid.get_physical_type({source_x, source_y, from_layer_num});
506-
bool is_allowed_type = allowed_types.empty() || allowed_types.find(src_type->name) != allowed_types.end();
506+
bool is_allowed_type = allowed_types.empty() || allowed_types.contains(src_type->name);
507507
if (src_type == device_ctx.EMPTY_PHYSICAL_TILE_TYPE || !is_allowed_type) {
508508
for (int sink_x = start_x; sink_x <= end_x; sink_x++) {
509509
for (int sink_y = start_y; sink_y <= end_y; sink_y++) {
@@ -703,13 +703,13 @@ static float delay_reduce(std::vector<float>& delays, e_reducer reducer) {
703703
float delay;
704704

705705
if (reducer == e_reducer::MIN) {
706-
auto itr = std::min_element(delays.begin(), delays.end());
706+
auto itr = std::ranges::min_element(delays);
707707
delay = *itr;
708708
} else if (reducer == e_reducer::MAX) {
709-
auto itr = std::max_element(delays.begin(), delays.end());
709+
auto itr = std::ranges::max_element(delays);
710710
delay = *itr;
711711
} else if (reducer == e_reducer::MEDIAN) {
712-
std::sort(delays.begin(), delays.end());
712+
std::ranges::sort(delays);
713713
delay = vtr::median_presorted<float>(delays.begin(), delays.end());
714714
} else if (reducer == e_reducer::ARITHMEAN) {
715715
delay = vtr::arithmean(delays.begin(), delays.end());
@@ -945,7 +945,7 @@ std::vector<int> get_best_classes(enum e_pin_type pintype, t_physical_tile_type_
945945
int pin = type->class_inf[i].pinlist[ipin];
946946
//If the pin isn't ignored, and has a non-zero Fc to some general
947947
//routing the class is suitable for delay profiling
948-
if (!type->is_ignored_pin[pin] && non_zero_fc_pins.count(pin)) {
948+
if (!type->is_ignored_pin[pin] && non_zero_fc_pins.contains(pin)) {
949949
any_pins_connect_to_general_routing = true;
950950
break;
951951
}
@@ -964,7 +964,7 @@ std::vector<int> get_best_classes(enum e_pin_type pintype, t_physical_tile_type_
964964
return type->class_inf[lhs].num_pins > type->class_inf[rhs].num_pins;
965965
};
966966

967-
std::stable_sort(best_classes.begin(), best_classes.end(), cmp_class);
967+
std::ranges::stable_sort(best_classes, cmp_class);
968968

969969
return best_classes;
970970
}

vpr/src/place/delay_model/override_delay_model.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,8 @@ void OverrideDelayModel::compute_override_delay_model_(RouterDelayProfiler& rout
7575
int to_pin_class = to_type->find_pin_class(to_port.port_name(), to_port.port_low_index() + iconn, e_pin_type::RECEIVER);
7676
VTR_ASSERT(to_pin_class != UNDEFINED);
7777

78-
bool found_sample_points;
7978
RRNodeId src_rr, sink_rr;
80-
found_sample_points = find_direct_connect_sample_locations(direct, from_type, from_pin, from_pin_class, to_type, to_pin, to_pin_class, src_rr, sink_rr);
79+
bool found_sample_points = find_direct_connect_sample_locations(direct, from_type, from_pin, from_pin_class, to_type, to_pin, to_pin_class, src_rr, sink_rr);
8180

8281
if (!found_sample_points) {
8382
++missing_instances;
@@ -86,7 +85,7 @@ void OverrideDelayModel::compute_override_delay_model_(RouterDelayProfiler& rout
8685

8786
//If some of the source/sink ports are logically equivalent we may have already
8887
//sampled the associated source/sink pair and don't need to do so again
89-
if (sampled_rr_pairs.count({src_rr, sink_rr})) continue;
88+
if (sampled_rr_pairs.contains({src_rr, sink_rr})) continue;
9089

9190
float direct_connect_delay = std::numeric_limits<float>::quiet_NaN();
9291
bool found_routing_path = route_profiler.calculate_delay(src_rr, sink_rr, router_opts2, &direct_connect_delay);

vpr/src/place/move_transactions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ e_block_move_result t_pl_blocks_to_be_moved::record_block_move(ClusterBlockId bl
4646
}
4747

4848
//Examines the currently proposed move and determine any empty locations
49-
std::set<t_pl_loc> t_pl_blocks_to_be_moved::determine_locations_emptied_by_move() {
49+
std::set<t_pl_loc> t_pl_blocks_to_be_moved::determine_locations_emptied_by_move() const {
5050
std::set<t_pl_loc> moved_from_set;
5151
std::set<t_pl_loc> moved_to_set;
5252

vpr/src/place/move_transactions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ struct t_pl_blocks_to_be_moved {
8383
t_pl_loc to,
8484
const BlkLocRegistry& blk_loc_registry);
8585

86-
std::set<t_pl_loc> determine_locations_emptied_by_move();
86+
std::set<t_pl_loc> determine_locations_emptied_by_move() const;
8787

8888
std::vector<t_pl_moved_block> moved_blocks;
8989
std::unordered_set<t_pl_loc> moved_from;

vpr/src/place/move_utils.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ static bool f_placer_breakpoint_reached = false;
2626
* @param to_layer_num The layer that the block is moving to
2727
* @param is_range_fixed Whether the search range is fixed (e.g., in case of placement constraints)
2828
* @param search_range The search range to adjust
29-
*
3029
*/
3130
static void adjust_search_range(t_logical_block_type_ptr block_type,
3231
const int compressed_column_num,
@@ -405,7 +404,7 @@ e_block_move_result identify_macro_self_swap_affected_macros(std::vector<int>& m
405404
int imacro_to = place_macros.get_imacro_from_iblk(blk_to);
406405

407406
if (imacro_to != -1) {
408-
auto itr = std::find(macros.begin(), macros.end(), imacro_to);
407+
auto itr = std::ranges::find(macros, imacro_to);
409408
if (itr == macros.end()) {
410409
macros.push_back(imacro_to);
411410
outcome = identify_macro_self_swap_affected_macros(macros, imacro_to, swap_offset, blk_loc_registry, place_macros, move_abortion_logger);
@@ -432,7 +431,7 @@ e_block_move_result record_macro_self_swaps(t_pl_blocks_to_be_moved& blocks_affe
432431
}
433432

434433
//Remove any duplicate macros
435-
affected_macros.resize(std::distance(affected_macros.begin(), std::unique(affected_macros.begin(), affected_macros.end())));
434+
affected_macros.resize(std::distance(affected_macros.begin(), std::ranges::unique(affected_macros).begin()));
436435

437436
std::vector<ClusterBlockId> displaced_blocks;
438437

@@ -448,14 +447,14 @@ e_block_move_result record_macro_self_swaps(t_pl_blocks_to_be_moved& blocks_affe
448447
auto is_non_macro_block = [&](ClusterBlockId blk) {
449448
int imacro_blk = place_macros.get_imacro_from_iblk(blk);
450449

451-
if (std::find(affected_macros.begin(), affected_macros.end(), imacro_blk) != affected_macros.end()) {
450+
if (std::ranges::find(affected_macros, imacro_blk) != affected_macros.end()) {
452451
return false;
453452
}
454453
return true;
455454
};
456455

457456
std::vector<ClusterBlockId> non_macro_displaced_blocks;
458-
std::copy_if(displaced_blocks.begin(), displaced_blocks.end(), std::back_inserter(non_macro_displaced_blocks), is_non_macro_block);
457+
std::ranges::copy_if(displaced_blocks, std::back_inserter(non_macro_displaced_blocks), is_non_macro_block);
459458

460459
//Based on the currently queued block moves, find the empty 'holes' left behind
461460
auto empty_locs = blocks_affected.determine_locations_emptied_by_move();
@@ -863,7 +862,6 @@ bool find_to_loc_centroid(t_logical_block_type_ptr blk_type,
863862
}
864863

865864
//Determine the valid compressed grid location ranges
866-
int delta_cx;
867865
t_bb search_range;
868866

869867
// If we are early in the anneal and the range limit still big enough --> search around the center location that the move proposed
@@ -878,7 +876,7 @@ bool find_to_loc_centroid(t_logical_block_type_ptr blk_type,
878876
compressed_loc_on_layer,
879877
std::min<float>(range_limiters.original_rlim, range_limiters.dm_rlim));
880878
}
881-
delta_cx = search_range.xmax - search_range.xmin;
879+
int delta_cx = search_range.xmax - search_range.xmin;
882880

883881
bool block_constrained = is_cluster_constrained(b_from);
884882

@@ -1141,7 +1139,6 @@ t_bb get_compressed_grid_bounded_search_range(const t_compressed_block_grid& com
11411139
const t_physical_tile_loc& from_compressed_loc,
11421140
const t_physical_tile_loc& target_compressed_loc,
11431141
float rlim) {
1144-
t_bb search_range;
11451142

11461143
int min_cx, max_cx, min_cy, max_cy;
11471144

@@ -1174,7 +1171,7 @@ t_bb get_compressed_grid_bounded_search_range(const t_compressed_block_grid& com
11741171
max_cy = std::min<int>(compressed_block_grid.get_num_rows(layer_num) - 1, cy_from + rlim_y_max_range);
11751172
}
11761173

1177-
search_range = t_bb(min_cx, max_cx, min_cy, max_cy, layer_num, layer_num);
1174+
t_bb search_range = t_bb(min_cx, max_cx, min_cy, max_cy, layer_num, layer_num);
11781175

11791176
return search_range;
11801177
}

vpr/src/place/net_cost_handler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ void NetCostHandler::alloc_and_load_for_fast_vertical_cost_update_() {
228228
});
229229
}
230230

231-
std::pair<double, double> NetCostHandler::comp_bb_cost(e_cost_methods method) {
231+
std::pair<double, double> NetCostHandler::comp_bb_cost(e_cost_methods method) const {
232232
return comp_bb_cost_functor_(method);
233233
}
234234

vpr/src/place/net_cost_handler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class NetCostHandler {
6868
*
6969
* @note The returned estimated wirelength is valid only when method == CHECK
7070
*/
71-
std::pair<double, double> comp_bb_cost(e_cost_methods method);
71+
std::pair<double, double> comp_bb_cost(e_cost_methods method) const;
7272

7373
/**
7474
* @brief Find all the nets and pins affected by this swap and update costs.

0 commit comments

Comments
 (0)