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 233 - (view) (download)

1 : monnier 233 functor PPCRewrite(Instr : PPCINSTR) = struct
2 :     structure I = Instr
3 :    
4 :     fun ea(NONE, _, _, _) = NONE
5 :     | ea(e as SOME(I.Direct r), rs, rt, mapr) =
6 :     if mapr r=rs then SOME(I.Direct rt) else e
7 :     | ea(e as SOME(I.FDirect r), rs, rt, mapr) =
8 :     if mapr r=rs then SOME(I.FDirect rt) else e
9 :     | ea(e as SOME(I.Displace{base, disp}), rs, rt, mapr) =
10 :     if mapr base=rs then SOME(I.Displace{base=rt, disp=disp})
11 :     else e
12 :    
13 :     fun rewriteUse(mapr, instr, rs, rt) = let
14 :     fun rplac r = if mapr r=rs then rt else r
15 :     fun rwOperand(opnd as I.RegOp r) =
16 :     if mapr r = rs then I.RegOp rt else opnd
17 :     | rwOperand opnd = opnd
18 :     in
19 :     case instr
20 :     of I.L {sz, rt, ra, d, mem} =>
21 :     I.L{sz=sz, rt=rt, ra=rplac ra, d=rwOperand d, mem=mem}
22 :     | I.ST {sz, rs, ra, d, mem} =>
23 :     I.ST{sz=sz, rs=rplac rs, ra=rplac ra, d=rwOperand d, mem=mem}
24 :     | I.ARITH{oper, rt, ra, rb, Rc, OE} =>
25 :     I.ARITH{oper=oper, rt=rt, ra=rplac ra, rb=rplac rb, Rc=Rc, OE=OE}
26 :     | I.ARITHI{oper, rt, ra, im} =>
27 :     I.ARITHI{oper=oper, rt=rt, ra=rplac ra, im=rwOperand im}
28 :     | I.ROTATE {oper, ra, rs, sh, mb, me} =>
29 :     I.ROTATE{oper=oper, ra=ra, rs=rplac rs, sh=rwOperand sh, mb=mb, me=me}
30 :     | I.COMPARE {cmp, bf, ra, rb} =>
31 :     I.COMPARE{cmp=cmp, bf=bf, ra=rplac ra, rb=rwOperand rb}
32 :     | I.MTSPR{rs, spr} => I.MTSPR{rs=rplac rs, spr=spr}
33 :     | I.TWI {to, ra, si} => I.TWI{to=to, ra=rplac ra, si=si}
34 :     | I.CALL {def, use=(r,f,c)} => I.CALL{def=def, use=(map rplac r,f,c)}
35 :     | I.COPY{dst, src, impl, tmp} =>
36 :     I.COPY{dst=dst, src=map rplac src, impl=impl, tmp=tmp}
37 :     | I.FCOPY{dst, src, impl, tmp} =>
38 :     I.FCOPY{dst=dst, src=src, impl=impl, tmp=ea(tmp, rs, rt, mapr)}
39 :     | _ => instr
40 :     end
41 :    
42 :     fun rewriteDef(mapr, instr, rs, rt) = let
43 :     fun rplac r = if mapr r = rs then rt else r
44 :     in
45 :     case instr
46 :     of I.L {sz, rt, ra, d, mem} =>
47 :     I.L{sz=sz, rt=rplac rt, ra=ra, d=d, mem=mem}
48 :     | I.UNARY {oper, rt, ra, Rc, OE} =>
49 :     I.UNARY{oper=oper, rt=rplac rt, ra=ra, Rc=Rc, OE=OE}
50 :     | I.ARITH {oper, rt, ra, rb, Rc, OE} =>
51 :     I.ARITH{oper=oper, rt=rplac rt, ra=ra, rb=rb, Rc=Rc, OE=OE}
52 :     | I.ARITHI {oper, rt, ra, im} =>
53 :     I.ARITHI {oper=oper, rt=rplac rt, ra=ra, im=im}
54 :     | I.ROTATE {oper, ra, rs, sh, mb, me} =>
55 :     I.ROTATE {oper=oper, ra=rplac ra, rs=rs, sh=sh, mb=mb, me=me}
56 :     | I.MFSPR {rt, spr} => I.MFSPR{rt=rplac rt, spr=spr}
57 :     | I.CALL {def=(r,f,c), use} => I.CALL{def=(map rplac r, f, c), use=use}
58 :     | I.COPY {dst, src, impl, tmp} =>
59 :     I.COPY{dst=map rplac dst, src=src, impl=impl, tmp=ea(tmp,rs,rt,mapr)}
60 :     | _ => instr
61 :     end
62 :    
63 :     fun frewriteUse(mapr, instr, fs, ft) = let
64 :     fun rplac r = if mapr r = fs then ft else r
65 :     in
66 :     case instr
67 :     of I.ST {sz, rs, ra, d, mem} =>
68 :     I.ST{sz=sz, rs=rplac rs, ra=ra, d=d, mem=mem}
69 :     | I.CALL{def, use=(r,f,c)} => I.CALL{def=def, use=(r, map rplac f, c)}
70 :     | I.FCOMPARE {cmp, bf, fa, fb} =>
71 :     I.FCOMPARE{cmp=cmp, bf=bf, fa=rplac fa, fb=rplac fb}
72 :     | I.FUNARY {oper, ft, fb, Rc} =>
73 :     I.FUNARY{oper=oper, ft=ft, fb=rplac fb, Rc=Rc}
74 :     | I.FARITH {oper, ft, fa, fb, Rc} =>
75 :     I.FARITH{oper=oper, ft=ft, fa=rplac fa, fb=rplac fb, Rc=Rc}
76 :     | I.FCOPY {dst, src, impl, tmp} =>
77 :     I.FCOPY{dst=dst, src=map rplac src, impl=impl, tmp=tmp}
78 :     | _ => instr
79 :     end
80 :    
81 :    
82 :     fun frewriteDef(mapr, instr, fs, ft) = let
83 :     fun rplac r = if mapr r = fs then ft else r
84 :     in
85 :     case instr
86 :     of I.L{sz, rt, ra, d, mem} =>
87 :     I.L{sz=sz, rt=rplac rt, ra=ra, d=d, mem=mem}
88 :     | I.FUNARY {oper, ft, fb, Rc} =>
89 :     I.FUNARY{oper=oper, ft=rplac ft, fb=fb, Rc=Rc}
90 :     | I.FARITH{oper, ft, fa, fb, Rc} =>
91 :     I.FARITH{oper=oper, ft=rplac ft, fa=fa, fb=fb, Rc=Rc}
92 :     (* CALL = BCLR {bo=ALWAYS, bf=0, bit=0, LK=true, labels=[] *)
93 :     | I.CALL{def=(r,f,c), use} => I.CALL{def=(r, map rplac f, c), use=use}
94 :     | I.FCOPY {dst, src, impl, tmp} =>
95 :     I.FCOPY{dst=map rplac dst, src=src, impl=impl, tmp=ea(tmp,fs,ft,mapr)}
96 :     | _ => instr
97 :     end
98 :     end
99 :    

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