Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Annotation of /sml/trunk/src/MLRISC/ppc/ra/ppcRewrite.sml
ViewVC logotype

Annotation of /sml/trunk/src/MLRISC/ppc/ra/ppcRewrite.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1539 - (view) (download)

1 : monnier 245 functor PPCRewrite(Instr : PPCINSTR) = struct
2 :     structure I = Instr
3 : leunga 657 structure C = I.C
4 : george 889 structure CB = CellsBasis
5 : george 901 structure CS = CB.CellSet
6 : monnier 245
7 : george 1003 fun error msg = MLRiscErrorMsg.error ("PPCRewrite", msg)
8 : leunga 744 fun ea(NONE, _, _) = NONE
9 :     | ea(e as SOME(I.Direct r), rs, rt) =
10 : george 889 if CB.sameColor(r,rs) then SOME(I.Direct rt) else e
11 : leunga 744 | ea(e as SOME(I.FDirect r), rs, rt) =
12 : george 889 if CB.sameColor(r,rs) then SOME(I.FDirect rt) else e
13 : george 1033 | 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 : monnier 245 else e
17 :    
18 : leunga 744 fun rewriteUse(instr, rs, rt) = let
19 : george 1009 fun rplac r = if CB.sameColor(r,rs) then rt else r
20 :     fun rwOperand(opnd as I.RegOp r) =
21 :     if CB.sameColor(r,rs) then I.RegOp rt else opnd
22 :     | rwOperand opnd = opnd
23 : george 1033 fun ea(SOME(I.Displace{base, disp, mem})) =
24 :     SOME(I.Displace{base=rplac base, disp=disp, mem=mem})
25 : george 1009 | ea x = x
26 :    
27 :     fun ppcUse(instr) =
28 :     (case instr
29 : george 1003 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} =>
40 :     I.ARITH{oper=oper, rt=rt, ra=rplac ra, rb=rplac rb, Rc=Rc, OE=OE}
41 :     | I.ARITHI{oper, rt, ra, im} =>
42 :     I.ARITHI{oper=oper, rt=rt, ra=rplac ra, im=rwOperand im}
43 :     | I.ROTATE {oper, ra, rs, sh, mb, me} =>
44 :     I.ROTATE{oper=oper, ra=ra, rs=rplac rs, sh=rplac sh, mb=mb, me=me}
45 :     | I.ROTATEI {oper, ra, rs, sh, mb, me} =>
46 :     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}
50 :     | I.TW {to, ra, si} => I.TW{to=to, ra=rplac ra, si=rwOperand si}
51 :     | I.TD {to, ra, si} => I.TD{to=to, ra=rplac ra, si=rwOperand si}
52 :     | I.CALL {def, use, cutsTo, mem} =>
53 :     I.CALL{def=def, use=CS.map {from=rs,to=rt} use,
54 :     cutsTo=cutsTo, mem=mem}
55 : allenleung 1539 | I.LWARX {rt, ra, rb} =>
56 :     I.LWARX{rt=rt, ra=rplac ra, rb=rplac rb}
57 :     | I.STWCX {rs, ra, rb} =>
58 :     I.STWCX{rs=rplac rs, ra=rplac ra, rb=rplac rb}
59 : george 1003 | _ => instr
60 : george 1009 (*esac*))
61 : monnier 245 in
62 : george 1003 case instr
63 :     of (I.ANNOTATION{i, ...}) => rewriteUse(i, rs, rt)
64 :     | I.INSTR(i) => I.INSTR(ppcUse(i))
65 : george 1009 | I.COPY{k, sz, dst, src, tmp} =>
66 :     I.COPY{k=k, sz=sz, dst=dst, tmp= ea tmp,
67 :     src=case k of CB.GP => map rplac src | _ => src}
68 : george 1003 | I.LIVE{regs, spilled} =>
69 :     I.LIVE{regs=C.addReg(rt, C.rmvReg(rs, regs)), spilled=spilled}
70 :     | _ => error "rewriteUse"
71 : monnier 245 end
72 :    
73 : george 1003
74 : leunga 744 fun rewriteDef(instr, rs, rt) = let
75 : george 1009 fun rplac r = if CB.sameColor(r,rs) then rt else r
76 :     fun ea (SOME(I.Direct r)) = SOME(I.Direct(rplac r))
77 :     | ea x = x
78 :     fun ppcDef(instr) =
79 :     (case instr
80 : george 1003 of I.L {ld, rt, ra, d, mem} =>
81 :     I.L{ld=ld, rt=rplac rt, ra=ra, d=d, mem=mem}
82 :     | I.UNARY {oper, rt, ra, Rc, OE} =>
83 :     I.UNARY{oper=oper, rt=rplac rt, ra=ra, Rc=Rc, OE=OE}
84 :     | I.ARITH {oper, rt, ra, rb, Rc, OE} =>
85 :     I.ARITH{oper=oper, rt=rplac rt, ra=ra, rb=rb, Rc=Rc, OE=OE}
86 :     | I.ARITHI {oper, rt, ra, im} =>
87 :     I.ARITHI {oper=oper, rt=rplac rt, ra=ra, im=im}
88 :     | I.ROTATE {oper, ra, rs, sh, mb, me} =>
89 :     I.ROTATE {oper=oper, ra=rplac ra, rs=rs, sh=sh, mb=mb, me=me}
90 :     | I.ROTATEI {oper, ra, rs, sh, mb, me} =>
91 :     I.ROTATEI {oper=oper, ra=rplac ra, rs=rs, sh=sh, mb=mb, me=me}
92 :     | I.MFSPR {rt, spr} => I.MFSPR{rt=rplac rt, spr=spr}
93 :     | I.CALL {def, use, cutsTo, mem} =>
94 :     I.CALL{def=CS.map {from=rs,to=rt} def, use=use,
95 :     cutsTo=cutsTo, mem=mem}
96 : allenleung 1539 | I.LWARX {rt, ra, rb} =>
97 :     I.LWARX{rt=rplac rt, ra=ra, rb=rb}
98 : george 1003 | _ => instr
99 : george 1009 (*esac*))
100 : george 1003 in
101 :     case instr
102 :     of (I.ANNOTATION{i, ...}) => rewriteDef(i, rs, rt)
103 :     | I.INSTR(i) => I.INSTR(ppcDef(i))
104 :     | I.KILL{regs, spilled} =>
105 :     I.KILL{regs=C.addReg(rt, C.rmvReg(rs, regs)), spilled=spilled}
106 : george 1009 | I.COPY {k, sz, dst, src, tmp} =>
107 :     I.COPY{k=k, sz=sz, src=src, tmp=ea tmp,
108 :     dst=case k of CB.GP => map rplac dst | _ => dst}
109 : george 1003 | _ => error "rewriteDef"
110 : monnier 245 end
111 :    
112 : george 1003
113 : leunga 744 fun frewriteUse(instr, fs, ft) = let
114 : george 1009 fun rplac r = if CB.sameColor(r,fs) then ft else r
115 :     fun ppcUse(instr) =
116 :     (case instr
117 : george 1003 of I.STF {st, fs, ra, d, mem} =>
118 :     I.STF{st=st, fs=rplac fs, ra=ra, d=d, mem=mem}
119 :     | I.CALL{def, use, cutsTo, mem} =>
120 :     I.CALL{def=def, use=CS.map {from=fs,to=ft} use,
121 :     cutsTo=cutsTo, mem=mem}
122 :     | I.FCOMPARE {cmp, bf, fa, fb} =>
123 :     I.FCOMPARE{cmp=cmp, bf=bf, fa=rplac fa, fb=rplac fb}
124 :     | I.FUNARY {oper, ft, fb, Rc} =>
125 :     I.FUNARY{oper=oper, ft=ft, fb=rplac fb, Rc=Rc}
126 :     | I.FARITH {oper, ft, fa, fb, Rc} =>
127 :     I.FARITH{oper=oper, ft=ft, fa=rplac fa, fb=rplac fb, Rc=Rc}
128 :     | I.FARITH3 {oper, ft, fa, fb, fc, Rc} =>
129 :     I.FARITH3{oper=oper,ft=ft,fa=rplac fa, fb=rplac fb, fc=rplac fc,Rc=Rc}
130 :     | _ => instr
131 : george 1009 (*esac*))
132 : monnier 245 in
133 : george 1003 case instr
134 :     of (I.ANNOTATION{i, ...}) => frewriteUse(i, fs, ft)
135 :     | I.INSTR(i) => I.INSTR(ppcUse(i))
136 :     | I.LIVE{regs, spilled} =>
137 :     I.LIVE{regs=C.addFreg(ft, C.rmvFreg(fs, regs)), spilled=spilled}
138 : george 1009 | I.COPY {k as CB.FP, sz, dst, src, tmp} =>
139 :     I.COPY{k=k, sz=sz, dst=dst, src=map rplac src, tmp=tmp}
140 :    
141 : george 1003 | _ => error "frewriteUse"
142 :    
143 : monnier 245 end
144 :    
145 : leunga 744 fun frewriteDef(instr, fs, ft) = let
146 : george 1009 fun rplac r = if CB.sameColor(r,fs) then ft else r
147 :     fun rplacEA (SOME(I.FDirect f)) = SOME(I.FDirect(rplac f))
148 :     | rplacEA ea = ea
149 :     fun ppcDef(instr) =
150 :     (case instr
151 : george 1003 of I.LF{ld, ft, ra, d, mem} =>
152 :     I.LF{ld=ld, ft=rplac ft, ra=ra, d=d, mem=mem}
153 :     | I.FUNARY {oper, ft, fb, Rc} =>
154 :     I.FUNARY{oper=oper, ft=rplac ft, fb=fb, Rc=Rc}
155 :     | I.FARITH{oper, ft, fa, fb, Rc} =>
156 :     I.FARITH{oper=oper, ft=rplac ft, fa=fa, fb=fb, Rc=Rc}
157 :     | I.FARITH3{oper, ft, fa, fb, fc, Rc} =>
158 :     I.FARITH3{oper=oper, ft=rplac ft, fa=fa, fb=fb, fc=fc, Rc=Rc}
159 :     (* CALL = BCLR {bo=ALWAYS, bf=0, bit=0, LK=true, labels=[] *)
160 :     | I.CALL{def, use, cutsTo, mem} =>
161 :     I.CALL{def=CS.map {from=fs,to=ft} def, use=use,
162 :     cutsTo=cutsTo, mem=mem}
163 :     | _ => instr
164 : george 1009 (*esac*))
165 : monnier 245 in
166 : george 1003 case instr
167 :     of (I.ANNOTATION{i, ...}) => frewriteDef(i, fs, ft)
168 :     | I.INSTR(i) => I.INSTR(ppcDef(i))
169 :     | I.KILL{regs, spilled} =>
170 :     I.KILL{regs=C.addFreg(ft, C.rmvFreg(fs, regs)), spilled=spilled}
171 : george 1009 | I.COPY {k as CB.FP, sz, dst, src, tmp} =>
172 :     I.COPY{k=k, sz=sz, dst=map rplac dst, src=src, tmp=rplacEA tmp}
173 : george 1003 | _ => error "frewriteDef"
174 : monnier 245 end
175 :     end
176 :    

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