From 3dfeff8e8e4c84929e35880bf0bbdea64c085fc0 Mon Sep 17 00:00:00 2001 From: bd-912 Date: Mon, 29 Apr 2024 16:44:42 -0600 Subject: Messy in+out argument passing, observe MoreThan4.vapor passes --- vaporize/LIRDict.java | 9 ++++++++- vaporize/LIRVisitor.java | 7 +++++-- vaporize/VaporizeVisitor.java | 46 +++++++++++++++++++++++++++++-------------- 3 files changed, 44 insertions(+), 18 deletions(-) (limited to 'vaporize') 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 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((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 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 vapor) { @@ -26,6 +27,7 @@ public class LIRVisitor extends VInstr.VisitorPR // 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 } 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 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 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 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 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", -- cgit v1.2.3