summaryrefslogtreecommitdiff
path: root/src/shader_recompiler/frontend/maxwell
diff options
context:
space:
mode:
Diffstat (limited to 'src/shader_recompiler/frontend/maxwell')
-rw-r--r--src/shader_recompiler/frontend/maxwell/control_flow.cpp13
-rw-r--r--src/shader_recompiler/frontend/maxwell/structured_control_flow.cpp8
-rw-r--r--src/shader_recompiler/frontend/maxwell/translate_program.cpp20
3 files changed, 23 insertions, 18 deletions
diff --git a/src/shader_recompiler/frontend/maxwell/control_flow.cpp b/src/shader_recompiler/frontend/maxwell/control_flow.cpp
index e7abea82f..1a954a509 100644
--- a/src/shader_recompiler/frontend/maxwell/control_flow.cpp
+++ b/src/shader_recompiler/frontend/maxwell/control_flow.cpp
@@ -5,7 +5,6 @@
5#include <algorithm> 5#include <algorithm>
6#include <array> 6#include <array>
7#include <optional> 7#include <optional>
8#include <ranges>
9#include <string> 8#include <string>
10#include <utility> 9#include <utility>
11 10
@@ -151,18 +150,18 @@ std::pair<Location, Stack> Stack::Pop(Token token) const {
151} 150}
152 151
153std::optional<Location> Stack::Peek(Token token) const { 152std::optional<Location> Stack::Peek(Token token) const {
154 const auto reverse_entries{entries | std::views::reverse}; 153 const auto it{std::find_if(entries.rbegin(), entries.rend(),
155 const auto it{std::ranges::find(reverse_entries, token, &StackEntry::token)}; 154 [token](const auto& entry) { return entry.token == token; })};
156 if (it == reverse_entries.end()) { 155 if (it == entries.rend()) {
157 return std::nullopt; 156 return std::nullopt;
158 } 157 }
159 return it->target; 158 return it->target;
160} 159}
161 160
162Stack Stack::Remove(Token token) const { 161Stack Stack::Remove(Token token) const {
163 const auto reverse_entries{entries | std::views::reverse}; 162 const auto it{std::find_if(entries.rbegin(), entries.rend(),
164 const auto it{std::ranges::find(reverse_entries, token, &StackEntry::token)}; 163 [token](const auto& entry) { return entry.token == token; })};
165 const auto pos{std::distance(reverse_entries.begin(), it)}; 164 const auto pos{std::distance(entries.rbegin(), it)};
166 Stack result; 165 Stack result;
167 result.entries.insert(result.entries.end(), entries.begin(), entries.end() - pos - 1); 166 result.entries.insert(result.entries.end(), entries.begin(), entries.end() - pos - 1);
168 return result; 167 return result;
diff --git a/src/shader_recompiler/frontend/maxwell/structured_control_flow.cpp b/src/shader_recompiler/frontend/maxwell/structured_control_flow.cpp
index 221454b99..8b3e0a15c 100644
--- a/src/shader_recompiler/frontend/maxwell/structured_control_flow.cpp
+++ b/src/shader_recompiler/frontend/maxwell/structured_control_flow.cpp
@@ -4,7 +4,6 @@
4 4
5#include <algorithm> 5#include <algorithm>
6#include <memory> 6#include <memory>
7#include <ranges>
8#include <string> 7#include <string>
9#include <unordered_map> 8#include <unordered_map>
10#include <utility> 9#include <utility>
@@ -167,7 +166,7 @@ std::string DumpExpr(const Statement* stmt) {
167 } 166 }
168} 167}
169 168
170std::string DumpTree(const Tree& tree, u32 indentation = 0) { 169[[maybe_unused]] std::string DumpTree(const Tree& tree, u32 indentation = 0) {
171 std::string ret; 170 std::string ret;
172 std::string indent(indentation, ' '); 171 std::string indent(indentation, ' ');
173 for (auto stmt = tree.begin(); stmt != tree.end(); ++stmt) { 172 for (auto stmt = tree.begin(); stmt != tree.end(); ++stmt) {
@@ -315,8 +314,9 @@ class GotoPass {
315public: 314public:
316 explicit GotoPass(Flow::CFG& cfg, ObjectPool<Statement>& stmt_pool) : pool{stmt_pool} { 315 explicit GotoPass(Flow::CFG& cfg, ObjectPool<Statement>& stmt_pool) : pool{stmt_pool} {
317 std::vector gotos{BuildTree(cfg)}; 316 std::vector gotos{BuildTree(cfg)};
318 for (const Node& goto_stmt : gotos | std::views::reverse) { 317 const auto end{gotos.rend()};
319 RemoveGoto(goto_stmt); 318 for (auto goto_stmt = gotos.rbegin(); goto_stmt != end; ++goto_stmt) {
319 RemoveGoto(*goto_stmt);
320 } 320 }
321 } 321 }
322 322
diff --git a/src/shader_recompiler/frontend/maxwell/translate_program.cpp b/src/shader_recompiler/frontend/maxwell/translate_program.cpp
index 83c77967d..c067d459c 100644
--- a/src/shader_recompiler/frontend/maxwell/translate_program.cpp
+++ b/src/shader_recompiler/frontend/maxwell/translate_program.cpp
@@ -4,7 +4,6 @@
4 4
5#include <algorithm> 5#include <algorithm>
6#include <memory> 6#include <memory>
7#include <ranges>
8#include <vector> 7#include <vector>
9 8
10#include "common/settings.h" 9#include "common/settings.h"
@@ -20,12 +19,19 @@
20namespace Shader::Maxwell { 19namespace Shader::Maxwell {
21namespace { 20namespace {
22IR::BlockList GenerateBlocks(const IR::AbstractSyntaxList& syntax_list) { 21IR::BlockList GenerateBlocks(const IR::AbstractSyntaxList& syntax_list) {
23 auto syntax_blocks{syntax_list | std::views::filter([](const auto& node) { 22 size_t num_syntax_blocks{};
24 return node.type == IR::AbstractSyntaxNode::Type::Block; 23 for (const auto& node : syntax_list) {
25 })}; 24 if (node.type == IR::AbstractSyntaxNode::Type::Block) {
26 IR::BlockList blocks(std::ranges::distance(syntax_blocks)); 25 ++num_syntax_blocks;
27 std::ranges::transform(syntax_blocks, blocks.begin(), 26 }
28 [](const IR::AbstractSyntaxNode& node) { return node.data.block; }); 27 }
28 IR::BlockList blocks;
29 blocks.reserve(num_syntax_blocks);
30 for (const auto& node : syntax_list) {
31 if (node.type == IR::AbstractSyntaxNode::Type::Block) {
32 blocks.push_back(node.data.block);
33 }
34 }
29 return blocks; 35 return blocks;
30} 36}
31 37