diff options
| author | 2021-01-09 03:30:07 -0300 | |
|---|---|---|
| committer | 2021-07-22 21:51:21 -0400 | |
| commit | 2d48a7b4d0666ad16d03a22d85712617a0849046 (patch) | |
| tree | dd1069afca86f66e77e3438da77421a43adf5091 /src/shader_recompiler/frontend/ir/value.h | |
| parent | thread_worker: Fix compile time error (diff) | |
| download | yuzu-2d48a7b4d0666ad16d03a22d85712617a0849046.tar.gz yuzu-2d48a7b4d0666ad16d03a22d85712617a0849046.tar.xz yuzu-2d48a7b4d0666ad16d03a22d85712617a0849046.zip | |
shader: Initial recompiler work
Diffstat (limited to 'src/shader_recompiler/frontend/ir/value.h')
| -rw-r--r-- | src/shader_recompiler/frontend/ir/value.h | 98 |
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 | |||
| 14 | namespace Shader::IR { | ||
| 15 | |||
| 16 | class Block; | ||
| 17 | class Inst; | ||
| 18 | |||
| 19 | class Value { | ||
| 20 | public: | ||
| 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 | |||
| 51 | private: | ||
| 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 | |||
| 69 | template <IR::Type type_> | ||
| 70 | class TypedValue : public Value { | ||
| 71 | public: | ||
| 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 | |||
| 88 | using U1 = TypedValue<Type::U1>; | ||
| 89 | using U8 = TypedValue<Type::U8>; | ||
| 90 | using U16 = TypedValue<Type::U16>; | ||
| 91 | using U32 = TypedValue<Type::U32>; | ||
| 92 | using U64 = TypedValue<Type::U64>; | ||
| 93 | using U32U64 = TypedValue<Type::U32 | Type::U64>; | ||
| 94 | using U16U32U64 = TypedValue<Type::U16 | Type::U32 | Type::U64>; | ||
| 95 | using UAny = TypedValue<Type::U8 | Type::U16 | Type::U32 | Type::U64>; | ||
| 96 | using ZSCO = TypedValue<Type::ZSCO>; | ||
| 97 | |||
| 98 | } // namespace Shader::IR | ||