From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 128753 invoked by alias); 27 Dec 2018 12:32:08 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 128731 invoked by uid 89); 27 Dec 2018 12:32:06 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,SPF_PASS autolearn=ham version=3.3.2 spammy=13217, 9959, 100000, walked X-HELO: mx1.suse.de Received: from mx2.suse.de (HELO mx1.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 27 Dec 2018 12:32:03 +0000 Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 06C87AE3D for ; Thu, 27 Dec 2018 12:32:00 +0000 (UTC) Subject: Re: GCC 8 backports From: =?UTF-8?Q?Martin_Li=c5=a1ka?= To: GCC Patches References: <9a21556a-0c16-c31a-f188-a75077c36bfa@suse.cz> <32e46ac2-3865-1b46-93bf-5ada7f8ff4e2@suse.cz> <7387d688-1a77-db9e-7318-c5a8c214bf09@suse.cz> <1620d43c-b6f7-46d6-8222-abf3bc5b6be1@suse.cz> Message-ID: <031df204-414b-ff04-6562-d965bc99bb9e@suse.cz> Date: Thu, 27 Dec 2018 14:59:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.3 MIME-Version: 1.0 In-Reply-To: <1620d43c-b6f7-46d6-8222-abf3bc5b6be1@suse.cz> Content-Type: multipart/mixed; boundary="------------29DBE48E1AE94B6B3E13E8AA" X-IsSubscribed: yes X-SW-Source: 2018-12/txt/msg01700.txt.bz2 This is a multi-part message in MIME format. --------------29DBE48E1AE94B6B3E13E8AA Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Content-length: 389 On 11/20/18 11:58 AM, Martin Liška wrote: > On 10/3/18 11:23 AM, Martin Liška wrote: >> On 9/25/18 8:48 AM, Martin Liška wrote: >>> Hi. >>> >>> One more tested patch. >>> >>> Martin >>> >> >> One more tested patch. >> >> Martin >> > > Hi. > > One another tested patch that I'm going to install. > > Martin > Hi. One another tested patch that I'm going to install. Thanks, Martin --------------29DBE48E1AE94B6B3E13E8AA Content-Type: text/x-patch; name="0001-Backport-r267338.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0001-Backport-r267338.patch" Content-length: 8722 >From 97052eab40506300510336bf668d4adc2a60a7cf Mon Sep 17 00:00:00 2001 From: hubicka Date: Fri, 21 Dec 2018 19:13:06 +0000 Subject: [PATCH] Backport r267338 gcc/ChangeLog: 2018-12-15 Jan Hubicka PR ipa/88561 * ipa-polymorphic-call.c (ipa_polymorphic_call_context::ipa_polymorphic_call_context): Handle arguments of thunks correctly. (ipa_polymorphic_call_context::get_dynamic_context): Be ready for NULL instance pinter. * lto-cgraph.c (lto_output_node): Always stream thunk info. gcc/testsuite/ChangeLog: 2018-12-15 Jan Hubicka PR ipa/88561 * g++.dg/tree-prof/devirt.C: New testcase. --- gcc/ipa-polymorphic-call.c | 32 +++++- gcc/lto-cgraph.c | 8 +- gcc/testsuite/g++.dg/tree-prof/devirt.C | 123 ++++++++++++++++++++++++ 3 files changed, 159 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/g++.dg/tree-prof/devirt.C diff --git a/gcc/ipa-polymorphic-call.c b/gcc/ipa-polymorphic-call.c index 13aca94dd00..d5e4a6a6f97 100644 --- a/gcc/ipa-polymorphic-call.c +++ b/gcc/ipa-polymorphic-call.c @@ -995,9 +995,22 @@ ipa_polymorphic_call_context::ipa_polymorphic_call_context (tree fndecl, { outer_type = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (base_pointer))); + cgraph_node *node = cgraph_node::get (current_function_decl); gcc_assert (TREE_CODE (outer_type) == RECORD_TYPE || TREE_CODE (outer_type) == UNION_TYPE); + /* Handle the case we inlined into a thunk. In this case + thunk has THIS pointer of type bar, but it really receives + address to its base type foo which sits in bar at + 0-thunk.fixed_offset. It starts with code that adds + think.fixed_offset to the pointer to compensate for this. + + Because we walked all the way to the begining of thunk, we now + see pointer &bar-thunk.fixed_offset and need to compensate + for it. */ + if (node->thunk.fixed_offset) + offset -= node->thunk.fixed_offset * BITS_PER_UNIT; + /* Dynamic casting has possibly upcasted the type in the hiearchy. In this case outer type is less informative than inner type and we should forget @@ -1005,7 +1018,11 @@ ipa_polymorphic_call_context::ipa_polymorphic_call_context (tree fndecl, if ((otr_type && !contains_type_p (outer_type, offset, otr_type)) - || !contains_polymorphic_type_p (outer_type)) + || !contains_polymorphic_type_p (outer_type) + /* If we compile thunk with virtual offset, the THIS pointer + is adjusted by unknown value. We can't thus use outer info + at all. */ + || node->thunk.virtual_offset_p) { outer_type = NULL; if (instance) @@ -1030,7 +1047,15 @@ ipa_polymorphic_call_context::ipa_polymorphic_call_context (tree fndecl, maybe_in_construction = false; } if (instance) - *instance = base_pointer; + { + /* If method is expanded thunk, we need to apply thunk offset + to instance pointer. */ + if (node->thunk.virtual_offset_p + || node->thunk.fixed_offset) + *instance = NULL; + else + *instance = base_pointer; + } return; } /* Non-PODs passed by value are really passed by invisible @@ -1547,6 +1572,9 @@ ipa_polymorphic_call_context::get_dynamic_type (tree instance, HOST_WIDE_INT instance_offset = offset; tree instance_outer_type = outer_type; + if (!instance) + return false; + if (otr_type) otr_type = TYPE_MAIN_VARIANT (otr_type); diff --git a/gcc/lto-cgraph.c b/gcc/lto-cgraph.c index 40baf858ca5..305f22bd7e9 100644 --- a/gcc/lto-cgraph.c +++ b/gcc/lto-cgraph.c @@ -546,7 +546,11 @@ lto_output_node (struct lto_simple_output_block *ob, struct cgraph_node *node, streamer_write_bitpack (&bp); streamer_write_data_stream (ob->main_stream, section, strlen (section) + 1); - if (node->thunk.thunk_p) + /* Stream thunk info always because we use it in + ipa_polymorphic_call_context::ipa_polymorphic_call_context + to properly interpret THIS pointers for thunks that has been converted + to Gimple. */ + if (node->definition) { streamer_write_uhwi_stream (ob->main_stream, @@ -1317,7 +1321,7 @@ input_node (struct lto_file_decl_data *file_data, if (section) node->set_section_for_node (section); - if (node->thunk.thunk_p) + if (node->definition) { int type = streamer_read_uhwi (ib); HOST_WIDE_INT fixed_offset = streamer_read_uhwi (ib); diff --git a/gcc/testsuite/g++.dg/tree-prof/devirt.C b/gcc/testsuite/g++.dg/tree-prof/devirt.C new file mode 100644 index 00000000000..05c9a26e7a4 --- /dev/null +++ b/gcc/testsuite/g++.dg/tree-prof/devirt.C @@ -0,0 +1,123 @@ +/* { dg-options "-O3 -fdump-tree-dom3" } */ +struct nsISupports +{ + virtual int QueryInterface (const int &aIID, void **aInstancePtr) = 0; + virtual __attribute__((noinline, noclone)) unsigned AddRef (void) = 0; + virtual unsigned Release (void) = 0; +}; + +struct nsIObserver : public nsISupports +{ + virtual int Observe (nsISupports * aSubject, const char *aTopic, const unsigned short *aData) = 0; +}; + +struct nsISupportsWeakReference : public nsISupports +{ + virtual int GetWeakReference (void **_retval) = 0; +}; + +struct nsSupportsWeakReference : public nsISupportsWeakReference +{ + nsSupportsWeakReference () : mProxy (0) {} + virtual int GetWeakReference (void **_retval) override { return 0; } + ~nsSupportsWeakReference () {} + void NoticeProxyDestruction () { mProxy = nullptr; } + void *mProxy; + void ClearWeakReferences (); + bool HasWeakReferences () const { return !!mProxy; } +}; + +struct mozIPersonalDictionary : public nsISupports +{ + virtual int Load (void) = 0; + virtual int Save (void) = 0; + virtual int GetWordList (void **aWordList) = 0; + virtual int Check (const int &word, bool * _retval) = 0; + virtual int AddWord (const int &word) = 0; + virtual int RemoveWord (const int &word) = 0; + virtual int IgnoreWord (const int &word) = 0; + virtual int EndSession (void) = 0; +}; + +struct mozPersonalDictionary final + : public mozIPersonalDictionary, public nsIObserver, public nsSupportsWeakReference +{ + virtual int QueryInterface (const int &aIID, void **aInstancePtr) override; + virtual __attribute__((noinline, noclone)) unsigned AddRef (void) override; + virtual unsigned Release (void) override; + unsigned long mRefCnt; + virtual int Load (void) override { return 0; } + virtual int Save (void) override { return 0; } + virtual int GetWordList (void **aWordList) override { return 0; } + virtual int Check (const int &word, bool * _retval) override { return 0; } + virtual int AddWord (const int &word) override { return 0; } + virtual int RemoveWord (const int &word) override { return 0; } + virtual int IgnoreWord (const int &word) override { return 0; } + virtual int EndSession (void) override { return 0; } + virtual int Observe (nsISupports * aSubject, const char *aTopic, const unsigned short *aData) override { return 0; } + mozPersonalDictionary () : mRefCnt(0) {} + int Init () { return 0; } + virtual ~mozPersonalDictionary () {} + bool mIsLoaded; + bool mSavePending; + void *mFile; + char mMonitor[96]; + char mMonitorSave[96]; + char mDictionaryTable[32]; + char mIgnoreTable[32]; +}; + +unsigned +mozPersonalDictionary::AddRef (void) +{ + unsigned count = ++mRefCnt; + return count; +} + +unsigned +mozPersonalDictionary::Release (void) +{ + unsigned count = --mRefCnt; + if (count == 0) + { + mRefCnt = 1; + delete (this); + return 0; + } + return count; +} + +int +mozPersonalDictionary::QueryInterface (const int &aIID, void **aInstancePtr) +{ + nsISupports *foundInterface; + if (aIID == 122) + foundInterface = static_cast (this); + else + foundInterface = static_cast (this); + int status; + foundInterface->AddRef (); + *aInstancePtr = foundInterface; + return status; +} + +__attribute__((noipa)) int +foo (nsISupports *p, const int &i) +{ + void *q; + return p->QueryInterface (i, &q); +} + +int +main () +{ + mozPersonalDictionary m; + int j = 123; + for (int i = 0; i < 100000; i++) + foo (static_cast (&m), j); + if (m.mRefCnt != 100000) + __builtin_abort (); +} + +/* { dg-final-use-not-autofdo { scan-ipa-dump-times 3 "folding virtual function call to virtual unsigned int mozPersonalDictionary::_ZThn16" "dom3" } } */ +/* { dg-final-use-not-autofdo { scan-ipa-dump-times 3 "folding virtual function call to virtual unsigned int mozPersonalDictionary::AddRef" "dom3" } } */ -- 2.20.1 --------------29DBE48E1AE94B6B3E13E8AA--