summaryrefslogtreecommitdiff
path: root/src/shader_recompiler/frontend/ir/microinstruction.h
diff options
context:
space:
mode:
authorGravatar ReinUsesLisp2021-02-06 02:38:22 -0300
committerGravatar ameerj2021-07-22 21:51:21 -0400
commitda8096e6e35af250dcc56a1af76b8a211df63a90 (patch)
tree5bac3a389afddd1ba23a9fb2ea410c077c28f3b8 /src/shader_recompiler/frontend/ir/microinstruction.h
parentshader: Add pools and rename files (diff)
downloadyuzu-da8096e6e35af250dcc56a1af76b8a211df63a90.tar.gz
yuzu-da8096e6e35af250dcc56a1af76b8a211df63a90.tar.xz
yuzu-da8096e6e35af250dcc56a1af76b8a211df63a90.zip
shader: Properly store phi on Inst
Diffstat (limited to 'src/shader_recompiler/frontend/ir/microinstruction.h')
-rw-r--r--src/shader_recompiler/frontend/ir/microinstruction.h37
1 files changed, 26 insertions, 11 deletions
diff --git a/src/shader_recompiler/frontend/ir/microinstruction.h b/src/shader_recompiler/frontend/ir/microinstruction.h
index 80baffb2e..ddf0f90a9 100644
--- a/src/shader_recompiler/frontend/ir/microinstruction.h
+++ b/src/shader_recompiler/frontend/ir/microinstruction.h
@@ -6,8 +6,8 @@
6 6
7#include <array> 7#include <array>
8#include <cstring> 8#include <cstring>
9#include <span>
10#include <type_traits> 9#include <type_traits>
10#include <utility>
11#include <vector> 11#include <vector>
12 12
13#include <boost/intrusive/list.hpp> 13#include <boost/intrusive/list.hpp>
@@ -25,7 +25,14 @@ constexpr size_t MAX_ARG_COUNT = 4;
25 25
26class Inst : public boost::intrusive::list_base_hook<> { 26class Inst : public boost::intrusive::list_base_hook<> {
27public: 27public:
28 explicit Inst(Opcode op_, u64 flags_) noexcept : op{op_}, flags{flags_} {} 28 explicit Inst(Opcode op_, u64 flags_) noexcept;
29 ~Inst();
30
31 Inst& operator=(const Inst&) = delete;
32 Inst(const Inst&) = delete;
33
34 Inst& operator=(Inst&&) = delete;
35 Inst(Inst&&) = delete;
29 36
30 /// Get the number of uses this instruction has. 37 /// Get the number of uses this instruction has.
31 [[nodiscard]] int UseCount() const noexcept { 38 [[nodiscard]] int UseCount() const noexcept {
@@ -50,26 +57,26 @@ public:
50 [[nodiscard]] bool IsPseudoInstruction() const noexcept; 57 [[nodiscard]] bool IsPseudoInstruction() const noexcept;
51 58
52 /// Determines if all arguments of this instruction are immediates. 59 /// Determines if all arguments of this instruction are immediates.
53 [[nodiscard]] bool AreAllArgsImmediates() const noexcept; 60 [[nodiscard]] bool AreAllArgsImmediates() const;
54 61
55 /// Determines if there is a pseudo-operation associated with this instruction. 62 /// Determines if there is a pseudo-operation associated with this instruction.
56 [[nodiscard]] bool HasAssociatedPseudoOperation() const noexcept; 63 [[nodiscard]] bool HasAssociatedPseudoOperation() const noexcept;
57 /// Gets a pseudo-operation associated with this instruction 64 /// Gets a pseudo-operation associated with this instruction
58 [[nodiscard]] Inst* GetAssociatedPseudoOperation(IR::Opcode opcode); 65 [[nodiscard]] Inst* GetAssociatedPseudoOperation(IR::Opcode opcode);
59 66
60 /// Get the number of arguments this instruction has.
61 [[nodiscard]] size_t NumArgs() const;
62
63 /// Get the type this instruction returns. 67 /// Get the type this instruction returns.
64 [[nodiscard]] IR::Type Type() const; 68 [[nodiscard]] IR::Type Type() const;
65 69
70 /// Get the number of arguments this instruction has.
71 [[nodiscard]] size_t NumArgs() const;
72
66 /// Get the value of a given argument index. 73 /// Get the value of a given argument index.
67 [[nodiscard]] Value Arg(size_t index) const; 74 [[nodiscard]] Value Arg(size_t index) const;
68 /// Set the value of a given argument index. 75 /// Set the value of a given argument index.
69 void SetArg(size_t index, Value value); 76 void SetArg(size_t index, Value value);
70 77
71 /// Get an immutable span to the phi operands. 78 /// Get a pointer to the block of a phi argument.
72 [[nodiscard]] std::span<const std::pair<Block*, Value>> PhiOperands() const noexcept; 79 [[nodiscard]] Block* PhiBlock(size_t index) const;
73 /// Add phi operand to a phi instruction. 80 /// Add phi operand to a phi instruction.
74 void AddPhiOperand(Block* predecessor, const Value& value); 81 void AddPhiOperand(Block* predecessor, const Value& value);
75 82
@@ -87,18 +94,26 @@ public:
87 } 94 }
88 95
89private: 96private:
97 struct NonTriviallyDummy {
98 NonTriviallyDummy() noexcept {}
99 };
100
90 void Use(const Value& value); 101 void Use(const Value& value);
91 void UndoUse(const Value& value); 102 void UndoUse(const Value& value);
92 103
93 IR::Opcode op{}; 104 IR::Opcode op{};
94 int use_count{}; 105 int use_count{};
95 std::array<Value, MAX_ARG_COUNT> args{}; 106 u64 flags{};
107 union {
108 NonTriviallyDummy dummy{};
109 std::array<Value, MAX_ARG_COUNT> args;
110 std::vector<std::pair<Block*, Value>> phi_args;
111 };
96 Inst* zero_inst{}; 112 Inst* zero_inst{};
97 Inst* sign_inst{}; 113 Inst* sign_inst{};
98 Inst* carry_inst{}; 114 Inst* carry_inst{};
99 Inst* overflow_inst{}; 115 Inst* overflow_inst{};
100 std::vector<std::pair<Block*, Value>> phi_operands;
101 u64 flags{};
102}; 116};
117static_assert(sizeof(Inst) <= 128, "Inst size unintentionally increased its size");
103 118
104} // namespace Shader::IR 119} // namespace Shader::IR