Commit fd743881 authored by POTTIER Francois's avatar POTTIER Francois
Browse files

DataFlow.ml: cosmetic cleanup.

parent a9a3c0bb
......@@ -76,7 +76,7 @@ module Run
(* [update x' p'] ensures that the property associated with the variable [x']
is at least [p']. If this causes a change in the property at [x'], then
[x] is scheduled or rescheduled. *)
[x'] is scheduled or rescheduled. *)
let update (x' : variable) (p' : property) =
match M.find x' properties with
......@@ -147,7 +147,8 @@ module ForType (T : TYPE) =
module ForIntSegment (K : sig val n: int end) =
Run(Glue.ArraysAsImperativeMaps(K))
(* An alternative interface, allowing specialized (more efficient) maps *)
(* [ForCustomMaps] is a forward data flow analysis that is tuned for
performance. *)
module ForCustomMaps
(P : MINIMAL_SEMI_LATTICE)
......@@ -159,27 +160,25 @@ module ForCustomMaps
open P
open G
(* Compared to the standard Queue, CompactQueue is quite faster and consumes
less memory.
On my computer, analysing the cca_cpp grammar terminates 5% faster (2s)
and consumes 13% less memory (~370MB).
*)
(* Compared to [Queue], [CompactQueue] is significantly faster and consumes
less memory. *)
let queue = CompactQueue.create ()
let pending =
CompactQueue.create ()
(* The queue stores a set of dirty variables, whose outgoing transitions must
be examined. The "B" map keeps track of whether a variable is queued or
not. *)
(* The queue stores a set of dirty variables, whose outgoing transitions
must be examined. The map [B] records whether a variable is currently
queued. *)
let schedule var =
if not (B.get var) then begin
B.set var true;
CompactQueue.add var queue
let schedule (x : variable) =
if not (B.get x) then begin
B.set x true;
CompactQueue.add x pending
end
(* [update x' p'] ensures that the property associated with the variable [x']
is at least [p']. If this causes a change in the property at [x'], then
[x] is scheduled or rescheduled. *)
[x'] is scheduled or rescheduled. *)
let update (x' : variable) (p' : property) =
let p = V.get x' in
......@@ -196,18 +195,19 @@ module ForCustomMaps
Its outgoing transitions are inspected and its successors are updated. *)
let examine (x : variable) =
(* [x] is dirty, so a property must have been associated with it. *)
G.foreach_successor x (V.get x) update
let p = V.get x in
G.foreach_successor x p update
(* Populate the queue with the root variables. *)
let () = G.foreach_root (fun x p -> V.set x p; schedule x)
let () =
G.foreach_root (fun x p -> V.set x p; schedule x)
(* As long as the queue is nonempty, take a variable and examine it. *)
let () =
while not (CompactQueue.is_empty queue) do
let var = CompactQueue.take queue in
while not (CompactQueue.is_empty pending) do
let var = CompactQueue.take pending in
B.set var false;
examine var
done
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment