summaryrefslogtreecommitdiff
path: root/src/shader_recompiler/frontend/ir/microinstruction.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/shader_recompiler/frontend/ir/microinstruction.h')
-rw-r--r--src/shader_recompiler/frontend/ir/microinstruction.h82
1 files changed, 82 insertions, 0 deletions
diff --git a/src/shader_recompiler/frontend/ir/microinstruction.h b/src/shader_recompiler/frontend/ir/microinstruction.h
new file mode 100644
index 000000000..43460b950
--- /dev/null
+++ b/src/shader_recompiler/frontend/ir/microinstruction.h
@@ -0,0 +1,82 @@
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
9#include <boost/intrusive/list.hpp>
10
11#include "common/common_types.h"
12#include "shader_recompiler/frontend/ir/opcode.h"
13#include "shader_recompiler/frontend/ir/type.h"
14#include "shader_recompiler/frontend/ir/value.h"
15
16namespace Shader::IR {
17
18constexpr size_t MAX_ARG_COUNT = 4;
19
20class Inst : public boost::intrusive::list_base_hook<> {
21public:
22 explicit Inst(Opcode op_) noexcept : op(op_) {}
23
24 /// Get the number of uses this instruction has.
25 [[nodiscard]] int UseCount() const noexcept {
26 return use_count;
27 }
28
29 /// Determines whether this instruction has uses or not.
30 [[nodiscard]] bool HasUses() const noexcept {
31 return use_count > 0;
32 }
33
34 /// Get the opcode this microinstruction represents.
35 [[nodiscard]] IR::Opcode Opcode() const noexcept {
36 return op;
37 }
38
39 /// Determines whether or not this instruction may have side effects.
40 [[nodiscard]] bool MayHaveSideEffects() const noexcept;
41
42 /// Determines whether or not this instruction is a pseudo-instruction.
43 /// Pseudo-instructions depend on their parent instructions for their semantics.
44 [[nodiscard]] bool IsPseudoInstruction() const noexcept;
45
46 /// Determines if there is a pseudo-operation associated with this instruction.
47 [[nodiscard]] bool HasAssociatedPseudoOperation() const noexcept;
48 /// Gets a pseudo-operation associated with this instruction
49 [[nodiscard]] Inst* GetAssociatedPseudoOperation(IR::Opcode opcode);
50
51 /// Get the number of arguments this instruction has.
52 [[nodiscard]] size_t NumArgs() const;
53
54 /// Get the type this instruction returns.
55 [[nodiscard]] IR::Type Type() const;
56
57 /// Get the value of a given argument index.
58 [[nodiscard]] Value Arg(size_t index) const;
59 /// Set the value of a given argument index.
60 void SetArg(size_t index, Value value);
61
62 void Invalidate();
63 void ClearArgs();
64
65 void ReplaceUsesWith(Value replacement);
66
67private:
68 void Use(const Value& value);
69 void UndoUse(const Value& value);
70
71 IR::Opcode op{};
72 int use_count{};
73 std::array<Value, MAX_ARG_COUNT> args{};
74 Inst* zero_inst{};
75 Inst* sign_inst{};
76 Inst* carry_inst{};
77 Inst* overflow_inst{};
78 Inst* zsco_inst{};
79 u64 flags{};
80};
81
82} // namespace Shader::IR