Skip to content

Commit dde79c2

Browse files
apply upstream changes - partially from ch24 excluding type changes, as well as features such as methods
1 parent 666d51d commit dde79c2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+304
-225
lines changed

seaofnodes/src/main/java/com/compilerprogramming/ezlang/compiler/Compiler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ private ReturnNode generateFunctionBody(Symbol.FunctionTypeSymbol functionTypeSy
304304
ScopeNode breakScope = _breakScope; _breakScope = null;
305305
ScopeNode continueScope = _continueScope; _continueScope = null;
306306

307-
FunNode fun = _fun = (FunNode)peep(new FunNode(sig,null,_code._start));
307+
FunNode fun = _fun = (FunNode)peep(new FunNode(sig, functionTypeSymbol.name,null,_code._start));
308308
// Once the function header is available, install in linker table -
309309
// allowing recursive functions. Linker matches on declared args and
310310
// exact fidx, and ignores the return (because the fidx will only match

seaofnodes/src/main/java/com/compilerprogramming/ezlang/compiler/IterPeeps.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ public void iterate( CodeGen code ) {
8282
// there's a new user), and replace in the graph.
8383
if( x != n ) {
8484
for( Node z : n. _inputs ) _work.push(z);
85+
for( Node z : x._outputs ) _work.push(z);
8586
n.subsume(x);
8687
}
8788
}

seaofnodes/src/main/java/com/compilerprogramming/ezlang/compiler/Var.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
public class Var {
1010

1111
public final String _name; // Declared name
12+
// These fields are not final for forward reference late updates or
13+
// promotions.
1214
public int _idx; // index in containing scope
1315
private Type _type; // Declared type
1416
public boolean _final; // Final field

seaofnodes/src/main/java/com/compilerprogramming/ezlang/compiler/codegen/CodeGen.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ public CodeGen parse() {
171171

172172
P.parse();
173173
_tParse = (int)(System.currentTimeMillis() - t0);
174+
//JSViewer.show();
174175
return this;
175176
}
176177

@@ -203,7 +204,7 @@ public CodeGen opto() {
203204
// loop unroll, peel, RCE, etc
204205
return this;
205206
}
206-
public <N extends Node> N add( N n ) { return (N)_iter.add(n); }
207+
public <N extends Node> N add( N n ) { return _iter.add(n); }
207208
public void addAll( Ary<Node> ary ) { _iter.addAll(ary); }
208209

209210

seaofnodes/src/main/java/com/compilerprogramming/ezlang/compiler/codegen/ElfFile.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.compilerprogramming.ezlang.compiler.codegen;
22

3+
import com.compilerprogramming.ezlang.compiler.codegen.Encoding.BAOS;
34
import com.compilerprogramming.ezlang.compiler.node.*;
45
import com.compilerprogramming.ezlang.compiler.type.*;
56
import com.compilerprogramming.ezlang.compiler.util.Ary;
@@ -246,7 +247,7 @@ public void export(String fname) throws IOException {
246247
pushSection(text);
247248

248249
// Build and write constant pool
249-
Encoding.BAOS cpool = new Encoding.BAOS();
250+
BAOS cpool = new BAOS();
250251
Encoding enc = _code._encoding;
251252
enc.writeConstantPool(cpool,false);
252253
DataSection rdata = new DataSection(".rodata", 1 /* SHT_PROGBITS */, cpool);

seaofnodes/src/main/java/com/compilerprogramming/ezlang/compiler/codegen/Encoding.java

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,18 @@ public static class BAOS extends ByteArrayOutputStream {
4343
public int [] _opStart; // Start of opcodes, by _nid
4444
public byte[] _opLen; // Length of opcodes, by _nid
4545

46+
// Function headers now padded when printing
47+
public boolean _padFunHeads;
48+
4649
// Big Constant relocation info.
4750
public static class Relo {
4851
public final Node _op;
4952
public final Type _t; // Constant type
5053
public final byte _off; // Offset from start of opcode
5154
public final byte _elf; // ELF relocation type, e.g. 2/PC32
52-
public int _target; // Where constant is finally placede
55+
public int _target; // Where constant is finally placed
5356
public int _opStart; // Opcode start
54-
Relo(Node op, Type t, byte off, byte elf ) {
57+
Relo( Node op, Type t, byte off, byte elf ) {
5558
_op=op; _t=t; _off=off; _elf=elf;
5659
}
5760
}
@@ -288,6 +291,9 @@ private static boolean shouldInvert(CFGNode t, CFGNode f, int bld) {
288291
// Fall/false into a full block, Jump/true to an empty block.
289292
if( f.nOuts()>1 && t.nOuts()==1 ) return false;
290293
if( t.nOuts()>1 && f.nOuts()==1 ) return true ;
294+
// Jump to a merge point, assuming other things are jumping there as well
295+
if( f.out(0) instanceof RegionNode ) return true ;
296+
if( t.out(0) instanceof RegionNode ) return false;
291297
// Everything else equal, use pre-order
292298
return t._pre > f._pre;
293299
}
@@ -357,11 +363,6 @@ private void compactShortForm() {
357363
slide = 0;
358364
for( int i=0; i<len; i++ ) {
359365
CFGNode bb = _code._cfg.at(i);
360-
// Functions pad to align 16
361-
if( bb instanceof FunNode ) {
362-
int newStart = _opStart[bb._nid]+slide;
363-
slide += (newStart+15 & -16)-newStart;
364-
}
365366
_opStart[bb._nid] += slide;
366367
// Slide down all other (non-CFG) ops in the block
367368
for( Node n : bb._outputs )
@@ -400,7 +401,7 @@ private void compactShortForm() {
400401
if( n instanceof MachNode && !(n instanceof CFGNode) )
401402
_opStart[n._nid] += slide;
402403
}
403-
404+
_padFunHeads = true;
404405

405406
// Copy/slide the bits to make space for all the longer branches
406407
int grow = _opStart[_code._cfg.at(len-1)._nid] - oldStarts[len-1];
@@ -417,6 +418,7 @@ private void compactShortForm() {
417418
}
418419
_bits.set(bits,bits.length);
419420
}
421+
420422
}
421423

422424

@@ -494,16 +496,19 @@ private void cpool( BAOS bits, TypeStruct ts ) {
494496
// Pad up to field
495497
while( off < foff ) { bits.write(0); off++; };
496498
// Constant array fields are special
497-
// FIXME Dibyendu
499+
int log = f._type.log_size();
500+
addN(log,f._type,bits);
501+
off += 1<<log;
502+
// Dibyendu we do not have constant arrays in EeZee
498503
// if( f._fname=="[]" ) { // Must be a constant array
499-
// ts._con.write(bits); // Write the constant array bits
500-
// off += ts._con.len();
504+
// ((TypeConAry)f._t).write(bits);
505+
// off += ((TypeConAry)f._t).len();
501506
// } else {
502-
// int log = f._type.log_size();
503-
// if( f._fname=="#" ) addN(log,ts._con.len(),bits); // Must be a constant array
504-
// else addN(log,f._type ,bits);
507+
// int log = f._t.log_size();
508+
// addN(log,f._t,bits);
505509
// off += 1<<log;
506510
// }
511+
507512
}
508513
}
509514

seaofnodes/src/main/java/com/compilerprogramming/ezlang/compiler/codegen/RegAlloc.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,8 +397,8 @@ boolean splitByLoop( byte round, LRG lrg ) {
397397
// If the minLoopDepth is less than the maxLoopDepth: for-all defs and
398398
// uses, if at minLoopDepth or lower, split after def and before use.
399399
for( Node n : _ns ) {
400-
if( n instanceof SplitNode ) continue; // Ignoring splits; since spilling need to split in a deeper loop
401-
if( n.isDead() ) continue; // Some Clonable went dead by other spill changes
400+
if( n instanceof SplitNode && min!=max ) continue; // Ignoring splits; since spilling need to split in a deeper loop
401+
if( n.isDead() ) continue; // Some Cloneable went dead by other spill changes
402402
// If this is a 2-address commutable op (e.g. AddX86, MulX86) and the rhs has only a single user,
403403
// commute the inputs... which chops the LHS live ranges' upper bound to just the RHS.
404404
if( n instanceof MachNode mach && lrg(n)==lrg && mach.twoAddress()==1 && mach.commutes() && n.in(2).nOuts()==1 )

seaofnodes/src/main/java/com/compilerprogramming/ezlang/compiler/node/ArithNode.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@ private TypeInteger con( Type t1, Type t2 ) {
5656
if( in(1) instanceof PhiNode lhs &&
5757
in(2) instanceof PhiNode rhs &&
5858
lhs.nIns() >= 2 && !lhs.inProgress() &&
59-
lhs.region()==rhs.region() ) {
59+
lhs.region()==rhs.region() &&
60+
lhs.nIns()>2 && // A 1-input Phi will collapse already
61+
// Disallow with self-looping phi; these will collapse
62+
(lhs.in(2)!=lhs && rhs.in(2)!=rhs) ) {
6063
// Profit check: only 1 instance of `this` will remain, all the
6164
// others will fold to constants.
6265
int cnt=0;

seaofnodes/src/main/java/com/compilerprogramming/ezlang/compiler/node/BoolNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public TypeInteger compute() {
3333
Type t2 = in(2)._type;
3434
// Exactly equals?
3535
if( t1.isHigh() || t2.isHigh() )
36-
return BOOL.dual();
36+
return (TypeInteger)BOOL.dual();
3737
if( in(1)==in(2) )
3838
// LT fails, both EQ and LE succeed
3939
return this instanceof LT ? FALSE : TRUE;

seaofnodes/src/main/java/com/compilerprogramming/ezlang/compiler/node/CFGNode.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public CFGNode uctrl() {
5555
// Used by the encoding / final BB layout
5656
public CFGNode uctrlSkipEmpty() {
5757
CFGNode x = this, y;
58-
while( x.nOuts() == 1 && (y=x.uctrl())!=null ) // Skip empty blocks
58+
while( x.nOuts() == 1 && (y=x.uctrl())!=null && !(y instanceof CallNode) ) // Skip empty blocks
5959
x = y;
6060
return x;
6161
}
@@ -85,6 +85,7 @@ public CFGNode _idom(CFGNode rhs, Node dep) {
8585
var comp = lhs.idepth() - rhs.idepth();
8686
if( comp >= 0 ) lhs = (dep==null ? lhs : dep.addDep(lhs)).idom();
8787
if( comp <= 0 ) rhs = (dep==null ? rhs : dep.addDep(rhs)).idom();
88+
if( lhs==null || rhs==null ) return null;
8889
}
8990
return lhs;
9091
}

0 commit comments

Comments
 (0)