1 (***********************************************************************)
5 (* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
7 (* Copyright 2000 Institut National de Recherche en Informatique et *)
8 (* en Automatique. All rights reserved. This file is distributed *)
9 (* under the terms of the Q Public License version 1.0. *)
11 (***********************************************************************)
13 (* $Id: reload.ml 8477 2007-11-06 15:16:56Z frisch $ *)
20 (* Reloading for the AMD64 *)
22 (* Summary of instruction set constraints:
23 "S" means either stack or register, "R" means register only.
24 Operation Res Arg1 Arg2
27 Iconst_int S if 32-bit signed, R otherwise
29 Iconst_symbol (not PIC) S
37 Iintop(Imul|Idiv|mod) R R S
41 Iintop_imm(Iadd, n)/lea R R
42 Iintop_imm(others) S S
47 Ispecific(Ifloatarithmem) R R R
61 class reload = object (self)
63 inherit Reloadgen.reload_generic as super
65 method reload_operation op arg res =
67 Iintop(Iadd|Isub|Iand|Ior|Ixor|Icomp _|Icheckbound) ->
68 (* One of the two arguments can reside in the stack, but not both *)
69 if stackp arg.(0) && stackp arg.(1)
70 then ([|arg.(0); self#makereg arg.(1)|], res)
72 | Iintop_imm(Iadd, _) when arg.(0).loc <> res.(0).loc ->
73 (* This add will be turned into a lea; args and results must be
75 super#reload_operation op arg res
76 | Iintop(Idiv | Imod | Ilsl | Ilsr | Iasr)
78 (* The argument(s) and results can be either in register or on stack *)
79 (* Note: Idiv, Imod: arg(0) and res(0) already forced in regs
80 Ilsl, Ilsr, Iasr: arg(1) already forced in regs *)
82 | Iintop(Imul) | Iaddf | Isubf | Imulf | Idivf ->
83 (* First argument (= result) must be in register, second arg
84 can reside in the stack *)
86 then (let r = self#makereg arg.(0) in ([|r; arg.(1)|], [|r|]))
88 | Ifloatofint | Iintoffloat ->
89 (* Result must be in register, but argument can be on stack *)
90 (arg, (if stackp res.(0) then [| self#makereg res.(0) |] else res))
92 if n <= 0x7FFFFFFFn && n >= -0x80000000n
94 else super#reload_operation op arg res
96 if !pic_code || !Clflags.dlcode
97 then super#reload_operation op arg res
99 | _ -> (* Other operations: all args and results in registers *)
100 super#reload_operation op arg res
102 method reload_test tst arg =
105 (* One of the two arguments can reside on stack *)
106 if stackp arg.(0) && stackp arg.(1)
107 then [| self#makereg arg.(0); arg.(1) |]
109 | Ifloattest(_, _) ->
110 (* Second argument can be on stack, first must be in register *)
112 then [| self#makereg arg.(0); arg.(1) |]
115 (* The argument(s) can be either in register or on stack *)
121 (new reload)#fundecl f