From patchwork Tue Jan 31 13:24:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 63975 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EA5FF3858426 for ; Tue, 31 Jan 2023 13:20:39 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by sourceware.org (Postfix) with ESMTPS id EAAAC3858D33 for ; Tue, 31 Jan 2023 13:20:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EAAAC3858D33 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embecosm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=embecosm.com Received: by mail-wr1-x435.google.com with SMTP id t7so5824109wrp.5 for ; Tue, 31 Jan 2023 05:20:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=dD5dLCsdhPc8yQ7ZLukExUiBqGXkxDB5yuOF67THOb0=; b=WALg6Cae2MPKVxGe9xADLnMkLlUHQ3+MPa9VTXkqg+4uVHfKXLyfB2laHbNofBsNo8 jbKx0O0yESr1fqhpBPmEvioY076NWctYJsH5qmNJSEdbCAVsp4SKuZ8ikkr/ep5VRYdd azvAMR6OrWQonnrMSxfuVblO+NI6sJg6Aj8swH1uxjk23Bx++gDhwVF8z9h888RRQyh7 i83+lwG6DBZs+aPfRemyJ/QjMogxvVdv5htybheIr75xtzPsVAFJccMUIYM9fhTsTA9p 6TImbLqtU7K+tm0wvu30M4k2JV7Cdqo2IxpR6glZamwfSdSJVL33VcvFStCptT10hdK3 ylaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=dD5dLCsdhPc8yQ7ZLukExUiBqGXkxDB5yuOF67THOb0=; b=y26GN1efOjp0BxmXMV8lP+xPX0rwkQEXRhNJKn5tNjuXMWrt1RRH8lTM7+nIPwU4Xo 7i++nDIayjuc2Gi7Ig6r44vEx4Q8CKdGRK9aN9dJ6fOgAmBip8eY1rhIyynk9PtIbf3R q1dA+caexDk4Fy7o1lmXMqw79SabHpMyU119INb32D2xL9r8mlkZBZfAE+isrbY6vpZp BWksmZdKYoR6nBsC+bYQDQQQtyrqXndsZoOonVTwaEqXo0zQdAXukUWmGW2hR6K2B1vP Vjpk8yWu1HLUZHB2mAxMDJu76kb/2rUCXtvBYchFhCW+8da2r7KTxf2PuMCahG4lK0EY v98Q== X-Gm-Message-State: AFqh2kp1fqtew1fTfhaaHAEeRH94b9g80ivDKjPxBwVuSnehG4GEYpSF cykSPGgAH1Z2takh89gXNqvCtcGGtz6Jtuz+yA== X-Google-Smtp-Source: AMrXdXvo6xinI6Z4ulSHNIiwLBTZrPcv3gFLsWronSHhKi+neoC7OSFfJx6V+hnWLfiIGpMbugwENA== X-Received: by 2002:a05:6000:549:b0:274:fae4:a518 with SMTP id b9-20020a056000054900b00274fae4a518mr46454703wrf.11.1675171222510; Tue, 31 Jan 2023 05:20:22 -0800 (PST) Received: from platypus.lan ([2001:861:5e4c:3bb0:6424:328a:1734:3249]) by smtp.gmail.com with ESMTPSA id l15-20020a5d6d8f000000b002bfb37497a8sm15665197wrs.31.2023.01.31.05.20.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Jan 2023 05:20:22 -0800 (PST) From: Arthur Cohen To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Arthur Cohen Subject: [COMMITTED] gccrs: builtins: Add add_overflow builtin and refactor class Date: Tue, 31 Jan 2023 14:24:07 +0100 Message-Id: <20230131132407.661219-1-arthur.cohen@embecosm.com> X-Mailer: git-send-email 2.39.1 MIME-Version: 1.0 X-Spam-Status: No, score=-14.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" gcc/rust/ChangeLog: * backend/rust-builtins.h: Refactor builtin context class and add overflow builtins. Tested on x86_64-pc-linux-gnu, committed on master. --- 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; }