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/IR/mlrisc-reshape-branches.sml
ViewVC logotype

Diff of /sml/trunk/src/MLRISC/IR/mlrisc-reshape-branches.sml

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

revision 544, Tue Feb 22 22:56:38 2000 UTC revision 545, Thu Feb 24 13:56:44 2000 UTC
# Line 5  Line 5 
5   * -- Allen   * -- Allen
6   *)   *)
7    
8  functor ReshapeBranchesFn  functor ReshapeBranches
9      ( structure IR   : MLRISC_IR      ( structure IR   : MLRISC_IR
10        structure P    : INSN_PROPERTIES        structure InsnProps : INSN_PROPERTIES
11           sharing IR.I = P.I           sharing IR.I = InsnProps.I
12      ) : RESHAPE_BRANCHES =      ) : MLRISC_IR_OPTIMIZATION =
13  struct  struct
14    
15     structure IR       = IR     structure IR       = IR
# Line 20  Line 20 
20     structure G        = Graph     structure G        = Graph
21     structure Util     = IR.Util     structure Util     = IR.Util
22    
23       type flowgraph = IR.IR
24    
25     (*     (*
26      * Restructure branches to in order to get better locality.      * Restructure branches to in order to get better locality.
27      *)      *)
28       val name = "ReshapeBranches"
29    
30     fun reshapeBranches IR =     fun run IR =
31     let val CFG as G.GRAPH cfg   = IR     let val CFG as G.GRAPH cfg   = IR
32         val Dom as G.GRAPH dom   = IR.dom  IR         val Dom as G.GRAPH dom   = IR.dom  IR
33         val Loop as G.GRAPH loop = IR.loop IR         val Loop as G.GRAPH loop = IR.loop IR
# Line 55  Line 58 
58                e2 as (_,k,CFG.EDGE{w=w2,k=k2 as CFG.BRANCH b2,a=a2})],                e2 as (_,k,CFG.EDGE{w=w2,k=k2 as CFG.BRANCH b2,a=a2})],
59                branch::rest) =>                branch::rest) =>
60               if should_flip(e1,e2) then               if should_flip(e1,e2) then
61                  let val branch' = P.negateConditional branch                  let val branch' = InsnProps.negateConditional branch
62                  in  if b1 andalso not(can_fallsthru j) orelse                  in  if b1 andalso not(can_fallsthru j) orelse
63                         b2 andalso not(can_fallsthru k) then                         b2 andalso not(can_fallsthru k) then
64                         raise GiveUp                         raise GiveUp
# Line 88  Line 91 
91                        flip_cond (fn _ => true) (i,#node_info cfg i)                        flip_cond (fn _ => true) (i,#node_info cfg i)
92                   | elim(e as (i,j,CFG.EDGE{k=CFG.FALLSTHRU,w,a,...})) =                   | elim(e as (i,j,CFG.EDGE{k=CFG.FALLSTHRU,w,a,...})) =
93                        let val i' as CFG.BLOCK{insns,...} = #node_info cfg i                        let val i' as CFG.BLOCK{insns,...} = #node_info cfg i
94                        in  insns := P.jump(                        in  insns := InsnProps.jump(
95                                  CFG.defineLabel(#node_info cfg i))::(!insns);                                  CFG.defineLabel(#node_info cfg i))::(!insns);
96                            CFG.removeEdge CFG e;                            CFG.removeEdge CFG e;
97                            #add_edge cfg (i,j,CFG.EDGE{k=CFG.JUMP,a=a,w=w});                            #add_edge cfg (i,j,CFG.EDGE{k=CFG.JUMP,a=a,w=w});
# Line 117  Line 120 
120                         val _ = elim_fallsthru i                         val _ = elim_fallsthru i
121                         val CFG.BLOCK{insns,...} = #node_info cfg i                         val CFG.BLOCK{insns,...} = #node_info cfg i
122                         fun remove_jump(insns as jmp::rest) =                         fun remove_jump(insns as jmp::rest) =
123                             if P.instrKind jmp = P.IK_JUMP then                             if InsnProps.instrKind jmp = InsnProps.IK_JUMP then
124                                rest else insns                                rest else insns
125                           | remove_jump [] = []                           | remove_jump [] = []
126                     in  insns := remove_jump(!insns);                     in  insns := remove_jump(!insns);
# Line 136  Line 139 
139    
140     in  #forall_nodes cfg (fn x => restructure_conditionals x handle _ => ());     in  #forall_nodes cfg (fn x => restructure_conditionals x handle _ => ());
141         #forall_nodes loop restructure_loop;         #forall_nodes loop restructure_loop;
142         if !changed then IR.changed IR else ()         if !changed then IR.changed IR else ();
143           IR
144     end     end
145    
146  end  end

Legend:
Removed from v.544  
changed lines
  Added in v.545

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