From fcd0145eb5cbba9a603455c3ce35cfa44d814d98 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 22 Sep 2020 22:48:06 -0400 Subject: [PATCH 1/2] control_flow: Make use of std::move in InsertBranch() Avoids unnecessary atomic increments and decrements. --- src/video_core/shader/control_flow.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/video_core/shader/control_flow.cpp b/src/video_core/shader/control_flow.cpp index 336397cdb..5963cf214 100644 --- a/src/video_core/shader/control_flow.cpp +++ b/src/video_core/shader/control_flow.cpp @@ -580,8 +580,8 @@ bool TryQuery(CFGRebuildState& state) { } void InsertBranch(ASTManager& mm, const BlockBranchInfo& branch_info) { - const auto get_expr = ([&](const Condition& cond) -> Expr { - Expr result{}; + const auto get_expr = [](const Condition& cond) -> Expr { + Expr result; if (cond.cc != ConditionCode::T) { result = MakeExpr(cond.cc); } @@ -594,10 +594,10 @@ void InsertBranch(ASTManager& mm, const BlockBranchInfo& branch_info) { } Expr extra = MakeExpr(pred); if (negate) { - extra = MakeExpr(extra); + extra = MakeExpr(std::move(extra)); } if (result) { - return MakeExpr(extra, result); + return MakeExpr(std::move(extra), std::move(result)); } return extra; } @@ -605,9 +605,10 @@ void InsertBranch(ASTManager& mm, const BlockBranchInfo& branch_info) { return result; } return MakeExpr(true); - }); + }; + if (std::holds_alternative(*branch_info)) { - const auto branch = std::get_if(branch_info.get()); + const auto* branch = std::get_if(branch_info.get()); if (branch->address < 0) { if (branch->kill) { mm.InsertReturn(get_expr(branch->condition), true); @@ -619,7 +620,7 @@ void InsertBranch(ASTManager& mm, const BlockBranchInfo& branch_info) { mm.InsertGoto(get_expr(branch->condition), branch->address); return; } - const auto multi_branch = std::get_if(branch_info.get()); + const auto* multi_branch = std::get_if(branch_info.get()); for (const auto& branch_case : multi_branch->branches) { mm.InsertGoto(MakeExpr(multi_branch->gpr, branch_case.cmp_value), branch_case.address); From 0dc6967ff1030e466e8e2da399079a28181c3c09 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 22 Sep 2020 22:54:32 -0400 Subject: [PATCH 2/2] control_flow: emplace elements in place within TryQuery() Places data structures where they'll eventually be moved to to avoid needing to even move them in the first place. --- src/video_core/shader/control_flow.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/video_core/shader/control_flow.cpp b/src/video_core/shader/control_flow.cpp index 5963cf214..4c8971615 100644 --- a/src/video_core/shader/control_flow.cpp +++ b/src/video_core/shader/control_flow.cpp @@ -547,13 +547,13 @@ bool TryQuery(CFGRebuildState& state) { gather_labels(q2.ssy_stack, state.ssy_labels, block); gather_labels(q2.pbk_stack, state.pbk_labels, block); if (std::holds_alternative(*block.branch)) { - const auto branch = std::get_if(block.branch.get()); + auto* branch = std::get_if(block.branch.get()); if (!branch->condition.IsUnconditional()) { q2.address = block.end + 1; state.queries.push_back(q2); } - Query conditional_query{q2}; + auto& conditional_query = state.queries.emplace_back(q2); if (branch->is_sync) { if (branch->address == unassigned_branch) { branch->address = conditional_query.ssy_stack.top(); @@ -567,15 +567,15 @@ bool TryQuery(CFGRebuildState& state) { conditional_query.pbk_stack.pop(); } conditional_query.address = branch->address; - state.queries.push_back(std::move(conditional_query)); return true; } - const auto multi_branch = std::get_if(block.branch.get()); + + const auto* multi_branch = std::get_if(block.branch.get()); for (const auto& branch_case : multi_branch->branches) { - Query conditional_query{q2}; + auto& conditional_query = state.queries.emplace_back(q2); conditional_query.address = branch_case.address; - state.queries.push_back(std::move(conditional_query)); } + return true; }