From b1769ac7e4ad454b2e17edfc2012f4938dd31bd7 Mon Sep 17 00:00:00 2001 From: Jakob Stoklund Olesen Date: Wed, 15 Feb 2017 13:53:01 -0800 Subject: [PATCH] Cache the affinity in LiveValue. Most of the register allocator algorithms will only have to look at the currently live values as presented by LiveValueTracker. Many also need the value's affinity which is stored in the LiveRange associated with the value. Save the extra table lookup by caching the affinity value inside LiveValue. --- lib/cretonne/src/regalloc/live_value_tracker.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/cretonne/src/regalloc/live_value_tracker.rs b/lib/cretonne/src/regalloc/live_value_tracker.rs index cdbfebe286..838c5b6bb9 100644 --- a/lib/cretonne/src/regalloc/live_value_tracker.rs +++ b/lib/cretonne/src/regalloc/live_value_tracker.rs @@ -9,6 +9,7 @@ use entity_list::{EntityList, ListPool}; use ir::instructions::BranchInfo; use ir::{Inst, Ebb, Value, DataFlowGraph, ProgramOrder, ExpandedProgramPoint}; use partition_slice::partition_slice; +use regalloc::affinity::Affinity; use regalloc::liveness::Liveness; use std::collections::HashMap; @@ -38,6 +39,12 @@ pub struct LiveValue { /// The local ending point of the live range in the current EBB, as returned by /// `LiveRange::def_local_end()` or `LiveRange::livein_local_end()`. pub endpoint: Inst, + + /// The affinity of the value as represented in its `LiveRange`. + /// + /// This value is simply a copy of the affinity stored in the live range. We copy it because + /// almost all users of `LiveValue` need to look at it. + pub affinity: Affinity, } struct LiveValueVec { @@ -60,10 +67,11 @@ impl LiveValueVec { } /// Add a new live value to `values`. - fn push(&mut self, value: Value, endpoint: Inst) { + fn push(&mut self, value: Value, endpoint: Inst, affinity: Affinity) { self.values.push(LiveValue { value: value, endpoint: endpoint, + affinity: affinity, }); } @@ -164,7 +172,7 @@ impl LiveValueTracker { // Check if this value is live-in here. if let Some(endpoint) = lr.livein_local_end(ebb, program_order) { - self.live.push(value, endpoint); + self.live.push(value, endpoint, lr.affinity); } } } @@ -176,7 +184,7 @@ impl LiveValueTracker { assert_eq!(lr.def(), ebb.into()); match lr.def_local_end().into() { ExpandedProgramPoint::Inst(endpoint) => { - self.live.push(value, endpoint); + self.live.push(value, endpoint, lr.affinity); } ExpandedProgramPoint::Ebb(local_ebb) => { // This is a dead EBB argument which is not even live into the first @@ -225,7 +233,7 @@ impl LiveValueTracker { assert_eq!(lr.def(), inst.into()); match lr.def_local_end().into() { ExpandedProgramPoint::Inst(endpoint) => { - self.live.push(value, endpoint); + self.live.push(value, endpoint, lr.affinity); } ExpandedProgramPoint::Ebb(ebb) => { panic!("Instruction result live range can't end at {}", ebb);