From 01afee4d48b05dee7686090716e23d467fae9838 Mon Sep 17 00:00:00 2001 From: Cliff Click Date: Wed, 13 Nov 2024 13:55:56 -0800 Subject: Minor inf loop fix --- .../src/main/java/com/seaofnodes/simple/node/LoopNode.java | 7 ++++--- .../src/test/java/com/seaofnodes/simple/Chapter11Test.java | 2 +- .../src/test/java/com/seaofnodes/simple/Chapter17Test.java | 12 +----------- 3 files changed, 6 insertions(+), 15 deletions(-) (limited to 'chapter17') diff --git a/chapter17/src/main/java/com/seaofnodes/simple/node/LoopNode.java b/chapter17/src/main/java/com/seaofnodes/simple/node/LoopNode.java index 22862cb9..27134420 100644 --- a/chapter17/src/main/java/com/seaofnodes/simple/node/LoopNode.java +++ b/chapter17/src/main/java/com/seaofnodes/simple/node/LoopNode.java @@ -34,7 +34,7 @@ public class LoopNode extends RegionNode { @Override public int loopDepth() { if( _loopDepth!=0 ) return _loopDepth; // Was already set - _loopDepth = entry()._loopDepth+1; // Entry depth plus one + _loopDepth = entry().loopDepth()+1; // Entry depth plus one // One-time tag loop exits for( CFGNode idom = back(); idom!=this; idom = idom.idom() ) { // Walk idom in loop, setting depth @@ -61,8 +61,9 @@ public class LoopNode extends RegionNode { CFGNode x = back(); while( x != this ) { if( x instanceof CProjNode exit && exit.in(0) instanceof IfNode iff ) { - Node other = iff.cproj(1-exit._idx); - if( !(other.out(0) instanceof LoopNode loop) || loop.entry()==exit ) + CFGNode other = iff.cproj(1-exit._idx); + //if( !(other.out(0) instanceof LoopNode loop) || loop.entry()==exit ) + if( other.loopDepth() < loopDepth() ) return; // Found an exit, not an infinite loop } x = x.idom(); diff --git a/chapter17/src/test/java/com/seaofnodes/simple/Chapter11Test.java b/chapter17/src/test/java/com/seaofnodes/simple/Chapter11Test.java index 79c0622c..5127b250 100644 --- a/chapter17/src/test/java/com/seaofnodes/simple/Chapter11Test.java +++ b/chapter17/src/test/java/com/seaofnodes/simple/Chapter11Test.java @@ -292,7 +292,7 @@ else { } """); StopNode stop = parser.parse().iterate(); - assertEquals("Stop[ return 9; return 0; return 0; return 0; return 0; return 0; return 0; return 0; ]", stop.toString()); + assertEquals("Stop[ return 9; return 0; return 0; return 0; return 0; return 0; return 0; ]", stop.toString()); } diff --git a/chapter17/src/test/java/com/seaofnodes/simple/Chapter17Test.java b/chapter17/src/test/java/com/seaofnodes/simple/Chapter17Test.java index 7de7d514..b1f7eb43 100644 --- a/chapter17/src/test/java/com/seaofnodes/simple/Chapter17Test.java +++ b/chapter17/src/test/java/com/seaofnodes/simple/Chapter17Test.java @@ -12,17 +12,7 @@ public class Chapter17Test { @Test public void testJig() { Parser parser = new Parser(""" -i32 v0=0; -if(1<