The unpac monorepo manager self-hosting as a monorepo using unpac
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request #13667 from tmcgilchrist/11162-rebased

instr_size fixes for arm64

authored by

Gabriel Scherer and committed by
GitHub
930d7e24 b5420186

+107 -17
+2 -2
.github/workflows/build.yml
··· 59 59 '${{ github.event.repository.full_name }}' 60 60 - name: Configure tree 61 61 run: | 62 - MAKE_ARG=-j CONFIG_ARG='--enable-flambda --enable-cmm-invariants --enable-dependency-generation --enable-native-toplevel' OCAMLRUNPARAM=b,v=0 bash -xe tools/ci/actions/runner.sh configure 62 + MAKE_ARG=-j CONFIG_ARG='--enable-flambda --enable-cmm-invariants --enable-codegen-invariants --enable-dependency-generation --enable-native-toplevel' OCAMLRUNPARAM=b,v=0 bash -xe tools/ci/actions/runner.sh configure 63 63 - name: Build 64 64 run: | 65 65 MAKE_ARG=-j bash -xe tools/ci/actions/runner.sh build ··· 188 188 189 189 - name: configure tree 190 190 run: | 191 - CONFIG_ARG='${{ matrix.config_arg }}' MAKE_ARG=-j bash -xe tools/ci/actions/runner.sh configure 191 + CONFIG_ARG='--enable-codegen-invariants ${{ matrix.config_arg }}' MAKE_ARG=-j bash -xe tools/ci/actions/runner.sh configure 192 192 - name: Build 193 193 run: | 194 194 MAKE_ARG=-j bash -xe tools/ci/actions/runner.sh build
+4
Changes
··· 91 91 (Pierre Chambart, review by Gabriel Scherer and Xavier Leroy, 92 92 report by Patrick Nicodemus) 93 93 94 + - #13667: (originally #11162) Fix instr_size computation on arm64. 95 + (Stephen Dolan and Tim McGilchrist, review by Xavier Leroy 96 + and David Allsopp) 97 + 94 98 ### Standard library: 95 99 96 100 - #13729: Add Either.retract
+1
Makefile.config.in
··· 213 213 FLAMBDA=@flambda@ 214 214 WITH_FLAMBDA_INVARIANTS=@flambda_invariants@ 215 215 WITH_CMM_INVARIANTS=@cmm_invariants@ 216 + WITH_CODEGEN_INVARIANTS=@codegen_invariants@ 216 217 FORCE_SAFE_STRING=true 217 218 DEFAULT_SAFE_STRING=true 218 219 WINDOWS_UNICODE=@windows_unicode@
+63 -14
asmcomp/arm64/emit.mlp
··· 407 407 max_offset 408 408 end 409 409 410 - module BR = Branch_relaxation.Make (struct 410 + module Size = struct 411 411 (* CR-someday mshinwell: B and BL have +/- 128Mb ranges; for the moment we 412 412 assume we will never exceed this. It would seem to be most likely to 413 413 occur for branches between functions; in this case, the linker should be ··· 449 449 450 450 let offset_pc_at_branch = 0 451 451 452 + let addsub_size n = 453 + let m = abs n in 454 + assert (m < 0x1_000_000); 455 + let ml = m land 0xFFF and mh = m land 0xFFF_000 in 456 + max 1 ((if mh <> 0 then 1 else 0) + 457 + (if ml <> 0 then 1 else 0)) 458 + 459 + let stack_adj_size n = 460 + (* see emit_stack_adjustment *) 461 + addsub_size n 462 + 452 463 let prologue_size f = 453 - (if initial_stack_offset f > 0 then 2 else 0) 454 - + (if f.fun_frame_required then (if fp then 2 else 1) else 0) 464 + let stk = initial_stack_offset f in 465 + (if stk > 0 then stack_adj_size (-stk) else 0) 466 + + (if f.fun_frame_required then (if fp then 2 else 1) else 0) 455 467 456 468 let epilogue_size f = 457 - if f.fun_frame_required then 3 else 2 469 + let stk = initial_stack_offset f in 470 + (if stk > 0 then stack_adj_size stk else 0) + 471 + (if f.fun_frame_required then 1 else 0) + 472 + 1 458 473 459 474 let instr_size f = function 460 475 | Lend -> 0 ··· 462 477 | Lop (Imove | Ispill | Ireload) -> 1 463 478 | Lop (Iconst_int n) -> 464 479 num_instructions_for_intconst n 465 - | Lop (Iconst_float _) -> 2 480 + | Lop (Iconst_float f) -> 481 + if f = 0L || is_immediate_float f then 1 else 2 466 482 | Lop (Iconst_symbol _) -> 2 467 483 | Lop (Icall_ind) -> 1 468 484 | Lop (Icall_imm _) -> 1 ··· 472 488 | Lop (Iextcall {alloc; stack_ofs} ) -> 473 489 if stack_ofs > 0 then 5 474 490 else if alloc then 3 475 - else 7 476 - | Lop (Istackoffset _) -> 2 491 + else 5 492 + | Lop (Istackoffset n) -> stack_adj_size (-n) 477 493 | Lop (Iload { memory_chunk; addressing_mode; is_atomic }) -> 478 494 let based = match addressing_mode with Iindexed _ -> 0 | Ibased _ -> 1 479 495 and barrier = if is_atomic then 1 else 0 ··· 489 505 based + barrier + single 490 506 | Lop (Ialloc _) when f.fun_fast -> 5 491 507 | Lop (Ispecific (Ialloc_far _)) when f.fun_fast -> 6 492 - | Lop (Ipoll _) -> 3 493 - | Lop (Ispecific (Ipoll_far _)) -> 4 508 + | Lop (Ipoll {return_label=None}) -> 3 509 + | Lop (Ipoll {return_label=Some _}) -> 4 510 + | Lop (Ispecific (Ipoll_far {return_label=None})) -> 4 511 + | Lop (Ispecific (Ipoll_far {return_label=Some _})) -> 5 494 512 | Lop (Ialloc { bytes = num_bytes; _ }) 495 513 | Lop (Ispecific (Ialloc_far { bytes = num_bytes; _ })) -> 496 514 begin match num_bytes with 497 - | 16 | 24 | 32 -> 1 498 - | _ -> 1 + num_instructions_for_intconst (Nativeint.of_int num_bytes) 515 + | 16 | 24 | 32 -> 2 516 + | _ -> 2 + num_instructions_for_intconst (Nativeint.of_int num_bytes) 499 517 end 500 518 | Lop (Iintop (Icomp _)) -> 2 501 519 | Lop (Icompf _) -> 2 ··· 508 526 | Lop (Ispecific (Ishiftcheckbound_far _)) -> 3 509 527 | Lop (Iintop Imod) -> 2 510 528 | Lop (Iintop Imulh) -> 1 529 + | Lop (Iintop_imm ((Iadd|Isub), n)) -> addsub_size n 511 530 | Lop (Iintop _) -> 1 512 531 | Lop (Iintop_imm _) -> 1 513 532 | Lop (Ifloatofint | Iintoffloat | Iabsf | Inegf | Ispecific Isqrtf) -> 1 ··· 568 587 | Ishiftcheckbound { shift; } -> 569 588 Lop (Ispecific (Ishiftcheckbound_far { shift; })) 570 589 | _ -> assert false 571 - end) 590 + end 591 + module BR = Branch_relaxation.Make (Size) 572 592 573 593 (* Output the assembly code for allocation. *) 574 594 ··· 1073 1093 1074 1094 (* Emission of an instruction sequence *) 1075 1095 1076 - let rec emit_all env i = 1077 - if i.desc = Lend then () else (emit_instr env i; emit_all env i.next) 1096 + (* for debugging instr_size errors *) 1097 + let emit_instr_debug env i = 1098 + let lbl = new_label () in 1099 + `{emit_label lbl}:\n`; 1100 + emit_instr env i; 1101 + let sz = Size.instr_size env.f i.desc * 4 in 1102 + ` .ifne (. - {emit_label lbl}) - {emit_int sz}\n`; 1103 + ` .error \"Emit.instr_size: instruction length mismatch\"\n`; 1104 + ` .endif\n` 1105 + 1106 + let rec emit_all env lbl_start acc i = 1107 + let debug = Config.with_codegen_invariants in 1108 + match i.desc with 1109 + | Lend -> 1110 + if debug then begin 1111 + (* acc measures in units of 32-bit instructions *) 1112 + let sz = acc * 4 in 1113 + ` .ifne (. - {emit_label lbl_start}) - {emit_int sz}\n`; 1114 + ` .error \"Emit.instr_size: instruction length mismatch\"\n`; 1115 + ` .endif\n`; 1116 + end 1117 + else 1118 + () 1119 + | _ -> 1120 + if debug then emit_instr_debug env i else emit_instr env i; 1121 + emit_all env lbl_start (acc + Size.instr_size env.f i.desc) i.next 1122 + 1123 + let emit_all env i = 1124 + let lbl = new_label () in 1125 + `{emit_label lbl}:\n`; 1126 + emit_all env lbl 0 i 1078 1127 1079 1128 (* Emission of a function declaration *) 1080 1129
+20
configure
··· 862 862 otherlibraries 863 863 instrumented_runtime_libs 864 864 instrumented_runtime 865 + codegen_invariants 865 866 debug_runtime 866 867 cmxs 867 868 natdynlink_archive ··· 998 999 ac_user_opts=' 999 1000 enable_option_checking 1000 1001 enable_debug_runtime 1002 + enable_codegen_invariants 1001 1003 enable_ocamldebug 1002 1004 enable_debugger 1003 1005 enable_dependency_generation ··· 1697 1699 --disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no) 1698 1700 --enable-FEATURE[=ARG] include FEATURE [ARG=yes] 1699 1701 --disable-debug-runtime do not build runtime with debugging support 1702 + --enable-codegen-invariants 1703 + enable invariants checks in native codegen 1700 1704 --enable-ocamldebug build ocamldebug [default=auto] 1701 1705 --enable-debugger alias for --enable-ocamldebug 1702 1706 --disable-dependency-generation ··· 3500 3504 3501 3505 3502 3506 3507 + 3503 3508 # TODO: rename this variable 3504 3509 3505 3510 ··· 3866 3871 if test ${enable_debug_runtime+y} 3867 3872 then : 3868 3873 enableval=$enable_debug_runtime; 3874 + fi 3875 + 3876 + 3877 + # Check whether --enable-codegen-invariants was given. 3878 + if test ${enable_codegen_invariants+y} 3879 + then : 3880 + enableval=$enable_codegen_invariants; 3869 3881 fi 3870 3882 3871 3883 ··· 21662 21674 debug_runtime=false ;; #( 21663 21675 *) : 21664 21676 debug_runtime=true ;; 21677 + esac 21678 + 21679 + ## Should the codegen with debugging support be built 21680 + case $enable_codegen_invariants in #( 21681 + no) : 21682 + codegen_invariants=false ;; #( 21683 + *) : 21684 + codegen_invariants=true ;; 21665 21685 esac 21666 21686 21667 21687 ## Determine how to link with the POSIX threads library
+10
configure.ac
··· 196 196 AC_SUBST([natdynlink_archive]) 197 197 AC_SUBST([cmxs]) 198 198 AC_SUBST([debug_runtime]) 199 + AC_SUBST([codegen_invariants]) 199 200 AC_SUBST([instrumented_runtime]) 200 201 AC_SUBST([instrumented_runtime_libs]) 201 202 AC_SUBST([otherlibraries]) ··· 377 378 AC_ARG_ENABLE([debug-runtime], 378 379 [AS_HELP_STRING([--disable-debug-runtime], 379 380 [do not build runtime with debugging support])]) 381 + 382 + AC_ARG_ENABLE([codegen-invariants], 383 + [AS_HELP_STRING([--enable-codegen-invariants], 384 + [enable invariants checks in native codegen])]) 380 385 381 386 AC_ARG_ENABLE([ocamldebug], 382 387 [AS_HELP_STRING([--enable-ocamldebug], ··· 2438 2443 AS_CASE([$enable_debug_runtime], 2439 2444 [no], [debug_runtime=false], 2440 2445 [debug_runtime=true]) 2446 + 2447 + ## Should the codegen with debugging support be built 2448 + AS_CASE([$enable_codegen_invariants], 2449 + [no], [codegen_invariants=false], 2450 + [codegen_invariants=true]) 2441 2451 2442 2452 ## Determine how to link with the POSIX threads library 2443 2453
+1 -1
tools/ci/inria/main
··· 155 155 make=make 156 156 instdir="$HOME/ocaml-tmp-install" 157 157 confoptions="--enable-ocamltest --enable-dependency-generation \ 158 - ${OCAML_CONFIGURE_OPTIONS}" 158 + --enable-codegen-invariants ${OCAML_CONFIGURE_OPTIONS}" 159 159 make_native=true 160 160 cleanup=false 161 161 check_make_alldepend=false
+1
utils/config.common.ml.in
··· 124 124 p_bool "supports_shared_libraries" supports_shared_libraries; 125 125 p_bool "native_dynlink" native_dynlink; 126 126 p_bool "naked_pointers" naked_pointers; 127 + p_bool "with_codegen_invariants" with_codegen_invariants; 127 128 128 129 p "exec_magic_number" exec_magic_number; 129 130 p "cmi_magic_number" cmi_magic_number;
+1
utils/config.fixed.ml
··· 49 49 let flambda = false 50 50 let with_flambda_invariants = false 51 51 let with_cmm_invariants = false 52 + let with_codegen_invariants = false 52 53 let windows_unicode = false 53 54 let flat_float_array = true 54 55 let align_double = true
+1
utils/config.generated.ml.in
··· 59 59 let flambda = @flambda@ 60 60 let with_flambda_invariants = @flambda_invariants@ 61 61 let with_cmm_invariants = @cmm_invariants@ 62 + let with_codegen_invariants = @codegen_invariants@ 62 63 let windows_unicode = @windows_unicode@ != 0 63 64 64 65 let flat_float_array = @flat_float_array@
+3
utils/config.mli
··· 227 227 val with_cmm_invariants : bool 228 228 (** Whether the invariants checks for Cmm are enabled *) 229 229 230 + val with_codegen_invariants : bool 231 + (** Whether the invariant checks for native code generation are enabled. *) 232 + 230 233 val reserved_header_bits : int 231 234 (** How many bits of a block's header are reserved *) 232 235