diff options
Diffstat (limited to 'vaporize')
-rw-r--r-- | vaporize/LIRDict.java | 9 | ||||
-rw-r--r-- | vaporize/LIRVisitor.java | 7 | ||||
-rw-r--r-- | vaporize/VaporizeVisitor.java | 46 |
3 files changed, 44 insertions, 18 deletions
diff --git a/vaporize/LIRDict.java b/vaporize/LIRDict.java index 30bfed3..ffb1c3e 100644 --- a/vaporize/LIRDict.java +++ b/vaporize/LIRDict.java @@ -12,14 +12,17 @@ public class LIRDict { private TreeSet<LIRVar> intervals; private int spilled_num; // the number of spilled registers + private int in_num; // the number of arguments passed in through the stack + private int out_num; // the size of the out stack private ControlFlowGraph cfg; - public LIRDict(VFunction f, ControlFlowGraph cfg) { + public LIRDict(VFunction f, ControlFlowGraph cfg, int out_num) { this.intervals = new TreeSet<LIRVar>((v1, v2) -> { return (v1.compareTo(v2) != 0) ? v1.compareTo(v2) : v1.equals(v2) ? 0 : 1; }); this.cfg = cfg; + this.out_num = out_num; for (VInstr s : f.body) { CFGNode n = cfg.getNode(s); @@ -84,4 +87,8 @@ public class LIRDict { return this.spilled_num; } + public int getOutNum() { + return this.out_num; + } + } diff --git a/vaporize/LIRVisitor.java b/vaporize/LIRVisitor.java index 821573c..21f632d 100644 --- a/vaporize/LIRVisitor.java +++ b/vaporize/LIRVisitor.java @@ -15,6 +15,7 @@ public class LIRVisitor extends VInstr.VisitorPR<ControlFlowGraph, String, Runti private Kettle kettle; private ArrayList<LIRDict> lirs; private CFGNode curr; // the current node being processed + private int curr_out_num; private String dot_format; // a list of edges to be processed by graphviz public LIRVisitor(VaporProgram vp, ArrayList<String> vapor) { @@ -26,6 +27,7 @@ public class LIRVisitor extends VInstr.VisitorPR<ControlFlowGraph, String, Runti for (VFunction f : vp.functions) { ControlFlowGraph cfg = new ControlFlowGraph(f); this.dot_format = ""; + this.curr_out_num = 0; MinimalLogger.info(String.format("LIRVisitor is collecting nodes for %s", this.kettle.parseFuncName(f))); @@ -86,7 +88,7 @@ public class LIRVisitor extends VInstr.VisitorPR<ControlFlowGraph, String, Runti MinimalLogger.info(String.format("Gathering intervals for %s", this.kettle.parseFuncName(f))); - LIRDict lir = new LIRDict(f, cfg); + LIRDict lir = new LIRDict(f, cfg, this.curr_out_num); this.lirs.add(lir); MinimalLogger.info(String.format("Found intervals: %s", lir.getIntervals().toString())); @@ -222,8 +224,9 @@ public class LIRVisitor extends VInstr.VisitorPR<ControlFlowGraph, String, Runti n.sourcePos.toString())); /////////////////////////////////////////////////////////////// CFGNode curr = cfg.getNode(n); + this.curr_out_num = Math.max(this.curr_out_num, n.args.length-4); if (n.dest != null) - cfg.addReference(curr, n.dest.toString()); + cfg.addDefinition(curr, n.dest.toString()); for (VOperand a : n.args) { cfg.addReference(curr, a.toString()); } diff --git a/vaporize/VaporizeVisitor.java b/vaporize/VaporizeVisitor.java index ba319cb..f9ad6c0 100644 --- a/vaporize/VaporizeVisitor.java +++ b/vaporize/VaporizeVisitor.java @@ -26,7 +26,9 @@ public class VaporizeVisitor extends VInstr.VisitorP<LIRDict, RuntimeException> // function in vp to be out of order? for (int i = 0; i < vp.functions.length; ++i) { this.addVaporm(String.format("func %s [in %d, out %d, local %d]", - vp.functions[i].ident, 0, 0, interval_list.get(i).getSpilledNum() + 14)); + vp.functions[i].ident, Math.max(vp.functions[i].params.length-4, 0), + interval_list.get(i).getOutNum(), + interval_list.get(i).getSpilledNum() + 14)); for (int j = 0; j < this.callee_save.length; ++j) { this.addVaporm(String.format(" local[%s] = %s", j, @@ -34,11 +36,16 @@ public class VaporizeVisitor extends VInstr.VisitorP<LIRDict, RuntimeException> } for (int j = 0; j < vp.functions[i].params.length; ++j) - this.addVaporm(String.format(" %s = %s", - interval_list.get(i).getInterval(vp.functions[i].params[j].toString()) - .getAssignedRegister(), - arg_pass[j])); - + if (j < 4) { // is in a registers + this.addVaporm(String.format(" %s = %s", + interval_list.get(i).getInterval(vp.functions[i].params[j].toString()) + .getAssignedRegister(), + arg_pass[j])); + } else // is in 'out' + this.addVaporm(String.format(" %s = in[%s]", + interval_list.get(i).getInterval(vp.functions[i].params[j].toString()) + .getAssignedRegister(), + j-4)); TreeSet<Node> f = this.sortFunction(vp.functions[i]); MinimalLogger.info(String.format("Starting loop with function:\n %s", @@ -77,9 +84,12 @@ public class VaporizeVisitor extends VInstr.VisitorP<LIRDict, RuntimeException> if (r.contains("local")) {// SPILL int i = this.spill_stack.size(); String reg = this.spillers[i]; - this.addVaporm(String.format(" %s = %s", - reg, - r)); + String str = String.format(" %s = %s", + reg, + r); + MinimalLogger.info(String.format("Adding string:\n%s", + str)); + this.vaporm.add(str); this.spill_stack.push(String.format(" %s = %s", r, reg)); @@ -101,6 +111,7 @@ public class VaporizeVisitor extends VInstr.VisitorP<LIRDict, RuntimeException> MinimalLogger.info(String.format("Adding string:\n%s", str)); this.vaporm.add(str); + this.emptySpillStack(); } public void visit(LIRDict d, VAssign n) throws RuntimeException { @@ -132,16 +143,21 @@ public class VaporizeVisitor extends VInstr.VisitorP<LIRDict, RuntimeException> this.caller_save[i])); } - // FIXME for arg num > 4! for (int i = 0; i < n.args.length; ++i) { String reg = (n.args[i] instanceof VVarRef.Local) ? this.getRegister(n.args[i].toString()) : n.args[i].toString(); - MinimalLogger.info(String.format("Adding argument for %s", - n.args[i].toString())); - this.addVaporm(String.format(" %s = %s", - this.arg_pass[i], - reg)); + if (i < 4) {// we have registers + MinimalLogger.info(String.format("Adding argument for %s", + n.args[i].toString())); + this.addVaporm(String.format(" %s = %s", + this.arg_pass[i], + reg)); + } else { // use 'out' + this.addVaporm(String.format(" out[%s] = %s", + i-4, + reg)); + } } MinimalLogger.severe(String.format("n addr: %s", |