SCM Repository
Annotation of /trunk/src/compiler/IL/ssa-fn.sml
Parent Directory
|
Revision Log
Revision 192 - (view) (download)
1 : | jhr | 137 | (* ssa-fn.sml |
2 : | jhr | 124 | * |
3 : | * COPYRIGHT (c) 2010 The Diderot Project (http://diderot.cs.uchicago.edu) | ||
4 : | * All rights reserved. | ||
5 : | jhr | 137 | * |
6 : | * The IL is a combination of a block-structured tree and an SSA control-flow | ||
7 : | * graph of blocks. | ||
8 : | jhr | 124 | *) |
9 : | |||
10 : | jhr | 192 | functor SSAFn (Op : OPERATORS) (*: SSA*) = |
11 : | struct | ||
12 : | jhr | 137 | |
13 : | jhr | 192 | structure Op = Op |
14 : | jhr | 137 | |
15 : | jhr | 192 | datatype stmt = STM of { |
16 : | jhr | 188 | id : Stamp.stamp, |
17 : | props : PropList.holder, | ||
18 : | jhr | 192 | preds : stmt list ref, |
19 : | phis : (var * var list) list ref, (* phi statements *) | ||
20 : | kind : stmt_kind ref | ||
21 : | jhr | 188 | } |
22 : | |||
23 : | jhr | 192 | and stmt_kind |
24 : | = BLOCK of { | ||
25 : | succ : stmt, | ||
26 : | body : assign list | ||
27 : | } | ||
28 : | | IF of { | ||
29 : | cond : var, | ||
30 : | thenBranch : stmt, | ||
31 : | elseBranch : stmt | ||
32 : | } | ||
33 : | | LOOP of { | ||
34 : | hdr : stmt, | ||
35 : | cond : var, | ||
36 : | body : stmt, | ||
37 : | exit : stmt | ||
38 : | } | ||
39 : | | NEW of { | ||
40 : | actor : Atom.atom, | ||
41 : | args : var list, | ||
42 : | succ : stmt | ||
43 : | } | ||
44 : | | DIE | ||
45 : | | STABILIZE | ||
46 : | | EXIT | ||
47 : | |||
48 : | jhr | 188 | and rhs |
49 : | = VAR of var | ||
50 : | | LIT of Literal.literal | ||
51 : | | OP of Op.rator * var list | ||
52 : | | CONS of var list (* tensor-value construction *) | ||
53 : | |||
54 : | jhr | 192 | and var = V of { |
55 : | jhr | 137 | name : string, (* name *) |
56 : | id : Stamp.stamp, (* unique ID *) | ||
57 : | useCnt : int ref, (* count of uses *) | ||
58 : | props : PropList.holder | ||
59 : | jhr | 124 | } |
60 : | |||
61 : | jhr | 192 | withtype assign = (var * rhs) |
62 : | jhr | 188 | |
63 : | jhr | 192 | fun same (STM{id=a, ...}, STM{id=b, ...}) = Stamp.same(a, b) |
64 : | fun compare (STM{id=a, ...}, STM{id=b, ...}) = Stamp.compare(a, b) | ||
65 : | fun hash (STM{id, ...}) = Stamp.hash id | ||
66 : | jhr | 188 | |
67 : | jhr | 192 | fun succs (STM{kind, ...}) = (case !kind |
68 : | of BLOCK{succ, ...} => [succ] | ||
69 : | | IF{thenBranch, elseBranch, ...} => [thenBranch, elseBranch] | ||
70 : | | LOOP{exit, ...} => [exit] | ||
71 : | | NEW{succ, ...} => [succ] | ||
72 : | | _ => [] | ||
73 : | (* end case *)) | ||
74 : | jhr | 188 | |
75 : | jhr | 192 | (* set the successor of a statement *) |
76 : | fun setSucc (STM{kind, ...}, stm) = (case !kind | ||
77 : | of BLOCK{succ, body} => kind := BLOCK{succ=stm, body=body} | ||
78 : | | IF{thenBranch, elseBranch, ...} => ( | ||
79 : | setSucc(thenBranch, stm); | ||
80 : | setSucc(elseBranch, stm)) | ||
81 : | | LOOP{hdr, cond, body, exit} => kind := LOOP{hdr=hdr, cond=cond, body=body, exit=stm} | ||
82 : | | NEW{actor, args, succ} => kind := NEW{actor=actor, args=args, succ=stm} | ||
83 : | | _ => () (* no successor *) | ||
84 : | (* end case *)) | ||
85 : | jhr | 188 | |
86 : | jhr | 192 | fun preds (STM{preds, ...}) = !preds |
87 : | jhr | 124 | |
88 : | jhr | 192 | fun addPred (STM{preds, ...}, stm) = |
89 : | if not(List.exists (fn b => same(stm, b)) (!preds)) | ||
90 : | then preds := stm :: !preds | ||
91 : | else (); | ||
92 : | jhr | 137 | |
93 : | jhr | 192 | fun mkSTM kind = STM{ |
94 : | jhr | 137 | id = Stamp.new(), |
95 : | jhr | 188 | props = PropList.newHolder(), |
96 : | jhr | 192 | preds = ref [], |
97 : | phis = ref [], | ||
98 : | kind = ref kind | ||
99 : | jhr | 137 | } |
100 : | |||
101 : | jhr | 192 | val dummy = mkSTM EXIT |
102 : | jhr | 137 | |
103 : | jhr | 192 | fun mkBLOCK args = mkSTM(BLOCK args) |
104 : | fun mkIF args = mkSTM(IF args) | ||
105 : | fun mkLOOP args = mkSTM(LOOP args) | ||
106 : | fun mkDIE () = mkSTM DIE | ||
107 : | fun mkSTABILIZE () = mkSTM STABILIZE | ||
108 : | fun mkEXIT () = mkSTM EXIT | ||
109 : | jhr | 137 | |
110 : | jhr | 124 | end |
root@smlnj-gforge.cs.uchicago.edu | ViewVC Help |
Powered by ViewVC 1.0.0 |