From b450b90a3e9adc8b606f3aa5140ed5b8710163c1 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Mon, 8 Feb 2021 17:50:57 -0800 Subject: [PATCH] Adjust reference/move nitpicks in use-def/reduce code Use std::move() and avoid superfluous copies by assigning to const-reference in a few places. --- src/script_opt/Reduce.h | 2 +- src/script_opt/UseDefs.cc | 6 +++--- src/script_opt/UseDefs.h | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/script_opt/Reduce.h b/src/script_opt/Reduce.h index d844992aa4..9a2a1d3088 100644 --- a/src/script_opt/Reduce.h +++ b/src/script_opt/Reduce.h @@ -108,7 +108,7 @@ public: // Tells the reducer to replace the given statement during the // next reduction pass. void AddStmtToReplace(const Stmt* s_old, StmtPtr s_new) - { replaced_stmts[s_old] = s_new; } + { replaced_stmts[s_old] = std::move(s_new); } // Tells the reducer that it can reclaim the storage associated // with the omitted statements. diff --git a/src/script_opt/UseDefs.cc b/src/script_opt/UseDefs.cc index e646a23ac6..019ee437f4 100644 --- a/src/script_opt/UseDefs.cc +++ b/src/script_opt/UseDefs.cc @@ -194,7 +194,7 @@ UDs UseDefs::PropagateUDs(const Stmt* s, UDs succ_UDs, case STMT_LIST: { auto sl = s->AsStmtList(); - auto stmts = sl->Stmts(); + const auto& stmts = sl->Stmts(); for ( int i = stmts.length(); --i >= 0; ) { @@ -396,7 +396,7 @@ UDs UseDefs::PropagateUDs(const Stmt* s, UDs succ_UDs, successor2[body.get()] = succ_stmt; auto body_UDs = PropagateUDs(body.get(), succ_UDs, succ.get(), second_pass); - auto cond = w->Condition(); + const auto& cond = w->Condition(); auto w_UDs = UD_Union(ExprUDs(cond.get()), body_UDs); FoldInUDs(w_UDs, body_UDs); @@ -404,7 +404,7 @@ UDs UseDefs::PropagateUDs(const Stmt* s, UDs succ_UDs, { // Create a successor for the cond_stmt // that has the correct UDs associated with it. - auto c_as_s = w->ConditionAsStmt(); + const auto& c_as_s = w->ConditionAsStmt(); auto c_as_s_UDs = std::make_shared(w_UDs); CreateUDs(c_as_s.get(), c_as_s_UDs); diff --git a/src/script_opt/UseDefs.h b/src/script_opt/UseDefs.h index 71e6d32516..a00b42e0cf 100644 --- a/src/script_opt/UseDefs.h +++ b/src/script_opt/UseDefs.h @@ -95,7 +95,7 @@ private: UDs PropagateUDs(const StmtPtr& s, UDs succ_UDs, const StmtPtr& succ_stmt, bool second_pass) { - return PropagateUDs(s.get(), succ_UDs, succ_stmt.get(), + return PropagateUDs(s.get(), std::move(succ_UDs), succ_stmt.get(), second_pass); } UDs PropagateUDs(const Stmt* s, UDs succ_UDs,