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/sparc/ra/sparcRewrite.sml
ViewVC logotype

Annotation of /sml/trunk/src/MLRISC/sparc/ra/sparcRewrite.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1294 - (view) (download)

1 : monnier 245 functor SparcRewrite(Instr:SPARCINSTR) =
2 :     struct
3 :     structure I = Instr
4 : leunga 657 structure C = I.C
5 : george 889 structure CB = CellsBasis
6 : george 901 structure CS = CB.CellSet
7 : monnier 245
8 : george 1003 fun error msg = MLRiscErrorMsg.error ("SparcRewrite", msg)
9 :    
10 :     fun rewriteUse(instr,rs,rt) = let
11 : george 1009 fun match r = CB.sameColor(r,rs)
12 :     fun R r = if match r then rt else r
13 :     fun O(i as I.REG r) = if match r then I.REG rt else i
14 :     | O i = i
15 : george 1033 fun EA(SOME(I.Displace{base, disp, mem})) =
16 :     SOME(I.Displace{base=R base, disp=disp, mem=mem})
17 : george 1009 | EA ea = ea
18 :     fun sparcUse(instr) =
19 :     (case instr of
20 : george 1003 I.LOAD{l,r,i,d,mem} => I.LOAD{l=l,r=R r,i=O i,d=d,mem=mem}
21 :     | I.STORE{s,d,r,i,mem} => I.STORE{s=s,d=R d,r=R r,i=O i,mem=mem}
22 :     | I.FLOAD{l,r,i,d,mem} => I.FLOAD{l=l,r=R r,i=O i,d=d,mem=mem}
23 :     | I.FSTORE{s,d,r,i,mem} => I.FSTORE{s=s,d=d,r=R r,i=O i,mem=mem}
24 :     | I.ARITH{a,r,i,d} => I.ARITH{a=a,r=R r,i=O i,d=d}
25 :     | I.SHIFT{s,r,i,d} => I.SHIFT{s=s,r=R r,i=O i,d=d}
26 :     | I.BR{r,p,rcond,a,nop,label} =>
27 :     I.BR{r=R r,p=p,rcond=rcond,a=a,nop=nop,label=label}
28 :     | I.MOVicc{b,i,d} => I.MOVicc{b=b,i=O i,d=R d}
29 :     | I.MOVfcc{b,i,d} => I.MOVfcc{b=b,i=O i,d=R d}
30 :     | I.MOVR{rcond,r,i,d} => I.MOVR{rcond=rcond,r=R r,i=O i,d=R d}
31 :     | I.JMP{r,i,labs,nop} => I.JMP{r=R r,i=O i,labs=labs,nop=nop}
32 :     | I.JMPL{r,i,d,defs,uses,cutsTo,nop,mem} =>
33 :     I.JMPL{r=R r,i=O i,d=d,defs=defs,
34 :     uses=CS.map {from=rs,to=rt} uses,
35 :     cutsTo=cutsTo,nop=nop,mem=mem}
36 :     | I.CALL{defs,uses,label,cutsTo,nop,mem} =>
37 :     I.CALL{defs=defs,uses=CS.map {from=rs,to=rt} uses,
38 :     label=label,cutsTo=cutsTo,nop=nop,mem=mem}
39 :     | I.SAVE{r,i,d} => I.SAVE{r=R r,i=O i,d=d}
40 :     | I.RESTORE{r,i,d} => I.RESTORE{r=R r,i=O i,d=d}
41 :     | I.WRY{r,i} => I.WRY{r=R r,i=O i}
42 :     | I.Ticc{t,cc,r,i} => I.Ticc{t=t,cc=cc,r=R r,i=O i}
43 :     | _ => instr
44 : george 1009 (*esac*))
45 : george 1003 in
46 :     case instr
47 :     of (I.ANNOTATION{i, ...}) => rewriteUse(i, rs, rt)
48 :     | I.LIVE{regs, spilled} => I.LIVE{regs=C.addReg(rt, C.rmvReg(rs, regs)),
49 :     spilled=spilled}
50 :     | I.INSTR(i) => I.INSTR(sparcUse(i))
51 : george 1009 | I.COPY{k as CB.GP, sz, src,dst,tmp} =>
52 :     I.COPY{k=k, sz=sz, src=map R src,dst=dst,tmp=EA tmp}
53 : george 1003 | _ => error "rewriteUse"
54 : monnier 245 end
55 :    
56 : george 1003 fun rewriteDef(instr,rs,rt) = let
57 : george 1009 fun match r = CB.sameColor(r,rs)
58 :     fun R r = if match r then rt else r
59 :     fun ea(SOME(I.Direct r)) = SOME(I.Direct(R r))
60 :     | ea x = x
61 :     fun sparcDef(instr) =
62 :     (case instr
63 :     of I.LOAD{l,r,i,d,mem} => I.LOAD{l=l,r=r,i=i,d=R d,mem=mem}
64 : george 1003 | I.ARITH{a,r,i,d} => I.ARITH{a=a,r=r,i=i,d=R d}
65 :     | I.SHIFT{s,r,i,d} => I.SHIFT{s=s,r=r,i=i,d=R d}
66 :     | I.SETHI{i,d} => I.SETHI{i=i,d=R d}
67 :     | I.MOVicc{b,i,d} => I.MOVicc{b=b,i=i,d=R d}
68 :     | I.MOVfcc{b,i,d} => I.MOVfcc{b=b,i=i,d=R d}
69 :     | I.MOVR{rcond,r,i,d} => I.MOVR{rcond=rcond,r=r,i=i,d=R d}
70 :     | I.JMPL{r,i,d,defs,uses,cutsTo,nop,mem} =>
71 :     I.JMPL{r=r,i=i,d=R d,defs=CS.map {from=rs,to=rt} defs,
72 :     uses=uses,cutsTo=cutsTo,nop=nop,mem=mem}
73 :     | I.CALL{defs,uses,label,cutsTo,nop,mem} =>
74 :     I.CALL{defs=CS.map {from=rs,to=rt} defs,
75 :     uses=uses,label=label,cutsTo=cutsTo,nop=nop,mem=mem}
76 :     | I.SAVE{r,i,d} => I.SAVE{r=r,i=i,d=R d}
77 :     | I.RESTORE{r,i,d} => I.RESTORE{r=r,i=i,d=R d}
78 :     | I.RDY{d} => I.RDY{d=R d}
79 :     | _ => instr
80 : george 1009 (*esac*))
81 : george 1003 in
82 :     case instr
83 : blume 1294 of I.ANNOTATION{i, ...} => rewriteDef(i, rs, rt)
84 : george 1003 | I.KILL{regs, spilled} =>
85 :     I.KILL{regs=C.addReg(rt, C.rmvReg(rs, regs)), spilled=spilled}
86 :     | I.INSTR(i) => I.INSTR(sparcDef(i))
87 : george 1009 | I.COPY{k as CB.GP, sz, src,dst,tmp} =>
88 :     I.COPY{k=k, sz=sz, src=src, dst=map R dst,tmp=ea tmp}
89 : george 1003 | _ => error "rewriteDef"
90 : monnier 245 end
91 :    
92 : george 1003
93 :     fun frewriteUse(instr,rs,rt) = let
94 : george 1009 fun match r = CB.sameColor(r,rs)
95 :     fun R r = if match r then rt else r
96 :     fun sparcUse(instr) =
97 :     (case instr of
98 : george 1003 I.FPop1{a,r,d} => I.FPop1{a=a,r=R r,d=d}
99 :     | I.FPop2{a,r1,r2,d} => I.FPop2{a=a,r1=R r1,r2=R r2,d=d}
100 :     | I.FCMP{cmp,r1,r2,nop} => I.FCMP{cmp=cmp,r1=R r1,r2=R r2,nop=nop}
101 :     | I.FSTORE{s,r,i,d,mem} => I.FSTORE{s=s,r=r,i=i,d=R d,mem=mem}
102 :     | I.FMOVicc{sz,b,r,d} => I.FMOVicc{sz=sz,b=b,r=R r,d=R d}
103 :     | I.FMOVfcc{sz,b,r,d} => I.FMOVfcc{sz=sz,b=b,r=R r,d=R d}
104 :     | I.JMPL{r,i,d,defs,uses,cutsTo,nop,mem} =>
105 :     I.JMPL{r=r,i=i,d=d,defs=defs,
106 :     uses=CS.map {from=rs,to=rt} uses,
107 :     cutsTo=cutsTo,nop=nop,mem=mem}
108 :     | I.CALL{defs,uses,label,cutsTo,nop,mem} =>
109 :     I.CALL{defs=defs,uses=CS.map {from=rs,to=rt} uses,
110 :     label=label,cutsTo=cutsTo,nop=nop,mem=mem}
111 :     | _ => instr
112 : george 1009 (*esac*))
113 : george 1003 in
114 :     case instr
115 : blume 1294 of I.ANNOTATION{i, ...} => frewriteUse(i, rs, rt)
116 : george 1003 | I.INSTR(i) => I.INSTR(sparcUse(i))
117 :     | I.LIVE{regs, spilled} =>
118 :     I.LIVE{regs=C.addFreg(rt, C.rmvFreg(rs, regs)), spilled=spilled}
119 : george 1009 | I.COPY{k as CB.FP, sz, src,dst,tmp} =>
120 :     I.COPY{k=k, sz=sz, src=map R src,dst=dst,tmp=tmp}
121 : george 1003 | _ => error "frewriteUse"
122 :    
123 : monnier 245 end
124 :    
125 : george 1003
126 :     fun frewriteDef(instr,rs,rt) = let
127 : george 1009 fun match r = CB.sameColor(r,rs)
128 :     fun R r = if match r then rt else r
129 :     fun ea(SOME(I.FDirect r)) = SOME(I.FDirect(R r))
130 :     | ea x = x
131 :     fun sparcDef(instr) =
132 :     (case instr of
133 : george 1003 I.FPop1{a,r,d} => I.FPop1{a=a,r=r,d=R d}
134 :     | I.FPop2{a,r1,r2,d} => I.FPop2{a=a,r1=r1,r2=r2,d=R d}
135 :     | I.FLOAD{l,r,i,d,mem} => I.FLOAD{l=l,r=r,i=i,d=R d,mem=mem}
136 :     | I.FMOVicc{sz,b,r,d} => I.FMOVicc{sz=sz,b=b,r=r,d=R d}
137 :     | I.FMOVfcc{sz,b,r,d} => I.FMOVfcc{sz=sz,b=b,r=r,d=R d}
138 :     | I.JMPL{r,i,d,defs,uses,cutsTo,nop,mem} =>
139 :     I.JMPL{r=r,i=i,d=d,defs=CS.map {from=rs,to=rt} defs,
140 :     uses=uses,cutsTo=cutsTo,nop=nop,mem=mem}
141 :     | I.CALL{defs,uses,label,cutsTo,nop,mem} =>
142 :     I.CALL{defs=CS.map {from=rs,to=rt} defs,
143 :     uses=uses,label=label,cutsTo=cutsTo,nop=nop,mem=mem}
144 :     | _ => instr
145 : george 1009 (*esac*))
146 : george 1003 in
147 :     case instr
148 : blume 1294 of I.ANNOTATION{i, ...} => frewriteDef(i, rs, rt)
149 : george 1003 | I.KILL{regs, spilled} =>
150 :     I.KILL{regs=C.addFreg(rt, C.rmvFreg(rs, regs)), spilled=spilled}
151 :     | I.INSTR(i) => I.INSTR(sparcDef(i))
152 : george 1009 | I.COPY{k as CB.FP, sz, src,dst,tmp} =>
153 :     I.COPY{k=k, sz=sz, src=src,dst=map R dst,tmp=ea tmp}
154 : george 1003 | _ => error "frewriteUse"
155 :    
156 :     end
157 : monnier 245 end
158 :    

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