diff options
| author | 2021-07-25 11:39:04 -0700 | |
|---|---|---|
| committer | 2021-07-25 11:39:04 -0700 | |
| commit | 98b26b6e126d4775fdf3f773fe8a8ac808a8ff8f (patch) | |
| tree | 816faa96c2c4d291825063433331a8ea4b3d08f1 /src/shader_recompiler/ir_opt/identity_removal_pass.cpp | |
| parent | Merge pull request #6699 from lat9nq/common-threads (diff) | |
| parent | shader: Support out of bound local memory reads and immediate writes (diff) | |
| download | yuzu-98b26b6e126d4775fdf3f773fe8a8ac808a8ff8f.tar.gz yuzu-98b26b6e126d4775fdf3f773fe8a8ac808a8ff8f.tar.xz yuzu-98b26b6e126d4775fdf3f773fe8a8ac808a8ff8f.zip | |
Merge pull request #6585 from ameerj/hades
Shader Decompiler Rewrite
Diffstat (limited to 'src/shader_recompiler/ir_opt/identity_removal_pass.cpp')
| -rw-r--r-- | src/shader_recompiler/ir_opt/identity_removal_pass.cpp | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/shader_recompiler/ir_opt/identity_removal_pass.cpp b/src/shader_recompiler/ir_opt/identity_removal_pass.cpp new file mode 100644 index 000000000..e9b55f835 --- /dev/null +++ b/src/shader_recompiler/ir_opt/identity_removal_pass.cpp | |||
| @@ -0,0 +1,38 @@ | |||
| 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 <vector> | ||
| 6 | |||
| 7 | #include "shader_recompiler/frontend/ir/basic_block.h" | ||
| 8 | #include "shader_recompiler/frontend/ir/value.h" | ||
| 9 | #include "shader_recompiler/ir_opt/passes.h" | ||
| 10 | |||
| 11 | namespace Shader::Optimization { | ||
| 12 | |||
| 13 | void IdentityRemovalPass(IR::Program& program) { | ||
| 14 | std::vector<IR::Inst*> to_invalidate; | ||
| 15 | for (IR::Block* const block : program.blocks) { | ||
| 16 | for (auto inst = block->begin(); inst != block->end();) { | ||
| 17 | const size_t num_args{inst->NumArgs()}; | ||
| 18 | for (size_t i = 0; i < num_args; ++i) { | ||
| 19 | IR::Value arg; | ||
| 20 | while ((arg = inst->Arg(i)).IsIdentity()) { | ||
| 21 | inst->SetArg(i, arg.Inst()->Arg(0)); | ||
| 22 | } | ||
| 23 | } | ||
| 24 | if (inst->GetOpcode() == IR::Opcode::Identity || | ||
| 25 | inst->GetOpcode() == IR::Opcode::Void) { | ||
| 26 | to_invalidate.push_back(&*inst); | ||
| 27 | inst = block->Instructions().erase(inst); | ||
| 28 | } else { | ||
| 29 | ++inst; | ||
| 30 | } | ||
| 31 | } | ||
| 32 | } | ||
| 33 | for (IR::Inst* const inst : to_invalidate) { | ||
| 34 | inst->Invalidate(); | ||
| 35 | } | ||
| 36 | } | ||
| 37 | |||
| 38 | } // namespace Shader::Optimization | ||