File: alphaSpillInstr.sml

package info (click to toggle)
mlton 20210117%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 58,464 kB
  • sloc: ansic: 27,682; sh: 4,455; asm: 3,569; lisp: 2,879; makefile: 2,347; perl: 1,169; python: 191; pascal: 68; javascript: 7
file content (81 lines) | stat: -rw-r--r-- 2,401 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
(* alphaSpillInstr.sml
 *
 * COPYRIGHT (c) 2002 Bell Labs, Lucent Technologies
 *
 * Alpha instructions to emit when spilling an instruction.
 *)

functor AlphaSpillInstr(Instr : ALPHAINSTR) : ARCH_SPILL_INSTR = struct
  structure I = Instr
  structure C = I.C
  structure CB = CellsBasis
 
  structure Rewrite = AlphaRewrite(I)

  fun error msg = MLRiscErrorMsg.error ("AlphaSpillInstr", msg)

  fun storeAtEA CB.GP (reg, I.Displace{base, disp, mem}) = 
       I.store{stOp=I.STL, b=base, d=I.LABop disp, r=reg, mem=mem}
    | storeAtEA CB.FP (reg, I.Displace{base, disp, mem}) =  
       I.fstore{stOp=I.STT, b=base, d=I.LABop disp, r=reg, mem=mem}
    | storeAtEA _ _ = error "storeAtEA"

  fun loadFromEA CB.GP (reg, I.Displace{base, disp, mem}) =
       I.load{ldOp=I.LDL, r=reg, b=base, d=I.LABop disp, mem=mem}
    | loadFromEA CB.FP (reg, I.Displace{base, disp, mem}) = 
       I.fload{ldOp=I.LDT, r=reg, b=base, d=I.LABop disp, mem=mem}
    | loadFromEA _ _ = error "loadFromEA"

  fun spillToEA ck reg_ea = 
      {code=[storeAtEA ck reg_ea], proh=[], newReg=NONE}

  fun reloadFromEA ck reg_ea =
      {code=[loadFromEA ck reg_ea], proh=[], newReg=NONE}

 (* spill a register to spillLoc *)
  fun spillR (instr, reg, spillLoc) = let
    val newR = C.newReg()
    val instr' = Rewrite.rewriteDef(instr, reg, newR)
  in 
      {code=[instr', storeAtEA CB.GP (newR, spillLoc)],
       proh=[newR],
       newReg=SOME newR}
  end

  fun spillF (instr, reg, spillLoc) = let
    val newR = C.newFreg()
    val instr' = Rewrite.frewriteDef(instr, reg, newR)
  in 
      {code=[instr', storeAtEA CB.FP (newR, spillLoc)],
       proh=[newR],
       newReg=SOME newR}
  end

 (* reload a register from spillLoc *)
  fun reloadR(instr, reg, spillLoc) = let
    val newR = C.newReg()
    val instr' = Rewrite.rewriteUse(instr, reg, newR)
  in
      {code=[loadFromEA CB.GP (newR, spillLoc), instr'],
       proh=[newR],
       newReg=SOME newR}
  end

  fun reloadF(instr, reg, spillLoc) = let
    val newR = C.newFreg()
    val instr' = Rewrite.frewriteUse(instr, reg, newR)
  in
      {code=[loadFromEA CB.FP (newR, spillLoc), instr'],
       proh=[newR],
       newReg=SOME newR}
  end

  fun spill CellsBasis.GP = spillR
    | spill CellsBasis.FP = spillF
    | spill _ = error "spill"

  fun reload CellsBasis.GP = reloadR
    | reload CellsBasis.FP = reloadF
    | reload _ = error "reload"
end