2021-01-08 22:30:07 -08:00
|
|
|
// Copyright 2021 yuzu Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "shader_recompiler/frontend/ir/basic_block.h"
|
|
|
|
#include "shader_recompiler/frontend/ir/microinstruction.h"
|
|
|
|
#include "shader_recompiler/ir_opt/passes.h"
|
|
|
|
|
|
|
|
namespace Shader::Optimization {
|
|
|
|
|
2021-03-13 22:41:05 -08:00
|
|
|
void IdentityRemovalPass(IR::Program& program) {
|
2021-01-08 22:30:07 -08:00
|
|
|
std::vector<IR::Inst*> to_invalidate;
|
|
|
|
|
2021-03-13 22:41:05 -08:00
|
|
|
for (IR::Block* const block : program.blocks) {
|
2021-02-05 00:58:02 -08:00
|
|
|
for (auto inst = block->begin(); inst != block->end();) {
|
|
|
|
const size_t num_args{inst->NumArgs()};
|
|
|
|
for (size_t i = 0; i < num_args; ++i) {
|
|
|
|
IR::Value arg;
|
|
|
|
while ((arg = inst->Arg(i)).IsIdentity()) {
|
|
|
|
inst->SetArg(i, arg.Inst()->Arg(0));
|
|
|
|
}
|
|
|
|
}
|
2021-04-05 19:25:22 -07:00
|
|
|
if (inst->GetOpcode() == IR::Opcode::Identity ||
|
|
|
|
inst->GetOpcode() == IR::Opcode::Void) {
|
2021-02-05 00:58:02 -08:00
|
|
|
to_invalidate.push_back(&*inst);
|
|
|
|
inst = block->Instructions().erase(inst);
|
|
|
|
} else {
|
|
|
|
++inst;
|
2021-01-08 22:30:07 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (IR::Inst* const inst : to_invalidate) {
|
|
|
|
inst->Invalidate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Shader::Optimization
|