Skip to content

Commit 3eddfc1

Browse files
committed
merged
2 parents 11e57fa + 3cc76c0 commit 3eddfc1

File tree

114 files changed

+5985
-2764
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

114 files changed

+5985
-2764
lines changed

.github/workflows/build.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ jobs:
109109
- name: gi
110110
config: --enable-middle-end=flambda2
111111
os: ubuntu-latest
112-
build_ocamlparam: '_,w=-46,regalloc=gi,regalloc-param=SPLIT_LIVE_RANGES:on,regalloc-param=GI_PRIORITY_HEURISTICS:interval-length,regalloc-param=GI_SELECTION_HEURISTICS:first-available,regalloc-param=GI_SPILLING_HEURISTICS:flat-uses,regalloc-validate=1,cfg-cse-optimize=1'
113-
ocamlparam: '_,w=-46,regalloc=gi,regalloc-param=SPLIT_LIVE_RANGES:on,regalloc-param=GI_PRIORITY_HEURISTICS:interval-length,regalloc-param=GI_SELECTION_HEURISTICS:first-available,regalloc-param=GI_SPILLING_HEURISTICS:flat-uses,regalloc-validate=1,cfg-cse-optimize=1'
112+
build_ocamlparam: '_,w=-46,regalloc=gi,regalloc-param=SPLIT_LIVE_RANGES:on,regalloc-param=GI_PRIORITY_HEURISTICS:interval-length,regalloc-param=GI_SELECTION_HEURISTICS:first-available,regalloc-param=GI_SPILLING_HEURISTICS:flat-uses,regalloc-validate=1,cfg-cse-optimize=1,vectorize=1'
113+
ocamlparam: '_,w=-46,regalloc=gi,regalloc-param=SPLIT_LIVE_RANGES:on,regalloc-param=GI_PRIORITY_HEURISTICS:interval-length,regalloc-param=GI_SELECTION_HEURISTICS:first-available,regalloc-param=GI_SPILLING_HEURISTICS:flat-uses,regalloc-validate=1,cfg-cse-optimize=1,vectorize=1'
114114
check_arch: true
115115

116116
- name: cfg-selection

Makefile.common-jst

+5
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ runtime-stdlib: boot-compiler
7878
# Dune does not believe the compiler can make .cmxs unless the following file exists.
7979
@touch _build/runtime_stdlib_install/lib/ocaml_runtime_stdlib/dynlink.cmxa
8080

81+
# This target is a polling version of "make runtime-stdlib"
82+
.PHONY: runtime-stdlib-hacking
83+
runtime-stdlib-hacking: boot-compiler
84+
RUNTIME_DIR=$(RUNTIME_DIR) $(dune) build -w $(ws_runstd) --only-package=ocaml_runtime_stdlib @install
85+
8186
compiler: runtime-stdlib
8287
RUNTIME_DIR=$(RUNTIME_DIR) SYSTEM=$(SYSTEM) MODEL=$(MODEL) \
8388
ASPP="$(ASPP)" ASPPFLAGS="$(ASPPFLAGS)" \

backend/.ocamlformat-enable

+6
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,21 @@ amd64/selection.ml
33
amd64/selection_utils.ml
44
amd64/simd*.ml
55
amd64/stack_check.ml
6+
amd64/vectorize_specific.ml
67
arm64/cfg_selection.ml
78
arm64/selection.ml
89
arm64/selection_utils.ml
910
arm64/simd*.ml
1011
arm64/stack_check.ml
12+
arm64/vectorize_specific.ml
1113
asm_targets/**/*.ml
1214
asm_targets/**/*.mli
1315
cfg/**/*.ml
1416
cfg/**/*.mli
17+
cfg/vectorize.ml
18+
cfg/vectorize.mli
19+
vectorize_utils.ml
20+
vectorize_utils.mli
1521
cfg_selectgen.ml
1622
cfg_selectgen.mli
1723
cfg_selection.mli

backend/amd64/arch.ml

+94-69
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,9 @@ let win64 =
288288
| "win64" | "mingw64" | "cygwin" -> true
289289
| _ -> false
290290

291-
(* Specific operations that are pure *)
292291

292+
(* Specific operations that are pure *)
293+
(* Keep in sync with [Vectorize_specific] *)
293294
let operation_is_pure = function
294295
| Ilea _ | Ibswap _ | Isextend32 | Izextend32
295296
| Ifloatarithmem _ -> true
@@ -300,7 +301,7 @@ let operation_is_pure = function
300301
| Isimd op -> Simd.is_pure op
301302

302303
(* Specific operations that can raise *)
303-
304+
(* Keep in sync with [Vectorize_specific] *)
304305
let operation_can_raise = function
305306
| Ilea _ | Ibswap _ | Isextend32 | Izextend32
306307
| Ifloatarithmem _
@@ -309,6 +310,7 @@ let operation_can_raise = function
309310
| Istore_int (_, _, _) | Ioffset_loc (_, _)
310311
| Icldemote _ | Iprefetch _ -> false
311312

313+
(* Keep in sync with [Vectorize_specific] *)
312314
let operation_allocates = function
313315
| Ilea _ | Ibswap _ | Isextend32 | Izextend32
314316
| Ifloatarithmem _
@@ -410,84 +412,107 @@ let equal_specific_operation left right =
410412

411413
(* addressing mode functions *)
412414

413-
let compare_addressing_mode_without_displ (addressing_mode_1: addressing_mode) (addressing_mode_2 : addressing_mode) =
414-
(* Ignores displ when comparing to show that it is possible to calculate the offset *)
415+
let equal_addressing_mode_without_displ (addressing_mode_1: addressing_mode) (addressing_mode_2 : addressing_mode) =
416+
(* Ignores [displ] when comparing to show that it is possible to calculate the offset,
417+
see [addressing_offset_in_bytes]. *)
415418
match addressing_mode_1, addressing_mode_2 with
416419
| Ibased (symbol1, global1, _), Ibased (symbol2, global2, _) -> (
417420
match global1, global2 with
418421
| Global, Global | Local, Local ->
419-
String.compare symbol1 symbol2
420-
| Global, Local -> -1
421-
| Local, Global -> 1)
422-
| Ibased _, _ -> -1
423-
| _, Ibased _ -> 1
424-
| Iindexed _, Iindexed _ -> 0
425-
| Iindexed _, _ -> -1
426-
| _, Iindexed _ -> 1
427-
| Iindexed2 _, Iindexed2 _ -> 0
428-
| Iindexed2 _, _ -> -1
429-
| _, Iindexed2 _ -> 1
430-
| Iscaled (scale1, _), Iscaled (scale2, _) -> Int.compare scale1 scale2
431-
| Iscaled _, _ -> -1
432-
| _, Iscaled _ -> 1
422+
String.equal symbol1 symbol2
423+
| (Global | Local), _ -> false)
424+
| Iindexed _, Iindexed _ -> true
425+
| Iindexed2 _, Iindexed2 _ -> true
426+
| Iscaled (scale1, _), Iscaled (scale2, _) -> Int.equal scale1 scale2
433427
| Iindexed2scaled (scale1, _), Iindexed2scaled (scale2, _) ->
434-
Int.compare scale1 scale2
435-
436-
let compare_addressing_mode_displ (addressing_mode_1: addressing_mode) (addressing_mode_2 : addressing_mode) =
437-
match addressing_mode_1, addressing_mode_2 with
438-
| Ibased (symbol1, global1, n1), Ibased (symbol2, global2, n2) -> (
439-
match global1, global2 with
440-
| Global, Global | Local, Local ->
441-
if symbol1 = symbol2 then Some (Int.compare n1 n2) else None
442-
| Global, Local | Local, Global -> None)
443-
| Iindexed n1, Iindexed n2 -> Some (Int.compare n1 n2)
444-
| Iindexed2 n1, Iindexed2 n2 -> Some (Int.compare n1 n2)
445-
| Iscaled (scale1, n1), Iscaled (scale2, n2) ->
446-
let scale_compare = scale1 - scale2 in
447-
if scale_compare = 0 then Some (Int.compare n1 n2) else None
448-
| Iindexed2scaled (scale1, n1), Iindexed2scaled (scale2, n2) ->
449-
let scale_compare = scale1 - scale2 in
450-
if scale_compare = 0 then Some (Int.compare n1 n2) else None
451-
| Ibased _, _ -> None
452-
| Iindexed _, _ -> None
453-
| Iindexed2 _, _ -> None
454-
| Iscaled _, _ -> None
455-
| Iindexed2scaled _, _ -> None
456-
457-
let addressing_offset_in_bytes (addressing_mode_1: addressing_mode) (addressing_mode_2 : addressing_mode) =
428+
Int.equal scale1 scale2
429+
| (Ibased _ | Iindexed _ | Iindexed2 _ | Iscaled _ | Iindexed2scaled _), _ -> false
430+
431+
let addressing_offset_in_bytes
432+
(addressing_mode_1: addressing_mode)
433+
(addressing_mode_2 : addressing_mode)
434+
~arg_offset_in_bytes
435+
args_1
436+
args_2
437+
=
438+
let address_arg_offset_in_bytes index =
439+
arg_offset_in_bytes args_1.(index) args_2.(index)
440+
in
458441
match addressing_mode_1, addressing_mode_2 with
459-
| Ibased (symbol1, global1, n1), Ibased (symbol2, global2, n2) -> (
460-
match global1, global2 with
461-
| Global, Global | Local, Local ->
462-
if symbol1 = symbol2 then Some (n2 - n1) else None
463-
| Global, Local | Local, Global -> None)
464-
| Iindexed n1, Iindexed n2 -> Some (n2 - n1)
465-
| Iindexed2 n1, Iindexed2 n2 -> Some (n2 - n1)
442+
| Ibased (symbol1, global1, n1), Ibased (symbol2, global2, n2) ->
443+
(* symbol + displ *)
444+
(match global1, global2 with
445+
| Global, Global | Local, Local ->
446+
if String.equal symbol1 symbol2 then Some (n2 - n1) else None
447+
| Global, Local | Local, Global -> None)
448+
| Iindexed n1, Iindexed n2 ->
449+
(* reg + displ *)
450+
(match address_arg_offset_in_bytes 0 with
451+
| Some base_off -> Some (base_off + (n2 - n1))
452+
| None -> None)
453+
| Iindexed2 n1, Iindexed2 n2 ->
454+
(* reg + reg + displ *)
455+
(match address_arg_offset_in_bytes 0, address_arg_offset_in_bytes 1 with
456+
| Some arg0_offset, Some arg1_offset ->
457+
Some (arg0_offset + arg1_offset + (n2 - n1))
458+
| (None, _|Some _, _) -> None)
466459
| Iscaled (scale1, n1), Iscaled (scale2, n2) ->
467-
let scale_compare = scale1 - scale2 in
468-
if scale_compare = 0 then Some (n2 - n1) else None
460+
(* reg * scale + displ *)
461+
if not (Int.compare scale1 scale2 = 0) then None
462+
else
463+
(match address_arg_offset_in_bytes 0 with
464+
| Some offset -> Some ((offset * scale1) + (n2 - n1))
465+
| None -> None)
469466
| Iindexed2scaled (scale1, n1), Iindexed2scaled (scale2, n2) ->
470-
let scale_compare = scale1 - scale2 in
471-
if scale_compare = 0 then Some (n2 - n1) else None
467+
(* reg + reg * scale + displ *)
468+
if not (Int.compare scale1 scale2 = 0) then None else
469+
(match address_arg_offset_in_bytes 0, address_arg_offset_in_bytes 1 with
470+
| Some arg0_offset, Some arg1_offset ->
471+
Some (arg0_offset + (arg1_offset*scale1) + (n2 - n1))
472+
| (None, _|Some _, _) -> None)
472473
| Ibased _, _ -> None
473474
| Iindexed _, _ -> None
474475
| Iindexed2 _, _ -> None
475476
| Iscaled _, _ -> None
476477
| Iindexed2scaled _, _ -> None
477478

478-
let can_cross_loads_or_stores (specific_operation : specific_operation) =
479-
match specific_operation with
480-
| Ilea _ | Istore_int _ | Ioffset_loc _ | Ifloatarithmem _ | Isimd _ | Icldemote _
481-
| Iprefetch _ ->
482-
false
483-
| Ibswap _ | Isextend32 | Izextend32 | Irdtsc | Irdpmc | Ilfence | Isfence | Imfence
484-
| Ipause ->
485-
true
486-
487-
let may_break_alloc_freshness (specific_operation : specific_operation) =
488-
match specific_operation with
489-
| Isimd _ -> true
490-
| Ilea _ | Istore_int _ | Ioffset_loc _ | Ifloatarithmem _ | Ibswap _ | Isextend32
491-
| Izextend32 | Irdtsc | Irdpmc | Ilfence | Isfence | Imfence | Ipause | Icldemote _
492-
| Iprefetch _ ->
493-
false
479+
let isomorphic_specific_operation op1 op2 =
480+
match op1, op2 with
481+
| Ilea a1, Ilea a2 -> equal_addressing_mode_without_displ a1 a2
482+
| Istore_int (_n1, a1, is_assign1), Istore_int (_n2, a2, is_assign2) ->
483+
equal_addressing_mode_without_displ a1 a2 && Bool.equal is_assign1 is_assign2
484+
| Ioffset_loc (_n1, a1), Ioffset_loc (_n2, a2) ->
485+
equal_addressing_mode_without_displ a1 a2
486+
| Ifloatarithmem (w1, o1, a1), Ifloatarithmem (w2, o2, a2) ->
487+
Cmm.equal_float_width w1 w2 &&
488+
equal_float_operation o1 o2 &&
489+
equal_addressing_mode_without_displ a1 a2
490+
| Ibswap { bitwidth = left }, Ibswap { bitwidth = right } ->
491+
Int.equal (int_of_bswap_bitwidth left) (int_of_bswap_bitwidth right)
492+
| Isextend32, Isextend32 ->
493+
true
494+
| Izextend32, Izextend32 ->
495+
true
496+
| Irdtsc, Irdtsc ->
497+
true
498+
| Irdpmc, Irdpmc ->
499+
true
500+
| Ilfence, Ilfence ->
501+
true
502+
| Isfence, Isfence ->
503+
true
504+
| Imfence, Imfence ->
505+
true
506+
| Ipause, Ipause -> true
507+
| Icldemote x, Icldemote x' -> equal_addressing_mode_without_displ x x'
508+
| Iprefetch { is_write = left_is_write; locality = left_locality; addr = left_addr; },
509+
Iprefetch { is_write = right_is_write; locality = right_locality; addr = right_addr; } ->
510+
Bool.equal left_is_write right_is_write
511+
&& equal_prefetch_temporal_locality_hint left_locality right_locality
512+
&& equal_addressing_mode_without_displ left_addr right_addr
513+
| Isimd l, Isimd r ->
514+
Simd.equal_operation l r
515+
| (Ilea _ | Istore_int _ | Ioffset_loc _ | Ifloatarithmem _ | Ibswap _ |
516+
Isextend32 | Izextend32 | Irdtsc | Irdpmc | Ilfence | Isfence | Imfence |
517+
Ipause | Isimd _ | Icldemote _ | Iprefetch _), _ ->
518+
false

backend/amd64/arch.mli

+9-8
Original file line numberDiff line numberDiff line change
@@ -140,14 +140,15 @@ val operation_allocates : specific_operation -> bool
140140
val float_cond_and_need_swap
141141
: Lambda.float_comparison -> X86_ast.float_condition * bool
142142

143+
val isomorphic_specific_operation : specific_operation -> specific_operation -> bool
143144
(* addressing mode functions *)
144145

145-
val compare_addressing_mode_without_displ : addressing_mode -> addressing_mode -> int
146+
val equal_addressing_mode_without_displ : addressing_mode -> addressing_mode -> bool
146147

147-
val compare_addressing_mode_displ : addressing_mode -> addressing_mode -> int option
148-
149-
val addressing_offset_in_bytes : addressing_mode -> addressing_mode -> int option
150-
151-
val can_cross_loads_or_stores : specific_operation -> bool
152-
153-
val may_break_alloc_freshness : specific_operation -> bool
148+
val addressing_offset_in_bytes
149+
: addressing_mode
150+
-> addressing_mode
151+
-> arg_offset_in_bytes:('a -> 'a -> int option)
152+
-> 'a array
153+
-> 'a array
154+
-> int option

0 commit comments

Comments
 (0)