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

SCM Repository

[smlnj] Annotation of /sml/trunk/src/MLRISC/frequencies/complete-probs-fn.sml
ViewVC logotype

Annotation of /sml/trunk/src/MLRISC/frequencies/complete-probs-fn.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1135 - (view) (download)

1 : jhr 1135 (* complete-probs-fn.sml
2 :     *
3 :     * COPYRIGHT (c) 2002 Bell Labs, Lucent Technologies
4 :     *
5 :     * Given a CFG that may have incomplete branch probability information,
6 :     * fill in the information.
7 :     *)
8 :    
9 :    
10 :     functor CompleteProbsFn (
11 :     structure CFG : CONTROL_FLOW_GRAPH
12 :     (* function to record edge probabilities *)
13 :     val recordProb : (CFG.edge_info * real) -> unit
14 :     ) : sig
15 :    
16 :     structure CFG : CONTROL_FLOW_GRAPH
17 :    
18 :     val completeProbs : CFG.cfg -> unit
19 :    
20 :     end = struct
21 :    
22 :     structure CFG = CFG
23 :     structure Prob = Probability
24 :    
25 :     val {get=getProb, ...} = MLRiscAnnotations.BRANCH_PROB
26 :    
27 :     (* Complete edge probabilities. *)
28 :     fun completeProbs (Graph.GRAPH{forall_nodes, out_edges, ...}) = let
29 :     fun doBlock (blkId, _) = let
30 :     fun computeProbs ((_, _, e as CFG.EDGE{a, ...})::r, remaining, n, es) = (
31 :     case getProb(!a)
32 :     of NONE => computeProbs (r, remaining, n+1, e::es)
33 :     | SOME p => (
34 :     recordProb (e, Prob.toReal p);
35 :     computeProbs (r, Prob.-(remaining, p), n, es))
36 :     (* end case *))
37 :     | computeProbs ([], _, 0, _) = ()
38 :     | computeProbs ([], remaining, n, es) = let
39 :     val p = Prob.toReal(Prob./(remaining, n))
40 :     in
41 :     List.app (fn e => recordProb (e, p)) es
42 :     end
43 :     in
44 :     computeProbs (out_edges blkId, Prob.always, 0, [])
45 :     end
46 :     in
47 :     forall_nodes doBlock
48 :     end
49 :    
50 :     end

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0