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

SCM Repository

[diderot] Diff of /branches/vis15/src/compiler/cfg-ir/ssa-fn.sml
ViewVC logotype

Diff of /branches/vis15/src/compiler/cfg-ir/ssa-fn.sml

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

revision 3501, Thu Dec 17 20:07:13 2015 UTC revision 3502, Thu Dec 17 23:13:35 2015 UTC
# Line 56  Line 56 
56            }            }
57        | FOREACH of {                    (* foreach-loop; this node combines aspects of the COND        | FOREACH of {                    (* foreach-loop; this node combines aspects of the COND
58                                           * and JOIN nodes. *)                                           * and JOIN nodes. *)
59              preds : node list ref,      (* the predecessors; the first item is the entry edge              pred : node ref,            (* the predecessor *)
                                          * and the others are the loop back edges. *)  
60              phis : phi list ref,        (* phi nodes (as in JOIN) *)              phis : phi list ref,        (* phi nodes (as in JOIN) *)
61              mask : bool list ref,       (* true for incoming fake edges *)              mask : bool list ref,       (* true for incoming fake edges *)
62              var : var,                  (* the loop variable *)              var : var,                  (* the loop variable *)
63              src : var,                  (* the source of values being iterated over *)              src : var,                  (* the source of values being iterated over *)
64              body : node ref,            (* the loop body *)              bodyEntry : node ref,       (* the loop body entry node *)
65                bodyExit : node ref,        (* the loop body exit node *)
66              succ : node ref             (* the loop-exit edge *)              succ : node ref             (* the loop-exit edge *)
67            }            }
68        | COM of  {                       (* comment *)        | COM of  {                       (* comment *)
# Line 384  Line 384 
384                  trueBranch = ref dummy, falseBranch = ref dummy                  trueBranch = ref dummy, falseBranch = ref dummy
385                })                })
386          fun mkFOREACH (var, src) = new (FOREACH{          fun mkFOREACH (var, src) = new (FOREACH{
387                  preds = ref [],                  pred = ref dummy,
388                  phis = ref [], mask = ref [],                  phis = ref [], mask = ref [],
389                  var = var, src = src,                  var = var, src = src,
390                  body = ref dummy, succ = ref dummy                  bodyEntry = ref dummy,
391                    bodyExit = ref dummy,
392                    succ = ref dummy
393                })                })
394          fun mkCOM text = new (COM{pred = ref dummy, text = text, succ = ref dummy})          fun mkCOM text = new (COM{pred = ref dummy, text = text, succ = ref dummy})
395          fun mkASSIGN (lhs, rhs) = (          fun mkASSIGN (lhs, rhs) = (
# Line 436  Line 438 
438                 of NULL => raise Fail("setPred on NULL node " ^ toString nd0)                 of NULL => raise Fail("setPred on NULL node " ^ toString nd0)
439                  | ENTRY _ => raise Fail("setPred on ENTRY node " ^ toString nd0)                  | ENTRY _ => raise Fail("setPred on ENTRY node " ^ toString nd0)
440                  | JOIN{preds, ...} => preds := !preds @ [nd]  (* assume preds are added in order *)                  | JOIN{preds, ...} => preds := !preds @ [nd]  (* assume preds are added in order *)
441                  | FOREACH{preds, ...} => preds := !preds @ [nd]                  | FOREACH{pred, ...} => pred := nd
442                  | COND{pred, ...} => pred := nd                  | COND{pred, ...} => pred := nd
443                  | COM{pred, ...} => pred := nd                  | COM{pred, ...} => pred := nd
444                  | ASSIGN{pred, ...} => pred := nd                  | ASSIGN{pred, ...} => pred := nd
# Line 451  Line 453 
453                  | ENTRY _ => []                  | ENTRY _ => []
454                  | JOIN{preds, ...} => !preds                  | JOIN{preds, ...} => !preds
455                  | COND{pred, ...} => [!pred]                  | COND{pred, ...} => [!pred]
456                  | FOREACH{preds, ...} => !preds                  | FOREACH{pred, bodyExit, ...} => [!pred, !bodyExit]
457                  | COM{pred, ...} => [!pred]                  | COM{pred, ...} => [!pred]
458                  | ASSIGN{pred, ...} => [!pred]                  | ASSIGN{pred, ...} => [!pred]
459                  | MASSIGN{pred, ...} => [!pred]                  | MASSIGN{pred, ...} => [!pred]
# Line 494  Line 496 
496                  | ENTRY{succ} => [!succ]                  | ENTRY{succ} => [!succ]
497                  | JOIN{succ, ...} => [!succ]                  | JOIN{succ, ...} => [!succ]
498                  | COND{trueBranch, falseBranch, ...} => [!trueBranch, !falseBranch]                  | COND{trueBranch, falseBranch, ...} => [!trueBranch, !falseBranch]
499                  | FOREACH{body, succ, ...} => [!body, !succ]                  | FOREACH{bodyEntry, succ, ...} => [!bodyEntry, !succ]
500                  | COM{succ, ...} => [!succ]                  | COM{succ, ...} => [!succ]
501                  | ASSIGN{succ, ...} => [!succ]                  | ASSIGN{succ, ...} => [!succ]
502                  | MASSIGN{succ, ...} => [!succ]                  | MASSIGN{succ, ...} => [!succ]
# Line 509  Line 511 
511            | setTrueBranch (nd, _) = raise Fail("setTrueBranch on " ^ toString nd)            | setTrueBranch (nd, _) = raise Fail("setTrueBranch on " ^ toString nd)
512          fun setFalseBranch (ND{kind=COND{falseBranch, ...}, ...}, nd) = falseBranch := nd          fun setFalseBranch (ND{kind=COND{falseBranch, ...}, ...}, nd) = falseBranch := nd
513            | setFalseBranch (nd, _) = raise Fail("setFalseBranch on " ^ toString nd)            | setFalseBranch (nd, _) = raise Fail("setFalseBranch on " ^ toString nd)
514          fun setBodyBranch (ND{kind=FOREACH{body, ...}, ...}, nd) = body := nd          fun setBodyEntry (ND{kind=FOREACH{bodyEntry, ...}, ...}, nd) = bodyEntry := nd
515            | setBodyBranch (nd, _) = raise Fail("setBodyBranch on " ^ toString nd)            | setBodyEntry (nd, _) = raise Fail("setBodyEntry on " ^ toString nd)
516            fun setBodyExit (ND{kind=FOREACH{bodyExit, ...}, ...}, nd) = bodyExit := nd
517              | setBodyExit (nd, _) = raise Fail("setBodyExit on " ^ toString nd)
518          fun setEdgeMask (ND{kind=JOIN{mask, ...}, ...}, mask') = mask := mask'          fun setEdgeMask (ND{kind=JOIN{mask, ...}, ...}, mask') = mask := mask'
519            | setEdgeMask (nd, _) = raise Fail("setEdgeMask on " ^ toString nd)            | setEdgeMask (nd, _) = raise Fail("setEdgeMask on " ^ toString nd)
520          fun addEdge (nd1, nd2) = (          fun addEdge (nd1, nd2) = (
# Line 522  Line 526 
526  (*DEBUG*)handle ex => (  (*DEBUG*)handle ex => (
527  print(concat["error in addEdge(", toString nd1, ",", toString nd2, ")\n"]);  print(concat["error in addEdge(", toString nd1, ",", toString nd2, ")\n"]);
528  raise ex)  raise ex)
529          (* replace the edge src-->oldDst by the edge src-->dst *)
530          fun replaceInEdge {src, oldDst, dst} = (          fun replaceInEdge {src, oldDst, dst} = (
531              (* first set the successor of src *)              (* first set the successor of src *)
532                case kind src                case kind src
# Line 529  Line 534 
534                      if same(!trueBranch, oldDst)                      if same(!trueBranch, oldDst)
535                        then trueBranch := dst                        then trueBranch := dst
536                        else falseBranch := dst                        else falseBranch := dst
537                    | FOREACH{bodyEntry, succ, ...} =>
538                        if same(!bodyEntry, oldDst)
539                          then bodyEntry := dst
540                          else succ := dst
541                  | _ => setSucc (src, dst)                  | _ => setSucc (src, dst)
542                (* end case *);                (* end case *);
543              (* then set the predecessor of dst *)              (* then set the predecessor of dst *)
# Line 536  Line 545 
545  (*DEBUG*)handle ex => (  (*DEBUG*)handle ex => (
546  print(concat["error in replaceInEdge(", toString src, ",", toString oldDst, ",", toString dst, ")\n"]);  print(concat["error in replaceInEdge(", toString src, ",", toString oldDst, ",", toString dst, ")\n"]);
547  raise ex)  raise ex)
548          (* replace the edge oldSrc-->dst by the edge src-->dst *)
549          fun replaceOutEdge {oldSrc, src, dst} = (          fun replaceOutEdge {oldSrc, src, dst} = (
550              (* first set the successor of src *)              (* first set the successor of src *)
551                case kind oldSrc                case kind oldSrc
# Line 543  Line 553 
553                      if same(!trueBranch, dst)                      if same(!trueBranch, dst)
554                        then setTrueBranch (src, dst)                        then setTrueBranch (src, dst)
555                        else setFalseBranch (src, dst)                        else setFalseBranch (src, dst)
556                    | FOREACH{bodyEntry, succ, ...} =>
557                        if same(!bodyEntry, dst)
558                          then setBodyEntry (src, dst)
559                          else setSucc (src, dst)
560                  | _ => setSucc (src, dst)                  | _ => setSucc (src, dst)
561                (* end case *);                (* end case *);
562              (* then set the predecessor of dst *)              (* then set the predecessor of dst *)
# Line 553  Line 567 
567                      in                      in
568                        preds := edit (!preds)                        preds := edit (!preds)
569                      end                      end
570                    | FOREACH{bodyExit, pred, ...} =>
571                        if same(!bodyExit, oldSrc)
572                          then bodyExit := src
573                          else pred := src
574                  | _ => setPred (dst, src)                  | _ => setPred (dst, src)
575                (* end case *))                (* end case *))
576  (*DEBUG*)handle ex => (  (*DEBUG*)handle ex => (

Legend:
Removed from v.3501  
changed lines
  Added in v.3502

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