kraid: Add a VirtualOpcode trait

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/42200>
This commit is contained in:
Faith Ekstrand 2026-06-08 13:04:33 -04:00 committed by Marge Bot
parent a3da0c152d
commit 166cea24fb
3 changed files with 45 additions and 2 deletions

View file

@ -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,

View file

@ -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] {

View file

@ -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::<Op>() == 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<T: Opcode> From<T> for Op
where