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/ppc/ra/ppcRewrite.sml
ViewVC logotype

Annotation of /sml/trunk/src/MLRISC/ppc/ra/ppcRewrite.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 657 - (view) (download)

1 : monnier 245 functor PPCRewrite(Instr : PPCINSTR) = struct
2 :     structure I = Instr
3 : leunga 657 structure C = I.C
4 : monnier 245
5 :     fun ea(NONE, _, _, _) = NONE
6 : george 545 | ea(e as SOME(I.Direct r), rs, rt, mapr : I.C.cell -> I.C.cell) =
7 : monnier 245 if mapr r=rs then SOME(I.Direct rt) else e
8 :     | ea(e as SOME(I.FDirect r), rs, rt, mapr) =
9 :     if mapr r=rs then SOME(I.FDirect rt) else e
10 :     | ea(e as SOME(I.Displace{base, disp}), rs, rt, mapr) =
11 :     if mapr base=rs then SOME(I.Displace{base=rt, disp=disp})
12 :     else e
13 :    
14 : george 545 fun rewriteUse(mapr : I.C.cell -> I.C.cell, instr, rs, rt) = let
15 : monnier 245 fun rplac r = if mapr r=rs then rt else r
16 :     fun rwOperand(opnd as I.RegOp r) =
17 :     if mapr r = rs then I.RegOp rt else opnd
18 :     | rwOperand opnd = opnd
19 :     in
20 :     case instr
21 : monnier 411 of I.L {ld, rt, ra, d, mem} =>
22 :     I.L{ld=ld, rt=rt, ra=rplac ra, d=rwOperand d, mem=mem}
23 :     | I.LF {ld, ft, ra, d, mem} =>
24 :     I.LF{ld=ld, ft=ft, ra=rplac ra, d=rwOperand d, mem=mem}
25 :     | I.ST {st, rs, ra, d, mem} =>
26 :     I.ST{st=st, rs=rplac rs, ra=rplac ra, d=rwOperand d, mem=mem}
27 :     | I.STF {st, fs, ra, d, mem} =>
28 :     I.STF{st=st, fs=fs, ra=rplac ra, d=rwOperand d, mem=mem}
29 :     | I.UNARY {oper, rt, ra, Rc, OE} =>
30 :     I.UNARY{oper=oper, rt=rt, ra=rplac ra, Rc=Rc, OE=OE}
31 : monnier 245 | I.ARITH{oper, rt, ra, rb, Rc, OE} =>
32 :     I.ARITH{oper=oper, rt=rt, ra=rplac ra, rb=rplac rb, Rc=Rc, OE=OE}
33 :     | I.ARITHI{oper, rt, ra, im} =>
34 :     I.ARITHI{oper=oper, rt=rt, ra=rplac ra, im=rwOperand im}
35 :     | I.ROTATE {oper, ra, rs, sh, mb, me} =>
36 : monnier 411 I.ROTATE{oper=oper, ra=ra, rs=rplac rs, sh=rplac sh, mb=mb, me=me}
37 :     | I.ROTATEI {oper, ra, rs, sh, mb, me} =>
38 :     I.ROTATEI{oper=oper, ra=ra, rs=rplac rs, sh=rwOperand sh, mb=mb, me=me}
39 :     | I.COMPARE {cmp, bf, l, ra, rb} =>
40 :     I.COMPARE{cmp=cmp, bf=bf, l=l, ra=rplac ra, rb=rwOperand rb}
41 : monnier 245 | I.MTSPR{rs, spr} => I.MTSPR{rs=rplac rs, spr=spr}
42 : monnier 411 | I.TW {to, ra, si} => I.TW{to=to, ra=rplac ra, si=rwOperand si}
43 :     | I.TD {to, ra, si} => I.TD{to=to, ra=rplac ra, si=rwOperand si}
44 :     | I.CALL {def, use=(r,f,c), mem} =>
45 :     I.CALL{def=def, use=(map rplac r,f,c), mem=mem}
46 : monnier 245 | I.COPY{dst, src, impl, tmp} =>
47 :     I.COPY{dst=dst, src=map rplac src, impl=impl, tmp=tmp}
48 :     | I.FCOPY{dst, src, impl, tmp} =>
49 :     I.FCOPY{dst=dst, src=src, impl=impl, tmp=ea(tmp, rs, rt, mapr)}
50 : leunga 657 | I.ANNOTATION{i,a} =>
51 :     I.ANNOTATION{i=rewriteUse(mapr,i,rs,rt),
52 :     a=case a of
53 :     C.DEF_USE{cellkind=C.GP,defs,uses} =>
54 :     C.DEF_USE{cellkind=C.GP,uses=map rplac uses,
55 :     defs=defs}
56 :     | _ => a}
57 : monnier 245 | _ => instr
58 :     end
59 :    
60 : george 545 fun rewriteDef(mapr : I.C.cell -> I.C.cell, instr, rs, rt) = let
61 : monnier 245 fun rplac r = if mapr r = rs then rt else r
62 :     in
63 :     case instr
64 : monnier 411 of I.L {ld, rt, ra, d, mem} =>
65 :     I.L{ld=ld, rt=rplac rt, ra=ra, d=d, mem=mem}
66 : monnier 245 | I.UNARY {oper, rt, ra, Rc, OE} =>
67 :     I.UNARY{oper=oper, rt=rplac rt, ra=ra, Rc=Rc, OE=OE}
68 :     | I.ARITH {oper, rt, ra, rb, Rc, OE} =>
69 :     I.ARITH{oper=oper, rt=rplac rt, ra=ra, rb=rb, Rc=Rc, OE=OE}
70 :     | I.ARITHI {oper, rt, ra, im} =>
71 :     I.ARITHI {oper=oper, rt=rplac rt, ra=ra, im=im}
72 :     | I.ROTATE {oper, ra, rs, sh, mb, me} =>
73 :     I.ROTATE {oper=oper, ra=rplac ra, rs=rs, sh=sh, mb=mb, me=me}
74 : monnier 411 | I.ROTATEI {oper, ra, rs, sh, mb, me} =>
75 :     I.ROTATEI {oper=oper, ra=rplac ra, rs=rs, sh=sh, mb=mb, me=me}
76 : monnier 245 | I.MFSPR {rt, spr} => I.MFSPR{rt=rplac rt, spr=spr}
77 : monnier 411 | I.CALL {def=(r,f,c), use, mem} =>
78 :     I.CALL{def=(map rplac r, f, c), use=use, mem=mem}
79 : monnier 245 | I.COPY {dst, src, impl, tmp} =>
80 :     I.COPY{dst=map rplac dst, src=src, impl=impl, tmp=ea(tmp,rs,rt,mapr)}
81 : leunga 657 | I.ANNOTATION{i,a} =>
82 :     I.ANNOTATION{i=rewriteDef(mapr,i,rs,rt),
83 :     a=case a of
84 :     C.DEF_USE{cellkind=C.GP,defs,uses} =>
85 :     C.DEF_USE{cellkind=C.GP,uses=uses,
86 :     defs=map rplac defs}
87 :     | _ => a}
88 : monnier 245 | _ => instr
89 :     end
90 :    
91 : george 545 fun frewriteUse(mapr : I.C.cell -> I.C.cell, instr, fs, ft) = let
92 : monnier 245 fun rplac r = if mapr r = fs then ft else r
93 :     in
94 :     case instr
95 : monnier 411 of I.STF {st, fs, ra, d, mem} =>
96 :     I.STF{st=st, fs=rplac fs, ra=ra, d=d, mem=mem}
97 :     | I.CALL{def, use=(r,f,c), mem} =>
98 :     I.CALL{def=def, use=(r, map rplac f, c), mem=mem}
99 : monnier 245 | I.FCOMPARE {cmp, bf, fa, fb} =>
100 :     I.FCOMPARE{cmp=cmp, bf=bf, fa=rplac fa, fb=rplac fb}
101 :     | I.FUNARY {oper, ft, fb, Rc} =>
102 :     I.FUNARY{oper=oper, ft=ft, fb=rplac fb, Rc=Rc}
103 :     | I.FARITH {oper, ft, fa, fb, Rc} =>
104 :     I.FARITH{oper=oper, ft=ft, fa=rplac fa, fb=rplac fb, Rc=Rc}
105 : monnier 411 | I.FARITH3 {oper, ft, fa, fb, fc, Rc} =>
106 :     I.FARITH3{oper=oper,ft=ft,fa=rplac fa, fb=rplac fb, fc=rplac fc,Rc=Rc}
107 : monnier 245 | I.FCOPY {dst, src, impl, tmp} =>
108 :     I.FCOPY{dst=dst, src=map rplac src, impl=impl, tmp=tmp}
109 : leunga 657 | I.ANNOTATION{i,a} =>
110 :     I.ANNOTATION{i=frewriteUse(mapr,i,fs,ft),
111 :     a=case a of
112 :     C.DEF_USE{cellkind=C.FP,defs,uses} =>
113 :     C.DEF_USE{cellkind=C.FP,uses=map rplac uses,
114 :     defs=defs}
115 :     | _ => a}
116 : monnier 245 | _ => instr
117 :     end
118 :    
119 :    
120 : george 545 fun frewriteDef(mapr : I.C.cell -> I.C.cell, instr, fs, ft) = let
121 : monnier 245 fun rplac r = if mapr r = fs then ft else r
122 :     in
123 :     case instr
124 : monnier 411 of I.LF{ld, ft, ra, d, mem} =>
125 :     I.LF{ld=ld, ft=rplac ft, ra=ra, d=d, mem=mem}
126 : monnier 245 | I.FUNARY {oper, ft, fb, Rc} =>
127 :     I.FUNARY{oper=oper, ft=rplac ft, fb=fb, Rc=Rc}
128 :     | I.FARITH{oper, ft, fa, fb, Rc} =>
129 :     I.FARITH{oper=oper, ft=rplac ft, fa=fa, fb=fb, Rc=Rc}
130 : monnier 411 | I.FARITH3{oper, ft, fa, fb, fc, Rc} =>
131 :     I.FARITH3{oper=oper, ft=rplac ft, fa=fa, fb=fb, fc=fc, Rc=Rc}
132 : monnier 245 (* CALL = BCLR {bo=ALWAYS, bf=0, bit=0, LK=true, labels=[] *)
133 : monnier 411 | I.CALL{def=(r,f,c), use, mem} =>
134 :     I.CALL{def=(r, map rplac f, c), use=use, mem=mem}
135 : monnier 245 | I.FCOPY {dst, src, impl, tmp} =>
136 :     I.FCOPY{dst=map rplac dst, src=src, impl=impl, tmp=ea(tmp,fs,ft,mapr)}
137 : leunga 657 | I.ANNOTATION{i,a} =>
138 :     I.ANNOTATION{i=frewriteDef(mapr,i,fs,ft),
139 :     a=case a of
140 :     C.DEF_USE{cellkind=C.FP,defs,uses} =>
141 :     C.DEF_USE{cellkind=C.FP,uses=uses,
142 :     defs=map rplac defs}
143 :     | _ => a}
144 : monnier 245 | _ => instr
145 :     end
146 :     end
147 :    

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