IR: Properly support Identity in IR::Value

This commit is contained in:
MerryMage 2016-08-05 14:09:10 +01:00
parent ca40015145
commit 01cfaf0286
2 changed files with 56 additions and 33 deletions

View file

@ -52,8 +52,56 @@ const char* GetNameOf(Opcode op) {
// Value class member definitions // Value class member definitions
bool Value::IsImmediate() const {
if (type == Type::Opaque)
return inner.inst->GetOpcode() == Opcode::Identity ? inner.inst->GetArg(0).IsImmediate() : false;
return true;
}
bool Value::IsEmpty() const {
return type == Type::Void;
}
Type Value::GetType() const { Type Value::GetType() const {
return IsImmediate() ? type : inner.inst->GetType(); if (type == Type::Opaque) {
if (inner.inst->GetOpcode() == Opcode::Identity) {
return inner.inst->GetArg(0).GetType();
} else {
return inner.inst->GetType();
}
}
return type;
}
Arm::Reg Value::GetRegRef() const {
DEBUG_ASSERT(type == Type::RegRef);
return inner.imm_regref;
}
Inst* Value::GetInst() const {
DEBUG_ASSERT(type == Type::Opaque);
return inner.inst;
}
bool Value::GetU1() const {
if (type == Type::Opaque && inner.inst->GetOpcode() == Opcode::Identity)
return inner.inst->GetArg(0).GetU1();
DEBUG_ASSERT(type == Type::U1);
return inner.imm_u1;
}
u8 Value::GetU8() const {
if (type == Type::Opaque && inner.inst->GetOpcode() == Opcode::Identity)
return inner.inst->GetArg(0).GetU8();
DEBUG_ASSERT(type == Type::U8);
return inner.imm_u8;
}
u32 Value::GetU32() const {
if (type == Type::Opaque && inner.inst->GetOpcode() == Opcode::Identity)
return inner.inst->GetArg(0).GetU32();
DEBUG_ASSERT(type == Type::U32);
return inner.imm_u32;
} }
// Inst class member definitions // Inst class member definitions

View file

@ -84,40 +84,15 @@ public:
inner.imm_u32 = value; inner.imm_u32 = value;
} }
bool IsEmpty() const { bool IsEmpty() const;
return type == Type::Void; bool IsImmediate() const;
}
bool IsImmediate() const {
return type != Type::Opaque;
}
Type GetType() const; Type GetType() const;
Inst* GetInst() const { Inst* GetInst() const;
DEBUG_ASSERT(type == Type::Opaque); Arm::Reg GetRegRef() const;
return inner.inst; bool GetU1() const;
} u8 GetU8() const;
u32 GetU32() const;
Arm::Reg GetRegRef() const {
DEBUG_ASSERT(type == Type::RegRef);
return inner.imm_regref;
}
bool GetU1() const {
DEBUG_ASSERT(type == Type::U1);
return inner.imm_u1;
}
u8 GetU8() const {
DEBUG_ASSERT(type == Type::U8);
return inner.imm_u8;
}
u32 GetU32() const {
DEBUG_ASSERT(type == Type::U32);
return inner.imm_u32;
}
private: private:
Type type; Type type;