summaryrefslogtreecommitdiff
path: root/src/shader_recompiler/frontend/ir/basic_block.cpp
diff options
context:
space:
mode:
authorGravatar ReinUsesLisp2021-05-14 00:40:54 -0300
committerGravatar ameerj2021-07-22 21:51:31 -0400
commitd54d7de40e7295827b0e4e4026441b53d3fc9569 (patch)
tree29b5074f851292dace7aeb5da7716675544b3735 /src/shader_recompiler/frontend/ir/basic_block.cpp
parentglasm: Implement Storage atomics (diff)
downloadyuzu-d54d7de40e7295827b0e4e4026441b53d3fc9569.tar.gz
yuzu-d54d7de40e7295827b0e4e4026441b53d3fc9569.tar.xz
yuzu-d54d7de40e7295827b0e4e4026441b53d3fc9569.zip
glasm: Rework control flow introducing a syntax list
This commit regresses VertexA shaders, their transformation pass has to be adapted to the new control flow.
Diffstat (limited to 'src/shader_recompiler/frontend/ir/basic_block.cpp')
-rw-r--r--src/shader_recompiler/frontend/ir/basic_block.cpp56
1 files changed, 12 insertions, 44 deletions
diff --git a/src/shader_recompiler/frontend/ir/basic_block.cpp b/src/shader_recompiler/frontend/ir/basic_block.cpp
index f92fc2571..7c08b25ce 100644
--- a/src/shader_recompiler/frontend/ir/basic_block.cpp
+++ b/src/shader_recompiler/frontend/ir/basic_block.cpp
@@ -14,10 +14,7 @@
14 14
15namespace Shader::IR { 15namespace Shader::IR {
16 16
17Block::Block(ObjectPool<Inst>& inst_pool_, u32 begin, u32 end) 17Block::Block(ObjectPool<Inst>& inst_pool_) : inst_pool{&inst_pool_} {}
18 : inst_pool{&inst_pool_}, location_begin{begin}, location_end{end} {}
19
20Block::Block(ObjectPool<Inst>& inst_pool_) : Block{inst_pool_, 0, 0} {}
21 18
22Block::~Block() = default; 19Block::~Block() = default;
23 20
@@ -40,39 +37,15 @@ Block::iterator Block::PrependNewInst(iterator insertion_point, Opcode op,
40 return result_it; 37 return result_it;
41} 38}
42 39
43void Block::SetBranches(Condition cond, Block* branch_true_, Block* branch_false_) { 40void Block::AddBranch(Block* block) {
44 branch_cond = cond; 41 if (std::ranges::find(imm_successors, block) != imm_successors.end()) {
45 branch_true = branch_true_; 42 throw LogicError("Successor already inserted");
46 branch_false = branch_false_; 43 }
47} 44 if (std::ranges::find(block->imm_predecessors, this) != block->imm_predecessors.end()) {
48 45 throw LogicError("Predecessor already inserted");
49void Block::SetBranch(Block* branch) {
50 branch_cond = Condition{true};
51 branch_true = branch;
52}
53
54void Block::SetReturn() {
55 branch_cond = Condition{true};
56 branch_true = nullptr;
57 branch_false = nullptr;
58}
59
60bool Block::IsVirtual() const noexcept {
61 return location_begin == location_end;
62}
63
64u32 Block::LocationBegin() const noexcept {
65 return location_begin;
66}
67
68u32 Block::LocationEnd() const noexcept {
69 return location_end;
70}
71
72void Block::AddImmediatePredecessor(Block* block) {
73 if (std::ranges::find(imm_predecessors, block) == imm_predecessors.end()) {
74 imm_predecessors.push_back(block);
75 } 46 }
47 imm_successors.push_back(block);
48 block->imm_predecessors.push_back(this);
76} 49}
77 50
78static std::string BlockToIndex(const std::map<const Block*, size_t>& block_to_index, 51static std::string BlockToIndex(const std::map<const Block*, size_t>& block_to_index,
@@ -92,15 +65,11 @@ static size_t InstIndex(std::map<const Inst*, size_t>& inst_to_index, size_t& in
92 return it->second; 65 return it->second;
93} 66}
94 67
95static std::string ArgToIndex(const std::map<const Block*, size_t>& block_to_index, 68static std::string ArgToIndex(std::map<const Inst*, size_t>& inst_to_index, size_t& inst_index,
96 std::map<const Inst*, size_t>& inst_to_index, size_t& inst_index,
97 const Value& arg) { 69 const Value& arg) {
98 if (arg.IsEmpty()) { 70 if (arg.IsEmpty()) {
99 return "<null>"; 71 return "<null>";
100 } 72 }
101 if (arg.IsLabel()) {
102 return BlockToIndex(block_to_index, arg.Label());
103 }
104 if (!arg.IsImmediate() || arg.IsIdentity()) { 73 if (!arg.IsImmediate() || arg.IsIdentity()) {
105 return fmt::format("%{}", InstIndex(inst_to_index, inst_index, arg.Inst())); 74 return fmt::format("%{}", InstIndex(inst_to_index, inst_index, arg.Inst()));
106 } 75 }
@@ -140,8 +109,7 @@ std::string DumpBlock(const Block& block, const std::map<const Block*, size_t>&
140 if (const auto it{block_to_index.find(&block)}; it != block_to_index.end()) { 109 if (const auto it{block_to_index.find(&block)}; it != block_to_index.end()) {
141 ret += fmt::format(" ${}", it->second); 110 ret += fmt::format(" ${}", it->second);
142 } 111 }
143 ret += fmt::format(": begin={:04x} end={:04x}\n", block.LocationBegin(), block.LocationEnd()); 112 ret += '\n';
144
145 for (const Inst& inst : block) { 113 for (const Inst& inst : block) {
146 const Opcode op{inst.GetOpcode()}; 114 const Opcode op{inst.GetOpcode()};
147 ret += fmt::format("[{:016x}] ", reinterpret_cast<u64>(&inst)); 115 ret += fmt::format("[{:016x}] ", reinterpret_cast<u64>(&inst));
@@ -153,7 +121,7 @@ std::string DumpBlock(const Block& block, const std::map<const Block*, size_t>&
153 const size_t arg_count{inst.NumArgs()}; 121 const size_t arg_count{inst.NumArgs()};
154 for (size_t arg_index = 0; arg_index < arg_count; ++arg_index) { 122 for (size_t arg_index = 0; arg_index < arg_count; ++arg_index) {
155 const Value arg{inst.Arg(arg_index)}; 123 const Value arg{inst.Arg(arg_index)};
156 const std::string arg_str{ArgToIndex(block_to_index, inst_to_index, inst_index, arg)}; 124 const std::string arg_str{ArgToIndex(inst_to_index, inst_index, arg)};
157 ret += arg_index != 0 ? ", " : " "; 125 ret += arg_index != 0 ? ", " : " ";
158 if (op == Opcode::Phi) { 126 if (op == Opcode::Phi) {
159 ret += fmt::format("[ {}, {} ]", arg_str, 127 ret += fmt::format("[ {}, {} ]", arg_str,