From 6fba7da78262533d06e4ff70380da8e628ab5330 Mon Sep 17 00:00:00 2001 From: Jakub Doka Date: Sun, 15 Dec 2024 20:35:44 +0100 Subject: [PATCH] more general tree walking algorightm was needed (probably) Signed-off-by: Jakub Doka --- lang/src/backend/hbvm.rs | 4 ++-- lang/src/backend/hbvm/regalloc.rs | 38 +++++++++++++++---------------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/lang/src/backend/hbvm.rs b/lang/src/backend/hbvm.rs index 970785c..b2b61fc 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 0a5723e..ce67e1d 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() } }