From patchwork Mon Apr 27 10:26:55 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 464932 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 4906C1402B6 for ; Mon, 27 Apr 2015 20:29:28 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass reason="1024-bit key; unprotected key" header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=oxVJkSi4; dkim-adsp=none (unprotected policy); dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:mime-version:content-type :content-transfer-encoding; q=dns; s=default; b=l6gl7ba30Q8jWDEK qnx5BdMZHkxcaPfCYj4z5gm+h2to109xFfu5VynMegHE3UY7DXEQ1u/vyMbISTPX GUg1180gpQJT2pvb237qmipKiwLq/NGsfhFbwlyzoCUAtf96K4L79d5YXdBkUXBI c2MKTKLRg9d0f4NDGRER+lHtM4c= 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:from :to:subject:date:message-id:mime-version:content-type :content-transfer-encoding; s=default; bh=az1R9DPtnBvd0eAsiKKQ1t yp3mc=; b=oxVJkSi4Jpm5logqR5SH70x8ymfDEm/TuVYt+5MhpF2weHCILnWWyo /tdj1ahNzyM/NWal7yEceZHlGPkMoiZ+su86iX7SOQ+TQT2YdiYoJ6Tl1rCVrLuo Z4KRONViz/C5R0U0aVJXN8xtDMD8uaL2+pf/J3pApa39AsFipv1v8= Received: (qmail 61610 invoked by alias); 27 Apr 2015 10:29:20 -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 61597 invoked by uid 89); 27 Apr 2015 10:29:20 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.4 required=5.0 tests=AWL, BAYES_00, KAM_ASCII_DIVIDERS, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_LOW autolearn=no version=3.3.2 X-HELO: smtp.eu.adacore.com Received: from mel.act-europe.fr (HELO smtp.eu.adacore.com) (194.98.77.210) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Mon, 27 Apr 2015 10:29:19 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id 1D1112E15625 for ; Mon, 27 Apr 2015 12:29:15 +0200 (CEST) Received: from smtp.eu.adacore.com ([127.0.0.1]) by localhost (smtp.eu.adacore.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id XGY4VFkyUIS1 for ; Mon, 27 Apr 2015 12:29:15 +0200 (CEST) Received: from polaris.localnet (bon31-6-88-161-99-133.fbx.proxad.net [88.161.99.133]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.eu.adacore.com (Postfix) with ESMTPSA id DB8AF2E15623 for ; Mon, 27 Apr 2015 12:29:14 +0200 (CEST) From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: Minor tweak to size functions Date: Mon, 27 Apr 2015 12:26:55 +0200 Message-ID: <1961080.nQ7DLJsfTp@polaris> User-Agent: KMail/4.7.2 (Linux/3.1.10-1.29-desktop; KDE/4.7.2; x86_64; ; ) MIME-Version: 1.0 The size functions are used by the Ada compiler to factor out the large size computations in self-referential types (dynamic types whose size depends on a discriminant in the object). We generate useless leaf size functions for size expressions involving discriminants: _Global.Sz4_Q (ada__streams__stream_element_count___XDLU_0__9223372036854775807 p0) { return (bitsizetype) p0 * 8; _Global.Sz5_Q (ada__streams__stream_element_count___XDLU_0__9223372036854775807 p0) { return (sizetype) p0; _Global.Sz6_Q (ada__streams__stream_element_count___XDLU_0__9223372036854775807 p0) { return (bitsizetype) p0 * 8; _Global.Sz7_Q (ada__streams__stream_element_count___XDLU_0__9223372036854775807 p0) { return (sizetype) p0; The wrapped expressions are simple arithmetic operations so there is no real point in creating a size function for them. That's already ensured for non- leaf size functions (size functions calling other size functions) and it's immediate to extend it down to the leaves. Tested on x86_64-suse-linux, applied on the mainline (this only affects the Ada compiler). The tree-cfg.c hunk adds the missing curly bracket at the end in the above dumps, applied as obvious. 2015-04-27 Eric Botcazou * stor-layout.c (self_referential_component_ref_p): New predicate. (copy_self_referential_tree_r): Use it. (self_referential_size): Punt for simple operations directly involving self-referential component references. * tree-cfg.c (dump_function_to_file): Add missing final curly bracket. Index: stor-layout.c =================================================================== --- stor-layout.c (revision 222439) +++ stor-layout.c (working copy) @@ -127,6 +127,20 @@ variable_size (tree size) /* An array of functions used for self-referential size computation. */ static GTY(()) vec *size_functions; +/* Return true if T is a self-referential component reference. */ + +static bool +self_referential_component_ref_p (tree t) +{ + if (TREE_CODE (t) != COMPONENT_REF) + return false; + + while (REFERENCE_CLASS_P (t)) + t = TREE_OPERAND (t, 0); + + return (TREE_CODE (t) == PLACEHOLDER_EXPR); +} + /* Similar to copy_tree_r but do not copy component references involving PLACEHOLDER_EXPRs. These nodes are spotted in find_placeholder_in_expr and substituted in substitute_in_expr. */ @@ -154,19 +168,10 @@ copy_self_referential_tree_r (tree *tp, } /* Default case: the component reference. */ - else if (code == COMPONENT_REF) + else if (self_referential_component_ref_p (*tp)) { - tree inner; - for (inner = TREE_OPERAND (*tp, 0); - REFERENCE_CLASS_P (inner); - inner = TREE_OPERAND (inner, 0)) - ; - - if (TREE_CODE (inner) == PLACEHOLDER_EXPR) - { - *walk_subtrees = 0; - return NULL_TREE; - } + *walk_subtrees = 0; + return NULL_TREE; } /* We're not supposed to have them in self-referential size trees @@ -199,7 +204,7 @@ self_referential_size (tree size) /* Do not factor out simple operations. */ t = skip_simple_constant_arithmetic (size); - if (TREE_CODE (t) == CALL_EXPR) + if (TREE_CODE (t) == CALL_EXPR || self_referential_component_ref_p (t)) return size; /* Collect the list of self-references in the expression. */ Index: tree-cfg.c =================================================================== --- tree-cfg.c (revision 222439) +++ tree-cfg.c (working copy) @@ -7441,7 +7441,11 @@ dump_function_to_file (tree fndecl, FILE else { if (!ignore_topmost_bind) - fprintf (file, "{\n"); + { + fprintf (file, "{\n"); + /* No topmost bind, pretend it's ignored for later. */ + ignore_topmost_bind = true; + } indent = 2; }