| 1 |
functor MIPSDelaySlots |
| 2 |
(structure I : MIPSINSTR |
| 3 |
structure P : INSN_PROPERTIES where I = I |
| 4 |
) : DELAY_SLOT_PROPERTIES = |
| 5 |
struct |
| 6 |
structure I = I |
| 7 |
structure C = I.C |
| 8 |
structure SL = C.SortedCells |
| 9 |
|
| 10 |
fun error msg = MLRiscErrorMsg.error("MIPSDelaySlotProps",msg) |
| 11 |
|
| 12 |
datatype delay_slot = D_NONE | D_ERROR | D_ALWAYS | D_TAKEN | D_FALLTHRU |
| 13 |
|
| 14 |
val delaySlotSize = 4 |
| 15 |
|
| 16 |
fun delaySlot{instr, backward} = |
| 17 |
case instr of |
| 18 |
I.J{nop, ...} => {n=false,nOn=D_ALWAYS,nOff=D_ERROR,nop=nop} |
| 19 |
| I.JR{nop, ...} => {n=false,nOn=D_ALWAYS,nOff=D_ERROR,nop=nop} |
| 20 |
| I.JAL{nop, ...} => {n=false,nOn=D_ALWAYS,nOff=D_ERROR,nop=nop} |
| 21 |
| I.JALR{nop, ...} => {n=false,nOn=D_ALWAYS,nOff=D_ERROR,nop=nop} |
| 22 |
| I.BRANCH{nop, ...} => {n=false,nOn=D_ALWAYS,nOff=D_ERROR,nop=nop} |
| 23 |
| I.FBRANCH{nop, ...} => {n=false,nOn=D_ALWAYS,nOff=D_ERROR,nop=nop} |
| 24 |
| I.ANNOTATION{i,...} => delaySlot{instr=i,backward=backward} |
| 25 |
| _ => {n=false,nOn=D_ERROR,nOff=D_NONE,nop=false} |
| 26 |
|
| 27 |
fun enableDelaySlot{instr, n=true, nop} = |
| 28 |
error "enableDelaySlot: can't nullify" |
| 29 |
| enableDelaySlot{instr, n, nop} = |
| 30 |
case instr of |
| 31 |
I.J{lab, ...} => I.J{lab=lab,nop=nop} |
| 32 |
| I.JR{rs, labels, ...} => I.JR{rs=rs,labels=labels,nop=nop} |
| 33 |
| I.JAL{lab, defs, uses, cutsTo, mem, ...} => |
| 34 |
I.JAL{lab=lab, defs=defs, uses=uses, cutsTo=cutsTo, mem=mem, nop=nop} |
| 35 |
| I.JALR{rs, rt, defs, uses, cutsTo, mem, ...} => |
| 36 |
I.JALR{rs=rs, rt=rt, |
| 37 |
defs=defs, uses=uses, cutsTo=cutsTo, mem=mem, nop=nop} |
| 38 |
| I.RET _ => I.RET{nop=nop} |
| 39 |
| I.BRANCH{likely, cond, rs, rt, lab, ...} => |
| 40 |
I.BRANCH{likely=likely, cond=cond, rs=rs, rt=rt, lab=lab, nop=nop} |
| 41 |
| I.FBRANCH{likely, fbranch, cc, lab, ...} => |
| 42 |
I.FBRANCH{likely=likely, fbranch=fbranch, cc=cc, lab=lab, nop=nop} |
| 43 |
| I.ANNOTATION{i,a} => |
| 44 |
I.ANNOTATION{i=enableDelaySlot{instr=i,n=n,nop=nop},a=a} |
| 45 |
| _ => error "enableDelaySlot" |
| 46 |
|
| 47 |
val defUseI = P.defUse C.GP |
| 48 |
val defUseF = P.defUse C.FP |
| 49 |
val zeroR = Option.valOf(C.zeroReg C.GP) |
| 50 |
fun conflict{src=i,dst=j} = error "conflict" |
| 51 |
|
| 52 |
fun delaySlotCandidate |
| 53 |
{jmp, delaySlot=(I.J _ | I.JR _ | I.JAL _ | I.JALR _ |
| 54 |
| I.RET _ | I.BRANCH _ | I.FBRANCH _)} = false |
| 55 |
| delaySlotCandidate{jmp=I.ANNOTATION{i,...},delaySlot} = |
| 56 |
delaySlotCandidate{jmp=i,delaySlot=delaySlot} |
| 57 |
| delaySlotCandidate{jmp,delaySlot=I.ANNOTATION{i,...}} = |
| 58 |
delaySlotCandidate{jmp=jmp,delaySlot=i} |
| 59 |
| delaySlotCandidate _ = true |
| 60 |
|
| 61 |
fun setTarget(I.ANNOTATION{i,a},lab) = I.ANNOTATION{i=setTarget(i,lab),a=a} |
| 62 |
| setTarget _ = error "setTarget" |
| 63 |
|
| 64 |
end |