From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 80AF53858D28 for ; Thu, 26 Jan 2023 14:45:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 80AF53858D28 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=1674744339; h=from:from: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=qRPe91UHigoPv6zXoHk6xPNYcT1aaCKnxA0F7OOxsu8=; b=fENIrgeUgjvAN3OUXaDZQFK+rn7yrKLRwpfq+HxlzYr5a7HT3s3hgIiGTGXlmGbn/hafzx pBQwRGgT+mNEDv/yjnd+x4qmaHr3QpvFtAzHv4I5nPX1rSq68HnCom+BUsYu14BPqAYOO2 QnoJdgVol1UOTkDlmupeob5dN+qJXtU= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-650-PZjGyCGTOru4g3vpBX4sxg-1; Thu, 26 Jan 2023 09:45:38 -0500 X-MC-Unique: PZjGyCGTOru4g3vpBX4sxg-1 Received: by mail-qv1-f70.google.com with SMTP id q17-20020a056214019100b004b1d3c9f3acso1179287qvr.0 for ; Thu, 26 Jan 2023 06:45:37 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:references:message-id:in-reply-to:subject:cc:to:date :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=qRPe91UHigoPv6zXoHk6xPNYcT1aaCKnxA0F7OOxsu8=; b=Z0CJBKWNaSNtMvsmzpzSZ8kAxLerkNQmtyVbrqv3azQYFh5nqKmFMWAkv/SmMFHjhz mrEbOuCetNOoU1bnfudd5iT4MTJLrWm0TLD41azfZTBDgRuvVA7wFp6DCmfL5w0nFX43 Rf7fjXhSUDD93U+JJUoO2u+aeoion/E14PIHJLStZIJRrWcRCz5xUmWypsa5nc/peNOn /l/Qj3wbYJMFN1J09TrKPbpITQiADLld/iH3U3Os6DMx2Mq+2cVRL/c4IJNV+bn5PKB9 l3fIgi1XzOH2YajXNnZcbR9zznvWuL73uvR7xJIvfosb7XA6uo40xTCoCJCfGQngkvmb qNkA== X-Gm-Message-State: AFqh2kq/92ufrNB0tNMHSHElfNFM+QqBpWNaOHXnINkO3Go+CEgI/Cw+ ivYja7fpVWD/FCf3+pSgK/CSMc9iGwkfLdsiGQdnr7GT1h7+zPunZ9QVsmpWS4hVWJI0cD6goGx ScOSkytjKNNO+2L7D/Q== X-Received: by 2002:a05:6214:3491:b0:532:20e5:6032 with SMTP id mr17-20020a056214349100b0053220e56032mr58678632qvb.27.1674744337464; Thu, 26 Jan 2023 06:45:37 -0800 (PST) X-Google-Smtp-Source: AMrXdXt4Gg6BYJUrk48i+zTXG4kPrziEeAYv4QFEapdQOh1khB2G7m62RtfrJw4pUFBLM/qcks2rlQ== X-Received: by 2002:a05:6214:3491:b0:532:20e5:6032 with SMTP id mr17-20020a056214349100b0053220e56032mr58678608qvb.27.1674744337196; Thu, 26 Jan 2023 06:45:37 -0800 (PST) Received: from [192.168.1.130] (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id o23-20020a05620a229700b006cebda00630sm993233qkh.60.2023.01.26.06.45.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Jan 2023 06:45:36 -0800 (PST) From: Patrick Palka X-Google-Original-From: Patrick Palka Date: Thu, 26 Jan 2023 09:45:35 -0500 (EST) To: Andrew Pinski cc: gcc-patches@gcc.gnu.org, jason@redhat.com Subject: Re: [PATCH] constexprify some tree variables In-Reply-To: <1668794731-9349-1-git-send-email-apinski@marvell.com> Message-ID: References: <1668794731-9349-1-git-send-email-apinski@marvell.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-13.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,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 List-Id: On Fri, 18 Nov 2022, apinski--- via Gcc-patches wrote: > From: Andrew Pinski > > Since we use C++11 by default now, we can > use constexpr for some const decls in tree-core.h. > > This patch does that and it allows for better optimizations > of GCC code with checking enabled and without LTO. > > For an example generic-match.cc compiling is speed up due > to the less number of basic blocks and less debugging info > produced. I did not check the speed of compiling the same source > but rather the speed of compiling the old vs new sources here > (but with the same compiler base). > > The small slow down in the parsing of the arrays in each TU > is migrated by a speed up in how much code/debugging info > is produced in the end. > > Note I looked at generic-match.cc since it is one of the > compiling sources which causes parallel building to stall and > I wanted to speed it up. > > OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. > Or should this wait until GCC 13 branches off? > > gcc/ChangeLog: > > PR middle-end/14840 > * tree-core.h (tree_code_type): Constexprify > by including all-tree.def. > (tree_code_length): Likewise. > * tree.cc (tree_code_type): Remove. > (tree_code_length): Remove. > --- > gcc/tree-core.h | 21 +++++++++++++++++++-- > gcc/tree.cc | 24 ------------------------ > 2 files changed, 19 insertions(+), 26 deletions(-) > > diff --git a/gcc/tree-core.h b/gcc/tree-core.h > index af75522504f..e146b133dbd 100644 > --- a/gcc/tree-core.h > +++ b/gcc/tree-core.h > @@ -2284,15 +2284,32 @@ struct floatn_type_info { > /* Matrix describing the structures contained in a given tree code. */ > extern bool tree_contains_struct[MAX_TREE_CODES][64]; > > +#define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE, > +#define END_OF_BASE_TREE_CODES tcc_exceptional, > + > + > /* Class of tree given its code. */ > -extern const enum tree_code_class tree_code_type[]; > +constexpr enum tree_code_class tree_code_type[] = { > +#include "all-tree.def" > +}; > + > +#undef DEFTREECODE > +#undef END_OF_BASE_TREE_CODES > > /* Each tree code class has an associated string representation. > These must correspond to the tree_code_class entries. */ > extern const char *const tree_code_class_strings[]; > > /* Number of argument-words in each kind of tree-node. */ > -extern const unsigned char tree_code_length[]; > + > +#define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH, > +#define END_OF_BASE_TREE_CODES 0, > +constexpr unsigned char tree_code_length[] = { > +#include "all-tree.def" > +}; > + > +#undef DEFTREECODE > +#undef END_OF_BASE_TREE_CODES IIUC defining these globals as non-inline constexpr gives them internal linkage, and so each TU contains its own unique copy of these globals. This bloats cc1plus by a tiny bit and is technically an ODR violation because some inline functions such as tree_class_check also ODR-use these variables and so each defn of tree_class_check will refer to a "different" tree_code_class. Since inline variables are a C++17 feature, I guess we could fix this by defining the globals the old way before C++17 and as inline constexpr otherwise? > > /* Vector of all alias pairs for global symbols. */ > extern GTY(()) vec *alias_pairs; > diff --git a/gcc/tree.cc b/gcc/tree.cc > index 574bd2e65d9..254b2373dcf 100644 > --- a/gcc/tree.cc > +++ b/gcc/tree.cc > @@ -74,31 +74,7 @@ along with GCC; see the file COPYING3. If not see > #include "asan.h" > #include "ubsan.h" > > -/* Tree code classes. */ > > -#define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE, > -#define END_OF_BASE_TREE_CODES tcc_exceptional, > - > -const enum tree_code_class tree_code_type[] = { > -#include "all-tree.def" > -}; > - > -#undef DEFTREECODE > -#undef END_OF_BASE_TREE_CODES > - > -/* Table indexed by tree code giving number of expression > - operands beyond the fixed part of the node structure. > - Not used for types or decls. */ > - > -#define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH, > -#define END_OF_BASE_TREE_CODES 0, > - > -const unsigned char tree_code_length[] = { > -#include "all-tree.def" > -}; > - > -#undef DEFTREECODE > -#undef END_OF_BASE_TREE_CODES > > /* Names of tree components. > Used for printing out the tree and error messages. */ > -- > 2.17.1 > >