Add an Index<Value> implementation to Liveness.
Use it to access live ranges that are supposed to be there.
This commit is contained in:
@@ -474,17 +474,14 @@ impl<'a> Context<'a> {
|
|||||||
//
|
//
|
||||||
// It is possible for `dest_arg` to have no affinity, and then it should simply
|
// It is possible for `dest_arg` to have no affinity, and then it should simply
|
||||||
// be ignored.
|
// be ignored.
|
||||||
if self.liveness.get(dest_arg).unwrap().affinity.is_reg() {
|
if self.liveness[dest_arg].affinity.is_reg() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ValueLoc::Reg(dest_reg) => {
|
ValueLoc::Reg(dest_reg) => {
|
||||||
// We've branched to `dest` before. Make sure we use the correct argument
|
// We've branched to `dest` before. Make sure we use the correct argument
|
||||||
// registers by reassigning `br_arg`.
|
// registers by reassigning `br_arg`.
|
||||||
let br_lr = self.liveness
|
if let Affinity::Reg(rci) = self.liveness[br_arg].affinity {
|
||||||
.get(br_arg)
|
|
||||||
.expect("Missing live range for branch argument");
|
|
||||||
if let Affinity::Reg(rci) = br_lr.affinity {
|
|
||||||
let rc = self.reginfo.rc(rci);
|
let rc = self.reginfo.rc(rci);
|
||||||
let br_reg = self.divert.reg(br_arg, locations);
|
let br_reg = self.divert.reg(br_arg, locations);
|
||||||
self.solver.reassign_in(br_arg, rc, br_reg, dest_reg);
|
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) {
|
for (&dest_arg, &br_arg) in dest_args.iter().zip(br_args) {
|
||||||
match locations[dest_arg] {
|
match locations[dest_arg] {
|
||||||
ValueLoc::Unassigned => {
|
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);
|
let br_reg = self.divert.reg(br_arg, locations);
|
||||||
locations[dest_arg] = ValueLoc::Reg(br_reg);
|
locations[dest_arg] = ValueLoc::Reg(br_reg);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -260,10 +260,7 @@ impl LiveValueTracker {
|
|||||||
// Add the values defined by `inst`.
|
// Add the values defined by `inst`.
|
||||||
let first_def = self.live.values.len();
|
let first_def = self.live.values.len();
|
||||||
for &value in dfg.inst_results(inst) {
|
for &value in dfg.inst_results(inst) {
|
||||||
let lr = match liveness.get(value) {
|
let lr = &liveness[value];
|
||||||
Some(lr) => lr,
|
|
||||||
None => panic!("{} result {} has no live range", dfg[inst].opcode(), value),
|
|
||||||
};
|
|
||||||
assert_eq!(lr.def(), inst.into());
|
assert_eq!(lr.def(), inst.into());
|
||||||
match lr.def_local_end().into() {
|
match lr.def_local_end().into() {
|
||||||
ExpandedProgramPoint::Inst(endpoint) => {
|
ExpandedProgramPoint::Inst(endpoint) => {
|
||||||
|
|||||||
@@ -183,6 +183,7 @@ use regalloc::affinity::Affinity;
|
|||||||
use regalloc::liverange::LiveRange;
|
use regalloc::liverange::LiveRange;
|
||||||
use sparse_map::SparseMap;
|
use sparse_map::SparseMap;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
|
use std::ops::Index;
|
||||||
|
|
||||||
/// A set of live ranges, indexed by value number.
|
/// A set of live ranges, indexed by value number.
|
||||||
type LiveRangeSet = SparseMap<Value, LiveRange>;
|
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),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -285,8 +285,7 @@ impl<'a> Context<'a> {
|
|||||||
|
|
||||||
for (op, &arg) in constraints.ins.iter().zip(args) {
|
for (op, &arg) in constraints.ins.iter().zip(args) {
|
||||||
if op.kind != ConstraintKind::Stack {
|
if op.kind != ConstraintKind::Stack {
|
||||||
let lv = self.liveness.get(arg).expect("Missing live range for arg");
|
if self.liveness[arg].affinity.is_stack() {
|
||||||
if lv.affinity.is_stack() {
|
|
||||||
self.candidates
|
self.candidates
|
||||||
.push(ReloadCandidate {
|
.push(ReloadCandidate {
|
||||||
value: arg,
|
value: arg,
|
||||||
|
|||||||
Reference in New Issue
Block a user