diff options
Diffstat (limited to 'src/shader_recompiler/backend/glasm/emit_glasm.cpp')
| -rw-r--r-- | src/shader_recompiler/backend/glasm/emit_glasm.cpp | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/shader_recompiler/backend/glasm/emit_glasm.cpp b/src/shader_recompiler/backend/glasm/emit_glasm.cpp index 8718cc7ec..2ce839059 100644 --- a/src/shader_recompiler/backend/glasm/emit_glasm.cpp +++ b/src/shader_recompiler/backend/glasm/emit_glasm.cpp | |||
| @@ -178,6 +178,10 @@ void EmitInst(EmitContext& ctx, IR::Inst* inst) { | |||
| 178 | throw LogicError("Invalid opcode {}", inst->GetOpcode()); | 178 | throw LogicError("Invalid opcode {}", inst->GetOpcode()); |
| 179 | } | 179 | } |
| 180 | 180 | ||
| 181 | bool IsReference(IR::Inst& inst) { | ||
| 182 | return inst.GetOpcode() == IR::Opcode::Reference; | ||
| 183 | } | ||
| 184 | |||
| 181 | void Precolor(EmitContext& ctx, const IR::Program& program) { | 185 | void Precolor(EmitContext& ctx, const IR::Program& program) { |
| 182 | for (IR::Block* const block : program.blocks) { | 186 | for (IR::Block* const block : program.blocks) { |
| 183 | for (IR::Inst& phi : block->Instructions() | std::views::take_while(IR::IsPhi)) { | 187 | for (IR::Inst& phi : block->Instructions() | std::views::take_while(IR::IsPhi)) { |
| @@ -194,11 +198,13 @@ void Precolor(EmitContext& ctx, const IR::Program& program) { | |||
| 194 | default: | 198 | default: |
| 195 | throw NotImplementedException("Phi node type {}", phi.Type()); | 199 | throw NotImplementedException("Phi node type {}", phi.Type()); |
| 196 | } | 200 | } |
| 201 | // Insert phi moves before references to avoid overwritting them | ||
| 197 | const size_t num_args{phi.NumArgs()}; | 202 | const size_t num_args{phi.NumArgs()}; |
| 198 | for (size_t i = 0; i < num_args; ++i) { | 203 | for (size_t i = 0; i < num_args; ++i) { |
| 199 | IR::IREmitter{*phi.PhiBlock(i)}.PhiMove(phi, phi.Arg(i)); | 204 | IR::Block& phi_block{*phi.PhiBlock(i)}; |
| 205 | auto it{std::find_if_not(phi_block.rbegin(), phi_block.rend(), IsReference).base()}; | ||
| 206 | IR::IREmitter{phi_block, it}.PhiMove(phi, phi.Arg(i)); | ||
| 200 | } | 207 | } |
| 201 | // Add reference to the phi node on the phi predecessor to avoid overwritting it | ||
| 202 | for (size_t i = 0; i < num_args; ++i) { | 208 | for (size_t i = 0; i < num_args; ++i) { |
| 203 | IR::IREmitter{*phi.PhiBlock(i)}.Reference(IR::Value{&phi}); | 209 | IR::IREmitter{*phi.PhiBlock(i)}.Reference(IR::Value{&phi}); |
| 204 | } | 210 | } |
| @@ -237,7 +243,7 @@ void EmitCode(EmitContext& ctx, const IR::Program& program) { | |||
| 237 | } | 243 | } |
| 238 | } else { | 244 | } else { |
| 239 | ctx.Add("MOV.S.CC RC,{};" | 245 | ctx.Add("MOV.S.CC RC,{};" |
| 240 | "BRK (EQ.x);" | 246 | "BRK(EQ.x);" |
| 241 | "ENDREP;", | 247 | "ENDREP;", |
| 242 | eval(node.data.repeat.cond)); | 248 | eval(node.data.repeat.cond)); |
| 243 | } | 249 | } |