summaryrefslogtreecommitdiff
path: root/vaporize/LIRVisitor.java
diff options
context:
space:
mode:
authorbd-912 <bdunahu@colostate.edu>2024-04-27 21:31:11 -0600
committerbd-912 <bdunahu@colostate.edu>2024-04-27 21:31:11 -0600
commitdfcf11cb8d7f28acad505c2785831424c38554b8 (patch)
tree0597a6f912d81ca5881df46a9bd52bebb6bfbc6f /vaporize/LIRVisitor.java
parent008d0de42fdabb54dc43de5cfa33f4c15bd1d7ba (diff)
LIRVisitor Correct Liveness Analysis!
Diffstat (limited to 'vaporize/LIRVisitor.java')
-rw-r--r--vaporize/LIRVisitor.java78
1 files changed, 52 insertions, 26 deletions
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<ControlFlowGraph, String, Runti
this.curr = cfg.getNode(f.body[0]);
// cascades downwards --- cfg.addEdges
for (VVarRef.Local l : f.params)
- cfg.addReaching(this.curr, l.ident.toString());
+ cfg.addDefinition(this.curr, l.ident.toString());
for (VInstr s : f.body)
s.accept(cfg, this);
+ int line = this.curr.getInstruction().sourcePos.line;
+ int stop = f.body[0].sourcePos.line;
+ MinimalLogger.info(String.format("Looking for liveness from final node %d to %d",
+ line, stop));
+ for (int i = line; i >= 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<ControlFlowGraph, String, Runti
n.sourcePos.toString()));
///////////////////////////////////////////////////////////////
CFGNode curr = cfg.getNode(n);
+ cfg.addDefinition(curr, n.dest.toString());
+ cfg.addReference(curr, ((VMemRef.Global) n.source).base.toString());
+
this.dot_format += cfg.addEdge(this.curr, curr);
this.curr = curr;
-
- cfg.addReaching(curr, n.dest.toString());
- cfg.addLiveness(curr, ((VMemRef.Global) n.source).base.toString());
///////////////////////////////////////////////////////////////
MinimalLogger.info(String.format("<-%s (\"%s\":%s)",
n.getClass().getSimpleName(),
@@ -116,11 +141,11 @@ public class LIRVisitor extends VInstr.VisitorPR<ControlFlowGraph, String, Runti
n.sourcePos.toString()));
///////////////////////////////////////////////////////////////
CFGNode curr = cfg.getNode(n);
+ cfg.addReference(curr, ((VMemRef.Global) n.dest).base.toString());
+ cfg.addReference(curr, n.source.toString());
+
this.dot_format += cfg.addEdge(this.curr, curr);
this.curr = curr;
-
- cfg.addLiveness(curr, ((VMemRef.Global) n.dest).base.toString());
- cfg.addLiveness(curr, n.source.toString());
///////////////////////////////////////////////////////////////
MinimalLogger.info(String.format("<-%s (\"%s\":%s)",
n.getClass().getSimpleName(),
@@ -136,11 +161,11 @@ public class LIRVisitor extends VInstr.VisitorPR<ControlFlowGraph, String, Runti
n.sourcePos.toString()));
///////////////////////////////////////////////////////////////
CFGNode curr = cfg.getNode(n);
+ cfg.addDefinition(curr, n.dest.toString());
+ cfg.addReference(curr, n.source.toString());
+
this.dot_format += cfg.addEdge(this.curr, curr);
this.curr = curr;
-
- cfg.addReaching(curr, n.dest.toString());
- cfg.addLiveness(curr, n.source.toString());
///////////////////////////////////////////////////////////////
MinimalLogger.info(String.format("<-%s (\"%s\":%s)",
n.getClass().getSimpleName(),
@@ -156,11 +181,11 @@ public class LIRVisitor extends VInstr.VisitorPR<ControlFlowGraph, String, Runti
n.sourcePos.toString()));
///////////////////////////////////////////////////////////////
CFGNode curr = cfg.getNode(n);
+ cfg.addReference(curr, n.value.toString());
+
this.dot_format += cfg.addEdge(this.curr, curr);
this.dot_format += cfg.addEdge(curr, cfg.getNode(new Integer(this.kettle
.findLabelIndex(n.target.toString()))));
-
- cfg.addLiveness(curr, n.value.toString());
///////////////////////////////////////////////////////////////
MinimalLogger.info(String.format("<-%s (\"%s\":%s)",
n.getClass().getSimpleName(),
@@ -197,15 +222,15 @@ public class LIRVisitor extends VInstr.VisitorPR<ControlFlowGraph, String, Runti
n.sourcePos.toString()));
///////////////////////////////////////////////////////////////
CFGNode curr = cfg.getNode(n);
- this.dot_format += cfg.addEdge(this.curr, curr);
- this.curr = curr;
-
if (n.dest != null)
- cfg.addReaching(curr, n.dest.toString());
+ cfg.addReference(curr, n.dest.toString());
for (VOperand a : n.args) {
- cfg.addLiveness(curr, a.toString());
+ cfg.addReference(curr, a.toString());
}
- cfg.addLiveness(curr, n.addr.toString());
+ cfg.addReference(curr, n.addr.toString());
+
+ this.dot_format += cfg.addEdge(this.curr, curr);
+ this.curr = curr;
///////////////////////////////////////////////////////////////
MinimalLogger.info(String.format("<-%s (\"%s\":%s)",
n.getClass().getSimpleName(),
@@ -221,14 +246,15 @@ public class LIRVisitor extends VInstr.VisitorPR<ControlFlowGraph, String, Runti
n.sourcePos.toString()));
///////////////////////////////////////////////////////////////
CFGNode curr = cfg.getNode(n);
- this.dot_format += cfg.addEdge(this.curr, curr);
- this.curr = curr;
if (n.dest != null)
- cfg.addReaching(curr, n.dest.toString());
+ cfg.addDefinition(curr, n.dest.toString());
for (VOperand a : n.args) {
- cfg.addLiveness(curr, a.toString());
+ cfg.addReference(curr, a.toString());
}
+
+ this.dot_format += cfg.addEdge(this.curr, curr);
+ this.curr = curr;
///////////////////////////////////////////////////////////////
MinimalLogger.info(String.format("<-%s (\"%s\":%s)",
n.getClass().getSimpleName(),
@@ -244,11 +270,11 @@ public class LIRVisitor extends VInstr.VisitorPR<ControlFlowGraph, String, Runti
n.sourcePos.toString()));
///////////////////////////////////////////////////////////////
CFGNode curr = cfg.getNode(n);
+ if (n.value != null)
+ cfg.addReference(curr, n.value.toString());
+
this.dot_format += cfg.addEdge(this.curr, curr);
this.curr = curr;
-
- if (n.value != null)
- cfg.addLiveness(curr, n.value.toString());
///////////////////////////////////////////////////////////////
MinimalLogger.info(String.format("<-%s (\"%s\":%s)",
n.getClass().getSimpleName(),