diff options
| author | 2021-05-25 17:37:35 -0300 | |
|---|---|---|
| committer | 2021-07-22 21:51:33 -0400 | |
| commit | 48aafe0961a2ddfb52b627c6ba6bce8276330550 (patch) | |
| tree | 3a8f1e05bf1a7f0e54301ca20d81c378c250cd7c /src/shader_recompiler/backend/glasm/emit_glasm.cpp | |
| parent | glasm: Remove unintentionally committed fmt::prints (diff) | |
| download | yuzu-48aafe0961a2ddfb52b627c6ba6bce8276330550.tar.gz yuzu-48aafe0961a2ddfb52b627c6ba6bce8276330550.tar.xz yuzu-48aafe0961a2ddfb52b627c6ba6bce8276330550.zip | |
glasm: Release phi node registers after they are no longer needed
Diffstat (limited to 'src/shader_recompiler/backend/glasm/emit_glasm.cpp')
| -rw-r--r-- | src/shader_recompiler/backend/glasm/emit_glasm.cpp | 53 |
1 files changed, 22 insertions, 31 deletions
diff --git a/src/shader_recompiler/backend/glasm/emit_glasm.cpp b/src/shader_recompiler/backend/glasm/emit_glasm.cpp index 5ffefaad2..4f838b699 100644 --- a/src/shader_recompiler/backend/glasm/emit_glasm.cpp +++ b/src/shader_recompiler/backend/glasm/emit_glasm.cpp | |||
| @@ -172,38 +172,29 @@ bool IsReference(IR::Inst& inst) { | |||
| 172 | return inst.GetOpcode() == IR::Opcode::Reference; | 172 | return inst.GetOpcode() == IR::Opcode::Reference; |
| 173 | } | 173 | } |
| 174 | 174 | ||
| 175 | void Precolor(EmitContext& ctx, const IR::Program& program) { | 175 | void PrecolorInst(IR::Inst& phi) { |
| 176 | // Insert phi moves before references to avoid overwritting other phis | ||
| 177 | const size_t num_args{phi.NumArgs()}; | ||
| 178 | for (size_t i = 0; i < num_args; ++i) { | ||
| 179 | IR::Block& phi_block{*phi.PhiBlock(i)}; | ||
| 180 | auto it{std::find_if_not(phi_block.rbegin(), phi_block.rend(), IsReference).base()}; | ||
| 181 | IR::IREmitter ir{phi_block, it}; | ||
| 182 | const IR::Value arg{phi.Arg(i)}; | ||
| 183 | if (arg.IsImmediate()) { | ||
| 184 | ir.PhiMove(phi, arg); | ||
| 185 | } else { | ||
| 186 | ir.PhiMove(phi, IR::Value{&RegAlloc::AliasInst(*arg.Inst())}); | ||
| 187 | } | ||
| 188 | } | ||
| 189 | for (size_t i = 0; i < num_args; ++i) { | ||
| 190 | IR::IREmitter{*phi.PhiBlock(i)}.Reference(IR::Value{&phi}); | ||
| 191 | } | ||
| 192 | } | ||
| 193 | |||
| 194 | void Precolor(const IR::Program& program) { | ||
| 176 | for (IR::Block* const block : program.blocks) { | 195 | for (IR::Block* const block : program.blocks) { |
| 177 | for (IR::Inst& phi : block->Instructions() | std::views::take_while(IR::IsPhi)) { | 196 | for (IR::Inst& phi : block->Instructions() | std::views::take_while(IR::IsPhi)) { |
| 178 | switch (phi.Arg(0).Type()) { | 197 | PrecolorInst(phi); |
| 179 | case IR::Type::U1: | ||
| 180 | case IR::Type::U32: | ||
| 181 | case IR::Type::F32: | ||
| 182 | ctx.reg_alloc.Define(phi); | ||
| 183 | break; | ||
| 184 | case IR::Type::U64: | ||
| 185 | case IR::Type::F64: | ||
| 186 | ctx.reg_alloc.LongDefine(phi); | ||
| 187 | break; | ||
| 188 | default: | ||
| 189 | throw NotImplementedException("Phi node type {}", phi.Type()); | ||
| 190 | } | ||
| 191 | // Insert phi moves before references to avoid overwritting them | ||
| 192 | const size_t num_args{phi.NumArgs()}; | ||
| 193 | for (size_t i = 0; i < num_args; ++i) { | ||
| 194 | IR::Block& phi_block{*phi.PhiBlock(i)}; | ||
| 195 | auto it{std::find_if_not(phi_block.rbegin(), phi_block.rend(), IsReference).base()}; | ||
| 196 | IR::IREmitter ir{phi_block, it}; | ||
| 197 | const IR::Value arg{phi.Arg(i)}; | ||
| 198 | if (arg.IsImmediate()) { | ||
| 199 | ir.PhiMove(phi, arg); | ||
| 200 | } else { | ||
| 201 | ir.PhiMove(phi, IR::Value{&RegAlloc::AliasInst(*arg.Inst())}); | ||
| 202 | } | ||
| 203 | } | ||
| 204 | for (size_t i = 0; i < num_args; ++i) { | ||
| 205 | IR::IREmitter{*phi.PhiBlock(i)}.Reference(IR::Value{&phi}); | ||
| 206 | } | ||
| 207 | } | 198 | } |
| 208 | } | 199 | } |
| 209 | } | 200 | } |
| @@ -388,7 +379,7 @@ std::string_view GetTessSpacing(TessSpacing spacing) { | |||
| 388 | std::string EmitGLASM(const Profile& profile, const RuntimeInfo& runtime_info, IR::Program& program, | 379 | std::string EmitGLASM(const Profile& profile, const RuntimeInfo& runtime_info, IR::Program& program, |
| 389 | Bindings& bindings) { | 380 | Bindings& bindings) { |
| 390 | EmitContext ctx{program, bindings, profile, runtime_info}; | 381 | EmitContext ctx{program, bindings, profile, runtime_info}; |
| 391 | Precolor(ctx, program); | 382 | Precolor(program); |
| 392 | EmitCode(ctx, program); | 383 | EmitCode(ctx, program); |
| 393 | std::string header{StageHeader(program.stage)}; | 384 | std::string header{StageHeader(program.stage)}; |
| 394 | SetupOptions(program, profile, runtime_info, header); | 385 | SetupOptions(program, profile, runtime_info, header); |