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/branches/idlbasis-devel/src/MLRISC/alpha/ra/alphaRewrite.sml
ViewVC logotype

Diff of /sml/branches/idlbasis-devel/src/MLRISC/alpha/ra/alphaRewrite.sml

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

sml/trunk/src/MLRISC/alpha/ra/alphaRewrite.sml revision 657, Fri Jun 9 05:20:54 2000 UTC sml/branches/idlbasis-devel/src/MLRISC/alpha/ra/alphaRewrite.sml revision 1232, Tue Jun 4 21:11:15 2002 UTC
# Line 6  Line 6 
6  functor AlphaRewrite(Instr : ALPHAINSTR) = struct  functor AlphaRewrite(Instr : ALPHAINSTR) = struct
7    structure I=Instr    structure I=Instr
8    structure C=I.C    structure C=I.C
9      structure CB=CellsBasis
10    fun rewriteUse(mapr : I.C.cell -> I.C.cell, instr, rs, rt) = let    structure CS=CB.CellSet
11      fun isRegOp (opnd as I.REGop r) = mapr r=rs    fun error msg = MLRiscErrorMsg.error ("AlphaRewrite", msg)
12    
13      fun rewriteUse(instr, rs, rt) = let
14        fun match r = CB.sameColor(r,rs)
15        fun replace r = if match r then rt else r
16        fun replaceEA(SOME(I.Displace{base, disp, mem})) =
17              SOME(I.Displace{base=replace base, disp=disp, mem=mem})
18          | replaceEA ea = ea
19        fun alphaUse(instr) = let
20          fun isRegOp (I.REGop r) = match r
21        | isRegOp _ = false        | isRegOp _ = false
22      fun rwOperand(opnd as I.REGop r) = if mapr r=rs then I.REGop rt else opnd        fun rwOperand(opnd as I.REGop r) =
23               if match r then I.REGop rt else opnd
24        | rwOperand opnd = opnd        | rwOperand opnd = opnd
     fun replace r = if mapr r=rs then rt else r  
25      fun load(ldClass, {ldOp, r, b, d, mem}) =      fun load(ldClass, {ldOp, r, b, d, mem}) =
26         if mapr b=rs then ldClass{ldOp=ldOp, r=r, b=rt, d=d, mem=mem}           if match b
27             then ldClass{ldOp=ldOp, r=r, b=rt, d=d, mem=mem}
28         else instr         else instr
29      fun fstore(stClass, {stOp, r, b, d, mem}) =      fun fstore(stClass, {stOp, r, b, d, mem}) =
30         if mapr b=rs then stClass{stOp=stOp, r=r, b=rt, d=d, mem=mem}           if match b then stClass{stOp=stOp, r=r, b=rt, d=d, mem=mem}
31         else instr         else instr
32      fun store{stOp, r, b, d, mem} =      fun store{stOp, r, b, d, mem} =
33        if mapr r=rs then          if match r then
34          if mapr b=rs then            if match b then
35            I.STORE{stOp=stOp, r=rt, b=rt, d=d, mem=mem}            I.STORE{stOp=stOp, r=rt, b=rt, d=d, mem=mem}
36          else          else
37            I.STORE{stOp=stOp, r=rt, b=b, d=d, mem=mem}            I.STORE{stOp=stOp, r=rt, b=b, d=d, mem=mem}
38        else if mapr b=rs then          else if match b then
39          I.STORE{stOp=stOp, r=r, b=rt, d=d, mem=mem}          I.STORE{stOp=stOp, r=r, b=rt, d=d, mem=mem}
40        else instr        else instr
41      fun operate(opClass, {oper, ra, rb, rc}) =      fun operate(opClass, {oper, ra, rb, rc}) =
42        if mapr ra=rs then          if match ra then
43          if isRegOp rb then          if isRegOp rb then
44            opClass{oper=oper, ra=rt, rb=I.REGop rt, rc=rc}            opClass{oper=oper, ra=rt, rb=I.REGop rt, rc=rc}
45          else opClass{oper=oper, ra=rt, rb=rb, rc=rc}          else opClass{oper=oper, ra=rt, rb=rb, rc=rc}
# Line 39  Line 49 
49    
50    in    in
51      case instr      case instr
52      of I.LDA{r, b, d} => if mapr b=rs then I.LDA{r=r, b=rt, d=d} else instr        of I.LDA{r, b, d} => if match b then I.LDA{r=r, b=rt, d=d} else instr
53       | I.LDAH{r, b, d} => if mapr b=rs then I.LDAH{r=r, b=rt, d=d} else instr         | I.LDAH{r, b, d} => if match b then I.LDAH{r=r, b=rt, d=d} else instr
54       | I.LOAD arg => load(I.LOAD, arg)       | I.LOAD arg => load(I.LOAD, arg)
55       | I.FLOAD farg => load(I.FLOAD, farg)       | I.FLOAD farg => load(I.FLOAD, farg)
56       | I.STORE arg => store arg       | I.STORE arg => store arg
57       | I.FSTORE farg => fstore(I.FSTORE, farg)       | I.FSTORE farg => fstore(I.FSTORE, farg)
58       | I.JMPL({r, b, d}, labs) =>       | I.JMPL({r, b, d}, labs) =>
59         if mapr b=rs then I.JMPL({r=r, b=rt, d=d}, labs) else instr           if match b then I.JMPL({r=r, b=rt, d=d}, labs) else instr
60       | I.JSR{r, b, d, defs, uses=(i,f), mem} =>         | I.JSR{r, b, d, defs, uses, cutsTo, mem} =>
61           I.JSR{r=r, b=replace b, d=d, defs=defs, uses=(map replace i, f),             I.JSR{r=r, b=replace b, d=d, defs=defs,
62                 mem=mem}                   uses=CS.map {from=rs,to=rt} uses, cutsTo=cutsTo, mem=mem}
63       | I.BSR{r, lab, defs, uses=(i,f), mem} =>         | I.BSR{r, lab, defs, uses, cutsTo, mem} =>
64           I.BSR{r=r, lab=lab, defs=defs, uses=(map replace i, f), mem=mem}             I.BSR{r=r, lab=lab, defs=defs,
65                     uses=CS.map {from=rs,to=rt} uses, cutsTo=cutsTo, mem=mem}
66       | I.RET{r,b,d} => I.RET{r=r, b=replace b, d=d}       | I.RET{r,b,d} => I.RET{r=r, b=replace b, d=d}
67       | I.BRANCH{b=I.BR, ...} => instr       | I.BRANCH{b=I.BR, ...} => instr
68       | I.BRANCH{b, r, lab} => if mapr r=rs then I.BRANCH{b=b, r=rt, lab=lab}         | I.BRANCH{b, r, lab} => if match r then I.BRANCH{b=b, r=rt, lab=lab}
69                                else instr                                else instr
70       | I.OPERATE arg => operate(I.OPERATE, arg)       | I.OPERATE arg => operate(I.OPERATE, arg)
71       | I.OPERATEV arg => operate(I.OPERATEV, arg)       | I.OPERATEV arg => operate(I.OPERATEV, arg)
72       | I.CMOVE{oper,ra,rb,rc} =>       | I.CMOVE{oper,ra,rb,rc} =>
73           I.CMOVE{oper=oper,ra=replace ra,rb=rwOperand rb,rc=replace rc}           I.CMOVE{oper=oper,ra=replace ra,rb=rwOperand rb,rc=replace rc}
      | I.COPY{dst, src, tmp, impl} =>  
          I.COPY{dst=dst, src=map replace src, tmp=tmp, impl=impl}  
74       | I.CALL_PAL{code, def, use } =>       | I.CALL_PAL{code, def, use } =>
75           I.CALL_PAL{code=code, def=def, use=map replace use}             I.CALL_PAL{code=code, def=def, use=CS.map {from=rs,to=rt} use}
76       | I.PSEUDOARITH{oper, ra, rb, rc, tmps} =>       | I.PSEUDOARITH{oper, ra, rb, rc, tmps} =>
77           I.PSEUDOARITH{oper=oper, ra=replace ra, rb=rwOperand rb, rc=rc,           I.PSEUDOARITH{oper=oper, ra=replace ra, rb=rwOperand rb, rc=rc,
78                         tmps=tmps}                         tmps=tmps}
      | I.ANNOTATION{i,a} =>  
            I.ANNOTATION{i=rewriteUse(mapr,i,rs,rt),  
                         a=case a of  
                            C.DEF_USE{cellkind=C.GP,defs,uses} =>  
                              C.DEF_USE{cellkind=C.GP,defs=defs,  
                                        uses=map replace uses}  
                           | _ => a}  
79       | _ => instr       | _ => instr
80    end    end
81      in
82          case instr
83           of (I.ANNOTATION{i, ...}) => rewriteUse(i, rs, rt)
84            | I.LIVE{regs, spilled} => I.LIVE{regs=C.addReg(rt, C.rmvReg(rs, regs)),
85                                               spilled=spilled}
86            | I.INSTR(i) => I.INSTR(alphaUse(i))
87            | I.COPY{k as CB.GP, sz, dst, src, tmp} =>
88               I.COPY{k=k, sz=sz, dst=dst, src=map replace src, tmp=replaceEA tmp}
89            | _ => error "rewriteUse"
90      end
91    
92    
93    fun frewriteUse(mapr : I.C.cell -> I.C.cell, instr, fs, ft) = let    fun frewriteUse(instr, fs, ft) = let
94      fun replace f = if mapr f=fs then ft else f      fun match f = CB.sameColor(f,fs)
95        fun replace f = if match f then ft else f
96        fun alphaUse(instr) = let
97      fun foperate(opClass, {oper, fa, fb, fc}) =      fun foperate(opClass, {oper, fa, fb, fc}) =
98        if mapr fa=fs then          if match fa then
99          opClass{oper=oper, fa=ft, fc=fc, fb=replace fb}          opClass{oper=oper, fa=ft, fc=fc, fb=replace fb}
100        else if mapr fb=fs then opClass{oper=oper, fa=fa, fb=ft, fc=fc}          else if match fb then opClass{oper=oper, fa=fa, fb=ft, fc=fc}
101        else instr        else instr
102    in    in
103      case instr      case instr
104      of I.FBRANCH{b, f, lab} =>      of I.FBRANCH{b, f, lab} =>
105         if mapr f=fs then I.FBRANCH{b=b, f=ft, lab=lab} else instr           if match f then I.FBRANCH{b=b, f=ft, lab=lab} else instr
      | I.FCOPY{dst, src, impl, tmp} =>  
         I.FCOPY{dst=dst, src=map(fn f => if mapr f=fs then ft else f) src,  
                 tmp=tmp, impl=impl}  
106       | I.FSTORE{stOp, r, b, d, mem} =>       | I.FSTORE{stOp, r, b, d, mem} =>
107          if mapr r=fs then I.FSTORE{stOp=stOp, r=ft, b=b, d=d, mem=mem} else instr            if match r then I.FSTORE{stOp=stOp, r=ft, b=b, d=d, mem=mem} else instr
108       | I.FOPERATE arg => foperate(I.FOPERATE, arg)       | I.FOPERATE arg => foperate(I.FOPERATE, arg)
109       | I.FOPERATEV arg => foperate(I.FOPERATEV, arg)       | I.FOPERATEV arg => foperate(I.FOPERATEV, arg)
110       | I.FUNARY{oper,fb,fc} =>       | I.FUNARY{oper,fb,fc} =>
111          if mapr fb=fs then I.FUNARY{oper=oper,fb=ft,fc=fc} else instr            if match fb then I.FUNARY{oper=oper,fb=ft,fc=fc} else instr
112       | I.FCMOVE{oper,fa,fb,fc} =>       | I.FCMOVE{oper,fa,fb,fc} =>
113           I.FCMOVE{oper=oper,fa=replace fa,fb=replace fb,fc=replace fc}           I.FCMOVE{oper=oper,fa=replace fa,fb=replace fb,fc=replace fc}
114       | I.JSR{r, b, d, defs, uses=(i,f), mem} =>         | I.JSR{r, b, d, defs, uses, cutsTo, mem} =>
115           I.JSR{r=r, b=b, d=d, defs=defs, uses=(i, map replace f), mem=mem}             I.JSR{r=r, b=b, d=d, defs=defs,
116       | I.BSR{r, lab, defs, uses=(i,f), mem} =>                   uses=CS.map {from=fs,to=ft} uses, cutsTo=cutsTo, mem=mem}
117           I.BSR{r=r, lab=lab, defs=defs, uses=(i, map replace f), mem=mem}         | I.BSR{r, lab, defs, uses, cutsTo, mem} =>
118       | I.ANNOTATION{i,a} =>             I.BSR{r=r, lab=lab, defs=defs,
119           I.ANNOTATION{i=frewriteUse(mapr,i,fs,ft),                   uses=CS.map {from=fs,to=ft} uses, cutsTo=cutsTo, mem=mem}
                       a=case a of  
                          C.DEF_USE{cellkind=C.FP,defs,uses} =>  
                            C.DEF_USE{cellkind=C.FP,defs=defs,  
                                      uses=map replace uses}  
                         | _ => a}  
   
120       | _ => instr       | _ => instr
121    end    end
122      in
123        case instr
124        of I.ANNOTATION{i, ...} => frewriteUse(instr, fs, ft)
125         | I.LIVE{regs, spilled} => I.LIVE{regs=C.addFreg(ft, C.rmvFreg(fs, regs)),
126                                            spilled=spilled}
127         | I.COPY{k as CB.FP, sz, dst, src, tmp} =>
128              I.COPY{k=k, sz=sz, dst=dst, tmp=tmp, src=map replace src}
129         | I.INSTR(i) => I.INSTR(alphaUse(i))
130         | _ => error "frewriteUse"
131      end
132    
133    
134    fun rewriteDef(mapr : I.C.cell -> I.C.cell, instr, rs, rt) = let    fun rewriteDef(instr, rs, rt) = let
135      fun rewrite r = if mapr r = rs then rt else r      fun match r = CB.sameColor(r,rs)
136        fun rewrite r = if match r then rt else r
137      fun ea (SOME(I.Direct r)) = SOME(I.Direct (rewrite r))      fun ea (SOME(I.Direct r)) = SOME(I.Direct (rewrite r))
138        | ea x = x        | ea x = x
139    in      fun alphaDef(instr) =
140      case instr       (case instr
141      of I.LDA{r, b, d} => if mapr r=rs then I.LDA{r=rt, b=b, d=d} else instr        of I.LDA{r, b, d} => if match r then I.LDA{r=rt, b=b, d=d} else instr
142       | I.LDAH{r, b, d} => if mapr r=rs then I.LDAH{r=rt, b=b, d=d} else instr         | I.LDAH{r, b, d} => if match r then I.LDAH{r=rt, b=b, d=d} else instr
143       | I.LOAD{ldOp, r, b, d, mem} =>       | I.LOAD{ldOp, r, b, d, mem} =>
144         if mapr r=rs then I.LOAD{ldOp=ldOp, r=rt, b=b, d=d, mem=mem} else instr           if match r then I.LOAD{ldOp=ldOp, r=rt, b=b, d=d, mem=mem} else instr
145       | I.JMPL({r, b, d}, labs) =>       | I.JMPL({r, b, d}, labs) =>
146         if mapr r=rs then I.JMPL({r=rt, b=b, d=d}, labs) else instr           if match r then I.JMPL({r=rt, b=b, d=d}, labs) else instr
147       | I.JSR{r, b, d, defs=(i,f), uses, mem} =>         | I.JSR{r, b, d, defs, uses, cutsTo, mem} =>
148           I.JSR{r=rewrite r, b=b, d=d, defs=(map rewrite i, f), uses=uses,             I.JSR{r=rewrite r, b=b, d=d, defs=CS.map {from=rs,to=rt} defs,
149                 mem=mem}                   uses=uses, cutsTo=cutsTo, mem=mem}
150       | I.BSR{r, lab, defs=(i,f), uses, mem} =>         | I.BSR{r, lab, defs, uses, cutsTo, mem} =>
151           I.BSR{r=rewrite r, lab=lab, defs=(map rewrite i, f), uses=uses,             I.BSR{r=rewrite r, lab=lab, defs=CS.map {from=rs,to=rt} defs,
152                 mem=mem}                   uses=uses, cutsTo=cutsTo, mem=mem}
153       | I.RET{r, b, d} => I.RET{r=rewrite r, b=b, d=d}       | I.RET{r, b, d} => I.RET{r=rewrite r, b=b, d=d}
154       | I.BRANCH{b=I.BR, r, lab} =>       | I.BRANCH{b=I.BR, r, lab} =>
155         if mapr r=rs then I.BRANCH{b=I.BR, r=rt, lab=lab} else instr           if match r then I.BRANCH{b=I.BR, r=rt, lab=lab} else instr
156       | I.OPERATE{oper, ra, rb, rc} =>       | I.OPERATE{oper, ra, rb, rc} =>
157         if mapr rc=rs then I.OPERATE{oper=oper, ra=ra, rb=rb, rc=rt} else instr           if match rc then I.OPERATE{oper=oper, ra=ra, rb=rb, rc=rt} else instr
158       | I.OPERATEV{oper, ra, rb, rc} =>       | I.OPERATEV{oper, ra, rb, rc} =>
159         if rc=rs then I.OPERATEV{oper=oper, ra=ra, rb=rb, rc=rt} else instr           if match rc then I.OPERATEV{oper=oper, ra=ra, rb=rb, rc=rt} else instr
160       | I.CMOVE{oper,ra,rb,rc} => I.CMOVE{oper=oper,ra=ra,rb=rb,rc=rewrite rc}       | I.CMOVE{oper,ra,rb,rc} => I.CMOVE{oper=oper,ra=ra,rb=rb,rc=rewrite rc}
      | I.COPY{dst, src, impl, tmp} =>  
         I.COPY{dst=map rewrite dst, src=src, tmp=ea tmp, impl=impl}  
161       | I.CALL_PAL{code, def, use } =>       | I.CALL_PAL{code, def, use } =>
162           I.CALL_PAL{code=code, def=map rewrite def, use=use}             I.CALL_PAL{code=code, def=CS.map {from=rs,to=rt} def, use=use}
163       | I.PSEUDOARITH{oper, ra, rb, rc, tmps=(i,f)} =>         | I.PSEUDOARITH{oper, ra, rb, rc, tmps} =>
164           I.PSEUDOARITH{oper=oper, ra=ra, rb=rb, rc=rewrite rc,           I.PSEUDOARITH{oper=oper, ra=ra, rb=rb, rc=rewrite rc,
165                         tmps=(map rewrite i,f)}                           tmps=CS.map {from=rs,to=rt} tmps}
      | I.ANNOTATION{i,a} =>  
          I.ANNOTATION{i=rewriteDef(mapr,i,rs,rt),  
                         a=case a of  
                            C.DEF_USE{cellkind=C.GP,defs,uses} =>  
                              C.DEF_USE{cellkind=C.GP,uses=uses,  
                                        defs=map rewrite defs}  
                           | _ => a}  
166       | _ => instr       | _ => instr
167        (*esac*))
168      in
169          case instr
170          of I.ANNOTATION{i, ...} => rewriteDef(i,rs,rt)
171           | I.KILL{regs, spilled} =>
172               I.KILL{regs=C.addReg(rt, C.rmvReg(rs, regs)), spilled=spilled}
173           | I.INSTR(i) => I.INSTR(alphaDef(i))
174           | I.COPY{k as CB.GP, sz, dst, src, tmp} =>
175              I.COPY{k=k, sz=sz, dst=map rewrite dst, src=src, tmp=ea tmp}
176           | _ => error "rewriteDef"
177    end    end
178    
179    fun frewriteDef(mapr : I.C.cell -> I.C.cell, instr, fs, ft) = let    fun frewriteDef(instr, fs, ft) = let
180      fun rewrite f = if mapr f = fs then ft else f      fun match f = CB.sameColor(f,fs)
181        fun rewrite f = if match f then ft else f
182      fun ea (SOME(I.FDirect f)) = SOME(I.FDirect(rewrite f))      fun ea (SOME(I.FDirect f)) = SOME(I.FDirect(rewrite f))
183        | ea x  = x        | ea x  = x
184    in      fun alphaDef(instr) =
185      case instr       (case instr
186      of I.DEFFREG f => if mapr f=fs then I.DEFFREG ft else instr        of I.FLOAD{ldOp, r, b, d, mem} =>
187       | I.FLOAD{ldOp, r, b, d, mem} =>            if match r then I.FLOAD{ldOp=ldOp, r=ft, b=b, d=d, mem=mem} else instr
         if mapr r=fs then I.FLOAD{ldOp=ldOp, r=ft, b=b, d=d, mem=mem} else instr  
188       | I.FOPERATE{oper, fa, fb, fc} =>       | I.FOPERATE{oper, fa, fb, fc} =>
189          if mapr fc=fs then I.FOPERATE{oper=oper, fa=fa, fb=fb, fc=ft} else instr            if match fc then I.FOPERATE{oper=oper, fa=fa, fb=fb, fc=ft} else instr
190       | I.FOPERATEV{oper, fa, fb, fc} =>       | I.FOPERATEV{oper, fa, fb, fc} =>
191          if mapr fc=fs then I.FOPERATEV{oper=oper, fa=fa, fb=fb, fc=ft} else instr            if match fc then I.FOPERATEV{oper=oper, fa=fa, fb=fb, fc=ft} else instr
192       | I.FUNARY{oper,fb,fc} =>       | I.FUNARY{oper,fb,fc} =>
193          if mapr fc=fs then I.FUNARY{oper=oper,fb=fb,fc=ft} else instr            if match fc then I.FUNARY{oper=oper,fb=fb,fc=ft} else instr
      | I.FCOPY{dst, src, tmp, impl} =>  
         I.FCOPY{dst=map rewrite dst, src=src, tmp=ea tmp, impl=impl}  
194       | I.FCMOVE{oper,fa,fb,fc} => I.FCMOVE{oper=oper,fa=fa,fb=fb,fc=rewrite fc}       | I.FCMOVE{oper,fa,fb,fc} => I.FCMOVE{oper=oper,fa=fa,fb=fb,fc=rewrite fc}
195       | I.JSR{r, b, d, defs=(i,f), uses, mem} =>         | I.JSR{r, b, d, defs, uses, cutsTo, mem} =>
196          I.JSR{r=r, b=b, d=d, defs=(i, map rewrite f), uses=uses, mem=mem}            I.JSR{r=r, b=b, d=d, defs=CS.map {from=fs,to=ft} defs,
197       | I.BSR{r, lab, defs=(i,f), uses, mem} =>                  uses=uses, cutsTo=cutsTo, mem=mem}
198          I.BSR{r=r, lab=lab, defs=(i, map rewrite f), uses=uses, mem=mem}         | I.BSR{r, lab, defs, uses, cutsTo, mem} =>
199       | I.PSEUDOARITH{oper, ra, rb, rc, tmps=(i,f)} =>            I.BSR{r=r, lab=lab, defs=CS.map {from=fs,to=ft} defs,
200           I.PSEUDOARITH{oper=oper, ra=ra, rb=rb, rc=rc, tmps=(i,map rewrite f)}                  uses=uses, cutsTo=cutsTo, mem=mem}
201       | I.ANNOTATION{i,a} =>         | I.PSEUDOARITH{oper, ra, rb, rc, tmps} =>
202           I.ANNOTATION{i=frewriteDef(mapr,i,fs,ft),             I.PSEUDOARITH{oper=oper, ra=ra, rb=rb, rc=rc,
203                          a=case a of                           tmps=CS.map {from=fs,to=ft} tmps}
                            C.DEF_USE{cellkind=C.FP,defs,uses} =>  
                              C.DEF_USE{cellkind=C.FP,uses=uses,  
                                        defs=map rewrite defs}  
                           | _ => a}  
204       | _  => instr       | _  => instr
205        (*esac*))
206      in
207          case instr
208           of I.ANNOTATION{i,a} => frewriteDef(i, fs, ft)
209            | I.KILL{regs, spilled} =>
210               I.KILL{regs=C.addFreg(ft, C.rmvFreg(fs, regs)), spilled=spilled}
211            | I.COPY{k as CB.FP, sz, dst, src, tmp} =>
212               I.COPY{k=k, sz=sz, dst=map rewrite dst, src=src, tmp=ea tmp}
213            | I.INSTR(i) => I.INSTR(alphaDef(i))
214            | _  => error "frewriteDef"
215    end    end
216  end  end
217    

Legend:
Removed from v.657  
changed lines
  Added in v.1232

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