summaryrefslogtreecommitdiff
path: root/src/test/java/com
diff options
context:
space:
mode:
authorCliff Click <cliffc@acm.org>2024-08-05 16:15:27 -0700
committerCliff Click <cliffc@acm.org>2026-10-08 16:52:27 -0700
commitfc06aa2bebec45aa93df5450ebf4c327f9f51496 (patch)
tree8788a35ac00f0d146d17b72e5491afd4082a1fb0 /src/test/java/com
parentc54580d2b2685829dab0976ed8c2bcae59322f69 (diff)
downloadSimple-fc06aa2bebec45aa93df5450ebf4c327f9f51496.tar.gz
Simple-fc06aa2bebec45aa93df5450ebf4c327f9f51496.zip
Chapter 13: Global Code Motion
Co-authored-by: Thalia Archibald <thalia@archibald.dev> Co-authored-by: Dibyendu Majumdar <mobile@majumdar.org.uk> Co-authored-by: Tamás Hadházy <85063808+Hels15@users.noreply.github.com> Co-authored-by: Hsiang-Ying Fu <66062782+fuhsnn@users.noreply.github.com> Co-authored-by: tannal <tannal2409@gmail.com> Co-authored-by: hadha <helsgithub15@gmail.com> Co-authored-by: fuhsnn <66062782+fuhsnn@users.noreply.github.com> Co-authored-by: XmiliaH <45106915+XmiliaH@users.noreply.github.com> Co-authored-by: Symious <14933944+symious@users.noreply.github.com> Co-authored-by: RobertObkircher <robert.obkircher@gmail.com> Co-authored-by: Robert Obkircher <robert.obkircher@gmail.com> Co-authored-by: Jun Kawasaki <jun784@gmail.com> Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
Diffstat (limited to 'src/test/java/com')
-rw-r--r--src/test/java/com/seaofnodes/simple/Chapter01Test.java2
-rw-r--r--src/test/java/com/seaofnodes/simple/Chapter04Test.java2
-rw-r--r--src/test/java/com/seaofnodes/simple/Chapter05Test.java14
-rw-r--r--src/test/java/com/seaofnodes/simple/Chapter06Test.java16
-rw-r--r--src/test/java/com/seaofnodes/simple/Chapter07Test.java48
-rw-r--r--src/test/java/com/seaofnodes/simple/Chapter08Test.java25
-rw-r--r--src/test/java/com/seaofnodes/simple/Chapter09Test.java26
-rw-r--r--src/test/java/com/seaofnodes/simple/Chapter10Test.java30
-rw-r--r--src/test/java/com/seaofnodes/simple/Chapter12Test.java2
-rw-r--r--src/test/java/com/seaofnodes/simple/Chapter13Test.java532
-rw-r--r--src/test/java/com/seaofnodes/simple/FuzzerWrap.java2
-rw-r--r--src/test/java/com/seaofnodes/simple/TypeTest.java26
-rw-r--r--src/test/java/com/seaofnodes/simple/evaluator/Evaluator.java3
-rw-r--r--src/test/java/com/seaofnodes/simple/evaluator/Scheduler.java14
14 files changed, 643 insertions, 99 deletions
diff --git a/src/test/java/com/seaofnodes/simple/Chapter01Test.java b/src/test/java/com/seaofnodes/simple/Chapter01Test.java
index 89882b2f..c10dc510 100644
--- a/src/test/java/com/seaofnodes/simple/Chapter01Test.java
+++ b/src/test/java/com/seaofnodes/simple/Chapter01Test.java
@@ -15,7 +15,7 @@ public class Chapter01Test {
StartNode start = Parser.START;
ReturnNode ret = (ReturnNode)stop.in(0);
- assertTrue(ret.ctrl() instanceof ProjNode);
+ assertTrue(ret.ctrl() instanceof CProjNode);
Node expr = ret.expr();
if( expr instanceof ConstantNode con ) {
assertEquals(start,con.in(0));
diff --git a/src/test/java/com/seaofnodes/simple/Chapter04Test.java b/src/test/java/com/seaofnodes/simple/Chapter04Test.java
index edc62f50..14d31245 100644
--- a/src/test/java/com/seaofnodes/simple/Chapter04Test.java
+++ b/src/test/java/com/seaofnodes/simple/Chapter04Test.java
@@ -83,7 +83,7 @@ public class Chapter04Test {
Parser parser = new Parser("return arg; ");
StopNode stop = parser.parse();
ReturnNode ret = stop.ret();
- assertTrue(ret.in(0) instanceof ProjNode);
+ assertTrue(ret.in(0) instanceof CProjNode);
assertTrue(ret.in(1) instanceof ProjNode);
assertEquals(1, ((ProjNode)ret.in(1))._idx);
assertTrue(ret.in(2) instanceof ProjNode);
diff --git a/src/test/java/com/seaofnodes/simple/Chapter05Test.java b/src/test/java/com/seaofnodes/simple/Chapter05Test.java
index 97cd9940..cd646126 100644
--- a/src/test/java/com/seaofnodes/simple/Chapter05Test.java
+++ b/src/test/java/com/seaofnodes/simple/Chapter05Test.java
@@ -22,7 +22,7 @@ else {
return a;""");
StopNode ret = parser.parse().iterate();
- assertEquals("return Phi(Region19,(arg+2),(arg-3));", ret.toString());
+ assertEquals("return Phi(Region21,(arg+2),(arg-3));", ret.toString());
}
@Test
@@ -37,7 +37,7 @@ if (arg == 1) {
}
return c;""", TypeInteger.BOT);
StopNode ret = parser.parse().iterate();
- assertEquals("return Phi(Region18,4,3);", ret.toString());
+ assertEquals("return Phi(Region20,4,3);", ret.toString());
}
@Test
@@ -65,7 +65,7 @@ else
b=a+1;
return a+b;""");
StopNode ret = parser.parse().iterate();
- assertEquals("return ((arg*2)+Phi(Region22,2,3));", ret.toString());
+ assertEquals("return ((arg*2)+Phi(Region24,2,3));", ret.toString());
}
@Test
@@ -80,7 +80,7 @@ else
a=b+1;
return a+b;""");
StopNode ret = parser.parse().iterate();
- assertEquals("return ((Phi(Region33,(arg*2),arg)+arg)+Phi(Region,4,5));", ret.toString());
+ assertEquals("return ((Phi(Region35,(arg*2),arg)+arg)+Phi(Region,4,5));", ret.toString());
}
@Test
@@ -100,7 +100,7 @@ else
return a;
""", TypeInteger.BOT);
StopNode stop = parser.parse().iterate();
- assertEquals("return Phi(Region37,Phi(Region23,2,3),Phi(Region35,4,5));", stop.toString());
+ assertEquals("return Phi(Region39,Phi(Region25,2,3),Phi(Region37,4,5));", stop.toString());
}
@Test
@@ -116,7 +116,7 @@ if( arg==0 )
return arg+a+b;
""", TypeInteger.BOT);
StopNode stop = parser.parse();
- assertEquals("return ((arg+Phi(Region16,1,0))+Phi(Region32,2,0));", stop.toString());
+ assertEquals("return ((arg+Phi(Region18,1,0))+Phi(Region34,2,0));", stop.toString());
}
@Test
@@ -130,7 +130,7 @@ if( arg==1 )
}
return a;""");
StopNode ret = parser.parse().iterate();
- assertEquals("return (arg==Phi(Region18,3,2));", ret.toString());
+ assertEquals("return (arg==Phi(Region20,3,2));", ret.toString());
}
@Test
diff --git a/src/test/java/com/seaofnodes/simple/Chapter06Test.java b/src/test/java/com/seaofnodes/simple/Chapter06Test.java
index 9af11b68..43e46a5d 100644
--- a/src/test/java/com/seaofnodes/simple/Chapter06Test.java
+++ b/src/test/java/com/seaofnodes/simple/Chapter06Test.java
@@ -17,7 +17,7 @@ return 1;
""");
StopNode stop = parser.parse().iterate();
assertEquals("return 2;", stop.toString());
- assertTrue(stop.ret().ctrl() instanceof ProjNode);
+ assertTrue(stop.ret().ctrl() instanceof CProjNode);
}
@Test
@@ -30,7 +30,7 @@ if (arg)
return (arg < a) < 3;
""");
StopNode stop = parser.parse().iterate();
- assertEquals("return ((arg<Phi(Region15,2,1))<3);", stop.toString());
+ assertEquals("return ((arg<Phi(Region17,2,1))<3);", stop.toString());
}
@Test
@@ -46,7 +46,7 @@ return a;
""");
StopNode stop = parser.parse().iterate();
assertEquals("return 2;", stop.toString());
- assertTrue(stop.ret().ctrl() instanceof ProjNode);
+ assertTrue(stop.ret().ctrl() instanceof CProjNode);
}
@Test
@@ -65,7 +65,7 @@ else
b=5;
return b;""", TypeInteger.BOT);
StopNode stop = parser.parse().iterate();
- assertEquals("return Phi(Region38,42,5);", stop.toString());
+ assertEquals("return Phi(Region40,42,5);", stop.toString());
}
@Test
@@ -84,7 +84,7 @@ else
b=5;
return b;""", TypeInteger.BOT);
StopNode stop = parser.parse().iterate();
- assertEquals("return Phi(Region31,2,5);", stop.toString());
+ assertEquals("return Phi(Region33,2,5);", stop.toString());
}
@Test
@@ -144,7 +144,7 @@ else
return a;
""", TypeInteger.BOT);
StopNode stop = parser.parse().iterate();
- assertEquals("return Phi(Region42,3,Phi(Region40,4,5));", stop.toString());
+ assertEquals("return Phi(Region44,3,Phi(Region42,4,5));", stop.toString());
}
@Test
@@ -200,7 +200,7 @@ if( arg ) {
return a+b;
""");
StopNode ret = parser.parse().iterate();
- assertEquals("return Phi(Region27,4,1);", ret.toString());
+ assertEquals("return Phi(Region29,4,1);", ret.toString());
}
@@ -251,7 +251,7 @@ if( arg ) {
return a+b+c;
""");
StopNode ret = parser.parse().iterate();
- assertEquals("return (Phi(Region39,Phi(Region24,2,3),0)+Phi(Region,3,1));", ret.toString());
+ assertEquals("return (Phi(Region41,Phi(Region26,2,3),0)+Phi(Region,3,1));", ret.toString());
}
diff --git a/src/test/java/com/seaofnodes/simple/Chapter07Test.java b/src/test/java/com/seaofnodes/simple/Chapter07Test.java
index ff0ca599..222982e7 100644
--- a/src/test/java/com/seaofnodes/simple/Chapter07Test.java
+++ b/src/test/java/com/seaofnodes/simple/Chapter07Test.java
@@ -18,8 +18,8 @@ public class Chapter07Test {
return arg;
""");
StopNode stop = parser.parse();
- assertEquals("return Phi(Loop7,arg,(Phi_arg+1));", stop.toString());
- assertTrue(stop.ret().ctrl() instanceof ProjNode);
+ assertEquals("return Phi(Loop9,arg,(Phi_arg+1));", stop.toString());
+ assertTrue(stop.ret().ctrl() instanceof CProjNode);
}
@Test
@@ -35,7 +35,7 @@ if(arg){}else{
return a;
""");
StopNode stop = parser.parse().iterate();
- assertEquals("return Phi(Region25,1,Phi(Loop14,1,(Phi_a+1)));", stop.toString());
+ assertEquals("return Phi(Region27,1,Phi(Loop16,1,(Phi_a+1)));", stop.toString());
}
@Test
@@ -55,7 +55,7 @@ while(i < arg) {
return sum;
""");
StopNode stop = parser.parse().iterate();
- assertEquals("return Phi(Loop9,0,Phi(Loop21,Phi_sum,(Phi_sum+Phi(Loop,0,(Phi_j+1)))));", stop.toString());
+ assertEquals("return Phi(Loop11,0,Phi(Loop23,Phi_sum,(Phi_sum+Phi(Loop,0,(Phi_j+1)))));", stop.toString());
}
@Test
@@ -71,8 +71,8 @@ while(a < 10) {
return b;
""");
StopNode stop = parser.parse();
- assertEquals("return Phi(Loop9,2,Phi(Region28,Phi_b,4));", stop.toString());
- assertTrue(stop.ret().ctrl() instanceof ProjNode);
+ assertEquals("return Phi(Loop11,2,Phi(Region30,Phi_b,4));", stop.toString());
+ assertTrue(stop.ret().ctrl() instanceof CProjNode);
}
@Test
@@ -90,8 +90,8 @@ while(a < 10) {
return b;
""");
StopNode stop = parser.parse().iterate();
- assertEquals("return Phi(Loop9,2,(Phi(Region28,Phi_b,4)+1));", stop.toString());
- assertTrue(stop.ret().ctrl() instanceof ProjNode);
+ assertEquals("return Phi(Loop11,2,(Phi(Region30,Phi_b,4)+1));", stop.toString());
+ assertTrue(stop.ret().ctrl() instanceof CProjNode);
}
@@ -107,8 +107,8 @@ while(a < 10) {
return a;
""");
StopNode stop = parser.parse();
- assertEquals("return Phi(Loop8,1,(Phi_a+3));", stop.toString());
- assertTrue(stop.ret().ctrl() instanceof ProjNode);
+ assertEquals("return Phi(Loop10,1,(Phi_a+3));", stop.toString());
+ assertTrue(stop.ret().ctrl() instanceof CProjNode);
}
@Test
@@ -123,8 +123,8 @@ while(a < 10) {
return a;
""");
StopNode stop = parser.parse().iterate();
- assertEquals("return Phi(Loop8,1,(Phi_a+3));", stop.toString());
- assertTrue(stop.ret().ctrl() instanceof ProjNode);
+ assertEquals("return Phi(Loop10,1,(Phi_a+3));", stop.toString());
+ assertTrue(stop.ret().ctrl() instanceof CProjNode);
}
@Test
@@ -136,8 +136,8 @@ while(arg) a = 2;
return a;
""");
StopNode stop = parser.parse();
- assertEquals("return Phi(Loop8,1,2);", stop.toString());
- assertTrue(stop.ret().ctrl() instanceof ProjNode);
+ assertEquals("return Phi(Loop10,1,2);", stop.toString());
+ assertTrue(stop.ret().ctrl() instanceof CProjNode);
}
@Test
@@ -149,8 +149,8 @@ while(arg) a = 2;
return a;
""");
StopNode stop = parser.parse().iterate();
- assertEquals("return Phi(Loop8,1,2);", stop.toString());
- assertTrue(stop.ret().ctrl() instanceof ProjNode);
+ assertEquals("return Phi(Loop10,1,2);", stop.toString());
+ assertTrue(stop.ret().ctrl() instanceof CProjNode);
}
@Test
@@ -165,8 +165,8 @@ while(a < 10) {
return a;
""");
StopNode stop = parser.parse();
- assertEquals("return Phi(Loop8,1,(Phi_a+3));", stop.toString());
- assertTrue(stop.ret().ctrl() instanceof ProjNode);
+ assertEquals("return Phi(Loop10,1,(Phi_a+3));", stop.toString());
+ assertTrue(stop.ret().ctrl() instanceof CProjNode);
}
@Test
@@ -181,8 +181,8 @@ while(a < 10) {
return a;
""");
StopNode stop = parser.parse().iterate();
- assertEquals("return Phi(Loop8,1,(Phi_a+3));", stop.toString());
- assertTrue(stop.ret().ctrl() instanceof ProjNode);
+ assertEquals("return Phi(Loop10,1,(Phi_a+3));", stop.toString());
+ assertTrue(stop.ret().ctrl() instanceof CProjNode);
}
@Test
@@ -198,8 +198,8 @@ while(a < 10) {
return a;
""");
StopNode stop = parser.parse();
- assertEquals("return Phi(Loop9,1,(Phi_a+3));", stop.toString());
- assertTrue(stop.ret().ctrl() instanceof ProjNode);
+ assertEquals("return Phi(Loop11,1,(Phi_a+3));", stop.toString());
+ assertTrue(stop.ret().ctrl() instanceof CProjNode);
}
@Test
@@ -215,8 +215,8 @@ while(a < 10) {
return a;
""");
StopNode stop = parser.parse().iterate();
- assertEquals("return Phi(Loop9,1,(Phi_a+3));", stop.toString());
- assertTrue(stop.ret().ctrl() instanceof ProjNode);
+ assertEquals("return Phi(Loop11,1,(Phi_a+3));", stop.toString());
+ assertTrue(stop.ret().ctrl() instanceof CProjNode);
}
}
diff --git a/src/test/java/com/seaofnodes/simple/Chapter08Test.java b/src/test/java/com/seaofnodes/simple/Chapter08Test.java
index 02c3a301..89ce8313 100644
--- a/src/test/java/com/seaofnodes/simple/Chapter08Test.java
+++ b/src/test/java/com/seaofnodes/simple/Chapter08Test.java
@@ -2,7 +2,6 @@ package com.seaofnodes.simple;
import com.seaofnodes.simple.evaluator.Evaluator;
import com.seaofnodes.simple.node.*;
-import com.seaofnodes.simple.type.TypeInteger;
import org.junit.Assert;
import org.junit.Test;
@@ -24,7 +23,7 @@ while(arg < 10) {
return arg;
""");
StopNode stop = parser.parse().iterate();
- assertEquals("return Phi(Region38,Phi(Region26,Phi(Loop7,arg,(Phi_arg+1)),Add),Add);", stop.toString());
+ assertEquals("return Phi(Region38,Phi(Region27,Phi(Loop9,arg,(Phi_arg+1)),Add),Add);", stop.toString());
assertTrue(stop.ret().ctrl() instanceof RegionNode);
Assert.assertEquals(5L, Evaluator.evaluate(stop, 1));
Assert.assertEquals(10L, Evaluator.evaluate(stop, 6));
@@ -47,8 +46,8 @@ while(arg < 10) {
return a;
""");
StopNode stop = parser.parse().iterate();
- assertEquals("return Phi(Loop8,1,Phi(Region45,Phi_a,(Phi_a+1)));", stop.toString());
- assertTrue(stop.ret().ctrl() instanceof ProjNode);
+ assertEquals("return Phi(Loop10,1,Phi(Region44,Phi_a,(Phi_a+1)));", stop.toString());
+ assertTrue(stop.ret().ctrl() instanceof CProjNode);
}
@@ -66,7 +65,7 @@ while(arg < 10) {
return arg;
""");
StopNode stop = parser.parse().iterate();
- assertEquals("return Phi(Region36,Phi(Loop7,arg,(Phi_arg+1)),Add);", stop.toString());
+ assertEquals("return Phi(Region36,Phi(Loop9,arg,(Phi_arg+1)),Add);", stop.toString());
assertTrue(stop.ret().ctrl() instanceof RegionNode);
}
@@ -82,7 +81,7 @@ while(arg < 10) {
return arg;
""");
StopNode stop = parser.parse().iterate();
- assertEquals("return Phi(Region26,Phi(Loop7,arg,(Phi_arg+1)),Add);", stop.toString());
+ assertEquals("return Phi(Region27,Phi(Loop9,arg,(Phi_arg+1)),Add);", stop.toString());
assertTrue(stop.ret().ctrl() instanceof RegionNode);
}
@@ -101,8 +100,8 @@ while(arg < 10) {
return arg;
""");
StopNode stop = parser.parse().iterate();
- assertEquals("return Phi(Loop7,arg,(Phi_arg+1));", stop.toString());
- assertTrue(stop.ret().ctrl() instanceof ProjNode);
+ assertEquals("return Phi(Loop9,arg,(Phi_arg+1));", stop.toString());
+ assertTrue(stop.ret().ctrl() instanceof CProjNode);
}
@@ -118,8 +117,8 @@ while(arg < 10) {
return arg;
""");
StopNode stop = parser.parse().iterate();
- assertEquals("return Phi(Loop7,arg,(Phi_arg+1));", stop.toString());
- assertTrue(stop.ret().ctrl() instanceof ProjNode);
+ assertEquals("return Phi(Loop9,arg,(Phi_arg+1));", stop.toString());
+ assertTrue(stop.ret().ctrl() instanceof CProjNode);
}
@Test
@@ -186,7 +185,7 @@ while(arg < 10) {
return a;
""");
StopNode stop = parser.parse().iterate();
- assertEquals("return Phi(Region29,Phi(Loop8,1,(Phi_a+1)),Add);", stop.toString());
+ assertEquals("return Phi(Region30,Phi(Loop10,1,(Phi_a+1)),Add);", stop.toString());
assertTrue(stop.ret().ctrl() instanceof RegionNode);
}
@@ -202,8 +201,8 @@ while(1) {
return a;
""");
StopNode stop = parser.parse().iterate();
- assertEquals("return (Phi(Loop8,1,Add)+1);", stop.toString());
- assertTrue(stop.ret().ctrl() instanceof ProjNode prj && prj._idx==1 );
+ assertEquals("return (Phi(Loop10,1,Add)+1);", stop.toString());
+ assertTrue(stop.ret().ctrl() instanceof CProjNode prj && prj._idx==1 );
}
}
diff --git a/src/test/java/com/seaofnodes/simple/Chapter09Test.java b/src/test/java/com/seaofnodes/simple/Chapter09Test.java
index b1fdc459..49ee75a2 100644
--- a/src/test/java/com/seaofnodes/simple/Chapter09Test.java
+++ b/src/test/java/com/seaofnodes/simple/Chapter09Test.java
@@ -5,7 +5,6 @@ import com.seaofnodes.simple.node.*;
import com.seaofnodes.simple.type.Type;
import com.seaofnodes.simple.type.TypeInteger;
import org.junit.Assert;
-import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.Ignore;
@@ -70,7 +69,7 @@ while (arg < 10) {
return arg;
""");
StopNode stop = parser.parse().iterate();
- assertEquals("return Phi(Loop8,arg,(Phi_arg+2));", stop.toString());
+ assertEquals("return Phi(Loop10,arg,(Phi_arg+2));", stop.toString());
Assert.assertEquals(11L, Evaluator.evaluate(stop, 1));
}
@@ -87,7 +86,7 @@ while (arg < 10) {
return arg;
""");
StopNode stop = parser.parse().iterate();
- assertEquals("return Phi(Loop9,arg,(Phi_arg+4));", stop.toString());
+ assertEquals("return Phi(Loop11,arg,(Phi_arg+4));", stop.toString());
Assert.assertEquals(13L, Evaluator.evaluate(stop, 1));
}
@@ -116,7 +115,7 @@ while (arg) {
return arg;
""");
StopNode stop = parser.parse().iterate();
- assertEquals("return Phi(Loop15,arg,(Phi_arg+1));", stop.toString());
+ assertEquals("return Phi(Loop17,arg,(Phi_arg+1));", stop.toString());
}
@Test
@@ -134,7 +133,7 @@ while(v1+arg) {
}
""");
StopNode stop = parser.parse().iterate();
- assertEquals("return 0;", stop.toString());
+ assertEquals("Stop[ return 0; return 0; ]", stop.toString());
}
@Test
@@ -186,7 +185,7 @@ while(arg) {
return a;
""");
StopNode stop = parser.parse().iterate();
- assertEquals("return Phi(Loop10,0,(-(Phi_a+3)));", stop.toString());
+ assertEquals("return Phi(Loop12,0,(-(Phi_a+3)));", stop.toString());
}
@Test
@@ -200,7 +199,7 @@ int v0=0!=0<-0;
return -0+0+0;
""");
StopNode stop = parser.parse().iterate();
- assertEquals("Stop[ ]", stop.toString());
+ assertEquals("return 0;", stop.toString());
}
@@ -227,7 +226,7 @@ while(1) {
}
""");
StopNode stop = parser.parse().iterate();
- assertEquals("Stop[ ]", stop.toString());
+ assertEquals("return 0;", stop.toString());
}
@Test
@@ -249,16 +248,17 @@ while(1) {
return 0!=0;
""");
StopNode stop = parser.parse().iterate();
- assertEquals("Stop[ ]", stop.toString());
+ assertEquals("return 0;", stop.toString());
}
@Test
public void testFuzz6() {
- Parser parser = new Parser("""
+ Parser parser = new Parser(
+"""
int v0=0;
while(0==1) while(v0)
v0=1+v0;
- """);
+""");
StopNode stop = parser.parse().iterate();
assertEquals("return 0;", stop.toString());
}
@@ -276,14 +276,14 @@ while(1)
return v1+v0;
""");
StopNode stop = parser.parse().iterate();
- assertEquals("Stop[ ]", stop.toString());
+ assertEquals("return 0;", stop.toString());
}
@Test
public void testFuzz8() {
Parser parser = new Parser("while(arg) arg = arg - 1; return arg;");
StopNode stop = parser.parse().iterate();
- assertEquals("return Phi(Loop7,arg,(Phi_arg-1));", stop.toString());
+ assertEquals("return Phi(Loop9,arg,(Phi_arg-1));", stop.toString());
}
@Test
diff --git a/src/test/java/com/seaofnodes/simple/Chapter10Test.java b/src/test/java/com/seaofnodes/simple/Chapter10Test.java
index e5d9b882..6649c0b0 100644
--- a/src/test/java/com/seaofnodes/simple/Chapter10Test.java
+++ b/src/test/java/com/seaofnodes/simple/Chapter10Test.java
@@ -2,15 +2,11 @@ package com.seaofnodes.simple;
import com.seaofnodes.simple.node.Node;
import com.seaofnodes.simple.node.StopNode;
-import com.seaofnodes.simple.type.*;
import com.seaofnodes.simple.node.LoadNode;
import com.seaofnodes.simple.node.StoreNode;
import com.seaofnodes.simple.evaluator.Evaluator;
import java.util.BitSet;
import org.junit.Test;
-
-import java.util.Arrays;
-
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
@@ -44,7 +40,7 @@ public class Chapter10Test {
"if (p != null) return p.x; return -1;",
"if (null != p) return p.x; return -1;",
"if (!!!!p) return p.x; return -1;",
- "if (!!!p) return -1; else return p.x;",
+ "if (!!!p) return -1; return p.x;",
"int b = !!p; if (b) return p.x + b - 1; return -1;"
} ) {
StopNode stop = new Parser(NULLABLE_POINT_SOURCE+body).parse().iterate();
@@ -169,7 +165,7 @@ while (arg) {
return bar.a;
""");
StopNode stop = parser.parse().iterate();
- assertEquals("return Phi(Loop11,0,(Phi_a+2));", stop.toString());
+ assertEquals("return Phi(Loop13,0,(Phi_a+2));", stop.toString());
}
@Test
@@ -221,7 +217,7 @@ if( bar ) bar.a = 1;
return bar;
""");
StopNode stop = parser.parse().iterate();
- assertEquals("return Phi(Region31,(*void)Phi(Region18,null,new Bar),null);", stop.toString());
+ assertEquals("return Phi(Region33,(*void)Phi(Region20,null,new Bar),null);", stop.toString());
}
@Test
@@ -237,7 +233,7 @@ else bar.a = 1;
return rez;
""");
StopNode stop = parser.parse().iterate();
- assertEquals("return Phi(Region37,4,3);", stop.toString());
+ assertEquals("return Phi(Region39,4,3);", stop.toString());
}
@Test
@@ -254,7 +250,8 @@ while(arg) {
return ret;
""");
try { parser.parse().iterate(); fail(); }
- catch( Exception e ) { assertEquals("Might be null accessing 'v0'", e.getMessage()); }
+ catch( Exception e ) {
+ assertEquals("Might be null accessing 'v0'", e.getMessage()); }
}
@Test
@@ -290,7 +287,7 @@ while( i.x < i.len ) {
return sum;
""");
StopNode stop = parser.parse().iterate();
- assertEquals("return Phi(Loop17,0,(Phi(Loop,0,(Phi_x+1))+Phi_sum));", stop.toString());
+ assertEquals("return Phi(Loop19,0,(Phi(Loop,0,(Phi_x+1))+Phi_sum));", stop.toString());
}
@@ -306,11 +303,12 @@ while(arg) {
v0.v0 = arg;
arg = arg-1;
if (arg==5) ret=v0;
+
}
return ret;
""");
StopNode stop = parser.parse().iterate();
- assertEquals("return Phi(Loop11,new s0,Phi(Region35,new s0,Phi_ret));", stop.toString());
+ assertEquals("return Phi(Loop13,new s0,Phi(Region37,new s0,Phi_ret));", stop.toString());
}
@Test
@@ -323,11 +321,12 @@ while(arg) {
v0.v0 = arg;
arg = arg-1;
if (arg==5) ret=v0;
+
}
return ret;
""");
StopNode stop = parser.parse().iterate();
- assertEquals("return Phi(Loop15,new s0,Phi(Region36,new s0,Phi_ret));", stop.toString());
+ assertEquals("return Phi(Loop17,new s0,Phi(Region38,new s0,Phi_ret));", stop.toString());
}
@@ -344,7 +343,7 @@ while(arg < 10) {
return ret;
""");
StopNode stop = parser.parse().iterate();
- assertEquals("return Phi(Loop11,new s0,Phi(Region33,new s0,Phi_ret));", stop.toString());
+ assertEquals("return Phi(Loop13,new s0,Phi(Region35,new s0,Phi_ret));", stop.toString());
}
@Test
@@ -462,7 +461,6 @@ return 0;
assertEquals("return 0;", stop.toString());
}
-
@Test public void testReadBeforeStores() {
var stop = new Parser("""
struct S { int x; int y; }
@@ -549,8 +547,8 @@ return 0;
if (arg) s.x=arg+1; else s.x=arg+2;
return s;
""").parse().iterate();
- // Releasing the old aggregate exposes the overwritten initializing Store.
- assertEquals(1,countMemoryNodes(stop,StoreNode.class,new BitSet()));
+ // These chapters still bind struct Stores to branch control.
+ assertEquals(3,countMemoryNodes(stop,StoreNode.class,new BitSet()));
assertEquals(2L,((Evaluator.Obj)Evaluator.evaluate(stop,0)).fields()[0]);
assertEquals(4L,((Evaluator.Obj)Evaluator.evaluate(stop,3)).fields()[0]);
}
diff --git a/src/test/java/com/seaofnodes/simple/Chapter12Test.java b/src/test/java/com/seaofnodes/simple/Chapter12Test.java
index 0d4f3c97..cbb50dba 100644
--- a/src/test/java/com/seaofnodes/simple/Chapter12Test.java
+++ b/src/test/java/com/seaofnodes/simple/Chapter12Test.java
@@ -29,7 +29,7 @@ while( arg ) {
return head.next.i;
""");
try { parser.parse().iterate(); fail(); }
- catch( Exception e ) { assertEquals("Might be null accessing 'next'",e.getMessage()); }
+ catch( Exception e ) { assertEquals("Might be null accessing 'i'",e.getMessage()); }
}
@Test
diff --git a/src/test/java/com/seaofnodes/simple/Chapter13Test.java b/src/test/java/com/seaofnodes/simple/Chapter13Test.java
new file mode 100644
index 00000000..2929d1a4
--- /dev/null
+++ b/src/test/java/com/seaofnodes/simple/Chapter13Test.java
@@ -0,0 +1,532 @@
+package com.seaofnodes.simple;
+
+
+import com.seaofnodes.simple.evaluator.Evaluator;
+import com.seaofnodes.simple.node.StopNode;
+import org.junit.Test;
+
+
+import static org.junit.Assert.assertEquals;
+
+public class Chapter13Test {
+
+ // A placeholder test used to rapidly rotate through fuzzer produced issues
+ @Test
+ public void testFuzzer() {
+ Parser parser = new Parser(
+"""
+while(-----arg) {
+ while(-arg) {
+ while(-----arg*---0) {
+ int N=--false==false<--arg;
+ while(N<-4==N) {
+ N=N+N;
+ }
+ }
+ {
+ int kzEl_r7EYz=3*----0!=-arg<(37*--97!=0/arg==arg)<=-(--arg!=0);
+ while(kzEl_r7EYz<---1) {
+ kzEl_r7EYz=kzEl_r7EYz+kzEl_r7EYz*arg>=24;
+ if(7) continue;
+ kzEl_r7EYz=false;
+ if(-kzEl_r7EYz+arg<-3) continue;
+ else {
+ while(kzEl_r7EYz) continue;
+ arg=----3;
+ kzEl_r7EYz=-(-----arg*1>-kzEl_r7EYz);
+ int v2uF_4ba=9;
+ }
+ }
+ }
+ int pjcp7rv=arg;
+ {
+ int m2ya3=--arg-pjcp7rv;
+ while(m2ya3<-----pjcp7rv>=pjcp7rv+--pjcp7rv!=---pjcp7rv!=-arg<---(-m2ya3)>m2ya3<=-----true>14!=--m2ya3) {
+ m2ya3=m2ya3+-(--0<=false<pjcp7rv/arg<=-true);
+ while((--m2ya3)<--arg<-----arg*false!=arg<pjcp7rv*arg) {
+ pjcp7rv=-3+-arg;
+ break;
+ }
+ while(-3) {
+ while(67+0-61) m2ya3=m2ya3;
+ if(----pjcp7rv==---(---arg)) pjcp7rv=0!=-23;
+ else pjcp7rv=----89;
+ while(m2ya3!=m2ya3<pjcp7rv) m2ya3=1;
+ while(--arg<=pjcp7rv) pjcp7rv=-32<=-m2ya3+62;
+ }
+ break;
+ }
+ }
+ {
+ int arg=-1<-9!=(-arg>=-pjcp7rv>=arg<=arg);
+ while(arg<-arg) {
+ arg=arg+--arg;
+ {
+ while((--93)--pjcp7rv*-pjcp7rv+arg) arg=0-(6>=(--(---41/(0))!=--pjcp7rv)>=---2*33);
+ pjcp7rv=11;
+ int c=pjcp7rv;
+ if(--107) break;
+ else break;
+ }
+ }
+ }
+ pjcp7rv=pjcp7rv;
+ int aR0Wkua=-pjcp7rv==pjcp7rv;
+ {
+ if(-0!=-0) while(-true) break;
+ else {
+ while(aR0Wkua) pjcp7rv=-0/pjcp7rv;
+ pjcp7rv=pjcp7rv;
+ }
+ }
+ }
+ if(-arg) {
+ {
+ int Isdlt0fr91=0!=arg;
+ while(Isdlt0fr91<-Isdlt0fr91==-Isdlt0fr91+true) {
+ Isdlt0fr91=Isdlt0fr91+-1!=true;
+ if(-arg) if(--arg<=Isdlt0fr91) Isdlt0fr91=-Isdlt0fr91;
+ int i=---arg<---arg!=--40;
+ {
+ int jVX43Ln4Dm=-(6)==-Isdlt0fr91/----0;
+ while(jVX43Ln4Dm<--(3-3)) {
+ jVX43Ln4Dm=jVX43Ln4Dm+-0<25;
+ i=24<--(jVX43Ln4Dm);
+ }
+ }
+ i=(arg!=----false>=7);
+ int Te=5>-arg;
+ break;
+ }
+ }
+ arg=arg!=--true/arg;
+ {
+ int UX=arg;
+ while(UX<-3*arg) {
+ UX=UX+arg/-1;
+ arg=-3--(-UX--47<arg==--arg==arg)/arg--UX>=-arg;
+ if(---12) while(-UX) break;
+ break;
+ }
+ }
+ continue;
+ }
+ if(arg) arg=--0;
+ else if(1) continue;
+ int DtTlhjYq=19==arg;
+ {
+ arg=--DtTlhjYq<=(DtTlhjYq/---DtTlhjYq<=-DtTlhjYq);
+ if(---arg) continue;
+ else {
+ int Zsl=40;
+ while(Zsl<--Zsl--false>((Zsl))==Zsl!=--DtTlhjYq-DtTlhjYq-DtTlhjYq) {
+ Zsl=Zsl+arg;
+ }
+ }
+ if((arg)) if(-DtTlhjYq) {
+ }
+ else while(((2)==3*arg/DtTlhjYq)<=0==---arg) return false;
+ else {
+ int lwbF=arg>=0;
+ while(lwbF<57) {
+ lwbF=lwbF+--(-arg+lwbF)>=-2>=arg!=arg;
+ arg=----0+0;
+ while(49) break;
+ if(true) DtTlhjYq=-----arg;
+ DtTlhjYq=0!=-----(0);
+ }
+ }
+ arg=---arg!=DtTlhjYq/--0;
+ DtTlhjYq=-DtTlhjYq/(--arg<arg);
+ if(32) {
+ int q=-DtTlhjYq;
+ while(q<arg*(0*q)/0) {
+ q=q+DtTlhjYq;
+ DtTlhjYq=arg;
+ }
+ }
+ else if(--arg) if(15) break;
+ else arg=0==arg<=-55>DtTlhjYq;
+ else {
+ }
+ DtTlhjYq=-0;
+ {
+ while((0)<-arg) DtTlhjYq=-DtTlhjYq;
+ }
+ if(30/--(arg)>=0) DtTlhjYq=-0>=arg;
+ else {
+ int Y2wcIQJ=--DtTlhjYq*---11;
+ if(arg==arg) {
+ Y2wcIQJ=-----Y2wcIQJ;
+ Y2wcIQJ=Y2wcIQJ<7;
+ if(DtTlhjYq) arg=arg;
+ else break;
+ while(-arg!=-31==(false<=-15>=-DtTlhjYq+--6*-----Y2wcIQJ<=---arg!=-Y2wcIQJ<=---0<-arg*--Y2wcIQJ)) DtTlhjYq=arg!=3;
+ }
+ continue;
+ }
+ arg=DtTlhjYq;
+ arg=--3/(---arg)>=80>=-DtTlhjYq<=DtTlhjYq;
+ arg=51+---(-true)!=arg!=----1==-DtTlhjYq;
+ if(11<=arg) if((arg)+79<32+(-arg)) continue;
+ else if(true==DtTlhjYq) break;
+ break;
+ }
+}
+if(arg!=62==arg) {
+ while(---arg) {
+ {
+ int bhmDacPM=arg/arg;
+ while(bhmDacPM<arg) {
+ bhmDacPM=bhmDacPM+80*((-bhmDacPM)/---bhmDacPM>1)<bhmDacPM-2!=7;
+ arg=-0;
+ arg=bhmDacPM>=-arg+-arg;
+ break;
+ }
+ }
+ int arg=true;
+ arg=arg<=arg;
+ {
+ int KlC=30;
+ while(KlC<-2) {
+ KlC=KlC+-1!=25<=-KlC>KlC>----0;
+ int Ij=arg>=-arg<=---10;
+ {
+ int LAbgurVa2R=-arg!=Ij;
+ while(LAbgurVa2R<-true) {
+ LAbgurVa2R=LAbgurVa2R+Ij;
+ KlC=-LAbgurVa2R;
+ Ij=42*(-Ij>true);
+ while(Ij) arg=KlC;
+ KlC=-----7>-(--KlC<--7)==-LAbgurVa2R;
+ }
+ }
+ int a=Ij<=-KlC;
+ if(Ij) {
+ int r1W=a!=-false;
+ }
+ else {
+ arg=56>=Ij;
+ while(54) break;
+ arg=8>=-(a<--Ij)/a>=-a-KlC;
+ }
+ int Yt_T=KlC;
+ arg=KlC;
+ }
+ }
+ if(----false/--arg/12+-----0) if(-9+-arg) while(arg!=(arg)) arg=--1>=-71-arg!=---(--arg*11+102)/--arg;
+ else if(----arg) continue;
+ if(-arg-arg) {
+ arg=-(-arg)*--(-3)<(-7==-arg----arg);
+ {
+ int arg=arg;
+ while(arg<-0>arg==-arg-(-arg>1+11)) {
+ arg=arg+6-arg!=--0>---30>=---arg<=arg/(3)+---arg;
+ }
+ }
+ arg=-arg+arg;
+ arg=--47+-arg<1>arg*(-arg==-arg--0>3);
+ arg=(----arg)!=arg+--59;
+ arg=--4+arg==-(arg)-arg;
+ }
+ else {
+ while(--true-----true*-25+-18>arg>=-----(-arg)---13) {
+ arg=-0+--true<false;
+ continue;
+ }
+ arg=true<=arg;
+ break;
+ }
+ arg=arg*22<--(0+-arg);
+ {
+ continue;
+ }
+ }
+ arg=1*---((3<=true)==---2);
+ arg=7+-(-1);
+ return arg+--true;
+}
+else {
+ int o3ypEsewxM=-(---arg);
+ int vzXB=(-(---11<=--o3ypEsewxM>=--0))<=-0/-arg;
+ int L=-arg;
+ int B4mHcrf=---vzXB;
+ int oZWGdzZl=-o3ypEsewxM;
+ int K6tQqa1=11;
+ while(0!=--L) {
+ int sdZfTM=vzXB*true+K6tQqa1;
+ while(sdZfTM<false) {
+ sdZfTM=sdZfTM+arg;
+ sdZfTM=oZWGdzZl;
+ K6tQqa1=-K6tQqa1;
+ arg=---K6tQqa1;
+ while((3+-K6tQqa1)<oZWGdzZl) {
+ if(-----(-1)) sdZfTM=-false;
+ {}
+ }
+ K6tQqa1=vzXB!=-(B4mHcrf+-7>false);
+ sdZfTM=vzXB;
+ }
+ }
+ L=false;
+ while(31) B4mHcrf=arg;
+ oZWGdzZl=-0<--oZWGdzZl<=--2;
+ if(K6tQqa1>=20<=46) {
+ if(-1+-L) if(oZWGdzZl) {
+ int wmhv=-----0;
+ }
+ int arg=0;
+ o3ypEsewxM=---(oZWGdzZl);
+ return -oZWGdzZl/0;
+ }
+ else if(arg) {
+ int yKk5=B4mHcrf>=4>K6tQqa1<-B4mHcrf/o3ypEsewxM;
+ return -K6tQqa1;
+ }
+ else {
+ if(---0) {
+ {}
+ {}
+ }
+ return o3ypEsewxM;
+ }
+}
+""");
+ StopNode stop = parser.parse().iterate();
+ assertEquals("Stop[ return 9; return 0; return 0; return 0; return 0; ]", stop.toString());
+ }
+
+
+ @Test
+ public void testPrimes() {
+ Parser parser = new Parser(
+"""
+if( arg < 2 ) return 0;
+int primeCount = 1;
+int prime = 3;
+while( prime <= arg ) {
+ int isPrime = 1;
+ // Check for even case, so the next loop need only check odds
+ if( (prime/2)*2 == prime )
+ continue;
+ // Check odds up to sqrt of prime
+ int j = 3;
+ while( j*j <= prime ) {
+ if( (prime/j)*j == prime ) {
+ isPrime = 0;
+ break;
+ }
+ j = j + 2;
+ }
+ if( isPrime )
+ primeCount = primeCount + 1;
+ prime = prime + 2;
+}
+return primeCount;
+""");
+ StopNode stop = parser.parse().iterate();
+ assertEquals("Stop[ return 0; return Phi(Loop21,1,Phi(Region88,Phi_primeCount,Phi(Region82,(Phi_primeCount+1),Phi_primeCount))); ]", stop.toString());
+ assertEquals(0L, Evaluator.evaluate(stop, 1)); // No primes 1 or below
+ assertEquals(1L, Evaluator.evaluate(stop, 2)); // 2
+ assertEquals(2L, Evaluator.evaluate(stop, 3)); // 2, 3
+ assertEquals(2L, Evaluator.evaluate(stop, 4)); // 2, 3
+ assertEquals(3L, Evaluator.evaluate(stop, 5)); // 2, 3, 5
+ assertEquals(4L, Evaluator.evaluate(stop, 10)); // 2, 3, 5, 7
+ }
+
+ @Test
+ public void testAntiDeps1() {
+ Parser parser = new Parser(
+"""
+struct S { int f; }
+S v=new S;
+v.f = 2;
+int i=new S.f;
+i=v.f;
+if (arg) v.f=1;
+return i;
+""");
+ StopNode stop = parser.parse().iterate();
+ assertEquals("return .f;", stop.toString());
+ }
+
+ @Test
+ public void testAntiDeps2() {
+ Parser parser = new Parser(
+"""
+struct S { int f; }
+S v = new S;
+S t = new S;
+int i = 0;
+if (arg) {
+ if (arg+1) v = t;
+ i = v.f;
+} else {
+ v.f = 2;
+}
+return i;
+""");
+ StopNode stop = parser.parse().iterate();
+ assertEquals("return Phi(Region37,.f,0);", stop.toString());
+ }
+
+ @Test
+ public void testAntiDeps3() {
+ Parser parser = new Parser(
+"""
+struct S { int f; }
+S v0 = new S;
+S? v1;
+if (arg) v1 = new S;
+if (v1) {
+ v0.f = v1.f;
+} else {
+ v0.f = 2;
+}
+return v0;
+""");
+ StopNode stop = parser.parse().iterate();
+ assertEquals("return new S;", stop.toString());
+ }
+
+
+ @Test
+ public void testAntiDeps4() {
+ Parser parser = new Parser(
+"""
+struct S { int f; }
+S v = new S;
+S t = new S;
+int i = v.f;
+if (arg+1) arg= 0;
+while (arg) v.f = 2;
+return i;
+""");
+ StopNode stop = parser.parse().iterate();
+ assertEquals("return .f;", stop.toString());
+ }
+
+ @Test
+ public void testAntiDeps5() {
+ Parser parser = new Parser(
+"""
+struct S { int f; }
+S v = new S;
+while(1) {
+ while(arg+1) { arg=arg-1; }
+ if (arg) break;
+ v.f = 2;
+}
+return v;
+""");
+ StopNode stop = parser.parse().iterate();
+ assertEquals("return new S;", stop.toString());
+ }
+
+ @Test
+ public void testAntiDeps6() {
+ Parser parser = new Parser(
+"""
+struct s { int v; }
+s ptr=new s;
+while( -arg )
+ ptr = new s;
+while(1)
+ arg = arg+ptr.v;
+""");
+ StopNode stop = parser.parse().iterate();
+ assertEquals("Stop[ return 0; return 0; ]", stop.toString());
+ }
+
+ @Test
+ public void testAntiDeps7() {
+ Parser parser = new Parser(
+"""
+struct S { int f; }
+S v = new S;
+S t = new S;
+int i = v.f;
+while (arg) {
+ v.f = arg;
+ arg = arg-1;
+}
+return i;
+""");
+ StopNode stop = parser.parse().iterate();
+ assertEquals("return .f;", stop.toString());
+ }
+
+ @Test
+ public void testAntiDeps8() {
+ Parser parser = new Parser(
+"""
+struct S { int f; }
+S v = new S;
+S t = new S;
+while(arg) {
+ arg=arg-1;
+ int f = v.f;
+ v.f = 2;
+ if (arg) arg = f;
+ else v.f = 3;
+}
+return arg;
+""");
+ StopNode stop = parser.parse().iterate();
+ assertEquals("return Phi(Loop17,arg,Phi(Region41,.f,0));", stop.toString());
+ }
+
+ @Test
+ public void testAntiDeps9() {
+ Parser parser = new Parser(
+"""
+struct S { int f; }
+S v = new S;
+S t = new S;
+if (arg) {
+ v.f=2;
+ int i=t.f;
+ v.f=i;
+}
+return v;
+""");
+ StopNode stop = parser.parse().iterate();
+ assertEquals("return new S;", stop.toString());
+ }
+
+ @Test
+ public void testExample2() {
+ Parser parser = new Parser(
+ """
+struct S { int f; }
+S v = new S;
+int i = arg;
+while (arg > 0) {
+ int j = i/3;
+ if (arg == 5)
+ v.f = j;
+ arg = arg - 1;
+}
+return v;
+ """);
+ StopNode stop = parser.parse().iterate();
+ //assertEquals("return new S;", stop.toString());
+ }
+
+ @Test
+ public void testSplit() {
+ Parser parser = new Parser(
+ """
+struct S { int f; }
+S s = new S;
+if( arg==0 ) s.f = 1;
+else if (arg == 1) s.f = 1;
+return s.f;
+""");
+ StopNode stop = parser.parse().iterate();
+ assertEquals("return Phi(Region43,1,Phi(Region38,1,0));", stop.toString());
+ assertEquals(1L, Evaluator.evaluate(stop, 0));
+ assertEquals(1L, Evaluator.evaluate(stop, 1));
+ assertEquals(0L, Evaluator.evaluate(stop, 2));
+ }
+}
diff --git a/src/test/java/com/seaofnodes/simple/FuzzerWrap.java b/src/test/java/com/seaofnodes/simple/FuzzerWrap.java
index 019140ad..52c2a014 100644
--- a/src/test/java/com/seaofnodes/simple/FuzzerWrap.java
+++ b/src/test/java/com/seaofnodes/simple/FuzzerWrap.java
@@ -29,8 +29,8 @@ public class FuzzerWrap {
fuzzer.fuzzPeepsRegression(seed);
}
- @Test
@Ignore
+ @Test
public void fuzzPeepsLarge() {
var fuzzer = new Fuzzer();
for (int i=0; i<1000000; i++)
diff --git a/src/test/java/com/seaofnodes/simple/TypeTest.java b/src/test/java/com/seaofnodes/simple/TypeTest.java
index 298fc6f8..9e8a1418 100644
--- a/src/test/java/com/seaofnodes/simple/TypeTest.java
+++ b/src/test/java/com/seaofnodes/simple/TypeTest.java
@@ -2,8 +2,8 @@ package com.seaofnodes.simple;
import com.seaofnodes.simple.type.*;
import org.junit.Assert;
+import org.junit.Ignore;
import org.junit.Test;
-
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
@@ -37,8 +37,8 @@ public class TypeTest {
Assert.assertEquals(TypeMem .BOT, m3.meet(m4));
Assert.assertEquals(m1, m1.glb());
- Assert.assertEquals(m1, m1.dual());
- Assert.assertEquals(m1, m1.glb().dual());
+ Assert.assertEquals(TypeMem.make(1), m1.dual());
+ Assert.assertEquals(m1.dual(), m1.glb().dual());
TypeMemPtr ptr1 = TypeMemPtr.make(s1);
Assert.assertEquals(s1, ptr1._obj);
@@ -128,10 +128,13 @@ public class TypeTest {
private static void check_symmetric( Type t0, Type t1 ) {
if( t1==t0 ) return;
Type mt = t0.meet(t1);
- Type ta = mt.dual().meet(t1.dual());
- Type tb = mt.dual().meet(t0.dual());
- assertSame(ta,t1.dual());
- assertSame(tb,t0.dual());
+ Type dm = mt.dual();
+ Type d0 = t0.dual();
+ Type d1 = t1.dual();
+ Type ta = dm.meet(d1);
+ Type tb = dm.meet(d0);
+ assertSame(ta,d1);
+ assertSame(tb,d0);
}
private static void assoc( Type t0, Type t1, Type t2 ) {
@@ -142,4 +145,13 @@ public class TypeTest {
assertSame(t01_2,t0_12);
}
+ // Test cyclic types and meets
+ @Test
+ public void testCyclic0() {
+ Type d0 = TypeStruct.S1.dual();
+ Type d1 = d0.dual();
+ assertSame(TypeStruct.S1,d1);
+ }
+
+
}
diff --git a/src/test/java/com/seaofnodes/simple/evaluator/Evaluator.java b/src/test/java/com/seaofnodes/simple/evaluator/Evaluator.java
index ac7c5e09..355d906b 100644
--- a/src/test/java/com/seaofnodes/simple/evaluator/Evaluator.java
+++ b/src/test/java/com/seaofnodes/simple/evaluator/Evaluator.java
@@ -140,7 +140,8 @@ public class Evaluator {
case StoreNode store -> store(store);
case MemMergeNode merge -> MEMORY;
case NewNode alloc -> alloc(alloc);
- case ProjNode proj -> ((Object[])val(proj.ctrl()))[proj._idx];
+ case CProjNode cproj -> ((Object[])val(cproj.ctrl()))[cproj._idx];
+ case ProjNode proj -> ((Object[])val( proj.in(0) ))[ proj._idx];
default -> throw new AssertionError("Unexpected node " + node);
};
}
diff --git a/src/test/java/com/seaofnodes/simple/evaluator/Scheduler.java b/src/test/java/com/seaofnodes/simple/evaluator/Scheduler.java
index 48ac0562..d16f4300 100644
--- a/src/test/java/com/seaofnodes/simple/evaluator/Scheduler.java
+++ b/src/test/java/com/seaofnodes/simple/evaluator/Scheduler.java
@@ -164,7 +164,7 @@ public class Scheduler {
* @return true if the node is not XCtrl.
*/
private static boolean isNotXCtrl(Node node) {
- return !(node instanceof ConstantNode c && c.compute() == Type.XCONTROL);
+ return !(node instanceof ConstantNode c && c.compute() == Type.XCONTROL) && !(node instanceof XCtrlNode);
}
/**
@@ -215,7 +215,7 @@ public class Scheduler {
private void refinePlacement(NodeData data, BasicBlock block) {
assert !isPinnedNode(data);
data.block = data.block == null ? block : dom(data.block, block);
- assert isValid(data) : data.node.uniqueName()+" at "+data.block.entry.uniqueName();
+ assert isValid(data);
}
/**
@@ -328,6 +328,8 @@ public class Scheduler {
for(int i=1; i<r.nIns(); i++) {
if (od(r.in(i)).map(d->d.block==null).orElse(false)) return false;
}
+ } else if (node instanceof XCtrlNode) {
+ return false;
} else {
assert d(node.in(0)).block != null;
}
@@ -403,7 +405,7 @@ public class Scheduler {
}
}
if (!(node instanceof ReturnNode))
- for (Node n:node._outputs) if (n.isCFG() && isCFGNodeReady(n) && d(n).block == null) queue.push(d(n));
+ for (Node n:node._outputs) if (n!=null && n.isCFG() && isCFGNodeReady(n) && d(n).block == null) queue.push(d(n));
var b = block;
for(var in:data.node._inputs) od(in).ifPresent(d->update(d, b));
}
@@ -449,7 +451,7 @@ public class Scheduler {
node = data.node;
assert node.isCFG();
if (!(node instanceof ReturnNode)) {
- for (var out : node._outputs) if (out.isCFG() && isNotXCtrl(out)) markAlive(cfgQueue, out, true);
+ for (var out : node._outputs) if (out!=null && out.isCFG() && isNotXCtrl(out)) markAlive(cfgQueue, out, true);
}
for (var in : node._inputs) if(in!=null && !in.isCFG() && isNotXCtrl(in)) markAlive(dataQueue, in, false);
}
@@ -503,7 +505,7 @@ public class Scheduler {
*/
private static Node findSingleCFGOut(Node node) {
if (node instanceof StartNode) {
- for(var n:node._outputs) if (n instanceof ProjNode p && p._idx==0) return p;
+ for(var n:node._outputs) if (n instanceof CProjNode p && p._idx==0) return p;
return null;
}
assert node._outputs.stream().filter(Node::isCFG).limit(2).count()<=1;
@@ -570,7 +572,7 @@ public class Scheduler {
switch(block.exit) {
case null: break;
case IfNode i:
- for(var out:i._outputs) if (out instanceof ProjNode p) block.next[p._idx] = blocks.get(p);
+ for(var out:i._outputs) if (out instanceof CProjNode p) block.next[p._idx] = blocks.get(p);
break;
case RegionNode r:
block.next[0] = blocks.get(r);