From patchwork Thu Jun 2 11:14:52 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prathamesh Kulkarni X-Patchwork-Id: 69150 Delivered-To: patch@linaro.org Received: by 10.140.106.246 with SMTP id e109csp58372qgf; Thu, 2 Jun 2016 04:15:26 -0700 (PDT) X-Received: by 10.66.178.139 with SMTP id cy11mr4705205pac.157.1464866126057; Thu, 02 Jun 2016 04:15:26 -0700 (PDT) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id b8si14209pfk.208.2016.06.02.04.15.25 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 02 Jun 2016 04:15:26 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-428870-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org; spf=pass (google.com: domain of gcc-patches-return-428870-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-428870-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:date:message-id:subject:from:to:content-type; q= dns; s=default; b=adZRTAq6nJh9LVLQmBE3IufTVldJfOe88fu/jlVBGD6eoS IHe5C4qrMXRj/zlVRvSpKWo1E0wzwIifH5mTZXO99FvIJi1oe01hVTeff57Kkhi4 5YbUKuNxTZrky95kRVspyh0GWEDtiESVgQZYts0PAbDFJobsthclcnP+ANP/k= 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 :mime-version:date:message-id:subject:from:to:content-type; s= default; bh=ystqb9xsHObX8XdApuTeJvD1A7E=; b=JYluJh6WlGT90tG06t6Q huo+iPGZn7tKiVDIco2qq9dbhbvo7775D4qxt+IqHP5hG8dJrGggbi75FQpwHK4c 5zeJnBqVhnF1o/gynsTfhC9CJoIVr2m0n4X4saLGhzQ1epO52QCHsrWZebgYQDTD PTxo8GKJ4IuFK7wChtHZWkw= Received: (qmail 115295 invoked by alias); 2 Jun 2016 11:15:13 -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 115188 invoked by uid 89); 2 Jun 2016 11:15:05 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy=TOP, 1577, val2, 3107 X-HELO: mail-io0-f173.google.com Received: from mail-io0-f173.google.com (HELO mail-io0-f173.google.com) (209.85.223.173) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Thu, 02 Jun 2016 11:14:55 +0000 Received: by mail-io0-f173.google.com with SMTP id p194so43152756iod.1 for ; Thu, 02 Jun 2016 04:14:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:date:message-id:subject:from:to; bh=7nOshW7Ewm5UEHkZcp3U0ak3GGi+8pIlAKg8f5XvfAQ=; b=NmiV7Fcmw65a1Het8HHUXYflJmVxH6nVyC9DvCCnRGylCmaArazwgRQ5NfNCRs7XuU 0XEhVmRwKQ8c4LvEWPGXBKwj7AR24dnBvRo1eiRLCqTkfN5meQREnk7h8/JPAmnTWdP9 pgcEWULGU9hIsrcHQd2Jz6NSDE11aa6gD+43np0Mpy7hiqUfoCMVPeu+eIIwNesUgbgz +kxZMmKWSwODu6RkWA2ZmC1Tm+B1Pb/TDQCmLNztiQLs79QrvS5/f1CtOA4qzBZ60LeO d7UfuzDtP4VDTNeVEEvInNGl8m6hOnLWKZCP6uTD/3bp4iIF3AVT4WiZrM1vkcxPJoRq zuQQ== X-Gm-Message-State: ALyK8tKLX6zE5Nn39cNV1Jc57APJrUNzOpMydWxO0SL5m6PFEVQ91h2j6Rmzho7AdVBg30hIQFTkbPpKHnNQIGpW MIME-Version: 1.0 X-Received: by 10.107.159.84 with SMTP id i81mr2296967ioe.29.1464866092759; Thu, 02 Jun 2016 04:14:52 -0700 (PDT) Received: by 10.36.236.5 with HTTP; Thu, 2 Jun 2016 04:14:52 -0700 (PDT) Date: Thu, 2 Jun 2016 16:44:52 +0530 Message-ID: Subject: [ipa-comdats] create a new comdat group for symbol if it's referenced from multiple comdat groups From: Prathamesh Kulkarni To: gcc Patches , Jan Hubicka , Richard Biener X-IsSubscribed: yes Hi, I was trying to address first TODO from ipa-comdats.c (attached patch) TODO: When symbol is used only by comdat symbols, but from different groups, it would make sense to produce a new comdat group for it with anonymous name. The patch simply puts symbol in a new comdat group and makes symbol the head of that group if newgroup and *val2 are COMDAT but not equal instead of setting newgroup to BOTTOM. Does this approach look reasonable ? For test-1.C (attached) q() is referenced from i1() and i2() which are comdat symbols and hence q() is put in it's own comdat-section. I suppose that's the expected result ? However it fails for test-2.C (attached) with the error error: comdat-local function called by int i1() outside its comdat and ICE verify_cgraph_node failed follows, which comes from cgraph.c:3095: bool check_comdat = comdat_local_p (); if (check_comdat && !in_same_comdat_group_p (e->caller)) { error ("comdat-local function called by %s outside its comdat", identifier_to_locale (e->caller->name ())); error_found = true; } Patch works for test-1.C because although q() is in different comdat group from it's callers, it's the only function in that group and hence same_comdat_group is NULL so comdat_local_p() returns false. Since check_comdat becomes false, we don't hit the error. For test-2.C, since r() is called by q(), the patch puts r() and q() in same comdat group with name "q". In this case for q(), comdat_local_p() returns true, because same_comdat_group is non-NULL. Since check_comdat is true and q() and it's caller i1() are not in same comdat groups, we hit the error. I am not sure how to fix this, and would be grateful for suggestions. I assumed r() and q() should be in same comdat group since q() became a comdat symbol and r() is only referenced from q(). Also, what name would be appropriate for "anonymous" comdat group ? I am currently giving it the name of the first symbol that gets put into it. Thanks, Prathamesh diff --git a/gcc/ipa-comdats.c b/gcc/ipa-comdats.c index 6e0f762..ea59bd9 100644 --- a/gcc/ipa-comdats.c +++ b/gcc/ipa-comdats.c @@ -55,6 +55,48 @@ along with GCC; see the file COPYING3. If not see #include "tree.h" #include "tree-pass.h" #include "cgraph.h" +#include "tree-pretty-print.h" + +tree +merge_comdat_group (tree *val2, tree newgroup, + symtab_node *symbol, + hash_map& comdat_head_map) +{ + /* *val2 is TOP. */ + if (val2 == NULL || *val2 == NULL) + return newgroup; + + /* *val2 is BOTTOM. */ + else if (*val2 == error_mark_node) + return error_mark_node; + + /* *val2 is COMDAT. */ + else + { + /* COMDAT meet TOP == COMDAT. */ + if (newgroup == NULL) + return *val2; + + /* COMDAT meet BOTTOM == BOTTOM. */ + else if (newgroup == error_mark_node) + return error_mark_node; + + /* COMDAT meet COMDAT == COMDAT if both are equal else + create new comdat group and assign it to symbol. */ + else + { + if (newgroup == *val2) + return newgroup; + + /* FIXME: using DECL_NAME (symbol->decl) as name of comdat section. */ + newgroup = DECL_NAME (symbol->decl); + DECL_COMDAT (symbol->decl) = 1; + symbol->set_comdat_group (newgroup); + comdat_head_map.put (newgroup, symbol); + return newgroup; + } + } +} /* Main dataflow loop propagating comdat groups across the symbol table. All references to SYMBOL are examined @@ -63,7 +105,8 @@ along with GCC; see the file COPYING3. If not see tree propagate_comdat_group (struct symtab_node *symbol, - tree newgroup, hash_map &map) + tree newgroup, hash_map &map, + hash_map& comdat_head_map) { int i; struct ipa_ref *ref; @@ -78,7 +121,7 @@ propagate_comdat_group (struct symtab_node *symbol, if (ref->use == IPA_REF_ALIAS) { - newgroup = propagate_comdat_group (symbol2, newgroup, map); + newgroup = propagate_comdat_group (symbol2, newgroup, map, comdat_head_map); continue; } @@ -105,7 +148,8 @@ propagate_comdat_group (struct symtab_node *symbol, /* The actual merge operation. */ tree *val2 = map.get (symbol2); - + newgroup = merge_comdat_group (val2, newgroup, symbol, comdat_head_map); +#if 0 if (val2 && *val2 != newgroup) { if (!newgroup) @@ -113,6 +157,7 @@ propagate_comdat_group (struct symtab_node *symbol, else newgroup = error_mark_node; } +#endif } /* If we analyze function, walk also callers. */ @@ -129,7 +174,7 @@ propagate_comdat_group (struct symtab_node *symbol, { /* Thunks can not call across section boundary. */ if (cn->thunk.thunk_p) - newgroup = propagate_comdat_group (symbol2, newgroup, map); + newgroup = propagate_comdat_group (symbol2, newgroup, map, comdat_head_map); /* If we see inline clone, its comdat group actually corresponds to the comdat group of the function it is inlined to. */ @@ -140,7 +185,8 @@ propagate_comdat_group (struct symtab_node *symbol, /* The actual merge operation. */ tree *val2 = map.get (symbol2); - + newgroup = merge_comdat_group (val2, newgroup, symbol, comdat_head_map); +#if 0 if (val2 && *val2 != newgroup) { if (!newgroup) @@ -148,6 +194,7 @@ propagate_comdat_group (struct symtab_node *symbol, else newgroup = error_mark_node; } +#endif } return newgroup; } @@ -310,7 +357,7 @@ ipa_comdats (void) if (group == error_mark_node) continue; - newgroup = propagate_comdat_group (symbol, group, map); + newgroup = propagate_comdat_group (symbol, group, map, comdat_head_map); /* If nothing changed, proceed to next symbol. */ if (newgroup == group)