summaryrefslogtreecommitdiff
path: root/src/shader_recompiler/frontend/ir/basic_block.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/shader_recompiler/frontend/ir/basic_block.h')
-rw-r--r--src/shader_recompiler/frontend/ir/basic_block.h134
1 files changed, 134 insertions, 0 deletions
diff --git a/src/shader_recompiler/frontend/ir/basic_block.h b/src/shader_recompiler/frontend/ir/basic_block.h
new file mode 100644
index 000000000..3ed2eb957
--- /dev/null
+++ b/src/shader_recompiler/frontend/ir/basic_block.h
@@ -0,0 +1,134 @@
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 <initializer_list>
8#include <map>
9
10#include <boost/intrusive/list.hpp>
11#include <boost/pool/pool_alloc.hpp>
12
13#include "shader_recompiler/frontend/ir/microinstruction.h"
14
15namespace Shader::IR {
16
17class Block {
18public:
19 using InstructionList = boost::intrusive::list<Inst>;
20 using size_type = InstructionList::size_type;
21 using iterator = InstructionList::iterator;
22 using const_iterator = InstructionList::const_iterator;
23 using reverse_iterator = InstructionList::reverse_iterator;
24 using const_reverse_iterator = InstructionList::const_reverse_iterator;
25
26 explicit Block(u32 begin, u32 end);
27 ~Block();
28
29 Block(const Block&) = delete;
30 Block& operator=(const Block&) = delete;
31
32 Block(Block&&) = default;
33 Block& operator=(Block&&) = default;
34
35 /// Appends a new instruction to the end of this basic block.
36 void AppendNewInst(Opcode op, std::initializer_list<Value> args);
37
38 /// Prepends a new instruction to this basic block before the insertion point.
39 iterator PrependNewInst(iterator insertion_point, Opcode op, std::initializer_list<Value> args);
40
41 /// Gets the starting location of this basic block.
42 [[nodiscard]] u32 LocationBegin() const noexcept;
43 /// Gets the end location for this basic block.
44 [[nodiscard]] u32 LocationEnd() const noexcept;
45
46 /// Gets a mutable reference to the instruction list for this basic block.
47 InstructionList& Instructions() noexcept;
48 /// Gets an immutable reference to the instruction list for this basic block.
49 const InstructionList& Instructions() const noexcept;
50
51 [[nodiscard]] bool empty() const {
52 return instructions.empty();
53 }
54 [[nodiscard]] size_type size() const {
55 return instructions.size();
56 }
57
58 [[nodiscard]] Inst& front() {
59 return instructions.front();
60 }
61 [[nodiscard]] const Inst& front() const {
62 return instructions.front();
63 }
64
65 [[nodiscard]] Inst& back() {
66 return instructions.back();
67 }
68 [[nodiscard]] const Inst& back() const {
69 return instructions.back();
70 }
71
72 [[nodiscard]] iterator begin() {
73 return instructions.begin();
74 }
75 [[nodiscard]] const_iterator begin() const {
76 return instructions.begin();
77 }
78 [[nodiscard]] iterator end() {
79 return instructions.end();
80 }
81 [[nodiscard]] const_iterator end() const {
82 return instructions.end();
83 }
84
85 [[nodiscard]] reverse_iterator rbegin() {
86 return instructions.rbegin();
87 }
88 [[nodiscard]] const_reverse_iterator rbegin() const {
89 return instructions.rbegin();
90 }
91 [[nodiscard]] reverse_iterator rend() {
92 return instructions.rend();
93 }
94 [[nodiscard]] const_reverse_iterator rend() const {
95 return instructions.rend();
96 }
97
98 [[nodiscard]] const_iterator cbegin() const {
99 return instructions.cbegin();
100 }
101 [[nodiscard]] const_iterator cend() const {
102 return instructions.cend();
103 }
104
105 [[nodiscard]] const_reverse_iterator crbegin() const {
106 return instructions.crbegin();
107 }
108 [[nodiscard]] const_reverse_iterator crend() const {
109 return instructions.crend();
110 }
111
112private:
113 /// Starting location of this block
114 u32 location_begin;
115 /// End location of this block
116 u32 location_end;
117
118 /// List of instructions in this block.
119 InstructionList instructions;
120
121 /// Memory pool for instruction list
122 boost::fast_pool_allocator<Inst, boost::default_user_allocator_malloc_free,
123 boost::details::pool::null_mutex>
124 instruction_alloc_pool;
125};
126
127[[nodiscard]] std::string DumpBlock(const Block& block);
128
129[[nodiscard]] std::string DumpBlock(const Block& block,
130 const std::map<const Block*, size_t>& block_to_index,
131 std::map<const Inst*, size_t>& inst_to_index,
132 size_t& inst_index);
133
134} // namespace Shader::IR