summaryrefslogtreecommitdiff
path: root/src/shader_recompiler/frontend/ir/value.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/shader_recompiler/frontend/ir/value.h98
1 files changed, 98 insertions, 0 deletions
diff --git a/src/shader_recompiler/frontend/ir/value.h b/src/shader_recompiler/frontend/ir/value.h
new file mode 100644
index 000000000..664dacf9d
--- /dev/null
+++ b/src/shader_recompiler/frontend/ir/value.h
@@ -0,0 +1,98 @@
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 "common/common_types.h"
8#include "shader_recompiler/exception.h"
9#include "shader_recompiler/frontend/ir/attribute.h"
10#include "shader_recompiler/frontend/ir/pred.h"
11#include "shader_recompiler/frontend/ir/reg.h"
12#include "shader_recompiler/frontend/ir/type.h"
13
14namespace Shader::IR {
15
16class Block;
17class Inst;
18
19class Value {
20public:
21 Value() noexcept : type{IR::Type::Void}, inst{nullptr} {}
22 explicit Value(IR::Inst* value) noexcept;
23 explicit Value(IR::Block* value) noexcept;
24 explicit Value(IR::Reg value) noexcept;
25 explicit Value(IR::Pred value) noexcept;
26 explicit Value(IR::Attribute value) noexcept;
27 explicit Value(bool value) noexcept;
28 explicit Value(u8 value) noexcept;
29 explicit Value(u16 value) noexcept;
30 explicit Value(u32 value) noexcept;
31 explicit Value(u64 value) noexcept;
32
33 [[nodiscard]] bool IsIdentity() const noexcept;
34 [[nodiscard]] bool IsEmpty() const noexcept;
35 [[nodiscard]] bool IsImmediate() const noexcept;
36 [[nodiscard]] bool IsLabel() const noexcept;
37 [[nodiscard]] IR::Type Type() const noexcept;
38
39 [[nodiscard]] IR::Inst* Inst() const;
40 [[nodiscard]] IR::Block* Label() const;
41 [[nodiscard]] IR::Inst* InstRecursive() const;
42 [[nodiscard]] IR::Reg Reg() const;
43 [[nodiscard]] IR::Pred Pred() const;
44 [[nodiscard]] IR::Attribute Attribute() const;
45 [[nodiscard]] bool U1() const;
46 [[nodiscard]] u8 U8() const;
47 [[nodiscard]] u16 U16() const;
48 [[nodiscard]] u32 U32() const;
49 [[nodiscard]] u64 U64() const;
50
51private:
52 void ValidateAccess(IR::Type expected) const;
53
54 IR::Type type;
55 union {
56 IR::Inst* inst;
57 IR::Block* label;
58 IR::Reg reg;
59 IR::Pred pred;
60 IR::Attribute attribute;
61 bool imm_u1;
62 u8 imm_u8;
63 u16 imm_u16;
64 u32 imm_u32;
65 u64 imm_u64;
66 };
67};
68
69template <IR::Type type_>
70class TypedValue : public Value {
71public:
72 TypedValue() = default;
73
74 template <IR::Type other_type>
75 requires((other_type & type_) != IR::Type::Void) explicit(false)
76 TypedValue(const TypedValue<other_type>& value)
77 : Value(value) {}
78
79 explicit TypedValue(const Value& value) : Value(value) {
80 if ((value.Type() & type_) == IR::Type::Void) {
81 throw InvalidArgument("Incompatible types {} and {}", type_, value.Type());
82 }
83 }
84
85 explicit TypedValue(IR::Inst* inst) : TypedValue(Value(inst)) {}
86};
87
88using U1 = TypedValue<Type::U1>;
89using U8 = TypedValue<Type::U8>;
90using U16 = TypedValue<Type::U16>;
91using U32 = TypedValue<Type::U32>;
92using U64 = TypedValue<Type::U64>;
93using U32U64 = TypedValue<Type::U32 | Type::U64>;
94using U16U32U64 = TypedValue<Type::U16 | Type::U32 | Type::U64>;
95using UAny = TypedValue<Type::U8 | Type::U16 | Type::U32 | Type::U64>;
96using ZSCO = TypedValue<Type::ZSCO>;
97
98} // namespace Shader::IR