Skip to content
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -1008,7 +1008,7 @@ func quicksort(arr: [Float], low: Int, high: Int) {
}
}

func eq(a: [Int], b: [Int], n: Int)->Int
func eq(a: [Float], b: [Float], n: Int)->Int
{
var result = 1
var i = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,13 @@ private ReturnNode generateFunctionBody(Symbol.FunctionTypeSymbol functionTypeSy
// Parse the body
Node last = compileStatement(funcDecl.block);

// Last expression is the return
if( ctrl()._type== Type.CONTROL )
fun.addReturn(ctrl(), _scope.mem().merge(), last);
// Add an implicit return only for reachable fall-through. Void functions
// use an integer sentinel in the backend signature.
if( ctrl()._type== Type.CONTROL ) {
EZType.EZTypeFunction functionType = (EZType.EZTypeFunction) functionTypeSymbol.type;
Node result = functionType.returnType instanceof EZType.EZTypeVoid ? ZERO : last;
fun.addReturn(ctrl(), _scope.mem().merge(), result);
}

// Pop off the inProgress node on the multi-exit Region merge
assert r.inProgress();
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package com.compilerprogramming.ezlang.compiler;

import com.compilerprogramming.ezlang.compiler.codegen.CodeGen;
import com.compilerprogramming.ezlang.compiler.node.Node;
import com.compilerprogramming.ezlang.compiler.node.StopNode;

import java.util.ArrayList;
import java.util.BitSet;
import java.util.List;
import java.util.function.Consumer;

public class IterPeeps2 {

static void dfs(Node root, Consumer<Node> consumer, BitSet visited) {
visited.set(root._nid);
/* For each successor node */
for (int i = 0; i < root.nOuts(); i++) {
Node S = root.out(i);
if (S == null)
continue;
if (!visited.get(S._nid))
dfs(S, consumer, visited);
}
consumer.accept(root);
}

public static List<Node> rpo(Node root) {
List<Node> nodes = new ArrayList<>();
// note add below prepends
dfs(root, (n)->nodes.add(0,n), new BitSet());
return nodes;
}

public void iterate(CodeGen code) {
final Node startNode = code._start; // We need the start node to get to the full graph
int iter = 1;
int count = 0; // Count of nodes we peepholed
for (;;iter++) {
List<Node> rpos = rpo(startNode);
count += rpos.size();
boolean progress = false;
for (int i = 0; i < rpos.size(); i++) {
Node n = rpos.get(i);
if (n.isDead()) continue;
Node x = n.peepholeOpt();
if (x != null) {
progress = true;
if (x.isDead()) continue;
// peepholeOpt can return brand-new nodes, needing an initial type set
if( x._type==null ) x.setType(x.compute());
if (x != n) n.subsume(x);
}
if( n.isUnused() && !(n instanceof StopNode) )
n.kill(); // Just plain dead
}
if (!progress) break;
}
System.out.println("Completed in " + iter + " iterations; peepholed " + count + " nodes");
// if( show )
// System.out.println(new GraphVisualizer().generateDotOutput(stopNode,null,null));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public CodeGen( String src, TypeInteger arg, long workListSeed ) {
_stop = new StopNode(src);
_src = src;
_arg = arg;
_iter = new IterPeeps(workListSeed);
_iter = new IterPeeps2();
_main = makeFun(TypeTuple.MAIN, Type.BOTTOM);
P = new Compiler(this,arg);
}
Expand Down Expand Up @@ -180,7 +180,7 @@ public CodeGen parse() {

// ---------------------------
// Iterator peepholes.
public final IterPeeps _iter;
public final IterPeeps2 _iter;
// Stop tracking deps while assertin
public boolean _midAssert;
// Statistics on peepholes
Expand All @@ -206,8 +206,6 @@ public CodeGen opto() {
// loop unroll, peel, RCE, etc
return this;
}
public <N extends Node> N add( N n ) { return _iter.add(n); }
public void addAll( Ary<Node> ary ) { _iter.addAll(ary); }


// ---------------------------
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.compilerprogramming.ezlang.compiler.codegen;

import com.compilerprogramming.ezlang.compiler.util.Ary;
import com.compilerprogramming.ezlang.compiler.IterPeeps.WorkList;
import com.compilerprogramming.ezlang.compiler.util.WorkList;
import com.compilerprogramming.ezlang.compiler.util.Utils;
import com.compilerprogramming.ezlang.compiler.node.*;
import com.compilerprogramming.ezlang.compiler.type.*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ boolean splitByLoop( byte round, LRG lrg ) {
// If the minLoopDepth is less than the maxLoopDepth: for-all defs and
// uses, if at minLoopDepth or lower, split after def and before use.
for( Node n : _ns ) {
if( n instanceof SplitNode && min!=max ) continue; // Ignoring splits; since spilling need to split in a deeper loop
if( n instanceof SplitNode ) continue; // Ignoring splits; since spilling need to split in a deeper loop
if( n.isDead() ) continue; // Some Cloneable went dead by other spill changes
// If this is a 2-address commutable op (e.g. AddX86, MulX86) and the rhs has only a single user,
// commute the inputs... which chops the LHS live ranges' upper bound to just the RHS.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,6 @@ public Node idealize() {
fun.setDef(1, Compiler.XCTRL); // No default/unknown StartNode caller
fun.setDef(2,call.ctrl()); // Bypass the Call;
fun.ret().setDef(3,null); // Return is folding also
CodeGen.CODE.addAll(fun._outputs);
// Repeat defs 1 layer down, for users of Parm (Phis)
for( Node parm : fun._outputs )
if( parm instanceof ParmNode )
CodeGen.CODE.addAll(parm._outputs);

// Inlining immediately blows all cache idepth fields past the inline point.
// Bump the global version number invalidating them en-masse.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ private Node link( FunNode fun ) {
if( use instanceof ParmNode parm )
parm.addDef(parm._idx==0 ? new ConstantNode(cend()._rpc).peephole() : arg(parm._idx));
// Call end points to function return
CodeGen.CODE.add(cend()).addDef(fun.ret());
cend().addDef(fun.ret());
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ public ParmNode rpc() {
public void setSig( TypeFunPtr sig ) {
assert sig.isa(_sig);
if( _sig != sig ) {
CODE.add(this);
_sig = sig;
}
}
Expand All @@ -89,8 +88,6 @@ public Node idealize() {
// Some linked path dies
Node progress = deadPath();
if( progress!=null ) {
if( nIns()==3 && in(2) instanceof CallNode call )
CODE.add(call.cend()); // If Start and one call, check for inline
return progress;
}

Expand All @@ -114,8 +111,6 @@ public Node idealize() {

// If down to a single input, become that input
if( nIns()==2 && !hasPhi() ) {
CODE.add( CODE._stop ); // Stop will remove dead path
CODE.add( _ret ); // Return will compute to TOP control
return in(1); // Collapse if no Phis; 1-input Phis will collapse on their own
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ public class IfNode extends CFGNode implements MultiNode {

public IfNode(Node ctrl, Node pred) {
super(ctrl, pred);
CodeGen.CODE.add(this); // Because idoms are complex, just add it
}
public IfNode(IfNode iff) { super(iff); }

Expand Down
Loading
Loading