Skip to content

Commit 776a609

Browse files
gretay-jspoechsel
authored andcommitted
Check in Proc if a Cmm.operation is supported by the target (oxcaml#23)
1 parent cbb4ac9 commit 776a609

File tree

10 files changed

+110
-0
lines changed

10 files changed

+110
-0
lines changed

backend/amd64/proc.ml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,3 +379,15 @@ let init () =
379379
num_available_registers.(0) <- 12
380380
end else
381381
num_available_registers.(0) <- 13
382+
383+
let operation_supported = function
384+
| Capply _ | Cextcall _ | Cload _ | Calloc | Cstore _
385+
| Caddi | Csubi | Cmuli | Cmulhi | Cdivi | Cmodi
386+
| Cand | Cor | Cxor | Clsl | Clsr | Casr
387+
| Ccmpi _ | Caddv | Cadda | Ccmpa _
388+
| Cnegf | Cabsf | Caddf | Csubf | Cmulf | Cdivf
389+
| Cfloatofint | Cintoffloat | Ccmpf _
390+
| Craise _
391+
| Ccheckbound
392+
| Cprobe _ | Cprobe_is_enabled _
393+
-> true

backend/arm/proc.ml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,3 +360,15 @@ let assemble_file infile outfile =
360360

361361

362362
let init () = ()
363+
364+
let operation_supported = function
365+
| Capply _ | Cextcall _ | Cload _ | Calloc | Cstore _
366+
| Caddi | Csubi | Cmuli | Cmulhi | Cdivi | Cmodi
367+
| Cand | Cor | Cxor | Clsl | Clsr | Casr
368+
| Ccmpi _ | Caddv | Cadda | Ccmpa _
369+
| Cnegf | Cabsf | Caddf | Csubf | Cmulf | Cdivf
370+
| Cfloatofint | Cintoffloat | Ccmpf _
371+
| Craise _
372+
| Ccheckbound
373+
| Cprobe _ | Cprobe_is_enabled _
374+
-> true

backend/arm64/proc.ml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,3 +308,15 @@ let assemble_file infile outfile =
308308

309309

310310
let init () = ()
311+
312+
let operation_supported = function
313+
| Capply _ | Cextcall _ | Cload _ | Calloc | Cstore _
314+
| Caddi | Csubi | Cmuli | Cmulhi | Cdivi | Cmodi
315+
| Cand | Cor | Cxor | Clsl | Clsr | Casr
316+
| Ccmpi _ | Caddv | Cadda | Ccmpa _
317+
| Cnegf | Cabsf | Caddf | Csubf | Cmulf | Cdivf
318+
| Cfloatofint | Cintoffloat | Ccmpf _
319+
| Craise _
320+
| Ccheckbound
321+
| Cprobe _ | Cprobe_is_enabled _
322+
-> true

backend/cmm_helpers.ml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2543,6 +2543,20 @@ let bigstring_set size unsafe arg1 arg2 arg3 dbg =
25432543
check_bound unsafe size dbg (bigstring_length ba dbg)
25442544
idx (unaligned_set size ba_data idx newval dbg))))))
25452545

2546+
2547+
(* [cextcall] is called from [Cmmgen.transl_ccall] *)
2548+
let cextcall (prim : Primitive.description) args dbg ret ty_args =
2549+
let name = Primitive.native_name prim in
2550+
let default = Cop(Cextcall { name; ret;
2551+
builtin = prim.prim_c_builtin;
2552+
effects = Arbitrary_effects;
2553+
coeffects = Has_coeffects;
2554+
alloc = prim.prim_alloc;
2555+
ty_args },
2556+
args, dbg)
2557+
in
2558+
default
2559+
25462560
(* Symbols *)
25472561

25482562
let cdefine_symbol (symb, (global: Cmmgen_state.is_global)) =

backend/cmm_helpers.mli

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,12 @@ val send :
575575
Lambda.meth_kind -> expression -> expression -> expression list ->
576576
Debuginfo.t -> expression
577577

578+
(** [cextcall prim args dbg type_of_result] returns Cextcall operation
579+
that corresponds to [prim]. If [prim] is a C builtin supported on the
580+
target, returns [Cmm.operation] variant for [prim]'s intrinsics. *)
581+
val cextcall : Primitive.description -> expression list -> Debuginfo.t ->
582+
machtype -> exttype list -> expression
583+
578584
(** Generic Cmm fragments *)
579585

580586
(** Generate generic functions *)

backend/i386/proc.ml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,3 +256,15 @@ let assemble_file infile outfile =
256256
X86_proc.assemble_file infile outfile
257257

258258
let init () = ()
259+
260+
let operation_supported = function
261+
| Capply _ | Cextcall _ | Cload _ | Calloc | Cstore _
262+
| Caddi | Csubi | Cmuli | Cmulhi | Cdivi | Cmodi
263+
| Cand | Cor | Cxor | Clsl | Clsr | Casr
264+
| Ccmpi _ | Caddv | Cadda | Ccmpa _
265+
| Cnegf | Cabsf | Caddf | Csubf | Cmulf | Cdivf
266+
| Cfloatofint | Cintoffloat | Ccmpf _
267+
| Craise _
268+
| Ccheckbound
269+
| Cprobe _ | Cprobe_is_enabled _
270+
-> true

backend/power/proc.ml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,3 +361,15 @@ let assemble_file infile outfile =
361361
" -o " ^ Filename.quote outfile ^ " " ^ Filename.quote infile)
362362

363363
let init () = ()
364+
365+
let operation_supported = function
366+
| Capply _ | Cextcall _ | Cload _ | Calloc | Cstore _
367+
| Caddi | Csubi | Cmuli | Cmulhi | Cdivi | Cmodi
368+
| Cand | Cor | Cxor | Clsl | Clsr | Casr
369+
| Ccmpi _ | Caddv | Cadda | Ccmpa _
370+
| Cnegf | Cabsf | Caddf | Csubf | Cmulf | Cdivf
371+
| Cfloatofint | Cintoffloat | Ccmpf _
372+
| Craise _
373+
| Ccheckbound
374+
| Cprobe _ | Cprobe_is_enabled _
375+
-> true

backend/proc.mli

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,9 @@ val assemble_file: string -> string -> int
8181

8282
(* Called before translating a fundecl. *)
8383
val init : unit -> unit
84+
85+
(** [operation_supported op] returns true when [op]
86+
can be implemented directly with a hardware instruction.
87+
Used in Cmmgen when converting [@@builtin] external calls
88+
to primitive operations. *)
89+
val operation_supported : Cmm.operation -> bool

backend/riscv/proc.ml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,3 +320,15 @@ let assemble_file infile outfile =
320320
(Config.asm ^ " -o " ^ Filename.quote outfile ^ " " ^ Filename.quote infile)
321321

322322
let init () = ()
323+
324+
let operation_supported = function
325+
| Capply _ | Cextcall _ | Cload _ | Calloc | Cstore _
326+
| Caddi | Csubi | Cmuli | Cmulhi | Cdivi | Cmodi
327+
| Cand | Cor | Cxor | Clsl | Clsr | Casr
328+
| Ccmpi _ | Caddv | Cadda | Ccmpa _
329+
| Cnegf | Cabsf | Caddf | Csubf | Cmulf | Cdivf
330+
| Cfloatofint | Cintoffloat | Ccmpf _
331+
| Craise _
332+
| Ccheckbound
333+
| Cprobe _ | Cprobe_is_enabled _
334+
-> true

backend/s390x/proc.ml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,3 +237,15 @@ let assemble_file infile outfile =
237237
" -o " ^ Filename.quote outfile ^ " " ^ Filename.quote infile)
238238

239239
let init () = ()
240+
241+
let operation_supported = function
242+
| Capply _ | Cextcall _ | Cload _ | Calloc | Cstore _
243+
| Caddi | Csubi | Cmuli | Cmulhi | Cdivi | Cmodi
244+
| Cand | Cor | Cxor | Clsl | Clsr | Casr
245+
| Ccmpi _ | Caddv | Cadda | Ccmpa _
246+
| Cnegf | Cabsf | Caddf | Csubf | Cmulf | Cdivf
247+
| Cfloatofint | Cintoffloat | Ccmpf _
248+
| Craise _
249+
| Ccheckbound
250+
| Cprobe _ | Cprobe_is_enabled _
251+
-> true

0 commit comments

Comments
 (0)