From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 120859 invoked by alias); 13 Oct 2017 18:29:48 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 120457 invoked by uid 89); 13 Oct 2017 18:29: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=defects, cares, (unknown) X-HELO: mail-qt0-f174.google.com Received: from mail-qt0-f174.google.com (HELO mail-qt0-f174.google.com) (209.85.216.174) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 13 Oct 2017 18:29:44 +0000 Received: by mail-qt0-f174.google.com with SMTP id 1so21251904qtn.3 for ; Fri, 13 Oct 2017 11:29:44 -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:from:subject:message-id:date :user-agent:mime-version:content-language; bh=RF4NXU4uk6IOdlWQG2/nH6EWegnGipUNPQi7bpsiMxY=; b=IRHaylLmkf+etwv6Tk/bOvdCpn4Yokt5xt5jpExzPgbhFRbOoyRUOorrURPHzk1zTr 0murYS6oQ+zxiRhVIqRDim82miac/M7oJy9Y1cQRkrGkuaqISYRmX2C/ObC4pGZ6xFDs fmq547vaJs/YGN7+AtjOe5hFZxEi32YMtrFIM/Q6bu8Ofo04JRujhqePIKpyWJI9Zy87 mjKaYTVKvikdx5gOwQzwNObtQlsGQ2lTkcYzfK7CQyEJ8O5zXPrdJ0PygW6YV7OhRs2k QfHnHa9zUb9usZLucTXuv+q5rVuI3K0h5I5O3rM3nKrcyH1fOU9OJs+tatp0NdSUX7rx Pzig== X-Gm-Message-State: AMCzsaUIS0BvBs7Lv/GECB0fgBDmWBupy+YNwcr8fzzanbYOPOKr6MyJ wj6vv9i/v+0eKjnTLpiIHuI= X-Google-Smtp-Source: ABhQp+RiI7av9dg7SOeU/AXH2qjkJkad1IJB5H9cPF0n/JIj2+y7elWtoB5/VbidTCWZHHkBQrdulA== X-Received: by 10.37.171.8 with SMTP id u8mr1519905ybi.315.1507919382526; Fri, 13 Oct 2017 11:29:42 -0700 (PDT) Received: from ?IPv6:2620:10d:c0a3:20fb:7500:e7fb:4a6f:2254? ([2620:10d:c091:200::7ed9]) by smtp.googlemail.com with ESMTPSA id k16sm897055ywh.18.2017.10.13.11.29.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 Oct 2017 11:29:42 -0700 (PDT) To: GCC Patches , Jeff Law , Richard Biener From: Nathan Sidwell Subject: [PATCH PR/82546] tree node size Message-ID: <3e7ecb64-cd96-47a3-cb75-53e41317d90c@acm.org> Date: Fri, 13 Oct 2017 18:32:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------09117E3FC8AD7C85255DFB32" X-SW-Source: 2017-10/txt/msg00900.txt.bz2 This is a multi-part message in MIME format. --------------09117E3FC8AD7C85255DFB32 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-length: 1518 [Although I filed this as a middle-end bug, it's really a core infra bug, not sure who the best reviewer is] In working on tree streaming in the modules branch, I discovered poor tree node size and hierarchy bits. Here's a fix for the first part of that. tree.c (tree_code_size) returns sizeof (tree_type_non_common) for any tcc_type node. That's wasteful, given we have tree_type_common-> tree_type_with_lang_specific-> tree_type_non_common available as choices. It's also obscuring defects in (at least) the c++ FE where we use tree_type_non_common fields, but claim the node doesn't contain that structure. Ew. This patch makes tree_code_size ask the lang hook for the size of non-core type nodes. It also fixes the c++ and objc FEs to return a size for the nodes it cares about. I don't (yet) know whether all the core types are tree_type_non_common, nor whether the FE's can return smaller sizes than the do with this patch. But at least the control flow is now correct. during developing this patch I added an assert that the lang hook was returning a size at least as big as tree_type_non_common, so they couldn't be more broken than before the patch. I intend to continue cleaning this up of course. It's not clear to me whether we should cache these node sizes in an array, and the way it goes about checking nodes with nested switches is understandable, but possible not the fastest solution. However let's at least get the sizing right first. ok? nathan -- Nathan Sidwell --------------09117E3FC8AD7C85255DFB32 Content-Type: text/x-patch; name="ns.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="ns.diff" Content-length: 8810 2017-10-13 Nathan Sidwell PR middle-end/82546 gcc/ * tree.c (tree_code_size): Reformat. Punt to lang hook for unknown TYPE nodes. gcc/cp/ * cp-objcp-common.c (cp_tree_size): Reformat. Adjust returns size of TYPE nodes. gcc/objc/ * objc-act.c (objc_common_tree_size): Return size of TYPE nodes. Index: cp/cp-objcp-common.c =================================================================== --- cp/cp-objcp-common.c (revision 253733) +++ cp/cp-objcp-common.c (working copy) @@ -61,43 +61,34 @@ cxx_warn_unused_global_decl (const_tree size_t cp_tree_size (enum tree_code code) { + gcc_checking_assert (code >= NUM_TREE_CODES); switch (code) { - case PTRMEM_CST: return sizeof (struct ptrmem_cst); - case BASELINK: return sizeof (struct tree_baselink); + case PTRMEM_CST: return sizeof (ptrmem_cst); + case BASELINK: return sizeof (tree_baselink); case TEMPLATE_PARM_INDEX: return sizeof (template_parm_index); - case DEFAULT_ARG: return sizeof (struct tree_default_arg); - case DEFERRED_NOEXCEPT: return sizeof (struct tree_deferred_noexcept); - case OVERLOAD: return sizeof (struct tree_overload); - case STATIC_ASSERT: return sizeof (struct tree_static_assert); + case DEFAULT_ARG: return sizeof (tree_default_arg); + case DEFERRED_NOEXCEPT: return sizeof (tree_deferred_noexcept); + case OVERLOAD: return sizeof (tree_overload); + case STATIC_ASSERT: return sizeof (tree_static_assert); case TYPE_ARGUMENT_PACK: - case TYPE_PACK_EXPANSION: - return sizeof (struct tree_common); - + case TYPE_PACK_EXPANSION: return sizeof (tree_type_non_common); case NONTYPE_ARGUMENT_PACK: - case EXPR_PACK_EXPANSION: - return sizeof (struct tree_exp); - - case ARGUMENT_PACK_SELECT: - return sizeof (struct tree_argument_pack_select); - - case TRAIT_EXPR: - return sizeof (struct tree_trait_expr); - - case LAMBDA_EXPR: return sizeof (struct tree_lambda_expr); - - case TEMPLATE_INFO: return sizeof (struct tree_template_info); - - case CONSTRAINT_INFO: return sizeof (struct tree_constraint_info); - - case USERDEF_LITERAL: return sizeof (struct tree_userdef_literal); - - case TEMPLATE_DECL: return sizeof (struct tree_template_decl); - + case EXPR_PACK_EXPANSION: return sizeof (tree_exp); + case ARGUMENT_PACK_SELECT: return sizeof (tree_argument_pack_select); + case TRAIT_EXPR: return sizeof (tree_trait_expr); + case LAMBDA_EXPR: return sizeof (tree_lambda_expr); + case TEMPLATE_INFO: return sizeof (tree_template_info); + case CONSTRAINT_INFO: return sizeof (tree_constraint_info); + case USERDEF_LITERAL: return sizeof (tree_userdef_literal); + case TEMPLATE_DECL: return sizeof (tree_template_decl); default: - if (TREE_CODE_CLASS (code) == tcc_declaration) - return sizeof (struct tree_decl_non_common); - gcc_unreachable (); + switch (TREE_CODE_CLASS (code)) + { + case tcc_declaration: return sizeof (tree_decl_non_common); + case tcc_type: return sizeof (tree_type_non_common); + default: gcc_unreachable (); + } } /* NOTREACHED */ } Index: objc/objc-act.c =================================================================== --- objc/objc-act.c (revision 253733) +++ objc/objc-act.c (working copy) @@ -10118,11 +10118,14 @@ objc_common_tree_size (enum tree_code co case CLASS_METHOD_DECL: case INSTANCE_METHOD_DECL: case KEYWORD_DECL: - case PROPERTY_DECL: - return sizeof (struct tree_decl_non_common); + case PROPERTY_DECL: return sizeof (tree_decl_non_common); + case CLASS_INTERFACE_TYPE: + case CLASS_IMPLEMENTATION_TYPE: + case CATEGORY_INTERFACE_TYPE: + case CATEGORY_IMPLEMENTATION_TYPE: + case PROTOCOL_INTERFACE_TYPE: return sizeof (tree_type_non_common); default: gcc_unreachable (); - } } Index: tree.c =================================================================== --- tree.c (revision 253733) +++ tree.c (working copy) @@ -763,40 +763,53 @@ tree_code_size (enum tree_code code) switch (TREE_CODE_CLASS (code)) { case tcc_declaration: /* A decl node */ - { - switch (code) - { - case FIELD_DECL: - return sizeof (struct tree_field_decl); - case PARM_DECL: - return sizeof (struct tree_parm_decl); - case VAR_DECL: - return sizeof (struct tree_var_decl); - case LABEL_DECL: - return sizeof (struct tree_label_decl); - case RESULT_DECL: - return sizeof (struct tree_result_decl); - case CONST_DECL: - return sizeof (struct tree_const_decl); - case TYPE_DECL: - return sizeof (struct tree_type_decl); - case FUNCTION_DECL: - return sizeof (struct tree_function_decl); - case DEBUG_EXPR_DECL: - return sizeof (struct tree_decl_with_rtl); - case TRANSLATION_UNIT_DECL: - return sizeof (struct tree_translation_unit_decl); - case NAMESPACE_DECL: - case IMPORTED_DECL: - case NAMELIST_DECL: - return sizeof (struct tree_decl_non_common); - default: - return lang_hooks.tree_size (code); - } - } + switch (code) + { + case FIELD_DECL: return sizeof (tree_field_decl); + case PARM_DECL: return sizeof (tree_parm_decl); + case VAR_DECL: return sizeof (tree_var_decl); + case LABEL_DECL: return sizeof (tree_label_decl); + case RESULT_DECL: return sizeof (tree_result_decl); + case CONST_DECL: return sizeof (tree_const_decl); + case TYPE_DECL: return sizeof (tree_type_decl); + case FUNCTION_DECL: return sizeof (tree_function_decl); + case DEBUG_EXPR_DECL: return sizeof (tree_decl_with_rtl); + case TRANSLATION_UNIT_DECL: return sizeof (tree_translation_unit_decl); + case NAMESPACE_DECL: + case IMPORTED_DECL: + case NAMELIST_DECL: return sizeof (tree_decl_non_common); + default: + gcc_checking_assert (code >= NUM_TREE_CODES); + return lang_hooks.tree_size (code); + } case tcc_type: /* a type node */ - return sizeof (struct tree_type_non_common); + switch (code) + { + case OFFSET_TYPE: + case ENUMERAL_TYPE: + case BOOLEAN_TYPE: + case INTEGER_TYPE: + case REAL_TYPE: + case POINTER_TYPE: + case REFERENCE_TYPE: + case NULLPTR_TYPE: + case FIXED_POINT_TYPE: + case COMPLEX_TYPE: + case VECTOR_TYPE: + case ARRAY_TYPE: + case RECORD_TYPE: + case UNION_TYPE: + case QUAL_UNION_TYPE: + case VOID_TYPE: + case POINTER_BOUNDS_TYPE: + case FUNCTION_TYPE: + case METHOD_TYPE: + case LANG_TYPE: return sizeof (tree_type_non_common); + default: + gcc_checking_assert (code >= NUM_TREE_CODES); + return lang_hooks.tree_size (code); + } case tcc_reference: /* a reference */ case tcc_expression: /* an expression */ @@ -810,14 +823,15 @@ tree_code_size (enum tree_code code) case tcc_constant: /* a constant */ switch (code) { - case VOID_CST: return sizeof (struct tree_typed); + case VOID_CST: return sizeof (tree_typed); case INTEGER_CST: gcc_unreachable (); - case REAL_CST: return sizeof (struct tree_real_cst); - case FIXED_CST: return sizeof (struct tree_fixed_cst); - case COMPLEX_CST: return sizeof (struct tree_complex); - case VECTOR_CST: return sizeof (struct tree_vector); + case REAL_CST: return sizeof (tree_real_cst); + case FIXED_CST: return sizeof (tree_fixed_cst); + case COMPLEX_CST: return sizeof (tree_complex); + case VECTOR_CST: return sizeof (tree_vector); case STRING_CST: gcc_unreachable (); default: + gcc_checking_assert (code >= NUM_TREE_CODES); return lang_hooks.tree_size (code); } @@ -825,23 +839,24 @@ tree_code_size (enum tree_code code) switch (code) { case IDENTIFIER_NODE: return lang_hooks.identifier_size; - case TREE_LIST: return sizeof (struct tree_list); + case TREE_LIST: return sizeof (tree_list); case ERROR_MARK: - case PLACEHOLDER_EXPR: return sizeof (struct tree_common); + case PLACEHOLDER_EXPR: return sizeof (tree_common); - case TREE_VEC: + case TREE_VEC: gcc_unreachable (); case OMP_CLAUSE: gcc_unreachable (); - case SSA_NAME: return sizeof (struct tree_ssa_name); + case SSA_NAME: return sizeof (tree_ssa_name); - case STATEMENT_LIST: return sizeof (struct tree_statement_list); + case STATEMENT_LIST: return sizeof (tree_statement_list); case BLOCK: return sizeof (struct tree_block); - case CONSTRUCTOR: return sizeof (struct tree_constructor); - case OPTIMIZATION_NODE: return sizeof (struct tree_optimization_option); - case TARGET_OPTION_NODE: return sizeof (struct tree_target_option); + case CONSTRUCTOR: return sizeof (tree_constructor); + case OPTIMIZATION_NODE: return sizeof (tree_optimization_option); + case TARGET_OPTION_NODE: return sizeof (tree_target_option); default: + gcc_checking_assert (code >= NUM_TREE_CODES); return lang_hooks.tree_size (code); } --------------09117E3FC8AD7C85255DFB32--