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 409 - (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 :     fun rewriteUse(mapr, instr, rs, rt) = let
10 :     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 :     | I.JSR({r,b,d}, defs, (i,f), mem) =>
50 :     I.JSR({r=r, b=replace b, d=d}, defs, (map replace i, f), mem)
51 :     | I.RET{r,b,d} => I.RET{r=r, b=replace b, d=d}
52 :     | I.BRANCH(I.BR, _, _) => instr
53 :     | I.BRANCH(br, r, lab) => if mapr r=rs then I.BRANCH(br, rt, lab) else instr
54 :     | I.OPERATE arg => operate(I.OPERATE, arg)
55 :     | I.OPERATEV arg => operate(I.OPERATEV, arg)
56 :     | I.CMOVE{oper,ra,rb,rc} =>
57 :     I.CMOVE{oper=oper,ra=replace ra,rb=rwOperand rb,rc=replace rc}
58 :     | I.COPY{dst, src, tmp, impl} =>
59 :     I.COPY{dst=dst, src=map replace src, tmp=tmp, impl=impl}
60 :     | I.CALL_PAL{code, def, use } =>
61 :     I.CALL_PAL{code=code, def=def, use=map replace use}
62 :     | I.ANNOTATION{i,a} => I.ANNOTATION{i=rewriteUse(mapr,i,rs,rt),a=a}
63 :     | _ => instr
64 :     end
65 :    
66 :     fun frewriteUse(mapr, instr, fs, ft) = let
67 :     fun replace f = if mapr f=fs then ft else f
68 :     fun foperate(opClass, {oper, fa, fb, fc}) =
69 :     if mapr fa=fs then
70 :     opClass{oper=oper, fa=ft, fc=fc, fb=replace fb}
71 :     else if mapr fb=fs then opClass{oper=oper, fa=fa, fb=ft, fc=fc}
72 :     else instr
73 :     in
74 :     case instr
75 :     of I.FBRANCH(br, f, lab) =>
76 :     if mapr f=fs then I.FBRANCH(br, ft, lab) else instr
77 :     | I.FCOPY{dst, src, impl, tmp} =>
78 :     I.FCOPY{dst=dst, src=map(fn f => if mapr f=fs then ft else f) src,
79 :     tmp=tmp, impl=impl}
80 :     | I.FSTORE{stOp, r, b, d, mem} =>
81 :     if mapr r=fs then I.FSTORE{stOp=stOp, r=ft, b=b, d=d, mem=mem} else instr
82 :     | I.FOPERATE arg => foperate(I.FOPERATE, arg)
83 :     | I.FOPERATEV arg => foperate(I.FOPERATEV, arg)
84 :     | I.FUNARY{oper,fb,fc} =>
85 :     if mapr fb=fs then I.FUNARY{oper=oper,fb=ft,fc=fc} else instr
86 :     | I.FCMOVE{oper,fa,fb,fc} =>
87 :     I.FCMOVE{oper=oper,fa=replace fa,fb=replace fb,fc=replace fc}
88 :     | I.JSR(opnds, defs, (i,f), mem) => I.JSR(opnds, defs, (i, map replace f), mem)
89 :     | I.ANNOTATION{i,a} => I.ANNOTATION{i=frewriteUse(mapr,i,fs,ft),a=a}
90 :     | _ => instr
91 :     end
92 :    
93 :     fun rewriteDef(mapr, instr, rs, rt) = let
94 :     fun rewrite r = if mapr r = rs then rt else r
95 :     fun ea (SOME(I.Direct r)) = SOME(I.Direct (rewrite r))
96 :     | ea x = x
97 :     in
98 :     case instr
99 :     of I.LDA{r, b, d} => if mapr r=rs then I.LDA{r=rt, b=b, d=d} else instr
100 :     | I.LDAH{r, b, d} => if mapr r=rs then I.LDAH{r=rt, b=b, d=d} else instr
101 :     | I.LOAD{ldOp, r, b, d, mem} =>
102 :     if mapr r=rs then I.LOAD{ldOp=ldOp, r=rt, b=b, d=d, mem=mem} else instr
103 :     | I.JMPL({r, b, d}, labs) =>
104 :     if mapr r=rs then I.JMPL({r=rt, b=b, d=d}, labs) else instr
105 :     | I.JSR({r, b, d}, (i,f), uses, mem) =>
106 :     I.JSR({r=rewrite r, b=b, d=d}, (map rewrite i, f), uses, mem)
107 :     | I.RET{r, b, d} => I.RET{r=rewrite r, b=b, d=d}
108 :     | I.BRANCH(I.BR, r, lab) =>
109 :     if mapr r=rs then I.BRANCH(I.BR, rt, lab) else instr
110 :     | I.OPERATE{oper, ra, rb, rc} =>
111 :     if mapr rc=rs then I.OPERATE{oper=oper, ra=ra, rb=rb, rc=rt} else instr
112 :     | I.OPERATEV{oper, ra, rb, rc} =>
113 :     if rc=rs then I.OPERATEV{oper=oper, ra=ra, rb=rb, rc=rt} else instr
114 :     | I.CMOVE{oper,ra,rb,rc} => I.CMOVE{oper=oper,ra=ra,rb=rb,rc=rewrite rc}
115 :     | I.COPY{dst, src, impl, tmp} =>
116 :     I.COPY{dst=map rewrite dst, src=src, tmp=ea tmp, impl=impl}
117 :     | I.CALL_PAL{code, def, use } =>
118 :     I.CALL_PAL{code=code, def=map rewrite def, use=use}
119 :     | I.ANNOTATION{i,a} => I.ANNOTATION{i=rewriteDef(mapr,i,rs,rt),a=a}
120 :     | _ => instr
121 :     end
122 :    
123 :     fun frewriteDef(mapr, instr, fs, ft) = let
124 :     fun rewrite f = if mapr f = fs then ft else f
125 :     fun ea (SOME(I.FDirect f)) = SOME(I.FDirect(rewrite f))
126 :     | ea x = x
127 :     in
128 :     case instr
129 :     of I.DEFFREG f => if mapr f=fs then I.DEFFREG ft else instr
130 :     | I.FLOAD{ldOp, r, b, d, mem} =>
131 :     if mapr r=fs then I.FLOAD{ldOp=ldOp, r=ft, b=b, d=d, mem=mem} else instr
132 :     | I.FOPERATE{oper, fa, fb, fc} =>
133 :     if mapr fc=fs then I.FOPERATE{oper=oper, fa=fa, fb=fb, fc=ft} else instr
134 :     | I.FOPERATEV{oper, fa, fb, fc} =>
135 :     if mapr fc=fs then I.FOPERATEV{oper=oper, fa=fa, fb=fb, fc=ft} else instr
136 :     | I.FUNARY{oper,fb,fc} =>
137 :     if mapr fc=fs then I.FUNARY{oper=oper,fb=fb,fc=ft} else instr
138 :     | I.FCOPY{dst, src, tmp, impl} =>
139 :     I.FCOPY{dst=map rewrite dst, src=src, tmp=ea tmp, impl=impl}
140 :     | I.FCMOVE{oper,fa,fb,fc} => I.FCMOVE{oper=oper,fa=fa,fb=fb,fc=rewrite fc}
141 :     | I.JSR(opnds, (i,f), uses, mem) => I.JSR(opnds, (i, map rewrite f), uses, mem)
142 :    
143 :     | I.ANNOTATION{i,a} => I.ANNOTATION{i=frewriteDef(mapr,i,fs,ft),a=a}
144 :     | _ => instr
145 :     end
146 :     end
147 :    

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