| 1 |
(* |
| 2 |
* This module describes how to fill delay slots on the HPPA |
| 3 |
*) |
| 4 |
|
| 5 |
functor HppaDelaySlots |
| 6 |
(structure I : HPPAINSTR |
| 7 |
structure P : INSN_PROPERTIES (* where I = I *) |
| 8 |
where type I.addressing_mode = I.addressing_mode |
| 9 |
and type I.ea = I.ea |
| 10 |
and type I.instr = I.instr |
| 11 |
and type I.instruction = I.instruction |
| 12 |
and type I.operand = I.operand |
| 13 |
) : DELAY_SLOT_PROPERTIES = |
| 14 |
struct |
| 15 |
structure I = I |
| 16 |
structure C = I.C |
| 17 |
structure SL = CellsBasis.SortedCells |
| 18 |
|
| 19 |
fun error msg = MLRiscErrorMsg.error("HppaDelaySlotProps",msg) |
| 20 |
|
| 21 |
datatype delay_slot = D_NONE | D_ERROR | D_ALWAYS | D_TAKEN | D_FALLTHRU |
| 22 |
|
| 23 |
val delaySlotSize = 4 |
| 24 |
|
| 25 |
(* |
| 26 |
* On the HP, things are quite complicated: |
| 27 |
* |
| 28 |
* For conditional branches: |
| 29 |
* ------------------------- |
| 30 |
* Branch direction |
| 31 |
* Forward Backward |
| 32 |
* Nullify bit on Nullify if branch taken Nullify if branch not-taken |
| 33 |
* Nullify bit off Delay slot active Delay slot active |
| 34 |
* |
| 35 |
* For unconditional branches: |
| 36 |
* --------------------------- |
| 37 |
* |
| 38 |
* Nullify bit on Delay slot nullified |
| 39 |
* Nullify bit off Delay slot active |
| 40 |
*) |
| 41 |
|
| 42 |
fun delaySlot{instr, backward} = |
| 43 |
case instr of |
| 44 |
I.INSTR(I.BCOND{nop,n,...}) => |
| 45 |
{nop=nop, n=n, nOn=if backward then D_TAKEN else D_FALLTHRU, |
| 46 |
nOff=D_ALWAYS} |
| 47 |
| I.INSTR(I.BCONDI{nop,n,...}) => |
| 48 |
{nop=nop, n=n, nOn=if backward then D_TAKEN else D_FALLTHRU, |
| 49 |
nOff=D_ALWAYS} |
| 50 |
| I.INSTR(I.BB{nop,n,...}) => |
| 51 |
{nop=nop, n=n, nOn=if backward then D_TAKEN else D_FALLTHRU, |
| 52 |
nOff=D_ALWAYS} |
| 53 |
| I.INSTR(I.B{n,...}) => {nop=false, n=n, nOn=D_NONE, nOff=D_ALWAYS} |
| 54 |
| I.INSTR(I.LONGJUMP{n,...}) => {nop=false, n=n, nOn=D_NONE, nOff=D_ALWAYS} |
| 55 |
| I.INSTR(I.BV{n,...}) => {nop=false, n=n, nOn=D_NONE, nOff=D_ALWAYS} |
| 56 |
| I.INSTR(I.BE{n,...}) => {nop=false, n=n, nOn=D_NONE, nOff=D_ALWAYS} |
| 57 |
| I.INSTR(I.BLR{n,...}) => {nop=false, n=n, nOn=D_NONE, nOff=D_ALWAYS} |
| 58 |
| I.INSTR(I.BL{n,...}) => {nop=false, n=n, nOn=D_NONE, nOff=D_ALWAYS} |
| 59 |
| I.ANNOTATION{i,...} => delaySlot{instr=i,backward=backward} |
| 60 |
| _ => {n=false,nOn=D_ERROR,nOff=D_NONE,nop=false} |
| 61 |
|
| 62 |
fun enableDelaySlot{instr, n, nop} = |
| 63 |
case (instr,nop) of |
| 64 |
(I.INSTR(I.BCOND{cmp,bc,r1,r2,t,f,...}),_) => |
| 65 |
I.bcond{cmp=cmp,bc=bc,nop=nop,n=n,r1=r1,r2=r2,t=t,f=f} |
| 66 |
| (I.INSTR(I.BCONDI{cmpi,bc,i,r2,t,f,...}),_) => |
| 67 |
I.bcondi{cmpi=cmpi,bc=bc,nop=nop,n=n,i=i,r2=r2,t=t,f=f} |
| 68 |
| (I.INSTR(I.BB{bc,p,r,t,f,...}),_) => |
| 69 |
I.bb{bc=bc,p=p,nop=nop,n=n,r=r,t=t,f=f} |
| 70 |
| (I.INSTR(I.B{lab,...}),false) => I.b{lab=lab,n=n} |
| 71 |
| (I.INSTR(I.BV{labs,b,x,...}),false) => I.bv{labs=labs,b=b,x=x,n=n} |
| 72 |
| (I.INSTR(I.BE{labs,b,d,sr,...}),false) => I.be{labs=labs,b=b,d=d,sr=sr,n=n} |
| 73 |
| (I.INSTR(I.BLR{x,t,labs,...}),false) => I.blr{x=x,t=t,labs=labs,n=n} |
| 74 |
| (I.INSTR(I.BL{lab,t,defs,uses,cutsTo,mem,...}),false) => |
| 75 |
I.bl{lab=lab,t=t,defs=defs,uses=uses,cutsTo=cutsTo,mem=mem,n=n} |
| 76 |
| (I.INSTR(I.LONGJUMP{lab,tmp,tmpLab,...}),false) => |
| 77 |
I.longjump{lab=lab,tmp=tmp,tmpLab=tmpLab,n=n} |
| 78 |
| (I.ANNOTATION{i,a},_) => |
| 79 |
I.ANNOTATION{i=enableDelaySlot{instr=i,n=n,nop=nop},a=a} |
| 80 |
| _ => error "enableDelaySlot" |
| 81 |
|
| 82 |
val defUseI = P.defUse CellsBasis.GP |
| 83 |
val defUseF = P.defUse CellsBasis.FP |
| 84 |
val zeroR = Option.valOf(C.zeroReg CellsBasis.GP) |
| 85 |
|
| 86 |
fun conflict{src=i,dst=j} = |
| 87 |
let fun clash(defUse) = |
| 88 |
let val (di,ui) = defUse i |
| 89 |
val (dj,uj) = defUse j |
| 90 |
in SL.nonEmptyIntersection(di,uj) orelse |
| 91 |
SL.nonEmptyIntersection(di,dj) orelse |
| 92 |
SL.nonEmptyIntersection(ui,dj) |
| 93 |
end |
| 94 |
fun defUseInt i = |
| 95 |
let val (d,u) = defUseI i |
| 96 |
val d = SL.uniq d |
| 97 |
val u = SL.uniq u |
| 98 |
(* no dependence on register 0! *) |
| 99 |
in (SL.rmv(zeroR,d), SL.rmv(zeroR,u)) end |
| 100 |
fun defUseReal i = |
| 101 |
let val (d,u) = defUseF i |
| 102 |
val d = SL.uniq d |
| 103 |
val u = SL.uniq u |
| 104 |
in (d,u) end |
| 105 |
in clash(defUseInt) orelse clash(defUseReal) |
| 106 |
end |
| 107 |
|
| 108 |
fun delaySlotCandidate{jmp,delaySlot= |
| 109 |
( I.INSTR(I.BCOND _) | I.INSTR(I.BCONDI _) | I.INSTR(I.BB _) | I.INSTR(I.FBRANCH _) |
| 110 |
| I.INSTR(I.BV _) | I.INSTR(I.BE _) | I.INSTR(I.COMCLR_LDO _) | I.INSTR(I.COMICLR_LDO _) |
| 111 |
| I.INSTR(I.B _) | I.INSTR(I.LONGJUMP _) | I.INSTR(I.BLR _) | I.INSTR(I.BL _) |
| 112 |
| I.INSTR(I.BLE _))} = false |
| 113 |
| delaySlotCandidate{jmp=I.ANNOTATION{i,...},delaySlot} = |
| 114 |
delaySlotCandidate{jmp=i,delaySlot=delaySlot} |
| 115 |
| delaySlotCandidate{jmp,delaySlot=I.ANNOTATION{i,...}} = |
| 116 |
delaySlotCandidate{jmp=jmp,delaySlot=i} |
| 117 |
| delaySlotCandidate _ = true |
| 118 |
|
| 119 |
fun setTarget(I.INSTR(I.BCOND{n,nop,r1,r2,cmp,bc,t,f,...}), lab) = |
| 120 |
I.bcond{cmp=cmp,bc=bc,nop=nop,n=n,r1=r1,r2=r2,t=lab,f=f} |
| 121 |
| setTarget(I.INSTR(I.BCONDI{n,nop,i,r2,cmpi,bc,t,f,...}), lab) = |
| 122 |
I.bcondi{cmpi=cmpi,bc=bc,nop=nop,n=n,i=i,r2=r2,t=lab,f=f} |
| 123 |
| setTarget(I.INSTR(I.BB{bc,r,p,n,nop,t,f,...}), lab) = |
| 124 |
I.bb{bc=bc,p=p,nop=nop,n=n,r=r,t=lab,f=f} |
| 125 |
| setTarget(I.INSTR(I.B{n,...}), lab) = I.b{n=n,lab=lab} |
| 126 |
| setTarget(I.INSTR(I.LONGJUMP{n, tmp, tmpLab, ...}), lab) = |
| 127 |
I.longjump{n=n, tmp=tmp, tmpLab=tmpLab, lab=lab} |
| 128 |
| setTarget(I.ANNOTATION{i,a},lab) = I.ANNOTATION{i=setTarget(i,lab),a=a} |
| 129 |
| setTarget _ = error "setTarget" |
| 130 |
|
| 131 |
end |