From patchwork Tue Oct 10 13:42:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 150795 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp209806vqb; Tue, 10 Oct 2023 06:43:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHC0UTKixD3d+SPm8d1KRUibZMnOQLlJuiHh2UHvJhGtTw2y9HJ472w+OZPHRxqif5fZvpZ X-Received: by 2002:a17:907:2715:b0:9ba:b5:e6b7 with SMTP id w21-20020a170907271500b009ba00b5e6b7mr9291585ejk.7.1696945406243; Tue, 10 Oct 2023 06:43:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696945406; cv=none; d=google.com; s=arc-20160816; b=sHoS6JgM2vuMeyl6HMNV0e90qSK+UKCW3d0pjSa7/TDwPl5dUcRJbEJOesVoosZLK3 nlkADBvY41kvtKUC4dyZ+Nwge2+JsZXal2DPAv+RxooCf5FsMDtPbpLmZPuVSw+CERfm 4doLZsoBreY7EnWvuenPV+LTFWpHf3F1PigXzhNEKhXpQ0sg8/xKgLZLM8EI4s0OwgVa yZL+dCZ/h6XL5E6wAf+RQL9SWoX044VKXF9cVEj1HG8viIB9WgQoVUE6MUa7A1ARq0jJ JmNrE3nbepol1+3fhrEqbubmZVLP3hmyQz2MgA8KDbjdnnMCq1OBv4LbxFfc4biE74Lb qvZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:reply-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-disposition:in-reply-to :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature:dmarc-filter:delivered-to; bh=ukWn0OuRhCPPoseUtePEU/46nLEbVpOgXur5LTEUEJc=; fh=J0Jxiv2Ku1JDqrQpD3wvi8+rVqX+Ce+7zdQ8crw7oWQ=; b=bqadK3H9QP1Ew/WX3XX9zpxIshkBQx/AifGaikki/+ZVfyfiawCS5i4l+8Y2FPbFdR /ofvmd1OX+T+XJ2UIQXQzPBhGFs5rJi5uSAYk+v8ZO5l7/P5v64mt3FtG7V/zb5qR27Z tr7VPXFRjAOBocyu12iaTA3MzsgvI0qm2C3LDKj7J0dGWE+DSmB6ISqYE+GkomTh8hqY DcpOYg/K7UDRLSJQiQZ05lJ5iIpSog38kBH55u3KDdAYAmhGSAb4PwY4kOFiKFluB4Zm Yy0k3vLl/PUha3ndvyjzne3PEYkqoIUNlv9gkkW6gMK8bmvmDrghgqs80/xubsqReNBI 8Vzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=SaJaPqQ8; 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"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id o14-20020a17090637ce00b009b2ca7666a7si5401538ejc.930.2023.10.10.06.43.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 06:43:26 -0700 (PDT) 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=@redhat.com header.s=mimecast20190719 header.b=SaJaPqQ8; 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"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 23A4E385C6FC for ; Tue, 10 Oct 2023 13:43:14 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 1981D3858C5E for ; Tue, 10 Oct 2023 13:42:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1981D3858C5E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1696945369; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references; bh=ukWn0OuRhCPPoseUtePEU/46nLEbVpOgXur5LTEUEJc=; b=SaJaPqQ8Tsaa3iLI8FtAHLU+6eyKbRNmOudUn7Dbm0TYtm5ljXXmbQ2z35UIgHwDDlNmB/ sRgGj/wOkIJeWcwWMQda3Wad/Dh6R4sFHZioUfhR1gAtO0XQCEuNRotPT8D2RXpRrMZYeb 9h9hUDTiijKTioRs6VY4u2QE8O0tQss= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-436-epbcYVquOY6VGmiNNvIduQ-1; Tue, 10 Oct 2023 09:42:48 -0400 X-MC-Unique: epbcYVquOY6VGmiNNvIduQ-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0C8638E7D2A; Tue, 10 Oct 2023 13:42:48 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.193.202]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AC7241005E2A; Tue, 10 Oct 2023 13:42:47 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 39ADgjF03594025 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 15:42:45 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 39ADgdad3594024; Tue, 10 Oct 2023 15:42:39 +0200 Date: Tue, 10 Oct 2023 15:42:39 +0200 From: Jakub Jelinek To: Richard Biener , Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] dwarf2out: Stop using wide_int in GC structures Message-ID: References: MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, 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: , Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779376226047260241 X-GMAIL-MSGID: 1779376226047260241 Hi! On Tue, Oct 10, 2023 at 09:30:31AM +0000, Richard Biener wrote: > On Mon, 9 Oct 2023, Jakub Jelinek wrote: > > > This makes wide_int unusable in GC structures, so for dwarf2out > > > which was the only place which needed it there is a new rwide_int type > > > (restricted wide_int) which supports only up to RWIDE_INT_MAX_ELTS limbs > > > inline and is trivially copyable (dwarf2out should never deal with large > > > _BitInt constants, those should have been lowered earlier). > > > > As discussed on IRC, the dwarf2out.{h,cc} needs are actually quite limited, > > it just needs to allocate new GC structures val_wide points to (constructed > > from some const wide_int_ref &) and needs to call operator==, > > get_precision, elt, get_len and get_val methods on it. > > Even trailing_wide_int would be overkill for that, the following just adds > > a new struct with precision/len and trailing val array members and > > implements the needed methods (only 2 of them using wide_int_ref constructed > > from those). > > > > Incremental patch, so far compile time tested only: > > LGTM, wonder if we can push this separately as prerequesite? Here it is as a separate independent patch. Even without the wide_int changing patch it should save some memory, by not always allocating room for 9 limbs, but say just the 2/3 or how many we actually need. And, another advantage is that if we really need it at some point, it could support even more than 9 limbs if it is created from a wide_int_ref with get_len () > 9. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2023-10-10 Jakub Jelinek * dwarf2out.h (wide_int_ptr): Remove. (dw_wide_int_ptr): New typedef. (struct dw_val_node): Change type of val_wide from wide_int_ptr to dw_wide_int_ptr. (struct dw_wide_int): New type. (dw_wide_int::elt): New method. (dw_wide_int::operator ==): Likewise. * dwarf2out.cc (get_full_len): Change argument type to const dw_wide_int & from const wide_int &. Use CEIL. Call get_precision method instead of calling wi::get_precision. (alloc_dw_wide_int): New function. (add_AT_wide): Change w argument type to const wide_int_ref & from const wide_int &. Use alloc_dw_wide_int. (mem_loc_descriptor, loc_descriptor): Use alloc_dw_wide_int. (insert_wide_int): Change val argument type to const wide_int_ref & from const wide_int &. (add_const_value_attribute): Pass rtx_mode_t temporary directly to add_AT_wide instead of using a temporary variable. Jakub --- gcc/dwarf2out.h.jj 2023-10-09 14:37:45.890939965 +0200 +++ gcc/dwarf2out.h 2023-10-09 16:46:14.705816928 +0200 @@ -30,7 +30,7 @@ typedef struct dw_cfi_node *dw_cfi_ref; typedef struct dw_loc_descr_node *dw_loc_descr_ref; typedef struct dw_loc_list_struct *dw_loc_list_ref; typedef struct dw_discr_list_node *dw_discr_list_ref; -typedef wide_int *wide_int_ptr; +typedef struct dw_wide_int *dw_wide_int_ptr; /* Call frames are described using a sequence of Call Frame @@ -252,7 +252,7 @@ struct GTY(()) dw_val_node { unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_unsigned_const"))) val_unsigned; double_int GTY ((tag ("dw_val_class_const_double"))) val_double; - wide_int_ptr GTY ((tag ("dw_val_class_wide_int"))) val_wide; + dw_wide_int_ptr GTY ((tag ("dw_val_class_wide_int"))) val_wide; dw_vec_const GTY ((tag ("dw_val_class_vec"))) val_vec; struct dw_val_die_union { @@ -313,6 +313,35 @@ struct GTY(()) dw_discr_list_node { int dw_discr_range; }; +struct GTY((variable_size)) dw_wide_int { + unsigned int precision; + unsigned int len; + HOST_WIDE_INT val[1]; + + unsigned int get_precision () const { return precision; } + unsigned int get_len () const { return len; } + const HOST_WIDE_INT *get_val () const { return val; } + inline HOST_WIDE_INT elt (unsigned int) const; + inline bool operator == (const dw_wide_int &) const; +}; + +inline HOST_WIDE_INT +dw_wide_int::elt (unsigned int i) const +{ + if (i < len) + return val[i]; + wide_int_ref ref = wi::storage_ref (val, len, precision); + return wi::sign_mask (ref); +} + +inline bool +dw_wide_int::operator == (const dw_wide_int &o) const +{ + wide_int_ref ref1 = wi::storage_ref (val, len, precision); + wide_int_ref ref2 = wi::storage_ref (o.val, o.len, o.precision); + return ref1 == ref2; +} + /* Interface from dwarf2out.cc to dwarf2cfi.cc. */ extern struct dw_loc_descr_node *build_cfa_loc (dw_cfa_location *, poly_int64); --- gcc/dwarf2out.cc.jj 2023-10-09 14:37:45.894939909 +0200 +++ gcc/dwarf2out.cc 2023-10-09 16:48:24.565014459 +0200 @@ -397,11 +397,9 @@ dump_struct_debug (tree type, enum debug of the number. */ static unsigned int -get_full_len (const wide_int &op) +get_full_len (const dw_wide_int &op) { - int prec = wi::get_precision (op); - return ((prec + HOST_BITS_PER_WIDE_INT - 1) - / HOST_BITS_PER_WIDE_INT); + return CEIL (op.get_precision (), HOST_BITS_PER_WIDE_INT); } static bool @@ -3900,7 +3898,7 @@ static void add_data_member_location_att struct vlr_context *); static bool add_const_value_attribute (dw_die_ref, machine_mode, rtx); static void insert_int (HOST_WIDE_INT, unsigned, unsigned char *); -static void insert_wide_int (const wide_int &, unsigned char *, int); +static void insert_wide_int (const wide_int_ref &, unsigned char *, int); static unsigned insert_float (const_rtx, unsigned char *); static rtx rtl_for_decl_location (tree); static bool add_location_or_const_value_attribute (dw_die_ref, tree, bool); @@ -4594,19 +4592,31 @@ AT_unsigned (dw_attr_node *a) return a->dw_attr_val.v.val_unsigned; } +dw_wide_int * +alloc_dw_wide_int (const wide_int_ref &w) +{ + dw_wide_int *p + = (dw_wide_int *) ggc_internal_alloc (sizeof (dw_wide_int) + + ((w.get_len () - 1) + * sizeof (HOST_WIDE_INT))); + p->precision = w.get_precision (); + p->len = w.get_len (); + memcpy (p->val, w.get_val (), p->len * sizeof (HOST_WIDE_INT)); + return p; +} + /* Add an unsigned wide integer attribute value to a DIE. */ static inline void add_AT_wide (dw_die_ref die, enum dwarf_attribute attr_kind, - const wide_int& w) + const wide_int_ref &w) { dw_attr_node attr; attr.dw_attr = attr_kind; attr.dw_attr_val.val_class = dw_val_class_wide_int; attr.dw_attr_val.val_entry = NULL; - attr.dw_attr_val.v.val_wide = ggc_alloc (); - *attr.dw_attr_val.v.val_wide = w; + attr.dw_attr_val.v.val_wide = alloc_dw_wide_int (w); add_dwarf_attr (die, &attr); } @@ -16714,8 +16724,8 @@ mem_loc_descriptor (rtx rtl, machine_mod mem_loc_result->dw_loc_oprnd1.v.val_die_ref.external = 0; mem_loc_result->dw_loc_oprnd2.val_class = dw_val_class_wide_int; - mem_loc_result->dw_loc_oprnd2.v.val_wide = ggc_alloc (); - *mem_loc_result->dw_loc_oprnd2.v.val_wide = rtx_mode_t (rtl, mode); + mem_loc_result->dw_loc_oprnd2.v.val_wide + = alloc_dw_wide_int (rtx_mode_t (rtl, mode)); } break; @@ -17288,8 +17298,8 @@ loc_descriptor (rtx rtl, machine_mode mo loc_result = new_loc_descr (DW_OP_implicit_value, GET_MODE_SIZE (int_mode), 0); loc_result->dw_loc_oprnd2.val_class = dw_val_class_wide_int; - loc_result->dw_loc_oprnd2.v.val_wide = ggc_alloc (); - *loc_result->dw_loc_oprnd2.v.val_wide = rtx_mode_t (rtl, int_mode); + loc_result->dw_loc_oprnd2.v.val_wide + = alloc_dw_wide_int (rtx_mode_t (rtl, int_mode)); } break; @@ -20189,7 +20199,7 @@ extract_int (const unsigned char *src, u /* Writes wide_int values to dw_vec_const array. */ static void -insert_wide_int (const wide_int &val, unsigned char *dest, int elt_size) +insert_wide_int (const wide_int_ref &val, unsigned char *dest, int elt_size) { int i; @@ -20274,8 +20284,7 @@ add_const_value_attribute (dw_die_ref di && (GET_MODE_PRECISION (int_mode) & (HOST_BITS_PER_WIDE_INT - 1)) == 0) { - wide_int w = rtx_mode_t (rtl, int_mode); - add_AT_wide (die, DW_AT_const_value, w); + add_AT_wide (die, DW_AT_const_value, rtx_mode_t (rtl, int_mode)); return true; } return false;