diff options
Diffstat (limited to 'src/shader_recompiler/frontend/ir/value.cpp')
| -rw-r--r-- | src/shader_recompiler/frontend/ir/value.cpp | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/src/shader_recompiler/frontend/ir/value.cpp b/src/shader_recompiler/frontend/ir/value.cpp new file mode 100644 index 000000000..d365ea1bc --- /dev/null +++ b/src/shader_recompiler/frontend/ir/value.cpp | |||
| @@ -0,0 +1,99 @@ | |||
| 1 | // Copyright 2021 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include "shader_recompiler/frontend/ir/opcodes.h" | ||
| 6 | #include "shader_recompiler/frontend/ir/value.h" | ||
| 7 | |||
| 8 | namespace Shader::IR { | ||
| 9 | |||
| 10 | Value::Value(IR::Inst* value) noexcept : type{Type::Opaque}, inst{value} {} | ||
| 11 | |||
| 12 | Value::Value(IR::Reg value) noexcept : type{Type::Reg}, reg{value} {} | ||
| 13 | |||
| 14 | Value::Value(IR::Pred value) noexcept : type{Type::Pred}, pred{value} {} | ||
| 15 | |||
| 16 | Value::Value(IR::Attribute value) noexcept : type{Type::Attribute}, attribute{value} {} | ||
| 17 | |||
| 18 | Value::Value(IR::Patch value) noexcept : type{Type::Patch}, patch{value} {} | ||
| 19 | |||
| 20 | Value::Value(bool value) noexcept : type{Type::U1}, imm_u1{value} {} | ||
| 21 | |||
| 22 | Value::Value(u8 value) noexcept : type{Type::U8}, imm_u8{value} {} | ||
| 23 | |||
| 24 | Value::Value(u16 value) noexcept : type{Type::U16}, imm_u16{value} {} | ||
| 25 | |||
| 26 | Value::Value(u32 value) noexcept : type{Type::U32}, imm_u32{value} {} | ||
| 27 | |||
| 28 | Value::Value(f32 value) noexcept : type{Type::F32}, imm_f32{value} {} | ||
| 29 | |||
| 30 | Value::Value(u64 value) noexcept : type{Type::U64}, imm_u64{value} {} | ||
| 31 | |||
| 32 | Value::Value(f64 value) noexcept : type{Type::F64}, imm_f64{value} {} | ||
| 33 | |||
| 34 | IR::Type Value::Type() const noexcept { | ||
| 35 | if (IsPhi()) { | ||
| 36 | // The type of a phi node is stored in its flags | ||
| 37 | return inst->Flags<IR::Type>(); | ||
| 38 | } | ||
| 39 | if (IsIdentity()) { | ||
| 40 | return inst->Arg(0).Type(); | ||
| 41 | } | ||
| 42 | if (type == Type::Opaque) { | ||
| 43 | return inst->Type(); | ||
| 44 | } | ||
| 45 | return type; | ||
| 46 | } | ||
| 47 | |||
| 48 | bool Value::operator==(const Value& other) const { | ||
| 49 | if (type != other.type) { | ||
| 50 | return false; | ||
| 51 | } | ||
| 52 | switch (type) { | ||
| 53 | case Type::Void: | ||
| 54 | return true; | ||
| 55 | case Type::Opaque: | ||
| 56 | return inst == other.inst; | ||
| 57 | case Type::Reg: | ||
| 58 | return reg == other.reg; | ||
| 59 | case Type::Pred: | ||
| 60 | return pred == other.pred; | ||
| 61 | case Type::Attribute: | ||
| 62 | return attribute == other.attribute; | ||
| 63 | case Type::Patch: | ||
| 64 | return patch == other.patch; | ||
| 65 | case Type::U1: | ||
| 66 | return imm_u1 == other.imm_u1; | ||
| 67 | case Type::U8: | ||
| 68 | return imm_u8 == other.imm_u8; | ||
| 69 | case Type::U16: | ||
| 70 | case Type::F16: | ||
| 71 | return imm_u16 == other.imm_u16; | ||
| 72 | case Type::U32: | ||
| 73 | case Type::F32: | ||
| 74 | return imm_u32 == other.imm_u32; | ||
| 75 | case Type::U64: | ||
| 76 | case Type::F64: | ||
| 77 | return imm_u64 == other.imm_u64; | ||
| 78 | case Type::U32x2: | ||
| 79 | case Type::U32x3: | ||
| 80 | case Type::U32x4: | ||
| 81 | case Type::F16x2: | ||
| 82 | case Type::F16x3: | ||
| 83 | case Type::F16x4: | ||
| 84 | case Type::F32x2: | ||
| 85 | case Type::F32x3: | ||
| 86 | case Type::F32x4: | ||
| 87 | case Type::F64x2: | ||
| 88 | case Type::F64x3: | ||
| 89 | case Type::F64x4: | ||
| 90 | break; | ||
| 91 | } | ||
| 92 | throw LogicError("Invalid type {}", type); | ||
| 93 | } | ||
| 94 | |||
| 95 | bool Value::operator!=(const Value& other) const { | ||
| 96 | return !operator==(other); | ||
| 97 | } | ||
| 98 | |||
| 99 | } // namespace Shader::IR | ||