summaryrefslogtreecommitdiff
path: root/chapter13/src/test/java/com/seaofnodes
diff options
context:
space:
mode:
authorCliff Click <cliffc@acm.org>2026-09-27 08:52:12 -0700
committerCliff Click <cliffc@acm.org>2026-09-27 08:52:12 -0700
commitc5ef4e52fd7d183861b33476db999fa04f777607 (patch)
treefae4a9fb155a2e60b4b4390cd0ad3d30851257c8 /chapter13/src/test/java/com/seaofnodes
parent4391fcc03a214e6296e19ca42487de023ab12f6a (diff)
downloadSimple-c5ef4e52fd7d183861b33476db999fa04f777607.tar.gz
Simple-c5ef4e52fd7d183861b33476db999fa04f777607.zip
Remove -disablePeephole
Diffstat (limited to 'chapter13/src/test/java/com/seaofnodes')
-rw-r--r--chapter13/src/test/java/com/seaofnodes/simple/Chapter02Test.java4
-rw-r--r--chapter13/src/test/java/com/seaofnodes/simple/Chapter03Test.java9
-rw-r--r--chapter13/src/test/java/com/seaofnodes/simple/Chapter07Test.java18
-rw-r--r--chapter13/src/test/java/com/seaofnodes/simple/Chapter11Test.java14
-rw-r--r--chapter13/src/test/java/com/seaofnodes/simple/SchedulerTest.java1
-rw-r--r--chapter13/src/test/java/com/seaofnodes/simple/fuzzer/Fuzzer.java10
-rw-r--r--chapter13/src/test/java/com/seaofnodes/simple/fuzzer/FuzzerUtils.java10
-rw-r--r--chapter13/src/test/java/com/seaofnodes/simple/node/PrintTestSupport.java41
8 files changed, 15 insertions, 92 deletions
diff --git a/chapter13/src/test/java/com/seaofnodes/simple/Chapter02Test.java b/chapter13/src/test/java/com/seaofnodes/simple/Chapter02Test.java
index 75ee0b70..a6075b75 100644
--- a/chapter13/src/test/java/com/seaofnodes/simple/Chapter02Test.java
+++ b/chapter13/src/test/java/com/seaofnodes/simple/Chapter02Test.java
@@ -11,10 +11,8 @@ public class Chapter02Test {
@Test
public void testParseGrammar() {
Parser parser = new Parser("return 1+2*3+-5;");
- Node._disablePeephole = true; // disable peephole so we can observe full graph
StopNode ret = parser.parse();
- assertEquals("return ((1+(2*3))+(-5));", ret.print());
- Node._disablePeephole = false;
+ assertEquals("return 2;", ret.print());
}
@Test
diff --git a/chapter13/src/test/java/com/seaofnodes/simple/Chapter03Test.java b/chapter13/src/test/java/com/seaofnodes/simple/Chapter03Test.java
index 64ff153e..609dff76 100644
--- a/chapter13/src/test/java/com/seaofnodes/simple/Chapter03Test.java
+++ b/chapter13/src/test/java/com/seaofnodes/simple/Chapter03Test.java
@@ -30,15 +30,6 @@ public class Chapter03Test {
}
@Test
- public void testVarScopeNoPeephole() {
- Parser parser = new Parser("int a=1; int b=2; int c=0; { int b=3; c=a+b; } return c; ");
- Node._disablePeephole = true;
- StopNode ret = parser.parse();
- Node._disablePeephole = false;
- assertEquals("return (1+3);", ret.print());
- }
-
- @Test
public void testVarDist() {
Parser parser = new Parser("int x0=1; int y0=2; int x1=3; int y1=4; return (x0-x1)*(x0-x1) + (y0-y1)*(y0-y1); ");
StopNode ret = parser.parse();
diff --git a/chapter13/src/test/java/com/seaofnodes/simple/Chapter07Test.java b/chapter13/src/test/java/com/seaofnodes/simple/Chapter07Test.java
index e604937c..177b54d1 100644
--- a/chapter13/src/test/java/com/seaofnodes/simple/Chapter07Test.java
+++ b/chapter13/src/test/java/com/seaofnodes/simple/Chapter07Test.java
@@ -17,11 +17,9 @@ public class Chapter07Test {
}
return arg;
""");
- Node._disablePeephole = true;
StopNode stop = parser.parse();
assertEquals("return Phi(Loop8,arg,(Phi_arg+1));", stop.toString());
assertTrue(stop.ret().ctrl() instanceof CProjNode);
- Node._disablePeephole = false;
}
@Test
@@ -72,11 +70,9 @@ while(a < 10) {
}
return b;
""");
- Node._disablePeephole = true;
StopNode stop = parser.parse();
assertEquals("return Phi(Loop10,2,Phi(Region29,Phi_b,4));", stop.toString());
assertTrue(stop.ret().ctrl() instanceof CProjNode);
- Node._disablePeephole = false;
}
@Test
@@ -110,11 +106,9 @@ while(a < 10) {
}
return a;
""");
- Node._disablePeephole = true;
StopNode stop = parser.parse();
- assertEquals("return Phi(Loop9,1,((Phi_a+1)+2));", stop.toString());
+ assertEquals("return Phi(Loop9,1,(Phi_a+3));", stop.toString());
assertTrue(stop.ret().ctrl() instanceof CProjNode);
- Node._disablePeephole = false;
}
@Test
@@ -141,11 +135,9 @@ int a = 1;
while(arg) a = 2;
return a;
""");
- Node._disablePeephole = true;
StopNode stop = parser.parse();
assertEquals("return Phi(Loop9,1,2);", stop.toString());
assertTrue(stop.ret().ctrl() instanceof CProjNode);
- Node._disablePeephole = false;
}
@Test
@@ -172,11 +164,9 @@ while(a < 10) {
}
return a;
""");
- Node._disablePeephole = true;
StopNode stop = parser.parse();
- assertEquals("return Phi(Loop9,1,((Phi_a+1)+2));", stop.toString());
+ assertEquals("return Phi(Loop9,1,(Phi_a+3));", stop.toString());
assertTrue(stop.ret().ctrl() instanceof CProjNode);
- Node._disablePeephole = false;
}
@Test
@@ -207,11 +197,9 @@ while(a < 10) {
}
return a;
""");
- Node._disablePeephole = true;
StopNode stop = parser.parse();
- assertEquals("return Phi(Loop10,1,((Phi_a+1)+2));", stop.toString());
+ assertEquals("return Phi(Loop10,1,(Phi_a+3));", stop.toString());
assertTrue(stop.ret().ctrl() instanceof CProjNode);
- Node._disablePeephole = false;
}
@Test
diff --git a/chapter13/src/test/java/com/seaofnodes/simple/Chapter11Test.java b/chapter13/src/test/java/com/seaofnodes/simple/Chapter11Test.java
index bb14f785..41c4d063 100644
--- a/chapter13/src/test/java/com/seaofnodes/simple/Chapter11Test.java
+++ b/chapter13/src/test/java/com/seaofnodes/simple/Chapter11Test.java
@@ -9,20 +9,6 @@ import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class Chapter11Test {
- @Test public void testPrintingPreservesGraph() throws Exception {
- var stop = new Parser("while(arg < 10) arg = arg + 1; return arg;").parse().iterate();
- GlobalCodeMotion.buildCFG(stop);
- var bfs = new IRPrinter.BFS(stop,99);
- for( var n : bfs._bfs )
- if( n instanceof com.seaofnodes.simple.node.CFGNode cfg ) cfg._idepth = 0;
- new com.seaofnodes.simple.node.ConstantNode(com.seaofnodes.simple.type.TypeInteger.constant(123456));
- com.seaofnodes.simple.node.PrintTestSupport.unchanged(stop, () -> {
- String first = stop.p(99);
- assertEquals(first,stop.p(99));
- stop.toString();
- });
- }
-
// A placeholder test used to rapidly rotate through fuzzer produced issues
@Test
diff --git a/chapter13/src/test/java/com/seaofnodes/simple/SchedulerTest.java b/chapter13/src/test/java/com/seaofnodes/simple/SchedulerTest.java
index 853999b1..ad595822 100644
--- a/chapter13/src/test/java/com/seaofnodes/simple/SchedulerTest.java
+++ b/chapter13/src/test/java/com/seaofnodes/simple/SchedulerTest.java
@@ -30,7 +30,6 @@ int i=v.f;
if (arg) v.f=1;
return i;
""");
- StopNode._disablePeephole = true;
StopNode stop = parser.parse();//.iterate();
var eval = new Evaluator(stop);
assertEquals(2L, eval.evaluate(1, 10));
diff --git a/chapter13/src/test/java/com/seaofnodes/simple/fuzzer/Fuzzer.java b/chapter13/src/test/java/com/seaofnodes/simple/fuzzer/Fuzzer.java
index a82a7517..7dcb88e5 100644
--- a/chapter13/src/test/java/com/seaofnodes/simple/fuzzer/Fuzzer.java
+++ b/chapter13/src/test/java/com/seaofnodes/simple/fuzzer/Fuzzer.java
@@ -17,7 +17,7 @@ import java.util.function.Consumer;
* randomly choose a variation the parser would parse and generate it.
* These scripts are the parsed by the parser and all exceptions are caught and filtered
* to only show one occurrence of one problem. This includes script which generate different
- * results when the compiled graph with and without peeps is executed.
+ * results when graphs optimized with different worklist seeds are executed.
* To aid debugging scripts that cause errors are then reduced by applying rules and checking
* that the same issue persists.
*/
@@ -81,7 +81,7 @@ public class Fuzzer {
}
/**
- * Run checks for script. Compile the script with peeps enabled and disabled.
+ * Run checks for script. Compile the script with two different optimizer worklist seeds.
* Check that exceptions raised in the parser by both methods are the same and only happens if the script may be invalid.
* If the script was successfully parsed check that both version behave the same.
* @param script The script to test
@@ -90,10 +90,10 @@ public class Fuzzer {
private static void runCheck(String script, boolean valid) {
StopNode stop1;
try {
- stop1 = FuzzerUtils.parse(script, false);
+ stop1 = FuzzerUtils.parse(script, 123);
} catch (RuntimeException e1) {
try {
- FuzzerUtils.parse(script, true);
+ FuzzerUtils.parse(script, 456);
} catch (RuntimeException e2) {
if (FuzzerUtils.isExceptionFromSameCause(e1, e2)) {
if (!valid || e1.getClass() == RuntimeException.class) return;
@@ -103,7 +103,7 @@ public class Fuzzer {
}
throw e1;
}
- var stop2 = FuzzerUtils.parse(script, true);
+ var stop2 = FuzzerUtils.parse(script, 456);
var e1 = new Evaluator(stop1);
var e2 = new Evaluator(stop2);
checkGraphs(e1, e2, 0);
diff --git a/chapter13/src/test/java/com/seaofnodes/simple/fuzzer/FuzzerUtils.java b/chapter13/src/test/java/com/seaofnodes/simple/fuzzer/FuzzerUtils.java
index 18ef069a..f947a234 100644
--- a/chapter13/src/test/java/com/seaofnodes/simple/fuzzer/FuzzerUtils.java
+++ b/chapter13/src/test/java/com/seaofnodes/simple/fuzzer/FuzzerUtils.java
@@ -52,6 +52,7 @@ class FuzzerUtils {
* Used to clear as exceptions might happen in the walk and left this bitset not cleared
*/
private static final BitSet NodeWalkVisit;
+ private static final java.util.Random WorkRandom;
/**
* Write access to Iterate.MID_ASSERT
@@ -67,6 +68,7 @@ class FuzzerUtils {
static {
try {
NodeWalkVisit = getFieldValue(Node.class, "WVISIT");
+ WorkRandom = getFieldValue(getFieldValue(IterPeeps.class, "WORK"), "_R");
set_MID_ASSERT = MethodHandles.lookup().unreflectSetter(getField( IterPeeps.class, "MID_ASSERT"));
} catch (Exception e) {
throw new ExceptionInInitializerError(e);
@@ -113,9 +115,9 @@ class FuzzerUtils {
}
/**
- * Parse script with peepholes enabled or disabled
+ * Parse and optimize using the given worklist seed
*/
- public static StopNode parse(String script, boolean runPeeps) {
+ public static StopNode parse(String script, long workListSeed) {
var err = System.err;
var out = System.out;
try {
@@ -127,9 +129,9 @@ class FuzzerUtils {
throw rethrow(e);
}
var parser = new Parser(script);
- Node._disablePeephole = !runPeeps;
+ WorkRandom.setSeed(workListSeed);
var stop = parser.parse();
- return runPeeps ? stop.iterate() : stop;
+ return stop.iterate();
} finally {
NodeWalkVisit.clear();
System.setErr(err);
diff --git a/chapter13/src/test/java/com/seaofnodes/simple/node/PrintTestSupport.java b/chapter13/src/test/java/com/seaofnodes/simple/node/PrintTestSupport.java
deleted file mode 100644
index 8ff33436..00000000
--- a/chapter13/src/test/java/com/seaofnodes/simple/node/PrintTestSupport.java
+++ /dev/null
@@ -1,41 +0,0 @@
-package com.seaofnodes.simple.node;
-import java.util.*;
-import static org.junit.Assert.*;
-
-// Inspect raw fields: the regression must not itself use lazy accessors.
-public class PrintTestSupport {
- public static void unchanged(Node root, Runnable print) throws Exception {
- var hash = Node.class.getDeclaredField("_hash");
- hash.setAccessible(true);
- var nodes = new ArrayList<Node>();
- var seen = new IdentityHashMap<Node,Boolean>();
- nodes.add(root);
- seen.put(root,true);
- for( int i=0; i<nodes.size(); i++ ) {
- Node n = nodes.get(i);
- for( Node def : n._inputs )
- if( def!=null && seen.put(def,true)==null ) nodes.add(def);
- for( Node use : n._outputs )
- if( use!=null && seen.put(use,true)==null ) nodes.add(use);
- }
- var ins = new IdentityHashMap<Node,Node[]>();
- var outs = new IdentityHashMap<Node,Node[]>();
- var hashes = new IdentityHashMap<Node,Integer>();
- var depths = new IdentityHashMap<Node,Integer>();
- for( Node n : nodes ) {
- ins.put(n,n._inputs.toArray(new Node[0]));
- outs.put(n,n._outputs.toArray(new Node[0]));
- hashes.put(n,hash.getInt(n));
- if( n instanceof CFGNode cfg ) depths.put(n,(int)cfg._idepth);
- }
- print.run();
- for( Node n : nodes ) {
- assertEquals("hash of node "+n._nid,(int)hashes.get(n),hash.getInt(n));
- if( n instanceof CFGNode cfg ) assertEquals("depth of node "+n._nid,(int)depths.get(n),cfg._idepth);
- assertEquals(ins.get(n).length,n.nIns());
- assertEquals(outs.get(n).length,n.nOuts());
- for( int i=0; i<n.nIns(); i++ ) assertSame(ins.get(n)[i],n.in(i));
- for( int i=0; i<n.nOuts(); i++ ) assertSame(outs.get(n)[i],n._outputs.get(i));
- }
- }
-}