Debian Codegraph @

lib/mlrisc-lib/MLRISC/mltree/mltree.sml

raw
1 (* mltree.sml
2 *
3 * COPYRIGHT (c) 1994 AT&T Bell Laboratories.
4 *
5 *)
6 functor MLTreeF(structure Constant : CONSTANT
7 structure Region : REGION
8 structure Extension : MLTREE_EXTENSION
9 ) : MLTREE =
10 struct
11 structure Constant = Constant
12 structure Region = Region
13 structure Basis = MLTreeBasis
14 structure Extension = Extension
15 structure I = MachineInt
16
17 type ty = Basis.ty
18 type fty = Basis.fty
19 type var = CellsBasis.cell (* variable *)
20 type src = var (* source variable *)
21 type dst = var (* destination variable *)
22 type reg = var (* physical register *)
23 type an = Annotations.annotation
24
25 datatype cond = datatype Basis.cond
26 datatype fcond = datatype Basis.fcond
27 datatype rounding_mode = datatype Basis.rounding_mode
28 datatype div_rounding_mode = datatype Basis.div_rounding_mode
29 datatype ext = datatype Basis.ext
30
31 (* Statements/effects. These types are parameterized by the statement
32 * extension type. Unfortunately, this has to be made polymorphic to make
33 * it possible for recursive type definitions to work.
34 *)
35 type controlflow = Label.label list (* control flow info *)
36 type ctrl = var (* control dependence info *)
37 type ctrls = ctrl list
38
39 datatype stm =
40 (* assignment *)
41 MV of ty * dst * rexp
42 | CCMV of dst * ccexp
43 | FMV of fty * dst * fexp
44
45 (* parallel copies *)
46 | COPY of ty * dst list * src list
47 | FCOPY of fty * dst list * src list
48
49 (* Control flow *)
50 | JMP of rexp * controlflow
51 | BCC of ccexp * Label.label
52 | CALL of {funct:rexp, targets:controlflow,
53 defs:mlrisc list, uses:mlrisc list,
54 region: Region.region, pops: Int32.int}
55 | FLOW_TO of stm * controlflow
56 | RET of controlflow
57 | IF of ccexp * stm * stm
58
59 (* memory update: ea, data *)
60 | STORE of ty * rexp * rexp * Region.region
61 | FSTORE of fty * rexp * fexp * Region.region
62
63 (* control dependence *)
64 | REGION of stm * ctrl
65
66 | SEQ of stm list (* sequencing *)
67 | DEFINE of Label.label (* define local label *)
68
69 | ANNOTATION of stm * an
70 | EXT of sext (* extension *)
71
72 | LIVE of mlrisc list
73 | KILL of mlrisc list
74
75 (* RTL operators:
76 * The following are used internally
77 * for describing instruction semantics.
78 * The frontend must not use these.
79 *)
80 | PHI of {preds:int list,block:int}
81 | ASSIGN of ty * rexp * rexp
82 | SOURCE
83 | SINK
84 | RTL of {hash:word, attribs:Basis.attribs ref, e:stm}
85
86 and rexp =
87 REG of ty * reg
88
89 (* sizes of constants are inferred by context *)
90 | LI of I.machine_int
91 | LABEL of Label.label
92 | CONST of Constant.const
93 | LABEXP of rexp
94
95 | NEG of ty * rexp
96 | ADD of ty * rexp * rexp
97 | SUB of ty * rexp * rexp
98
99 (* signed multiplication etc. *)
100 | MULS of ty * rexp * rexp
101 | DIVS of div_rounding_mode * ty * rexp * rexp
102 | REMS of div_rounding_mode * ty * rexp * rexp
103
104 (* unsigned multiplication etc. *)
105 | MULU of ty * rexp * rexp
106 | DIVU of ty * rexp * rexp
107 | REMU of ty * rexp * rexp
108
109 (* overflow-trapping versions of above. These are all signed *)
110 | NEGT of ty * rexp
111 | ADDT of ty * rexp * rexp
112 | SUBT of ty * rexp * rexp
113 | MULT of ty * rexp * rexp
114 | DIVT of div_rounding_mode * ty * rexp * rexp
115
116 (* bit operations *)
117 | ANDB of ty * rexp * rexp
118 | ORB of ty * rexp * rexp
119 | XORB of ty * rexp * rexp
120 | EQVB of ty * rexp * rexp
121 | NOTB of ty * rexp
122
123 | SRA of ty * rexp * rexp (* value, shift *)
124 | SRL of ty * rexp * rexp
125 | SLL of ty * rexp * rexp
126
127 (* type promotion/conversion *)
128 | SX of ty * ty * rexp (* toTy, fromTy *)
129 | ZX of ty * ty * rexp (* toTy, fromTy *)
130 | CVTF2I of ty * rounding_mode * fty * fexp
131
132 (*
133 * COND(ty,cc,e1,e2):
134 * Evaluate into either e1 or e2, depending on cc.
135 * Both e1 and e2 are allowed to be evaluated eagerly.
136 *)
137 | COND of ty * ccexp * rexp * rexp
138
139 (* integer load *)
140 | LOAD of ty * rexp * Region.region
141
142 (* predication *)
143 | PRED of rexp * ctrl
144
145 | LET of stm * rexp
146
147 | REXT of ty * rext
148
149 | MARK of rexp * an
150
151 | OP of ty * oper * rexp list
152 | ARG of ty * rep ref * string
153 | $ of ty * CellsBasis.cellkind * rexp
154 | PARAM of int
155 | BITSLICE of ty * (int * int) list * rexp
156 | ???
157
158 and rep = REP of string
159
160 and oper = OPER of Basis.misc_op
161
162 and fexp =
163 FREG of fty * src
164 | FLOAD of fty * rexp * Region.region
165
166 | FADD of fty * fexp * fexp
167 | FMUL of fty * fexp * fexp
168 | FSUB of fty * fexp * fexp
169 | FDIV of fty * fexp * fexp
170 | FABS of fty * fexp
171 | FNEG of fty * fexp
172 | FSQRT of fty * fexp
173 | FCOND of fty * ccexp *
174 fexp * fexp
175 | FCOPYSIGN of fty * fexp (*sign*) * fexp (*magnitude*)
176
177 | CVTI2F of fty * ty * rexp (* from signed integer *)
178 | CVTF2F of fty * fty * fexp (* float to float conversion *)
179
180 | FPRED of fexp * ctrl
181
182 | FEXT of fty * fext
183
184 | FMARK of fexp * an
185
186 and ccexp =
187 CC of Basis.cond * src
188 | FCC of Basis.fcond * src
189 | TRUE
190 | FALSE
191 | NOT of ccexp
192 | AND of ccexp * ccexp
193 | OR of ccexp * ccexp
194 | XOR of ccexp * ccexp
195 | EQV of ccexp * ccexp
196 | CMP of ty * Basis.cond * rexp * rexp
197 | FCMP of fty * Basis.fcond * fexp * fexp
198 | CCMARK of ccexp * an
199 | CCEXT of ty * ccext
200
201 and mlrisc =
202 CCR of ccexp
203 | GPR of rexp
204 | FPR of fexp
205
206 withtype sext = (stm, rexp, fexp, ccexp) Extension.sx
207 and rext = (stm, rexp, fexp, ccexp) Extension.rx
208 and fext = (stm, rexp, fexp, ccexp) Extension.fx
209 and ccext = (stm, rexp, fexp, ccexp) Extension.ccx
210 and labexp = rexp
211
212 (*
213 * Useful type abbreviations for working for MLTree.
214 *)
215 type rewriter = (* rewriting functions *)
216 {stm:stm->stm, rexp:rexp->rexp, fexp:fexp->fexp, ccexp:ccexp->ccexp}
217 type 'a folder = (* aggregation functions *)
218 {stm:stm*'a->'a, rexp:rexp*'a->'a, fexp:fexp*'a->'a, ccexp:ccexp*'a->'a}
219 type hasher = (* hashing functions *)
220 {stm:stm->word, rexp:rexp->word, fexp:fexp->word, ccexp:ccexp->word}
221 type equality = (* comparison functions *)
222 {stm:stm * stm->bool, rexp:rexp * rexp->bool,
223 fexp:fexp * fexp->bool, ccexp:ccexp * ccexp->bool}
224 type printer = (* pretty printing functions *)
225 {stm:stm->string, rexp:rexp->string, fexp:fexp->string, ccexp:ccexp->string,
226 dstReg : ty * var -> string, srcReg : ty * var -> string}
227
228 end (* MLTREE *)
229