Skip to content

Commit 453f417

Browse files
committed
std::move optimizations for crit paths result and report string
1 parent 0f6c83c commit 453f417

File tree

6 files changed

+27
-22
lines changed

6 files changed

+27
-22
lines changed

vpr/src/base/vpr_context.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ class ServerContext : public Context {
575575
const server::TaskResolver& task_resolver() const { return task_resolver_; }
576576
server::TaskResolver& mutable_task_resolver() { return task_resolver_; }
577577

578-
void set_crit_paths(const std::vector<tatum::TimingPath>& crit_paths) { crit_paths_ = crit_paths; }
578+
void set_crit_paths(std::vector<tatum::TimingPath>&& crit_paths) { crit_paths_ = std::move(crit_paths); }
579579
const std::vector<tatum::TimingPath>& crit_paths() const { return crit_paths_; }
580580

581581
void clear_crit_path_elements() { crit_path_element_indexes_.clear(); }

vpr/src/server/pathhelper.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ static void collect_crit_path_metadata(std::stringstream& ss, const std::vector<
3232
/**
3333
* @brief Helper function to calculate critical path timing report with specified parameters.
3434
*/
35-
CritPathsResult calc_critical_path(const std::string& report_type, int crit_path_num, e_timing_report_detail details_level, bool is_flat_routing) {
35+
CritPathsResultPtr calc_critical_path(const std::string& report_type, int crit_path_num, e_timing_report_detail details_level, bool is_flat_routing) {
3636
// shortcuts
3737
const std::shared_ptr<SetupHoldTimingInfo>& timing_info = g_vpr_ctx.server().timing_info();
3838
const std::shared_ptr<RoutingDelayCalculator>& routing_delay_calc = g_vpr_ctx.server().routing_delay_calc();
@@ -50,20 +50,21 @@ CritPathsResult calc_critical_path(const std::string& report_type, int crit_path
5050

5151
tatum::TimingReporter timing_reporter(resolver, *timing_ctx.graph, *timing_ctx.constraints);
5252

53-
std::vector<tatum::TimingPath> paths;
53+
CritPathsResultPtr result = std::make_shared<CritPathsResult>();
54+
5455
std::stringstream ss;
5556
if (report_type == comm::KEY_SETUP_PATH_LIST) {
56-
timing_reporter.report_timing_setup(paths, ss, *timing_info->setup_analyzer(), analysis_opts.timing_report_npaths);
57+
timing_reporter.report_timing_setup(result->paths, ss, *timing_info->setup_analyzer(), analysis_opts.timing_report_npaths);
5758
} else if (report_type == comm::KEY_HOLD_PATH_LIST) {
58-
timing_reporter.report_timing_hold(paths, ss, *timing_info->hold_analyzer(), analysis_opts.timing_report_npaths);
59+
timing_reporter.report_timing_hold(result->paths, ss, *timing_info->hold_analyzer(), analysis_opts.timing_report_npaths);
5960
}
6061

61-
if (!paths.empty()) {
62-
collect_crit_path_metadata(ss, paths);
63-
return CritPathsResult{paths, ss.str()};
64-
} else {
65-
return CritPathsResult{std::vector<tatum::TimingPath>(), ""};
62+
if (!result->paths.empty()) {
63+
collect_crit_path_metadata(ss, result->paths);
64+
result->report = ss.str();
6665
}
66+
67+
return result;
6768
}
6869

6970
} // namespace server

vpr/src/server/pathhelper.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include <vector>
77
#include <string>
8+
#include <memory>
89

910
#include "tatum/report/TimingPath.hpp"
1011
#include "vpr_types.h"
@@ -21,11 +22,12 @@ struct CritPathsResult {
2122
std::vector<tatum::TimingPath> paths;
2223
std::string report;
2324
};
25+
using CritPathsResultPtr = std::shared_ptr<CritPathsResult>;
2426

2527
/**
2628
* @brief Helper function to calculate critical path timing report with specified parameters.
2729
*/
28-
CritPathsResult calc_critical_path(const std::string& type, int crit_path_num, e_timing_report_detail details_level, bool is_flat_routing);
30+
CritPathsResultPtr calc_critical_path(const std::string& type, int crit_path_num, e_timing_report_detail details_level, bool is_flat_routing);
2931

3032
} // namespace server
3133

vpr/src/server/task.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,13 @@ void Task::fail(const std::string& error) {
4040
bake_response();
4141
}
4242

43-
void Task::success(const std::string& result) {
44-
m_result = result;
43+
void Task::success() {
44+
m_is_finished = true;
45+
bake_response();
46+
}
47+
48+
void Task::success(std::string&& result) {
49+
m_result = std::move(result);
4550
m_is_finished = true;
4651
bake_response();
4752
}

vpr/src/server/task.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ class Task {
4242
bool is_response_fully_sent() const { return m_is_response_fully_sent; }
4343

4444
void fail(const std::string& error);
45-
void success(const std::string& result = "");
45+
void success();
46+
void success(std::string&& result);
4647

4748
std::string info(bool skip_duration = false) const;
4849

vpr/src/server/taskresolver.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,10 @@ void TaskResolver::process_get_path_list_task(ezgl::application*, const TaskPtr&
9999
// calculate critical path depending on options and store result in server context
100100
std::optional<e_timing_report_detail> details_level_opt = try_get_details_level_enum(details_level_str);
101101
if (details_level_opt) {
102-
CritPathsResult crit_paths_result = calc_critical_path(path_type, n_critical_path_num, details_level_opt.value(), is_flat);
103-
104-
// setup context
105-
server_ctx.set_crit_paths(crit_paths_result.paths);
106-
107-
if (crit_paths_result.is_valid()) {
108-
std::string msg{crit_paths_result.report};
109-
task->success(msg);
102+
CritPathsResultPtr crit_paths_result = calc_critical_path(path_type, n_critical_path_num, details_level_opt.value(), is_flat);
103+
if (crit_paths_result->is_valid()) {
104+
server_ctx.set_crit_paths(std::move(crit_paths_result->paths));
105+
task->success(std::move(crit_paths_result->report));
110106
} else {
111107
std::string msg{"Critical paths report is empty"};
112108
VTR_LOG_ERROR(msg.c_str());

0 commit comments

Comments
 (0)