[meta] Move ApplyTarget/bind to cdsl/inst;
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
use crate::cdsl::formats::FormatRegistry;
|
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::operands::{OperandKind, OperandKindFields};
|
||||||
use crate::cdsl::types::{LaneType, ValueType};
|
use crate::cdsl::types::ValueType;
|
||||||
use crate::cdsl::typevar::{TypeSetBuilder, TypeVar};
|
use crate::cdsl::typevar::{TypeSetBuilder, TypeVar};
|
||||||
|
|
||||||
use cranelift_entity::{entity_impl, PrimaryMap};
|
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<ApplyTarget> for &Instruction {
|
|
||||||
fn into(self) -> ApplyTarget {
|
|
||||||
ApplyTarget::Inst(self.clone())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Into<ApplyTarget> for BoundInstruction {
|
|
||||||
fn into(self) -> ApplyTarget {
|
|
||||||
ApplyTarget::Bound(self)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn bind(target: impl Into<ApplyTarget>, lane_type: impl Into<LaneType>) -> 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.
|
/// Apply an instruction to arguments.
|
||||||
///
|
///
|
||||||
/// An `Apply` AST expression is created by using function call syntax on instructions. This
|
/// An `Apply` AST expression is created by using function call syntax on instructions. This
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ use crate::cdsl::formats::{
|
|||||||
};
|
};
|
||||||
use crate::cdsl::operands::Operand;
|
use crate::cdsl::operands::Operand;
|
||||||
use crate::cdsl::type_inference::Constraint;
|
use crate::cdsl::type_inference::Constraint;
|
||||||
use crate::cdsl::types::ValueType;
|
use crate::cdsl::types::{LaneType, ValueType};
|
||||||
use crate::cdsl::typevar::TypeVar;
|
use crate::cdsl::typevar::TypeVar;
|
||||||
|
|
||||||
use std::fmt;
|
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<ApplyTarget> for &Instruction {
|
||||||
|
fn into(self) -> ApplyTarget {
|
||||||
|
ApplyTarget::Inst(self.clone())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Into<ApplyTarget> for BoundInstruction {
|
||||||
|
fn into(self) -> ApplyTarget {
|
||||||
|
ApplyTarget::Bound(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn bind(target: impl Into<ApplyTarget>, lane_type: impl Into<LaneType>) -> 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 }
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use crate::cdsl::ast::{bind, var, ExprBuilder, Literal};
|
use crate::cdsl::ast::{var, ExprBuilder, Literal};
|
||||||
use crate::cdsl::inst::InstructionGroup;
|
use crate::cdsl::inst::{bind, InstructionGroup};
|
||||||
use crate::cdsl::xform::TransformGroupBuilder;
|
use crate::cdsl::xform::TransformGroupBuilder;
|
||||||
|
|
||||||
use crate::shared::types::Int::{I32, I64};
|
use crate::shared::types::Int::{I32, I64};
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use crate::cdsl::ast::{bind, var, ExprBuilder, Literal};
|
use crate::cdsl::ast::{var, ExprBuilder, Literal};
|
||||||
use crate::cdsl::inst::{Instruction, InstructionGroup};
|
use crate::cdsl::inst::{bind, Instruction, InstructionGroup};
|
||||||
use crate::cdsl::xform::{TransformGroupBuilder, TransformGroups};
|
use crate::cdsl::xform::{TransformGroupBuilder, TransformGroups};
|
||||||
|
|
||||||
use crate::shared::OperandKinds;
|
use crate::shared::OperandKinds;
|
||||||
|
|||||||
Reference in New Issue
Block a user