summaryrefslogtreecommitdiff
path: root/src/shader_recompiler/frontend/ir
diff options
context:
space:
mode:
authorGravatar ReinUsesLisp2021-02-14 20:15:42 -0300
committerGravatar ameerj2021-07-22 21:51:22 -0400
commitcbfb7d182a4e90e4e263696d1fca35e47d3eabb4 (patch)
treea8d384aa0daefdfafd9b61330e06b1cf7ac40ea6 /src/shader_recompiler/frontend/ir
parentshader: Misc fixes (diff)
downloadyuzu-cbfb7d182a4e90e4e263696d1fca35e47d3eabb4.tar.gz
yuzu-cbfb7d182a4e90e4e263696d1fca35e47d3eabb4.tar.xz
yuzu-cbfb7d182a4e90e4e263696d1fca35e47d3eabb4.zip
shader: Support SSA loops on IR
Diffstat (limited to 'src/shader_recompiler/frontend/ir')
-rw-r--r--src/shader_recompiler/frontend/ir/function.h1
-rw-r--r--src/shader_recompiler/frontend/ir/post_order.cpp48
-rw-r--r--src/shader_recompiler/frontend/ir/post_order.h13
3 files changed, 62 insertions, 0 deletions
diff --git a/src/shader_recompiler/frontend/ir/function.h b/src/shader_recompiler/frontend/ir/function.h
index fd7d56419..d1f061146 100644
--- a/src/shader_recompiler/frontend/ir/function.h
+++ b/src/shader_recompiler/frontend/ir/function.h
@@ -12,6 +12,7 @@ namespace Shader::IR {
12 12
13struct Function { 13struct Function {
14 BlockList blocks; 14 BlockList blocks;
15 BlockList post_order_blocks;
15}; 16};
16 17
17} // namespace Shader::IR 18} // namespace Shader::IR
diff --git a/src/shader_recompiler/frontend/ir/post_order.cpp b/src/shader_recompiler/frontend/ir/post_order.cpp
new file mode 100644
index 000000000..a48b8dec5
--- /dev/null
+++ b/src/shader_recompiler/frontend/ir/post_order.cpp
@@ -0,0 +1,48 @@
1// Copyright 2021 yuzu Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#include <boost/container/flat_set.hpp>
6#include <boost/container/small_vector.hpp>
7
8#include "shader_recompiler/frontend/ir/basic_block.h"
9#include "shader_recompiler/frontend/ir/post_order.h"
10
11namespace Shader::IR {
12
13BlockList PostOrder(const BlockList& blocks) {
14 boost::container::small_vector<Block*, 16> block_stack;
15 boost::container::flat_set<Block*> visited;
16
17 BlockList post_order_blocks;
18 post_order_blocks.reserve(blocks.size());
19
20 Block* const first_block{blocks.front()};
21 visited.insert(first_block);
22 block_stack.push_back(first_block);
23
24 const auto visit_branch = [&](Block* block, Block* branch) {
25 if (!branch) {
26 return false;
27 }
28 if (!visited.insert(branch).second) {
29 return false;
30 }
31 // Calling push_back twice is faster than insert on msvc
32 block_stack.push_back(block);
33 block_stack.push_back(branch);
34 return true;
35 };
36 while (!block_stack.empty()) {
37 Block* const block{block_stack.back()};
38 block_stack.pop_back();
39
40 if (!visit_branch(block, block->TrueBranch()) &&
41 !visit_branch(block, block->FalseBranch())) {
42 post_order_blocks.push_back(block);
43 }
44 }
45 return post_order_blocks;
46}
47
48} // namespace Shader::IR
diff --git a/src/shader_recompiler/frontend/ir/post_order.h b/src/shader_recompiler/frontend/ir/post_order.h
new file mode 100644
index 000000000..30137ff57
--- /dev/null
+++ b/src/shader_recompiler/frontend/ir/post_order.h
@@ -0,0 +1,13 @@
1// Copyright 2021 yuzu Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include "shader_recompiler/frontend/ir/basic_block.h"
8
9namespace Shader::IR {
10
11BlockList PostOrder(const BlockList& blocks);
12
13} // namespace Shader::IR