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/trunk/src/MLRISC/alpha/ra/alphaRewrite.sml
ViewVC logotype

Annotation of /sml/trunk/src/MLRISC/alpha/ra/alphaRewrite.sml

Parent Directory Parent Directory | Revision Log Revision Log


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

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