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

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

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