summaryrefslogtreecommitdiffstats
path: root/src/shader_recompiler
diff options
context:
space:
mode:
authorReinUsesLisp <reinuseslisp@airmail.cc>2021-04-21 09:59:16 +0200
committerameerj <52414509+ameerj@users.noreply.github.com>2021-07-23 03:51:28 +0200
commit75dee55486cac936f3a2d68533772d23aa733b72 (patch)
tree1c72e6bf1ad648552b26445af563768daacf2bb1 /src/shader_recompiler
parentshader: Intrusively store in a block if it's sealed or not (diff)
downloadyuzu-75dee55486cac936f3a2d68533772d23aa733b72.tar
yuzu-75dee55486cac936f3a2d68533772d23aa733b72.tar.gz
yuzu-75dee55486cac936f3a2d68533772d23aa733b72.tar.bz2
yuzu-75dee55486cac936f3a2d68533772d23aa733b72.tar.lz
yuzu-75dee55486cac936f3a2d68533772d23aa733b72.tar.xz
yuzu-75dee55486cac936f3a2d68533772d23aa733b72.tar.zst
yuzu-75dee55486cac936f3a2d68533772d23aa733b72.zip
Diffstat (limited to 'src/shader_recompiler')
-rw-r--r--src/shader_recompiler/frontend/ir/value.cpp107
-rw-r--r--src/shader_recompiler/frontend/ir/value.h104
2 files changed, 102 insertions, 109 deletions
diff --git a/src/shader_recompiler/frontend/ir/value.cpp b/src/shader_recompiler/frontend/ir/value.cpp
index c021d3fa9..b962f170d 100644
--- a/src/shader_recompiler/frontend/ir/value.cpp
+++ b/src/shader_recompiler/frontend/ir/value.cpp
@@ -51,107 +51,6 @@ IR::Type Value::Type() const noexcept {
return type;
}
-IR::Inst* Value::Inst() const {
- ValidateAccess(Type::Opaque);
- return inst;
-}
-
-IR::Block* Value::Label() const {
- ValidateAccess(Type::Label);
- return label;
-}
-
-IR::Inst* Value::InstRecursive() const {
- ValidateAccess(Type::Opaque);
- if (IsIdentity()) {
- return inst->Arg(0).InstRecursive();
- }
- return inst;
-}
-
-IR::Value Value::Resolve() const {
- if (IsIdentity()) {
- return inst->Arg(0).Resolve();
- }
- return *this;
-}
-
-IR::Reg Value::Reg() const {
- ValidateAccess(Type::Reg);
- return reg;
-}
-
-IR::Pred Value::Pred() const {
- ValidateAccess(Type::Pred);
- return pred;
-}
-
-IR::Attribute Value::Attribute() const {
- ValidateAccess(Type::Attribute);
- return attribute;
-}
-
-IR::Patch Value::Patch() const {
- ValidateAccess(Type::Patch);
- return patch;
-}
-
-bool Value::U1() const {
- if (IsIdentity()) {
- return inst->Arg(0).U1();
- }
- ValidateAccess(Type::U1);
- return imm_u1;
-}
-
-u8 Value::U8() const {
- if (IsIdentity()) {
- return inst->Arg(0).U8();
- }
- ValidateAccess(Type::U8);
- return imm_u8;
-}
-
-u16 Value::U16() const {
- if (IsIdentity()) {
- return inst->Arg(0).U16();
- }
- ValidateAccess(Type::U16);
- return imm_u16;
-}
-
-u32 Value::U32() const {
- if (IsIdentity()) {
- return inst->Arg(0).U32();
- }
- ValidateAccess(Type::U32);
- return imm_u32;
-}
-
-f32 Value::F32() const {
- if (IsIdentity()) {
- return inst->Arg(0).F32();
- }
- ValidateAccess(Type::F32);
- return imm_f32;
-}
-
-u64 Value::U64() const {
- if (IsIdentity()) {
- return inst->Arg(0).U64();
- }
- ValidateAccess(Type::U64);
- return imm_u64;
-}
-
-f64 Value::F64() const {
- if (IsIdentity()) {
- return inst->Arg(0).F64();
- }
- ValidateAccess(Type::F64);
- return imm_f64;
-}
-
bool Value::operator==(const Value& other) const {
if (type != other.type) {
return false;
@@ -205,10 +104,4 @@ bool Value::operator!=(const Value& other) const {
return !operator==(other);
}
-void Value::ValidateAccess(IR::Type expected) const {
- if (type != expected) {
- throw LogicError("Reading {} out of {}", expected, type);
- }
-}
-
} // namespace Shader::IR
diff --git a/src/shader_recompiler/frontend/ir/value.h b/src/shader_recompiler/frontend/ir/value.h
index 7b20824ed..bb7d19001 100644
--- a/src/shader_recompiler/frontend/ir/value.h
+++ b/src/shader_recompiler/frontend/ir/value.h
@@ -14,6 +14,7 @@
#include <boost/container/small_vector.hpp>
#include <boost/intrusive/list.hpp>
+#include "common/assert.h"
#include "common/bit_cast.h"
#include "common/common_types.h"
#include "shader_recompiler/exception.h"
@@ -76,8 +77,6 @@ public:
[[nodiscard]] bool operator!=(const Value& other) const;
private:
- void ValidateAccess(IR::Type expected) const;
-
IR::Type type{};
union {
IR::Inst* inst{};
@@ -288,4 +287,105 @@ inline bool Value::IsImmediate() const noexcept {
return current_type != Type::Opaque;
}
+inline IR::Inst* Value::Inst() const {
+ DEBUG_ASSERT(type == Type::Opaque);
+ return inst;
+}
+
+inline IR::Block* Value::Label() const {
+ DEBUG_ASSERT(type == Type::Label);
+ return label;
+}
+
+inline IR::Inst* Value::InstRecursive() const {
+ DEBUG_ASSERT(type == Type::Opaque);
+ if (IsIdentity()) {
+ return inst->Arg(0).InstRecursive();
+ }
+ return inst;
+}
+
+inline IR::Value Value::Resolve() const {
+ if (IsIdentity()) {
+ return inst->Arg(0).Resolve();
+ }
+ return *this;
+}
+
+inline IR::Reg Value::Reg() const {
+ DEBUG_ASSERT(type == Type::Reg);
+ return reg;
+}
+
+inline IR::Pred Value::Pred() const {
+ DEBUG_ASSERT(type == Type::Pred);
+ return pred;
+}
+
+inline IR::Attribute Value::Attribute() const {
+ DEBUG_ASSERT(type == Type::Attribute);
+ return attribute;
+}
+
+inline IR::Patch Value::Patch() const {
+ DEBUG_ASSERT(type == Type::Patch);
+ return patch;
+}
+
+inline bool Value::U1() const {
+ if (IsIdentity()) {
+ return inst->Arg(0).U1();
+ }
+ DEBUG_ASSERT(type == Type::U1);
+ return imm_u1;
+}
+
+inline u8 Value::U8() const {
+ if (IsIdentity()) {
+ return inst->Arg(0).U8();
+ }
+ DEBUG_ASSERT(type == Type::U8);
+ return imm_u8;
+}
+
+inline u16 Value::U16() const {
+ if (IsIdentity()) {
+ return inst->Arg(0).U16();
+ }
+ DEBUG_ASSERT(type == Type::U16);
+ return imm_u16;
+}
+
+inline u32 Value::U32() const {
+ if (IsIdentity()) {
+ return inst->Arg(0).U32();
+ }
+ DEBUG_ASSERT(type == Type::U32);
+ return imm_u32;
+}
+
+inline f32 Value::F32() const {
+ if (IsIdentity()) {
+ return inst->Arg(0).F32();
+ }
+ DEBUG_ASSERT(type == Type::F32);
+ return imm_f32;
+}
+
+inline u64 Value::U64() const {
+ if (IsIdentity()) {
+ return inst->Arg(0).U64();
+ }
+ DEBUG_ASSERT(type == Type::U64);
+ return imm_u64;
+}
+
+inline f64 Value::F64() const {
+ if (IsIdentity()) {
+ return inst->Arg(0).F64();
+ }
+ DEBUG_ASSERT(type == Type::F64);
+ return imm_f64;
+}
+
} // namespace Shader::IR