Removing some clones and fixing parent scoping in case of globals

Signed-off-by: Jakub Doka <jakub.doka2@gmail.com>
This commit is contained in:
Jakub Doka 2024-12-02 12:59:07 +01:00
parent c553c3d9e9
commit c5d5301b7b
No known key found for this signature in database
GPG key ID: C6E9A89936B8C143

View file

@ -31,6 +31,7 @@ use {
}, },
hashbrown::hash_map, hashbrown::hash_map,
hbbytecode::DisasmError, hbbytecode::DisasmError,
std::panic,
}; };
pub const VOID: Nid = 0; pub const VOID: Nid = 0;
@ -183,8 +184,7 @@ impl Nodes {
for l in self[LOOPS].outputs.clone() { for l in self[LOOPS].outputs.clone() {
if !seen.get(l) { if !seen.get(l) {
self[l].outputs.push(NEVER); self.bind(l, NEVER);
self[NEVER].inputs.push(l);
} }
} }
} }
@ -412,13 +412,13 @@ impl Nodes {
return; return;
} }
for usage in self[node].outputs.clone() { for &usage in self[node].outputs.iter() {
if self.is_forward_edge(usage, node) && self[node].kind == Kind::Stre { if self.is_forward_edge(usage, node) && self[node].kind == Kind::Stre {
self.push_down(usage, visited, antideps, scheds, antidep_bounds); self.push_down(usage, visited, antideps, scheds, antidep_bounds);
} }
} }
for usage in self[node].outputs.clone() { for &usage in self[node].outputs.iter() {
if self.is_forward_edge(usage, node) { if self.is_forward_edge(usage, node) {
self.push_down(usage, visited, antideps, scheds, antidep_bounds); self.push_down(usage, visited, antideps, scheds, antidep_bounds);
} }
@ -490,7 +490,7 @@ impl Nodes {
return min; return min;
} }
for out in self[self[load].inputs[2]].outputs.clone() { for &out in self[self[load].inputs[2]].outputs.iter() {
match self[out].kind { match self[out].kind {
Kind::Stre => { Kind::Stre => {
let mut cursor = scheds[out as usize]; let mut cursor = scheds[out as usize];
@ -1069,6 +1069,48 @@ impl Nodes {
return Some(self.new_node(ty, K::BinOp { op }, [ctrl, a, new_rhs], tys)); return Some(self.new_node(ty, K::BinOp { op }, [ctrl, a, new_rhs], tys));
} }
//if op == T::Add
// && self[rhs].kind == (K::BinOp { op: T::Mul })
// && let &[_, mul_lhs, mul_rhs] = self[rhs].inputs.as_slice()
// && self[mul_lhs].kind == K::Phi
// && let &[phi_ctrl, phi_lhs, phi_rhs] = self[mul_lhs].inputs.as_slice()
// && phi_rhs != VOID
// && self[phi_ctrl].kind == K::Loop
// && self[phi_rhs].kind == (K::BinOp { op: T::Add })
// && self[phi_rhs].inputs[1] == mul_lhs
//{
// debug_assert_eq!(
// self[mul_lhs].outputs.len(),
// 1,
// "{:?}",
// self[mul_lhs]
// .outputs
// .iter()
// .map(|&n| (
// &self[n].kind,
// self[n].inputs.iter().position(|&n| n == mul_lhs)
// ))
// .collect::<Vec<_>>()
// );
// let init_shift = self.new_node(
// self[rhs].ty,
// K::BinOp { op: T::Mul },
// [ctrl, phi_lhs, mul_rhs],
// tys,
// );
// let init =
// self.new_node(ty, K::BinOp { op: T::Add }, [ctrl, lhs, init_shift], tys);
// let new_value = self.new_node_nop(ty, K::Phi, [phi_ctrl, init, 0]);
// let next = self.new_node(
// ty,
// Kind::BinOp { op: T::Add },
// [ctrl, new_value, mul_rhs],
// tys,
// );
// return Some(self.modify_input(new_value, 2, next));
//}
if changed { if changed {
return Some(self.new_node(ty, self[target].kind, [ctrl, lhs, rhs], tys)); return Some(self.new_node(ty, self[target].kind, [ctrl, lhs, rhs], tys));
} }
@ -1976,7 +2018,7 @@ impl Nodes {
return; return;
} }
let node = self[nd].clone(); let node = &self[nd];
for &i in &node.inputs[1..] { for &i in &node.inputs[1..] {
let dom = self.idom(i, scheds); let dom = self.idom(i, scheds);
debug_assert!( debug_assert!(
@ -5462,12 +5504,12 @@ impl<'a> Codegen<'a> {
} }
} }
fn eval_global(&mut self, file: Module, name: Ident, expr: &Expr) -> ty::Id { fn eval_global(&mut self, file: Module, parent: ty::Id, name: Ident, expr: &Expr) -> ty::Id {
self.ct.activate(); self.ct.activate();
let gid = self.tys.ins.globals.push(GlobalData { file, name, ..Default::default() }); let gid = self.tys.ins.globals.push(GlobalData { file, name, ..Default::default() });
self.pool.push_ci(file, self.ci.parent, None, self.tys.tasks.len(), &mut self.ci); self.pool.push_ci(file, parent, None, self.tys.tasks.len(), &mut self.ci);
let prev_err_len = self.errors.borrow().len(); let prev_err_len = self.errors.borrow().len();
self.expr(&(Expr::Return { pos: expr.pos(), val: Some(expr) })); self.expr(&(Expr::Return { pos: expr.pos(), val: Some(expr) }));
@ -5766,7 +5808,7 @@ impl<'a> Codegen<'a> {
_ if sc.alloc_const _ if sc.alloc_const
&& let Some(name) = sc.name => && let Some(name) = sc.name =>
{ {
self.eval_global(sc.file, name, expr) self.eval_global(sc.file, sc.parent, name, expr)
} }
_ if sc.alloc_const => { _ if sc.alloc_const => {
ty::Id::from(self.eval_const(sc.file, sc.parent, expr, ty::Id::TYPE)) ty::Id::from(self.eval_const(sc.file, sc.parent, expr, ty::Id::TYPE))