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

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

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