summaryrefslogtreecommitdiff
path: root/src/shader_recompiler/ir_opt
diff options
context:
space:
mode:
Diffstat (limited to 'src/shader_recompiler/ir_opt')
-rw-r--r--src/shader_recompiler/ir_opt/constant_propagation_pass.cpp9
-rw-r--r--src/shader_recompiler/ir_opt/global_memory_to_storage_buffer_pass.cpp10
-rw-r--r--src/shader_recompiler/ir_opt/ssa_rewrite_pass.cpp50
3 files changed, 9 insertions, 60 deletions
diff --git a/src/shader_recompiler/ir_opt/constant_propagation_pass.cpp b/src/shader_recompiler/ir_opt/constant_propagation_pass.cpp
index 8999c3a3d..1720d7a09 100644
--- a/src/shader_recompiler/ir_opt/constant_propagation_pass.cpp
+++ b/src/shader_recompiler/ir_opt/constant_propagation_pass.cpp
@@ -374,17 +374,14 @@ std::optional<IR::Value> FoldCompositeExtractImpl(IR::Value inst_value, IR::Opco
374 if (inst->Opcode() == construct) { 374 if (inst->Opcode() == construct) {
375 return inst->Arg(first_index); 375 return inst->Arg(first_index);
376 } 376 }
377
378 if (inst->Opcode() != insert) { 377 if (inst->Opcode() != insert) {
379 return std::nullopt; 378 return std::nullopt;
380 } 379 }
381
382 IR::Value value_index{inst->Arg(2)}; 380 IR::Value value_index{inst->Arg(2)};
383 if (!value_index.IsImmediate()) { 381 if (!value_index.IsImmediate()) {
384 return std::nullopt; 382 return std::nullopt;
385 } 383 }
386 384 const u32 second_index{value_index.U32()};
387 const u32 second_index = value_index.U32();
388 if (first_index != second_index) { 385 if (first_index != second_index) {
389 IR::Value value_composite{inst->Arg(0)}; 386 IR::Value value_composite{inst->Arg(0)};
390 if (value_composite.IsImmediate()) { 387 if (value_composite.IsImmediate()) {
@@ -404,8 +401,8 @@ void FoldCompositeExtract(IR::Inst& inst, IR::Opcode construct, IR::Opcode inser
404 if (!value_2.IsImmediate()) { 401 if (!value_2.IsImmediate()) {
405 return; 402 return;
406 } 403 }
407 const u32 first_index = value_2.U32(); 404 const u32 first_index{value_2.U32()};
408 auto result = FoldCompositeExtractImpl(value_1, insert, construct, first_index); 405 const std::optional result{FoldCompositeExtractImpl(value_1, insert, construct, first_index)};
409 if (!result) { 406 if (!result) {
410 return; 407 return;
411 } 408 }
diff --git a/src/shader_recompiler/ir_opt/global_memory_to_storage_buffer_pass.cpp b/src/shader_recompiler/ir_opt/global_memory_to_storage_buffer_pass.cpp
index d4bae249b..8876a5c33 100644
--- a/src/shader_recompiler/ir_opt/global_memory_to_storage_buffer_pass.cpp
+++ b/src/shader_recompiler/ir_opt/global_memory_to_storage_buffer_pass.cpp
@@ -4,9 +4,9 @@
4 4
5#include <algorithm> 5#include <algorithm>
6#include <compare> 6#include <compare>
7#include <map>
7#include <optional> 8#include <optional>
8#include <ranges> 9#include <ranges>
9#include <map>
10 10
11#include <boost/container/flat_set.hpp> 11#include <boost/container/flat_set.hpp>
12#include <boost/container/small_vector.hpp> 12#include <boost/container/small_vector.hpp>
@@ -295,12 +295,12 @@ void CollectStorageBuffers(IR::Block& block, IR::Inst& inst, StorageBufferSet& s
295 } 295 }
296 } 296 }
297 // Collect storage buffer and the instruction 297 // Collect storage buffer and the instruction
298 const bool is_a_write = IsGlobalMemoryWrite(inst); 298 const bool is_a_write{IsGlobalMemoryWrite(inst)};
299 auto it = writes_map.find(*storage_buffer); 299 auto it{writes_map.find(*storage_buffer)};
300 if (it == writes_map.end()) { 300 if (it == writes_map.end()) {
301 writes_map[*storage_buffer] = is_a_write; 301 writes_map[*storage_buffer] = is_a_write;
302 } else { 302 } else {
303 it->second = it->second || is_a_write; 303 it->second = it->second || is_a_write;
304 } 304 }
305 storage_buffer_set.insert(*storage_buffer); 305 storage_buffer_set.insert(*storage_buffer);
306 to_replace.push_back(StorageInst{ 306 to_replace.push_back(StorageInst{
diff --git a/src/shader_recompiler/ir_opt/ssa_rewrite_pass.cpp b/src/shader_recompiler/ir_opt/ssa_rewrite_pass.cpp
index 7dab33034..72d4abb77 100644
--- a/src/shader_recompiler/ir_opt/ssa_rewrite_pass.cpp
+++ b/src/shader_recompiler/ir_opt/ssa_rewrite_pass.cpp
@@ -38,10 +38,6 @@ struct ZeroFlagTag : FlagTag {};
38struct SignFlagTag : FlagTag {}; 38struct SignFlagTag : FlagTag {};
39struct CarryFlagTag : FlagTag {}; 39struct CarryFlagTag : FlagTag {};
40struct OverflowFlagTag : FlagTag {}; 40struct OverflowFlagTag : FlagTag {};
41struct FCSMFlagTag : FlagTag {};
42struct TAFlagTag : FlagTag {};
43struct TRFlagTag : FlagTag {};
44struct MXFlagTag : FlagTag {};
45 41
46struct GotoVariable : FlagTag { 42struct GotoVariable : FlagTag {
47 GotoVariable() = default; 43 GotoVariable() = default;
@@ -57,8 +53,7 @@ struct IndirectBranchVariable {
57}; 53};
58 54
59using Variant = std::variant<IR::Reg, IR::Pred, ZeroFlagTag, SignFlagTag, CarryFlagTag, 55using Variant = std::variant<IR::Reg, IR::Pred, ZeroFlagTag, SignFlagTag, CarryFlagTag,
60 OverflowFlagTag, FCSMFlagTag, TAFlagTag, TRFlagTag, MXFlagTag, 56 OverflowFlagTag, GotoVariable, IndirectBranchVariable>;
61 GotoVariable, IndirectBranchVariable>;
62using ValueMap = boost::container::flat_map<IR::Block*, IR::Value, std::less<IR::Block*>>; 57using ValueMap = boost::container::flat_map<IR::Block*, IR::Value, std::less<IR::Block*>>;
63 58
64struct DefTable { 59struct DefTable {
@@ -94,22 +89,6 @@ struct DefTable {
94 return overflow_flag; 89 return overflow_flag;
95 } 90 }
96 91
97 [[nodiscard]] ValueMap& operator[](FCSMFlagTag) noexcept {
98 return fcsm_flag;
99 }
100
101 [[nodiscard]] ValueMap& operator[](TAFlagTag) noexcept {
102 return ta_flag;
103 }
104
105 [[nodiscard]] ValueMap& operator[](TRFlagTag) noexcept {
106 return tr_flag;
107 }
108
109 [[nodiscard]] ValueMap& operator[](MXFlagTag) noexcept {
110 return mr_flag;
111 }
112
113 std::array<ValueMap, IR::NUM_USER_REGS> regs; 92 std::array<ValueMap, IR::NUM_USER_REGS> regs;
114 std::array<ValueMap, IR::NUM_USER_PREDS> preds; 93 std::array<ValueMap, IR::NUM_USER_PREDS> preds;
115 boost::container::flat_map<u32, ValueMap> goto_vars; 94 boost::container::flat_map<u32, ValueMap> goto_vars;
@@ -118,10 +97,6 @@ struct DefTable {
118 ValueMap sign_flag; 97 ValueMap sign_flag;
119 ValueMap carry_flag; 98 ValueMap carry_flag;
120 ValueMap overflow_flag; 99 ValueMap overflow_flag;
121 ValueMap fcsm_flag;
122 ValueMap ta_flag;
123 ValueMap tr_flag;
124 ValueMap mr_flag;
125}; 100};
126 101
127IR::Opcode UndefOpcode(IR::Reg) noexcept { 102IR::Opcode UndefOpcode(IR::Reg) noexcept {
@@ -272,18 +247,6 @@ void VisitInst(Pass& pass, IR::Block* block, IR::Inst& inst) {
272 case IR::Opcode::SetOFlag: 247 case IR::Opcode::SetOFlag:
273 pass.WriteVariable(OverflowFlagTag{}, block, inst.Arg(0)); 248 pass.WriteVariable(OverflowFlagTag{}, block, inst.Arg(0));
274 break; 249 break;
275 case IR::Opcode::SetFCSMFlag:
276 pass.WriteVariable(FCSMFlagTag{}, block, inst.Arg(0));
277 break;
278 case IR::Opcode::SetTAFlag:
279 pass.WriteVariable(TAFlagTag{}, block, inst.Arg(0));
280 break;
281 case IR::Opcode::SetTRFlag:
282 pass.WriteVariable(TRFlagTag{}, block, inst.Arg(0));
283 break;
284 case IR::Opcode::SetMXFlag:
285 pass.WriteVariable(MXFlagTag{}, block, inst.Arg(0));
286 break;
287 case IR::Opcode::GetRegister: 250 case IR::Opcode::GetRegister:
288 if (const IR::Reg reg{inst.Arg(0).Reg()}; reg != IR::Reg::RZ) { 251 if (const IR::Reg reg{inst.Arg(0).Reg()}; reg != IR::Reg::RZ) {
289 inst.ReplaceUsesWith(pass.ReadVariable(reg, block)); 252 inst.ReplaceUsesWith(pass.ReadVariable(reg, block));
@@ -312,17 +275,6 @@ void VisitInst(Pass& pass, IR::Block* block, IR::Inst& inst) {
312 case IR::Opcode::GetOFlag: 275 case IR::Opcode::GetOFlag:
313 inst.ReplaceUsesWith(pass.ReadVariable(OverflowFlagTag{}, block)); 276 inst.ReplaceUsesWith(pass.ReadVariable(OverflowFlagTag{}, block));
314 break; 277 break;
315 case IR::Opcode::GetFCSMFlag:
316 inst.ReplaceUsesWith(pass.ReadVariable(FCSMFlagTag{}, block));
317 break;
318 case IR::Opcode::GetTAFlag:
319 inst.ReplaceUsesWith(pass.ReadVariable(TAFlagTag{}, block));
320 break;
321 case IR::Opcode::GetTRFlag:
322 inst.ReplaceUsesWith(pass.ReadVariable(TRFlagTag{}, block));
323 break;
324 case IR::Opcode::GetMXFlag:
325 inst.ReplaceUsesWith(pass.ReadVariable(MXFlagTag{}, block));
326 break; 278 break;
327 default: 279 default:
328 break; 280 break;