more general tree walking algorightm was needed (probably)

Signed-off-by: Jakub Doka <jakub.doka2@gmail.com>
This commit is contained in:
Jakub Doka 2024-12-15 20:35:44 +01:00
parent 7837eeb90d
commit 6fba7da782
No known key found for this signature in database
GPG key ID: C6E9A89936B8C143
2 changed files with 21 additions and 21 deletions

View file

@ -438,7 +438,7 @@ impl Nodes {
((node.kind == Kind::Stre && node.inputs[2] == target) ((node.kind == Kind::Stre && node.inputs[2] == target)
|| (node.kind == Kind::Load && node.inputs[1] == target)) || (node.kind == Kind::Load && node.inputs[1] == target))
&& (node.ty.loc(tys) == Loc::Reg && (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 || (node.kind == Kind::Load
&& !matches!(tys.parama(node.ty).0, Some(PLoc::Ref(..))) && !matches!(tys.parama(node.ty).0, Some(PLoc::Ref(..)))
&& node.outputs.iter().all(|&o| matches!(self[o].kind, Kind::Call { .. } | Kind::Return { .. })))) && 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 { enum PLoc {
Reg(Reg, u16), Reg(Reg, u16),
WideReg(Reg, u16), WideReg(Reg, u16),

View file

@ -121,9 +121,10 @@ impl HbvmBackend {
|| nodes.is_hard_zero(allc) || nodes.is_hard_zero(allc)
|| allc == MEM || allc == MEM
|| matches!(node.kind, Kind::Loop | Kind::Region), || matches!(node.kind, Kind::Loop | Kind::Region),
"{nid} {:?}\n{allc} {:?}", "{nid} {:?}\n{allc} {:?} {}",
nodes[nid], 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) 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, Kind::Load => self[user].inputs[2] != val,
_ => self[user].inputs[0] != val || self[user].inputs[1..].contains(&val), _ => self[user].inputs[0] != val || self[user].inputs[1..].contains(&val),
} }
@ -761,19 +758,22 @@ impl Nodes {
return None.into_iter().flatten(); return None.into_iter().flatten();
} }
Some( let mut uses = vec![];
self[nid] let mut to_expand = vec![nid];
.outputs while let Some(exp) = to_expand.pop() {
.iter() for &o in self[exp].outputs.iter() {
.filter(move |&&n| self.is_data_dep(nid, n, types)) if !self.is_data_dep(exp, o, types) {
.map(move |n| self.this_or_delegates(nid, n)) continue;
.flat_map(|(p, ls)| ls.iter().map(move |l| (p, l))) }
.filter(|&(o, &n)| self.is_data_dep(o, n, types)) if self.is_unlocked(o) {
.map(|(p, &n)| (self.use_block_of(p, n), n)) uses.push((self.use_block_of(exp, o), o));
.inspect(|&(_, n)| debug_assert!(self.is_unlocked(n))), } else {
) to_expand.push(o);
.into_iter() }
.flatten() }
}
Some(uses).into_iter().flatten()
} }
} }