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 624 - (view) (download)
Original Path: sml/trunk/src/MLRISC/alpha/ra/alphaRewrite.sml

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

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