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

SCM Repository

[smlnj] Annotation of /sml/branches/idlbasis-devel/src/MLRISC/alpha/ra/alphaRewrite.sml
ViewVC logotype

Annotation of /sml/branches/idlbasis-devel/src/MLRISC/alpha/ra/alphaRewrite.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1002 - (view) (download)

1 : monnier 409 (* alphaRewrite.sml -- rewrite an alpha instruction
2 :     *
3 :     * COPYRIGHT (c) 1997 Bell Labs
4 :     *)
5 :    
6 :     functor AlphaRewrite(Instr : ALPHAINSTR) = struct
7 :     structure I=Instr
8 : leunga 657 structure C=I.C
9 : blume 1002 structure CB=CellsBasis
10 :     structure CS=CB.CellSet
11 : monnier 409
12 : leunga 744 fun rewriteUse(instr, rs, rt) = let
13 : blume 1002 fun match r = CB.sameColor(r,rs)
14 : leunga 744 fun isRegOp (I.REGop r) = match r
15 : monnier 409 | isRegOp _ = false
16 : leunga 744 fun rwOperand(opnd as I.REGop r) =
17 :     if match r then I.REGop rt else opnd
18 : monnier 409 | rwOperand opnd = opnd
19 : leunga 744 fun replace r = if match r then rt else r
20 : monnier 409 fun load(ldClass, {ldOp, r, b, d, mem}) =
21 : leunga 744 if match b
22 :     then ldClass{ldOp=ldOp, r=r, b=rt, d=d, mem=mem}
23 : monnier 409 else instr
24 :     fun fstore(stClass, {stOp, r, b, d, mem}) =
25 : leunga 744 if match b then stClass{stOp=stOp, r=r, b=rt, d=d, mem=mem}
26 : monnier 409 else instr
27 :     fun store{stOp, r, b, d, mem} =
28 : leunga 744 if match r then
29 :     if match b then
30 : monnier 409 I.STORE{stOp=stOp, r=rt, b=rt, d=d, mem=mem}
31 :     else
32 :     I.STORE{stOp=stOp, r=rt, b=b, d=d, mem=mem}
33 : leunga 744 else if match b then
34 : monnier 409 I.STORE{stOp=stOp, r=r, b=rt, d=d, mem=mem}
35 :     else instr
36 :     fun operate(opClass, {oper, ra, rb, rc}) =
37 : leunga 744 if match ra then
38 : monnier 409 if isRegOp rb then
39 :     opClass{oper=oper, ra=rt, rb=I.REGop rt, rc=rc}
40 :     else opClass{oper=oper, ra=rt, rb=rb, rc=rc}
41 :     else if isRegOp rb then
42 :     opClass{oper=oper, ra=ra, rb=I.REGop rt, rc=rc}
43 :     else instr
44 :    
45 :     in
46 :     case instr
47 : leunga 744 of I.LDA{r, b, d} => if match b then I.LDA{r=r, b=rt, d=d} else instr
48 :     | I.LDAH{r, b, d} => if match b then I.LDAH{r=r, b=rt, d=d} else instr
49 : monnier 409 | I.LOAD arg => load(I.LOAD, arg)
50 :     | I.FLOAD farg => load(I.FLOAD, farg)
51 :     | I.STORE arg => store arg
52 :     | I.FSTORE farg => fstore(I.FSTORE, farg)
53 :     | I.JMPL({r, b, d}, labs) =>
54 : leunga 744 if match b then I.JMPL({r=r, b=rt, d=d}, labs) else instr
55 : blume 859 | I.JSR{r, b, d, defs, uses, cutsTo, mem} =>
56 : leunga 744 I.JSR{r=r, b=replace b, d=d, defs=defs,
57 : blume 1002 uses=CS.map {from=rs,to=rt} uses, cutsTo=cutsTo, mem=mem}
58 : blume 859 | I.BSR{r, lab, defs, uses, cutsTo, mem} =>
59 : leunga 744 I.BSR{r=r, lab=lab, defs=defs,
60 : blume 1002 uses=CS.map {from=rs,to=rt} uses, cutsTo=cutsTo, mem=mem}
61 : monnier 409 | I.RET{r,b,d} => I.RET{r=r, b=replace b, d=d}
62 : george 545 | I.BRANCH{b=I.BR, ...} => instr
63 : leunga 744 | I.BRANCH{b, r, lab} => if match r then I.BRANCH{b=b, r=rt, lab=lab}
64 : george 545 else instr
65 : monnier 409 | I.OPERATE arg => operate(I.OPERATE, arg)
66 :     | I.OPERATEV arg => operate(I.OPERATEV, arg)
67 :     | I.CMOVE{oper,ra,rb,rc} =>
68 :     I.CMOVE{oper=oper,ra=replace ra,rb=rwOperand rb,rc=replace rc}
69 :     | I.COPY{dst, src, tmp, impl} =>
70 :     I.COPY{dst=dst, src=map replace src, tmp=tmp, impl=impl}
71 :     | I.CALL_PAL{code, def, use } =>
72 : blume 1002 I.CALL_PAL{code=code, def=def, use=CS.map {from=rs,to=rt} use}
73 : leunga 628 | I.PSEUDOARITH{oper, ra, rb, rc, tmps} =>
74 :     I.PSEUDOARITH{oper=oper, ra=replace ra, rb=rwOperand rb, rc=rc,
75 :     tmps=tmps}
76 : leunga 657 | I.ANNOTATION{i,a} =>
77 : leunga 744 I.ANNOTATION{i=rewriteUse(i,rs,rt),
78 : leunga 657 a=case a of
79 : blume 1002 CB.DEF_USE{cellkind=CB.GP,defs,uses} =>
80 :     CB.DEF_USE{cellkind=CB.GP,defs=defs,
81 : leunga 657 uses=map replace uses}
82 :     | _ => a}
83 : monnier 409 | _ => instr
84 :     end
85 :    
86 : leunga 744 fun frewriteUse(instr, fs, ft) = let
87 : blume 1002 fun match f = CB.sameColor(f,fs)
88 : leunga 744 fun replace f = if match f then ft else f
89 : monnier 409 fun foperate(opClass, {oper, fa, fb, fc}) =
90 : leunga 744 if match fa then
91 : monnier 409 opClass{oper=oper, fa=ft, fc=fc, fb=replace fb}
92 : leunga 744 else if match fb then opClass{oper=oper, fa=fa, fb=ft, fc=fc}
93 : monnier 409 else instr
94 :     in
95 :     case instr
96 : george 545 of I.FBRANCH{b, f, lab} =>
97 : leunga 744 if match f then I.FBRANCH{b=b, f=ft, lab=lab} else instr
98 : monnier 409 | I.FCOPY{dst, src, impl, tmp} =>
99 : leunga 744 I.FCOPY{dst=dst, src=map(fn f => if match f then ft else f) src,
100 : monnier 409 tmp=tmp, impl=impl}
101 :     | I.FSTORE{stOp, r, b, d, mem} =>
102 : leunga 744 if match r then I.FSTORE{stOp=stOp, r=ft, b=b, d=d, mem=mem} else instr
103 : monnier 409 | I.FOPERATE arg => foperate(I.FOPERATE, arg)
104 :     | I.FOPERATEV arg => foperate(I.FOPERATEV, arg)
105 :     | I.FUNARY{oper,fb,fc} =>
106 : leunga 744 if match fb then I.FUNARY{oper=oper,fb=ft,fc=fc} else instr
107 : monnier 409 | I.FCMOVE{oper,fa,fb,fc} =>
108 :     I.FCMOVE{oper=oper,fa=replace fa,fb=replace fb,fc=replace fc}
109 : blume 859 | I.JSR{r, b, d, defs, uses, cutsTo, mem} =>
110 : leunga 744 I.JSR{r=r, b=b, d=d, defs=defs,
111 : blume 1002 uses=CS.map {from=fs,to=ft} uses, cutsTo=cutsTo, mem=mem}
112 : blume 859 | I.BSR{r, lab, defs, uses, cutsTo, mem} =>
113 : leunga 744 I.BSR{r=r, lab=lab, defs=defs,
114 : blume 1002 uses=CS.map {from=fs,to=ft} uses, cutsTo=cutsTo, mem=mem}
115 : leunga 657 | I.ANNOTATION{i,a} =>
116 : leunga 744 I.ANNOTATION{i=frewriteUse(i,fs,ft),
117 : leunga 657 a=case a of
118 : blume 1002 CB.DEF_USE{cellkind=CB.FP,defs,uses} =>
119 :     CB.DEF_USE{cellkind=CB.FP,defs=defs,
120 : leunga 657 uses=map replace uses}
121 :     | _ => a}
122 :    
123 : monnier 409 | _ => instr
124 :     end
125 :    
126 : leunga 744 fun rewriteDef(instr, rs, rt) = let
127 : blume 1002 fun match r = CB.sameColor(r,rs)
128 : leunga 744 fun rewrite r = if match r then rt else r
129 : monnier 409 fun ea (SOME(I.Direct r)) = SOME(I.Direct (rewrite r))
130 :     | ea x = x
131 :     in
132 :     case instr
133 : leunga 744 of I.LDA{r, b, d} => if match r then I.LDA{r=rt, b=b, d=d} else instr
134 :     | I.LDAH{r, b, d} => if match r then I.LDAH{r=rt, b=b, d=d} else instr
135 : monnier 409 | I.LOAD{ldOp, r, b, d, mem} =>
136 : leunga 744 if match r then I.LOAD{ldOp=ldOp, r=rt, b=b, d=d, mem=mem} else instr
137 : monnier 409 | I.JMPL({r, b, d}, labs) =>
138 : leunga 744 if match r then I.JMPL({r=rt, b=b, d=d}, labs) else instr
139 : blume 859 | I.JSR{r, b, d, defs, uses, cutsTo, mem} =>
140 : blume 1002 I.JSR{r=rewrite r, b=b, d=d, defs=CS.map {from=rs,to=rt} defs,
141 : blume 859 uses=uses, cutsTo=cutsTo, mem=mem}
142 :     | I.BSR{r, lab, defs, uses, cutsTo, mem} =>
143 : blume 1002 I.BSR{r=rewrite r, lab=lab, defs=CS.map {from=rs,to=rt} defs,
144 : blume 859 uses=uses, cutsTo=cutsTo, mem=mem}
145 : monnier 409 | I.RET{r, b, d} => I.RET{r=rewrite r, b=b, d=d}
146 : george 545 | I.BRANCH{b=I.BR, r, lab} =>
147 : leunga 744 if match r then I.BRANCH{b=I.BR, r=rt, lab=lab} else instr
148 : monnier 409 | I.OPERATE{oper, ra, rb, rc} =>
149 : leunga 744 if match rc then I.OPERATE{oper=oper, ra=ra, rb=rb, rc=rt} else instr
150 : monnier 409 | I.OPERATEV{oper, ra, rb, rc} =>
151 : leunga 744 if match rc then I.OPERATEV{oper=oper, ra=ra, rb=rb, rc=rt} else instr
152 : monnier 409 | I.CMOVE{oper,ra,rb,rc} => I.CMOVE{oper=oper,ra=ra,rb=rb,rc=rewrite rc}
153 :     | I.COPY{dst, src, impl, tmp} =>
154 :     I.COPY{dst=map rewrite dst, src=src, tmp=ea tmp, impl=impl}
155 : leunga 744 | I.CALL_PAL{code, def, use} =>
156 : blume 1002 I.CALL_PAL{code=code, def=CS.map {from=rs,to=rt} def, use=use}
157 : leunga 744 | I.PSEUDOARITH{oper, ra, rb, rc, tmps} =>
158 : leunga 628 I.PSEUDOARITH{oper=oper, ra=ra, rb=rb, rc=rewrite rc,
159 : blume 1002 tmps=CS.map {from=rs,to=rt} tmps}
160 : leunga 657 | I.ANNOTATION{i,a} =>
161 : leunga 744 I.ANNOTATION{i=rewriteDef(i,rs,rt),
162 : leunga 657 a=case a of
163 : blume 1002 CB.DEF_USE{cellkind=CB.GP,defs,uses} =>
164 :     CB.DEF_USE{cellkind=CB.GP,uses=uses,
165 : leunga 657 defs=map rewrite defs}
166 :     | _ => a}
167 : monnier 409 | _ => instr
168 :     end
169 :    
170 : leunga 744 fun frewriteDef(instr, fs, ft) = let
171 : blume 1002 fun match f = CB.sameColor(f,fs)
172 : leunga 744 fun rewrite f = if match f then ft else f
173 : monnier 409 fun ea (SOME(I.FDirect f)) = SOME(I.FDirect(rewrite f))
174 :     | ea x = x
175 :     in
176 :     case instr
177 : leunga 744 of I.DEFFREG f => if match f then I.DEFFREG ft else instr
178 : monnier 409 | I.FLOAD{ldOp, r, b, d, mem} =>
179 : leunga 744 if match r then I.FLOAD{ldOp=ldOp, r=ft, b=b, d=d, mem=mem} else instr
180 : monnier 409 | I.FOPERATE{oper, fa, fb, fc} =>
181 : leunga 744 if match fc then I.FOPERATE{oper=oper, fa=fa, fb=fb, fc=ft} else instr
182 : monnier 409 | I.FOPERATEV{oper, fa, fb, fc} =>
183 : leunga 744 if match fc then I.FOPERATEV{oper=oper, fa=fa, fb=fb, fc=ft} else instr
184 : monnier 409 | I.FUNARY{oper,fb,fc} =>
185 : leunga 744 if match fc then I.FUNARY{oper=oper,fb=fb,fc=ft} else instr
186 : monnier 409 | I.FCOPY{dst, src, tmp, impl} =>
187 :     I.FCOPY{dst=map rewrite dst, src=src, tmp=ea tmp, impl=impl}
188 :     | I.FCMOVE{oper,fa,fb,fc} => I.FCMOVE{oper=oper,fa=fa,fb=fb,fc=rewrite fc}
189 : blume 859 | I.JSR{r, b, d, defs, uses, cutsTo, mem} =>
190 : blume 1002 I.JSR{r=r, b=b, d=d, defs=CS.map {from=fs,to=ft} defs,
191 : blume 859 uses=uses, cutsTo=cutsTo, mem=mem}
192 :     | I.BSR{r, lab, defs, uses, cutsTo, mem} =>
193 : blume 1002 I.BSR{r=r, lab=lab, defs=CS.map {from=fs,to=ft} defs,
194 : blume 859 uses=uses, cutsTo=cutsTo, mem=mem}
195 : leunga 744 | I.PSEUDOARITH{oper, ra, rb, rc, tmps} =>
196 :     I.PSEUDOARITH{oper=oper, ra=ra, rb=rb, rc=rc,
197 : blume 1002 tmps=CS.map {from=fs,to=ft} tmps}
198 : leunga 657 | I.ANNOTATION{i,a} =>
199 : leunga 744 I.ANNOTATION{i=frewriteDef(i,fs,ft),
200 : leunga 657 a=case a of
201 : blume 1002 CB.DEF_USE{cellkind=CB.FP,defs,uses} =>
202 :     CB.DEF_USE{cellkind=CB.FP,uses=uses,
203 : leunga 657 defs=map rewrite defs}
204 :     | _ => a}
205 : monnier 409 | _ => instr
206 :     end
207 :     end
208 :    

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