From patchwork Tue Aug 6 21:27:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 1969683 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=quicinc.com header.i=@quicinc.com header.a=rsa-sha256 header.s=qcppdkim1 header.b=ILGQDdOc; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Wdmdg72n9z1yfC for ; Wed, 7 Aug 2024 07:28:55 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C89E9385C6CD for ; Tue, 6 Aug 2024 21:28:53 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by sourceware.org (Postfix) with ESMTPS id 818B63858C35 for ; Tue, 6 Aug 2024 21:27:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 818B63858C35 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=quicinc.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 818B63858C35 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722979650; cv=none; b=NNnfAI9167HmXVgf9zW/dI5g9RF3RkigzHuhr7iqDCvmCoGh1DKu0tya6Di3FitvkgjcbAncoaz0snmtsEz3+68LkDBgx+9ttVm6PmsMPzbJ21gDAT/o7x0G9KKPKhrvP1naH4N6XH9bOTkU23M6UJ6mypUAuWAp0b3sUuZXFJI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722979650; c=relaxed/simple; bh=g8JwS8eOiRgoqNwXaN+LQoLCgZUNVdN4Bgnf2rhGh6o=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=W38bASphrgGQfBNYNgB/eZt/epFOXRlVl/wCNPtLFtCr3HYIQkeDShVA3PiF6gvtWb+Y5AQw3/g0DjObMV+X7dqL7yNABKMFNXqJqIGWjmFJsFgbMcWdjzWOwMajYvVqqchYd4E0u+utcvr7rypbAN0Bl/Qzq3eU+gncaN7e/Xk= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0279869.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 476H6Wui012190 for ; Tue, 6 Aug 2024 21:27:27 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= XaoS5xQwcgUn/VquH/t6bqCToOZIBNcydgla2dstWDI=; b=ILGQDdOcBIo+5u1/ RYDSpWFFbedz+CtdJErBgyQdNWITKXLT93sOlb8Gov22/QPAU+pKVAeR0z6mvJWT tnrN7KfJDb9lurK0jPT9cXbUeJq1R2FGCQB3G/w8JCez9p0ptKNujrPouj4/Jmrk 2voRbQZlXOjWkckN2wGITyMr+97EMe8CWIjJj8Ilwo81IFnz3zIq1Pl3wDVypOaM QpQRuufcpurgUUsL5G4XVrFxVNYvuUhOevyZB0H6B43L6wpk+/gNIJFtB8HrPm/F VosWFIJwBLJ0H5BAIrJ9FDLp8LFhUQ0puA6Hfz2VP47ZGIc/mjftaKSOQQOzoILY 6pks9g== Received: from nasanppmta01.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 40sbj6rsxm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 06 Aug 2024 21:27:26 +0000 (GMT) Received: from nasanex01c.na.qualcomm.com (nasanex01c.na.qualcomm.com [10.45.79.139]) by NASANPPMTA01.qualcomm.com (8.17.1.19/8.17.1.19) with ESMTPS id 476LRPct027767 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 6 Aug 2024 21:27:25 GMT Received: from hu-apinski-lv.qualcomm.com (10.49.16.6) by nasanex01c.na.qualcomm.com (10.45.79.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.9; Tue, 6 Aug 2024 14:27:25 -0700 From: Andrew Pinski To: CC: Andrew Pinski Subject: [PATCH 2/5] range: Make range_op_table a true singleton class [PR116209] Date: Tue, 6 Aug 2024 14:27:11 -0700 Message-ID: <20240806212714.308434-3-quic_apinski@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240806212714.308434-1-quic_apinski@quicinc.com> References: <20240806212714.308434-1-quic_apinski@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nasanex01c.na.qualcomm.com (10.45.79.139) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: Ith1dTHDTnQ4CiDYsqPke62YSYbEnsHI X-Proofpoint-GUID: Ith1dTHDTnQ4CiDYsqPke62YSYbEnsHI X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-08-06_17,2024-08-06_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 priorityscore=1501 adultscore=0 mlxscore=0 lowpriorityscore=0 bulkscore=0 phishscore=0 mlxlogscore=999 clxscore=1015 malwarescore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2407110000 definitions=main-2408060150 X-Spam-Status: No, score=-13.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org This is a small cleanup with respect to the ranger_op_table class. There should only ever be one instance of ranger_op_table so this adds a static member function which returns the instance. A few variables that are defined in range-op.cc should be local to the file so wrap them with an anonymous namespace. Also change operator_table into a reference that is initialized to the singelton. This has a small extra overhead at intiialization time of the operator_table; could be improved if we used C++20's consteval. Since this happens only once, there it should be ok. Bootstrapped and tested on x86_64-linux-gnu. PR tree-optimization/116209 gcc/ChangeLog: * range-op.cc (op_equal, op_not_equal, op_lt, op_le, op_gt, op_ge, op_ident, op_cst, op_cast, op_plus, op_abs, op_minus, op_negate, op_mult, op_addr, op_bitwise_not, op_bitwise_xor, op_bitwise_and, op_bitwise_or, op_min, op_max, default_operator): Wrap with anonymous namespace. (operator_table): Change to reference and initialize with range_op_table::singleton. (range_op_table::singleton): New function. * range-op.h (range_op_table): New method, singleton. Make most functions private (rather than protected). Make ctor private. Signed-off-by: Andrew Pinski --- gcc/range-op.cc | 19 ++++++++++++++----- gcc/range-op.h | 5 +++-- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/gcc/range-op.cc b/gcc/range-op.cc index c576f688221..56a014e99bc 100644 --- a/gcc/range-op.cc +++ b/gcc/range-op.cc @@ -49,8 +49,9 @@ along with GCC; see the file COPYING3. If not see #include "tree-ssa-ccp.h" #include "range-op-mixed.h" -// Instantiate the operators which apply to multiple types here. +namespace { +// Instantiate the operators which apply to multiple types here. operator_equal op_equal; operator_not_equal op_not_equal; operator_lt op_lt; @@ -74,7 +75,12 @@ operator_min op_min; operator_max op_max; // Instantaite a range operator table. -range_op_table operator_table; +range_op_table &operator_table = range_op_table::singleton(); + +// Instantiate a default range operator for opcodes with no entry. +range_operator default_operator; + +} // Invoke the initialization routines for each class of range. @@ -111,9 +117,12 @@ range_op_table::range_op_table () set (MAX_EXPR, op_max); } -// Instantiate a default range operator for opcodes with no entry. - -range_operator default_operator; +// Returns the singleton instance of the table. +range_op_table &range_op_table::singleton() +{ + static range_op_table single; + return single; +} // Create a default range_op_handler. diff --git a/gcc/range-op.h b/gcc/range-op.h index 8edf967a445..e4e11f89624 100644 --- a/gcc/range-op.h +++ b/gcc/range-op.h @@ -391,13 +391,13 @@ extern void wi_set_zero_nonzero_bits (tree type, class range_op_table final { public: - range_op_table (); inline range_operator *operator[] (unsigned code) { gcc_checking_assert (code < RANGE_OP_TABLE_SIZE); return m_range_tree[code]; } -protected: + static range_op_table &singleton(); +private: inline void set (unsigned code, range_operator &op) { gcc_checking_assert (code < RANGE_OP_TABLE_SIZE); @@ -408,6 +408,7 @@ protected: void initialize_integral_ops (); void initialize_pointer_ops (); void initialize_float_ops (); + range_op_table (); }; #endif // GCC_RANGE_OP_H