Debian Codegraph @

lib/mlrisc-lib/MLRISC/sparc/backpatch/sparcDelaySlotProps.sml

raw
1 functor SparcDelaySlots
2 (structure I : SPARCINSTR
3 structure P : INSN_PROPERTIES (* where I = I *)
4 where type I.addressing_mode = I.addressing_mode
5 and type I.ea = I.ea
6 and type I.instr = I.instr
7 and type I.instruction = I.instruction
8 and type I.operand = I.operand
9 (* sharing/defn conflict: sharing P.I = I*)
10 ) : DELAY_SLOT_PROPERTIES =
11 struct
12 structure I = I
13 structure C = I.C
14 structure SL = CellsBasis.SortedCells
15
16 fun error msg = MLRiscErrorMsg.error("SparcDelaySlotProps",msg)
17
18 datatype delay_slot = D_NONE | D_ERROR | D_ALWAYS | D_TAKEN | D_FALLTHRU
19
20 val delaySlotSize = 4
21
22 fun delaySlot{instr, backward} =
23 case instr of
24 I.INSTR(I.CALL{nop,...}) => {n=false,nOn=D_ERROR,nOff=D_ALWAYS,nop=nop}
25 | I.INSTR(I.JMP{nop,...}) => {n=false,nOn=D_ERROR,nOff=D_ALWAYS,nop=nop}
26 | I.INSTR(I.JMPL{nop,...}) => {n=false,nOn=D_ERROR,nOff=D_ALWAYS,nop=nop}
27 | I.INSTR(I.RET{nop,...}) => {n=false,nOn=D_ERROR,nOff=D_ALWAYS,nop=nop}
28 | I.INSTR(I.Bicc{b=I.BA,a,nop,...}) => {n=false,nOn=D_NONE,nOff=D_ALWAYS,nop=nop}
29 | I.INSTR(I.Bicc{a,nop,...}) => {n=a,nOn=D_TAKEN,nOff=D_ALWAYS,nop=nop}
30 | I.INSTR(I.FBfcc{a,nop,...}) => {n=a,nOn=D_TAKEN,nOff=D_ALWAYS,nop=nop}
31 | I.INSTR(I.BR{a,nop,...}) => {n=a,nOn=D_TAKEN,nOff=D_ALWAYS,nop=nop}
32 | I.INSTR(I.BP{a,nop,...}) => {n=a,nOn=D_TAKEN,nOff=D_ALWAYS,nop=nop}
33 | I.INSTR(I.FCMP{nop,...}) => {n=false,nOn=D_ERROR,nOff=D_ALWAYS,nop=nop}
34 | I.ANNOTATION{i,...} => delaySlot{instr=i,backward=backward}
35 | _ => {n=false,nOn=D_ERROR,nOff=D_NONE,nop=false}
36
37 fun enableDelaySlot{instr, n, nop} =
38 case (instr,n) of
39 (I.INSTR(I.CALL{defs,uses,label,cutsTo,mem,...}),false) =>
40 I.call{defs=defs,uses=uses,label=label,cutsTo=cutsTo,
41 nop=nop,mem=mem}
42 | (I.INSTR(I.JMPL{r,i,d,defs,uses,mem,cutsTo,...}),false) =>
43 I.jmpl{r=r,i=i,d=d,defs=defs,uses=uses,cutsTo=cutsTo,
44 nop=nop,mem=mem}
45 | (I.INSTR(I.JMP{r,i,labs,...}),false) =>
46 I.jmp{r=r,i=i,labs=labs,nop=nop}
47 | (I.INSTR(I.RET{leaf,...}),false) => I.ret{leaf=leaf,nop=nop}
48 | (I.INSTR(I.Bicc{b,a,label,...}),_) => I.bicc{b=b,a=n,nop=nop,label=label}
49 | (I.INSTR(I.FBfcc{b,a,label,...}),_) => I.fbfcc{b=b,a=n,nop=nop,label=label}
50 | (I.INSTR(I.BR{nop,label,p,r,rcond,...}),_) =>
51 I.br{rcond=rcond,r=r,a=n,nop=nop,label=label,p=p}
52 | (I.INSTR(I.BP{nop,label,p,cc,b,...}),_) =>
53 I.bp{b=b,cc=cc,a=n,nop=nop,label=label,p=p}
54 | (I.INSTR(I.FCMP{cmp,r1,r2,...}),false) => I.fcmp{cmp=cmp,r1=r1,r2=r2,nop=nop}
55 | (I.ANNOTATION{i,a},n) =>
56 I.ANNOTATION{i=enableDelaySlot{instr=i,n=n,nop=nop},a=a}
57 | _ => error "enableDelaySlot"
58
59 val defUseI = P.defUse CellsBasis.GP
60 val defUseF = P.defUse CellsBasis.FP
61 val psr = [C.psr]
62 val fsr = [C.fsr]
63 val y = [C.y]
64 val zeroR = Option.valOf(C.zeroReg CellsBasis.GP)
65 val everything = [C.y,C.psr,C.fsr]
66 fun conflict{src=i,dst=j} =
67 let fun cc I.ANDCC = true
68 | cc I.ANDNCC = true
69 | cc I.ORCC = true
70 | cc I.ORNCC = true
71 | cc I.XORCC = true
72 | cc I.XNORCC = true
73 | cc I.ADDCC = true
74 | cc I.TADDCC = true
75 | cc I.TADDTVCC = true
76 | cc I.SUBCC = true
77 | cc I.TSUBCC = true
78 | cc I.TSUBTVCC= true
79 | cc I.UMULCC = true
80 | cc I.SMULCC = true
81 | cc I.UDIVCC = true
82 | cc I.SDIVCC = true
83 | cc _ = false
84 fun defUseOther(I.INSTR(I.Ticc _)) = ([],psr)
85 | defUseOther(I.INSTR(I.ARITH{a,...})) =
86 if cc a then (psr,[]) else ([],[])
87 | defUseOther(I.INSTR(I.WRY _)) = (y,[])
88 | defUseOther(I.INSTR(I.RDY _)) = ([],y)
89 | defUseOther(I.INSTR(I.FCMP _)) = (fsr,[])
90 | defUseOther(I.INSTR(I.Bicc{b=I.BA,...})) = ([],[])
91 | defUseOther(I.INSTR(I.Bicc _)) = ([],psr)
92 | defUseOther(I.INSTR(I.FBfcc _)) = ([],fsr)
93 | defUseOther(I.INSTR(I.MOVicc _)) = ([],psr)
94 | defUseOther(I.INSTR(I.MOVfcc _)) = ([],fsr)
95 | defUseOther(I.INSTR(I.FMOVicc _)) = ([],psr)
96 | defUseOther(I.INSTR(I.FMOVfcc _)) = ([],fsr)
97 | defUseOther(I.INSTR(I.CALL _)) = (everything,[])
98 | defUseOther(I.INSTR(I.JMPL _)) = (everything,[])
99 | defUseOther(I.ANNOTATION{i,...}) = defUseOther i
100 | defUseOther _ = ([],[])
101 fun clash(defUse) =
102 let val (di,ui) = defUse i
103 val (dj,uj) = defUse j
104 in SL.nonEmptyIntersection(di,uj) orelse
105 SL.nonEmptyIntersection(di,dj) orelse
106 SL.nonEmptyIntersection(ui,dj)
107 end
108 fun toSL f i = let val (d,u) = f i
109 in (SL.uniq d, SL.uniq u) end
110 fun defUseInt i =
111 let val (d,u) = defUseI i
112 val d = SL.uniq d
113 val u = SL.uniq u
114 (* no dependence on register 0! *)
115 in (SL.rmv(zeroR,d), SL.rmv(zeroR,u)) end
116 in clash(defUseInt) orelse
117 clash(toSL defUseF) orelse
118 clash(toSL defUseOther)
119 end
120
121 fun delaySlotCandidate{jmp,delaySlot=
122 ( I.INSTR(I.CALL _) | I.INSTR(I.Bicc _) | I.INSTR(I.FBfcc _)
123 | I.INSTR(I.Ticc _) | I.INSTR(I.BR _) | I.INSTR(I.JMP _) | I.INSTR(I.JMPL _)
124 | I.INSTR(I.RET _) | I.INSTR(I.BP _) | I.INSTR(I.FCMP _))} = false
125 | delaySlotCandidate{jmp=I.ANNOTATION{i,...},delaySlot} =
126 delaySlotCandidate{jmp=i,delaySlot=delaySlot}
127 | delaySlotCandidate{jmp,delaySlot=I.ANNOTATION{i,...}} =
128 delaySlotCandidate{jmp=jmp,delaySlot=i}
129 | delaySlotCandidate _ = true
130
131 fun setTarget(I.INSTR(I.Bicc{b,a,nop,...}),lab) = I.bicc{b=b,a=a,nop=nop,label=lab}
132 | setTarget(I.INSTR(I.FBfcc{b,a,nop,...}),lab) = I.fbfcc{b=b,a=a,nop=nop,label=lab}
133 | setTarget(I.INSTR(I.BR{rcond,p,r,a,nop,...}),lab) =
134 I.br{rcond=rcond,p=p,r=r,a=a,nop=nop,label=lab}
135 | setTarget(I.INSTR(I.BP{b,p,cc,a,nop,...}),lab) =
136 I.bp{b=b,p=p,cc=cc,a=a,nop=nop,label=lab}
137 | setTarget(I.ANNOTATION{i,a},lab) = I.ANNOTATION{i=setTarget(i,lab),a=a}
138 | setTarget _ = error "setTarget"
139
140 end