value.cpp 2.7 KB

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