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/branches/SMLNJ/src/MLRISC/IR/mlrisc-cfg-structuring.sml
ViewVC logotype

Diff of /sml/branches/SMLNJ/src/MLRISC/IR/mlrisc-cfg-structuring.sml

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

revision 410, Fri Sep 3 00:25:03 1999 UTC revision 411, Fri Sep 3 00:25:03 1999 UTC
# Line 1  Line 1 
1    (*
2     * Module for adding preheaders and splitting critical edges
3     *
4     * -- Allen
5     *)
6    
7  functor CFGStructuringFn(IR : MLRISC_IR) : CFG_STRUCTURING =  functor CFGStructuringFn(IR : MLRISC_IR) : CFG_STRUCTURING =
8  struct  struct
9    
# Line 8  Line 14 
14     structure W    = CFG.W     structure W    = CFG.W
15     structure G    = Graph     structure G    = Graph
16    
17     structure Reshape = ControlFlowGraphRestructureF(structure Loop = Loop)     structure Reshape = ControlFlowGraphRestructureFn(structure Loop = Loop)
18    
19     fun restructure IR { add_preheader, split_critical_edges } =     fun reshape { add_preheader, split_critical_edges } IR =
20     let fun reshape IR =     let  val CFG as G.GRAPH cfg = IR
        let  val CFG as G.GRAPH cfg = IR.cfg' IR  
21              val loop               = IR.loop IR              val loop               = IR.loop IR
22    
23              fun is_falls_thru(_,_,CFG.EDGE{k=CFG.BRANCH false,...}) = true              fun is_falls_thru(_,_,CFG.EDGE{k=CFG.BRANCH false,...}) = true
24                | is_falls_thru(_,_,CFG.EDGE{k=CFG.FALLS_THRU,...}) = true            | is_falls_thru(_,_,CFG.EDGE{k=CFG.FALLSTHRU,...}) = true
25                | is_falls_thru(_,_,_) = false                | is_falls_thru(_,_,_) = false
26    
27              fun ins_preheader{header,entries=[]} = ()              fun ins_preheader{header,entries=[]} = ()
# Line 24  Line 29 
29                | ins_preheader{header=(h,h'),entries} =                | ins_preheader{header=(h,h'),entries} =
30                  let fun sum_weights([],n) = n                  let fun sum_weights([],n) = n
31                        | sum_weights((_,_,CFG.EDGE{w,a,...})::es,n) =                        | sum_weights((_,_,CFG.EDGE{w,a,...})::es,n) =
32                            sum_weights(es,W.+(!w,n))                        sum_weights(es,!w + n)
33                      val w = sum_weights(entries,W.zero)                      val w = sum_weights(entries,W.zero)
34                      val BB.BLOCK{live_in=ref li,...} = h'                  val CFG.BLOCK{annotations=old_an,...} = h'
35                      val p = #new_id cfg ()                      val p = #new_id cfg ()
36                      val (preheader as BB.BLOCK{freq,live_in,live_out,...},                  val (preheader as CFG.BLOCK{freq,annotations,...}, new_edge) =
                          new_edge) =  
37                         if List.exists is_falls_thru entries then                         if List.exists is_falls_thru entries then
38                           (BB.empty_block(p,w),                       (CFG.empty_block(p,w),
39                           (p,h,CFG.EDGE{k=CFG.FALLS_THRU,w=ref w,a=a}))                       (p,h,CFG.EDGE{k=CFG.FALLSTHRU,w=ref w,a=a}))
40                         else                         else
41                           (BB.jump_block(p,BB.define_label h',w),                       (CFG.jump_block(p,CFG.define_label h',w),
42                           (p,h,CFG.EDGE{k=CFG.JUMP,w=ref w,a=a}))                           (p,h,CFG.EDGE{k=CFG.JUMP,w=ref w,a=a}))
43                      val new_entries = map (fn (i,j,e) => (i,p,e)) entries                      val new_entries = map (fn (i,j,e) => (i,p,e)) entries
44                  in  live_in  := li; live_out := li;              in  annotations := !old_an;
45                      app (fn (i,j,_) => #remove_edge cfg (i,j)) entries;                      app (fn (i,j,_) => #remove_edge cfg (i,j)) entries;
46                      app (#add_edge cfg) new_entries;                      app (#add_edge cfg) new_entries;
47                      #add_node cfg (p,preheader);                      #add_node cfg (p,preheader);
# Line 52  Line 56 
56                   };                   };
57              CFG.changed CFG              CFG.changed CFG
58          end          end
    in  
        reshape IR  
    end  
59    
60  end  end
61    
 (*  
  * $Log$  
  *)  

Legend:
Removed from v.410  
changed lines
  Added in v.411

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