From patchwork Tue Oct 10 13:03:33 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 823834 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-463858-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="eeAo31/O"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yBHPD3gSvz9tYM for ; Wed, 11 Oct 2017 00:03:59 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to:cc :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=i+FBIdRSZ6IJz2Uigl9Cv6v8maj5FfgSVaKLLGoqD4yI1uFFKo AeIfW38q3mXHc8nw5GiAvWqUf1aP1RHpn9QPi/ABwHwuqmphsfqJ4S9t2Jg38iL6 w4fYDZyEN1d7EkYJRVXlMbgQmPEDl7xHgt42Ac0/Mc9IhCwl7oOwItzyA= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to:cc :from:subject:message-id:date:mime-version:content-type; s= default; bh=iXYmiE4SGujbPJJD1u9nbJ7sfg4=; b=eeAo31/OLIePTCikXN7v Hli08D7YiTQ88iO8cYBJj44H+EaG564bcaBuggmpPFALKeJw/jgO+ehewNMXCWRZ 5l/57r/mufD0TtNjmY0/YeDDXqSSs8tvd7WqnuJzRT7XmQAP6T+kntficsGj2Vtd EJSydIjgi/HeOvdlPqn8mTI= Received: (qmail 128998 invoked by alias); 10 Oct 2017 13:03:48 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 127300 invoked by uid 89); 10 Oct 2017 13:03:47 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.6 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy=deeply, Forward, H*Ad:U*nathan, 3378 X-HELO: mail-qt0-f170.google.com Received: from mail-qt0-f170.google.com (HELO mail-qt0-f170.google.com) (209.85.216.170) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 10 Oct 2017 13:03:37 +0000 Received: by mail-qt0-f170.google.com with SMTP id o52so50845953qtc.9 for ; Tue, 10 Oct 2017 06:03:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:to:cc:from:subject:message-id:date :user-agent:mime-version:content-language; bh=Kb6oeWST5ackgKo7Z/kAA+kGve/IThOseZOvz1NBjq4=; b=oa8KqSeLtGgJWYtQsJhH9FMTfS1h7xHGXEdzVDUnRyDpw7A7slJ0qMUPuu+oxmBTQg CCK5f9fTc137+00Puom26rwvDmoX1fb9T9EHD0w7guQCRkO7255olFJp9vvUEopIFpCj ySY73C9DaIAU10t4XX70VuhZ9aUPj+ggiKsHA+kY7zbajK3sCifiHI66v+ctrOukmmGu jiGIEbnlDQMYUIxM2HaD8YO4CPPGkmTK0c8O3yPaCnTBsxJmAq6pS8KpfCqfebtMeGhn I8I5PFM/zUbCSA6Z8SvLtc3ZVEiIy3sOZ7EYfzNrLJSu+9Ttn4ae5m0+a90ghLjW0JtS 8FBA== X-Gm-Message-State: AMCzsaV66bGpsmjHgi798dzy96tSj9Daxn6KP0RxUqhrjp5uwaCpx2Wz sntfWJLzRgKC1r6Re6TVv3U= X-Google-Smtp-Source: AOwi7QCqgMKfiEow8+PG3lgDFKcRB3S5SkTGhefGcTQT4Vk/rL94egSEtHRNgkweseoeEtFcoEuz2w== X-Received: by 10.129.156.10 with SMTP id t10mr2030487ywg.9.1507640615708; Tue, 10 Oct 2017 06:03:35 -0700 (PDT) Received: from ?IPv6:2620:10d:c0a3:20fb:7500:e7fb:4a6f:2254? ([2620:10d:c091:200::3:9bf7]) by smtp.googlemail.com with ESMTPSA id k16sm5818615ywh.18.2017.10.10.06.03.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 10 Oct 2017 06:03:35 -0700 (PDT) To: GCC Patches Cc: Richard Biener , Jan Hubicka From: Nathan Sidwell Subject: [PATCH] DECL_ASSEMBLER_NAME and friends Message-ID: <235e8ca5-65d4-ee29-386c-c4594ed35ffd@acm.org> Date: Tue, 10 Oct 2017 09:03:33 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 I have a patch cleaning up a bit of the C++ FE, which will involve hashing via DECL_ASSEMBLER_NAME. however, all the items in that hash are known to have it set, so its mapping to a function call is undesirable. This patch adds DECL_ASSEMBLER_NAME_RAW, which gets at the field directly. I can then use that for my hash table. The cleanup to use that is fairly trivial. However, I also looked more deeply at DECL_ASSEMBLER_NAME_SET_P. It does more than the name suggests -- namely checking HAS_DECL_ASSEMBLER_NAME_P too. There are about 72 uses of DECL_ASSEMBLER_NAME_SET_P and investigation showed only about 4 applying it to decls that are not HAS_DECL_ASSEMBLER_NAME_P. So, I remove the HAS_DECL_ASSEMBLER_NAME_P from DECL_ASSEMBLER_NAME_SET_P and explicitly check it at the 4 locations that need it. In doing this I noticed a couple of items: 1) ipa-utils.h (type_in_anonymous_namespace_p) is applying HAS_DECL_ASSEMBLER_NAME_P to a type. That's clearly wrong, It looks like a thinko for TYPE_NAME (t). Making that change seems fine. 2) tree-ssa-structalias.c (alias_get_name) seemed overly complicated, so I reimplemented it. I checked the target-specific code, and there are only two uses of DECL_ASSEMBLER_NAME_SET_P. Both look safe to me (the avr one seems superfluous, and DECL_ASSEMBLER_NAME would be fine there. booted on x86_64-linux ok? nathan 2017-10-10 Nathan Sidwell * tree.h (DECL_ASSEMBLER_NAME_RAW): New. (SET_DECL_ASSEMBLER_NAME): Use it. (DECL_ASSEMBLER_NAME_SET_P): Likewise. Don't check HAS_DECL_ASSEMBLER_NAME_P. * tree.c (decl_assembler_name): Use DECL_ASSEMBLER_NAME_RAW. * gimple-expr.c (gimple_decl_printable_name: Check HAS_DECL_ASSEMBLER_NAME_P too. * ipa-utils.h (type_in_anonymous_namespace_p): Check DECL_ASSEMBLER_NAME_SET_P of TYPE_NAME. (odr_type_p): No need to assert TYPE_NAME is a TYPE_DECL. * passes.c (rest_of_decl_compilation): Check HAS_DECL_ASSEMBLER_NAME_P too. * recog.c (verify_changes): Likewise. * tree-pretty-print.c (dump_decl_name): Likewise. * tree-ssa-structalias.c (alias_get_name): Likewise. Reimplement. c/ * c-decl.c (grokdeclarator): Check HAS_DECL_ASSEMBLER_NAME_P too. lto/ * lto.c (mentions_vars_p_decl_with_vis): Use DECL_ASSEMBLER_NAME_RAW. (lto_fixup_prevailing_decls): Likewise. Index: c/c-decl.c =================================================================== --- c/c-decl.c (revision 253502) +++ c/c-decl.c (working copy) @@ -7011,7 +7011,8 @@ grokdeclarator (const struct c_declarato /* This is the earliest point at which we might know the assembler name of a variable. Thus, if it's known before this, die horribly. */ - gcc_assert (!DECL_ASSEMBLER_NAME_SET_P (decl)); + gcc_assert (!HAS_DECL_ASSEMBLER_NAME_P (decl) + || !DECL_ASSEMBLER_NAME_SET_P (decl)); if (warn_cxx_compat && VAR_P (decl) Index: gimple-expr.c =================================================================== --- gimple-expr.c (revision 253502) +++ gimple-expr.c (working copy) @@ -337,9 +337,8 @@ gimple_decl_printable_name (tree decl, i if (!DECL_NAME (decl)) return NULL; - if (DECL_ASSEMBLER_NAME_SET_P (decl)) + if (HAS_DECL_ASSEMBLER_NAME_P (decl) && DECL_ASSEMBLER_NAME_SET_P (decl)) { - const char *str, *mangled_str; int dmgl_opts = DMGL_NO_OPTS; if (verbosity >= 2) @@ -352,9 +351,10 @@ gimple_decl_printable_name (tree decl, i dmgl_opts |= DMGL_PARAMS; } - mangled_str = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)); - str = cplus_demangle_v3 (mangled_str, dmgl_opts); - return (str) ? str : mangled_str; + const char *mangled_str + = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME_RAW (decl)); + const char *str = cplus_demangle_v3 (mangled_str, dmgl_opts); + return str ? str : mangled_str; } return IDENTIFIER_POINTER (DECL_NAME (decl)); Index: ipa-utils.h =================================================================== --- ipa-utils.h (revision 253502) +++ ipa-utils.h (working copy) @@ -217,11 +217,11 @@ type_in_anonymous_namespace_p (const_tre { /* C++ FE uses magic as assembler names of anonymous types. verify that this match with type_in_anonymous_namespace_p. */ - gcc_checking_assert (!in_lto_p || !DECL_ASSEMBLER_NAME_SET_P (t) - || !strcmp - ("", - IDENTIFIER_POINTER - (DECL_ASSEMBLER_NAME (TYPE_NAME (t))))); + gcc_checking_assert (!in_lto_p + || !DECL_ASSEMBLER_NAME_SET_P (TYPE_NAME (t)) + || !strcmp ("", + IDENTIFIER_POINTER + (DECL_ASSEMBLER_NAME (TYPE_NAME (t))))); return true; } return false; @@ -245,14 +245,13 @@ odr_type_p (const_tree t) if (type_in_anonymous_namespace_p (t)) return true; - if (TYPE_NAME (t) && TREE_CODE (TYPE_NAME (t)) == TYPE_DECL - && DECL_ASSEMBLER_NAME_SET_P (TYPE_NAME (t))) + if (TYPE_NAME (t) && DECL_ASSEMBLER_NAME_SET_P (TYPE_NAME (t))) { /* C++ FE uses magic as assembler names of anonymous types. verify that this match with type_in_anonymous_namespace_p. */ gcc_checking_assert (strcmp ("", - IDENTIFIER_POINTER - (DECL_ASSEMBLER_NAME (TYPE_NAME (t))))); + IDENTIFIER_POINTER + (DECL_ASSEMBLER_NAME (TYPE_NAME (t))))); return true; } return false; Index: lto/lto.c =================================================================== --- lto/lto.c (revision 253502) +++ lto/lto.c (working copy) @@ -591,7 +591,7 @@ mentions_vars_p_decl_with_vis (tree t) return true; /* Accessor macro has side-effects, use field-name here. */ - CHECK_NO_VAR (t->decl_with_vis.assembler_name); + CHECK_NO_VAR (DECL_ASSEMBLER_NAME_RAW (t)); return false; } @@ -2557,7 +2557,7 @@ lto_fixup_prevailing_decls (tree t) } if (CODE_CONTAINS_STRUCT (code, TS_DECL_WITH_VIS)) { - LTO_NO_PREVAIL (t->decl_with_vis.assembler_name); + LTO_NO_PREVAIL (DECL_ASSEMBLER_NAME_RAW (t)); } if (CODE_CONTAINS_STRUCT (code, TS_DECL_NON_COMMON)) { Index: passes.c =================================================================== --- passes.c (revision 253502) +++ passes.c (working copy) @@ -197,7 +197,9 @@ rest_of_decl_compilation (tree decl, /* Can't defer this, because it needs to happen before any later function definitions are processed. */ - if (DECL_ASSEMBLER_NAME_SET_P (decl) && DECL_REGISTER (decl)) + if (HAS_DECL_ASSEMBLER_NAME_P (decl) + && DECL_ASSEMBLER_NAME_SET_P (decl) + && DECL_REGISTER (decl)) make_decl_rtl (decl); /* Forward declarations for nested functions are not "external", Index: recog.c =================================================================== --- recog.c (revision 253502) +++ recog.c (working copy) @@ -408,6 +408,7 @@ verify_changes (int num) && REG_P (changes[i].old) && asm_noperands (PATTERN (object)) > 0 && REG_EXPR (changes[i].old) != NULL_TREE + && HAS_DECL_ASSEMBLER_NAME_P (REG_EXPR (changes[i].old)) && DECL_ASSEMBLER_NAME_SET_P (REG_EXPR (changes[i].old)) && DECL_REGISTER (REG_EXPR (changes[i].old))) { Index: tree-pretty-print.c =================================================================== --- tree-pretty-print.c (revision 253502) +++ tree-pretty-print.c (working copy) @@ -249,8 +249,10 @@ dump_decl_name (pretty_printer *pp, tree { if (DECL_NAME (node)) { - if ((flags & TDF_ASMNAME) && DECL_ASSEMBLER_NAME_SET_P (node)) - pp_tree_identifier (pp, DECL_ASSEMBLER_NAME (node)); + if ((flags & TDF_ASMNAME) + && HAS_DECL_ASSEMBLER_NAME_P (node) + && DECL_ASSEMBLER_NAME_SET_P (node)) + pp_tree_identifier (pp, DECL_ASSEMBLER_NAME_RAW (node)); /* For DECL_NAMELESS names look for embedded uids in the names and sanitize them for TDF_NOUID. */ else if ((flags & TDF_NOUID) && DECL_NAMELESS (node)) Index: tree-ssa-structalias.c =================================================================== --- tree-ssa-structalias.c (revision 253502) +++ tree-ssa-structalias.c (working copy) @@ -2849,41 +2849,33 @@ lookup_vi_for_tree (tree t) static const char * alias_get_name (tree decl) { - const char *res = NULL; - char *temp; - - if (!dump_file) - return "NULL"; - - if (TREE_CODE (decl) == SSA_NAME) + const char *res = "NULL"; + if (dump_file) { - res = get_name (decl); - if (res) - temp = xasprintf ("%s_%u", res, SSA_NAME_VERSION (decl)); - else - temp = xasprintf ("_%u", SSA_NAME_VERSION (decl)); - res = ggc_strdup (temp); - free (temp); - } - else if (DECL_P (decl)) - { - if (DECL_ASSEMBLER_NAME_SET_P (decl)) - res = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)); - else + char *temp = NULL; + if (TREE_CODE (decl) == SSA_NAME) + { + res = get_name (decl); + temp = xasprintf ("%s_%u", res ? res : "", SSA_NAME_VERSION (decl)); + } + else if (HAS_DECL_ASSEMBLER_NAME_P (decl) + && DECL_ASSEMBLER_NAME_SET_P (decl)) + res = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME_RAW (decl)); + else if (DECL_P (decl)) { res = get_name (decl); if (!res) - { - temp = xasprintf ("D.%u", DECL_UID (decl)); - res = ggc_strdup (temp); - free (temp); - } + temp = xasprintf ("D.%u", DECL_UID (decl)); + } + + if (temp) + { + res = ggc_strdup (temp); + free (temp); } } - if (res != NULL) - return res; - return "NULL"; + return res; } /* Find the variable id for tree T in the map. Index: tree.c =================================================================== --- tree.c (revision 253502) +++ tree.c (working copy) @@ -671,7 +671,7 @@ decl_assembler_name (tree decl) { if (!DECL_ASSEMBLER_NAME_SET_P (decl)) lang_hooks.set_decl_assembler_name (decl); - return DECL_WITH_VIS_CHECK (decl)->decl_with_vis.assembler_name; + return DECL_ASSEMBLER_NAME_RAW (decl); } /* When the target supports COMDAT groups, this indicates which group the Index: tree.h =================================================================== --- tree.h (revision 253502) +++ tree.h (working copy) @@ -2722,6 +2722,10 @@ extern void decl_value_expr_insert (tree LTO compilation and C++. */ #define DECL_ASSEMBLER_NAME(NODE) decl_assembler_name (NODE) +/* Raw accessor for DECL_ASSEMBLE_NAME. */ +#define DECL_ASSEMBLER_NAME_RAW(NODE) \ + (DECL_WITH_VIS_CHECK (NODE)->decl_with_vis.assembler_name) + /* Return true if NODE is a NODE that can contain a DECL_ASSEMBLER_NAME. This is true of all DECL nodes except FIELD_DECL. */ #define HAS_DECL_ASSEMBLER_NAME_P(NODE) \ @@ -2731,12 +2735,11 @@ extern void decl_value_expr_insert (tree the NODE might still have a DECL_ASSEMBLER_NAME -- it just hasn't been set yet. */ #define DECL_ASSEMBLER_NAME_SET_P(NODE) \ - (HAS_DECL_ASSEMBLER_NAME_P (NODE) \ - && DECL_WITH_VIS_CHECK (NODE)->decl_with_vis.assembler_name != NULL_TREE) + (DECL_ASSEMBLER_NAME_RAW (NODE) != NULL_TREE) /* Set the DECL_ASSEMBLER_NAME for NODE to NAME. */ #define SET_DECL_ASSEMBLER_NAME(NODE, NAME) \ - (DECL_WITH_VIS_CHECK (NODE)->decl_with_vis.assembler_name = (NAME)) + (DECL_ASSEMBLER_NAME_RAW (NODE) = (NAME)) /* Copy the DECL_ASSEMBLER_NAME from DECL1 to DECL2. Note that if DECL1's DECL_ASSEMBLER_NAME has not yet been set, using this macro will not cause