Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Diff of /sml/trunk/src/MLRISC/mltree/mltree.sml
ViewVC logotype

Diff of /sml/trunk/src/MLRISC/mltree/mltree.sml

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

revision 476, Wed Nov 10 22:59:58 1999 UTC revision 591, Mon Apr 3 01:19:20 2000 UTC
# Line 4  Line 4 
4   *   *
5   *)   *)
6    
7  functor MLTreeF(structure Const : CONSTANT  functor MLTreeF(structure LabelExp  : LABELEXP
8                  structure R : REGION                  structure Region    : REGION
9                  structure S : INSTRUCTION_STREAM                  structure Stream    : INSTRUCTION_STREAM
10                  type rextension                  structure Extension : MLTREE_EXTENSION
                 type fextension  
11                 ) : MLTREE =                 ) : MLTREE =
12  struct  struct
13    structure Constant = Const    structure LabelExp = LabelExp
14    structure PseudoOp = S.P    structure Constant = LabelExp.Constant
15    structure Stream = S    structure PseudoOp = Stream.P
16    structure Region = R    structure Stream = Stream
17      structure Region = Region
18    structure Basis  = MLTreeBasis    structure Basis  = MLTreeBasis
19    structure Util   = MLTreeUtil    structure Extension = Extension
   
   type rextension = rextension  
   type fextension = rextension  
20    
21    type ty  = Basis.ty    type ty  = Basis.ty
22    type fty = Basis.fty    type fty = Basis.fty
# Line 27  Line 24 
24    type src = var (* source variable *)    type src = var (* source variable *)
25    type dst = var (* destination variable *)    type dst = var (* destination variable *)
26    type reg = var (* physical register *)    type reg = var (* physical register *)
27      type an = Annotations.annotation
28    
29    datatype cond = datatype Basis.cond    datatype cond = datatype Basis.cond
30    datatype fcond = datatype Basis.fcond    datatype fcond = datatype Basis.fcond
   datatype ext = datatype Basis.ext  
31    datatype rounding_mode = datatype Basis.rounding_mode    datatype rounding_mode = datatype Basis.rounding_mode
32      datatype ext = datatype Basis.ext
33    
34    (* phi-functions for SSA form *)    (* phi-functions for SSA form *)
35    datatype phi =    datatype phi =
36        PHI  of ty * dst * src list        RPHI  of ty * dst * src list
37      | FPHI of fty * dst * src list      | FPHI of fty * dst * src list
38      | CCPHI of dst * src list      | CCPHI of dst * src list
39    
40    (* aliasing declarations    (* aliasing declarations
41     * These are used to define physical register bindings for SSA names     * These are used to define physical register bindings for SSA names
42     *)     *)
43    type alias = var * reg    type alias = var * reg (* var is aliased to register *)
44    
45    (* statements *)    (* Statements/effects.  These types are parameterized by the statement
46       * extension type.  Unfortunately, this has to be made polymorphic to make
47       * it possible for recursive type definitions to work.
48       *
49       * Terms marked with rtl are used within the rtl language
50       *)
51    datatype stm =    datatype stm =
52        MV      of ty * dst * rexp        (* assignment *)
53          MV      of ty * dst * rexp   (* rtl *)
54      | CCMV    of dst * ccexp      | CCMV    of dst * ccexp
55      | FMV     of fty * dst * fexp      | FMV     of fty * dst * fexp
56      | COPY    of ty * dst list * src list  
57          (* parallel copies *)
58        | COPY    of ty * dst list * src list   (* rtl *)
59      | FCOPY   of fty * dst list * src list      | FCOPY   of fty * dst list * src list
60      | JMP     of rexp * Label.label list  
61      | CALL    of rexp * mlrisc list * mlrisc list * Region.region        (* control flow *)
62      | RET      | JMP     of ctrls * rexp * controlflow (* rtl *)
63        | BCC     of ctrls * ccexp * Label.label
64      | STORE  of ty * rexp * rexp * Region.region        (* address, data *)      | CALL    of {funct:rexp, targets:controlflow,
65      | STORE_UNALIGNED of ty * rexp * rexp * Region.region                    defs:mlrisc list, uses:mlrisc list,
66      | FSTORE of fty * rexp * fexp * Region.region       (* address, data *)                    cdefs:ctrls, cuses: ctrls, region: Region.region} (* rtl *)
67      | FSTORE_UNALIGNED of fty * rexp * fexp * Region.region      | RET     of ctrls * controlflow (* rtl *)
68      | BCC    of Basis.cond * ccexp * Label.label      | JOIN    of ctrls
69      | FBCC   of Basis.fcond * ccexp * Label.label      | IF      of ctrls * ccexp * stm * stm   (* rtl *)
70      | ANNOTATION of stm * Annotations.annotation  
71          (* memory update: ea, data *)
72        (* The following are used internally by SSA optimizations;      | STORE  of ty * rexp * rexp * Region.region
73         * The frontend should not generate these.      | FSTORE of fty * rexp * fexp * Region.region
74         *)  
75      | RTL of word ref * word * stm (* an RTL *)        (* control dependence *)
76      | RTLPHI of int (* a phi-function at block id *)      | REGION of stm * ctrl
77      | RTLPINNED of stm (* pinned statement *)  
78      | RTLPAR of stm list (* parallel execution *)      | SEQ    of stm list   (* sequencing *)
79        | DEFINE of Label.label   (* define local label *)
80    
81        | ANNOTATION of stm * an
82        | EXT of sext  (* extension *)
83    
84          (* RTL operators:
85           * The following are used internally for describing instruction semantics.
86           * The frontend must not use these.
87           *)
88        | PHI    of int                    (* a phi-function at some block id *)
89        | PINNED of stm      (* pinned statement *)
90        | RTL    of {hash:word ref, attribs:Basis.attribs, e:stm}
91    
92    and rexp =    and rexp =
93        REG    of ty * src        REG    of ty * reg            (* rtl *)
94    
95        (* sizes of constants are inferred by context *)        (* sizes of constants are inferred by context *)
96      | LI     of int      | LI     of int                 (* rtl *)
97      | LI32   of Word32.word      | LI32   of Word32.word         (* rtl *)
98      | LI64   of Word64.word      | LI64   of Word64.word         (* rtl *)
99      | LABEL  of LabelExp.labexp      | LABEL  of LabelExp.labexp
100      | CONST  of Constant.const      | CONST  of Constant.const
101    
102      | ADD    of ty * rexp * rexp      | NEG    of ty * rexp
103      | SUB    of ty * rexp * rexp      | ADD    of ty * rexp * rexp    (* rtl *)
104        | SUB    of ty * rexp * rexp    (* rtl *)
105    
106        (* signed multiplication etc. *)        (* signed multiplication etc. *)
107      | MULS   of ty * rexp * rexp      | MULS   of ty * rexp * rexp    (* rtl *)
108      | DIVS   of ty * rexp * rexp      | DIVS   of ty * rexp * rexp    (* rtl *)
109      | REMS   of ty * rexp * rexp      | QUOTS  of ty * rexp * rexp    (* rtl *)
110        | REMS   of ty * rexp * rexp    (* rtl *)
111    
112        (* unsigned multiplication etc. *)        (* unsigned multiplication etc. *)
113      | MULU   of ty * rexp * rexp      | MULU   of ty * rexp * rexp    (* rtl *)
114      | DIVU   of ty * rexp * rexp      | DIVU   of ty * rexp * rexp    (* rtl *)
115      | REMU   of ty * rexp * rexp      | REMU   of ty * rexp * rexp    (* rtl *)
116    
117        (* trapping versions of above. These are all signed *)        (* trapping versions of above. These are all signed *)
118      | ADDT   of ty * rexp * rexp      | NEGT   of ty * rexp
119      | SUBT   of ty * rexp * rexp      | ADDT   of ty * rexp * rexp    (* rtl *)
120      | MULT   of ty * rexp * rexp      | SUBT   of ty * rexp * rexp    (* rtl *)
121      | DIVT   of ty * rexp * rexp      | MULT   of ty * rexp * rexp    (* rtl *)
122      | REMT   of ty * rexp * rexp      | DIVT   of ty * rexp * rexp    (* rtl *)
123        | QUOTT  of ty * rexp * rexp    (* rtl *)
124      | ANDB   of ty * rexp * rexp      | REMT   of ty * rexp * rexp    (* rtl *)
125      | ORB    of ty * rexp * rexp  
126      | XORB   of ty * rexp * rexp        (* bit operations *)
127      | NOTB   of ty * rexp      | ANDB   of ty * rexp * rexp    (* rtl *)
128        | ORB    of ty * rexp * rexp    (* rtl *)
129      | SRA   of ty * rexp * rexp         (* value, shift *)      | XORB   of ty * rexp * rexp    (* rtl *)
130      | SRL   of ty * rexp * rexp      | NOTB   of ty * rexp              (* rtl *)
131      | SLL   of ty * rexp * rexp  
132        | SRA   of ty * rexp * rexp   (* value, shift *) (* rtl *)
133        (* type promotion *)      | SRL   of ty * rexp * rexp     (* rtl *)
134      | CVTI2I of ty * Basis.ext * ty * rexp      | SLL   of ty * rexp * rexp     (* rtl *)
135      | CVTF2I of ty * Basis.rounding_mode * fty * fexp  
136          (* type promotion/conversion *)
137        (* conditional (eager) evaluation *)      | CVTI2I of ty * ext * ty * rexp  (* signed extension *) (* rtl *)
138      | COND of ty * ccexp * rexp * rexp      | CVTF2I of ty * rounding_mode * fty * fexp (* rtl *)
139    
140          (*
141           * COND(ty,cc,e1,e2):
142           * Evaluate into either e1 or e2, depending on cc.
143           * Both e1 and e2 are allowed to be evaluated eagerly.
144           *)
145        | COND of ty * ccexp * rexp * rexp  (* rtl *)
146    
147        (* integer load *)        (* integer load *)
148      | LOAD of ty * rexp * Region.region      | LOAD of ty * rexp * Region.region (* rtl *)
     | LOAD_UNALIGNED of ty * rexp * Region.region  
149    
150      | SEQ of stm * rexp        (* predication *)
151        | PRED of rexp * ctrl
152    
153      | EXT of ty * rextension * rexp list      | LET of stm * rexp
154    
155      | MARK of rexp * Annotations.annotation      | REXT of ty * rext
156    
157        (* Used in RTL *)      | MARK of rexp * an
     | RTLPC (* the program counter; used for describing relative addressing *)  
     | RTLMISC of Basis.misc_op ref * rexp list  
158    
159    and fexp =    and fexp =
160        FREG   of fty * src        FREG   of fty * src
161      | FLOAD  of fty * rexp * Region.region      | FLOAD  of fty * rexp * Region.region
     | FLOAD_UNALIGNED  of fty * rexp * Region.region  
162    
163      | FADD   of fty * fexp * fexp      | FADD   of fty * fexp * fexp
164      | FMUL   of fty * fexp * fexp      | FMUL   of fty * fexp * fexp
# Line 143  Line 167 
167      | FABS   of fty * fexp      | FABS   of fty * fexp
168      | FNEG   of fty * fexp      | FNEG   of fty * fexp
169      | FSQRT  of fty * fexp      | FSQRT  of fty * fexp
170        | FCOND  of fty * ccexp *
171                    fexp * fexp
172        | FCOPYSIGN of fty * fexp (*sign*) * fexp (*magnitude*)
173    
174      | CVTI2F of fty * Basis.ext * ty * rexp      | CVTI2F of fty * ty * rexp  (* from signed integer *)
175      | CVTF2F of fty * Basis.rounding_mode * fty * fexp      | CVTF2F of fty * fty * fexp (* float to float conversion *)
     | FSEQ   of stm * fexp  
176    
177      | FEXT of fty * fextension * fexp list      | FPRED of fexp * ctrl
178    
179      | FMARK of fexp * Annotations.annotation      | FEXT of fty * fext
180    
181        (* used in RTL *)      | FMARK of fexp * an
     | RTLFMISC of Basis.misc_op ref * fexp list  
182    
183    and ccexp =    and ccexp =
184        CC     of src        CC     of Basis.cond * src                        (* rtl *)
185      | CMP    of ty * Basis.cond * rexp * rexp      | FCC    of Basis.fcond * src                       (* rtl *)
186        | TRUE                                              (* rtl *)
187        | FALSE                                             (* rtl *)
188        | NOT    of ccexp                     (* rtl *)
189        | AND    of ccexp * ccexp   (* rtl *)
190        | OR     of ccexp * ccexp   (* rtl *)
191        | XOR    of ccexp * ccexp   (* rtl *)
192        | CMP    of ty * Basis.cond * rexp * rexp(*rtl*)
193      | FCMP   of fty * Basis.fcond * fexp * fexp      | FCMP   of fty * Basis.fcond * fexp * fexp
194      | CCMARK of ccexp * Annotations.annotation      | CCMARK of ccexp * an
195      | RTLCCMISC of Basis.misc_op ref * ccexp list      | CCEXT  of ty * ccext
196    
197    and mlrisc = CCR of ccexp | GPR of rexp | FPR of fexp    and mlrisc =
198          CCR of ccexp
199        | GPR of rexp
200        | FPR of fexp
201    
202      withtype controlflow = Label.label list (* control flow info *)
203           and ctrl   = var                   (* control dependence info *)
204           and ctrls  = ctrl list
205           and sext   = (stm, rexp, fexp, ccexp) Extension.sx
206           and rext   = (stm, rexp, fexp, ccexp) Extension.rx
207           and fext   = (stm, rexp, fexp, ccexp) Extension.fx
208           and ccext  = (stm, rexp, fexp, ccexp) Extension.ccx
209    
210    exception Unsupported of string * rexp    (*
211       * Instruction streams
212       *)
213      type ('i,'regmap,'cellset) stream =
214           ('i -> unit,'regmap, an list, 'cellset, alias, phi) Stream.stream
215    
216    type ('i,'regmap) stream =    (*
217         ('i -> unit,'regmap,Annotations.annotations,     * Extension mechanism
218          mlrisc list, alias, phi) Stream.stream     *)
219    
220      datatype ('instr,'regmap,'cellset,'operand,'addressing_mode) reducer =
221        REDUCER of
222        { reduceRexp    : rexp -> reg,
223          reduceFexp    : fexp -> reg,
224          reduceCCexp   : ccexp -> reg,
225          reduceStm     : stm * an list -> unit,
226          operand       : rexp -> 'operand,
227          reduceOperand : 'operand -> reg,
228          addressOf     : rexp -> 'addressing_mode,
229          emit          : 'instr * an list -> unit,
230          instrStream   : ('instr,'regmap,'cellset) stream,
231          mltreeStream  : (stm,'regmap,mlrisc list) stream
232        }
233    
234      (*
235       * Useful type abbreviations for working for MLTree.
236       *)
237      type rewriter =  (* rewriting functions *)
238        {stm:stm->stm, rexp:rexp->rexp, fexp:fexp->fexp, ccexp:ccexp->ccexp}
239      type 'a folder = (* aggregation functions *)
240        {stm:stm*'a->'a, rexp:rexp*'a->'a, fexp:fexp*'a->'a, ccexp:ccexp*'a->'a}
241      type hasher =    (* hashing functions *)
242        {stm:stm->word, rexp:rexp->word, fexp:fexp->word, ccexp:ccexp->word}
243      type equality =  (* comparison functions *)
244        {stm:stm * stm->bool, rexp:rexp * rexp->bool,
245         fexp:fexp * fexp->bool, ccexp:ccexp * ccexp->bool}
246      type printer =   (* pretty printing functions *)
247        {stm:stm->string, rexp:rexp->string, fexp:fexp->string, ccexp:ccexp->string,
248         dstReg : ty * var -> string, srcReg : ty * var -> string}
249    
250  end (* MLTREE *)  end (* MLTREE *)

Legend:
Removed from v.476  
changed lines
  Added in v.591

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