From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1643) id 1285D3858406; Wed, 31 Aug 2022 10:40:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1285D3858406 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1661942440; bh=MdbKwTEJipAC3SZhf8L0lRYDMs+ajEW4kF1Tr5U74Qg=; h=From:To:Subject:Date:From; b=yQ4UZz1eia7ry5irIydzyWBp9XWJ6+FGzphDNPU64gx02kgbVyFd5+IDHuZKLhOE3 W1UDrKixNPw12c3v+F65VEyU8t1NEYP3hRlf9DClbNoYEBrCJttIc1e5MmxaYRbnj8 7UlNo4GbAsMY1Gy/NpviH0drkQAd4YqUEI2UgEeQ= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Thomas Schwinge To: gcc-cvs@gcc.gnu.org Subject: [gcc/devel/rust/master] builtins: Add add_overflow builtin and refactor class X-Act-Checkin: gcc X-Git-Author: Arthur Cohen X-Git-Refname: refs/heads/devel/rust/master X-Git-Oldrev: 3e79563a65e78ddb6b2ef10df7e1d4e3441aaff2 X-Git-Newrev: ff7d6bfed2e7bc08fba1cc456daf464e6176dd46 Message-Id: <20220831104040.1285D3858406@sourceware.org> Date: Wed, 31 Aug 2022 10:40:40 +0000 (GMT) List-Id: https://gcc.gnu.org/g:ff7d6bfed2e7bc08fba1cc456daf464e6176dd46 commit ff7d6bfed2e7bc08fba1cc456daf464e6176dd46 Author: Arthur Cohen Date: Wed Aug 24 17:21:38 2022 +0200 builtins: Add add_overflow builtin and refactor class Diff: --- gcc/rust/backend/rust-builtins.h | 51 ++++++++++++++++++++++++++++------------ 1 file changed, 36 insertions(+), 15 deletions(-) diff --git a/gcc/rust/backend/rust-builtins.h b/gcc/rust/backend/rust-builtins.h index 2bfa6c6cdf7..5cd84010723 100644 --- a/gcc/rust/backend/rust-builtins.h +++ b/gcc/rust/backend/rust-builtins.h @@ -18,8 +18,9 @@ #define RUST_BUILTINS_H #include "rust-system.h" -#include "tree.h" +#include "rust-tree.h" #include "langhooks.h" +#include "tree.h" namespace Rust { namespace Compile { @@ -99,16 +100,34 @@ private: BuiltinsContext () { setup (); } - void setup () + void setup_overflow_fns () + { + tree overflow_type + = build_varargs_function_type_list (boolean_type_node, NULL_TREE); + + define_builtin ("add_overflow", BUILT_IN_ADD_OVERFLOW, + "__builtin_add_overflow", "add_overflow", overflow_type, 0); + define_builtin ("sub_overflow", BUILT_IN_SUB_OVERFLOW, + "__builtin_sub_overflow", "sub_overflow", overflow_type, 0); + define_builtin ("mul_overflow", BUILT_IN_MUL_OVERFLOW, + "__builtin_mul_overflow", "mul_overflow", overflow_type, 0); + } + + void setup_math_fns () { tree math_function_type_f32 = build_function_type_list (float_type_node, float_type_node, NULL_TREE); define_builtin ("sinf32", BUILT_IN_SINF, "__builtin_sinf", "sinf", math_function_type_f32, builtin_const); - define_builtin ("sqrtf32", BUILT_IN_SQRTF, "__builtin_sqrtf", "sqrtf", math_function_type_f32, builtin_const); + } + + void setup () + { + setup_math_fns (); + setup_overflow_fns (); define_builtin ("unreachable", BUILT_IN_UNREACHABLE, "__builtin_unreachable", NULL, @@ -132,6 +151,16 @@ private: 0); } + static void handle_flags (tree decl, int flags) + { + if (flags & builtin_const) + TREE_READONLY (decl) = 1; + if (flags & builtin_noreturn) + TREE_READONLY (decl) = 1; + if (flags & builtin_novops) + DECL_IS_NOVOPS (decl) = 1; + } + // Define a builtin function. BCODE is the builtin function code // defined by builtins.def. NAME is the name of the builtin function. // LIBNAME is the name of the corresponding library function, and is @@ -144,24 +173,16 @@ private: { tree decl = add_builtin_function (name, fntype, bcode, BUILT_IN_NORMAL, libname, NULL_TREE); - if ((flags & builtin_const) != 0) - TREE_READONLY (decl) = 1; - if ((flags & builtin_noreturn) != 0) - TREE_THIS_VOLATILE (decl) = 1; - if ((flags & builtin_novops) != 0) - DECL_IS_NOVOPS (decl) = 1; + handle_flags (decl, flags); set_builtin_decl (bcode, decl, true); + this->builtin_functions_[name] = decl; if (libname != NULL) { decl = add_builtin_function (libname, fntype, bcode, BUILT_IN_NORMAL, NULL, NULL_TREE); - if ((flags & builtin_const) != 0) - TREE_READONLY (decl) = 1; - if ((flags & builtin_noreturn) != 0) - TREE_THIS_VOLATILE (decl) = 1; - if ((flags & builtin_novops) != 0) - DECL_IS_NOVOPS (decl) = 1; + handle_flags (decl, flags); + this->builtin_functions_[libname] = decl; }