about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorTim Blazytko <tim.blazytko@rub.de>2015-05-10 00:36:44 +0200
committerTim Blazytko <tim.blazytko@rub.de>2015-06-02 14:56:08 +0200
commit9dd0d7c43f9079fddda74d58c5cc9caca26479fe (patch)
treeb8755307c0b4c69f3a3284584c08dbac14ae9ee0
parent6c2f49b969dbb2d4490ff2aa150a00086280b116 (diff)
downloadmiasm-9dd0d7c43f9079fddda74d58c5cc9caca26479fe.tar.gz
miasm-9dd0d7c43f9079fddda74d58c5cc9caca26479fe.zip
graph.py: added computation of the dominance frontier
-rw-r--r--miasm2/core/graph.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/miasm2/core/graph.py b/miasm2/core/graph.py
index c647ede8..0d129b3d 100644
--- a/miasm2/core/graph.py
+++ b/miasm2/core/graph.py
@@ -312,3 +312,26 @@ shape = "box"
                     idoms[n] = p
                     break
         return idoms
+
+    def compute_dominance_frontier(self, head):
+        """
+        Compute the dominance frontier of the graph
+
+        Source: Cooper, Keith D., Timothy J. Harvey, and Ken Kennedy.
+        "A simple, fast dominance algorithm."
+        Software Practice & Experience 4 (2001), p. 9
+        """
+        idoms = self.compute_immediate_dominators(head)
+        df = {}
+
+        for n in idoms:
+            if self._nodes_pred[n] >= 2:
+                for p in self.predecessors_iter(n):
+                    runner = p
+                    while runner != idoms[n]:
+                        if n not in df:
+                            df[n] = set()
+
+                        df[n].add(runner)
+                        runner = idoms[runner]
+        return df