diff options
| author | 2021-02-14 20:15:42 -0300 | |
|---|---|---|
| committer | 2021-07-22 21:51:22 -0400 | |
| commit | cbfb7d182a4e90e4e263696d1fca35e47d3eabb4 (patch) | |
| tree | a8d384aa0daefdfafd9b61330e06b1cf7ac40ea6 /src/shader_recompiler/frontend/ir/post_order.cpp | |
| parent | shader: Misc fixes (diff) | |
| download | yuzu-cbfb7d182a4e90e4e263696d1fca35e47d3eabb4.tar.gz yuzu-cbfb7d182a4e90e4e263696d1fca35e47d3eabb4.tar.xz yuzu-cbfb7d182a4e90e4e263696d1fca35e47d3eabb4.zip | |
shader: Support SSA loops on IR
Diffstat (limited to 'src/shader_recompiler/frontend/ir/post_order.cpp')
| -rw-r--r-- | src/shader_recompiler/frontend/ir/post_order.cpp | 48 |
1 files changed, 48 insertions, 0 deletions
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 | |||
| 11 | namespace Shader::IR { | ||
| 12 | |||
| 13 | BlockList 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 | ||