From 2b999d9bd67751ced2b091a778830c2f2977df05 Mon Sep 17 00:00:00 2001 From: Jakob Stoklund Olesen Date: Thu, 29 Jun 2017 15:13:04 -0700 Subject: [PATCH] Add an Index implementation to Liveness. Use it to access live ranges that are supposed to be there. --- lib/cretonne/src/regalloc/coloring.rs | 9 +++------ lib/cretonne/src/regalloc/live_value_tracker.rs | 5 +---- lib/cretonne/src/regalloc/liveness.rs | 12 ++++++++++++ lib/cretonne/src/regalloc/reload.rs | 3 +-- 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/lib/cretonne/src/regalloc/coloring.rs b/lib/cretonne/src/regalloc/coloring.rs index 1a21f78f7e..733506ef0d 100644 --- a/lib/cretonne/src/regalloc/coloring.rs +++ b/lib/cretonne/src/regalloc/coloring.rs @@ -474,17 +474,14 @@ impl<'a> Context<'a> { // // It is possible for `dest_arg` to have no affinity, and then it should simply // be ignored. - if self.liveness.get(dest_arg).unwrap().affinity.is_reg() { + if self.liveness[dest_arg].affinity.is_reg() { return true; } } ValueLoc::Reg(dest_reg) => { // We've branched to `dest` before. Make sure we use the correct argument // registers by reassigning `br_arg`. - let br_lr = self.liveness - .get(br_arg) - .expect("Missing live range for branch argument"); - if let Affinity::Reg(rci) = br_lr.affinity { + if let Affinity::Reg(rci) = self.liveness[br_arg].affinity { let rc = self.reginfo.rc(rci); let br_reg = self.divert.reg(br_arg, locations); self.solver.reassign_in(br_arg, rc, br_reg, dest_reg); @@ -518,7 +515,7 @@ impl<'a> Context<'a> { for (&dest_arg, &br_arg) in dest_args.iter().zip(br_args) { match locations[dest_arg] { ValueLoc::Unassigned => { - if self.liveness.get(dest_arg).unwrap().affinity.is_reg() { + if self.liveness[dest_arg].affinity.is_reg() { let br_reg = self.divert.reg(br_arg, locations); locations[dest_arg] = ValueLoc::Reg(br_reg); } diff --git a/lib/cretonne/src/regalloc/live_value_tracker.rs b/lib/cretonne/src/regalloc/live_value_tracker.rs index b243b93923..bee25aa287 100644 --- a/lib/cretonne/src/regalloc/live_value_tracker.rs +++ b/lib/cretonne/src/regalloc/live_value_tracker.rs @@ -260,10 +260,7 @@ impl LiveValueTracker { // Add the values defined by `inst`. let first_def = self.live.values.len(); for &value in dfg.inst_results(inst) { - let lr = match liveness.get(value) { - Some(lr) => lr, - None => panic!("{} result {} has no live range", dfg[inst].opcode(), value), - }; + let lr = &liveness[value]; assert_eq!(lr.def(), inst.into()); match lr.def_local_end().into() { ExpandedProgramPoint::Inst(endpoint) => { diff --git a/lib/cretonne/src/regalloc/liveness.rs b/lib/cretonne/src/regalloc/liveness.rs index 2093b15299..973e278f62 100644 --- a/lib/cretonne/src/regalloc/liveness.rs +++ b/lib/cretonne/src/regalloc/liveness.rs @@ -183,6 +183,7 @@ use regalloc::affinity::Affinity; use regalloc::liverange::LiveRange; use sparse_map::SparseMap; use std::mem; +use std::ops::Index; /// A set of live ranges, indexed by value number. type LiveRangeSet = SparseMap; @@ -451,3 +452,14 @@ impl Liveness { } } } + +impl Index for Liveness { + type Output = LiveRange; + + fn index(&self, index: Value) -> &LiveRange { + match self.ranges.get(index) { + Some(lr) => lr, + None => panic!("{} has no live range", index), + } + } +} diff --git a/lib/cretonne/src/regalloc/reload.rs b/lib/cretonne/src/regalloc/reload.rs index e8327b5a73..93860071d3 100644 --- a/lib/cretonne/src/regalloc/reload.rs +++ b/lib/cretonne/src/regalloc/reload.rs @@ -285,8 +285,7 @@ impl<'a> Context<'a> { for (op, &arg) in constraints.ins.iter().zip(args) { if op.kind != ConstraintKind::Stack { - let lv = self.liveness.get(arg).expect("Missing live range for arg"); - if lv.affinity.is_stack() { + if self.liveness[arg].affinity.is_stack() { self.candidates .push(ReloadCandidate { value: arg,