Add dfg.inst_args(_mut) methods.

A shortcut for calling arguments() directly that goes with the existing
inst_results() method.
This commit is contained in:
Jakob Stoklund Olesen
2017-03-23 12:39:05 -07:00
parent c5c9f211df
commit f710f13949
7 changed files with 19 additions and 10 deletions

View File

@@ -344,6 +344,16 @@ impl DataFlowGraph {
DisplayInst(self, inst)
}
/// Get the value arguments on `inst` as a slice.
pub fn inst_args(&self, inst: Inst) -> &[Value] {
self.insts[inst].arguments(&self.value_lists)
}
/// Get the value arguments on `inst` as a mutable slice.
pub fn inst_args_mut(&mut self, inst: Inst) -> &mut [Value] {
self.insts[inst].arguments_mut(&mut self.value_lists)
}
/// Create result values for an instruction that produces multiple results.
///
/// Instructions that produce 0 or 1 result values only need to be created with `make_inst`. If

View File

@@ -348,8 +348,7 @@ fn check_call_signature(dfg: &DataFlowGraph, inst: Inst) -> Result<(), SigRef> {
fn check_return_signature(dfg: &DataFlowGraph, inst: Inst, sig: &Signature) -> bool {
let fixed_values = dfg[inst].opcode().constraints().fixed_value_arguments();
check_arg_types(dfg,
dfg[inst]
.arguments(&dfg.value_lists)
dfg.inst_args(inst)
.iter()
.skip(fixed_values)
.cloned(),

View File

@@ -289,7 +289,7 @@ fn resolve_splits(dfg: &DataFlowGraph, value: Value) -> Value {
Opcode::Vsplit => Opcode::Vconcat,
_ => return value,
};
split_arg = dfg[inst].arguments(&dfg.value_lists)[0];
split_arg = dfg.inst_args(inst)[0];
} else {
return value;
}
@@ -297,7 +297,7 @@ fn resolve_splits(dfg: &DataFlowGraph, value: Value) -> Value {
// See if split_arg is defined by a concatenation instruction.
if let ValueDef::Res(inst, _) = dfg.value_def(split_arg) {
if dfg[inst].opcode() == concat_opc {
return dfg[inst].arguments(&dfg.value_lists)[split_res];
return dfg.inst_args(inst)[split_res];
}
}
@@ -316,10 +316,10 @@ fn resolve_splits(dfg: &DataFlowGraph, value: Value) -> Value {
pub fn simplify_branch_arguments(dfg: &mut DataFlowGraph, branch: Inst) {
let mut new_args = Vec::new();
for &arg in dfg[branch].arguments(&dfg.value_lists) {
for &arg in dfg.inst_args(branch) {
let new_arg = resolve_splits(dfg, arg);
new_args.push(new_arg);
}
dfg.insts[branch].arguments_mut(&mut dfg.value_lists).copy_from_slice(&new_args);
dfg.inst_args_mut(branch).copy_from_slice(&new_args);
}

View File

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

View File

@@ -320,7 +320,7 @@ impl Liveness {
.unwrap_or(&[])
.iter();
for &arg in func.dfg[inst].arguments(&func.dfg.value_lists) {
for &arg in func.dfg.inst_args(inst) {
// Get the live range, create it as a dead range if necessary.
let lr = get_or_create(&mut self.ranges, arg, func, recipe_constraints);

View File

@@ -196,7 +196,7 @@ impl<'a> Verifier<'a> {
fn verify_entity_references(&self, inst: Inst) -> Result<()> {
use ir::instructions::InstructionData::*;
for &arg in self.func.dfg[inst].arguments(&self.func.dfg.value_lists) {
for &arg in self.func.dfg.inst_args(inst) {
self.verify_value(inst, arg)?;
}

View File

@@ -160,7 +160,7 @@ fn type_suffix(func: &Function, inst: Inst) -> Option<Type> {
// Write out any value aliases appearing in `inst`.
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) {
for &arg in func.dfg.inst_args(inst) {
let resolved = func.dfg.resolve_aliases(arg);
if resolved != arg {
writeln!(w, "{1:0$}{2} -> {3}", indent, "", arg, resolved)?;