summaryrefslogtreecommitdiff
path: root/src/shader_recompiler/ir_opt/ssa_rewrite_pass.cpp
diff options
context:
space:
mode:
authorGravatar ReinUsesLisp2021-02-11 16:39:06 -0300
committerGravatar ameerj2021-07-22 21:51:22 -0400
commit9170200a11715d131645d1ffb92e86e6ef0d7e88 (patch)
tree6c6f84c38a9b59d023ecb09c0737ea56da166b64 /src/shader_recompiler/ir_opt/ssa_rewrite_pass.cpp
parentspirv: Initial SPIR-V support (diff)
downloadyuzu-9170200a11715d131645d1ffb92e86e6ef0d7e88.tar.gz
yuzu-9170200a11715d131645d1ffb92e86e6ef0d7e88.tar.xz
yuzu-9170200a11715d131645d1ffb92e86e6ef0d7e88.zip
shader: Initial implementation of an AST
Diffstat (limited to 'src/shader_recompiler/ir_opt/ssa_rewrite_pass.cpp')
-rw-r--r--src/shader_recompiler/ir_opt/ssa_rewrite_pass.cpp24
1 files changed, 21 insertions, 3 deletions
diff --git a/src/shader_recompiler/ir_opt/ssa_rewrite_pass.cpp b/src/shader_recompiler/ir_opt/ssa_rewrite_pass.cpp
index 15a9db90a..8ca996e93 100644
--- a/src/shader_recompiler/ir_opt/ssa_rewrite_pass.cpp
+++ b/src/shader_recompiler/ir_opt/ssa_rewrite_pass.cpp
@@ -34,6 +34,13 @@ struct SignFlagTag : FlagTag {};
34struct CarryFlagTag : FlagTag {}; 34struct CarryFlagTag : FlagTag {};
35struct OverflowFlagTag : FlagTag {}; 35struct OverflowFlagTag : FlagTag {};
36 36
37struct GotoVariable : FlagTag {
38 GotoVariable() = default;
39 explicit GotoVariable(u32 index_) : index{index_} {}
40
41 u32 index;
42};
43
37struct DefTable { 44struct DefTable {
38 [[nodiscard]] ValueMap& operator[](IR::Reg variable) noexcept { 45 [[nodiscard]] ValueMap& operator[](IR::Reg variable) noexcept {
39 return regs[IR::RegIndex(variable)]; 46 return regs[IR::RegIndex(variable)];
@@ -43,6 +50,10 @@ struct DefTable {
43 return preds[IR::PredIndex(variable)]; 50 return preds[IR::PredIndex(variable)];
44 } 51 }
45 52
53 [[nodiscard]] ValueMap& operator[](GotoVariable goto_variable) {
54 return goto_vars[goto_variable.index];
55 }
56
46 [[nodiscard]] ValueMap& operator[](ZeroFlagTag) noexcept { 57 [[nodiscard]] ValueMap& operator[](ZeroFlagTag) noexcept {
47 return zero_flag; 58 return zero_flag;
48 } 59 }
@@ -61,6 +72,7 @@ struct DefTable {
61 72
62 std::array<ValueMap, IR::NUM_USER_REGS> regs; 73 std::array<ValueMap, IR::NUM_USER_REGS> regs;
63 std::array<ValueMap, IR::NUM_USER_PREDS> preds; 74 std::array<ValueMap, IR::NUM_USER_PREDS> preds;
75 boost::container::flat_map<u32, ValueMap> goto_vars;
64 ValueMap zero_flag; 76 ValueMap zero_flag;
65 ValueMap sign_flag; 77 ValueMap sign_flag;
66 ValueMap carry_flag; 78 ValueMap carry_flag;
@@ -68,15 +80,15 @@ struct DefTable {
68}; 80};
69 81
70IR::Opcode UndefOpcode(IR::Reg) noexcept { 82IR::Opcode UndefOpcode(IR::Reg) noexcept {
71 return IR::Opcode::Undef32; 83 return IR::Opcode::UndefU32;
72} 84}
73 85
74IR::Opcode UndefOpcode(IR::Pred) noexcept { 86IR::Opcode UndefOpcode(IR::Pred) noexcept {
75 return IR::Opcode::Undef1; 87 return IR::Opcode::UndefU1;
76} 88}
77 89
78IR::Opcode UndefOpcode(const FlagTag&) noexcept { 90IR::Opcode UndefOpcode(const FlagTag&) noexcept {
79 return IR::Opcode::Undef1; 91 return IR::Opcode::UndefU1;
80} 92}
81 93
82[[nodiscard]] bool IsPhi(const IR::Inst& inst) noexcept { 94[[nodiscard]] bool IsPhi(const IR::Inst& inst) noexcept {
@@ -165,6 +177,9 @@ void SsaRewritePass(IR::Function& function) {
165 pass.WriteVariable(pred, block, inst.Arg(1)); 177 pass.WriteVariable(pred, block, inst.Arg(1));
166 } 178 }
167 break; 179 break;
180 case IR::Opcode::SetGotoVariable:
181 pass.WriteVariable(GotoVariable{inst.Arg(0).U32()}, block, inst.Arg(1));
182 break;
168 case IR::Opcode::SetZFlag: 183 case IR::Opcode::SetZFlag:
169 pass.WriteVariable(ZeroFlagTag{}, block, inst.Arg(0)); 184 pass.WriteVariable(ZeroFlagTag{}, block, inst.Arg(0));
170 break; 185 break;
@@ -187,6 +202,9 @@ void SsaRewritePass(IR::Function& function) {
187 inst.ReplaceUsesWith(pass.ReadVariable(pred, block)); 202 inst.ReplaceUsesWith(pass.ReadVariable(pred, block));
188 } 203 }
189 break; 204 break;
205 case IR::Opcode::GetGotoVariable:
206 inst.ReplaceUsesWith(pass.ReadVariable(GotoVariable{inst.Arg(0).U32()}, block));
207 break;
190 case IR::Opcode::GetZFlag: 208 case IR::Opcode::GetZFlag:
191 inst.ReplaceUsesWith(pass.ReadVariable(ZeroFlagTag{}, block)); 209 inst.ReplaceUsesWith(pass.ReadVariable(ZeroFlagTag{}, block));
192 break; 210 break;