From 93f79d7a488dac4d6e6960d906055d7126db46e5 Mon Sep 17 00:00:00 2001 From: Jakob Stoklund Olesen Date: Wed, 12 Oct 2016 16:01:06 -0700 Subject: [PATCH] Move second_result outside boxed storage. In instruction formats that have multiple results AND boxed storage, place the second_result field outside the boxed storage. The 16-byte instruction format has room for opcode, type, second_result in the first 8 bytes, and the boxed pointer in the last 8 bytes. This provides a simpler implementation of the second_result() and second_result_mut() InstructionData methods. --- cranelift/src/libcretonne/ir/instructions.rs | 6 ++-- cranelift/src/libreader/parser.rs | 6 ++-- meta/gen_instr.py | 38 +++++++------------- 3 files changed, 16 insertions(+), 34 deletions(-) diff --git a/cranelift/src/libcretonne/ir/instructions.rs b/cranelift/src/libcretonne/ir/instructions.rs index b971a05ffa..37b1106d36 100644 --- a/cranelift/src/libcretonne/ir/instructions.rs +++ b/cranelift/src/libcretonne/ir/instructions.rs @@ -158,6 +158,7 @@ pub enum InstructionData { TernaryOverflow { opcode: Opcode, ty: Type, + second_result: Value, data: Box, }, InsertLane { @@ -203,6 +204,7 @@ pub enum InstructionData { Call { opcode: Opcode, ty: Type, + second_result: Value, data: Box, }, Return { @@ -284,7 +286,6 @@ impl Display for UnaryImmVectorData { /// Payload data for ternary instructions with multiple results, such as `iadd_carry`. #[derive(Clone, Debug)] pub struct TernaryOverflowData { - pub second_result: Value, pub args: [Value; 3], } @@ -334,9 +335,6 @@ impl Display for BranchData { /// Payload of a call instruction. #[derive(Clone, Debug)] pub struct CallData { - /// Second result value for a call producing multiple return values. - second_result: Value, - /// Callee function. pub func_ref: FuncRef, diff --git a/cranelift/src/libreader/parser.rs b/cranelift/src/libreader/parser.rs index 5023195e11..5c86e4e21a 100644 --- a/cranelift/src/libreader/parser.rs +++ b/cranelift/src/libreader/parser.rs @@ -1089,10 +1089,8 @@ impl<'a> Parser<'a> { InstructionData::TernaryOverflow { opcode: opcode, ty: VOID, - data: Box::new(TernaryOverflowData { - second_result: NO_VALUE, - args: [lhs, rhs, cin], - }), + second_result: NO_VALUE, + data: Box::new(TernaryOverflowData { args: [lhs, rhs, cin] }), } } InstructionFormat::Jump => { diff --git a/meta/gen_instr.py b/meta/gen_instr.py index 582c0477f0..26783ae82f 100644 --- a/meta/gen_instr.py +++ b/meta/gen_instr.py @@ -87,23 +87,16 @@ def gen_instruction_data_impl(fmt): 'pub fn second_result(&self) -> Option {', '}'): with fmt.indented('match *self {', '}'): for f in cretonne.InstructionFormat.all_formats: - if not f.multiple_results: - # Single or no results. - fmt.line( - 'InstructionData::{} {{ .. }} => None,' - .format(f.name)) - elif f.boxed_storage: - # Multiple results, boxed storage. - fmt.line( - 'InstructionData::' + f.name + - ' { ref data, .. }' + - ' => Some(data.second_result),') - else: - # Multiple results, inline storage. + if f.multiple_results: fmt.line( 'InstructionData::' + f.name + ' { second_result, .. }' + ' => Some(second_result),') + else: + # Single or no results. + fmt.line( + 'InstructionData::{} {{ .. }} => None,' + .format(f.name)) fmt.doc_comment('Mutable reference to second result value, if any.') with fmt.indented( @@ -111,23 +104,16 @@ def gen_instruction_data_impl(fmt): " -> Option<&'a mut Value> {", '}'): with fmt.indented('match *self {', '}'): for f in cretonne.InstructionFormat.all_formats: - if not f.multiple_results: - # Single or no results. - fmt.line( - 'InstructionData::{} {{ .. }} => None,' - .format(f.name)) - elif f.boxed_storage: - # Multiple results, boxed storage. - fmt.line( - 'InstructionData::' + f.name + - ' { ref mut data, .. }' + - ' => Some(&mut data.second_result),') - else: - # Multiple results, inline storage. + if f.multiple_results: fmt.line( 'InstructionData::' + f.name + ' { ref mut second_result, .. }' + ' => Some(second_result),') + else: + # Single or no results. + fmt.line( + 'InstructionData::{} {{ .. }} => None,' + .format(f.name)) fmt.doc_comment('Get the controlling type variable operand.') with fmt.indented(