From d301fb9f2b3fce6b289ec0e680fee5c2157154c6 Mon Sep 17 00:00:00 2001 From: Jakob Stoklund Olesen Date: Thu, 9 Mar 2017 15:56:33 -0800 Subject: [PATCH] Convert return formats to value lists. With the Return and ReturnReg formats converted to using value lists for storing their arguments, thee are no remaining instruction formats with variable argument lists in boxed storage. The Return and ReturnReg formats are also going to be merged since they are identical now. --- lib/cretonne/meta/base/formats.py | 4 ++-- lib/cretonne/meta/cdsl/formats.py | 4 ++++ lib/cretonne/src/ir/builder.rs | 2 +- lib/cretonne/src/ir/instructions.rs | 32 ++--------------------------- lib/cretonne/src/write.rs | 18 ++++++++-------- lib/reader/src/parser.rs | 18 +++++++--------- 6 files changed, 25 insertions(+), 53 deletions(-) diff --git a/lib/cretonne/meta/base/formats.py b/lib/cretonne/meta/base/formats.py index 9f7a805940..c72d5034f8 100644 --- a/lib/cretonne/meta/base/formats.py +++ b/lib/cretonne/meta/base/formats.py @@ -51,8 +51,8 @@ Call = InstructionFormat( IndirectCall = InstructionFormat( sig_ref, VALUE, VARIABLE_ARGS, multiple_results=True, value_list=True) -Return = InstructionFormat(VARIABLE_ARGS, boxed_storage=True) -ReturnReg = InstructionFormat(VALUE, VARIABLE_ARGS, boxed_storage=True) +Return = InstructionFormat(VARIABLE_ARGS, value_list=True) +ReturnReg = InstructionFormat(VALUE, VARIABLE_ARGS, value_list=True) # Finally extract the names of global variables in this module. InstructionFormat.extract_names(globals()) diff --git a/lib/cretonne/meta/cdsl/formats.py b/lib/cretonne/meta/cdsl/formats.py index 422d84c296..98f6964e5c 100644 --- a/lib/cretonne/meta/cdsl/formats.py +++ b/lib/cretonne/meta/cdsl/formats.py @@ -63,6 +63,10 @@ class InstructionFormat(object): self.value_operands = tuple( i for i, k in enumerate(self.kinds) if k is VALUE) + # We require a value list for storage of variable arguments. + if VARIABLE_ARGS in self.kinds: + assert self.has_value_list, "Need a value list for variable args" + # The typevar_operand argument must point to a 'value' operand. self.typevar_operand = kwargs.get('typevar_operand', None) # type: int if self.typevar_operand is not None: diff --git a/lib/cretonne/src/ir/builder.rs b/lib/cretonne/src/ir/builder.rs index ebb8ae2350..fa15587445 100644 --- a/lib/cretonne/src/ir/builder.rs +++ b/lib/cretonne/src/ir/builder.rs @@ -5,7 +5,7 @@ use ir::{types, instructions}; use ir::{InstructionData, DataFlowGraph, Cursor}; -use ir::{Opcode, Type, Inst, Value, Ebb, JumpTable, VariableArgs, SigRef, FuncRef, ValueList}; +use ir::{Opcode, Type, Inst, Value, Ebb, JumpTable, SigRef, FuncRef, ValueList}; use ir::immediates::{Imm64, Uimm8, Ieee32, Ieee64, ImmVector}; use ir::condcodes::{IntCC, FloatCC}; diff --git a/lib/cretonne/src/ir/instructions.rs b/lib/cretonne/src/ir/instructions.rs index d7393c9293..a3cd4509da 100644 --- a/lib/cretonne/src/ir/instructions.rs +++ b/lib/cretonne/src/ir/instructions.rs @@ -228,12 +228,12 @@ pub enum InstructionData { Return { opcode: Opcode, ty: Type, - data: Box, + args: ValueList, }, ReturnReg { opcode: Opcode, ty: Type, - data: Box, + args: ValueList, }, } @@ -331,34 +331,6 @@ impl Display for TernaryOverflowData { } } -/// Payload of a return instruction. -#[derive(Clone, Debug)] -pub struct ReturnData { - /// Dynamically sized array containing return values. - pub varargs: VariableArgs, -} - -/// Payload of a return instruction. -#[derive(Clone, Debug)] -pub struct ReturnRegData { - /// Return address. - pub arg: Value, - /// Dynamically sized array containing return values. - pub varargs: VariableArgs, -} - -impl ReturnRegData { - /// Get references to the arguments. - pub fn arguments(&self) -> [&[Value]; 2] { - [ref_slice(&self.arg), &self.varargs] - } - - /// Get mutable references to the arguments. - pub fn arguments_mut(&mut self) -> [&mut [Value]; 2] { - [ref_slice_mut(&mut self.arg), &mut self.varargs] - } -} - /// Analyzing an instruction. /// /// Avoid large matches on instruction formats by using the methods defined here to examine diff --git a/lib/cretonne/src/write.rs b/lib/cretonne/src/write.rs index 5e8968c48b..59c97d9283 100644 --- a/lib/cretonne/src/write.rs +++ b/lib/cretonne/src/write.rs @@ -282,19 +282,19 @@ fn write_instruction(w: &mut Write, args[0], DisplayValues(&args[1..])) } - Return { ref data, .. } => { - if data.varargs.is_empty() { + Return { ref args, .. } => { + if args.is_empty() { writeln!(w, "") } else { - writeln!(w, " {}", data.varargs) + writeln!(w, + " {}", + DisplayValues(args.as_slice(&func.dfg.value_lists))) } } - ReturnReg { ref data, .. } => { - if data.varargs.is_empty() { - writeln!(w, " {}", data.arg) - } else { - writeln!(w, " {}, {}", data.arg, data.varargs) - } + ReturnReg { ref args, .. } => { + writeln!(w, + " {}", + DisplayValues(args.as_slice(&func.dfg.value_lists))) } } } diff --git a/lib/reader/src/parser.rs b/lib/reader/src/parser.rs index 26fbe234a0..72f43a043d 100644 --- a/lib/reader/src/parser.rs +++ b/lib/reader/src/parser.rs @@ -15,7 +15,7 @@ use cretonne::ir::types::VOID; use cretonne::ir::immediates::{Imm64, Ieee32, Ieee64}; use cretonne::ir::entities::AnyEntity; use cretonne::ir::instructions::{InstructionFormat, InstructionData, VariableArgs, - TernaryOverflowData, ReturnData, ReturnRegData}; + TernaryOverflowData}; use cretonne::isa::{self, TargetIsa, Encoding}; use cretonne::settings; use testfile::{TestFile, Details, Comment}; @@ -217,13 +217,12 @@ impl<'a> Context<'a> { self.map.rewrite_values(args.as_mut_slice(value_lists), loc)?; } - InstructionData::Return { ref mut data, .. } => { - self.map.rewrite_values(&mut data.varargs, loc)?; + InstructionData::Return { ref mut args, .. } => { + self.map.rewrite_values(args.as_mut_slice(value_lists), loc)?; } - InstructionData::ReturnReg { ref mut data, .. } => { - self.map.rewrite_value(&mut data.arg, loc)?; - self.map.rewrite_values(&mut data.varargs, loc)?; + InstructionData::ReturnReg { ref mut args, .. } => { + self.map.rewrite_values(args.as_mut_slice(value_lists), loc)?; } } } @@ -1527,7 +1526,7 @@ impl<'a> Parser<'a> { InstructionData::Return { opcode: opcode, ty: VOID, - data: Box::new(ReturnData { varargs: args }), + args: args.into_value_list(&[], &mut ctx.function.dfg.value_lists), } } InstructionFormat::ReturnReg => { @@ -1540,10 +1539,7 @@ impl<'a> Parser<'a> { InstructionData::ReturnReg { opcode: opcode, ty: VOID, - data: Box::new(ReturnRegData { - arg: raddr, - varargs: args, - }), + args: args.into_value_list(&[raddr], &mut ctx.function.dfg.value_lists), } } InstructionFormat::BranchTable => {