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

SCM Repository

[diderot] Diff of /trunk/src/compiler/IL/ssa-fn.sml
ViewVC logotype

Diff of /trunk/src/compiler/IL/ssa-fn.sml

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

revision 392, Thu Oct 14 15:34:28 2010 UTC revision 435, Tue Oct 19 13:14:20 2010 UTC
# Line 1  Line 1 
1  (* ssa-fn.sml  (* ssa-fn.sml
2   *   *
3   * COPYRIGHT (c) 2010 The Diderot Project (http://diderot.cs.uchicago.edu)   * COPYRIGHT (c) 2010 The Diderot Project (http://diderot-language.cs.uchicago.edu)
4   * All rights reserved.   * All rights reserved.
5   *   *
6   * The IL is a combination of a block-structured tree and an SSA control-flow   * The IL is a combination of a block-structured tree and an SSA control-flow
# Line 89  Line 89 
89      and var = V of {      and var = V of {
90          name : string,                  (* name *)          name : string,                  (* name *)
91          id : Stamp.stamp,               (* unique ID *)          id : Stamp.stamp,               (* unique ID *)
92            ty : Ty.ty,                     (* type *)
93          bind : var_bind ref,            (* binding *)          bind : var_bind ref,            (* binding *)
94          useCnt : int ref,               (* count of uses *)          useCnt : int ref,               (* count of uses *)
95          props : PropList.holder          props : PropList.holder
# Line 196  Line 197 
197        end        end
198    
199      structure Var : sig      structure Var : sig
200          val new : string -> var          val new : string * Ty.ty -> var
201          val name : var -> string          val name : var -> string
202            val ty : var -> Ty.ty
203          val binding : var -> var_bind          val binding : var -> var_bind
204          val setBinding : var * var_bind -> unit          val setBinding : var * var_bind -> unit
205          val same : var * var -> bool          val same : var * var -> bool
# Line 221  Line 223 
223          structure Tbl : MONO_HASH_TABLE where type Key.hash_key = var          structure Tbl : MONO_HASH_TABLE where type Key.hash_key = var
224        end        end
225    
226      (* return a string representation of a PHI node *)
227        val phiToString : (var * var list) -> string
228    
229      (* return a string representation of an assignment *)
230        val assignToString : assign -> string
231    
232    (* 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
233     * be in preorder with parents before children.     * be in preorder with parents before children.
234     *)     *)
# Line 314  Line 322 
322    
323      and var = V of {      and var = V of {
324          name : string,                  (* name *)          name : string,                  (* name *)
325            ty : Ty.ty,                     (* type *)
326          bind : var_bind ref,            (* binding *)          bind : var_bind ref,            (* binding *)
327          id : Stamp.stamp,               (* unique ID *)          id : Stamp.stamp,               (* unique ID *)
328          useCnt : int ref,               (* count of uses *)          useCnt : int ref,               (* count of uses *)
# Line 387  Line 396 
396          fun mkSTABILIZE () = new (STABILIZE{pred = ref dummy})          fun mkSTABILIZE () = new (STABILIZE{pred = ref dummy})
397          fun mkEXIT () = new (EXIT{pred = ref dummy})          fun mkEXIT () = new (EXIT{pred = ref dummy})
398        (* editing node edges *)        (* editing node edges *)
399          fun setPred (ND{kind, ...}, nd) = (case kind          fun setPred (nd0 as ND{kind, ...}, nd) = (case kind
400                 of NULL => raise Fail "setPred on NULL node"                 of NULL => raise Fail("setPred on NULL node "^toString nd0)
401                  | ENTRY _ => raise Fail "setPred on ENTRY node"                  | ENTRY _ => raise Fail("setPred on ENTRY node "^toString nd0)
402                  | JOIN{preds, ...} => if List.exists (fn nd' => same(nd, nd')) (!preds)                  | JOIN{preds, ...} => if List.exists (fn nd' => same(nd, nd')) (!preds)
403                      then ()                      then ()
404                      else preds := nd :: !preds                      else preds := nd :: !preds
# Line 400  Line 409 
409                  | STABILIZE{pred} => pred := nd                  | STABILIZE{pred} => pred := nd
410                  | EXIT{pred} => pred := nd                  | EXIT{pred} => pred := nd
411                (* end case *))                (* end case *))
412          fun preds (ND{kind, ...}) = (case kind          fun preds (nd as ND{kind, ...}) = (case kind
413                 of NULL => raise Fail "preds on NULL node"                 of NULL => raise Fail("preds on NULL node "^toString nd)
414                  | ENTRY _ => []                  | ENTRY _ => []
415                  | JOIN{preds, ...} => !preds                  | JOIN{preds, ...} => !preds
416                  | COND{pred, ...} => [!pred]                  | COND{pred, ...} => [!pred]
# Line 422  Line 431 
431                  | STABILIZE _ => false                  | STABILIZE _ => false
432                  | EXIT _ => false                  | EXIT _ => false
433                (* end case *))                (* end case *))
434          fun setSucc (ND{kind, ...}, nd) = (case kind          fun setSucc (nd0 as ND{kind, ...}, nd) = (case kind
435                 of NULL => raise Fail "setSucc on NULL node"                 of NULL => raise Fail("setSucc on NULL node "^toString nd0)
436                  | ENTRY{succ} => succ := nd                  | ENTRY{succ} => succ := nd
437                  | JOIN{succ, ...} => succ := nd                  | JOIN{succ, ...} => succ := nd
438                  | COND _ => raise Fail "setSucc on COND node"                  | COND _ => raise Fail("setSucc on COND node "^toString nd0)
439                  | BLOCK{succ, ...} => succ := nd                  | BLOCK{succ, ...} => succ := nd
440                  | NEW{succ, ...} => succ := nd                  | NEW{succ, ...} => succ := nd
441                  | DIE _ => raise Fail "setSucc on DIE node"                  | DIE _ => raise Fail("setSucc on DIE node "^toString nd0)
442                  | STABILIZE _ => raise Fail "setSucc on STABILIZE node"                  | STABILIZE _ => raise Fail("setSucc on STABILIZE node "^toString nd0)
443                  | EXIT _ => raise Fail "setSucc on EXIT node"                  | EXIT _ => raise Fail("setSucc on EXIT node "^toString nd0)
444                (* end case *))                (* end case *))
445          fun succs (ND{kind, ...}) = (case kind          fun succs (nd as ND{kind, ...}) = (case kind
446                 of NULL => raise Fail "succs on NULL node"                 of NULL => raise Fail("succs on NULL node "^toString nd)
447                  | ENTRY{succ} => [!succ]                  | ENTRY{succ} => [!succ]
448                  | JOIN{succ, ...} => [!succ]                  | JOIN{succ, ...} => [!succ]
449                  | COND{trueBranch, falseBranch, ...} => [!trueBranch, !falseBranch]                  | COND{trueBranch, falseBranch, ...} => [!trueBranch, !falseBranch]
# Line 535  Line 544 
544    
545      structure Var =      structure Var =
546        struct        struct
547          fun new name = V{          fun new (name, ty) = V{
548                  name = name,                  name = name,
549                  id = Stamp.new(),                  id = Stamp.new(),
550                    ty = ty,
551                  bind = ref VB_NONE,                  bind = ref VB_NONE,
552                  useCnt = ref 0,                  useCnt = ref 0,
553                  props = PropList.newHolder()                  props = PropList.newHolder()
554                }                }
555          fun name (V{name, ...}) = name          fun name (V{name, ...}) = name
556            fun ty (V{ty, ...}) = ty
557          fun binding (V{bind, ...}) = !bind          fun binding (V{bind, ...}) = !bind
558          fun setBinding (V{bind, ...}, vb) = bind := vb          fun setBinding (V{bind, ...}, vb) = bind := vb
559          fun same (V{id=a, ...}, V{id=b, ...}) = Stamp.same(a, b)          fun same (V{id=a, ...}, V{id=b, ...}) = Stamp.same(a, b)
# Line 572  Line 583 
583            end)            end)
584        end        end
585    
586      (* return a string representation of a PHI node *)
587        fun phiToString (y, xs) = String.concat [
588                Ty.toString(Var.ty y), " ", Var.toString y, " = PHI(",
589                String.concatWith "," (List.map Var.toString xs), ")"
590              ]
591    
592      (* return a string representation of an assignment *)
593        fun assignToString (y, rhs) = let
594              val rhs = (case rhs
595                     of VAR x => Var.toString x
596                      | LIT lit => Literal.toString lit
597                      | OP(rator, xs) => String.concat [
598                            Op.toString rator,
599                            "(", String.concatWith "," (List.map Var.toString xs), ")"
600                          ]
601                      | CONS xs => String.concat [
602                            "[", String.concatWith "," (List.map Var.toString xs), "]"
603                          ]
604                    (* end case *))
605              in
606                String.concat [Ty.toString(Var.ty y), " ", Var.toString y, " = ", rhs]
607              end
608    
609    (* 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
610     * be in preorder with parents before children.     * be in preorder with parents before children.
611     *)     *)

Legend:
Removed from v.392  
changed lines
  Added in v.435

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