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 657, Fri Jun 9 05:20:54 2000 UTC revision 744, Fri Dec 8 04:11:42 2000 UTC
# Line 7  Line 7 
7    structure I=Instr    structure I=Instr
8    structure C=I.C    structure C=I.C
9    
10    fun rewriteUse(mapr : I.C.cell -> I.C.cell, instr, rs, rt) = let    fun rewriteUse(instr, rs, rt) = let
11      fun isRegOp (opnd as I.REGop r) = mapr r=rs      fun match r = C.sameColor(r,rs)
12        fun isRegOp (I.REGop r) = match r
13        | isRegOp _ = false        | isRegOp _ = false
14      fun rwOperand(opnd as I.REGop r) = if mapr r=rs then I.REGop rt else opnd      fun rwOperand(opnd as I.REGop r) =
15             if match r then I.REGop rt else opnd
16        | rwOperand opnd = opnd        | rwOperand opnd = opnd
17      fun replace r = if mapr r=rs then rt else r      fun replace r = if match r then rt else r
18      fun load(ldClass, {ldOp, r, b, d, mem}) =      fun load(ldClass, {ldOp, r, b, d, mem}) =
19         if mapr b=rs then ldClass{ldOp=ldOp, r=r, b=rt, d=d, mem=mem}         if match b
20           then ldClass{ldOp=ldOp, r=r, b=rt, d=d, mem=mem}
21         else instr         else instr
22      fun fstore(stClass, {stOp, r, b, d, mem}) =      fun fstore(stClass, {stOp, r, b, d, mem}) =
23         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}
24         else instr         else instr
25      fun store{stOp, r, b, d, mem} =      fun store{stOp, r, b, d, mem} =
26        if mapr r=rs then        if match r then
27          if mapr b=rs then          if match b then
28            I.STORE{stOp=stOp, r=rt, b=rt, d=d, mem=mem}            I.STORE{stOp=stOp, r=rt, b=rt, d=d, mem=mem}
29          else          else
30            I.STORE{stOp=stOp, r=rt, b=b, d=d, mem=mem}            I.STORE{stOp=stOp, r=rt, b=b, d=d, mem=mem}
31        else if mapr b=rs then        else if match b then
32          I.STORE{stOp=stOp, r=r, b=rt, d=d, mem=mem}          I.STORE{stOp=stOp, r=r, b=rt, d=d, mem=mem}
33        else instr        else instr
34      fun operate(opClass, {oper, ra, rb, rc}) =      fun operate(opClass, {oper, ra, rb, rc}) =
35        if mapr ra=rs then        if match ra then
36          if isRegOp rb then          if isRegOp rb then
37            opClass{oper=oper, ra=rt, rb=I.REGop rt, rc=rc}            opClass{oper=oper, ra=rt, rb=I.REGop rt, rc=rc}
38          else opClass{oper=oper, ra=rt, rb=rb, rc=rc}          else opClass{oper=oper, ra=rt, rb=rb, rc=rc}
# Line 39  Line 42 
42    
43    in    in
44      case instr      case instr
45      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
46       | 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
47       | I.LOAD arg => load(I.LOAD, arg)       | I.LOAD arg => load(I.LOAD, arg)
48       | I.FLOAD farg => load(I.FLOAD, farg)       | I.FLOAD farg => load(I.FLOAD, farg)
49       | I.STORE arg => store arg       | I.STORE arg => store arg
50       | I.FSTORE farg => fstore(I.FSTORE, farg)       | I.FSTORE farg => fstore(I.FSTORE, farg)
51       | I.JMPL({r, b, d}, labs) =>       | I.JMPL({r, b, d}, labs) =>
52         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
53       | I.JSR{r, b, d, defs, uses=(i,f), mem} =>       | I.JSR{r, b, d, defs, uses, mem} =>
54           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,
55                 mem=mem}                 uses=C.CellSet.map {from=rs,to=rt} uses, mem=mem}
56       | I.BSR{r, lab, defs, uses=(i,f), mem} =>       | I.BSR{r, lab, defs, uses, mem} =>
57           I.BSR{r=r, lab=lab, defs=defs, uses=(map replace i, f), mem=mem}           I.BSR{r=r, lab=lab, defs=defs,
58                   uses=C.CellSet.map {from=rs,to=rt} uses, mem=mem}
59       | 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}
60       | I.BRANCH{b=I.BR, ...} => instr       | I.BRANCH{b=I.BR, ...} => instr
61       | 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}
62                                else instr                                else instr
63       | I.OPERATE arg => operate(I.OPERATE, arg)       | I.OPERATE arg => operate(I.OPERATE, arg)
64       | I.OPERATEV arg => operate(I.OPERATEV, arg)       | I.OPERATEV arg => operate(I.OPERATEV, arg)
# Line 63  Line 67 
67       | I.COPY{dst, src, tmp, impl} =>       | I.COPY{dst, src, tmp, impl} =>
68           I.COPY{dst=dst, src=map replace src, tmp=tmp, impl=impl}           I.COPY{dst=dst, src=map replace src, tmp=tmp, impl=impl}
69       | I.CALL_PAL{code, def, use } =>       | I.CALL_PAL{code, def, use } =>
70           I.CALL_PAL{code=code, def=def, use=map replace use}           I.CALL_PAL{code=code, def=def, use=C.CellSet.map {from=rs,to=rt} use}
71       | I.PSEUDOARITH{oper, ra, rb, rc, tmps} =>       | I.PSEUDOARITH{oper, ra, rb, rc, tmps} =>
72           I.PSEUDOARITH{oper=oper, ra=replace ra, rb=rwOperand rb, rc=rc,           I.PSEUDOARITH{oper=oper, ra=replace ra, rb=rwOperand rb, rc=rc,
73                         tmps=tmps}                         tmps=tmps}
74       | I.ANNOTATION{i,a} =>       | I.ANNOTATION{i,a} =>
75             I.ANNOTATION{i=rewriteUse(mapr,i,rs,rt),             I.ANNOTATION{i=rewriteUse(i,rs,rt),
76                          a=case a of                          a=case a of
77                             C.DEF_USE{cellkind=C.GP,defs,uses} =>                             C.DEF_USE{cellkind=C.GP,defs,uses} =>
78                               C.DEF_USE{cellkind=C.GP,defs=defs,                               C.DEF_USE{cellkind=C.GP,defs=defs,
# Line 77  Line 81 
81       | _ => instr       | _ => instr
82    end    end
83    
84    fun frewriteUse(mapr : I.C.cell -> I.C.cell, instr, fs, ft) = let    fun frewriteUse(instr, fs, ft) = let
85      fun replace f = if mapr f=fs then ft else f       fun match f = C.sameColor(f,fs)
86        fun replace f = if match f then ft else f
87      fun foperate(opClass, {oper, fa, fb, fc}) =      fun foperate(opClass, {oper, fa, fb, fc}) =
88        if mapr fa=fs then        if match fa then
89          opClass{oper=oper, fa=ft, fc=fc, fb=replace fb}          opClass{oper=oper, fa=ft, fc=fc, fb=replace fb}
90        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}
91        else instr        else instr
92    in    in
93      case instr      case instr
94      of I.FBRANCH{b, f, lab} =>      of I.FBRANCH{b, f, lab} =>
95         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
96       | I.FCOPY{dst, src, impl, tmp} =>       | I.FCOPY{dst, src, impl, tmp} =>
97          I.FCOPY{dst=dst, src=map(fn f => if mapr f=fs then ft else f) src,          I.FCOPY{dst=dst, src=map(fn f => if match f then ft else f) src,
98                  tmp=tmp, impl=impl}                  tmp=tmp, impl=impl}
99       | I.FSTORE{stOp, r, b, d, mem} =>       | I.FSTORE{stOp, r, b, d, mem} =>
100          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
101       | I.FOPERATE arg => foperate(I.FOPERATE, arg)       | I.FOPERATE arg => foperate(I.FOPERATE, arg)
102       | I.FOPERATEV arg => foperate(I.FOPERATEV, arg)       | I.FOPERATEV arg => foperate(I.FOPERATEV, arg)
103       | I.FUNARY{oper,fb,fc} =>       | I.FUNARY{oper,fb,fc} =>
104          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
105       | I.FCMOVE{oper,fa,fb,fc} =>       | I.FCMOVE{oper,fa,fb,fc} =>
106           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}
107       | I.JSR{r, b, d, defs, uses=(i,f), mem} =>       | I.JSR{r, b, d, defs, uses, mem} =>
108           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,
109       | I.BSR{r, lab, defs, uses=(i,f), mem} =>                 uses=C.CellSet.map {from=fs,to=ft} uses, mem=mem}
110           I.BSR{r=r, lab=lab, defs=defs, uses=(i, map replace f), mem=mem}       | I.BSR{r, lab, defs, uses, mem} =>
111             I.BSR{r=r, lab=lab, defs=defs,
112                   uses=C.CellSet.map {from=fs,to=ft} uses, mem=mem}
113       | I.ANNOTATION{i,a} =>       | I.ANNOTATION{i,a} =>
114           I.ANNOTATION{i=frewriteUse(mapr,i,fs,ft),           I.ANNOTATION{i=frewriteUse(i,fs,ft),
115                        a=case a of                        a=case a of
116                           C.DEF_USE{cellkind=C.FP,defs,uses} =>                           C.DEF_USE{cellkind=C.FP,defs,uses} =>
117                             C.DEF_USE{cellkind=C.FP,defs=defs,                             C.DEF_USE{cellkind=C.FP,defs=defs,
# Line 114  Line 121 
121       | _ => instr       | _ => instr
122    end    end
123    
124    fun rewriteDef(mapr : I.C.cell -> I.C.cell, instr, rs, rt) = let    fun rewriteDef(instr, rs, rt) = let
125      fun rewrite r = if mapr r = rs then rt else r      fun match r = C.sameColor(r,rs)
126        fun rewrite r = if match r then rt else r
127      fun ea (SOME(I.Direct r)) = SOME(I.Direct (rewrite r))      fun ea (SOME(I.Direct r)) = SOME(I.Direct (rewrite r))
128        | ea x = x        | ea x = x
129    in    in
130      case instr      case instr
131      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
132       | 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
133       | I.LOAD{ldOp, r, b, d, mem} =>       | I.LOAD{ldOp, r, b, d, mem} =>
134         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
135       | I.JMPL({r, b, d}, labs) =>       | I.JMPL({r, b, d}, labs) =>
136         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
137       | I.JSR{r, b, d, defs=(i,f), uses, mem} =>       | I.JSR{r, b, d, defs, uses, mem} =>
138           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=C.CellSet.map {from=rs,to=rt} defs,
139                 mem=mem}                 uses=uses, mem=mem}
140       | I.BSR{r, lab, defs=(i,f), uses, mem} =>       | I.BSR{r, lab, defs, uses, mem} =>
141           I.BSR{r=rewrite r, lab=lab, defs=(map rewrite i, f), uses=uses,           I.BSR{r=rewrite r, lab=lab, defs=C.CellSet.map {from=rs,to=rt} defs,
142                 mem=mem}                 uses=uses, mem=mem}
143       | 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}
144       | I.BRANCH{b=I.BR, r, lab} =>       | I.BRANCH{b=I.BR, r, lab} =>
145         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
146       | I.OPERATE{oper, ra, rb, rc} =>       | I.OPERATE{oper, ra, rb, rc} =>
147         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
148       | I.OPERATEV{oper, ra, rb, rc} =>       | I.OPERATEV{oper, ra, rb, rc} =>
149         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
150       | 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}
151       | I.COPY{dst, src, impl, tmp} =>       | I.COPY{dst, src, impl, tmp} =>
152          I.COPY{dst=map rewrite dst, src=src, tmp=ea tmp, impl=impl}          I.COPY{dst=map rewrite dst, src=src, tmp=ea tmp, impl=impl}
153       | I.CALL_PAL{code, def, use } =>       | I.CALL_PAL{code, def, use } =>
154           I.CALL_PAL{code=code, def=map rewrite def, use=use}           I.CALL_PAL{code=code, def=C.CellSet.map {from=rs,to=rt} def, use=use}
155       | I.PSEUDOARITH{oper, ra, rb, rc, tmps=(i,f)} =>       | I.PSEUDOARITH{oper, ra, rb, rc, tmps} =>
156           I.PSEUDOARITH{oper=oper, ra=ra, rb=rb, rc=rewrite rc,           I.PSEUDOARITH{oper=oper, ra=ra, rb=rb, rc=rewrite rc,
157                         tmps=(map rewrite i,f)}                         tmps=C.CellSet.map {from=rs,to=rt} tmps}
158       | I.ANNOTATION{i,a} =>       | I.ANNOTATION{i,a} =>
159           I.ANNOTATION{i=rewriteDef(mapr,i,rs,rt),           I.ANNOTATION{i=rewriteDef(i,rs,rt),
160                          a=case a of                          a=case a of
161                             C.DEF_USE{cellkind=C.GP,defs,uses} =>                             C.DEF_USE{cellkind=C.GP,defs,uses} =>
162                               C.DEF_USE{cellkind=C.GP,uses=uses,                               C.DEF_USE{cellkind=C.GP,uses=uses,
# Line 157  Line 165 
165       | _ => instr       | _ => instr
166    end    end
167    
168    fun frewriteDef(mapr : I.C.cell -> I.C.cell, instr, fs, ft) = let    fun frewriteDef(instr, fs, ft) = let
169      fun rewrite f = if mapr f = fs then ft else f      fun match f = C.sameColor(f,fs)
170        fun rewrite f = if match f then ft else f
171      fun ea (SOME(I.FDirect f)) = SOME(I.FDirect(rewrite f))      fun ea (SOME(I.FDirect f)) = SOME(I.FDirect(rewrite f))
172        | ea x  = x        | ea x  = x
173    in    in
174      case instr      case instr
175      of I.DEFFREG f => if mapr f=fs then I.DEFFREG ft else instr      of I.DEFFREG f => if match f then I.DEFFREG ft else instr
176       | I.FLOAD{ldOp, r, b, d, mem} =>       | I.FLOAD{ldOp, r, b, d, mem} =>
177          if mapr r=fs 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
178       | I.FOPERATE{oper, fa, fb, fc} =>       | I.FOPERATE{oper, fa, fb, fc} =>
179          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
180       | I.FOPERATEV{oper, fa, fb, fc} =>       | I.FOPERATEV{oper, fa, fb, fc} =>
181          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
182       | I.FUNARY{oper,fb,fc} =>       | I.FUNARY{oper,fb,fc} =>
183          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
184       | I.FCOPY{dst, src, tmp, impl} =>       | I.FCOPY{dst, src, tmp, impl} =>
185          I.FCOPY{dst=map rewrite dst, src=src, tmp=ea tmp, impl=impl}          I.FCOPY{dst=map rewrite dst, src=src, tmp=ea tmp, impl=impl}
186       | 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}
187       | I.JSR{r, b, d, defs=(i,f), uses, mem} =>       | I.JSR{r, b, d, defs, uses, mem} =>
188          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=C.CellSet.map {from=fs,to=ft} defs,
189       | I.BSR{r, lab, defs=(i,f), uses, mem} =>                uses=uses, mem=mem}
190          I.BSR{r=r, lab=lab, defs=(i, map rewrite f), uses=uses, mem=mem}       | I.BSR{r, lab, defs, uses, mem} =>
191       | I.PSEUDOARITH{oper, ra, rb, rc, tmps=(i,f)} =>          I.BSR{r=r, lab=lab, defs=C.CellSet.map {from=fs,to=ft} defs,
192           I.PSEUDOARITH{oper=oper, ra=ra, rb=rb, rc=rc, tmps=(i,map rewrite f)}                uses=uses, mem=mem}
193         | I.PSEUDOARITH{oper, ra, rb, rc, tmps} =>
194             I.PSEUDOARITH{oper=oper, ra=ra, rb=rb, rc=rc,
195                           tmps=C.CellSet.map {from=fs,to=ft} tmps}
196       | I.ANNOTATION{i,a} =>       | I.ANNOTATION{i,a} =>
197           I.ANNOTATION{i=frewriteDef(mapr,i,fs,ft),           I.ANNOTATION{i=frewriteDef(i,fs,ft),
198                          a=case a of                          a=case a of
199                             C.DEF_USE{cellkind=C.FP,defs,uses} =>                             C.DEF_USE{cellkind=C.FP,defs,uses} =>
200                               C.DEF_USE{cellkind=C.FP,uses=uses,                               C.DEF_USE{cellkind=C.FP,uses=uses,

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

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