summaryrefslogtreecommitdiff
path: root/src/shader_recompiler/frontend/ir/basic_block.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/shader_recompiler/frontend/ir/basic_block.h')
-rw-r--r--src/shader_recompiler/frontend/ir/basic_block.h51
1 files changed, 10 insertions, 41 deletions
diff --git a/src/shader_recompiler/frontend/ir/basic_block.h b/src/shader_recompiler/frontend/ir/basic_block.h
index 0b0c97af6..7e134b4c7 100644
--- a/src/shader_recompiler/frontend/ir/basic_block.h
+++ b/src/shader_recompiler/frontend/ir/basic_block.h
@@ -12,6 +12,7 @@
12#include <boost/intrusive/list.hpp> 12#include <boost/intrusive/list.hpp>
13 13
14#include "common/bit_cast.h" 14#include "common/bit_cast.h"
15#include "common/common_types.h"
15#include "shader_recompiler/frontend/ir/condition.h" 16#include "shader_recompiler/frontend/ir/condition.h"
16#include "shader_recompiler/frontend/ir/value.h" 17#include "shader_recompiler/frontend/ir/value.h"
17#include "shader_recompiler/object_pool.h" 18#include "shader_recompiler/object_pool.h"
@@ -27,7 +28,6 @@ public:
27 using reverse_iterator = InstructionList::reverse_iterator; 28 using reverse_iterator = InstructionList::reverse_iterator;
28 using const_reverse_iterator = InstructionList::const_reverse_iterator; 29 using const_reverse_iterator = InstructionList::const_reverse_iterator;
29 30
30 explicit Block(ObjectPool<Inst>& inst_pool_, u32 begin, u32 end);
31 explicit Block(ObjectPool<Inst>& inst_pool_); 31 explicit Block(ObjectPool<Inst>& inst_pool_);
32 ~Block(); 32 ~Block();
33 33
@@ -44,22 +44,8 @@ public:
44 iterator PrependNewInst(iterator insertion_point, Opcode op, 44 iterator PrependNewInst(iterator insertion_point, Opcode op,
45 std::initializer_list<Value> args = {}, u32 flags = 0); 45 std::initializer_list<Value> args = {}, u32 flags = 0);
46 46
47 /// Set the branches to jump to when all instructions have executed. 47 /// Adds a new branch to this basic block.
48 void SetBranches(Condition cond, Block* branch_true, Block* branch_false); 48 void AddBranch(Block* block);
49 /// Set the branch to unconditionally jump to when all instructions have executed.
50 void SetBranch(Block* branch);
51 /// Mark the block as a return block.
52 void SetReturn();
53
54 /// Returns true when the block does not implement any guest instructions directly.
55 [[nodiscard]] bool IsVirtual() const noexcept;
56 /// Gets the starting location of this basic block.
57 [[nodiscard]] u32 LocationBegin() const noexcept;
58 /// Gets the end location for this basic block.
59 [[nodiscard]] u32 LocationEnd() const noexcept;
60
61 /// Adds a new immediate predecessor to this basic block.
62 void AddImmediatePredecessor(Block* block);
63 49
64 /// Gets a mutable reference to the instruction list for this basic block. 50 /// Gets a mutable reference to the instruction list for this basic block.
65 [[nodiscard]] InstructionList& Instructions() noexcept { 51 [[nodiscard]] InstructionList& Instructions() noexcept {
@@ -71,9 +57,13 @@ public:
71 } 57 }
72 58
73 /// Gets an immutable span to the immediate predecessors. 59 /// Gets an immutable span to the immediate predecessors.
74 [[nodiscard]] std::span<Block* const> ImmediatePredecessors() const noexcept { 60 [[nodiscard]] std::span<Block* const> ImmPredecessors() const noexcept {
75 return imm_predecessors; 61 return imm_predecessors;
76 } 62 }
63 /// Gets an immutable span to the immediate successors.
64 [[nodiscard]] std::span<Block* const> ImmSuccessors() const noexcept {
65 return imm_successors;
66 }
77 67
78 /// Intrusively store the host definition of this instruction. 68 /// Intrusively store the host definition of this instruction.
79 template <typename DefinitionType> 69 template <typename DefinitionType>
@@ -87,19 +77,6 @@ public:
87 return Common::BitCast<DefinitionType>(definition); 77 return Common::BitCast<DefinitionType>(definition);
88 } 78 }
89 79
90 [[nodiscard]] Condition BranchCondition() const noexcept {
91 return branch_cond;
92 }
93 [[nodiscard]] bool IsTerminationBlock() const noexcept {
94 return !branch_true && !branch_false;
95 }
96 [[nodiscard]] Block* TrueBranch() const noexcept {
97 return branch_true;
98 }
99 [[nodiscard]] Block* FalseBranch() const noexcept {
100 return branch_false;
101 }
102
103 void SetSsaRegValue(IR::Reg reg, const Value& value) noexcept { 80 void SetSsaRegValue(IR::Reg reg, const Value& value) noexcept {
104 ssa_reg_values[RegIndex(reg)] = value; 81 ssa_reg_values[RegIndex(reg)] = value;
105 } 82 }
@@ -178,22 +155,14 @@ public:
178private: 155private:
179 /// Memory pool for instruction list 156 /// Memory pool for instruction list
180 ObjectPool<Inst>* inst_pool; 157 ObjectPool<Inst>* inst_pool;
181 /// Starting location of this block
182 u32 location_begin;
183 /// End location of this block
184 u32 location_end;
185 158
186 /// List of instructions in this block 159 /// List of instructions in this block
187 InstructionList instructions; 160 InstructionList instructions;
188 161
189 /// Condition to choose the branch to take
190 Condition branch_cond{true};
191 /// Block to jump into when the branch condition evaluates as true
192 Block* branch_true{nullptr};
193 /// Block to jump into when the branch condition evaluates as false
194 Block* branch_false{nullptr};
195 /// Block immediate predecessors 162 /// Block immediate predecessors
196 std::vector<Block*> imm_predecessors; 163 std::vector<Block*> imm_predecessors;
164 /// Block immediate successors
165 std::vector<Block*> imm_successors;
197 166
198 /// Intrusively store the value of a register in the block. 167 /// Intrusively store the value of a register in the block.
199 std::array<Value, NUM_REGS> ssa_reg_values; 168 std::array<Value, NUM_REGS> ssa_reg_values;