diff --git a/cranelift/codegen/meta/src/cdsl/ast.rs b/cranelift/codegen/meta/src/cdsl/ast.rs index 37892fc896..ccb9adec01 100644 --- a/cranelift/codegen/meta/src/cdsl/ast.rs +++ b/cranelift/codegen/meta/src/cdsl/ast.rs @@ -574,7 +574,7 @@ macro_rules! def_rhs { // inst.type(a, b, c) ($inst:ident.$type:ident($($src:expr),*)) => { - ExprBuilder::apply(bind($inst, $type).into(), vec![$($src.clone().into()),*]) + ExprBuilder::apply($inst.bind($type).into(), vec![$($src.clone().into()),*]) }; } diff --git a/cranelift/codegen/meta/src/cdsl/inst.rs b/cranelift/codegen/meta/src/cdsl/inst.rs index 2dcd3e4d9a..b469e8b91f 100644 --- a/cranelift/codegen/meta/src/cdsl/inst.rs +++ b/cranelift/codegen/meta/src/cdsl/inst.rs @@ -143,6 +143,10 @@ impl Instruction { None => Vec::new(), } } + + pub fn bind(&self, lane_type: impl Into) -> BoundInstruction { + bind(self.clone(), lane_type.into(), Vec::new()) + } } impl fmt::Display for Instruction { @@ -341,6 +345,12 @@ pub struct BoundInstruction { pub value_types: Vec, } +impl BoundInstruction { + pub fn bind(self, lane_type: impl Into) -> BoundInstruction { + bind(self.inst, lane_type.into(), self.value_types) + } +} + /// Check if this instruction is polymorphic, and verify its use of type variables. fn verify_polymorphic( operands_in: &Vec, @@ -626,18 +636,13 @@ impl Into for BoundInstruction { } } -pub fn bind(target: impl Into, lane_type: impl Into) -> BoundInstruction { - let value_type = ValueType::from(lane_type.into()); - - let (inst, value_types) = match target.into() { - InstSpec::Inst(inst) => (inst, vec![value_type]), - InstSpec::Bound(bound_inst) => { - let mut new_value_types = bound_inst.value_types; - new_value_types.push(value_type); - (bound_inst.inst, new_value_types) - } - }; - +/// Helper bind reused by {Bound,}Instruction::bind. +fn bind( + inst: Instruction, + lane_type: LaneType, + mut value_types: Vec, +) -> BoundInstruction { + value_types.push(ValueType::from(lane_type)); match &inst.polymorphic_info { Some(poly) => { assert!( @@ -652,6 +657,5 @@ pub fn bind(target: impl Into, lane_type: impl Into) -> Boun )); } } - BoundInstruction { inst, value_types } } diff --git a/cranelift/codegen/meta/src/isa/x86/legalize.rs b/cranelift/codegen/meta/src/isa/x86/legalize.rs index 853dff2c17..b214c26914 100644 --- a/cranelift/codegen/meta/src/isa/x86/legalize.rs +++ b/cranelift/codegen/meta/src/isa/x86/legalize.rs @@ -1,5 +1,5 @@ use crate::cdsl::ast::{var, ExprBuilder, Literal}; -use crate::cdsl::inst::{bind, InstructionGroup}; +use crate::cdsl::inst::InstructionGroup; use crate::cdsl::xform::TransformGroupBuilder; use crate::shared::types::Int::{I32, I64}; diff --git a/cranelift/codegen/meta/src/shared/legalize.rs b/cranelift/codegen/meta/src/shared/legalize.rs index 435e28187a..66ce180c1c 100644 --- a/cranelift/codegen/meta/src/shared/legalize.rs +++ b/cranelift/codegen/meta/src/shared/legalize.rs @@ -1,5 +1,5 @@ use crate::cdsl::ast::{var, ExprBuilder, Literal}; -use crate::cdsl::inst::{bind, Instruction, InstructionGroup}; +use crate::cdsl::inst::{Instruction, InstructionGroup}; use crate::cdsl::xform::{TransformGroupBuilder, TransformGroups}; use crate::shared::OperandKinds; @@ -352,7 +352,7 @@ pub fn define(insts: &InstructionGroup, immediates: &OperandKinds) -> TransformG for &extend_op in &[uextend, sextend] { // The sign extension operators have two typevars: the result has one and controls the // instruction, then the input has one. - let bound = bind(bind(extend_op, I16), I8); + let bound = extend_op.bind(I16).bind(I8); widen.legalize( def!(a = bound(b)), vec![def!(c = extend_op.I32(b)), def!(a = ireduce(c))], @@ -520,7 +520,7 @@ pub fn define(insts: &InstructionGroup, immediates: &OperandKinds) -> TransformG // group. for &dest_ty in &[F32, F64] { for &src_ty in &[I8, I16] { - let bound_inst = bind(bind(fcvt_from_uint, dest_ty), src_ty); + let bound_inst = fcvt_from_uint.bind(dest_ty).bind(src_ty); expand.legalize( def!(a = bound_inst(b)), vec![ @@ -529,7 +529,7 @@ pub fn define(insts: &InstructionGroup, immediates: &OperandKinds) -> TransformG ], ); - let bound_inst = bind(bind(fcvt_from_sint, dest_ty), src_ty); + let bound_inst = fcvt_from_sint.bind(dest_ty).bind(src_ty); expand.legalize( def!(a = bound_inst(b)), vec![