Skip to content

Commit 170baaa

Browse files
[VTR][LOG] Improved Unused Arg Warning Suppression
Previously, VTR's logging used `sizeof` static casted to void in order to suppress the unused argument warning when we want logs to be a NOP. The `sizeof` operator may have some strange affects, but since the code is NOP anyways thats not a huge deal. The reason for this change is that intellisence that use clangd flag this as a potential issue causing warnings. This also exposes a potential issue where a LOG message is using a function that may have memory effects, so it may not be cleaned up by the compiler properly. The unused variables should be handled explicitly. Also moved static variables from the header file of vtr_log to the implementation. No functional change, but just prevents these variables from being present and accessible in every file that uses vtr_log (which is alot).
1 parent 31f60a5 commit 170baaa

File tree

6 files changed

+26
-25
lines changed

6 files changed

+26
-25
lines changed

libs/libvtrutil/src/vtr_log.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
#include <string>
2-
#include <fstream>
31
#include <cstdarg>
2+
#include <fstream>
3+
#include <string>
4+
#include <unordered_set>
45

56
#include "vtr_util.h"
67
#include "vtr_log.h"
@@ -19,6 +20,9 @@ void set_log_file(const char* filename) {
1920

2021
} // namespace vtr
2122

23+
static std::unordered_set<std::string> warnings_to_suppress;
24+
static std::string noisy_warn_log_file;
25+
2226
void add_warnings_to_suppress(std::string function_name) {
2327
warnings_to_suppress.insert(function_name);
2428
}

libs/libvtrutil/src/vtr_log.h

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#ifndef VTR_LOG_H
22
#define VTR_LOG_H
33
#include <tuple>
4-
#include <unordered_set>
54
#include <string>
65

76
/**
@@ -99,21 +98,15 @@
9998
} while (false)
10099

101100
/*
102-
* No-op version of logging macro which avoids unused parameter warnings.
101+
* No-op version of logging macro. Drops all arguments so they have no
102+
* performance effects.
103103
*
104-
* Note that to avoid unused parameter warnings we call sizeof() and cast
105-
* the result to void. sizeof is evaluated at compile time so there is no
106-
* run-time overhead.
107-
*
108-
* Also note the use of std::make_tuple to ensure all arguments in VA_ARGS
109-
* are used.
104+
* Note: To prevent unused variable warnings, users of this logging feature
105+
* should handle the case when debugging is off. This should be done
106+
* explicitly to prevent hidden function calls that do not get optimized.
110107
*/
111108
#define VTR_LOGVF_NOP(expr, file, line, ...) \
112109
do { \
113-
static_cast<void>(sizeof(expr)); \
114-
static_cast<void>(sizeof(file)); \
115-
static_cast<void>(sizeof(line)); \
116-
static_cast<void>(sizeof(std::make_tuple(__VA_ARGS__))); \
117110
} while (false)
118111

119112
// Debug logging macros
@@ -142,9 +135,6 @@ void set_log_file(const char* filename);
142135

143136
} // namespace vtr
144137

145-
static std::unordered_set<std::string> warnings_to_suppress;
146-
static std::string noisy_warn_log_file;
147-
148138
/**
149139
* @brief The following data structure and functions allow to suppress noisy warnings and direct them into an external file, if specified.
150140
*/

vpr/src/route/connection_router.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,6 @@ t_heap* ConnectionRouter<Heap>::timing_driven_route_connection_from_heap(RRNodeI
193193
VTR_LOGV_DEBUG(router_debug_, " Initial heap empty (no source)\n");
194194
}
195195

196-
const auto& device_ctx = g_vpr_ctx.device();
197196
auto& route_ctx = g_vpr_ctx.mutable_routing();
198197

199198
t_heap* cheapest = nullptr;
@@ -217,6 +216,8 @@ t_heap* ConnectionRouter<Heap>::timing_driven_route_connection_from_heap(RRNodeI
217216
if (rcv_path_manager.is_enabled()) {
218217
rcv_path_manager.insert_backwards_path_into_traceback(cheapest->path_data, cheapest->cost, cheapest->backward_path_cost, route_ctx);
219218
}
219+
const auto& device_ctx = g_vpr_ctx.device();
220+
static_cast<void>(device_ctx); // Ignore unused variable when logging is disabled.
220221
VTR_LOGV_DEBUG(router_debug_, " Found target %8d (%s)\n", inode, describe_rr_node(device_ctx.rr_graph, device_ctx.grid, device_ctx.rr_indexed_data, inode, is_flat_).c_str());
221222
break;
222223
}
@@ -525,7 +526,6 @@ void ConnectionRouter<Heap>::timing_driven_add_to_heap(const t_conn_cost_params&
525526
RRNodeId to_node,
526527
const RREdgeId from_edge,
527528
RRNodeId target_node) {
528-
const auto& device_ctx = g_vpr_ctx.device();
529529
t_heap next;
530530

531531
// Initalize RCV data struct if needed, otherwise it's set to nullptr
@@ -557,6 +557,8 @@ void ConnectionRouter<Heap>::timing_driven_add_to_heap(const t_conn_cost_params&
557557
float new_back_cost = next.backward_path_cost;
558558

559559
if (new_total_cost < best_total_cost && ((rcv_path_manager.is_enabled()) || (new_back_cost < best_back_cost))) {
560+
const auto& device_ctx = g_vpr_ctx.device();
561+
static_cast<void>(device_ctx); // Ignore unused variable when logging is disabled.
560562
VTR_LOGV_DEBUG(router_debug_, " Expanding to node %d (%s)\n", to_node,
561563
describe_rr_node(device_ctx.rr_graph,
562564
device_ctx.grid,
@@ -596,6 +598,8 @@ void ConnectionRouter<Heap>::timing_driven_add_to_heap(const t_conn_cost_params&
596598
rr_graph_);
597599

598600
} else {
601+
const auto& device_ctx = g_vpr_ctx.device();
602+
static_cast<void>(device_ctx); // Ignore unused variable when logging is disabled.
599603
VTR_LOGV_DEBUG(router_debug_, " Didn't expand to %d (%s)\n", to_node, describe_rr_node(device_ctx.rr_graph, device_ctx.grid, device_ctx.rr_indexed_data, to_node, is_flat_).c_str());
600604
VTR_LOGV_DEBUG(router_debug_, " Prev Total Cost %g Prev back Cost %g \n", best_total_cost, best_back_cost);
601605
VTR_LOGV_DEBUG(router_debug_, " New Total Cost %g New back Cost %g \n", new_total_cost, new_back_cost);
@@ -783,12 +787,13 @@ void ConnectionRouter<Heap>::evaluate_timing_driven_node_costs(t_heap* to,
783787

784788
total_cost = compute_node_cost_using_rcv(cost_params, to_node, target_node, to->path_data->backward_delay, to->path_data->backward_cong, to->R_upstream);
785789
} else {
786-
const auto& device_ctx = g_vpr_ctx.device();
787790
//Update total cost
788791
float expected_cost = router_lookahead_.get_expected_cost(to_node,
789792
target_node,
790793
cost_params,
791794
to->R_upstream);
795+
const auto& device_ctx = g_vpr_ctx.device();
796+
static_cast<void>(device_ctx); // Ignore unused variable when logging is disabled.
792797
VTR_LOGV_DEBUG(router_debug_ && !std::isfinite(expected_cost),
793798
" Lookahead from %s (%s) to %s (%s) is non-finite, expected_cost = %f, to->R_upstream = %f\n",
794799
rr_node_arch_name(to_node, is_flat_).c_str(),
@@ -871,7 +876,6 @@ void ConnectionRouter<Heap>::add_route_tree_node_to_heap(
871876
RRNodeId target_node,
872877
const t_conn_cost_params& cost_params,
873878
const t_bb& net_bb) {
874-
const auto& device_ctx = g_vpr_ctx.device();
875879
const RRNodeId inode = rt_node.inode;
876880
float backward_path_cost = cost_params.criticality * rt_node.Tdel;
877881
float R_upstream = rt_node.R_upstream;
@@ -894,6 +898,8 @@ void ConnectionRouter<Heap>::add_route_tree_node_to_heap(
894898
target_node,
895899
cost_params,
896900
R_upstream);
901+
const auto& device_ctx = g_vpr_ctx.device();
902+
static_cast<void>(device_ctx); // Ignore unused variable when logging is disabled.
897903
VTR_LOGV_DEBUG(router_debug_, " Adding node %8d to heap from init route tree with cost %g (%s)\n",
898904
inode,
899905
tot_cost,

vpr/src/route/route_net.tpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,14 +414,15 @@ inline NetResultFlags route_sink(ConnectionRouter& router,
414414
const std::vector<std::unordered_map<RRNodeId, int>>& choking_spots,
415415
bool is_flat,
416416
const t_bb& net_bb) {
417-
const auto& device_ctx = g_vpr_ctx.device();
418417
auto& route_ctx = g_vpr_ctx.mutable_routing();
419418

420419
NetResultFlags flags;
421420

422421
profiling::sink_criticality_start();
423422

424423
RRNodeId sink_node = route_ctx.net_rr_terminals[net_id][target_pin];
424+
const auto& device_ctx = g_vpr_ctx.device();
425+
static_cast<void>(device_ctx);
425426
VTR_LOGV_DEBUG(f_router_debug, "Net %zu Target %d (%s)\n", size_t(net_id), itarget, describe_rr_node(device_ctx.rr_graph, device_ctx.grid, device_ctx.rr_indexed_data, sink_node, is_flat).c_str());
426427

427428
router.clear_modified_rr_node_info();

vpr/src/route/router_lookahead_extended_map.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,10 +243,9 @@ std::pair<float, float> ExtendedMapLookahead::get_expected_delay_and_cong(RRNode
243243
float expected_cost = expected_delay_cost + expected_cong_cost;
244244

245245
VTR_LOGV_DEBUG(f_router_debug, "Requested lookahead from node %d to %d\n", size_t(from_node), size_t(to_node));
246-
const std::string& segment_name = rr_graph.rr_segments(RRSegmentId(from_seg_index)).name;
247246
VTR_LOGV_DEBUG(f_router_debug, "Lookahead returned %s (%d) with distance (%d, %d)\n",
248-
segment_name.c_str(), from_seg_index,
249-
dx, dy);
247+
rr_graph.rr_segments(RRSegmentId(from_seg_index)).name.c_str(),
248+
from_seg_index, dx, dy);
250249
VTR_LOGV_DEBUG(f_router_debug, "Lookahead delay: %g\n", expected_delay_cost);
251250
VTR_LOGV_DEBUG(f_router_debug, "Lookahead congestion: %g\n", expected_cong_cost);
252251
VTR_LOGV_DEBUG(f_router_debug, "Criticality: %g\n", params.criticality);

vpr/src/route/router_lookahead_map_utils.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,7 @@ t_src_opin_delays compute_router_src_opin_lookahead(bool is_flat) {
441441
}
442442
}
443443
if (reachable_wire_found) {
444+
static_cast<void>(is_flat); // Ignore unused variable when logging is disabled.
444445
VTR_LOGV_DEBUG(f_router_debug, "Found no reachable wires from %s (%s) at (%d,%d,%d)\n",
445446
rr_node_typename[rr_type],
446447
rr_node_arch_name(node_id, is_flat).c_str(),

0 commit comments

Comments
 (0)