2022-04-23 10:59:50 +02:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2021-01-09 07:30:07 +01:00
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "shader_recompiler/frontend/ir/basic_block.h"
|
2021-04-21 05:35:47 +02:00
|
|
|
#include "shader_recompiler/frontend/ir/value.h"
|
2021-01-09 07:30:07 +01:00
|
|
|
#include "shader_recompiler/ir_opt/passes.h"
|
|
|
|
|
|
|
|
namespace Shader::Optimization {
|
|
|
|
|
2021-03-14 07:41:05 +01:00
|
|
|
void IdentityRemovalPass(IR::Program& program) {
|
2021-01-09 07:30:07 +01:00
|
|
|
std::vector<IR::Inst*> to_invalidate;
|
2021-03-14 07:41:05 +01:00
|
|
|
for (IR::Block* const block : program.blocks) {
|
2021-02-05 09:58:02 +01: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-06 04:25:22 +02:00
|
|
|
if (inst->GetOpcode() == IR::Opcode::Identity ||
|
|
|
|
inst->GetOpcode() == IR::Opcode::Void) {
|
2021-02-05 09:58:02 +01:00
|
|
|
to_invalidate.push_back(&*inst);
|
|
|
|
inst = block->Instructions().erase(inst);
|
|
|
|
} else {
|
|
|
|
++inst;
|
2021-01-09 07:30:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (IR::Inst* const inst : to_invalidate) {
|
|
|
|
inst->Invalidate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Shader::Optimization
|