From patchwork Thu Aug 14 22:23:33 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Enkovich X-Patchwork-Id: 380036 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 E1AB3140090 for ; Fri, 15 Aug 2014 08:23:54 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=u6ugvwLPpC40uMSfOj7nKrLeON9//DPcNC/h7Hl5cjTz4V7VTqcKI rYDQLlm9knLiH/MKs5wspyMqUcjtGcQ4RKPNLM4FQgCQExXlDPuN/zCOS/Zg4OJv WBly1HBr9mOR5eGwXv3hnybUdu35NuHpX3wWCrbEU7Y4qHCFaTzmK0= 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:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=HdSR4LSnV0Z5seHEeWvwWdtqqsE=; b=MpSXYWEB+C/Qq84uunvH FflkvezdpfBgKbSHwIiX2D2l1M/rnEjRvAD9TXeQg5Ovv4mN32mrquNdFTYZHcMH zCKc/+fvNM6nAcV2r9kNK7EwbSKyXer4SPw4qVYpZ5BDpwWtgZ+J8dlKDU4gupz5 HTtFegrGHeNNqfV3naiy8lU= Received: (qmail 3612 invoked by alias); 14 Aug 2014 22:23: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 3584 invoked by uid 89); 14 Aug 2014 22:23:47 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.5 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-pd0-f175.google.com Received: from mail-pd0-f175.google.com (HELO mail-pd0-f175.google.com) (209.85.192.175) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Thu, 14 Aug 2014 22:23:46 +0000 Received: by mail-pd0-f175.google.com with SMTP id r10so2307416pdi.6 for ; Thu, 14 Aug 2014 15:23:44 -0700 (PDT) X-Received: by 10.68.117.238 with SMTP id kh14mr7295445pbb.55.1408055024493; Thu, 14 Aug 2014 15:23:44 -0700 (PDT) Received: from msticlxl57.ims.intel.com (fmdmzpr02-ext.fm.intel.com. [192.55.55.37]) by mx.google.com with ESMTPSA id pl10sm6308680pbb.56.2014.08.14.15.23.42 for (version=TLSv1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 14 Aug 2014 15:23:43 -0700 (PDT) Date: Fri, 15 Aug 2014 02:23:33 +0400 From: Ilya Enkovich To: gcc-patches@gcc.gnu.org Subject: [PATCH] Avoid redundant indirect_info computation during inderct edge cloning Message-ID: <20140814222333.GA34087@msticlxl57.ims.intel.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes Hi, I get a segafult in decl_maybe_in_construction_p during function versioning. We have following steps in clone creation (e.g. as in create_version_clone_with_body): 1. Create function decl 2. Create clone of cgraph node 3. Copy function body After the first step there is no body attached to function and DECL_STRUCT_FUNCTION for new decl is NULL. It is initialized on the third step. But on the second step get_polymorphic_call_info may be called for new function; it calls decl_maybe_in_construction_p which assumes DECL_STRUCT_FUNCTION already exists. I firstly wanted to fix decl_maybe_in_construction_p but then realized cgraph_clone_edge copy indirect_info from the original edge anyway and therefore its computation is not required at all. Following patch removes redundant indirect_info computation. Bootstrapped and regtested on linux-x86_64. Does it look OK for trunk? Thanks, Ilya --- 2014-08-15 Ilya Enkovich * cgraph.h (cgraph_node::create_indirect_edge): Add compute_indirect_info param. * cgraph.c (cgraph_node::create_indirect_edge): Compute indirect_info only when it is required. * cgraphclones.c (cgraph_clone_edge): Do not recompute indirect_info for cloned indirect edge. diff --git a/gcc/cgraph.c b/gcc/cgraph.c index 370a96a..cb49cdc 100644 --- a/gcc/cgraph.c +++ b/gcc/cgraph.c @@ -942,7 +942,8 @@ cgraph_allocate_init_indirect_info (void) struct cgraph_edge * cgraph_node::create_indirect_edge (gimple call_stmt, int ecf_flags, - gcov_type count, int freq) + gcov_type count, int freq, + bool compute_indirect_info) { struct cgraph_edge *edge = cgraph_node::create_edge (this, NULL, call_stmt, count, freq, true); @@ -954,7 +955,8 @@ cgraph_node::create_indirect_edge (gimple call_stmt, int ecf_flags, edge->indirect_info->ecf_flags = ecf_flags; /* Record polymorphic call info. */ - if (call_stmt + if (compute_indirect_info + && call_stmt && (target = gimple_call_fn (call_stmt)) && virtual_method_call_p (target)) { diff --git a/gcc/cgraph.h b/gcc/cgraph.h index 13c09af..2594ae5 100644 --- a/gcc/cgraph.h +++ b/gcc/cgraph.h @@ -915,7 +915,8 @@ public: statement destination is a formal parameter of the caller with index PARAM_INDEX. */ struct cgraph_edge *create_indirect_edge (gimple call_stmt, int ecf_flags, - gcov_type count, int freq); + gcov_type count, int freq, + bool compute_indirect_info = true); /* Like cgraph_create_edge walk the clone tree and update all clones sharing same function body. If clones already have edge for OLD_STMT; only diff --git a/gcc/cgraphclones.c b/gcc/cgraphclones.c index c04b5c8..557f734 100644 --- a/gcc/cgraphclones.c +++ b/gcc/cgraphclones.c @@ -136,7 +136,7 @@ cgraph_clone_edge (struct cgraph_edge *e, struct cgraph_node *n, { new_edge = n->create_indirect_edge (call_stmt, e->indirect_info->ecf_flags, - count, freq); + count, freq, false); *new_edge->indirect_info = *e->indirect_info; } }