summaryrefslogtreecommitdiff
path: root/src/graph.ml
diff options
context:
space:
mode:
authorAlasdair Armstrong2019-03-06 14:11:24 +0000
committerAlasdair Armstrong2019-03-06 14:14:19 +0000
commit2b4018a07e9eead8bfe147611b24a4d5856b4d56 (patch)
tree456ce19e0ad0b413a3c4597008222425aba0e4f3 /src/graph.ml
parent2cd88a225adf5f382df85a046cd59c43e1436965 (diff)
Add option to slice out printing and tracing functions when generating C
Make instruction dependency graph use graph.ml Expose incremental graph building functions for performance in graph.mli
Diffstat (limited to 'src/graph.ml')
-rw-r--r--src/graph.ml25
1 files changed, 18 insertions, 7 deletions
diff --git a/src/graph.ml b/src/graph.ml
index e3af0b97..21863e47 100644
--- a/src/graph.ml
+++ b/src/graph.ml
@@ -69,6 +69,15 @@ module type S =
val add_edge : node -> node -> graph -> graph
val add_edges : node -> node list -> graph -> graph
+ (** Add edges to the graph, but may leave the internal structure
+ of the graph in a non-normalized state. Fix leaves repairs any
+ such issue in the graph. These additional functions are much
+ faster than those above, but it is important to call fix_leaves
+ before calling reachable, prune, or any other function. *)
+ val add_edge' : node -> node -> graph -> graph
+ val add_edges' : node -> node list -> graph -> graph
+ val fix_leaves : graph -> graph
+
val children : graph -> node -> node list
(** Return the set of nodes that are reachable from the first set
@@ -119,19 +128,21 @@ module Make(Ord: OrderedType) = struct
let fix_leaves cg =
NS.fold (fun leaf cg -> if NM.mem leaf cg then cg else NM.add leaf NS.empty cg) (leaves cg) cg
- (* FIXME: don't use fix_leaves because this is inefficient *)
- let add_edge caller callee cg =
+ let add_edge' caller callee cg =
try
- fix_leaves (NM.add caller (NS.add callee (NM.find caller cg)) cg)
+ NM.add caller (NS.add callee (NM.find caller cg)) cg
with
- | Not_found -> fix_leaves (NM.add caller (NS.singleton callee) cg)
+ | Not_found -> NM.add caller (NS.singleton callee) cg
- let add_edges caller callees cg =
+ let add_edges' caller callees cg =
let callees = List.fold_left (fun s c -> NS.add c s) NS.empty callees in
try
- fix_leaves (NM.add caller (NS.union callees (NM.find caller cg)) cg)
+ NM.add caller (NS.union callees (NM.find caller cg)) cg
with
- | Not_found -> fix_leaves (NM.add caller callees cg)
+ | Not_found -> NM.add caller callees cg
+
+ let add_edge caller callee cg = fix_leaves (add_edge' caller callee cg)
+ let add_edges caller callees cg = fix_leaves (add_edges' caller callees cg)
let reachable roots cuts cg =
let visited = ref NS.empty in