Debian Codegraph @

lib/mlrisc-lib/MLRISC/hppa/ra/hppaSpillInstr.sml

raw
1 (* hppaSpillInstr.sml
2 *
3 * COPYRIGHT (c) 2002 Bell Labs, Lucent Technologies
4 *
5 * Hppa instructions to emit when spilling an instruction.
6 *)
7
8 functor HppaSpillInstr(Instr : HPPAINSTR) : ARCH_SPILL_INSTR = struct
9 structure I = Instr
10 structure C = I.C
11 structure Rewrite = HppaRewrite(I)
12 structure CB=CellsBasis
13
14 fun error msg = MLRiscErrorMsg.error ("HppaSpillInstr", msg)
15
16 val tmpR = I.C.asmTmpR
17 fun storeToEA CB.GP (reg, I.Displace{base, disp, mem}) =
18 [I.store{st=I.STW, b=base, d=I.LabExp(disp, I.F), r=reg, mem=mem}]
19 | storeToEA CB.FP (reg, I.Displace{base, disp, mem}) =
20 [I.ldil{i=I.HILabExp(disp, I.F), t=tmpR},
21 I.ldo{i=I.LOLabExp(disp, I.F), b=tmpR, t=tmpR},
22 I.fstorex{fstx=I.FSTDX, b=base, x=tmpR, r=reg, mem=mem}]
23 | storeToEA _ _ = error "storeToEA"
24
25 fun loadFromEA CB.GP (reg, I.Displace{base, disp, mem}) =
26 [I.loadi{li=I.LDW, r=base, i=I.LabExp(disp,I.F), t=reg, mem=mem}]
27 | loadFromEA CB.FP (reg, I.Displace{base, disp, mem}) =
28 [I.ldil{i=I.HILabExp(disp, I.F), t=tmpR},
29 I.ldo{i=I.LOLabExp(disp, I.F), b=tmpR, t=tmpR},
30 I.floadx{flx=I.FLDDX, b=base, x=tmpR, t=reg, mem=mem}]
31 | loadFromEA _ _ = error "loadFromEA"
32
33 fun spillToEA ck reg_ea =
34 {code=storeToEA ck reg_ea, proh=[], newReg=NONE}
35 fun reloadFromEA ck reg_ea =
36 {code=loadFromEA ck reg_ea, proh=[], newReg=NONE}
37
38 (* spill a register to spillLoc *)
39 fun spillR (instr, reg, ea) = let
40 val newR = C.newReg()
41 val instr' = Rewrite.rewriteDef(instr, reg, newR)
42 in
43 {code=instr' :: storeToEA CB.GP (newR, ea),
44 proh=[newR],
45 newReg=SOME newR}
46 end
47
48 fun spillF (instr, reg, ea) = let
49 val newR = C.newFreg()
50 val instr' = Rewrite.frewriteDef(instr, reg, newR)
51 in
52 {code=instr' :: storeToEA CB.FP (newR, ea),
53 proh=[newR],
54 newReg=SOME newR}
55 end
56
57 (* reload a register from spillLoc *)
58 fun reloadR(instr, reg, ea) = let
59 val newR = C.newReg()
60 val instr' = Rewrite.rewriteUse(instr, reg, newR)
61 in
62 {code= loadFromEA CB.GP (newR, ea) @ [instr'],
63 proh=[newR],
64 newReg=SOME newR}
65 end
66
67 fun reloadF(instr, reg, ea) = let
68 val newR = C.newFreg()
69 val instr' = Rewrite.frewriteUse(instr, reg, newR)
70 in
71 {code=loadFromEA CB.FP (newR, ea) @ [instr'],
72 proh=[newR],
73 newReg=SOME newR}
74 end
75
76 fun spill CellsBasis.GP = spillR
77 | spill CellsBasis.FP = spillF
78 | spill _ = error "spill"
79
80 fun reload CellsBasis.GP = reloadR
81 | reload CellsBasis.FP = reloadF
82 | reload _ = error "reload"
83 end
84