From 99d3fe964eb556370d0f23327b29c26cee9b3edb Mon Sep 17 00:00:00 2001 From: Cliff Click Date: Sat, 29 Mar 2025 14:47:33 -0700 Subject: Fix non-deterministic bug --- .../src/main/java/com/seaofnodes/simple/codegen/RegAlloc.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'chapter21/src/main/java/com/seaofnodes') diff --git a/chapter21/src/main/java/com/seaofnodes/simple/codegen/RegAlloc.java b/chapter21/src/main/java/com/seaofnodes/simple/codegen/RegAlloc.java index 6ffb42c9..fa3c2b81 100644 --- a/chapter21/src/main/java/com/seaofnodes/simple/codegen/RegAlloc.java +++ b/chapter21/src/main/java/com/seaofnodes/simple/codegen/RegAlloc.java @@ -151,7 +151,6 @@ public class RegAlloc { if( bb instanceof CallNode ) lastFun._hasCalls = true; } - // Top driver: repeated rounds of coloring and splitting. byte round=0; while( !graphColor(round) ) { @@ -203,7 +202,11 @@ public class RegAlloc { // independently... which generally requires a full pass over the // program for each failing live range. i.e., might be a lot of // passes. - for( LRG lrg : _failed.keySet() ) + + // Sort, to avoid non-deterministic HashMap ordering + LRG[] splits = _failed.keySet().toArray(new LRG[0]); + Arrays.sort(splits, (x,y) -> x._lrg - y._lrg ); + for( LRG lrg : splits ) split(round,lrg); } -- cgit v1.2.3