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 1249 - (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 : blume 1249 val dumpCFG = MLRiscControl.mkFlag
26 :     ("dump-cfg-after-complete-probs",
27 :     "when true, CFG is output after probability completion")
28 :    
29 : jhr 1135 val {get=getProb, ...} = MLRiscAnnotations.BRANCH_PROB
30 :    
31 :     (* Complete edge probabilities. *)
32 : blume 1249 fun completeProbs (cfg as Graph.GRAPH{forall_nodes, out_edges, ...}) = let
33 : jhr 1135 fun doBlock (blkId, _) = let
34 :     fun computeProbs ((_, _, e as CFG.EDGE{a, ...})::r, remaining, n, es) = (
35 :     case getProb(!a)
36 :     of NONE => computeProbs (r, remaining, n+1, e::es)
37 :     | SOME p => (
38 :     recordProb (e, Prob.toReal p);
39 :     computeProbs (r, Prob.-(remaining, p), n, es))
40 :     (* end case *))
41 :     | computeProbs ([], _, 0, _) = ()
42 :     | computeProbs ([], remaining, n, es) = let
43 :     val p = Prob.toReal(Prob./(remaining, n))
44 :     in
45 :     List.app (fn e => recordProb (e, p)) es
46 :     end
47 :     in
48 :     computeProbs (out_edges blkId, Prob.always, 0, [])
49 :     end
50 :     in
51 :     forall_nodes doBlock
52 : blume 1249 before (if !dumpCFG then CFG.dump (!MLRiscControl.debug_stream,
53 :     "after probability completion", cfg)
54 :     else ())
55 : jhr 1135 end
56 :    
57 :     end

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