summaryrefslogtreecommitdiff
path: root/src/shader_recompiler/frontend/ir
diff options
context:
space:
mode:
Diffstat (limited to 'src/shader_recompiler/frontend/ir')
-rw-r--r--src/shader_recompiler/frontend/ir/basic_block.cpp5
-rw-r--r--src/shader_recompiler/frontend/ir/basic_block.h11
-rw-r--r--src/shader_recompiler/frontend/ir/function.h12
-rw-r--r--src/shader_recompiler/frontend/ir/microinstruction.h2
-rw-r--r--src/shader_recompiler/frontend/ir/opcodes.cpp (renamed from src/shader_recompiler/frontend/ir/opcode.cpp)4
-rw-r--r--src/shader_recompiler/frontend/ir/opcodes.h (renamed from src/shader_recompiler/frontend/ir/opcode.h)2
-rw-r--r--src/shader_recompiler/frontend/ir/opcodes.inc (renamed from src/shader_recompiler/frontend/ir/opcode.inc)0
-rw-r--r--src/shader_recompiler/frontend/ir/program.cpp38
-rw-r--r--src/shader_recompiler/frontend/ir/program.h21
-rw-r--r--src/shader_recompiler/frontend/ir/value.cpp2
10 files changed, 73 insertions, 24 deletions
diff --git a/src/shader_recompiler/frontend/ir/basic_block.cpp b/src/shader_recompiler/frontend/ir/basic_block.cpp
index 249251dd0..1a5d82135 100644
--- a/src/shader_recompiler/frontend/ir/basic_block.cpp
+++ b/src/shader_recompiler/frontend/ir/basic_block.cpp
@@ -14,7 +14,8 @@
14 14
15namespace Shader::IR { 15namespace Shader::IR {
16 16
17Block::Block(u32 begin, u32 end) : location_begin{begin}, location_end{end} {} 17Block::Block(ObjectPool<Inst>& inst_pool_, u32 begin, u32 end)
18 : inst_pool{&inst_pool_}, location_begin{begin}, location_end{end} {}
18 19
19Block::~Block() = default; 20Block::~Block() = default;
20 21
@@ -24,7 +25,7 @@ void Block::AppendNewInst(Opcode op, std::initializer_list<Value> args) {
24 25
25Block::iterator Block::PrependNewInst(iterator insertion_point, Opcode op, 26Block::iterator Block::PrependNewInst(iterator insertion_point, Opcode op,
26 std::initializer_list<Value> args, u64 flags) { 27 std::initializer_list<Value> args, u64 flags) {
27 Inst* const inst{std::construct_at(instruction_alloc_pool.allocate(), op, flags)}; 28 Inst* const inst{inst_pool->Create(op, flags)};
28 const auto result_it{instructions.insert(insertion_point, *inst)}; 29 const auto result_it{instructions.insert(insertion_point, *inst)};
29 30
30 if (inst->NumArgs() != args.size()) { 31 if (inst->NumArgs() != args.size()) {
diff --git a/src/shader_recompiler/frontend/ir/basic_block.h b/src/shader_recompiler/frontend/ir/basic_block.h
index ec4a41cb1..ec3ad6263 100644
--- a/src/shader_recompiler/frontend/ir/basic_block.h
+++ b/src/shader_recompiler/frontend/ir/basic_block.h
@@ -10,9 +10,9 @@
10#include <vector> 10#include <vector>
11 11
12#include <boost/intrusive/list.hpp> 12#include <boost/intrusive/list.hpp>
13#include <boost/pool/pool_alloc.hpp>
14 13
15#include "shader_recompiler/frontend/ir/microinstruction.h" 14#include "shader_recompiler/frontend/ir/microinstruction.h"
15#include "shader_recompiler/object_pool.h"
16 16
17namespace Shader::IR { 17namespace Shader::IR {
18 18
@@ -25,7 +25,7 @@ public:
25 using reverse_iterator = InstructionList::reverse_iterator; 25 using reverse_iterator = InstructionList::reverse_iterator;
26 using const_reverse_iterator = InstructionList::const_reverse_iterator; 26 using const_reverse_iterator = InstructionList::const_reverse_iterator;
27 27
28 explicit Block(u32 begin, u32 end); 28 explicit Block(ObjectPool<Inst>& inst_pool_, u32 begin, u32 end);
29 ~Block(); 29 ~Block();
30 30
31 Block(const Block&) = delete; 31 Block(const Block&) = delete;
@@ -119,6 +119,8 @@ public:
119 } 119 }
120 120
121private: 121private:
122 /// Memory pool for instruction list
123 ObjectPool<Inst>* inst_pool;
122 /// Starting location of this block 124 /// Starting location of this block
123 u32 location_begin; 125 u32 location_begin;
124 /// End location of this block 126 /// End location of this block
@@ -127,11 +129,6 @@ private:
127 /// List of instructions in this block 129 /// List of instructions in this block
128 InstructionList instructions; 130 InstructionList instructions;
129 131
130 /// Memory pool for instruction list
131 boost::fast_pool_allocator<Inst, boost::default_user_allocator_malloc_free,
132 boost::details::pool::null_mutex>
133 instruction_alloc_pool;
134
135 /// Block immediate predecessors 132 /// Block immediate predecessors
136 std::vector<IR::Block*> imm_predecessors; 133 std::vector<IR::Block*> imm_predecessors;
137}; 134};
diff --git a/src/shader_recompiler/frontend/ir/function.h b/src/shader_recompiler/frontend/ir/function.h
index 2d4dc5b98..bba7d1d39 100644
--- a/src/shader_recompiler/frontend/ir/function.h
+++ b/src/shader_recompiler/frontend/ir/function.h
@@ -4,22 +4,14 @@
4 4
5#pragma once 5#pragma once
6 6
7#include <memory> 7#include <boost/container/small_vector.hpp>
8#include <vector>
9 8
10#include "shader_recompiler/frontend/ir/basic_block.h" 9#include "shader_recompiler/frontend/ir/basic_block.h"
11 10
12namespace Shader::IR { 11namespace Shader::IR {
13 12
14struct Function { 13struct Function {
15 struct InplaceDelete { 14 boost::container::small_vector<Block*, 16> blocks;
16 void operator()(IR::Block* block) const noexcept {
17 std::destroy_at(block);
18 }
19 };
20 using UniqueBlock = std::unique_ptr<IR::Block, InplaceDelete>;
21
22 std::vector<UniqueBlock> blocks;
23}; 15};
24 16
25} // namespace Shader::IR 17} // namespace Shader::IR
diff --git a/src/shader_recompiler/frontend/ir/microinstruction.h b/src/shader_recompiler/frontend/ir/microinstruction.h
index 22101c9e2..80baffb2e 100644
--- a/src/shader_recompiler/frontend/ir/microinstruction.h
+++ b/src/shader_recompiler/frontend/ir/microinstruction.h
@@ -13,7 +13,7 @@
13#include <boost/intrusive/list.hpp> 13#include <boost/intrusive/list.hpp>
14 14
15#include "common/common_types.h" 15#include "common/common_types.h"
16#include "shader_recompiler/frontend/ir/opcode.h" 16#include "shader_recompiler/frontend/ir/opcodes.h"
17#include "shader_recompiler/frontend/ir/type.h" 17#include "shader_recompiler/frontend/ir/type.h"
18#include "shader_recompiler/frontend/ir/value.h" 18#include "shader_recompiler/frontend/ir/value.h"
19 19
diff --git a/src/shader_recompiler/frontend/ir/opcode.cpp b/src/shader_recompiler/frontend/ir/opcodes.cpp
index 65d074029..1f188411a 100644
--- a/src/shader_recompiler/frontend/ir/opcode.cpp
+++ b/src/shader_recompiler/frontend/ir/opcodes.cpp
@@ -7,7 +7,7 @@
7#include <string_view> 7#include <string_view>
8 8
9#include "shader_recompiler/exception.h" 9#include "shader_recompiler/exception.h"
10#include "shader_recompiler/frontend/ir/opcode.h" 10#include "shader_recompiler/frontend/ir/opcodes.h"
11 11
12namespace Shader::IR { 12namespace Shader::IR {
13namespace { 13namespace {
@@ -26,7 +26,7 @@ constexpr std::array META_TABLE{
26 .type{type_token}, \ 26 .type{type_token}, \
27 .arg_types{__VA_ARGS__}, \ 27 .arg_types{__VA_ARGS__}, \
28 }, 28 },
29#include "opcode.inc" 29#include "opcodes.inc"
30#undef OPCODE 30#undef OPCODE
31}; 31};
32 32
diff --git a/src/shader_recompiler/frontend/ir/opcode.h b/src/shader_recompiler/frontend/ir/opcodes.h
index 1f4440379..999fb2e77 100644
--- a/src/shader_recompiler/frontend/ir/opcode.h
+++ b/src/shader_recompiler/frontend/ir/opcodes.h
@@ -14,7 +14,7 @@ namespace Shader::IR {
14 14
15enum class Opcode { 15enum class Opcode {
16#define OPCODE(name, ...) name, 16#define OPCODE(name, ...) name,
17#include "opcode.inc" 17#include "opcodes.inc"
18#undef OPCODE 18#undef OPCODE
19}; 19};
20 20
diff --git a/src/shader_recompiler/frontend/ir/opcode.inc b/src/shader_recompiler/frontend/ir/opcodes.inc
index 6eb105d92..6eb105d92 100644
--- a/src/shader_recompiler/frontend/ir/opcode.inc
+++ b/src/shader_recompiler/frontend/ir/opcodes.inc
diff --git a/src/shader_recompiler/frontend/ir/program.cpp b/src/shader_recompiler/frontend/ir/program.cpp
new file mode 100644
index 000000000..0ce99ef2a
--- /dev/null
+++ b/src/shader_recompiler/frontend/ir/program.cpp
@@ -0,0 +1,38 @@
1// Copyright 2021 yuzu Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include <map>
8#include <string>
9
10#include <fmt/format.h>
11
12#include "shader_recompiler/frontend/ir/function.h"
13#include "shader_recompiler/frontend/ir/program.h"
14
15namespace Shader::IR {
16
17std::string DumpProgram(const Program& program) {
18 size_t index{0};
19 std::map<const IR::Inst*, size_t> inst_to_index;
20 std::map<const IR::Block*, size_t> block_to_index;
21
22 for (const IR::Function& function : program.functions) {
23 for (const IR::Block* const block : function.blocks) {
24 block_to_index.emplace(block, index);
25 ++index;
26 }
27 }
28 std::string ret;
29 for (const IR::Function& function : program.functions) {
30 ret += fmt::format("Function\n");
31 for (const auto& block : function.blocks) {
32 ret += IR::DumpBlock(*block, block_to_index, inst_to_index, index) + '\n';
33 }
34 }
35 return ret;
36}
37
38} // namespace Shader::IR \ No newline at end of file
diff --git a/src/shader_recompiler/frontend/ir/program.h b/src/shader_recompiler/frontend/ir/program.h
new file mode 100644
index 000000000..efaf1aa1e
--- /dev/null
+++ b/src/shader_recompiler/frontend/ir/program.h
@@ -0,0 +1,21 @@
1// Copyright 2021 yuzu Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include <string>
8
9#include <boost/container/small_vector.hpp>
10
11#include "shader_recompiler/frontend/ir/function.h"
12
13namespace Shader::IR {
14
15struct Program {
16 boost::container::small_vector<Function, 1> functions;
17};
18
19[[nodiscard]] std::string DumpProgram(const Program& program);
20
21} // namespace Shader::IR
diff --git a/src/shader_recompiler/frontend/ir/value.cpp b/src/shader_recompiler/frontend/ir/value.cpp
index 93ff8ccf1..9ea61813b 100644
--- a/src/shader_recompiler/frontend/ir/value.cpp
+++ b/src/shader_recompiler/frontend/ir/value.cpp
@@ -3,7 +3,7 @@
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5#include "shader_recompiler/frontend/ir/microinstruction.h" 5#include "shader_recompiler/frontend/ir/microinstruction.h"
6#include "shader_recompiler/frontend/ir/opcode.h" 6#include "shader_recompiler/frontend/ir/opcodes.h"
7#include "shader_recompiler/frontend/ir/value.h" 7#include "shader_recompiler/frontend/ir/value.h"
8 8
9namespace Shader::IR { 9namespace Shader::IR {