summaryrefslogtreecommitdiff
path: root/chapter20/src/test/java/com/seaofnodes
diff options
context:
space:
mode:
authorCliff Click <cliffc@acm.org>2026-09-20 22:38:58 -0700
committerCliff Click <cliffc@acm.org>2026-09-20 22:38:58 -0700
commit40b33cb6f8b8dc4d8551c3b522e7c5682a44540a (patch)
treee44d0380390109e3597bc5a1b1744e715cc30b62 /chapter20/src/test/java/com/seaofnodes
parent1e527b16b28f31b08cbb36b7b1bf2d689487a989 (diff)
downloadSimple-40b33cb6f8b8dc4d8551c3b522e7c5682a44540a.tar.gz
Simple-40b33cb6f8b8dc4d8551c3b522e7c5682a44540a.zip
Final reg-alloc across chapters cleanup
Diffstat (limited to 'chapter20/src/test/java/com/seaofnodes')
-rw-r--r--chapter20/src/test/java/com/seaofnodes/simple/Chapter20Test.java17
-rw-r--r--chapter20/src/test/java/com/seaofnodes/simple/codegen/RegAllocTestSupport.java13
2 files changed, 30 insertions, 0 deletions
diff --git a/chapter20/src/test/java/com/seaofnodes/simple/Chapter20Test.java b/chapter20/src/test/java/com/seaofnodes/simple/Chapter20Test.java
index 00a8407f..71a4bc36 100644
--- a/chapter20/src/test/java/com/seaofnodes/simple/Chapter20Test.java
+++ b/chapter20/src/test/java/com/seaofnodes/simple/Chapter20Test.java
@@ -10,6 +10,23 @@ import static com.seaofnodes.simple.Main.PORTS;
import static org.junit.Assert.*;
public class Chapter20Test {
+ @Test public void testAllocatorFixedNeighbor() throws Exception { com.seaofnodes.simple.codegen.RegAllocTestSupport.uncoloredFixedNeighbor(); }
+
+ @Test public void testNarrowStoreMasks() {
+ for( String type : new String[]{"i8","u8","i16","u16"} ) {
+ CodeGen code = new CodeGen("struct S { "+type+" x; }; S !s=new S; s.x=arg; return 0;")
+ .parse().opto().typeCheck().instSelect(PORTS,"x86_64_v2","SystemV").GCM().localSched().regAlloc();
+ int stores=0;
+ for( var bb : code._cfg )
+ for( var node : bb.outs() )
+ if( node instanceof com.seaofnodes.simple.node.cpus.x86_64_v2.StoreX86 st ) {
+ stores++;
+ assertEquals(-1,st.regmap(4).nextReg((short)15));
+ }
+ assertEquals(1,stores);
+ }
+ }
+
@Test public void testInlinedReturnValue() {
String src = """
struct S { int x; };
diff --git a/chapter20/src/test/java/com/seaofnodes/simple/codegen/RegAllocTestSupport.java b/chapter20/src/test/java/com/seaofnodes/simple/codegen/RegAllocTestSupport.java
index bb1d49bf..1b3963c5 100644
--- a/chapter20/src/test/java/com/seaofnodes/simple/codegen/RegAllocTestSupport.java
+++ b/chapter20/src/test/java/com/seaofnodes/simple/codegen/RegAllocTestSupport.java
@@ -30,6 +30,19 @@ public class RegAllocTestSupport {
return code;
}
+ public static void uncoloredFixedNeighbor() throws Exception {
+ CodeGen code = graph();
+ RegAlloc alloc = new RegAlloc(code);
+ Op def = new Op(new RegMask(3L),null,null,false,code._start);
+ LRG lrg = alloc.newLRG(def);
+ LRG neighbor = new LRG((short)99);
+ neighbor._mask = A;
+ lrg.addNeighbor(neighbor); // Uncolored, but its only possible color is A.
+ var bias = IFG.class.getDeclaredMethod("biasColorNeighbors",RegAlloc.class,Node.class,RegMask.class);
+ bias.setAccessible(true);
+ assertEquals((short)1,bias.invoke(null,alloc,def,new RegMaskRW(3L,0L)));
+ }
+
public static void masks() {
for( int reg : new int[]{0,63,64,65,127} ) {
RegMask mask = new RegMask(reg);