diff options
Diffstat (limited to 'src/shader_recompiler/frontend/ir')
| -rw-r--r-- | src/shader_recompiler/frontend/ir/basic_block.h | 14 | ||||
| -rw-r--r-- | src/shader_recompiler/frontend/ir/microinstruction.cpp | 11 | ||||
| -rw-r--r-- | src/shader_recompiler/frontend/ir/value.h | 3 |
3 files changed, 28 insertions, 0 deletions
diff --git a/src/shader_recompiler/frontend/ir/basic_block.h b/src/shader_recompiler/frontend/ir/basic_block.h index 7e134b4c7..9ce1ed07e 100644 --- a/src/shader_recompiler/frontend/ir/basic_block.h +++ b/src/shader_recompiler/frontend/ir/basic_block.h | |||
| @@ -152,6 +152,17 @@ public: | |||
| 152 | return instructions.crend(); | 152 | return instructions.crend(); |
| 153 | } | 153 | } |
| 154 | 154 | ||
| 155 | // Set the order of the block, it can be set pre order, the user decides | ||
| 156 | void SetOrder(u32 new_order) { | ||
| 157 | order = new_order; | ||
| 158 | } | ||
| 159 | |||
| 160 | // Get the order of the block. | ||
| 161 | // The higher, the closer is the block to the end. | ||
| 162 | [[nodiscard]] u32 GetOrder() const { | ||
| 163 | return order; | ||
| 164 | } | ||
| 165 | |||
| 155 | private: | 166 | private: |
| 156 | /// Memory pool for instruction list | 167 | /// Memory pool for instruction list |
| 157 | ObjectPool<Inst>* inst_pool; | 168 | ObjectPool<Inst>* inst_pool; |
| @@ -171,6 +182,9 @@ private: | |||
| 171 | 182 | ||
| 172 | /// Intrusively stored host definition of this block. | 183 | /// Intrusively stored host definition of this block. |
| 173 | u32 definition{}; | 184 | u32 definition{}; |
| 185 | |||
| 186 | /// Order of the block. | ||
| 187 | u32 order{}; | ||
| 174 | }; | 188 | }; |
| 175 | 189 | ||
| 176 | using BlockList = std::vector<Block*>; | 190 | using BlockList = std::vector<Block*>; |
diff --git a/src/shader_recompiler/frontend/ir/microinstruction.cpp b/src/shader_recompiler/frontend/ir/microinstruction.cpp index 3dfa5a880..e563b4022 100644 --- a/src/shader_recompiler/frontend/ir/microinstruction.cpp +++ b/src/shader_recompiler/frontend/ir/microinstruction.cpp | |||
| @@ -6,6 +6,7 @@ | |||
| 6 | #include <memory> | 6 | #include <memory> |
| 7 | 7 | ||
| 8 | #include "shader_recompiler/exception.h" | 8 | #include "shader_recompiler/exception.h" |
| 9 | #include "shader_recompiler/frontend/ir/basic_block.h" | ||
| 9 | #include "shader_recompiler/frontend/ir/type.h" | 10 | #include "shader_recompiler/frontend/ir/type.h" |
| 10 | #include "shader_recompiler/frontend/ir/value.h" | 11 | #include "shader_recompiler/frontend/ir/value.h" |
| 11 | 12 | ||
| @@ -291,6 +292,16 @@ void Inst::AddPhiOperand(Block* predecessor, const Value& value) { | |||
| 291 | phi_args.emplace_back(predecessor, value); | 292 | phi_args.emplace_back(predecessor, value); |
| 292 | } | 293 | } |
| 293 | 294 | ||
| 295 | void Inst::OrderPhiArgs() { | ||
| 296 | if (op != Opcode::Phi) { | ||
| 297 | throw LogicError("{} is not a Phi instruction", op); | ||
| 298 | } | ||
| 299 | std::sort(phi_args.begin(), phi_args.end(), | ||
| 300 | [](const std::pair<Block*, Value>& a, const std::pair<Block*, Value>& b) { | ||
| 301 | return a.first->GetOrder() < b.first->GetOrder(); | ||
| 302 | }); | ||
| 303 | } | ||
| 304 | |||
| 294 | void Inst::Invalidate() { | 305 | void Inst::Invalidate() { |
| 295 | ClearArgs(); | 306 | ClearArgs(); |
| 296 | ReplaceOpcode(Opcode::Void); | 307 | ReplaceOpcode(Opcode::Void); |
diff --git a/src/shader_recompiler/frontend/ir/value.h b/src/shader_recompiler/frontend/ir/value.h index 334bb47aa..6c9ef6bdd 100644 --- a/src/shader_recompiler/frontend/ir/value.h +++ b/src/shader_recompiler/frontend/ir/value.h | |||
| @@ -182,6 +182,9 @@ public: | |||
| 182 | /// Add phi operand to a phi instruction. | 182 | /// Add phi operand to a phi instruction. |
| 183 | void AddPhiOperand(Block* predecessor, const Value& value); | 183 | void AddPhiOperand(Block* predecessor, const Value& value); |
| 184 | 184 | ||
| 185 | /// Orders the Phi arguments from farthest away to nearest. | ||
| 186 | void OrderPhiArgs(); | ||
| 187 | |||
| 185 | void Invalidate(); | 188 | void Invalidate(); |
| 186 | void ClearArgs(); | 189 | void ClearArgs(); |
| 187 | 190 | ||