From patchwork Thu Aug 15 16:17:10 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hubicka X-Patchwork-Id: 267403 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 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "localhost", Issuer "www.qmailtoaster.com" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 866A02C0251 for ; Fri, 16 Aug 2013 02:17:26 +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:cc:subject:message-id:references:mime-version :content-type:in-reply-to; q=dns; s=default; b=TcL0bW5umRIOoUK2z D0FFWN88AMdm1MqEvpbtw/CyUo7Nbhz9/qxy6EiocaSie78DF/jfPrm/sowxHj7R b6tzh2YdfCPXy/J+jdFexb3XKEUSZOoklAopDRn6FP1cY+Io1nxVzLZCybwlwG7Q HMfrv72zy8Xss7Gh6gUQfw7ErI= 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:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=default; bh=tInr0KxR4AdWXf42BQ4Kpc/ vMww=; b=dZuxvtMeeXbKXFsjXGYNPydi5OflFK6FCAviknI35id3ui84GkhUgr0 P+QRTvsEdUKdAziTUy24XRcPQNukYGz/QzL589ktAAzEVQFXTMacDRsDMH1IarqE 9twbo43s6KtuBHvZlbac1HWiGIPTNnvy1KDKo9LjC8xwYnONNNKI= Received: (qmail 11380 invoked by alias); 15 Aug 2013 16:17:17 -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 11361 invoked by uid 89); 15 Aug 2013 16:17:16 -0000 X-Spam-SWARE-Status: No, score=-5.4 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_LOW, RCVD_IN_HOSTKARMA_NO, RCVD_IN_HOSTKARMA_W, RCVD_IN_HOSTKARMA_WL, RP_MATCHES_RCVD, T_FRT_BELOW2 autolearn=ham version=3.3.2 Received: from nikam.ms.mff.cuni.cz (HELO nikam.ms.mff.cuni.cz) (195.113.20.16) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Thu, 15 Aug 2013 16:17:14 +0000 Received: by nikam.ms.mff.cuni.cz (Postfix, from userid 16202) id 10971543278; Thu, 15 Aug 2013 18:17:10 +0200 (CEST) Date: Thu, 15 Aug 2013 18:17:10 +0200 From: Jan Hubicka To: Jason Merrill Cc: Jan Hubicka , gcc-patches@gcc.gnu.org, mjambor@suse.cz Subject: Re: [RFC] Bare bones of virtual call tracking Message-ID: <20130815161710.GA26705@kam.mff.cuni.cz> References: <20130812121624.GF22678@kam.mff.cuni.cz> <5208FF6C.3060408@redhat.com> <20130813225117.GE30983@kam.mff.cuni.cz> <20130814061440.GB21037@kam.mff.cuni.cz> <520BBBF4.5050908@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <520BBBF4.5050908@redhat.com> User-Agent: Mutt/1.5.20 (2009-06-14) > On 08/14/2013 02:14 AM, Jan Hubicka wrote: > >As a temporary hack I suppose I can rely on assembler name of virtual table > >to be unique for each templated class? > > Actually, that seems like a fine solution for devirtualization; just > compare the mangled name of the vtable to establish type identity. OK, does this seem to make sense? I checked that it gets rid of my false ODR violation warnings (I disabled the code for types not having virtual tables). So if it looks OK, I would like to go ahead with this patch. (I am testing it now in isolation at x86_64-linux). Honza Index: tree.c =================================================================== --- tree.c (revision 201764) +++ tree.c (working copy) @@ -11833,15 +11833,15 @@ types_same_for_odr (tree type1, tree typ if (type1 == type2) return true; - /* If types are not structuraly same, do not bother to contnue. - Match in the remainder of code would mean ODR violation. */ - if (!types_compatible_p (type1, type2)) - return false; - + /* Without LTO main variants of types are unique. */ #ifndef ENABLE_CHECKING if (!in_lto_p) return false; #endif + /* If types are not structuraly same, do not bother to contnue. + Match in the remainder of code would mean ODR violation. */ + if (!types_compatible_p (type1, type2)) + return false; /* Check for anonymous namespaces. Those have !TREE_PUBLIC on the corresponding TYPE_STUB_DECL. */ @@ -11852,6 +11852,34 @@ types_same_for_odr (tree type1, tree typ || !TREE_PUBLIC (TYPE_STUB_DECL (type2)))) return false; + /* When assembler name of virtual table is available, it is + easy to compare types for equivalence. + FIXME: the code bellow consider all instantiations of the same + template to have same name. This is because we have no access + to template parameters. + To avoid false positives that may lead to wrong devirtualizations, + compoare also representative virtual tables. + We can still return false positive positives for types without + virtual tables, but for the moment we do not care. */ + if (TYPE_BINFO (type1) && TYPE_BINFO (type2) + && BINFO_VTABLE (TYPE_BINFO (type1)) + && BINFO_VTABLE (TYPE_BINFO (type2))) + { + tree v1 = BINFO_VTABLE (TYPE_BINFO (type1)); + tree v2 = BINFO_VTABLE (TYPE_BINFO (type2)); + + if (TREE_CODE (v1) == POINTER_PLUS_EXPR) + { + if (TREE_CODE (v2) != POINTER_PLUS_EXPR + || !operand_equal_p (TREE_OPERAND (v1, 1), + TREE_OPERAND (v2, 1), 0)) + return false; + v1 = TREE_OPERAND (TREE_OPERAND (v1, 0), 0); + v2 = TREE_OPERAND (TREE_OPERAND (v2, 0), 0); + } + return DECL_ASSEMBLER_NAME (v1) == DECL_ASSEMBLER_NAME (v2); + } + if (!TYPE_NAME (type1)) return false; if (!decls_same_for_odr (TYPE_NAME (type1), TYPE_NAME (type2)))