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 411 - (view) (download)
Original Path: sml/branches/SMLNJ/src/MLRISC/ppc/ra/ppcRewrite.sml

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

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