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/IR/static-branch-prediction.sml
ViewVC logotype

Annotation of /sml/trunk/src/MLRISC/IR/static-branch-prediction.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 651 - (view) (download)

1 : monnier 411 (*
2 :     * This module performs static branch prediction using heuristics
3 :     * similar to Ball and Larus'
4 :     *
5 :     * -- Allen
6 :     *)
7 :    
8 : george 545 functor StaticBranchPrediction
9 :     (structure IR : MLRISC_IR
10 :     structure InsnProps : INSN_PROPERTIES
11 : monnier 411 structure FreqProps : FREQUENCY_PROPERTIES
12 : george 545 sharing IR.I = FreqProps.I = InsnProps.I
13 :     val loopMultiplier : int
14 :     ) : MLRISC_IR_OPTIMIZATION =
15 : monnier 245 struct
16 :    
17 :     structure IR = IR
18 :     structure CFG = IR.CFG
19 : george 545 structure CompFreq = ComputeFrequencies(structure Loop = IR.Loop
20 :     structure Freq = CFG.W)
21 : monnier 245
22 : george 545 type flowgraph = IR.IR
23 :    
24 :     val name = "StaticBranchPrediction"
25 :     fun run IR =
26 : monnier 411 let fun branchProb(CFG.BLOCK{insns,...}) =
27 :     case !insns of
28 :     [] => 100 (* the fallsthru edge is always taken *)
29 :     | jmp::_ =>
30 : george 545 (case InsnProps.instrKind jmp of
31 :     InsnProps.IK_JUMP => FreqProps.branchProb jmp
32 : monnier 411 | _ => 100 (* the fallsthru edge is always taken *)
33 :     )
34 :    
35 : monnier 245
36 : monnier 411 fun nodeFreq(CFG.BLOCK{freq,...}) = freq
37 :     fun edgeFreq(CFG.EDGE{w,...}) = w
38 : monnier 245
39 : monnier 411 (* is this a conditional branch and is it in the taken direction? *)
40 :     fun isTakenBranch(_,_,CFG.EDGE{k=CFG.BRANCH b,...}) = b
41 :     | isTakenBranch _ = false
42 : monnier 245
43 : monnier 411 in CompFreq.compute_frequencies
44 :     { cfg = IR,
45 :     loop = IR.loop IR,
46 :     loopMultiplier = loopMultiplier,
47 :     nodeFreq = nodeFreq,
48 :     edgeFreq = edgeFreq,
49 :     branchProb = branchProb,
50 :     isTakenBranch = isTakenBranch
51 : george 545 };
52 :     IR
53 : monnier 245 end
54 :    
55 :     end

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