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

revision 1002, Fri Nov 30 17:11:33 2001 UTC revision 1232, Tue Jun 4 21:11:15 2002 UTC
# Line 8  Line 8 
8    structure C=I.C    structure C=I.C
9    structure CB=CellsBasis    structure CB=CellsBasis
10    structure CS=CB.CellSet    structure CS=CB.CellSet
11      fun error msg = MLRiscErrorMsg.error ("AlphaRewrite", msg)
12    
13    fun rewriteUse(instr, rs, rt) = let    fun rewriteUse(instr, rs, rt) = let
14      fun match r = CB.sameColor(r,rs)      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      fun isRegOp (I.REGop r) = match r
21        | isRegOp _ = false        | isRegOp _ = false
22      fun rwOperand(opnd as I.REGop r) =      fun rwOperand(opnd as I.REGop r) =
23           if match r then I.REGop rt else opnd           if match r then I.REGop rt else opnd
24        | rwOperand opnd = opnd        | rwOperand opnd = opnd
     fun replace r = if match r then rt else r  
25      fun load(ldClass, {ldOp, r, b, d, mem}) =      fun load(ldClass, {ldOp, r, b, d, mem}) =
26         if match b         if match b
27         then ldClass{ldOp=ldOp, r=r, b=rt, d=d, mem=mem}         then ldClass{ldOp=ldOp, r=r, b=rt, d=d, mem=mem}
# Line 66  Line 71 
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=CS.map {from=rs,to=rt} 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(i,rs,rt),  
                         a=case a of  
                            CB.DEF_USE{cellkind=CB.GP,defs,uses} =>  
                              CB.DEF_USE{cellkind=CB.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(instr, fs, ft) = let    fun frewriteUse(instr, fs, ft) = let
94       fun match f = CB.sameColor(f,fs)       fun match f = CB.sameColor(f,fs)
95      fun replace f = if match f then ft else f      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 match fa 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}
# Line 95  Line 103 
103      case instr      case instr
104      of I.FBRANCH{b, f, lab} =>      of I.FBRANCH{b, f, lab} =>
105         if match f 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 match f 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 match r 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)
# Line 112  Line 117 
117       | I.BSR{r, lab, defs, uses, cutsTo, mem} =>       | I.BSR{r, lab, defs, uses, cutsTo, mem} =>
118           I.BSR{r=r, lab=lab, defs=defs,           I.BSR{r=r, lab=lab, defs=defs,
119                 uses=CS.map {from=fs,to=ft} uses, cutsTo=cutsTo, mem=mem}                 uses=CS.map {from=fs,to=ft} uses, cutsTo=cutsTo, mem=mem}
      | I.ANNOTATION{i,a} =>  
          I.ANNOTATION{i=frewriteUse(i,fs,ft),  
                       a=case a of  
                          CB.DEF_USE{cellkind=CB.FP,defs,uses} =>  
                            CB.DEF_USE{cellkind=CB.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(instr, rs, rt) = let    fun rewriteDef(instr, rs, rt) = let
135      fun match r = CB.sameColor(r,rs)      fun match r = CB.sameColor(r,rs)
136      fun rewrite r = if match r then rt else r      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 match r 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 match r 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} =>
# Line 150  Line 158 
158       | I.OPERATEV{oper, ra, rb, rc} =>       | I.OPERATEV{oper, ra, rb, rc} =>
159         if match rc 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=CS.map {from=rs,to=rt} 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.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=CS.map {from=rs,to=rt} tmps}                         tmps=CS.map {from=rs,to=rt} tmps}
      | I.ANNOTATION{i,a} =>  
          I.ANNOTATION{i=rewriteDef(i,rs,rt),  
                         a=case a of  
                            CB.DEF_USE{cellkind=CB.GP,defs,uses} =>  
                              CB.DEF_USE{cellkind=CB.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(instr, fs, ft) = let    fun frewriteDef(instr, fs, ft) = let
# Line 172  Line 181 
181      fun rewrite f = if match f then ft else f      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 match f then I.DEFFREG ft else instr        of I.FLOAD{ldOp, r, b, d, mem} =>
      | I.FLOAD{ldOp, r, b, d, mem} =>  
187          if match r then I.FLOAD{ldOp=ldOp, r=ft, b=b, d=d, mem=mem} else instr          if match r 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 match fc 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
# Line 183  Line 191 
191          if match fc 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 match fc 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, uses, cutsTo, mem} =>       | I.JSR{r, b, d, defs, uses, cutsTo, mem} =>
196          I.JSR{r=r, b=b, d=d, defs=CS.map {from=fs,to=ft} defs,          I.JSR{r=r, b=b, d=d, defs=CS.map {from=fs,to=ft} defs,
# Line 195  Line 201 
201       | I.PSEUDOARITH{oper, ra, rb, rc, tmps} =>       | I.PSEUDOARITH{oper, ra, rb, rc, tmps} =>
202           I.PSEUDOARITH{oper=oper, ra=ra, rb=rb, rc=rc,           I.PSEUDOARITH{oper=oper, ra=ra, rb=rb, rc=rc,
203                         tmps=CS.map {from=fs,to=ft} tmps}                         tmps=CS.map {from=fs,to=ft} tmps}
      | I.ANNOTATION{i,a} =>  
          I.ANNOTATION{i=frewriteDef(i,fs,ft),  
                         a=case a of  
                            CB.DEF_USE{cellkind=CB.FP,defs,uses} =>  
                              CB.DEF_USE{cellkind=CB.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.1002  
changed lines
  Added in v.1232

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