shader: Store type of phi nodes in flags

This is needed because pseudo-instructions where invalidated.
This commit is contained in:
ReinUsesLisp 2021-03-30 03:19:50 -03:00 committed by ameerj
parent b0d5572abf
commit 514a6b07ee
3 changed files with 11 additions and 2 deletions

View file

@ -288,7 +288,8 @@ Id EmitPhi(EmitContext& ctx, IR::Inst* inst) {
operands.push_back(PhiArgDef(ctx, inst, index)); operands.push_back(PhiArgDef(ctx, inst, index));
operands.push_back(inst->PhiBlock(index)->Definition<Id>()); operands.push_back(inst->PhiBlock(index)->Definition<Id>());
} }
const Id result_type{TypeId(ctx, inst->Arg(0).Type())}; // The type of a phi instruction is stored in its flags
const Id result_type{TypeId(ctx, inst->Flags<IR::Type>())};
return ctx.OpPhi(result_type, std::span(operands.data(), operands.size())); return ctx.OpPhi(result_type, std::span(operands.data(), operands.size()));
} }

View file

@ -193,6 +193,10 @@ void Inst::AddPhiOperand(Block* predecessor, const Value& value) {
if (!value.IsImmediate()) { if (!value.IsImmediate()) {
Use(value); Use(value);
} }
if (Flags<IR::Type>() == IR::Type::Void) {
// Set the type of the phi node
SetFlags<IR::Type>(value.Type());
}
phi_args.emplace_back(predecessor, value); phi_args.emplace_back(predecessor, value);
} }

View file

@ -56,7 +56,11 @@ bool Value::IsLabel() const noexcept {
} }
IR::Type Value::Type() const noexcept { IR::Type Value::Type() const noexcept {
if (IsIdentity() || IsPhi()) { if (IsPhi()) {
// The type of a phi node is stored in its flags
return inst->Flags<IR::Type>();
}
if (IsIdentity()) {
return inst->Arg(0).Type(); return inst->Arg(0).Type();
} }
if (type == Type::Opaque) { if (type == Type::Opaque) {