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: 50838 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2746402wrn; Tue, 31 Jan 2023 05:20:58 -0800 (PST) X-Google-Smtp-Source: AK7set/TzmoG5YH0l9snUL+lWFKdlhCHRY3o14w8a2waGETUfyV16S0WY0fVpiQ2PS7ub7KdA2Ky X-Received: by 2002:a05:6402:339:b0:4a2:2e8a:14cb with SMTP id q25-20020a056402033900b004a22e8a14cbmr12052767edw.2.1675171258813; Tue, 31 Jan 2023 05:20:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675171258; cv=none; d=google.com; s=arc-20160816; b=wc3Q8S29d1bPYHzb+h8tLTrAcl6HNqP/KUADIBUwTzLKCsUxdp22SA8rUnRiXZinnb 8GxpsnazkQuQW2x6NsXRc9oEro8EFFdxTm5dOi6gSBLqfNF1F/3HqO5vX4SL9nKS8L0t E8aDFEmPnLbXNOSfih34L5sQAHLWWFcu64RFNQSnKzopQp9LVvyMS2XeJ1YL+s0hdKSN j889/I5Sv1M286L0Q85WsIkScNY+OtCesg4E3Z6RN1dLvpj7BexB9omeRG6931itfvZf NPGHMu/fnfdj4vXIgm6yn+RkkpGzHO0O70WmLMcLjdGT+MfpWVLHCfwCUAurpbgelqgj OueQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature :dmarc-filter:delivered-to; bh=dD5dLCsdhPc8yQ7ZLukExUiBqGXkxDB5yuOF67THOb0=; b=rjKazF2h64vMijJyw1Oy888J4iHqHpH4j1EHs6WzO4Z3yyGTGPofifoOeyoHSaIla3 1Db073aZVrJVi/3mnDR8R+ak744BcW2TlfuPftpCGVX3iGHIeormQ9FXkHG9R+a8e4z8 BC4UiJ5Bwllc48r8114Ofe01H1rsufXa2xS+GL3vQKsHlYFu+BZh8FU/zgLE84YVDWN8 zroa130LYKfSnG2vWqPcsYRS3kEm4MO9qQXOhljPJy60EOO4sxb9Wo58A9wX23uq542T iqbgGog2xsshl3hLwUqCffAbKJupLucdehCZWLK3Qoai6wYpTwg1d75pdf6pnA5ooFd1 PWjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=WALg6Cae; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id h11-20020a50ed8b000000b0049ecc8190basi17164874edr.254.2023.01.31.05.20.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Jan 2023 05:20:58 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=WALg6Cae; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CD1363858C2D for ; Tue, 31 Jan 2023 13:20:48 +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-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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756544377762699661?= X-GMAIL-MSGID: =?utf-8?q?1756544377762699661?= 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; }