From patchwork Tue Dec 2 13:54:19 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Enkovich X-Patchwork-Id: 416878 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 C3FBA14011D for ; Wed, 3 Dec 2014 00:54:37 +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:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=OULmgRMy6H8HcbkIFB7FZuB0gIl8uMBtGQA++2VfBJ1zhtZwfOtBP LSOoIu2B8zRugpvux5TTCm6KqFDBwrWh+f8XotpDoJjGpDzO2AULtej70VC32zdj nMU4fMuE1nnPVhCXlvWgAKs9jwq/UwmWzL5E4z2YS1UNzEzA8VgATs= 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=/ByMMbnnWz2051R8L2sbZWnBjYc=; b=KLIIDRxeOBeFnwSnpkt7 XRvqt9BXzNQP3vHfNSmt4bFnzuW3NTWpOng5NQdiaasMcr1onC9FD9TUNKY59h1z pr8puYXT+k7xqEE2rnTYuG77AvuvCarCSn6b43WISE2DQpA+qTNtNMsvFub3W1rk kgHztKUpyljqB3B5b+lMwzY= Received: (qmail 7131 invoked by alias); 2 Dec 2014 13:54:30 -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 7118 invoked by uid 89); 2 Dec 2014 13:54:29 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 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-f178.google.com Received: from mail-pd0-f178.google.com (HELO mail-pd0-f178.google.com) (209.85.192.178) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Tue, 02 Dec 2014 13:54:28 +0000 Received: by mail-pd0-f178.google.com with SMTP id g10so13148742pdj.23 for ; Tue, 02 Dec 2014 05:54:26 -0800 (PST) X-Received: by 10.70.102.234 with SMTP id fr10mr110623337pdb.145.1417528466222; Tue, 02 Dec 2014 05:54:26 -0800 (PST) Received: from msticlxl57.ims.intel.com ([192.55.54.42]) by mx.google.com with ESMTPSA id dj1sm20367444pbb.48.2014.12.02.05.54.23 for (version=TLSv1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 02 Dec 2014 05:54:25 -0800 (PST) Date: Tue, 2 Dec 2014 16:54:19 +0300 From: Ilya Enkovich To: gcc-patches@gcc.gnu.org Subject: [PATCH, CHKP] Keep instrumentation references consistency when merging cgraph nodes Message-ID: <20141202135419.GE2963@msticlxl57.ims.intel.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes Hi, Currently cgraph nodes merge may break instrumented_version references. It depends on order nodes are read and merged and therefore problem is not nicely reproducible. I couldn't make a small reproducer. This patch fixes problem and 253.perlbmk benchmark build with '-O3 -flto -fcheck-pointer-bounds -mmpx'. Bootstrapped and tested on x86_64-unknown-linux-gnu. OK for trunk? Thanks, Ilya --- 2014-12-02 Ilya Enkovich * lto-cgraph.c (input_cgraph_1): Don't break existing instrumentation clone references. * lto/lto-symtab.c (lto_cgraph_replace_node): Redirect instrumented_version references appropriately. diff --git a/gcc/lto-cgraph.c b/gcc/lto-cgraph.c index d424e14..b310b44 100644 --- a/gcc/lto-cgraph.c +++ b/gcc/lto-cgraph.c @@ -1562,7 +1562,18 @@ input_cgraph_1 (struct lto_file_decl_data *file_data, cnode->instrumented_version = cgraph_node::get (cnode->orig_decl); if (cnode->instrumented_version) - cnode->instrumented_version->instrumented_version = cnode; + { + /* We may have multiple nodes for a single function which + will be merged later. To have a proper merge we need + to keep instrumentation_version reference between nodes + consistent: each instrumented_version reference should + have proper reverse reference. Thus don't break existing + instrumented_version reference if it already exists. */ + if (cnode->instrumented_version->instrumented_version) + cnode->instrumented_version = NULL; + else + cnode->instrumented_version->instrumented_version = cnode; + } /* Restore decl names reference. */ if (IDENTIFIER_TRANSPARENT_ALIAS (DECL_ASSEMBLER_NAME (cnode->decl)) diff --git a/gcc/lto/lto-symtab.c b/gcc/lto/lto-symtab.c index 4c4e48a..f5d82a7 100644 --- a/gcc/lto/lto-symtab.c +++ b/gcc/lto/lto-symtab.c @@ -99,6 +99,20 @@ lto_cgraph_replace_node (struct cgraph_node *node, /* Redirect incomming references. */ prevailing_node->clone_referring (node); + /* Fix instrumentation references. */ + if (node->instrumented_version) + { + gcc_assert (node->instrumentation_clone + == prevailing_node->instrumentation_clone); + node->instrumented_version->instrumented_version = prevailing_node; + if (!prevailing_node->instrumented_version) + prevailing_node->instrumented_version = node->instrumented_version; + /* Need to reset node->instrumented_version to NULL, + otherwise node removal code would reset + node->instrumented_version->instrumented_version. */ + node->instrumented_version = NULL; + } + ipa_merge_profiles (prevailing_node, node); lto_free_function_in_decl_state_for_node (node);