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

SCM Repository

[diderot] Diff of /branches/pure-cfg/src/compiler/IL/backward-dfa-fn.sml
ViewVC logotype

Diff of /branches/pure-cfg/src/compiler/IL/backward-dfa-fn.sml

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

revision 488, Wed Jan 12 23:21:04 2011 UTC revision 740, Mon Apr 4 02:07:42 2011 UTC
# Line 35  Line 35 
35      fun clear node = (clrIn node; clrOut node)      fun clear node = (clrIn node; clrOut node)
36    
37      fun analyse (exitVal, cfg) = let      fun analyse (exitVal, cfg) = let
38          (* use DFS order to get quicker convergence *)          (* use reverse DFS order to get quicker convergence *)
39            val nodes = IL.CFG.sort cfg            val nodes = List.rev (IL.CFG.sort cfg)
40          (* set initial values for exit nodes *)          (* the first pass does not do change propagation, since we haven't computed anything yet *)
41            val _ = List.app (fn nd => if IL.Node.hasSucc nd then () else setIn(nd, exitVal nd)) nodes            fun initNode nd = if IL.Node.hasSucc nd
42                    then let
43                      val outValue = D.join (List.map getIn (IL.Node.succs nd))
44                      val inValue = D.transfer (outValue, nd)
45                      in
46                        setOut (nd, outValue);
47                        setIn (nd, inValue)
48                      end
49                    else setIn(nd, exitVal nd)  (* exit node *)
50            (* once nodes are initialized, we iterate until we reach a fixed point *)
51            fun iterate () = let            fun iterate () = let
52                  val anyChange = ref false                  val anyChange = ref false
53                  fun doNode nd = let                  fun doNode nd = let
54                        val outValue = D.join (List.map getIn (IL.Node.succs nd))                        val outValue = D.join (List.map getIn (IL.Node.succs nd))
55                        in                        in
56                          if D.same(getOut nd, outValue)                          if D.same(getOut nd, outValue)
57                            then ()(* output unchanged, so output will be unchanged *)                            then ()(* output unchanged, so input will be unchanged *)
58                            else let                            else let
59                              val inValue = D.transfer (outValue, nd)                              val inValue = D.transfer (outValue, nd)
60                              in                              in
# Line 61  Line 70 
70                    if !anyChange then iterate() else ()                    if !anyChange then iterate() else ()
71                  end                  end
72            in            in
73              iterate (); nodes            (* initialize the rest of the nodes *)
74                List.app initNode nodes;
75              (* iterate to a fixed point *)
76                iterate ();
77                nodes
78            end            end
79    
80      fun inValue nd = getIn nd      fun inValue nd = getIn nd

Legend:
Removed from v.488  
changed lines
  Added in v.740

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