Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] Diff of /branches/vis12/src/compiler/IL/rewrite-fn.sml
ViewVC logotype

Diff of /branches/vis12/src/compiler/IL/rewrite-fn.sml

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

revision 2199, Sun Feb 24 15:15:14 2013 UTC revision 2200, Sun Feb 24 15:16:01 2013 UTC
# Line 11  Line 11 
11    (* rewrite the right-hand-side of an assignment; returns NONE if there are no changes    (* rewrite the right-hand-side of an assignment; returns NONE if there are no changes
12     * and SOME assigns if the assignment is rewritten to the assigns list.     * and SOME assigns if the assignment is rewritten to the assigns list.
13     *)     *)
14      val doRHS : IL.var * IL.rhs -> (IL.var * IL.rhs) list option      val doAssign : IL.assign -> (IL.var * IL.rhs) list option
15      (* rewrite the rhs of an multi-assignment *)
16        val doMAssign : IL.massign -> (IL.var * IL.rhs) list option
17    (* eliminates unused variables; returns true if any changes *)    (* eliminates unused variables; returns true if any changes *)
18      val elimUnusedVars : IL.cfg -> bool      val elimUnusedVars : IL.cfg -> bool
19    end    end
# Line 26  Line 28 
28    
29      fun useCount (IL.V{useCnt, ...}) = !useCnt      fun useCount (IL.V{useCnt, ...}) = !useCnt
30    
31    (* simplify expressions *)    (* simplify assignment and multi-assignment statements *)
32      fun simplify (nd as IL.ND{kind=IL.ASSIGN{stm=(y, rhs), ...}, ...}) =      fun simplify nd = let
33            if (useCount y = 0)            fun rewrite (SOME[]) = (IL.CFG.deleteNode nd; true)
34              then false (* skip unused assignments *)              | rewrite (SOME assigns) = let
             else (case doRHS(y, rhs)  
                of SOME[] => (IL.CFG.deleteNode nd; true)  
                 | SOME assigns => let  
35                      val assigns = List.map                      val assigns = List.map
36                            (fn (y, rhs) => (IL.Var.setBinding(y, IL.VB_RHS rhs); IL.ASSGN(y, rhs)))                            (fn (y, rhs) => (IL.Var.setBinding(y, IL.VB_RHS rhs); IL.ASSGN(y, rhs)))
37                              assigns                              assigns
# Line 40  Line 39 
39                        IL.CFG.replaceNodeWithCFG (nd, IL.CFG.mkBlock assigns);                        IL.CFG.replaceNodeWithCFG (nd, IL.CFG.mkBlock assigns);
40                        true                        true
41                      end                      end
42                  | NONE => false              | rewrite NONE = false
43                (* end case *))            in
44        | simplify _ = false              case IL.Node.kind nd
45                 of IL.ASSIGN{stm=(y, rhs), ...} => if (useCount y = 0)
46                      then false (* skip unused assignments *)
47                      else rewrite (doAssign (y, rhs))
48                  | IL.MASSIGN{stm, ...} => rewrite (doMAssign stm)
49                  | _ => false
50                (* end case *)
51              end
52    
53      fun loopToFixPt f = let      fun loopToFixPt f = let
54            fun loop anyChanges = if f() then loop true else anyChanges            fun loop anyChanges = if f() then loop true else anyChanges

Legend:
Removed from v.2199  
changed lines
  Added in v.2200

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