diff options
| author | 2021-02-03 16:43:04 -0300 | |
|---|---|---|
| committer | 2021-07-22 21:51:21 -0400 | |
| commit | d24a16045f0f6b0b873d5e3b5bf187c1a8c4343f (patch) | |
| tree | 0108a028b437bc59dfe7864f333cf4c50a46d3b5 /src/shader_recompiler/ir_opt | |
| parent | shader: SSA and dominance (diff) | |
| download | yuzu-d24a16045f0f6b0b873d5e3b5bf187c1a8c4343f.tar.gz yuzu-d24a16045f0f6b0b873d5e3b5bf187c1a8c4343f.tar.xz yuzu-d24a16045f0f6b0b873d5e3b5bf187c1a8c4343f.zip | |
shader: Initial instruction support
Diffstat (limited to 'src/shader_recompiler/ir_opt')
| -rw-r--r-- | src/shader_recompiler/ir_opt/get_set_elimination_pass.cpp | 87 | ||||
| -rw-r--r-- | src/shader_recompiler/ir_opt/passes.h | 1 |
2 files changed, 0 insertions, 88 deletions
diff --git a/src/shader_recompiler/ir_opt/get_set_elimination_pass.cpp b/src/shader_recompiler/ir_opt/get_set_elimination_pass.cpp deleted file mode 100644 index 21b8526cd..000000000 --- a/src/shader_recompiler/ir_opt/get_set_elimination_pass.cpp +++ /dev/null | |||
| @@ -1,87 +0,0 @@ | |||
| 1 | // Copyright 2021 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include <array> | ||
| 6 | |||
| 7 | #include "shader_recompiler/frontend/ir/basic_block.h" | ||
| 8 | #include "shader_recompiler/frontend/ir/microinstruction.h" | ||
| 9 | #include "shader_recompiler/ir_opt/passes.h" | ||
| 10 | |||
| 11 | namespace Shader::Optimization { | ||
| 12 | namespace { | ||
| 13 | using Iterator = IR::Block::iterator; | ||
| 14 | |||
| 15 | enum class TrackingType { | ||
| 16 | Reg, | ||
| 17 | }; | ||
| 18 | |||
| 19 | struct RegisterInfo { | ||
| 20 | IR::Value register_value; | ||
| 21 | TrackingType tracking_type; | ||
| 22 | Iterator last_set_instruction; | ||
| 23 | bool set_instruction_present = false; | ||
| 24 | }; | ||
| 25 | |||
| 26 | void DoSet(IR::Block& block, RegisterInfo& info, IR::Value value, Iterator set_inst, | ||
| 27 | TrackingType tracking_type) { | ||
| 28 | if (info.set_instruction_present) { | ||
| 29 | info.last_set_instruction->Invalidate(); | ||
| 30 | block.Instructions().erase(info.last_set_instruction); | ||
| 31 | } | ||
| 32 | info.register_value = value; | ||
| 33 | info.tracking_type = tracking_type; | ||
| 34 | info.set_instruction_present = true; | ||
| 35 | info.last_set_instruction = set_inst; | ||
| 36 | } | ||
| 37 | |||
| 38 | RegisterInfo Nothing(Iterator get_inst, TrackingType tracking_type) { | ||
| 39 | RegisterInfo info{}; | ||
| 40 | info.register_value = IR::Value{&*get_inst}; | ||
| 41 | info.tracking_type = tracking_type; | ||
| 42 | return info; | ||
| 43 | } | ||
| 44 | |||
| 45 | void DoGet(RegisterInfo& info, Iterator get_inst, TrackingType tracking_type) { | ||
| 46 | if (info.register_value.IsEmpty()) { | ||
| 47 | info = Nothing(get_inst, tracking_type); | ||
| 48 | return; | ||
| 49 | } | ||
| 50 | if (info.tracking_type == tracking_type) { | ||
| 51 | get_inst->ReplaceUsesWith(info.register_value); | ||
| 52 | return; | ||
| 53 | } | ||
| 54 | info = Nothing(get_inst, tracking_type); | ||
| 55 | } | ||
| 56 | } // Anonymous namespace | ||
| 57 | |||
| 58 | void GetSetElimination(IR::Block& block) { | ||
| 59 | std::array<RegisterInfo, 255> reg_info; | ||
| 60 | |||
| 61 | for (Iterator inst = block.begin(); inst != block.end(); ++inst) { | ||
| 62 | switch (inst->Opcode()) { | ||
| 63 | case IR::Opcode::GetRegister: { | ||
| 64 | const IR::Reg reg{inst->Arg(0).Reg()}; | ||
| 65 | if (reg == IR::Reg::RZ) { | ||
| 66 | break; | ||
| 67 | } | ||
| 68 | const size_t index{static_cast<size_t>(reg)}; | ||
| 69 | DoGet(reg_info.at(index), inst, TrackingType::Reg); | ||
| 70 | break; | ||
| 71 | } | ||
| 72 | case IR::Opcode::SetRegister: { | ||
| 73 | const IR::Reg reg{inst->Arg(0).Reg()}; | ||
| 74 | if (reg == IR::Reg::RZ) { | ||
| 75 | break; | ||
| 76 | } | ||
| 77 | const size_t index{static_cast<size_t>(reg)}; | ||
| 78 | DoSet(block, reg_info.at(index), inst->Arg(1), inst, TrackingType::Reg); | ||
| 79 | break; | ||
| 80 | } | ||
| 81 | default: | ||
| 82 | break; | ||
| 83 | } | ||
| 84 | } | ||
| 85 | } | ||
| 86 | |||
| 87 | } // namespace Shader::Optimization | ||
diff --git a/src/shader_recompiler/ir_opt/passes.h b/src/shader_recompiler/ir_opt/passes.h index 83f094d73..7ed4005ed 100644 --- a/src/shader_recompiler/ir_opt/passes.h +++ b/src/shader_recompiler/ir_opt/passes.h | |||
| @@ -17,7 +17,6 @@ void Invoke(Func&& func, IR::Function& function) { | |||
| 17 | } | 17 | } |
| 18 | 18 | ||
| 19 | void DeadCodeEliminationPass(IR::Block& block); | 19 | void DeadCodeEliminationPass(IR::Block& block); |
| 20 | void GetSetElimination(IR::Block& block); | ||
| 21 | void IdentityRemovalPass(IR::Block& block); | 20 | void IdentityRemovalPass(IR::Block& block); |
| 22 | void SsaRewritePass(IR::Function& function); | 21 | void SsaRewritePass(IR::Function& function); |
| 23 | void VerificationPass(const IR::Block& block); | 22 | void VerificationPass(const IR::Block& block); |