diff --git a/lang/src/backend/hbvm.rs b/lang/src/backend/hbvm.rs index 970785cf..b2b61fc6 100644 --- a/lang/src/backend/hbvm.rs +++ b/lang/src/backend/hbvm.rs @@ -438,7 +438,7 @@ impl Nodes { ((node.kind == Kind::Stre && node.inputs[2] == target) || (node.kind == Kind::Load && node.inputs[1] == target)) && (node.ty.loc(tys) == Loc::Reg - // this means the struct is actually loaded into a register so no BMC needed + // this means the struct is actually loaded into a register so no BMC needed || (node.kind == Kind::Load && !matches!(tys.parama(node.ty).0, Some(PLoc::Ref(..))) && node.outputs.iter().all(|&o| matches!(self[o].kind, Kind::Call { .. } | Kind::Return { .. })))) @@ -643,7 +643,7 @@ impl TokenKind { } } -#[derive(Clone, Copy)] +#[derive(Clone, Copy, Debug)] enum PLoc { Reg(Reg, u16), WideReg(Reg, u16), diff --git a/lang/src/backend/hbvm/regalloc.rs b/lang/src/backend/hbvm/regalloc.rs index 0a5723e3..ce67e1d3 100644 --- a/lang/src/backend/hbvm/regalloc.rs +++ b/lang/src/backend/hbvm/regalloc.rs @@ -121,9 +121,10 @@ impl HbvmBackend { || nodes.is_hard_zero(allc) || allc == MEM || matches!(node.kind, Kind::Loop | Kind::Region), - "{nid} {:?}\n{allc} {:?}", + "{nid} {:?}\n{allc} {:?} {}", nodes[nid], - nodes[allc] + nodes[allc], + ty::Display::new(tys, files, nodes[allc].ty) ); }; @@ -712,10 +713,6 @@ impl Nodes { ); self[user].inputs.iter().position(|&v| v == val).is_some_and(|v| v < 3) } - //Kind::Call { .. } => { - // self[val].kind != Kind::Load - // || matches!(types.parama(self[val].ty).0, Some(PLoc::Ref(..))) - //} Kind::Load => self[user].inputs[2] != val, _ => self[user].inputs[0] != val || self[user].inputs[1..].contains(&val), } @@ -761,19 +758,22 @@ impl Nodes { return None.into_iter().flatten(); } - Some( - self[nid] - .outputs - .iter() - .filter(move |&&n| self.is_data_dep(nid, n, types)) - .map(move |n| self.this_or_delegates(nid, n)) - .flat_map(|(p, ls)| ls.iter().map(move |l| (p, l))) - .filter(|&(o, &n)| self.is_data_dep(o, n, types)) - .map(|(p, &n)| (self.use_block_of(p, n), n)) - .inspect(|&(_, n)| debug_assert!(self.is_unlocked(n))), - ) - .into_iter() - .flatten() + let mut uses = vec![]; + let mut to_expand = vec![nid]; + while let Some(exp) = to_expand.pop() { + for &o in self[exp].outputs.iter() { + if !self.is_data_dep(exp, o, types) { + continue; + } + if self.is_unlocked(o) { + uses.push((self.use_block_of(exp, o), o)); + } else { + to_expand.push(o); + } + } + } + + Some(uses).into_iter().flatten() } }