From dfcf11cb8d7f28acad505c2785831424c38554b8 Mon Sep 17 00:00:00 2001 From: bd-912 Date: Sat, 27 Apr 2024 21:31:11 -0600 Subject: LIRVisitor Correct Liveness Analysis! --- vaporize/LIRDict.java | 49 ++++++++++++++++----------- vaporize/LIRVisitor.java | 78 ++++++++++++++++++++++++++++--------------- vaporize/VaporizeVisitor.java | 3 +- 3 files changed, 83 insertions(+), 47 deletions(-) (limited to 'vaporize') diff --git a/vaporize/LIRDict.java b/vaporize/LIRDict.java index 4f3d3c1..50c79b0 100644 --- a/vaporize/LIRDict.java +++ b/vaporize/LIRDict.java @@ -1,5 +1,6 @@ package vaporize; +import cs132.vapor.ast.VCodeLabel; import cs132.vapor.ast.VFunction; import cs132.vapor.ast.VInstr; @@ -24,29 +25,29 @@ public class LIRDict { CFGNode n = cfg.getNode(s); int line = n.getInstruction().sourcePos.line; + // reaching String info = "L" + line; - for (String var : n.getReaching()) + for (String var : n.getDefinitions()) if (!this.contains(var)) { this.intervals.add(new LIRVar(var, line, line)); - MinimalLogger.info(String.format("Reaching on %s --- New var %s", - info, - var)); - } else { - this.getInterval(var).trySetLastUse(line); - MinimalLogger.info(String.format("Reaching on %s --- Updating var %s", - info, - var)); + MinimalLogger.info(String.format("Found def of %s at line %s", + var, + line)); + } + for (String var : n.getReaching()) + if (n.getLiveness().contains(var)) { + if (this.contains(var)) { + this.getInterval(var).trySetLastUse(line); + MinimalLogger.info(String.format("Var %s still live on %s", + var, + line)); + } else { + this.intervals.add(new LIRVar(var, line, line)); + MinimalLogger.info(String.format("Var %s still live on %s", + var, + line)); + } } - for (String var : n.getLiveness()) { - if (!this.contains(var)) - MinimalLogger.severe(String.format("%s was used before defined!", - var)); - MinimalLogger.info(String.format("Liveness on %s --- Updating var %s", - info, - var)); - this.getInterval(var).trySetLastUse(line); - } - } } @@ -83,4 +84,14 @@ public class LIRDict { return this.spilled_num; } + private int subOneLine(int i) { + int ret = i - 1; + + CFGNode n = cfg.getNode(new Integer(ret)); + if (n != null && n.getInstruction() instanceof VCodeLabel) + --ret; + + return ret; + } + } diff --git a/vaporize/LIRVisitor.java b/vaporize/LIRVisitor.java index da6abb6..821573c 100644 --- a/vaporize/LIRVisitor.java +++ b/vaporize/LIRVisitor.java @@ -45,14 +45,39 @@ public class LIRVisitor extends VInstr.VisitorPR= stop; --i) { + this.curr = cfg.getNode(new Integer(i)); + for (CFGNode source : this.curr.getSources()) { + for (String var : this.curr.getLiveness()) { + if (!source.getDefinitions().contains(var)) { + // MinimalLogger.info(String.format("%s: %s added to liveness of %s.", + // this.curr, + // var, + // source)); + source.liveness.add(var); + } else { + // MinimalLogger.info(String.format("%s: %s was defined in %s.", + // this.curr, + // var, + // source)); + } + } + } + } + MinimalLogger.info(String.format("Spitting out reaching/liveness...")); for (CFGNode n : cfg.getNodes()) - MinimalLogger.info(String.format("%s ::: %s ::: %s", + MinimalLogger.info(String.format("%s ::: %s ::: %s ::: %s", n.toString(), + n.getDefinitions(), n.getReaching(), n.getLiveness())); @@ -96,11 +121,11 @@ public class LIRVisitor extends VInstr.VisitorPR d.getInterval(n.value.toString()).getAssignedRegister() : n.value.toString(); this.addVaporm(String.format(" $v0 = %s", - d.getInterval(((VVarRef.Local) n.value).ident) - .getAssignedRegister())); + reg)); } for (int j = 0; j < this.callee_save.length; ++j) { this.addVaporm(String.format(" %s = local[%s]", -- cgit v1.2.3