Skip to content

Commit

Permalink
chapter11: fix remaining idom idepth comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertObkircher committed Jan 1, 2025
1 parent 0b7f46e commit 7503c7d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/sea_of_nodes/global_code_motion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl Loop {

let mut x = self.back(sea);
while x.node() != *self {
if let Some(exit) = x.node().to_cproj(sea) {
if x.node().to_cproj(sea).is_some() {
return; // Found an exit, not an infinite loop
}
x = x.idom(sea).unwrap()
Expand All @@ -78,7 +78,7 @@ impl Loop {
for i in 0..sea.outputs[self].len() {
let use_ = sea.outputs[self][i];
if let Some(phi) = use_.to_phi(sea) {
iff.add_def(Some(use_), sea);
iff.add_def(Some(*phi), sea);
}
}

Expand Down Expand Up @@ -358,7 +358,7 @@ fn find_anti_dep(
// We could skip final-field loads here.
// Walk LCA->early, flagging Load's block location choices
{
let mut early = Some(early);
let early = Some(early);
let mut cfg = Some(lca);
while early.is_some() && cfg != early.unwrap().idom(sea) {
sea[cfg.unwrap()].anti = Some(load);
Expand Down
8 changes: 4 additions & 4 deletions src/sea_of_nodes/nodes/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ impl Cfg {
};
let mut lhs = self;
while lhs != rhs {
let comp = lhs.idepth(sea) - rhs.idepth(sea);
let comp = lhs.idepth(sea) as i64 - rhs.idepth(sea) as i64;
if comp >= 0 {
lhs = lhs.idom(sea).unwrap()
}
Expand Down Expand Up @@ -162,7 +162,7 @@ impl Cfg {
visit.add(this);

match this.downcast(&sea.ops) {
TypedNode::If(i) => {
TypedNode::If(_) => {
for proj in &sea.outputs[this] {
let proj = proj.to_proj(sea).unwrap().to_cfg(&sea.ops).unwrap();
if sea[proj].loop_depth == 0 {
Expand All @@ -171,12 +171,12 @@ impl Cfg {
}
self.cfg(0, sea).unwrap().walk_unreach(visit, unreach, sea);
}
TypedNode::Region(r) => {
TypedNode::Region(_) => {
for i in 1..this.inputs(sea).len() {
self.cfg(i, sea).unwrap().walk_unreach(visit, unreach, sea);
}
}
TypedNode::Start(s) => {}
TypedNode::Start(_) => {}
_ => self.cfg(0, sea).unwrap().walk_unreach(visit, unreach, sea),
}

Expand Down
3 changes: 3 additions & 0 deletions src/sea_of_nodes/nodes/iter_peeps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
use crate::datastructures::id_set::IdSet;
use crate::datastructures::random::Random;
use crate::sea_of_nodes::global_code_motion::build_cfg;
use crate::sea_of_nodes::nodes::index::Stop;
use crate::sea_of_nodes::nodes::{Node, Nodes, Op};

Expand Down Expand Up @@ -131,6 +132,8 @@ impl<'t> Nodes<'t> {
n.kill(self); // just plain dead
}
}
// NOTE: java prints here, before building the cfg
build_cfg(stop, self);
}

pub fn type_check(&mut self, stop: Stop) -> Result<(), String> {
Expand Down

0 comments on commit 7503c7d

Please sign in to comment.