summaryrefslogtreecommitdiff
path: root/src/shader_recompiler/frontend/ir/microinstruction.h
diff options
context:
space:
mode:
authorGravatar ReinUsesLisp2021-04-21 00:35:47 -0300
committerGravatar ameerj2021-07-22 21:51:28 -0400
commit050e81500c002f304d581f28700de549b828a2bc (patch)
tree906868122c08a0771987e6953c096476c0ebc277 /src/shader_recompiler/frontend/ir/microinstruction.h
parentshader: Move siblings check to a separate function and comment them out (diff)
downloadyuzu-050e81500c002f304d581f28700de549b828a2bc.tar.gz
yuzu-050e81500c002f304d581f28700de549b828a2bc.tar.xz
yuzu-050e81500c002f304d581f28700de549b828a2bc.zip
shader: Move microinstruction header to the value header
Diffstat (limited to 'src/shader_recompiler/frontend/ir/microinstruction.h')
-rw-r--r--src/shader_recompiler/frontend/ir/microinstruction.h162
1 files changed, 0 insertions, 162 deletions
diff --git a/src/shader_recompiler/frontend/ir/microinstruction.h b/src/shader_recompiler/frontend/ir/microinstruction.h
deleted file mode 100644
index ea55fc29c..000000000
--- a/src/shader_recompiler/frontend/ir/microinstruction.h
+++ /dev/null
@@ -1,162 +0,0 @@
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 <array>
8#include <cstring>
9#include <type_traits>
10#include <utility>
11#include <vector>
12
13#include <boost/container/small_vector.hpp>
14#include <boost/intrusive/list.hpp>
15
16#include "common/bit_cast.h"
17#include "common/common_types.h"
18#include "shader_recompiler/frontend/ir/opcodes.h"
19#include "shader_recompiler/frontend/ir/type.h"
20#include "shader_recompiler/frontend/ir/value.h"
21
22namespace Shader::IR {
23
24class Block;
25
26struct AssociatedInsts;
27
28class Inst : public boost::intrusive::list_base_hook<> {
29public:
30 explicit Inst(Opcode op_, u32 flags_) noexcept;
31 ~Inst();
32
33 Inst& operator=(const Inst&) = delete;
34 Inst(const Inst&) = delete;
35
36 Inst& operator=(Inst&&) = delete;
37 Inst(Inst&&) = delete;
38
39 /// Get the number of uses this instruction has.
40 [[nodiscard]] int UseCount() const noexcept {
41 return use_count;
42 }
43
44 /// Determines whether this instruction has uses or not.
45 [[nodiscard]] bool HasUses() const noexcept {
46 return use_count > 0;
47 }
48
49 /// Get the opcode this microinstruction represents.
50 [[nodiscard]] IR::Opcode GetOpcode() const noexcept {
51 return op;
52 }
53
54 /// Determines if there is a pseudo-operation associated with this instruction.
55 [[nodiscard]] bool HasAssociatedPseudoOperation() const noexcept {
56 return associated_insts != nullptr;
57 }
58
59 /// Determines whether or not this instruction may have side effects.
60 [[nodiscard]] bool MayHaveSideEffects() const noexcept;
61
62 /// Determines whether or not this instruction is a pseudo-instruction.
63 /// Pseudo-instructions depend on their parent instructions for their semantics.
64 [[nodiscard]] bool IsPseudoInstruction() const noexcept;
65
66 /// Determines if all arguments of this instruction are immediates.
67 [[nodiscard]] bool AreAllArgsImmediates() const;
68
69 /// Gets a pseudo-operation associated with this instruction
70 [[nodiscard]] Inst* GetAssociatedPseudoOperation(IR::Opcode opcode);
71
72 /// Get the type this instruction returns.
73 [[nodiscard]] IR::Type Type() const;
74
75 /// Get the number of arguments this instruction has.
76 [[nodiscard]] size_t NumArgs() const {
77 return op == Opcode::Phi ? phi_args.size() : NumArgsOf(op);
78 }
79
80 /// Get the value of a given argument index.
81 [[nodiscard]] Value Arg(size_t index) const noexcept {
82 if (op == Opcode::Phi) {
83 return phi_args[index].second;
84 } else {
85 return args[index];
86 }
87 }
88
89 /// Set the value of a given argument index.
90 void SetArg(size_t index, Value value);
91
92 /// Get a pointer to the block of a phi argument.
93 [[nodiscard]] Block* PhiBlock(size_t index) const;
94 /// Add phi operand to a phi instruction.
95 void AddPhiOperand(Block* predecessor, const Value& value);
96
97 void Invalidate();
98 void ClearArgs();
99
100 void ReplaceUsesWith(Value replacement);
101
102 void ReplaceOpcode(IR::Opcode opcode);
103
104 template <typename FlagsType>
105 requires(sizeof(FlagsType) <= sizeof(u32) && std::is_trivially_copyable_v<FlagsType>)
106 [[nodiscard]] FlagsType Flags() const noexcept {
107 FlagsType ret;
108 std::memcpy(reinterpret_cast<char*>(&ret), &flags, sizeof(ret));
109 return ret;
110 }
111
112 template <typename FlagsType>
113 requires(sizeof(FlagsType) <= sizeof(u32) && std::is_trivially_copyable_v<FlagsType>)
114 [[nodiscard]] void SetFlags(FlagsType value) noexcept {
115 std::memcpy(&flags, &value, sizeof(value));
116 }
117
118 /// Intrusively store the host definition of this instruction.
119 template <typename DefinitionType>
120 void SetDefinition(DefinitionType def) {
121 definition = Common::BitCast<u32>(def);
122 }
123
124 /// Return the intrusively stored host definition of this instruction.
125 template <typename DefinitionType>
126 [[nodiscard]] DefinitionType Definition() const noexcept {
127 return Common::BitCast<DefinitionType>(definition);
128 }
129
130private:
131 struct NonTriviallyDummy {
132 NonTriviallyDummy() noexcept {}
133 };
134
135 void Use(const Value& value);
136 void UndoUse(const Value& value);
137
138 IR::Opcode op{};
139 int use_count{};
140 u32 flags{};
141 u32 definition{};
142 union {
143 NonTriviallyDummy dummy{};
144 boost::container::small_vector<std::pair<Block*, Value>, 2> phi_args;
145 std::array<Value, 5> args;
146 };
147 std::unique_ptr<AssociatedInsts> associated_insts;
148};
149static_assert(sizeof(Inst) <= 128, "Inst size unintentionally increased");
150
151struct AssociatedInsts {
152 union {
153 Inst* in_bounds_inst;
154 Inst* sparse_inst;
155 Inst* zero_inst{};
156 };
157 Inst* sign_inst{};
158 Inst* carry_inst{};
159 Inst* overflow_inst{};
160};
161
162} // namespace Shader::IR