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

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

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