summaryrefslogtreecommitdiff
path: root/src/shader_recompiler/frontend
diff options
context:
space:
mode:
Diffstat (limited to 'src/shader_recompiler/frontend')
-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 {
51 return type; 51 return type;
52} 52}
53 53
54IR::Inst* Value::Inst() const {
55 ValidateAccess(Type::Opaque);
56 return inst;
57}
58
59IR::Block* Value::Label() const {
60 ValidateAccess(Type::Label);
61 return label;
62}
63
64IR::Inst* Value::InstRecursive() const {
65 ValidateAccess(Type::Opaque);
66 if (IsIdentity()) {
67 return inst->Arg(0).InstRecursive();
68 }
69 return inst;
70}
71
72IR::Value Value::Resolve() const {
73 if (IsIdentity()) {
74 return inst->Arg(0).Resolve();
75 }
76 return *this;
77}
78
79IR::Reg Value::Reg() const {
80 ValidateAccess(Type::Reg);
81 return reg;
82}
83
84IR::Pred Value::Pred() const {
85 ValidateAccess(Type::Pred);
86 return pred;
87}
88
89IR::Attribute Value::Attribute() const {
90 ValidateAccess(Type::Attribute);
91 return attribute;
92}
93
94IR::Patch Value::Patch() const {
95 ValidateAccess(Type::Patch);
96 return patch;
97}
98
99bool Value::U1() const {
100 if (IsIdentity()) {
101 return inst->Arg(0).U1();
102 }
103 ValidateAccess(Type::U1);
104 return imm_u1;
105}
106
107u8 Value::U8() const {
108 if (IsIdentity()) {
109 return inst->Arg(0).U8();
110 }
111 ValidateAccess(Type::U8);
112 return imm_u8;
113}
114
115u16 Value::U16() const {
116 if (IsIdentity()) {
117 return inst->Arg(0).U16();
118 }
119 ValidateAccess(Type::U16);
120 return imm_u16;
121}
122
123u32 Value::U32() const {
124 if (IsIdentity()) {
125 return inst->Arg(0).U32();
126 }
127 ValidateAccess(Type::U32);
128 return imm_u32;
129}
130
131f32 Value::F32() const {
132 if (IsIdentity()) {
133 return inst->Arg(0).F32();
134 }
135 ValidateAccess(Type::F32);
136 return imm_f32;
137}
138
139u64 Value::U64() const {
140 if (IsIdentity()) {
141 return inst->Arg(0).U64();
142 }
143 ValidateAccess(Type::U64);
144 return imm_u64;
145}
146
147f64 Value::F64() const {
148 if (IsIdentity()) {
149 return inst->Arg(0).F64();
150 }
151 ValidateAccess(Type::F64);
152 return imm_f64;
153}
154
155bool Value::operator==(const Value& other) const { 54bool Value::operator==(const Value& other) const {
156 if (type != other.type) { 55 if (type != other.type) {
157 return false; 56 return false;
@@ -205,10 +104,4 @@ bool Value::operator!=(const Value& other) const {
205 return !operator==(other); 104 return !operator==(other);
206} 105}
207 106
208void Value::ValidateAccess(IR::Type expected) const {
209 if (type != expected) {
210 throw LogicError("Reading {} out of {}", expected, type);
211 }
212}
213
214} // namespace Shader::IR 107} // 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 @@
14#include <boost/container/small_vector.hpp> 14#include <boost/container/small_vector.hpp>
15#include <boost/intrusive/list.hpp> 15#include <boost/intrusive/list.hpp>
16 16
17#include "common/assert.h"
17#include "common/bit_cast.h" 18#include "common/bit_cast.h"
18#include "common/common_types.h" 19#include "common/common_types.h"
19#include "shader_recompiler/exception.h" 20#include "shader_recompiler/exception.h"
@@ -76,8 +77,6 @@ public:
76 [[nodiscard]] bool operator!=(const Value& other) const; 77 [[nodiscard]] bool operator!=(const Value& other) const;
77 78
78private: 79private:
79 void ValidateAccess(IR::Type expected) const;
80
81 IR::Type type{}; 80 IR::Type type{};
82 union { 81 union {
83 IR::Inst* inst{}; 82 IR::Inst* inst{};
@@ -288,4 +287,105 @@ inline bool Value::IsImmediate() const noexcept {
288 return current_type != Type::Opaque; 287 return current_type != Type::Opaque;
289} 288}
290 289
290inline IR::Inst* Value::Inst() const {
291 DEBUG_ASSERT(type == Type::Opaque);
292 return inst;
293}
294
295inline IR::Block* Value::Label() const {
296 DEBUG_ASSERT(type == Type::Label);
297 return label;
298}
299
300inline IR::Inst* Value::InstRecursive() const {
301 DEBUG_ASSERT(type == Type::Opaque);
302 if (IsIdentity()) {
303 return inst->Arg(0).InstRecursive();
304 }
305 return inst;
306}
307
308inline IR::Value Value::Resolve() const {
309 if (IsIdentity()) {
310 return inst->Arg(0).Resolve();
311 }
312 return *this;
313}
314
315inline IR::Reg Value::Reg() const {
316 DEBUG_ASSERT(type == Type::Reg);
317 return reg;
318}
319
320inline IR::Pred Value::Pred() const {
321 DEBUG_ASSERT(type == Type::Pred);
322 return pred;
323}
324
325inline IR::Attribute Value::Attribute() const {
326 DEBUG_ASSERT(type == Type::Attribute);
327 return attribute;
328}
329
330inline IR::Patch Value::Patch() const {
331 DEBUG_ASSERT(type == Type::Patch);
332 return patch;
333}
334
335inline bool Value::U1() const {
336 if (IsIdentity()) {
337 return inst->Arg(0).U1();
338 }
339 DEBUG_ASSERT(type == Type::U1);
340 return imm_u1;
341}
342
343inline u8 Value::U8() const {
344 if (IsIdentity()) {
345 return inst->Arg(0).U8();
346 }
347 DEBUG_ASSERT(type == Type::U8);
348 return imm_u8;
349}
350
351inline u16 Value::U16() const {
352 if (IsIdentity()) {
353 return inst->Arg(0).U16();
354 }
355 DEBUG_ASSERT(type == Type::U16);
356 return imm_u16;
357}
358
359inline u32 Value::U32() const {
360 if (IsIdentity()) {
361 return inst->Arg(0).U32();
362 }
363 DEBUG_ASSERT(type == Type::U32);
364 return imm_u32;
365}
366
367inline f32 Value::F32() const {
368 if (IsIdentity()) {
369 return inst->Arg(0).F32();
370 }
371 DEBUG_ASSERT(type == Type::F32);
372 return imm_f32;
373}
374
375inline u64 Value::U64() const {
376 if (IsIdentity()) {
377 return inst->Arg(0).U64();
378 }
379 DEBUG_ASSERT(type == Type::U64);
380 return imm_u64;
381}
382
383inline f64 Value::F64() const {
384 if (IsIdentity()) {
385 return inst->Arg(0).F64();
386 }
387 DEBUG_ASSERT(type == Type::F64);
388 return imm_f64;
389}
390
291} // namespace Shader::IR 391} // namespace Shader::IR