Skip to content

Commit ad4e287

Browse files
Use range-based loops and constant reference arguments in some NoC files.
1 parent 0e29f62 commit ad4e287

File tree

6 files changed

+37
-36
lines changed

6 files changed

+37
-36
lines changed

vpr/src/noc/noc_storage.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,9 @@ NocLinkId NocStorage::get_parallel_link(NocLinkId current_link) const {
223223
NocLinkId parallel_link = INVALID_LINK_ID;
224224

225225
// go through the links of the sink router and the link that has the current source router as the sink router of the link is the parallel link we are looking for
226-
for (auto link = sink_router_links->begin(); link != sink_router_links->end(); link++) {
227-
if (link_storage[*link].get_sink_router() == curr_source_router) {
228-
parallel_link = *link;
226+
for (auto sink_router_link : *sink_router_links) {
227+
if (link_storage[sink_router_link].get_sink_router() == curr_source_router) {
228+
parallel_link = sink_router_link;
229229
break;
230230
}
231231
}
@@ -264,17 +264,17 @@ void NocStorage::echo_noc(char* file_name) const {
264264
fprintf(fp, "\n");
265265

266266
// go through each router and print its information
267-
for (auto router = router_storage.begin(); router != router_storage.end(); router++) {
268-
fprintf(fp, "Router %d:\n", router->get_router_user_id());
267+
for (const auto& router : router_storage) {
268+
fprintf(fp, "Router %d:\n", router.get_router_user_id());
269269
// if the router tile is larger than a single grid, the position represents the bottom left corner of the tile
270-
fprintf(fp, "Equivalent Physical Tile Grid Position -> (%d,%d)\n", router->get_router_grid_position_x(), router->get_router_grid_position_y());
270+
fprintf(fp, "Equivalent Physical Tile Grid Position -> (%d,%d)\n", router.get_router_grid_position_x(), router.get_router_grid_position_y());
271271
fprintf(fp, "Router Connections ->");
272272

273-
auto& router_connections = this->get_noc_router_connections(this->convert_router_id(router->get_router_user_id()));
273+
auto& router_connections = this->get_noc_router_connections(this->convert_router_id(router.get_router_user_id()));
274274

275275
// go through the outgoing links of the current router and print the connecting router
276-
for (auto link_id = router_connections.begin(); link_id != router_connections.end(); link_id++) {
277-
const NocRouterId connecting_router_id = get_single_noc_link(*link_id).get_sink_router();
276+
for (auto router_connection : router_connections) {
277+
const NocRouterId connecting_router_id = get_single_noc_link(router_connection).get_sink_router();
278278

279279
fprintf(fp, " %d", get_single_noc_router(connecting_router_id).get_router_user_id());
280280
}

vpr/src/noc/noc_traffic_flows.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ const std::vector<NocTrafficFlowId>& NocTrafficFlows::get_all_traffic_flow_id(vo
5454

5555
// setters for the traffic flows
5656

57-
void NocTrafficFlows::create_noc_traffic_flow(std::string source_router_module_name, std::string sink_router_module_name, ClusterBlockId source_router_cluster_id, ClusterBlockId sink_router_cluster_id, double traffic_flow_bandwidth, double traffic_flow_latency, int traffic_flow_priority) {
57+
void NocTrafficFlows::create_noc_traffic_flow(const std::string& source_router_module_name, const std::string& sink_router_module_name, ClusterBlockId source_router_cluster_id, ClusterBlockId sink_router_cluster_id, double traffic_flow_bandwidth, double traffic_flow_latency, int traffic_flow_priority) {
5858
VTR_ASSERT_MSG(!built_traffic_flows, "NoC traffic flows have already been added, cannot modify further.");
5959

6060
// create and add the new traffic flow to the vector
@@ -106,7 +106,7 @@ void NocTrafficFlows::clear_traffic_flows(void) {
106106
return;
107107
}
108108

109-
bool NocTrafficFlows::check_if_cluster_block_has_traffic_flows(ClusterBlockId block_id) {
109+
bool NocTrafficFlows::check_if_cluster_block_has_traffic_flows(ClusterBlockId block_id) const {
110110
auto traffic_flows = get_traffic_flows_associated_to_router_block(block_id);
111111

112112
// indicate whether a vector of traffic flows were found that are associated to the current cluster block
@@ -149,15 +149,15 @@ void NocTrafficFlows::echo_noc_traffic_flows(char* file_name) {
149149
int traffic_flow_id = 0;
150150

151151
// go through each traffic flow and print its information
152-
for (auto traffic_flow = noc_traffic_flows.begin(); traffic_flow != noc_traffic_flows.end(); traffic_flow++) {
152+
for (const auto& traffic_flow : noc_traffic_flows) {
153153
// print the current traffic flows data
154154
fprintf(fp, "Traffic flow ID: %d\n", traffic_flow_id);
155-
fprintf(fp, "Traffic flow source router block name: %s\n", traffic_flow->source_router_module_name.c_str());
156-
fprintf(fp, "Traffic flow source router block cluster ID: %lu\n", (size_t)traffic_flow->source_router_cluster_id);
157-
fprintf(fp, "Traffic flow sink router block name: %s\n", traffic_flow->sink_router_module_name.c_str());
158-
fprintf(fp, "Traffic flow sink router block cluster ID: %lu\n", (size_t)traffic_flow->sink_router_cluster_id);
159-
fprintf(fp, "Traffic flow bandwidth: %f bps\n", traffic_flow->traffic_flow_bandwidth);
160-
fprintf(fp, "Traffic flow latency: %f seconds\n", traffic_flow->max_traffic_flow_latency);
155+
fprintf(fp, "Traffic flow source router block name: %s\n", traffic_flow.source_router_module_name.c_str());
156+
fprintf(fp, "Traffic flow source router block cluster ID: %lu\n", (size_t)traffic_flow.source_router_cluster_id);
157+
fprintf(fp, "Traffic flow sink router block name: %s\n", traffic_flow.sink_router_module_name.c_str());
158+
fprintf(fp, "Traffic flow sink router block cluster ID: %lu\n", (size_t)traffic_flow.sink_router_cluster_id);
159+
fprintf(fp, "Traffic flow bandwidth: %f bps\n", traffic_flow.traffic_flow_bandwidth);
160+
fprintf(fp, "Traffic flow latency: %f seconds\n", traffic_flow.max_traffic_flow_latency);
161161

162162
// separate the next link information
163163
fprintf(fp, "\n");
@@ -174,16 +174,16 @@ void NocTrafficFlows::echo_noc_traffic_flows(char* file_name) {
174174

175175
// go through each router block cluster and print its associated traffic flows
176176
// we only print out the traffic flow ids
177-
for (auto it = traffic_flows_associated_to_router_blocks.begin(); it != traffic_flows_associated_to_router_blocks.end(); it++) {
177+
for (const auto& router_traffic_flows : traffic_flows_associated_to_router_blocks) {
178178
// print the current router cluster id
179-
fprintf(fp, "Cluster ID %lu: ", (size_t)it->first);
179+
fprintf(fp, "Cluster ID %lu: ", (size_t)router_traffic_flows.first);
180180

181181
// get the vector of associated traffic flows
182-
auto assoc_traffic_flows = &(it->second);
182+
auto assoc_traffic_flows = &(router_traffic_flows.second);
183183

184184
// now go through the associated traffic flows of the current router and print their ids
185-
for (auto traffic_flow = assoc_traffic_flows->begin(); traffic_flow != assoc_traffic_flows->end(); traffic_flow++) {
186-
fprintf(fp, "%lu ", (size_t)*traffic_flow);
185+
for (auto assoc_traffic_flow : *assoc_traffic_flows) {
186+
fprintf(fp, "%lu ", (size_t)assoc_traffic_flow);
187187
}
188188

189189
// separate to the next cluster associated traffic flows information

vpr/src/noc/noc_traffic_flows.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <iostream>
3232
#include <unordered_map>
3333
#include <unordered_set>
34+
#include <utility>
3435
#include <vector>
3536
#include "clustered_netlist_fwd.h"
3637
#include "noc_data_types.h"
@@ -65,8 +66,8 @@ struct t_noc_traffic_flow {
6566

6667
/** Constructor initializes all variables*/
6768
t_noc_traffic_flow(std::string source_router_name, std::string sink_router_name, ClusterBlockId source_router_id, ClusterBlockId sink_router_id, double flow_bandwidth, double max_flow_latency, int flow_priority)
68-
: source_router_module_name(source_router_name)
69-
, sink_router_module_name(sink_router_name)
69+
: source_router_module_name(std::move(source_router_name))
70+
, sink_router_module_name(std::move(sink_router_name))
7071
, source_router_cluster_id(source_router_id)
7172
, sink_router_cluster_id(sink_router_id)
7273
, traffic_flow_bandwidth(flow_bandwidth)
@@ -252,7 +253,7 @@ class NocTrafficFlows {
252253
* at the sink router.
253254
* @param traffic_flow_priority The importance of a given traffic flow.
254255
*/
255-
void create_noc_traffic_flow(std::string source_router_module_name, std::string sink_router_module_name, ClusterBlockId source_router_cluster_id, ClusterBlockId sink_router_cluster_id, double traffic_flow_bandwidth, double traffic_flow_latency, int traffic_flow_priority);
256+
void create_noc_traffic_flow(const std::string& source_router_module_name, const std::string& sink_router_module_name, ClusterBlockId source_router_cluster_id, ClusterBlockId sink_router_cluster_id, double traffic_flow_bandwidth, double traffic_flow_latency, int traffic_flow_priority);
256257

257258
/**
258259
* @brief Copies the passed in router_cluster_id_in_netlist vector to the
@@ -302,7 +303,7 @@ class NocTrafficFlows {
302303
* @return true The block has traffic flows that it is a part of
303304
* @return false The block has no traffic flows it is a prt of
304305
*/
305-
bool check_if_cluster_block_has_traffic_flows(ClusterBlockId block_id);
306+
bool check_if_cluster_block_has_traffic_flows(ClusterBlockId block_id) const;
306307

307308
/**
308309
* @brief Writes out the NocTrafficFlows class information to a file.

vpr/src/noc/xy_routing.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,9 @@ bool XYRouting::move_to_next_router(NocRouterId& curr_router_id, int curr_router
106106
const std::vector<NocLinkId>& router_connections = noc_model.get_noc_router_connections(curr_router_id);
107107

108108
// go through each outgoing link and determine whether the link leads towards the intended route direction
109-
for (auto connecting_link = router_connections.begin(); connecting_link != router_connections.end(); connecting_link++) {
109+
for (auto connecting_link : router_connections) {
110110
// get the current outgoing link which is being processed
111-
const NocLink& curr_outgoing_link = noc_model.get_single_noc_link(*connecting_link);
111+
const NocLink& curr_outgoing_link = noc_model.get_single_noc_link(connecting_link);
112112

113113
// get the next router that we will visit if we travel across the current link
114114
next_router_id = curr_outgoing_link.get_sink_router();
@@ -154,7 +154,7 @@ bool XYRouting::move_to_next_router(NocRouterId& curr_router_id, int curr_router
154154
// If the next router was already visited, then this link is not valid, so indicate this and move onto processing the next link.
155155
if (found_next_router && !visited_next_router) {
156156
// if we are here then the link is legal to traverse, so add it to the found route and traverse the link by moving to the router connected by this link
157-
flow_route.push_back(*connecting_link);
157+
flow_route.push_back(connecting_link);
158158
curr_router_id = next_router_id;
159159

160160
// we found a suitable router to visit next, so add it to the set of visited routers

vpr/src/noc/xy_routing.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ class XYRouting : public NocRouting {
140140
* that is currently being visited on the FPGA
141141
* @return RouteDirection The direction to travel next
142142
*/
143-
RouteDirection get_direction_to_travel(int sink_router_x_position, int sink_router_y_position, int curr_router_x_position, int curr_router_y_position);
143+
static RouteDirection get_direction_to_travel(int sink_router_x_position, int sink_router_y_position, int curr_router_x_position, int curr_router_y_position);
144144

145145
/**
146146
* @brief Given the direction to travel next, this function determines
@@ -166,7 +166,7 @@ class XYRouting : public NocRouting {
166166
* @return true A suitable link was found that we can traverse next
167167
* @return false No suitable link was found that could be traversed
168168
*/
169-
bool move_to_next_router(NocRouterId& curr_router_id, int curr_router_x_position, int curr_router_y_position, RouteDirection next_step_direction, std::vector<NocLinkId>& flow_route, std::unordered_set<NocRouterId>& visited_routers, const NocStorage& noc_model);
169+
static bool move_to_next_router(NocRouterId& curr_router_id, int curr_router_x_position, int curr_router_y_position, RouteDirection next_step_direction, std::vector<NocLinkId>& flow_route, std::unordered_set<NocRouterId>& visited_routers, const NocStorage& noc_model);
170170
};
171171

172172
#endif

vpr/test/test_noc_place_utils.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ TEST_CASE("test_initial_noc_placement", "[noc_place_utils]") {
179179
}
180180

181181
// now call the test function
182-
initial_noc_placement();
182+
initial_noc_routing();
183183

184184
// now verify the function by comparing the link bandwidths in the noc model (should have been updated by the test function) to the golden set
185185
int number_of_links = golden_link_bandwidths.size();
@@ -357,7 +357,7 @@ TEST_CASE("test_initial_comp_cost_functions", "[noc_place_utils]") {
357357

358358
// assume this works
359359
// this is needed to set up the global noc packet router and also global datastructures
360-
initial_noc_placement();
360+
initial_noc_routing();
361361

362362
SECTION("test_comp_noc_aggregate_bandwidth_cost") {
363363
//initialize all the cost calculator datastructures
@@ -613,7 +613,7 @@ TEST_CASE("test_find_affected_noc_routers_and_update_noc_costs, test_commit_noc_
613613

614614
// assume this works
615615
// this is needed to set up the global noc packet router and also global datastructures
616-
initial_noc_placement();
616+
initial_noc_routing();
617617

618618
// datastructure below will store the bandwidth usages of all the links
619619
// and will be updated throughout this test.
@@ -1344,7 +1344,7 @@ TEST_CASE("test_revert_noc_traffic_flow_routes", "[noc_place_utils]") {
13441344

13451345
// assume this works
13461346
// this is needed to set up the global noc packet router and also global datastructures
1347-
initial_noc_placement();
1347+
initial_noc_routing();
13481348

13491349
// datastructure below will store the bandwidth usages of all the links
13501350
// and will be updated throughout this test.

0 commit comments

Comments
 (0)