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

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