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 411 - (view) (download)
Original Path: sml/branches/SMLNJ/src/MLRISC/sparc/ra/sparcRewrite.sml

1 : monnier 245 functor SparcRewrite(Instr:SPARCINSTR) =
2 :     struct
3 :     structure I = Instr
4 :    
5 :     fun rwset(S,rw) = SortedList.uniq(map rw S)
6 :    
7 :     fun rewriteUse(mapr,instr,rs,rt) =
8 :     let fun R r = if mapr r = rs then rt else r
9 :     fun O(i as I.REG r) = if mapr r = rs then I.REG rt else i
10 :     | O i = i
11 :     in case instr of
12 :     I.LOAD{l,r,i,d,mem} => I.LOAD{l=l,r=R r,i=O i,d=d,mem=mem}
13 :     | I.STORE{s,d,r,i,mem} => I.STORE{s=s,d=R d,r=R r,i=O i,mem=mem}
14 :     | I.FLOAD{l,r,i,d,mem} => I.FLOAD{l=l,r=R r,i=O i,d=d,mem=mem}
15 :     | I.FSTORE{s,d,r,i,mem} => I.FSTORE{s=s,d=d,r=R r,i=O i,mem=mem}
16 : monnier 411 | I.ARITH{a,r,i,d} => I.ARITH{a=a,r=R r,i=O i,d=d}
17 : monnier 245 | I.SHIFT{s,r,i,d} => I.SHIFT{s=s,r=R r,i=O i,d=d}
18 : monnier 411 | I.BR{r,p,rcond,a,nop,label} =>
19 :     I.BR{r=R r,p=p,rcond=rcond,a=a,nop=nop,label=label}
20 :     | I.MOVicc{b,i,d} => I.MOVicc{b=b,i=O i,d=R d}
21 :     | I.MOVfcc{b,i,d} => I.MOVfcc{b=b,i=O i,d=R d}
22 :     | I.MOVR{rcond,r,i,d} => I.MOVR{rcond=rcond,r=R r,i=O i,d=R d}
23 : monnier 245 | I.JMP{r,i,labs,nop} => I.JMP{r=R r,i=O i,labs=labs,nop=nop}
24 : monnier 411 | I.JMPL{r,i,d,defs,uses=(A,B,C),nop,mem} =>
25 :     I.JMPL{r=R r,i=O i,d=d,defs=defs,uses=(rwset(A,R),B,C),nop=nop,mem=mem}
26 :     | I.CALL{defs,uses=(A,B,C),label,nop,mem} =>
27 :     I.CALL{defs=defs,uses=(rwset(A,R),B,C),label=label,nop=nop,mem=mem}
28 : monnier 245 | I.SAVE{r,i,d} => I.SAVE{r=R r,i=O i,d=d}
29 :     | I.RESTORE{r,i,d} => I.RESTORE{r=R r,i=O i,d=d}
30 :     | I.WRY{r,i} => I.WRY{r=R r,i=O i}
31 : monnier 411 | I.Ticc{t,cc,r,i} => I.Ticc{t=t,cc=cc,r=R r,i=O i}
32 : monnier 245 | I.COPY{src,dst,tmp,impl} =>
33 :     I.COPY{src=map R src,dst=dst,tmp=tmp,impl=impl}
34 : monnier 411 | I.ANNOTATION{i,a} => I.ANNOTATION{i=rewriteUse(mapr,i,rs,rt),a=a}
35 : monnier 245 | _ => instr
36 :     end
37 :    
38 :     fun rewriteDef(mapr,instr,rs,rt) =
39 :     let fun R r = if mapr r = rs then rt else r
40 :     fun ea(SOME(I.Direct r)) = SOME(I.Direct(R r))
41 :     | ea x = x
42 :     in case instr of
43 :     I.LOAD{l,r,i,d,mem} => I.LOAD{l=l,r=r,i=i,d=R d,mem=mem}
44 : monnier 411 | I.ARITH{a,r,i,d} => I.ARITH{a=a,r=r,i=i,d=R d}
45 : monnier 245 | I.SHIFT{s,r,i,d} => I.SHIFT{s=s,r=r,i=i,d=R d}
46 :     | I.SETHI{i,d} => I.SETHI{i=i,d=R d}
47 : monnier 411 | I.MOVicc{b,i,d} => I.MOVicc{b=b,i=i,d=R d}
48 :     | I.MOVfcc{b,i,d} => I.MOVfcc{b=b,i=i,d=R d}
49 :     | I.MOVR{rcond,r,i,d} => I.MOVR{rcond=rcond,r=r,i=i,d=R d}
50 :     | I.JMPL{r,i,d,defs=(A,B,C),uses,nop,mem} =>
51 :     I.JMPL{r=r,i=i,d=R d,defs=(rwset(A,R),B,C),uses=uses,nop=nop,mem=mem}
52 :     | I.CALL{defs=(A,B,C),uses,label,nop,mem} =>
53 :     I.CALL{defs=(rwset(A,R),B,C),uses=uses,label=label,nop=nop,mem=mem}
54 : monnier 245 | I.SAVE{r,i,d} => I.SAVE{r=r,i=i,d=R d}
55 :     | I.RESTORE{r,i,d} => I.RESTORE{r=r,i=i,d=R d}
56 :     | I.RDY{d} => I.RDY{d=R d}
57 :     | I.COPY{src,dst,tmp,impl} =>
58 :     I.COPY{src=src,dst=map R dst,tmp=ea tmp,impl=impl}
59 : monnier 411 | I.ANNOTATION{i,a} => I.ANNOTATION{i=rewriteDef(mapr,i,rs,rt),a=a}
60 : monnier 245 | _ => instr
61 :     end
62 :    
63 :     fun frewriteUse(mapr,instr,rs,rt) =
64 :     let fun R r = if mapr r = rs then rt else r
65 :     in case instr of
66 :     I.FPop1{a,r,d} => I.FPop1{a=a,r=R r,d=d}
67 :     | I.FPop2{a,r1,r2,d} => I.FPop2{a=a,r1=R r1,r2=R r2,d=d}
68 :     | I.FCMP{cmp,r1,r2,nop} => I.FCMP{cmp=cmp,r1=R r1,r2=R r2,nop=nop}
69 :     | I.FSTORE{s,r,i,d,mem} => I.FSTORE{s=s,r=r,i=i,d=R d,mem=mem}
70 : monnier 411 | I.FMOVicc{sz,b,r,d} => I.FMOVicc{sz=sz,b=b,r=R r,d=R d}
71 :     | I.FMOVfcc{sz,b,r,d} => I.FMOVfcc{sz=sz,b=b,r=R r,d=R d}
72 :     | I.JMPL{r,i,d,defs,uses=(A,B,C),nop,mem} =>
73 :     I.JMPL{r=r,i=i,d=d,defs=defs,uses=(A,rwset(B,R),C),nop=nop,mem=mem}
74 :     | I.CALL{defs,uses=(A,B,C),label,nop,mem} =>
75 :     I.CALL{defs=defs,uses=(A,rwset(B,R),C),label=label,nop=nop,mem=mem}
76 : monnier 245 | I.FCOPY{src,dst,tmp,impl} =>
77 :     I.FCOPY{src=map R src,dst=dst,tmp=tmp,impl=impl}
78 : monnier 411 | I.ANNOTATION{i,a} => I.ANNOTATION{i=frewriteUse(mapr,i,rs,rt),a=a}
79 : monnier 245 | _ => instr
80 :     end
81 :    
82 :     fun frewriteDef(mapr,instr,rs,rt) =
83 :     let fun R r = if mapr r = rs then rt else r
84 :     fun ea(SOME(I.FDirect r)) = SOME(I.FDirect(R r))
85 :     | ea x = x
86 :     in case instr of
87 :     I.FPop1{a,r,d} => I.FPop1{a=a,r=r,d=R d}
88 :     | I.FPop2{a,r1,r2,d} => I.FPop2{a=a,r1=r1,r2=r2,d=R d}
89 :     | I.FLOAD{l,r,i,d,mem} => I.FLOAD{l=l,r=r,i=i,d=R d,mem=mem}
90 : monnier 411 | I.FMOVicc{sz,b,r,d} => I.FMOVicc{sz=sz,b=b,r=r,d=R d}
91 :     | I.FMOVfcc{sz,b,r,d} => I.FMOVfcc{sz=sz,b=b,r=r,d=R d}
92 :     | I.JMPL{r,i,d,defs=(A,B,C),uses,nop,mem} =>
93 :     I.JMPL{r=r,i=i,d=d,defs=(A,rwset(B,R),C),uses=uses,nop=nop,mem=mem}
94 :     | I.CALL{defs=(A,B,C),uses,label,nop,mem} =>
95 :     I.CALL{defs=(A,rwset(B,R),C),uses=uses,label=label,nop=nop,mem=mem}
96 : monnier 245 | I.FCOPY{src,dst,tmp,impl} =>
97 :     I.FCOPY{src=src,dst=map R dst,tmp=ea tmp,impl=impl}
98 : monnier 411 | I.ANNOTATION{i,a}=> I.ANNOTATION{i=frewriteDef(mapr,i,rs,rt),a=a}
99 : monnier 245 | _ => instr
100 :     end
101 :    
102 :     end
103 :    

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