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

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