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

SCM Repository

[smlnj] Diff of /sml/trunk/src/MLRISC/flowgraph/buildFlowgraph.sml
ViewVC logotype

Diff of /sml/trunk/src/MLRISC/flowgraph/buildFlowgraph.sml

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1135, Tue Mar 12 16:09:26 2002 UTC revision 1136, Tue Mar 12 19:44:02 2002 UTC
# Line 146  Line 146 
146        fun addEdge(from, to, kind) =        fun addEdge(from, to, kind) =
147          #add_edge graph (from, to, CFG.EDGE{k=kind, w=ref 0.0, a=ref[]})          #add_edge graph (from, to, CFG.EDGE{k=kind, w=ref 0.0, a=ref[]})
148    
149          fun addEdgeAn(from, to, kind, an) =
150            #add_edge graph (from, to, CFG.EDGE{k=kind, w=ref 0.0, a=ref an})
151    
152        fun target lab =        fun target lab =
153          (case (IntHashTable.find labelMap (hashLabel lab))          (case (IntHashTable.find labelMap (hashLabel lab))
154            of SOME bId => bId            of SOME bId => bId
155             | NONE => EXIT)             | NONE => EXIT)
156    
157        fun jump(from, [Props.ESCAPES], _) = addEdge(from, EXIT, CFG.EXIT)        val {get=getProb, ...} = MLRiscAnnotations.BRANCH_PROB
158          | jump(from, [Props.LABELLED lab], _) = addEdge(from, target lab, CFG.JUMP)  
159          | jump(from, [Props.LABELLED lab, Props.FALLTHROUGH], blks) = let        fun jump(from, instr, blocks) = let
160            fun branch(targetLab) = let
161              val (_, an) = Props.getAnnotations instr
162              val an = List.filter
163                           (fn (MLRiscAnnotations.BRANCHPROB _) => true | _ => false)
164                           an
165             fun next(CFG.BLOCK{id, ...}::_) = id             fun next(CFG.BLOCK{id, ...}::_) = id
166               | next [] = error "jump.next"               | next [] = error "jump.next"
167            in            in
168              addEdge(from, target lab, CFG.BRANCH true);              addEdgeAn(from, target targetLab, CFG.BRANCH true, an);
169              addEdge(from, next blks, CFG.BRANCH false)              addEdge(from, next blocks, CFG.BRANCH false)
170            end            end
171          | jump(from, [f as Props.FALLTHROUGH, l as Props.LABELLED _], blks) =        in
172              jump(from, [l, f], blks)            case Props.branchTargets instr
173          | jump(from, targets, _) = let             of [Props.ESCAPES] => addEdge(from, EXIT, CFG.EXIT)
174                | [Props.LABELLED lab] => addEdge(from, target lab, CFG.JUMP)
175                | [Props.LABELLED lab, Props.FALLTHROUGH] => branch(lab)
176                | [Props.FALLTHROUGH, Props.LABELLED lab] =>  branch(lab)
177                | targets =>  let
178              fun switch(Props.LABELLED lab, n) =              fun switch(Props.LABELLED lab, n) =
179                   (addEdge(from, target lab, CFG.SWITCH(n)); n+1)                   (addEdge(from, target lab, CFG.SWITCH(n)); n+1)
180                | switch _ = error "jump.switch"                | switch _ = error "jump.switch"
181            in List.foldl switch 0 targets; ()            in List.foldl switch 0 targets; ()
182            end            end
183          end
184    
185        and fallsThru(id, blks) =        and fallsThru(id, blks) =
186          case blks          case blks
# Line 178  Line 191 
191          and addEdges [] = ()          and addEdges [] = ()
192            | addEdges(CFG.BLOCK{id, insns=ref[], ...}::blocks) = fallsThru(id, blocks)            | addEdges(CFG.BLOCK{id, insns=ref[], ...}::blocks) = fallsThru(id, blocks)
193            | addEdges(CFG.BLOCK{id, insns=ref(instr::_), ...}::blocks) = let            | addEdges(CFG.BLOCK{id, insns=ref(instr::_), ...}::blocks) = let
194                fun doJmp () = jump(id, Props.branchTargets instr, blocks)                fun doJmp () = jump(id, instr, blocks)
195              in              in
196               case Props.instrKind instr               case Props.instrKind instr
197                of Props.IK_JUMP => doJmp()                of Props.IK_JUMP => doJmp()

Legend:
Removed from v.1135  
changed lines
  Added in v.1136

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