diff options
| author | Cliff Click <cliffc@acm.org> | 2025-03-30 10:54:39 -0700 |
|---|---|---|
| committer | Cliff Click <cliffc@acm.org> | 2025-03-30 10:54:39 -0700 |
| commit | 8701c671c8e6d6eedc01436ea38bde01fba634f0 (patch) | |
| tree | 2edec5882f8d49640ed7baed58cc2e8a293e3956 | |
| parent | 7d60f55d2c97677e03a6b01869b4832111a12267 (diff) | |
| download | Simple-8701c671c8e6d6eedc01436ea38bde01fba634f0.tar.gz Simple-8701c671c8e6d6eedc01436ea38bde01fba634f0.zip | |
Fix BB layout bug
Fix split of popular value bug.
3 files changed, 34 insertions, 5 deletions
diff --git a/chapter21/src/main/java/com/seaofnodes/simple/codegen/Encoding.java b/chapter21/src/main/java/com/seaofnodes/simple/codegen/Encoding.java index f2a2449e..fa703edc 100644 --- a/chapter21/src/main/java/com/seaofnodes/simple/codegen/Encoding.java +++ b/chapter21/src/main/java/com/seaofnodes/simple/codegen/Encoding.java @@ -186,9 +186,14 @@ public class Encoding { // If the *next* BB has already been visited, we may need an // unconditional jump here if( visit.get(next._nid) && !(next instanceof StopNode) ) { - // If all the blocks, in RPO order, to our target - // are empty, we will fall in and not need a jump. - if( next instanceof LoopNode || !isEmptyBackwardsScan(rpo,next) ) { + boolean needJump = next instanceof LoopNode + // If backwards to a loop, and the block has statements, + // will need a jump. Empty blocks can just backwards branch. + ? (bb.nOuts()>1) + // Forwards jump. If all the blocks, in RPO order, to our + // target are empty, we will fall in and not need a jump. + : !isEmptyBackwardsScan(rpo,next); + if( needJump ) { CFGNode jmp = _code._mach.jump(); jmp.setDefX(0,bb); next.setDef(next._inputs.find(bb),jmp); @@ -230,8 +235,13 @@ public class Encoding { // when the False RPO visit returns, the IF is immediately next. // When the RPO is reversed, the fall-through path will always be // following the IF. - _rpo_cfg(t,visit,rpo); - _rpo_cfg(f,visit,rpo); + if( t.nOuts()==1 ) { + _rpo_cfg(f,visit,rpo); + _rpo_cfg(t,visit,rpo); + } else { + _rpo_cfg(t,visit,rpo); + _rpo_cfg(f,visit,rpo); + } } rpo.add(bb); } 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 36de2cdb..9c0f5f51 100644 --- a/chapter21/src/main/java/com/seaofnodes/simple/codegen/RegAlloc.java +++ b/chapter21/src/main/java/com/seaofnodes/simple/codegen/RegAlloc.java @@ -284,6 +284,7 @@ public class RegAlloc { for( RegMask rmask : rclass ) { Node split = makeSplit(def,"popular",round,lrg); split.insertAfter( def ); + if( split.nIns()>1 ) split.setDef(1,def); // all uses by class to split for( int j=0; j < def._outputs._len; j++ ) { Node use = def._outputs.at(j); diff --git a/chapter21/src/test/java/com/seaofnodes/simple/progs/HellowWorld.smp b/chapter21/src/test/java/com/seaofnodes/simple/progs/HellowWorld.smp new file mode 100644 index 00000000..172dffa0 --- /dev/null +++ b/chapter21/src/test/java/com/seaofnodes/simple/progs/HellowWorld.smp @@ -0,0 +1,18 @@ + +{ i32 byte[] i64 -> i64 } write = extern; +byte[] buf = new byte[100]; +buf[ 0] = 'H'; +buf[ 1] = 'e'; +buf[ 2] = 'l'; +buf[ 3] = 'l'; +buf[ 4] = 'o'; +buf[ 5] = ','; +buf[ 6] = 'W'; +buf[ 7] = 'o'; +buf[ 8] = 'r'; +buf[ 9] = 'l'; +buf[10] = 'd'; +buf[11] = '!'; +buf[12] = '\n'; + +return write(0,buf,12); |
