Skip to content

Commit 866a922

Browse files
chapter17: idealize region
1 parent 887b308 commit 866a922

1 file changed

Lines changed: 12 additions & 9 deletions

File tree

src/sea_of_nodes/nodes/idealize.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use crate::datastructures::id::Id;
2-
use crate::sea_of_nodes::nodes::node::IfOp;
32
use crate::sea_of_nodes::nodes::node::{
43
Add, Bool, CProj, Cast, Constant, Div, If, Load, Minus, Mul, Not, Phi, Return, Stop, Store,
54
Sub, TypedNode,
65
};
6+
use crate::sea_of_nodes::nodes::node::{IfOp, Region};
77
use crate::sea_of_nodes::nodes::{BoolOp, Node, Nodes, Op};
88
use crate::sea_of_nodes::types::Ty;
99

@@ -20,7 +20,8 @@ impl Node {
2020
TypedNode::Return(n) => n.idealize_return(sea),
2121
TypedNode::Proj(_) => None,
2222
TypedNode::CProj(n) => n.idealize_cproj(sea),
23-
TypedNode::Region(_) | TypedNode::Loop(_) => self.idealize_region(sea),
23+
TypedNode::Region(n) => n.idealize_region(sea),
24+
TypedNode::Loop(n) => n.idealize_region(sea), // super
2425
TypedNode::If(n) => n.idealize_if(sea),
2526
TypedNode::Cast(n) => n.idealize_cast(sea),
2627
TypedNode::Load(n) => n.idealize_load(sea),
@@ -376,9 +377,9 @@ impl CProj {
376377
}
377378
}
378379

379-
impl Node {
380+
impl Region {
380381
fn idealize_region(self, sea: &mut Nodes) -> Option<Node> {
381-
if Nodes::in_progress(&sea.ops, &sea.inputs, self) {
382+
if Nodes::in_progress(&sea.ops, &sea.inputs, **self) {
382383
return None;
383384
}
384385

@@ -416,7 +417,7 @@ impl Node {
416417
Some(**sea.xctrl)
417418
} else {
418419
self.del_def(path, sea);
419-
Some(self)
420+
Some(**self)
420421
};
421422
}
422423
}
@@ -429,10 +430,12 @@ impl Node {
429430
// If a CFG diamond with no merging, delete: "if( pred ) {} else {};"
430431
if !self.has_phi(sea) {
431432
// No Phi users, just a control user
432-
if let Some(p1) = self.inputs(sea)[1].and_then(|n| n.to_proj(sea)) {
433-
if let Some(p2) = self.inputs(sea)[2].and_then(|n| n.to_proj(sea)) {
434-
if p1.inputs(sea)[0] == p2.inputs(sea)[0] {
435-
if let Some(iff) = p1.inputs(sea)[0].and_then(|n| n.to_if(sea)) {
433+
if let Some(p1) = self.inputs(sea)[1].and_then(|n| n.to_cproj(sea)) {
434+
if let Some(p2) = self.inputs(sea)[2].and_then(|n| n.to_cproj(sea)) {
435+
if p1.inputs(sea)[0].unwrap().add_dep(self, sea)
436+
== p2.inputs(sea)[0].unwrap().add_dep(self, sea)
437+
{
438+
if let Some(iff) = p1.inputs(sea)[0].unwrap().to_if(sea) {
436439
return iff.inputs(sea)[0];
437440
}
438441
}

0 commit comments

Comments
 (0)