From 166cea24fbaff6dc178bf96b62d17206de32e032 Mon Sep 17 00:00:00 2001 From: Faith Ekstrand Date: Mon, 8 Jun 2026 13:04:33 -0400 Subject: [PATCH] kraid: Add a VirtualOpcode trait Part-of: --- src/panfrost/compiler/kraid/ir.rs | 13 +++++++++++++ src/panfrost/compiler/kraid/model.rs | 12 ++++++++++-- src/panfrost/compiler/kraid/ops.rs | 22 ++++++++++++++++++++++ 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/src/panfrost/compiler/kraid/ir.rs b/src/panfrost/compiler/kraid/ir.rs index ed2a53b295a..ada774d82e2 100644 --- a/src/panfrost/compiler/kraid/ir.rs +++ b/src/panfrost/compiler/kraid/ir.rs @@ -587,6 +587,19 @@ pub trait Opcode: } } +/// A trait that allows querying various properties of an opcode. Virtual ops, +/// which must be lowered implement this trait directly while it may require +/// going through `Model` for other ops. +pub trait VirtualOpcode { + fn is_message(&self) -> bool { + false + } + + fn src_supports_imm32(&self, _src: &Src) -> bool { + false + } +} + #[derive(Clone)] pub struct Instr { pub op: Op, diff --git a/src/panfrost/compiler/kraid/model.rs b/src/panfrost/compiler/kraid/model.rs index 8301fbc37a4..88efd7ec6ea 100644 --- a/src/panfrost/compiler/kraid/model.rs +++ b/src/panfrost/compiler/kraid/model.rs @@ -40,11 +40,19 @@ impl Model for ValhallModel { } fn op_is_message(&self, op: &Op) -> bool { - v9_op_is_message(op, self.arch) + if let Some(vop) = op.as_virtual() { + vop.is_message() + } else { + v9_op_is_message(op, self.arch) + } } fn op_src_supports_imm32(&self, op: &Op, src: &Src) -> bool { - v9_op_src_supports_imm32(op, src, self.arch) + if let Some(vop) = op.as_virtual() { + vop.src_supports_imm32(src) + } else { + v9_op_src_supports_imm32(op, src, self.arch) + } } fn small_constants(&self) -> &[SmallConstant] { diff --git a/src/panfrost/compiler/kraid/ops.rs b/src/panfrost/compiler/kraid/ops.rs index 3660f16230c..92fd1a11ab5 100644 --- a/src/panfrost/compiler/kraid/ops.rs +++ b/src/panfrost/compiler/kraid/ops.rs @@ -453,6 +453,12 @@ impl fmt::Display for OpMkVecV2I8 { } } +impl VirtualOpcode for OpMkVecV2I8 { + fn src_supports_imm32(&self, _src: &Src) -> bool { + true + } +} + #[repr(C)] #[derive(Clone, Opcode)] pub struct OpMkVecV4I8 { @@ -477,6 +483,12 @@ impl fmt::Display for OpMkVecV4I8 { } } +impl VirtualOpcode for OpMkVecV4I8 { + fn src_supports_imm32(&self, _src: &Src) -> bool { + true + } +} + #[repr(C)] #[derive(Clone, Opcode)] #[variants(dst_type in [I16, I32])] @@ -655,6 +667,16 @@ const _: () = { assert!(size_of::() == 16); }; +impl Op { + pub fn as_virtual(&self) -> Option<&dyn VirtualOpcode> { + match self { + Op::MkVecV2I8(op) => Some(op.as_ref()), + Op::MkVecV4I8(op) => Some(op.as_ref()), + _ => None, + } + } +} + // The Opcode constraint exists to keep the type system from recursing impl From for Op where