From b562fdcd5cb637c8c42aae7ba048b248cb3318d9 Mon Sep 17 00:00:00 2001 From: Jakob Stoklund Olesen Date: Thu, 5 Oct 2017 14:46:34 -0700 Subject: [PATCH] Remove the dfg::resolve_copies() method. This method was important back when result values couldn't be moved between instructions. Now that results can be moved, value aliases do everything we need. Copy instructions are still used to break interferences in the register allocator's coalescing phase, but there isn't really any reason to use a copy instruction over a value alias anywhere else. After and during register allocation, copy instructions are significant, so we never want to "see through" them like the resolve_copies() function did. This is related to #166, but probably doesn't fix the underlying problem. --- lib/cretonne/src/ir/dfg.rs | 31 +---------------------------- lib/cretonne/src/legalizer/split.rs | 4 ++-- 2 files changed, 3 insertions(+), 32 deletions(-) diff --git a/lib/cretonne/src/ir/dfg.rs b/lib/cretonne/src/ir/dfg.rs index 25859535bc..dbb643e7f3 100644 --- a/lib/cretonne/src/ir/dfg.rs +++ b/lib/cretonne/src/ir/dfg.rs @@ -4,7 +4,7 @@ use entity::{PrimaryMap, EntityMap}; use isa::TargetIsa; use ir::builder::{InsertBuilder, ReplaceBuilder}; use ir::extfunc::ExtFuncData; -use ir::instructions::{Opcode, InstructionData, CallInfo}; +use ir::instructions::{InstructionData, CallInfo}; use ir::layout::{Cursor, LayoutCursorInserter}; use ir::types; use ir::{Ebb, Inst, Value, Type, SigRef, Signature, FuncRef, ValueList, ValueListPool}; @@ -211,33 +211,6 @@ impl DataFlowGraph { resolve_aliases(&self.values, value) } - /// Resolve value copies. - /// - /// Find the original definition of a value, looking through value aliases as well as - /// copy/spill/fill instructions. - pub fn resolve_copies(&self, value: Value) -> Value { - let mut v = value; - - for _ in 0..self.insts.len() { - v = self.resolve_aliases(v); - v = match self.value_def(v) { - ValueDef::Res(inst, 0) => { - match self[inst] { - InstructionData::Unary { opcode, arg, .. } => { - match opcode { - Opcode::Copy | Opcode::Spill | Opcode::Fill => arg, - _ => return v, - } - } - _ => return v, - } - } - _ => return v, - }; - } - panic!("Copy loop detected for {}", value); - } - /// Resolve all aliases among inst's arguments. /// /// For each argument of inst which is defined by an alias, replace the @@ -1090,7 +1063,5 @@ mod tests { let c3 = pos.ins().copy(c); // This does not see through copies. assert_eq!(pos.func.dfg.resolve_aliases(c3), c3); - // But this goes through both copies and aliases. - assert_eq!(pos.func.dfg.resolve_copies(c3), c2); } } diff --git a/lib/cretonne/src/legalizer/split.rs b/lib/cretonne/src/legalizer/split.rs index 62e5391474..96e1b03145 100644 --- a/lib/cretonne/src/legalizer/split.rs +++ b/lib/cretonne/src/legalizer/split.rs @@ -190,7 +190,7 @@ fn split_value( concat: Opcode, repairs: &mut Vec, ) -> (Value, Value) { - let value = pos.func.dfg.resolve_copies(value); + let value = pos.func.dfg.resolve_aliases(value); let mut reuse = None; match pos.func.dfg.value_def(value) { @@ -293,7 +293,7 @@ fn add_repair( /// /// This function resolves `v11` to `v1` and `v12` to `v2`. fn resolve_splits(dfg: &ir::DataFlowGraph, value: Value) -> Value { - let value = dfg.resolve_copies(value); + let value = dfg.resolve_aliases(value); // Deconstruct a split instruction. let split_res;