diff --git a/lib/cretonne/meta/gen_instr.py b/lib/cretonne/meta/gen_instr.py index 4d71e1e5b4..b1b32b7bf3 100644 --- a/lib/cretonne/meta/gen_instr.py +++ b/lib/cretonne/meta/gen_instr.py @@ -109,16 +109,14 @@ def gen_instruction_data_impl(fmt): the instruction formats: - `pub fn opcode(&self) -> Opcode` - - `pub fn first_type(&self) -> Type` - `pub fn arguments(&self, &pool) -> &[Value]` - `pub fn arguments_mut(&mut self, &pool) -> &mut [Value]` - `pub fn take_value_list(&mut self) -> Option` - `pub fn put_value_list(&mut self, args: ValueList>` """ - # The `opcode` and `first_type` methods simply read the `opcode` and `ty` - # members. This is really a workaround for Rust's enum types missing shared - # members. + # The `opcode` method simply reads the `opcode` members. This is really a + # workaround for Rust's enum types missing shared members. with fmt.indented('impl InstructionData {', '}'): fmt.doc_comment('Get the opcode of this instruction.') with fmt.indented('pub fn opcode(&self) -> Opcode {', '}'): @@ -128,23 +126,6 @@ def gen_instruction_data_impl(fmt): 'InstructionData::{} {{ opcode, .. }} => opcode,' .format(f.name)) - fmt.doc_comment('Type of the first result, or `VOID`.') - with fmt.indented('pub fn first_type(&self) -> Type {', '}'): - with fmt.indented('match *self {', '}'): - for f in InstructionFormat.all_formats: - fmt.line( - 'InstructionData::{} {{ ty, .. }} => ty,' - .format(f.name)) - - fmt.doc_comment('Mutable reference to the type of the first result.') - with fmt.indented( - 'pub fn first_type_mut(&mut self) -> &mut Type {', '}'): - with fmt.indented('match *self {', '}'): - for f in InstructionFormat.all_formats: - fmt.line( - 'InstructionData::{} {{ ref mut ty, .. }} => ty,' - .format(f.name)) - fmt.doc_comment('Get the controlling type variable operand.') with fmt.indented( 'pub fn typevar_operand(&self, pool: &ValueListPool) -> ' @@ -490,7 +471,6 @@ def gen_format_constructor(iform, fmt): with fmt.indented( 'let data = InstructionData::{} {{'.format(iform.name), '};'): fmt.line('opcode: opcode,') - fmt.line('ty: types::VOID,') gen_member_inits(iform, fmt) fmt.line('self.build(data, ctrl_typevar)') diff --git a/lib/cretonne/src/ir/builder.rs b/lib/cretonne/src/ir/builder.rs index 312e5144da..0414f7c282 100644 --- a/lib/cretonne/src/ir/builder.rs +++ b/lib/cretonne/src/ir/builder.rs @@ -117,12 +117,6 @@ impl<'f> InstBuilderBase<'f> for ReplaceBuilder<'f> { // The old result values were either detached or non-existent. // Construct new ones. self.dfg.make_inst_results(self.inst, ctrl_typevar); - } else { - // Normally, make_inst_results() would also set the first result type, but we're not - // going to call that, so set it manually. - *self.dfg[self.inst].first_type_mut() = self.dfg - .compute_result_type(self.inst, 0, ctrl_typevar) - .unwrap_or_default(); } (self.inst, self.dfg) diff --git a/lib/cretonne/src/ir/dfg.rs b/lib/cretonne/src/ir/dfg.rs index 1aebfbb03e..49392d8bfb 100644 --- a/lib/cretonne/src/ir/dfg.rs +++ b/lib/cretonne/src/ir/dfg.rs @@ -132,7 +132,7 @@ impl DataFlowGraph { pub fn value_type(&self, v: Value) -> Type { use ir::entities::ExpandedValue::*; match v.expand() { - Direct(i) => self.insts[i].first_type(), + Direct(_) => panic!("Unexpected direct value"), Table(i) => { match self.extended_values[i] { ValueData::Inst { ty, .. } => ty, @@ -411,11 +411,6 @@ impl DataFlowGraph { } } - if let Some(v) = self.results[inst].first(&mut self.value_lists) { - let ty = self.value_type(v); - *self[inst].first_type_mut() = ty; - } - total_results } @@ -725,10 +720,7 @@ mod tests { fn make_inst() { let mut dfg = DataFlowGraph::new(); - let idata = InstructionData::Nullary { - opcode: Opcode::Iconst, - ty: types::VOID, - }; + let idata = InstructionData::Nullary { opcode: Opcode::Iconst }; let inst = dfg.make_inst(idata); dfg.make_inst_results(inst, types::I32); assert_eq!(inst.to_string(), "inst0"); @@ -739,7 +731,6 @@ mod tests { let immdfg = &dfg; let ins = &immdfg[inst]; assert_eq!(ins.opcode(), Opcode::Iconst); - assert_eq!(ins.first_type(), types::I32); } // Results. @@ -754,10 +745,7 @@ mod tests { fn no_results() { let mut dfg = DataFlowGraph::new(); - let idata = InstructionData::Nullary { - opcode: Opcode::Trap, - ty: types::VOID, - }; + let idata = InstructionData::Nullary { opcode: Opcode::Trap }; let inst = dfg.make_inst(idata); assert_eq!(dfg.display_inst(inst).to_string(), "trap"); diff --git a/lib/cretonne/src/ir/instructions.rs b/lib/cretonne/src/ir/instructions.rs index 1e1262a507..61ed2f1eeb 100644 --- a/lib/cretonne/src/ir/instructions.rs +++ b/lib/cretonne/src/ir/instructions.rs @@ -100,161 +100,107 @@ impl FromStr for Opcode { #[derive(Clone, Debug)] #[allow(missing_docs)] pub enum InstructionData { - Nullary { opcode: Opcode, ty: Type }, - Unary { - opcode: Opcode, - ty: Type, - arg: Value, - }, - UnaryImm { - opcode: Opcode, - ty: Type, - imm: Imm64, - }, - UnaryIeee32 { - opcode: Opcode, - ty: Type, - imm: Ieee32, - }, - UnaryIeee64 { - opcode: Opcode, - ty: Type, - imm: Ieee64, - }, - UnarySplit { - opcode: Opcode, - ty: Type, - arg: Value, - }, - Binary { - opcode: Opcode, - ty: Type, - args: [Value; 2], - }, + Nullary { opcode: Opcode }, + Unary { opcode: Opcode, arg: Value }, + UnaryImm { opcode: Opcode, imm: Imm64 }, + UnaryIeee32 { opcode: Opcode, imm: Ieee32 }, + UnaryIeee64 { opcode: Opcode, imm: Ieee64 }, + UnarySplit { opcode: Opcode, arg: Value }, + Binary { opcode: Opcode, args: [Value; 2] }, BinaryImm { opcode: Opcode, - ty: Type, arg: Value, imm: Imm64, }, - BinaryOverflow { - opcode: Opcode, - ty: Type, - args: [Value; 2], - }, - Ternary { - opcode: Opcode, - ty: Type, - args: [Value; 3], - }, - MultiAry { - opcode: Opcode, - ty: Type, - args: ValueList, - }, + BinaryOverflow { opcode: Opcode, args: [Value; 2] }, + Ternary { opcode: Opcode, args: [Value; 3] }, + MultiAry { opcode: Opcode, args: ValueList }, InsertLane { opcode: Opcode, - ty: Type, lane: Uimm8, args: [Value; 2], }, ExtractLane { opcode: Opcode, - ty: Type, lane: Uimm8, arg: Value, }, IntCompare { opcode: Opcode, - ty: Type, cond: IntCC, args: [Value; 2], }, IntCompareImm { opcode: Opcode, - ty: Type, cond: IntCC, arg: Value, imm: Imm64, }, FloatCompare { opcode: Opcode, - ty: Type, cond: FloatCC, args: [Value; 2], }, Jump { opcode: Opcode, - ty: Type, destination: Ebb, args: ValueList, }, Branch { opcode: Opcode, - ty: Type, destination: Ebb, args: ValueList, }, BranchIcmp { opcode: Opcode, - ty: Type, cond: IntCC, destination: Ebb, args: ValueList, }, BranchTable { opcode: Opcode, - ty: Type, arg: Value, table: JumpTable, }, Call { opcode: Opcode, - ty: Type, func_ref: FuncRef, args: ValueList, }, IndirectCall { opcode: Opcode, - ty: Type, sig_ref: SigRef, args: ValueList, }, StackLoad { opcode: Opcode, - ty: Type, stack_slot: StackSlot, offset: Offset32, }, StackStore { opcode: Opcode, - ty: Type, arg: Value, stack_slot: StackSlot, offset: Offset32, }, HeapLoad { opcode: Opcode, - ty: Type, arg: Value, offset: Uoffset32, }, HeapStore { opcode: Opcode, - ty: Type, args: [Value; 2], offset: Uoffset32, }, Load { opcode: Opcode, - ty: Type, flags: MemFlags, arg: Value, offset: Offset32, }, Store { opcode: Opcode, - ty: Type, flags: MemFlags, args: [Value; 2], offset: Offset32, diff --git a/lib/cretonne/src/isa/riscv/mod.rs b/lib/cretonne/src/isa/riscv/mod.rs index b1f399665b..8bf9d7b732 100644 --- a/lib/cretonne/src/isa/riscv/mod.rs +++ b/lib/cretonne/src/isa/riscv/mod.rs @@ -118,7 +118,6 @@ mod tests { // Try to encode iadd_imm.i64 vx1, -10. let inst64 = InstructionData::BinaryImm { opcode: Opcode::IaddImm, - ty: types::I64, arg: arg64, imm: immediates::Imm64::new(-10), }; @@ -130,7 +129,6 @@ mod tests { // Try to encode iadd_imm.i64 vx1, -10000. let inst64_large = InstructionData::BinaryImm { opcode: Opcode::IaddImm, - ty: types::I64, arg: arg64, imm: immediates::Imm64::new(-10000), }; @@ -142,7 +140,6 @@ mod tests { // Create an iadd_imm.i32 which is encodable in RV64. let inst32 = InstructionData::BinaryImm { opcode: Opcode::IaddImm, - ty: types::I32, arg: arg32, imm: immediates::Imm64::new(10), }; @@ -168,7 +165,6 @@ mod tests { // Try to encode iadd_imm.i64 vx1, -10. let inst64 = InstructionData::BinaryImm { opcode: Opcode::IaddImm, - ty: types::I64, arg: arg64, imm: immediates::Imm64::new(-10), }; @@ -180,7 +176,6 @@ mod tests { // Try to encode iadd_imm.i64 vx1, -10000. let inst64_large = InstructionData::BinaryImm { opcode: Opcode::IaddImm, - ty: types::I64, arg: arg64, imm: immediates::Imm64::new(-10000), }; @@ -192,7 +187,6 @@ mod tests { // Create an iadd_imm.i32 which is encodable in RV32. let inst32 = InstructionData::BinaryImm { opcode: Opcode::IaddImm, - ty: types::I32, arg: arg32, imm: immediates::Imm64::new(10), }; @@ -204,7 +198,6 @@ mod tests { // Create an imul.i32 which is encodable in RV32, but only when use_m is true. let mul32 = InstructionData::Binary { opcode: Opcode::Imul, - ty: types::I32, args: [arg32, arg32], }; @@ -232,7 +225,6 @@ mod tests { // Create an imul.i32 which is encodable in RV32M. let mul32 = InstructionData::Binary { opcode: Opcode::Imul, - ty: types::I32, args: [arg32, arg32], }; assert_eq!(encstr(&*isa, isa.encode(&dfg, &mul32, types::I32).unwrap()), diff --git a/lib/cretonne/src/verifier.rs b/lib/cretonne/src/verifier.rs index 0b84ad82bd..7a287a64bd 100644 --- a/lib/cretonne/src/verifier.rs +++ b/lib/cretonne/src/verifier.rs @@ -183,23 +183,13 @@ impl<'a> Verifier<'a> { .unwrap_or(0); let total_results = fixed_results + var_results; - if total_results == 0 { - // Instructions with no results have a NULL `first_type()` - let ret_type = inst_data.first_type(); - if ret_type != types::VOID { - return err!(inst, - "instruction with no results expects NULL return type, found {}", - ret_type); - } - } else { - // All result values for multi-valued instructions are created - let got_results = dfg.inst_results(inst).len(); - if got_results != total_results { - return err!(inst, - "expected {} result values, found {}", - total_results, - got_results); - } + // All result values for multi-valued instructions are created + let got_results = dfg.inst_results(inst).len(); + if got_results != total_results { + return err!(inst, + "expected {} result values, found {}", + total_results, + got_results); } self.verify_entity_references(inst) @@ -671,7 +661,6 @@ mod tests { use super::{Verifier, Error}; use ir::Function; use ir::instructions::{InstructionData, Opcode}; - use ir::types; macro_rules! assert_err_with_msg { ($e:expr, $msg:expr) => ( @@ -698,11 +687,9 @@ mod tests { let mut func = Function::new(); let ebb0 = func.dfg.make_ebb(); func.layout.append_ebb(ebb0); - let nullary_with_bad_opcode = func.dfg - .make_inst(InstructionData::Nullary { - opcode: Opcode::Jump, - ty: types::VOID, - }); + let nullary_with_bad_opcode = + func.dfg + .make_inst(InstructionData::Nullary { opcode: Opcode::Jump }); func.layout.append_inst(nullary_with_bad_opcode, ebb0); let verifier = Verifier::new(&func); assert_err_with_msg!(verifier.run(), "instruction format"); diff --git a/lib/reader/src/parser.rs b/lib/reader/src/parser.rs index a501d6aaa3..dcc76b1b15 100644 --- a/lib/reader/src/parser.rs +++ b/lib/reader/src/parser.rs @@ -1404,44 +1404,34 @@ impl<'a> Parser<'a> { opcode: Opcode) -> Result { let idata = match opcode.format() { - InstructionFormat::Nullary => { - InstructionData::Nullary { - opcode: opcode, - ty: VOID, - } - } + InstructionFormat::Nullary => InstructionData::Nullary { opcode: opcode }, InstructionFormat::Unary => { InstructionData::Unary { opcode: opcode, - ty: VOID, arg: self.match_value("expected SSA value operand")?, } } InstructionFormat::UnaryImm => { InstructionData::UnaryImm { opcode: opcode, - ty: VOID, imm: self.match_imm64("expected immediate integer operand")?, } } InstructionFormat::UnaryIeee32 => { InstructionData::UnaryIeee32 { opcode: opcode, - ty: VOID, imm: self.match_ieee32("expected immediate 32-bit float operand")?, } } InstructionFormat::UnaryIeee64 => { InstructionData::UnaryIeee64 { opcode: opcode, - ty: VOID, imm: self.match_ieee64("expected immediate 64-bit float operand")?, } } InstructionFormat::UnarySplit => { InstructionData::UnarySplit { opcode: opcode, - ty: VOID, arg: self.match_value("expected SSA value operand")?, } } @@ -1451,7 +1441,6 @@ impl<'a> Parser<'a> { let rhs = self.match_value("expected SSA value second operand")?; InstructionData::Binary { opcode: opcode, - ty: VOID, args: [lhs, rhs], } } @@ -1461,7 +1450,6 @@ impl<'a> Parser<'a> { let rhs = self.match_imm64("expected immediate integer second operand")?; InstructionData::BinaryImm { opcode: opcode, - ty: VOID, arg: lhs, imm: rhs, } @@ -1472,7 +1460,6 @@ impl<'a> Parser<'a> { let rhs = self.match_value("expected SSA value second operand")?; InstructionData::BinaryOverflow { opcode: opcode, - ty: VOID, args: [lhs, rhs], } } @@ -1486,7 +1473,6 @@ impl<'a> Parser<'a> { let false_arg = self.match_value("expected SSA value false operand")?; InstructionData::Ternary { opcode: opcode, - ty: VOID, args: [ctrl_arg, true_arg, false_arg], } } @@ -1494,7 +1480,6 @@ impl<'a> Parser<'a> { let args = self.parse_value_list()?; InstructionData::MultiAry { opcode: opcode, - ty: VOID, args: args.into_value_list(&[], &mut ctx.function.dfg.value_lists), } } @@ -1504,7 +1489,6 @@ impl<'a> Parser<'a> { let args = self.parse_opt_value_list()?; InstructionData::Jump { opcode: opcode, - ty: VOID, destination: ebb_num, args: args.into_value_list(&[], &mut ctx.function.dfg.value_lists), } @@ -1516,7 +1500,6 @@ impl<'a> Parser<'a> { let args = self.parse_opt_value_list()?; InstructionData::Branch { opcode: opcode, - ty: VOID, destination: ebb_num, args: args.into_value_list(&[ctrl_arg], &mut ctx.function.dfg.value_lists), } @@ -1531,7 +1514,6 @@ impl<'a> Parser<'a> { let args = self.parse_opt_value_list()?; InstructionData::BranchIcmp { opcode: opcode, - ty: VOID, cond: cond, destination: ebb_num, args: args.into_value_list(&[lhs, rhs], &mut ctx.function.dfg.value_lists), @@ -1545,7 +1527,6 @@ impl<'a> Parser<'a> { let rhs = self.match_value("expected SSA value last operand")?; InstructionData::InsertLane { opcode: opcode, - ty: VOID, lane: lane, args: [lhs, rhs], } @@ -1556,7 +1537,6 @@ impl<'a> Parser<'a> { let lane = self.match_uimm8("expected lane number")?; InstructionData::ExtractLane { opcode: opcode, - ty: VOID, lane: lane, arg: arg, } @@ -1568,7 +1548,6 @@ impl<'a> Parser<'a> { let rhs = self.match_value("expected SSA value second operand")?; InstructionData::IntCompare { opcode: opcode, - ty: VOID, cond: cond, args: [lhs, rhs], } @@ -1580,7 +1559,6 @@ impl<'a> Parser<'a> { let rhs = self.match_imm64("expected immediate second operand")?; InstructionData::IntCompareImm { opcode: opcode, - ty: VOID, cond: cond, arg: lhs, imm: rhs, @@ -1593,7 +1571,6 @@ impl<'a> Parser<'a> { let rhs = self.match_value("expected SSA value second operand")?; InstructionData::FloatCompare { opcode: opcode, - ty: VOID, cond: cond, args: [lhs, rhs], } @@ -1606,7 +1583,6 @@ impl<'a> Parser<'a> { self.match_token(Token::RPar, "expected ')' after arguments")?; InstructionData::Call { opcode: opcode, - ty: VOID, func_ref: func_ref, args: args.into_value_list(&[], &mut ctx.function.dfg.value_lists), } @@ -1621,7 +1597,6 @@ impl<'a> Parser<'a> { self.match_token(Token::RPar, "expected ')' after arguments")?; InstructionData::IndirectCall { opcode: opcode, - ty: VOID, sig_ref: sig_ref, args: args.into_value_list(&[callee], &mut ctx.function.dfg.value_lists), } @@ -1633,7 +1608,6 @@ impl<'a> Parser<'a> { .and_then(|num| ctx.get_jt(num, &self.loc))?; InstructionData::BranchTable { opcode: opcode, - ty: VOID, arg: arg, table: table, } @@ -1644,7 +1618,6 @@ impl<'a> Parser<'a> { let offset = self.optional_offset32()?; InstructionData::StackLoad { opcode: opcode, - ty: VOID, stack_slot: ss, offset: offset, } @@ -1657,7 +1630,6 @@ impl<'a> Parser<'a> { let offset = self.optional_offset32()?; InstructionData::StackStore { opcode: opcode, - ty: VOID, arg: arg, stack_slot: ss, offset: offset, @@ -1668,7 +1640,6 @@ impl<'a> Parser<'a> { let offset = self.optional_uoffset32()?; InstructionData::HeapLoad { opcode: opcode, - ty: VOID, arg: addr, offset: offset, } @@ -1680,7 +1651,6 @@ impl<'a> Parser<'a> { let offset = self.optional_uoffset32()?; InstructionData::HeapStore { opcode: opcode, - ty: VOID, args: [arg, addr], offset: offset, } @@ -1691,7 +1661,6 @@ impl<'a> Parser<'a> { let offset = self.optional_offset32()?; InstructionData::Load { opcode: opcode, - ty: VOID, flags: flags, arg: addr, offset: offset, @@ -1705,7 +1674,6 @@ impl<'a> Parser<'a> { let offset = self.optional_offset32()?; InstructionData::Store { opcode: opcode, - ty: VOID, flags: flags, args: [arg, addr], offset: offset,