|
@@ -2,6 +2,10 @@
|
|
|
// Licensed under GPLv2 or any later version
|
|
// Licensed under GPLv2 or any later version
|
|
|
// Refer to the license.txt file included.
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
|
|
+#include <algorithm>
|
|
|
|
|
+
|
|
|
|
|
+#include <boost/container/small_vector.hpp>
|
|
|
|
|
+
|
|
|
#include "shader_recompiler/frontend/ir/basic_block.h"
|
|
#include "shader_recompiler/frontend/ir/basic_block.h"
|
|
|
#include "shader_recompiler/frontend/ir/value.h"
|
|
#include "shader_recompiler/frontend/ir/value.h"
|
|
|
#include "shader_recompiler/ir_opt/passes.h"
|
|
#include "shader_recompiler/ir_opt/passes.h"
|
|
@@ -25,7 +29,26 @@ void DeadInstElimination(IR::Block* const block) {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+void DeletedPhiArgElimination(IR::Program& program, std::span<const IR::Block*> dead_blocks) {
|
|
|
|
|
+ for (IR::Block* const block : program.blocks) {
|
|
|
|
|
+ for (IR::Inst& phi : *block) {
|
|
|
|
|
+ if (!IR::IsPhi(phi)) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ for (size_t i = 0; i < phi.NumArgs(); ++i) {
|
|
|
|
|
+ if (std::ranges::find(dead_blocks, phi.PhiBlock(i)) == dead_blocks.end()) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ // Phi operand at this index is an unreachable block
|
|
|
|
|
+ phi.ErasePhiOperand(i);
|
|
|
|
|
+ --i;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
void DeadBranchElimination(IR::Program& program) {
|
|
void DeadBranchElimination(IR::Program& program) {
|
|
|
|
|
+ boost::container::small_vector<const IR::Block*, 3> dead_blocks;
|
|
|
const auto begin_it{program.syntax_list.begin()};
|
|
const auto begin_it{program.syntax_list.begin()};
|
|
|
for (auto node_it = begin_it; node_it != program.syntax_list.end(); ++node_it) {
|
|
for (auto node_it = begin_it; node_it != program.syntax_list.end(); ++node_it) {
|
|
|
if (node_it->type != IR::AbstractSyntaxNode::Type::If) {
|
|
if (node_it->type != IR::AbstractSyntaxNode::Type::If) {
|
|
@@ -55,6 +78,7 @@ void DeadBranchElimination(IR::Program& program) {
|
|
|
case IR::AbstractSyntaxNode::Type::Block: {
|
|
case IR::AbstractSyntaxNode::Type::Block: {
|
|
|
IR::Block* const block{node_it->data.block};
|
|
IR::Block* const block{node_it->data.block};
|
|
|
DeadInstElimination<false>(block);
|
|
DeadInstElimination<false>(block);
|
|
|
|
|
+ dead_blocks.push_back(block);
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
default:
|
|
default:
|
|
@@ -66,6 +90,9 @@ void DeadBranchElimination(IR::Program& program) {
|
|
|
// Account for loop increment
|
|
// Account for loop increment
|
|
|
--node_it;
|
|
--node_it;
|
|
|
}
|
|
}
|
|
|
|
|
+ if (!dead_blocks.empty()) {
|
|
|
|
|
+ DeletedPhiArgElimination(program, std::span(dead_blocks.data(), dead_blocks.size()));
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
} // namespace
|
|
} // namespace
|
|
|
|
|
|