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/ssa-fn.sml
ViewVC logotype

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

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

revision 1016, Fri Apr 29 21:59:23 2011 UTC revision 1017, Sun May 1 03:06:05 2011 UTC
# Line 94  Line 94 
94    (***** Program representation *****)    (***** Program representation *****)
95    
96      datatype program = Program of {      datatype program = Program of {
         globals : var list,  
97          globalInit : cfg,          globalInit : cfg,
98          initially : initially,          initially : initially,
99          strands : strand list          strands : strand list
# Line 118  Line 117 
117      and method = Method of {      and method = Method of {
118          name : Atom.atom,          name : Atom.atom,
119          stateIn : var list,     (* names of state variables on method entry *)          stateIn : var list,     (* names of state variables on method entry *)
         stateOut : var list,    (* names of state variables on method exit *)  
120          body : cfg              (* method body *)          body : cfg              (* method body *)
121        }        }
122    
# Line 133  Line 131 
131        (* entry/exit nodes of a CFG *)        (* entry/exit nodes of a CFG *)
132          val entry : cfg -> node          val entry : cfg -> node
133          val exit : cfg -> node          val exit : cfg -> node
134          (* return the list of variables that are live at exit from a CFG *)
135            val liveAtExit : cfg -> var list
136        (* DFS sorting of the graph rooted at the entry to a statement; the resulting list will        (* DFS sorting of the graph rooted at the entry to a statement; the resulting list will
137         * be in preorder with parents before children.         * be in preorder with parents before children.
138         *)         *)
# Line 151  Line 151 
151        (* replace a simple node in a cfg with a different simple node *)        (* replace a simple node in a cfg with a different simple node *)
152          val replaceNode : (node * node) -> unit          val replaceNode : (node * node) -> unit
153        (* replace a simple node in a cfg with a subgraph *)        (* replace a simple node in a cfg with a subgraph *)
154          val splice : (node * cfg) -> unit          val replaceNodeWithCFG : (node * cfg) -> unit
155        (* concatenate two CFGs *)        (* concatenate two CFGs *)
156          val concat : cfg * cfg -> cfg          val concat : cfg * cfg -> cfg
157        (* append a node to a CFG *)        (* append a node to a CFG *)
# Line 182  Line 182 
182          val setTrueBranch : node * node -> unit  (* set trueBranch successor for COND node *)          val setTrueBranch : node * node -> unit  (* set trueBranch successor for COND node *)
183          val setFalseBranch : node * node -> unit (* set falseBranch successor for COND node *)          val setFalseBranch : node * node -> unit (* set falseBranch successor for COND node *)
184          val addEdge : node * node -> unit          val addEdge : node * node -> unit
185        (* replace in-going and out-going edges *)        (* replace the edge src-->oldDst by the edge src-->dst *)
186          val replaceInEdge : {src : node, oldDst : node, dst : node} -> unit          val replaceInEdge : {src : node, oldDst : node, dst : node} -> unit
187          (* replace the edge oldSrc-->dst by the edge src-->dst *)
188          val replaceOutEdge : {oldSrc : node, src : node, dst : node} -> unit          val replaceOutEdge : {oldSrc : node, src : node, dst : node} -> unit
189        (* constructors *)        (* constructors *)
190          val mkENTRY : unit -> node          val mkENTRY : unit -> node
# Line 345  Line 346 
346    (***** Program representation *****)    (***** Program representation *****)
347    
348      datatype program = Program of {      datatype program = Program of {
         globals : var list,  
349          globalInit : cfg,          globalInit : cfg,
350          initially : initially,          initially : initially,
351          strands : strand list          strands : strand list
# Line 369  Line 369 
369      and method = Method of {      and method = Method of {
370          name : Atom.atom,          name : Atom.atom,
371          stateIn : var list,     (* names of state variables on method entry *)          stateIn : var list,     (* names of state variables on method entry *)
         stateOut : var list,    (* names of state variables on method exit *)  
372          body : cfg              (* method body *)          body : cfg              (* method body *)
373        }        }
374    
# Line 614  Line 613 
613          fun entry (CFG{entry = nd, ...}) = nd          fun entry (CFG{entry = nd, ...}) = nd
614          fun exit (CFG{exit = nd, ...}) = nd          fun exit (CFG{exit = nd, ...}) = nd
615    
616          (* return the list of variables that are live at exit from a CFG *)
617            fun liveAtExit cfg = (case Node.kind(exit cfg)
618                   of EXIT{live, ...} => live
619                    | _ => raise Fail "bogus exit node"
620                  (* end case *))
621    
622        (* DFS sorting of the graph rooted at the entry to a statement; the resulting list will        (* DFS sorting of the graph rooted at the entry to a statement; the resulting list will
623         * be in preorder with parents before children.         * be in preorder with parents before children.
624         *)         *)
# Line 671  Line 676 
676                 of ASSIGN{pred, succ, ...} => (                 of ASSIGN{pred, succ, ...} => (
677                      Node.replaceInEdge {src = !pred, oldDst = oldNd, dst = node};                      Node.replaceInEdge {src = !pred, oldDst = oldNd, dst = node};
678                      Node.replaceOutEdge {oldSrc = oldNd, src = node, dst = !succ})                      Node.replaceOutEdge {oldSrc = oldNd, src = node, dst = !succ})
679                    | NEW{pred, succ, ...} => (
680                        Node.replaceInEdge {src = !pred, oldDst = oldNd, dst = node};
681                        Node.replaceOutEdge {oldSrc = oldNd, src = node, dst = !succ})
682                    | EXIT{pred, ...} =>
683                        Node.replaceInEdge {src = !pred, oldDst = oldNd, dst = node}
684                  | _ => raise Fail "unsupported replaceNode"                  | _ => raise Fail "unsupported replaceNode"
685                (* end case *))                (* end case *))
686    
687        (* replace a simple node in a cfg with a subgraph *)        (* replace a simple node in a cfg with a subgraph *)
688          fun splice (nd as ND{kind, ...}, cfg as CFG{entry, exit}) =          fun replaceNodeWithCFG (nd as ND{kind, ...}, cfg as CFG{entry, exit}) =
689                if isEmpty cfg                if isEmpty cfg
690                  then deleteNode nd                  then deleteNode nd
691                  else (case kind                  else (case kind
692                     of ASSIGN{pred, succ, ...} => (                     of ASSIGN{pred, succ, ...} => (
693                          Node.replaceInEdge {src = !pred, oldDst = nd, dst = entry};                          Node.replaceInEdge {src = !pred, oldDst = nd, dst = entry};
694                          Node.replaceOutEdge {oldSrc = nd, src = exit, dst = !succ})                          Node.replaceOutEdge {oldSrc = nd, src = exit, dst = !succ})
695                      | _ => raise Fail "unsupported splice"                      | _ => raise Fail "unsupported replaceNodeWithCFG"
696                    (* end case *))                    (* end case *))
697    
698        (* concatenate two CFGs *)        (* concatenate two CFGs *)

Legend:
Removed from v.1016  
changed lines
  Added in v.1017

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