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 485, Fri Dec 10 16:06:03 2010 UTC revision 486, Wed Jan 5 17:00:05 2011 UTC
# Line 43  Line 43 
43            }            }
44        | COM of  {                       (* comment *)        | COM of  {                       (* comment *)
45              pred : node ref,              pred : node ref,
46              stm : assign,              text : string list,
47              succ : node ref              succ : node ref
48            }            }
49        | ASSIGN of {                     (* assignment *)        | ASSIGN of {                     (* assignment *)
# Line 156  Line 156 
156          val mkJOIN : (var * var list) list -> node          val mkJOIN : (var * var list) list -> node
157          val mkCOND : {cond : var, trueBranch : node, falseBranch : node} -> node          val mkCOND : {cond : var, trueBranch : node, falseBranch : node} -> node
158          val mkCOM : string list -> node          val mkCOM : string list -> node
159          val mkASSIGN : assign list -> node          val mkASSIGN : assign -> node
160          val mkNEW : {actor : Atom.atom, args : var list} -> node          val mkNEW : {actor : Atom.atom, args : var list} -> node
161          val mkDIE : unit -> node          val mkDIE : unit -> node
162          val mkSTABILIZE : unit -> node          val mkSTABILIZE : unit -> node
# Line 225  Line 225 
225    
226      datatype cfg = CFG of {      datatype cfg = CFG of {
227          entry : node ref,       (* the entry node of a graph; not necessarily an ENTRY node *)          entry : node ref,       (* the entry node of a graph; not necessarily an ENTRY node *)
228          exir : node ref         (* the exit node of a graph; not necessarily a DIE, STABILIZE,          exit : node ref         (* the exit node of a graph; not necessarily a DIE, STABILIZE,
229                                   * or EXIT node.                                   * or EXIT node.
230                                   *)                                   *)
231        }        }
# Line 330  Line 330 
330    
331      structure Node =      structure Node =
332        struct        struct
333            fun id (ND{id, ...}) = id
334            fun kind (ND{kind, ...}) = kind
335          fun same (ND{id=a, ...}, ND{id=b, ...}) = Stamp.same(a, b)          fun same (ND{id=a, ...}, ND{id=b, ...}) = Stamp.same(a, b)
336          fun compare (ND{id=a, ...}, ND{id=b, ...}) = Stamp.compare(a, b)          fun compare (ND{id=a, ...}, ND{id=b, ...}) = Stamp.compare(a, b)
337          fun hash (ND{id, ...}) = Stamp.hash id          fun hash (ND{id, ...}) = Stamp.hash id
# Line 493  Line 495 
495      structure CFG =      structure CFG =
496        struct        struct
497        (* create a basic block from a list of assignments *)        (* create a basic block from a list of assignments *)
498          fun mkBlock [] = CFG{entry = Node.dummy, exit = Node.dummy}          fun mkBlock [] = CFG{entry = ref Node.dummy, exit = ref Node.dummy}
499            | mkBlock (stm::stms) = let            | mkBlock (stm::stms) = let
500                val entry = Node.mkASSIGN stm                val entry = Node.mkASSIGN stm
501                fun f (stm, prev) = let                fun f (stm, prev) = let
# Line 504  Line 506 
506                      end                      end
507                val exit = List.foldl f entry stms                val exit = List.foldl f entry stms
508                in                in
509                  CFG{entry = entry, exit = exit}                  CFG{entry = ref entry, exit = ref exit}
510                end                end
511    
512        (* 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
513         * be in preorder with parents before children.         * be in preorder with parents before children.
514         *)         *)
515          fun sort (CFG{entry, ...} = let          fun sort (CFG{entry, ...}) = let
516                val {getFn, setFn} = PropList.newFlag (fn (ND{props, ...}) => props)                val {getFn, setFn} = PropList.newFlag (fn (ND{props, ...}) => props)
517                fun dfs (nd, l) =                fun dfs (nd, l) =
518                      if getFn nd                      if getFn nd
# Line 518  Line 520 
520                        else (                        else (
521                          setFn (nd, true);                          setFn (nd, true);
522                          nd :: List.foldl dfs l (Node.succs nd))                          nd :: List.foldl dfs l (Node.succs nd))
523                val nodes = dfs (entry, [])                val nodes = dfs (!entry, [])
524                in                in
525                  List.app (fn nd => setFn(nd, false)) nodes;                  List.app (fn nd => setFn(nd, false)) nodes;
526                  nodes                  nodes
# Line 534  Line 536 
536                          f nd; (* visit *)                          f nd; (* visit *)
537                          setFn (nd, true);                          setFn (nd, true);
538                          nd :: List.foldl dfs l (Node.succs nd))                          nd :: List.foldl dfs l (Node.succs nd))
539                val nodes = dfs (entry, [])                val nodes = dfs (!entry, [])
540                in                in
541                  List.app (fn nd => setFn(nd, false)) nodes                  List.app (fn nd => setFn(nd, false)) nodes
542                end                end

Legend:
Removed from v.485  
changed lines
  Added in v.486

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