diff options
author | Xavier Leroy <xavier.leroy@college-de-france.fr> | 2021-04-25 13:57:47 +0200 |
---|---|---|
committer | Xavier Leroy <xavierleroy@users.noreply.github.com> | 2021-05-02 18:06:32 +0200 |
commit | 320c55590cc30d4ef5b2c1a226f0f940a6bdb445 (patch) | |
tree | ed6ad57e251e164fec31c57a6f2162daabc8305d | |
parent | 38b0babd5a642cea8912524debc63edc67fda08b (diff) | |
download | compcert-320c55590cc30d4ef5b2c1a226f0f940a6bdb445.tar.gz compcert-320c55590cc30d4ef5b2c1a226f0f940a6bdb445.zip |
Support __builtin_unreachable
Not yet used for optimizations.
-rw-r--r-- | aarch64/Asmexpand.ml | 4 | ||||
-rw-r--r-- | arm/Asmexpand.ml | 4 | ||||
-rw-r--r-- | cfrontend/C2C.ml | 3 | ||||
-rw-r--r-- | common/Builtins0.v | 5 | ||||
-rw-r--r-- | cparser/Cflow.ml | 6 | ||||
-rw-r--r-- | powerpc/Asmexpand.ml | 3 | ||||
-rw-r--r-- | riscV/Asmexpand.ml | 4 | ||||
-rw-r--r-- | x86/Asmexpand.ml | 5 |
8 files changed, 32 insertions, 2 deletions
diff --git a/aarch64/Asmexpand.ml b/aarch64/Asmexpand.ml index 6c80e9d3..d24a9ef6 100644 --- a/aarch64/Asmexpand.ml +++ b/aarch64/Asmexpand.ml @@ -355,8 +355,12 @@ let expand_builtin_inline name args res = (* Synchronization *) | "__builtin_membar", [], _ -> () + (* No operation *) | "__builtin_nop", [], _ -> emit Pnop + (* Optimization hint *) + | "__builtin_unreachable", [], _ -> + () (* Byte swap *) | ("__builtin_bswap" | "__builtin_bswap32"), [BA(IR a1)], BR(IR res) -> emit (Prev(W, res, a1)) diff --git a/arm/Asmexpand.ml b/arm/Asmexpand.ml index 15cbebec..01b18c37 100644 --- a/arm/Asmexpand.ml +++ b/arm/Asmexpand.ml @@ -407,8 +407,12 @@ let expand_builtin_inline name args res = (* Vararg stuff *) | "__builtin_va_start", [BA(IR a)], _ -> expand_builtin_va_start a + (* No operation *) | "__builtin_nop", [], _ -> emit Pnop + (* Optimization hint *) + | "__builtin_unreachable", [], _ -> + () (* Catch-all *) | _ -> raise (Error ("unrecognized builtin " ^ name)) diff --git a/cfrontend/C2C.ml b/cfrontend/C2C.ml index fee3d86e..8b205d19 100644 --- a/cfrontend/C2C.ml +++ b/cfrontend/C2C.ml @@ -268,6 +268,9 @@ let builtins_generic = { (TPtr(TVoid [], []), [TPtr(TVoid [], []); TInt(IULong, [])], false); + (* Optimization hints *) + "__builtin_unreachable", + (TVoid [], [], false); (* Helper functions for int64 arithmetic *) "__compcert_i64_dtos", (TInt(ILongLong, []), diff --git a/common/Builtins0.v b/common/Builtins0.v index d84c9112..2251b3d7 100644 --- a/common/Builtins0.v +++ b/common/Builtins0.v @@ -341,6 +341,7 @@ Inductive standard_builtin : Type := | BI_i16_bswap | BI_i32_bswap | BI_i64_bswap + | BI_unreachable | BI_i64_umulh | BI_i64_smulh | BI_i64_sdiv @@ -376,6 +377,7 @@ Definition standard_builtin_table : list (string * standard_builtin) := :: ("__builtin_bswap", BI_i32_bswap) :: ("__builtin_bswap32", BI_i32_bswap) :: ("__builtin_bswap64", BI_i64_bswap) + :: ("__builtin_unreachable", BI_unreachable) :: ("__compcert_i64_umulh", BI_i64_umulh) :: ("__compcert_i64_smulh", BI_i64_smulh) :: ("__compcert_i64_sdiv", BI_i64_sdiv) @@ -414,6 +416,8 @@ Definition standard_builtin_sig (b: standard_builtin) : signature := mksignature (Tlong :: nil) Tlong cc_default | BI_i16_bswap => mksignature (Tint :: nil) Tint cc_default + | BI_unreachable => + mksignature nil Tvoid cc_default | BI_i64_shl | BI_i64_shr | BI_i64_sar => mksignature (Tlong :: Tint :: nil) Tlong cc_default | BI_i64_dtos | BI_i64_dtou => @@ -448,6 +452,7 @@ Program Definition standard_builtin_sem (b: standard_builtin) : builtin_sem (sig | BI_i64_bswap => mkbuiltin_n1t Tlong Tlong (fun n => Int64.repr (decode_int (List.rev (encode_int 8%nat (Int64.unsigned n))))) + | BI_unreachable => mkbuiltin Tvoid (fun vargs => None) _ _ | BI_i64_umulh => mkbuiltin_n2t Tlong Tlong Tlong Int64.mulhu | BI_i64_smulh => mkbuiltin_n2t Tlong Tlong Tlong Int64.mulhs | BI_i64_sdiv => mkbuiltin_v2p Tlong Val.divls _ _ diff --git a/cparser/Cflow.ml b/cparser/Cflow.ml index cc257189..8a2a3fe4 100644 --- a/cparser/Cflow.ml +++ b/cparser/Cflow.ml @@ -23,8 +23,12 @@ open Cutil module StringSet = Set.Make(String) (* Functions declared noreturn by the standard *) +(* We also add our own "__builtin_unreachable" function because, currently, + it is difficult to attach attributes to a built-in function. *) + let std_noreturn_functions = - ["longjmp";"exit";"_exit";"abort";"_Exit";"quick_exit";"thrd_exit"] + ["longjmp";"exit";"_exit";"abort";"_Exit";"quick_exit";"thrd_exit"; + "__builtin_unreachable"] (* Statements are abstracted as "flow transformers": functions from possible inputs to possible outcomes. diff --git a/powerpc/Asmexpand.ml b/powerpc/Asmexpand.ml index 4cb72c10..e663226f 100644 --- a/powerpc/Asmexpand.ml +++ b/powerpc/Asmexpand.ml @@ -793,6 +793,9 @@ let expand_builtin_inline name args res = (* no operation *) | "__builtin_nop", [], _ -> emit (Pori (GPR0, GPR0, Cint _0)) + (* Optimization hint *) + | "__builtin_unreachable", [], _ -> + () (* atomic operations *) | "__builtin_atomic_exchange", [BA (IR a1); BA (IR a2); BA (IR a3)],_ -> (* Register constraints imposed by Machregs.v *) diff --git a/riscV/Asmexpand.ml b/riscV/Asmexpand.ml index e8c142e9..dc0ec184 100644 --- a/riscV/Asmexpand.ml +++ b/riscV/Asmexpand.ml @@ -646,8 +646,12 @@ let expand_builtin_inline name args res = (fun rl -> emit (Pmulw (rl, X a, X b)); emit (Pmulhuw (rh, X a, X b))) + (* No operation *) | "__builtin_nop", [], _ -> emit Pnop + (* Optimization hint *) + | "__builtin_unreachable", [], _ -> + () (* Catch-all *) | _ -> raise (Error ("unrecognized builtin " ^ name)) diff --git a/x86/Asmexpand.ml b/x86/Asmexpand.ml index 14cbb373..d757d7c2 100644 --- a/x86/Asmexpand.ml +++ b/x86/Asmexpand.ml @@ -487,9 +487,12 @@ let expand_builtin_inline name args res = (* Synchronization *) | "__builtin_membar", [], _ -> () - (* no operation *) + (* No operation *) | "__builtin_nop", [], _ -> emit Pnop + (* Optimization hint *) + | "__builtin_unreachable", [], _ -> + () (* Catch-all *) | _ -> raise (Error ("unrecognized builtin " ^ name)) |