summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIru Cai <mytbk920423@gmail.com>2014-11-27 15:59:40 +0800
committerIru Cai <mytbk920423@gmail.com>2014-11-27 16:03:46 +0800
commit06c4bed365ca396f2e69f9f5aff50aab71182909 (patch)
treefcd8c29a4542f1e8f66c1901d77011529362995b /src
parente2324d5aeeafa6a77dfb5d4588b06edd0c1f2d06 (diff)
downloadminijava-06c4bed365ca396f2e69f9f5aff50aab71182909.tar.xz
lifeness analysis
Diffstat (limited to 'src')
-rw-r--r--src/spiglet/spiglet2kanga/SpgGoal.java1
-rw-r--r--src/spiglet/spiglet2kanga/SpgProc.java34
-rw-r--r--src/spiglet/spiglet2kanga/SpgStmt.java3
3 files changed, 38 insertions, 0 deletions
diff --git a/src/spiglet/spiglet2kanga/SpgGoal.java b/src/spiglet/spiglet2kanga/SpgGoal.java
index 92b1843..cc0527b 100644
--- a/src/spiglet/spiglet2kanga/SpgGoal.java
+++ b/src/spiglet/spiglet2kanga/SpgGoal.java
@@ -24,6 +24,7 @@ public class SpgGoal extends SpgSym {
SpgProc p = procs.elementAt(i);
p.setJmpTarget();
p.getDefUse();
+ p.getActiveVars();
}
}
}
diff --git a/src/spiglet/spiglet2kanga/SpgProc.java b/src/spiglet/spiglet2kanga/SpgProc.java
index 77c7fe8..57cbb63 100644
--- a/src/spiglet/spiglet2kanga/SpgProc.java
+++ b/src/spiglet/spiglet2kanga/SpgProc.java
@@ -62,7 +62,10 @@ public class SpgProc extends SpgSym {
} else {
if (i==statements.size()-1) {
stmt.succ1 = null;
+ } else {
+ stmt.succ1 = statements.elementAt(i+1);
}
+ stmt.succ2 = null;
}
}
}
@@ -73,5 +76,36 @@ public class SpgProc extends SpgSym {
}
}
+ public void getActiveVars() {
+ boolean modified = true;
+
+ // first, initialize the out[] of the last statement
+ if (retexp!=null) {
+ statements.lastElement().out = retexp.getTmpUsed();
+ }
+
+ // then, loop in all statements for in[] and out[]
+ while (modified) {
+ modified = false;
+ for (int i=statements.size()-1; i>=0; i--) {
+ SpgStmt st = statements.elementAt(i);
+ // first, reset the out[] set
+ if (st.succ1!=null) {
+ modified |= st.out.addAll(st.succ1.in);
+ }
+ if (st.succ2!=null) {
+ modified |= st.out.addAll(st.succ2.in);
+ }
+ st.in.clear();
+ st.in.addAll(st.out);
+ if (st.def!=null) {
+ st.in.removeAll(st.def);
+ }
+ if (st.use!=null) {
+ st.in.addAll(st.use);
+ }
+ }
+ }
+ }
}
diff --git a/src/spiglet/spiglet2kanga/SpgStmt.java b/src/spiglet/spiglet2kanga/SpgStmt.java
index e6298dc..7ee9af0 100644
--- a/src/spiglet/spiglet2kanga/SpgStmt.java
+++ b/src/spiglet/spiglet2kanga/SpgStmt.java
@@ -14,9 +14,12 @@ public class SpgStmt extends SpgSym{
public SpgStmt succ1, succ2;
public HashSet<SpgTemp> def, use;
+ public HashSet<SpgTemp> in, out;
public SpgStmt(StmtType t) {
type = t;
+ in = new HashSet<SpgTemp>();
+ out = new HashSet<SpgTemp>();
}
public String toString() {