[meta] Have bind() be a method of {Bound,}Instruction instead of a static method;

This commit is contained in:
Benjamin Bouvier
2019-05-23 12:01:25 +02:00
parent 724d1cd2a1
commit 6935033c9e
4 changed files with 23 additions and 19 deletions

View File

@@ -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()),*])
};
}

View File

@@ -143,6 +143,10 @@ impl Instruction {
None => Vec::new(),
}
}
pub fn bind(&self, lane_type: impl Into<LaneType>) -> 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<ValueType>,
}
impl BoundInstruction {
pub fn bind(self, lane_type: impl Into<LaneType>) -> 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<Operand>,
@@ -626,18 +636,13 @@ impl Into<InstSpec> for BoundInstruction {
}
}
pub fn bind(target: impl Into<InstSpec>, lane_type: impl Into<LaneType>) -> 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<ValueType>,
) -> 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<InstSpec>, lane_type: impl Into<LaneType>) -> Boun
));
}
}
BoundInstruction { inst, value_types }
}

View File

@@ -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};

View File

@@ -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![