Compare commits

..

3 Commits

Author SHA1 Message Date
Billy Laws
dd862dff66 Include <bit> header when std::count{r,l}_zero is used
Needed for compilation with older libc++ releases
2022-03-22 21:11:24 +00:00
Narr the Reg
f83cd2e8b9 Merge pull request #8067 from ameerj/qt-browser-include
qt_web_browser: Add missing includes
2022-03-21 21:33:09 -06:00
ameerj
b3cfccdb80 qt_web_browser: Add missing includes 2022-03-21 22:42:14 -04:00
7 changed files with 17 additions and 99 deletions

View File

@@ -2,6 +2,8 @@
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#include <bit>
#include "shader_recompiler/backend/spirv/emit_spirv.h"
#include "shader_recompiler/backend/spirv/emit_spirv_instructions.h"
#include "shader_recompiler/backend/spirv/spirv_emit_context.h"

View File

@@ -2,6 +2,7 @@
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#include <bit>
#include <tuple>
#include <utility>

View File

@@ -4,6 +4,7 @@
#include <algorithm>
#include <array>
#include <bit>
#include <climits>
#include <boost/container/static_vector.hpp>

View File

@@ -326,11 +326,6 @@ void Inst::AddPhiOperand(Block* predecessor, const Value& value) {
phi_args.emplace_back(predecessor, value);
}
void Inst::ErasePhiOperand(size_t index) {
const auto operand_it{phi_args.begin() + static_cast<ptrdiff_t>(index)};
phi_args.erase(operand_it);
}
void Inst::OrderPhiArgs() {
if (op != Opcode::Phi) {
throw LogicError("{} is not a Phi instruction", op);

View File

@@ -179,13 +179,9 @@ public:
/// Get a pointer to the block of a phi argument.
[[nodiscard]] Block* PhiBlock(size_t index) const;
/// Add phi operand to a phi instruction.
void AddPhiOperand(Block* predecessor, const Value& value);
// Erase the phi operand at the given index.
void ErasePhiOperand(size_t index);
/// Orders the Phi arguments from farthest away to nearest.
void OrderPhiArgs();

View File

@@ -2,104 +2,24 @@
// Licensed under GPLv2 or any later version
// 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/value.h"
#include "shader_recompiler/ir_opt/passes.h"
namespace Shader::Optimization {
namespace {
template <bool TEST_USES>
void DeadInstElimination(IR::Block* const block) {
// We iterate over the instructions in reverse order.
// This is because removing an instruction reduces the number of uses for earlier instructions.
auto it{block->end()};
while (it != block->begin()) {
--it;
if constexpr (TEST_USES) {
if (it->HasUses() || it->MayHaveSideEffects()) {
continue;
}
}
it->Invalidate();
it = block->Instructions().erase(it);
}
}
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) {
boost::container::small_vector<const IR::Block*, 3> dead_blocks;
const auto begin_it{program.syntax_list.begin()};
for (auto node_it = begin_it; node_it != program.syntax_list.end(); ++node_it) {
if (node_it->type != IR::AbstractSyntaxNode::Type::If) {
continue;
}
IR::Inst* const cond_ref{node_it->data.if_node.cond.Inst()};
const IR::U1 cond{cond_ref->Arg(0)};
if (!cond.IsImmediate()) {
continue;
}
if (cond.U1()) {
continue;
}
// False immediate condition. Remove condition ref, erase the entire branch.
cond_ref->Invalidate();
// Account for nested if-statements within the if(false) branch
u32 nested_ifs{1u};
while (node_it->type != IR::AbstractSyntaxNode::Type::EndIf || nested_ifs > 0) {
node_it = program.syntax_list.erase(node_it);
switch (node_it->type) {
case IR::AbstractSyntaxNode::Type::If:
++nested_ifs;
break;
case IR::AbstractSyntaxNode::Type::EndIf:
--nested_ifs;
break;
case IR::AbstractSyntaxNode::Type::Block: {
IR::Block* const block{node_it->data.block};
DeadInstElimination<false>(block);
dead_blocks.push_back(block);
break;
}
default:
break;
}
}
// Erase EndIf node of the if(false) branch
node_it = program.syntax_list.erase(node_it);
// Account for loop increment
--node_it;
}
if (!dead_blocks.empty()) {
DeletedPhiArgElimination(program, std::span(dead_blocks.data(), dead_blocks.size()));
}
}
} // namespace
void DeadCodeEliminationPass(IR::Program& program) {
DeadBranchElimination(program);
// We iterate over the instructions in reverse order.
// This is because removing an instruction reduces the number of uses for earlier instructions.
for (IR::Block* const block : program.post_order_blocks) {
DeadInstElimination<true>(block);
auto it{block->end()};
while (it != block->begin()) {
--it;
if (!it->HasUses() && !it->MayHaveSideEffects()) {
it->Invalidate();
it = block->Instructions().erase(it);
}
}
}
}

View File

@@ -11,6 +11,9 @@
#include <QWebEngineScriptCollection>
#include <QWebEngineSettings>
#include <QWebEngineUrlScheme>
#include "core/hid/input_interpreter.h"
#include "yuzu/applets/qt_web_browser_scripts.h"
#endif
#include "common/fs/path_util.h"