Simplify the arguments() return type.

Now that variable arguments are always stored in a value list with the
fixed arguments, we no longer need the arcane [&[Value]; 2] return type.

Arguments are always stored contiguously, so just return a &[Value]
slice.

Also remove the each_arg() methods which were just trying to make it
easier to work with the old slice pair.
This commit is contained in:
Jakob Stoklund Olesen
2017-03-09 22:04:13 -08:00
parent 703762a67c
commit f451cf42c8
5 changed files with 9 additions and 34 deletions

View File

@@ -67,7 +67,7 @@ def gen_arguments_method(fmt, is_mut):
with fmt.indented( with fmt.indented(
'pub fn {f}<\'a>(&\'a {m}self, pool: &\'a {m}ValueListPool) -> ' 'pub fn {f}<\'a>(&\'a {m}self, pool: &\'a {m}ValueListPool) -> '
'[&{m}[Value]; 2] {{' '&{m}[Value] {{'
.format(f=method, m=mut), '}'): .format(f=method, m=mut), '}'):
with fmt.indented('match *self {', '}'): with fmt.indented('match *self {', '}'):
for f in InstructionFormat.all_formats: for f in InstructionFormat.all_formats:
@@ -79,9 +79,8 @@ def gen_arguments_method(fmt, is_mut):
if f.has_value_list: if f.has_value_list:
arg = ''.format(mut) arg = ''.format(mut)
fmt.line( fmt.line(
'{} {{ ref {}args, .. }} => ' '{} {{ ref {}args, .. }} => args.{}(pool),'
'[ &{}[], args.{}(pool) ],' .format(n, mut, as_slice))
.format(n, mut, mut, as_slice))
continue continue
# Fixed args. # Fixed args.
@@ -103,8 +102,8 @@ def gen_arguments_method(fmt, is_mut):
capture = 'ref {}args, '.format(mut) capture = 'ref {}args, '.format(mut)
arg = 'args' arg = 'args'
fmt.line( fmt.line(
'{} {{ {} .. }} => [{}, &{}[]],' '{} {{ {} .. }} => {},'
.format(n, capture, arg, mut)) .format(n, capture, arg))
def gen_instruction_data_impl(fmt): def gen_instruction_data_impl(fmt):

View File

@@ -336,30 +336,6 @@ impl Display for TernaryOverflowData {
/// Avoid large matches on instruction formats by using the methods defined here to examine /// Avoid large matches on instruction formats by using the methods defined here to examine
/// instructions. /// instructions.
impl InstructionData { impl InstructionData {
/// Execute a closure once for each argument to this instruction.
/// See also the `arguments()` method.
pub fn each_arg<F>(&self, pool: &ValueListPool, mut func: F)
where F: FnMut(Value)
{
for part in &self.arguments(pool) {
for &arg in part.iter() {
func(arg);
}
}
}
/// Execute a closure with a mutable reference to each argument to this instruction.
/// See also the `arguments_mut()` method.
pub fn each_arg_mut<F>(&mut self, pool: &mut ValueListPool, mut func: F)
where F: FnMut(&mut Value)
{
for part in &mut self.arguments_mut(pool) {
for arg in part.iter_mut() {
func(arg);
}
}
}
/// Return information about the destination of a branch or jump instruction. /// Return information about the destination of a branch or jump instruction.
/// ///
/// Any instruction that can transfer control to another EBB reveals its possible destinations /// Any instruction that can transfer control to another EBB reveals its possible destinations

View File

@@ -299,7 +299,7 @@ impl<'a> Context<'a> {
} }
ConstraintKind::Tied(arg_index) => { ConstraintKind::Tied(arg_index) => {
// This def must use the same register as a fixed instruction argument. // This def must use the same register as a fixed instruction argument.
let arg = dfg[inst].arguments(&dfg.value_lists)[0][arg_index as usize]; let arg = dfg[inst].arguments(&dfg.value_lists)[arg_index as usize];
let loc = locations[arg]; let loc = locations[arg];
*locations.ensure(lv.value) = loc; *locations.ensure(lv.value) = loc;
// Mark the reused register. It's not really clear if we support tied // Mark the reused register. It's not really clear if we support tied

View File

@@ -318,7 +318,7 @@ impl Liveness {
let mut operand_constraints = let mut operand_constraints =
recipe_constraints.get(recipe).map(|c| c.ins).unwrap_or(&[]).iter(); recipe_constraints.get(recipe).map(|c| c.ins).unwrap_or(&[]).iter();
func.dfg[inst].each_arg(&func.dfg.value_lists, |arg| { for &arg in func.dfg[inst].arguments(&func.dfg.value_lists) {
// Get the live range, create it as a dead range if necessary. // Get the live range, create it as a dead range if necessary.
let lr = get_or_create(&mut self.ranges, arg, func, recipe_constraints); let lr = get_or_create(&mut self.ranges, arg, func, recipe_constraints);
@@ -333,7 +333,7 @@ impl Liveness {
if let Some(constraint) = operand_constraints.next() { if let Some(constraint) = operand_constraints.next() {
lr.affinity.merge(constraint, &reg_info); lr.affinity.merge(constraint, &reg_info);
} }
}); }
} }
} }
} }

View File

@@ -157,7 +157,7 @@ fn type_suffix(func: &Function, inst: Inst) -> Option<Type> {
// Write out any value aliases appearing in `inst`. // Write out any value aliases appearing in `inst`.
fn write_value_aliases(w: &mut Write, func: &Function, inst: Inst, indent: usize) -> Result { fn write_value_aliases(w: &mut Write, func: &Function, inst: Inst, indent: usize) -> Result {
for &arg in func.dfg[inst].arguments(&func.dfg.value_lists).iter().flat_map(|x| x.iter()) { for &arg in func.dfg[inst].arguments(&func.dfg.value_lists) {
let resolved = func.dfg.resolve_aliases(arg); let resolved = func.dfg.resolve_aliases(arg);
if resolved != arg { if resolved != arg {
writeln!(w, "{1:0$}{2} -> {3}", indent, "", arg, resolved)?; writeln!(w, "{1:0$}{2} -> {3}", indent, "", arg, resolved)?;