Add an Index<Value> implementation to Liveness.

Use it to access live ranges that are supposed to be there.
This commit is contained in:
Jakob Stoklund Olesen
2017-06-29 15:13:04 -07:00
parent 138d3c75c6
commit 2b999d9bd6
4 changed files with 17 additions and 12 deletions

View File

@@ -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);
}

View File

@@ -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) => {

View File

@@ -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<Value, LiveRange>;
@@ -451,3 +452,14 @@ impl Liveness {
}
}
}
impl Index<Value> 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),
}
}
}

View File

@@ -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,