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

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

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