diff --git a/cranelift/codegen/meta/src/cdsl/ast.rs b/cranelift/codegen/meta/src/cdsl/ast.rs index 1df8ea3050..46214e2abf 100644 --- a/cranelift/codegen/meta/src/cdsl/ast.rs +++ b/cranelift/codegen/meta/src/cdsl/ast.rs @@ -1,7 +1,7 @@ use crate::cdsl::formats::FormatRegistry; -use crate::cdsl::inst::{BoundInstruction, Instruction, InstructionPredicate}; +use crate::cdsl::inst::{ApplyTarget, Instruction, InstructionPredicate}; use crate::cdsl::operands::{OperandKind, OperandKindFields}; -use crate::cdsl::types::{LaneType, ValueType}; +use crate::cdsl::types::ValueType; use crate::cdsl::typevar::{TypeSetBuilder, TypeVar}; use cranelift_entity::{entity_impl, PrimaryMap}; @@ -364,62 +364,6 @@ impl VarPool { } } -pub enum ApplyTarget { - Inst(Instruction), - Bound(BoundInstruction), -} - -impl ApplyTarget { - pub fn inst(&self) -> &Instruction { - match &self { - ApplyTarget::Inst(inst) => inst, - ApplyTarget::Bound(bound_inst) => &bound_inst.inst, - } - } -} - -impl Into for &Instruction { - fn into(self) -> ApplyTarget { - ApplyTarget::Inst(self.clone()) - } -} - -impl Into for BoundInstruction { - fn into(self) -> ApplyTarget { - ApplyTarget::Bound(self) - } -} - -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() { - ApplyTarget::Inst(inst) => (inst, vec![value_type]), - ApplyTarget::Bound(bound_inst) => { - let mut new_value_types = bound_inst.value_types; - new_value_types.push(value_type); - (bound_inst.inst, new_value_types) - } - }; - - match &inst.polymorphic_info { - Some(poly) => { - assert!( - value_types.len() <= 1 + poly.other_typevars.len(), - format!("trying to bind too many types for {}", inst.name) - ); - } - None => { - panic!(format!( - "trying to bind a type for {} which is not a polymorphic instruction", - inst.name - )); - } - } - - BoundInstruction { inst, value_types } -} - /// Apply an instruction to arguments. /// /// An `Apply` AST expression is created by using function call syntax on instructions. This diff --git a/cranelift/codegen/meta/src/cdsl/inst.rs b/cranelift/codegen/meta/src/cdsl/inst.rs index 3cd722c260..6b9bfe60a1 100644 --- a/cranelift/codegen/meta/src/cdsl/inst.rs +++ b/cranelift/codegen/meta/src/cdsl/inst.rs @@ -4,7 +4,7 @@ use crate::cdsl::formats::{ }; use crate::cdsl::operands::Operand; use crate::cdsl::type_inference::Constraint; -use crate::cdsl::types::ValueType; +use crate::cdsl::types::{LaneType, ValueType}; use crate::cdsl::typevar::TypeVar; use std::fmt; @@ -598,3 +598,59 @@ impl InstructionPredicate { } } } + +pub enum ApplyTarget { + Inst(Instruction), + Bound(BoundInstruction), +} + +impl ApplyTarget { + pub fn inst(&self) -> &Instruction { + match &self { + ApplyTarget::Inst(inst) => inst, + ApplyTarget::Bound(bound_inst) => &bound_inst.inst, + } + } +} + +impl Into for &Instruction { + fn into(self) -> ApplyTarget { + ApplyTarget::Inst(self.clone()) + } +} + +impl Into for BoundInstruction { + fn into(self) -> ApplyTarget { + ApplyTarget::Bound(self) + } +} + +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() { + ApplyTarget::Inst(inst) => (inst, vec![value_type]), + ApplyTarget::Bound(bound_inst) => { + let mut new_value_types = bound_inst.value_types; + new_value_types.push(value_type); + (bound_inst.inst, new_value_types) + } + }; + + match &inst.polymorphic_info { + Some(poly) => { + assert!( + value_types.len() <= 1 + poly.other_typevars.len(), + format!("trying to bind too many types for {}", inst.name) + ); + } + None => { + panic!(format!( + "trying to bind a type for {} which is not a polymorphic instruction", + inst.name + )); + } + } + + 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 7a0cd8379c..853dff2c17 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::{bind, var, ExprBuilder, Literal}; -use crate::cdsl::inst::InstructionGroup; +use crate::cdsl::ast::{var, ExprBuilder, Literal}; +use crate::cdsl::inst::{bind, 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 93819fc430..435e28187a 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::{bind, var, ExprBuilder, Literal}; -use crate::cdsl::inst::{Instruction, InstructionGroup}; +use crate::cdsl::ast::{var, ExprBuilder, Literal}; +use crate::cdsl::inst::{bind, Instruction, InstructionGroup}; use crate::cdsl::xform::{TransformGroupBuilder, TransformGroups}; use crate::shared::OperandKinds;