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
ViewVC logotype

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

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

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

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