Home My Page Projects Code Snippets Project Openings SML/NJ
 Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] View of /sml/trunk/src/MLRISC/frequencies/complete-probs-fn.sml
 [smlnj] / sml / trunk / src / MLRISC / frequencies / complete-probs-fn.sml View of /sml/trunk/src/MLRISC/frequencies/complete-probs-fn.sml

Tue Mar 12 16:09:26 2002 UTC (17 years, 3 months ago) by jhr
File size: 1328 byte(s)
```  Added functor to compute block and edge frequencies from edge
probabilities.
```
```(* complete-probs-fn.sml
*
* COPYRIGHT (c) 2002 Bell Labs, Lucent Technologies
*
* Given a CFG that may have incomplete branch probability information,
* fill in the information.
*)

functor CompleteProbsFn (
structure CFG : CONTROL_FLOW_GRAPH
(* function to record edge probabilities *)
val recordProb : (CFG.edge_info * real) -> unit
) : sig

structure CFG : CONTROL_FLOW_GRAPH

val completeProbs : CFG.cfg -> unit

end = struct

structure CFG = CFG
structure Prob = Probability

val {get=getProb, ...} = MLRiscAnnotations.BRANCH_PROB

(* Complete edge probabilities. *)
fun completeProbs (Graph.GRAPH{forall_nodes, out_edges, ...}) = let
fun doBlock (blkId, _) = let
fun computeProbs ((_, _, e as CFG.EDGE{a, ...})::r, remaining, n, es) = (
case getProb(!a)
of NONE => computeProbs (r, remaining, n+1, e::es)
| SOME p => (
recordProb (e, Prob.toReal p);
computeProbs (r, Prob.-(remaining, p), n, es))
(* end case *))
| computeProbs ([], _, 0, _) = ()
| computeProbs ([], remaining, n, es) = let
val p = Prob.toReal(Prob./(remaining, n))
in
List.app (fn e => recordProb (e, p)) es
end
in
computeProbs (out_edges blkId, Prob.always, 0, [])
end
in
forall_nodes doBlock
end

end
```