shader: Add pools and rename files
This commit is contained in:
parent
be94ee88d2
commit
16cb00c521
30 changed files with 255 additions and 108 deletions
|
@ -14,7 +14,8 @@
|
|||
|
||||
namespace Shader::IR {
|
||||
|
||||
Block::Block(u32 begin, u32 end) : location_begin{begin}, location_end{end} {}
|
||||
Block::Block(ObjectPool<Inst>& inst_pool_, u32 begin, u32 end)
|
||||
: inst_pool{&inst_pool_}, location_begin{begin}, location_end{end} {}
|
||||
|
||||
Block::~Block() = default;
|
||||
|
||||
|
@ -24,7 +25,7 @@ void Block::AppendNewInst(Opcode op, std::initializer_list<Value> args) {
|
|||
|
||||
Block::iterator Block::PrependNewInst(iterator insertion_point, Opcode op,
|
||||
std::initializer_list<Value> args, u64 flags) {
|
||||
Inst* const inst{std::construct_at(instruction_alloc_pool.allocate(), op, flags)};
|
||||
Inst* const inst{inst_pool->Create(op, flags)};
|
||||
const auto result_it{instructions.insert(insertion_point, *inst)};
|
||||
|
||||
if (inst->NumArgs() != args.size()) {
|
||||
|
|
|
@ -10,9 +10,9 @@
|
|||
#include <vector>
|
||||
|
||||
#include <boost/intrusive/list.hpp>
|
||||
#include <boost/pool/pool_alloc.hpp>
|
||||
|
||||
#include "shader_recompiler/frontend/ir/microinstruction.h"
|
||||
#include "shader_recompiler/object_pool.h"
|
||||
|
||||
namespace Shader::IR {
|
||||
|
||||
|
@ -25,7 +25,7 @@ public:
|
|||
using reverse_iterator = InstructionList::reverse_iterator;
|
||||
using const_reverse_iterator = InstructionList::const_reverse_iterator;
|
||||
|
||||
explicit Block(u32 begin, u32 end);
|
||||
explicit Block(ObjectPool<Inst>& inst_pool_, u32 begin, u32 end);
|
||||
~Block();
|
||||
|
||||
Block(const Block&) = delete;
|
||||
|
@ -119,6 +119,8 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
/// Memory pool for instruction list
|
||||
ObjectPool<Inst>* inst_pool;
|
||||
/// Starting location of this block
|
||||
u32 location_begin;
|
||||
/// End location of this block
|
||||
|
@ -127,11 +129,6 @@ private:
|
|||
/// List of instructions in this block
|
||||
InstructionList instructions;
|
||||
|
||||
/// Memory pool for instruction list
|
||||
boost::fast_pool_allocator<Inst, boost::default_user_allocator_malloc_free,
|
||||
boost::details::pool::null_mutex>
|
||||
instruction_alloc_pool;
|
||||
|
||||
/// Block immediate predecessors
|
||||
std::vector<IR::Block*> imm_predecessors;
|
||||
};
|
||||
|
|
|
@ -4,22 +4,14 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <boost/container/small_vector.hpp>
|
||||
|
||||
#include "shader_recompiler/frontend/ir/basic_block.h"
|
||||
|
||||
namespace Shader::IR {
|
||||
|
||||
struct Function {
|
||||
struct InplaceDelete {
|
||||
void operator()(IR::Block* block) const noexcept {
|
||||
std::destroy_at(block);
|
||||
}
|
||||
};
|
||||
using UniqueBlock = std::unique_ptr<IR::Block, InplaceDelete>;
|
||||
|
||||
std::vector<UniqueBlock> blocks;
|
||||
boost::container::small_vector<Block*, 16> blocks;
|
||||
};
|
||||
|
||||
} // namespace Shader::IR
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
#include <boost/intrusive/list.hpp>
|
||||
|
||||
#include "common/common_types.h"
|
||||
#include "shader_recompiler/frontend/ir/opcode.h"
|
||||
#include "shader_recompiler/frontend/ir/opcodes.h"
|
||||
#include "shader_recompiler/frontend/ir/type.h"
|
||||
#include "shader_recompiler/frontend/ir/value.h"
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
#include <string_view>
|
||||
|
||||
#include "shader_recompiler/exception.h"
|
||||
#include "shader_recompiler/frontend/ir/opcode.h"
|
||||
#include "shader_recompiler/frontend/ir/opcodes.h"
|
||||
|
||||
namespace Shader::IR {
|
||||
namespace {
|
||||
|
@ -26,7 +26,7 @@ constexpr std::array META_TABLE{
|
|||
.type{type_token}, \
|
||||
.arg_types{__VA_ARGS__}, \
|
||||
},
|
||||
#include "opcode.inc"
|
||||
#include "opcodes.inc"
|
||||
#undef OPCODE
|
||||
};
|
||||
|
|
@ -14,7 +14,7 @@ namespace Shader::IR {
|
|||
|
||||
enum class Opcode {
|
||||
#define OPCODE(name, ...) name,
|
||||
#include "opcode.inc"
|
||||
#include "opcodes.inc"
|
||||
#undef OPCODE
|
||||
};
|
||||
|
38
src/shader_recompiler/frontend/ir/program.cpp
Normal file
38
src/shader_recompiler/frontend/ir/program.cpp
Normal file
|
@ -0,0 +1,38 @@
|
|||
// Copyright 2021 yuzu Emulator Project
|
||||
// Licensed under GPLv2 or any later version
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
#include <fmt/format.h>
|
||||
|
||||
#include "shader_recompiler/frontend/ir/function.h"
|
||||
#include "shader_recompiler/frontend/ir/program.h"
|
||||
|
||||
namespace Shader::IR {
|
||||
|
||||
std::string DumpProgram(const Program& program) {
|
||||
size_t index{0};
|
||||
std::map<const IR::Inst*, size_t> inst_to_index;
|
||||
std::map<const IR::Block*, size_t> block_to_index;
|
||||
|
||||
for (const IR::Function& function : program.functions) {
|
||||
for (const IR::Block* const block : function.blocks) {
|
||||
block_to_index.emplace(block, index);
|
||||
++index;
|
||||
}
|
||||
}
|
||||
std::string ret;
|
||||
for (const IR::Function& function : program.functions) {
|
||||
ret += fmt::format("Function\n");
|
||||
for (const auto& block : function.blocks) {
|
||||
ret += IR::DumpBlock(*block, block_to_index, inst_to_index, index) + '\n';
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
} // namespace Shader::IR
|
21
src/shader_recompiler/frontend/ir/program.h
Normal file
21
src/shader_recompiler/frontend/ir/program.h
Normal file
|
@ -0,0 +1,21 @@
|
|||
// Copyright 2021 yuzu Emulator Project
|
||||
// Licensed under GPLv2 or any later version
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <boost/container/small_vector.hpp>
|
||||
|
||||
#include "shader_recompiler/frontend/ir/function.h"
|
||||
|
||||
namespace Shader::IR {
|
||||
|
||||
struct Program {
|
||||
boost::container::small_vector<Function, 1> functions;
|
||||
};
|
||||
|
||||
[[nodiscard]] std::string DumpProgram(const Program& program);
|
||||
|
||||
} // namespace Shader::IR
|
|
@ -3,7 +3,7 @@
|
|||
// Refer to the license.txt file included.
|
||||
|
||||
#include "shader_recompiler/frontend/ir/microinstruction.h"
|
||||
#include "shader_recompiler/frontend/ir/opcode.h"
|
||||
#include "shader_recompiler/frontend/ir/opcodes.h"
|
||||
#include "shader_recompiler/frontend/ir/value.h"
|
||||
|
||||
namespace Shader::IR {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue