Home My Page Projects Code Snippets Project Openings SML/NJ
 Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

# SCM Repository

[smlnj] Diff of /sml/trunk/src/MLRISC/ppc/ra/ppcRewrite.sml
 [smlnj] / sml / trunk / src / MLRISC / ppc / ra / ppcRewrite.sml

# Diff of /sml/trunk/src/MLRISC/ppc/ra/ppcRewrite.sml

sml/branches/SMLNJ/src/MLRISC/ppc/ra/ppcRewrite.sml revision 245, Sat Apr 17 18:47:12 1999 UTC sml/trunk/src/MLRISC/ppc/ra/ppcRewrite.sml revision 744, Fri Dec 8 04:11:42 2000 UTC
# Line 1  Line 1
1  functor PPCRewrite(Instr : PPCINSTR) = struct  functor PPCRewrite(Instr : PPCINSTR) = struct
2    structure I = Instr    structure I = Instr
3      structure C = I.C
4
5    fun ea(NONE, _, _, _) = NONE    fun ea(NONE, _, _) = NONE
6      | ea(e as SOME(I.Direct r), rs, rt, mapr) =      | ea(e as SOME(I.Direct r), rs, rt) =
7         if mapr r=rs then SOME(I.Direct rt) else e         if C.sameColor(r,rs) then SOME(I.Direct rt) else e
8      | ea(e as SOME(I.FDirect r), rs, rt, mapr) =      | ea(e as SOME(I.FDirect r), rs, rt) =
9         if mapr r=rs then SOME(I.FDirect rt) else e         if C.sameColor(r,rs) then SOME(I.FDirect rt) else e
10      | ea(e as SOME(I.Displace{base, disp}), rs, rt, mapr) =      | ea(e as SOME(I.Displace{base, disp}), rs, rt) =
11         if mapr base=rs then SOME(I.Displace{base=rt, disp=disp})         if C.sameColor(base,rs) then SOME(I.Displace{base=rt, disp=disp})
12         else e         else e
13
14    fun rewriteUse(mapr, instr, rs, rt) = let    fun rewriteUse(instr, rs, rt) = let
15      fun rplac r = if mapr r=rs then rt else r      fun rplac r = if C.sameColor(r,rs) then rt else r
16      fun rwOperand(opnd as I.RegOp r) =      fun rwOperand(opnd as I.RegOp r) =
17           if mapr r = rs then I.RegOp rt else opnd           if C.sameColor(r,rs) then I.RegOp rt else opnd
18        | rwOperand opnd = opnd        | rwOperand opnd = opnd
19    in    in
20      case instr      case instr
21      of I.L {sz, rt, ra, d, mem} =>      of I.L {ld, rt, ra, d, mem} =>
22          I.L{sz=sz, rt=rt, ra=rplac ra, d=rwOperand d, mem=mem}          I.L{ld=ld, rt=rt, ra=rplac ra, d=rwOperand d, mem=mem}
23       | I.ST {sz, rs, ra, d, mem} =>       | I.LF {ld, ft, ra, d, mem} =>
24          I.ST{sz=sz, rs=rplac rs, ra=rplac ra, d=rwOperand d, mem=mem}          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       | I.ARITH{oper, rt, ra, rb, Rc, OE} =>       | 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}          I.ARITH{oper=oper, rt=rt, ra=rplac ra, rb=rplac rb, Rc=Rc, OE=OE}
33       | I.ARITHI{oper, rt, ra, im} =>       | I.ARITHI{oper, rt, ra, im} =>
34          I.ARITHI{oper=oper, rt=rt, ra=rplac ra, im=rwOperand im}          I.ARITHI{oper=oper, rt=rt, ra=rplac ra, im=rwOperand im}
35       | I.ROTATE {oper, ra, rs, sh, mb, me} =>       | I.ROTATE {oper, ra, rs, sh, mb, me} =>
36          I.ROTATE{oper=oper, ra=ra, rs=rplac rs, sh=rwOperand sh, mb=mb, me=me}          I.ROTATE{oper=oper, ra=ra, rs=rplac rs, sh=rplac sh, mb=mb, me=me}
37       | I.COMPARE {cmp, bf, ra, rb} =>       | I.ROTATEI {oper, ra, rs, sh, mb, me} =>
38          I.COMPARE{cmp=cmp, bf=bf, ra=rplac ra, rb=rwOperand rb}          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       | I.MTSPR{rs, spr} => I.MTSPR{rs=rplac rs, spr=spr}       | I.MTSPR{rs, spr} => I.MTSPR{rs=rplac rs, spr=spr}
42       | I.TWI {to, ra, si} => I.TWI{to=to, ra=rplac ra, si=si}       | I.TW {to, ra, si} => I.TW{to=to, ra=rplac ra, si=rwOperand si}
43       | I.CALL {def, use=(r,f,c)} => I.CALL{def=def, use=(map rplac r,f,c)}       | I.TD {to, ra, si} => I.TD{to=to, ra=rplac ra, si=rwOperand si}
44         | I.CALL {def, use, mem} =>
45              I.CALL{def=def, use=C.CellSet.map {from=rs,to=rt} use, mem=mem}
46       | I.COPY{dst, src, impl, tmp} =>       | I.COPY{dst, src, impl, tmp} =>
47          I.COPY{dst=dst, src=map rplac src, impl=impl, tmp=tmp}          I.COPY{dst=dst, src=map rplac src, impl=impl, tmp=tmp}
48       | I.FCOPY{dst, src, impl, tmp} =>       | I.FCOPY{dst, src, impl, tmp} =>
49          I.FCOPY{dst=dst, src=src, impl=impl, tmp=ea(tmp, rs, rt, mapr)}          I.FCOPY{dst=dst, src=src, impl=impl, tmp=ea(tmp, rs, rt)}
50         | I.ANNOTATION{i,a} =>
51             I.ANNOTATION{i=rewriteUse(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       | _ => instr       | _ => instr
58    end    end
59
60    fun rewriteDef(mapr, instr, rs, rt) = let    fun rewriteDef(instr, rs, rt) = let
61      fun rplac r = if mapr r = rs then rt else r      fun rplac r = if C.sameColor(r,rs) then rt else r
62    in    in
63      case instr      case instr
64      of I.L {sz, rt, ra, d, mem} =>      of I.L {ld, rt, ra, d, mem} =>
65          I.L{sz=sz, rt=rplac rt, ra=ra, d=d, mem=mem}          I.L{ld=ld, rt=rplac rt, ra=ra, d=d, mem=mem}
66       | I.UNARY {oper, rt, ra, Rc, OE} =>       | I.UNARY {oper, rt, ra, Rc, OE} =>
67          I.UNARY{oper=oper, rt=rplac rt, ra=ra, Rc=Rc, OE=OE}          I.UNARY{oper=oper, rt=rplac rt, ra=ra, Rc=Rc, OE=OE}
68       | I.ARITH {oper, rt, ra, rb, Rc, OE} =>       | I.ARITH {oper, rt, ra, rb, Rc, OE} =>
# Line 53  Line 71
71          I.ARITHI {oper=oper, rt=rplac rt, ra=ra, im=im}          I.ARITHI {oper=oper, rt=rplac rt, ra=ra, im=im}
72       | I.ROTATE {oper, ra, rs, sh, mb, me} =>       | I.ROTATE {oper, ra, rs, sh, mb, me} =>
73          I.ROTATE {oper=oper, ra=rplac ra, rs=rs, sh=sh, mb=mb, me=me}          I.ROTATE {oper=oper, ra=rplac ra, rs=rs, sh=sh, mb=mb, me=me}
74         | 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       | I.MFSPR {rt, spr} => I.MFSPR{rt=rplac rt, spr=spr}       | I.MFSPR {rt, spr} => I.MFSPR{rt=rplac rt, spr=spr}
77       | I.CALL {def=(r,f,c), use} => I.CALL{def=(map rplac r, f, c), use=use}       | I.CALL {def, use, mem} =>
78            I.CALL{def=C.CellSet.map {from=rs,to=rt} def, use=use, mem=mem}
79       | I.COPY {dst, src, impl, tmp} =>       | I.COPY {dst, src, impl, tmp} =>
80          I.COPY{dst=map rplac dst, src=src, impl=impl, tmp=ea(tmp,rs,rt,mapr)}          I.COPY{dst=map rplac dst, src=src, impl=impl, tmp=ea(tmp,rs,rt)}
81         | I.ANNOTATION{i,a} =>
82            I.ANNOTATION{i=rewriteDef(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       | _ => instr       | _ => instr
89    end    end
90
91    fun frewriteUse(mapr, instr, fs, ft) = let    fun frewriteUse(instr, fs, ft) = let
92      fun rplac r = if mapr r = fs then ft else r      fun rplac r = if C.sameColor(r,fs) then ft else r
93    in    in
94      case instr      case instr
95      of I.ST {sz, rs, ra, d, mem} =>      of I.STF {st, fs, ra, d, mem} =>
96           I.ST{sz=sz, rs=rplac rs, ra=ra, d=d, mem=mem}           I.STF{st=st, fs=rplac fs, ra=ra, d=d, mem=mem}
97       | I.CALL{def, use=(r,f,c)} => I.CALL{def=def, use=(r, map rplac f, c)}       | I.CALL{def, use, mem} =>
98             I.CALL{def=def, use=C.CellSet.map {from=fs,to=ft} use, mem=mem}
99       | I.FCOMPARE {cmp, bf, fa, fb} =>       | I.FCOMPARE {cmp, bf, fa, fb} =>
100           I.FCOMPARE{cmp=cmp, bf=bf, fa=rplac fa, fb=rplac fb}           I.FCOMPARE{cmp=cmp, bf=bf, fa=rplac fa, fb=rplac fb}
101       | I.FUNARY {oper, ft, fb, Rc} =>       | I.FUNARY {oper, ft, fb, Rc} =>
102           I.FUNARY{oper=oper, ft=ft, fb=rplac fb, Rc=Rc}           I.FUNARY{oper=oper, ft=ft, fb=rplac fb, Rc=Rc}
103       | I.FARITH {oper, ft, fa, fb, Rc} =>       | I.FARITH {oper, ft, fa, fb, Rc} =>
104           I.FARITH{oper=oper, ft=ft, fa=rplac fa, fb=rplac fb, Rc=Rc}           I.FARITH{oper=oper, ft=ft, fa=rplac fa, fb=rplac fb, Rc=Rc}
105         | 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       | I.FCOPY {dst, src, impl, tmp} =>       | I.FCOPY {dst, src, impl, tmp} =>
108           I.FCOPY{dst=dst, src=map rplac src, impl=impl, tmp=tmp}           I.FCOPY{dst=dst, src=map rplac src, impl=impl, tmp=tmp}
109         | I.ANNOTATION{i,a} =>
110             I.ANNOTATION{i=frewriteUse(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       | _ => instr       | _ => instr
117    end    end
118
119
120    fun frewriteDef(mapr, instr, fs, ft) = let    fun frewriteDef(instr, fs, ft) = let
121      fun rplac r = if mapr r = fs then ft else r      fun rplac r = if C.sameColor(r,fs) then ft else r
122    in    in
123      case instr      case instr
124      of I.L{sz, rt, ra, d, mem} =>      of I.LF{ld, ft, ra, d, mem} =>
125          I.L{sz=sz, rt=rplac rt, ra=ra, d=d, mem=mem}          I.LF{ld=ld, ft=rplac ft, ra=ra, d=d, mem=mem}
126       | I.FUNARY {oper, ft, fb, Rc} =>       | I.FUNARY {oper, ft, fb, Rc} =>
127          I.FUNARY{oper=oper, ft=rplac ft, fb=fb, Rc=Rc}          I.FUNARY{oper=oper, ft=rplac ft, fb=fb, Rc=Rc}
128       | I.FARITH{oper, ft, fa, fb, Rc} =>       | I.FARITH{oper, ft, fa, fb, Rc} =>
129          I.FARITH{oper=oper, ft=rplac ft, fa=fa, fb=fb, Rc=Rc}          I.FARITH{oper=oper, ft=rplac ft, fa=fa, fb=fb, Rc=Rc}
130         | 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      (* CALL = BCLR {bo=ALWAYS, bf=0, bit=0, LK=true, labels=[] *)      (* CALL = BCLR {bo=ALWAYS, bf=0, bit=0, LK=true, labels=[] *)
133       | I.CALL{def=(r,f,c), use} => I.CALL{def=(r, map rplac f, c), use=use}       | I.CALL{def, use, mem} =>
134            I.CALL{def=C.CellSet.map {from=fs,to=ft} def, use=use, mem=mem}
135       | I.FCOPY {dst, src, impl, tmp} =>       | I.FCOPY {dst, src, impl, tmp} =>
136          I.FCOPY{dst=map rplac dst, src=src, impl=impl, tmp=ea(tmp,fs,ft,mapr)}          I.FCOPY{dst=map rplac dst, src=src, impl=impl, tmp=ea(tmp,fs,ft)}
137         | I.ANNOTATION{i,a} =>
138            I.ANNOTATION{i=frewriteDef(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       | _ => instr       | _ => instr
145    end    end
146  end  end

Legend:
 Removed from v.245 changed lines Added in v.744