From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by sourceware.org (Postfix) with ESMTP id 029F93857820 for ; Mon, 30 Nov 2020 22:28:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 029F93857820 Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-374-KyvzfR9cOY6wIB-SXLTNeA-1; Mon, 30 Nov 2020 17:28:09 -0500 X-MC-Unique: KyvzfR9cOY6wIB-SXLTNeA-1 Received: by mail-qk1-f200.google.com with SMTP id s128so10844662qke.0 for ; Mon, 30 Nov 2020 14:28:09 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=LG0ZMzLclmuvPXiy7G/CdCmeBUXXJbmH/Boac8y8lBk=; b=SV3n8BhQJUM+YNa9Seq3GLA7ReOBGIMcoq5ZbFQ86jyHwfxcTmSXVFseT9i6DTJXc8 cZFiLGNV5m4uuSszPfPXyyhArS2ZGp8LljPzeGx957jvtCOUJxtg8iNGfZd/vBCFQl3l GGv1Mglw21csIc/ILFTHKqfEgZmKW1z3H5q5FGsBycT/nLlr1rztSGDTNqG3nvgYSUo/ 47ZLWDOWq21kCjnOGiVlteoj6sVMrYGOt43RcCYEm/HsIS7eT9C/bvHTJqQ5SuBwj2Tz 2s8OCQ995Lt/zbDNZj26/kLIkeKmBqBc9l4bHq6HGSSnSjMx5hsCT2okm+F67dmUIfS2 Ta0A== X-Gm-Message-State: AOAM532Gj5yEIi/2v2VVrX4LGRP8/GaRUTi3q9Namtyb5nBtTTFugbHI 7Q+3Qze3PkSj7BhtDbc0lz7S7LkijYepWcJbrh2PNyCxcloKqXRdPYz7gqksPBXOBAg4XIIj8gZ u+2H/1IYnxaU+L0ZuVA== X-Received: by 2002:a37:b347:: with SMTP id c68mr25440320qkf.291.1606775289297; Mon, 30 Nov 2020 14:28:09 -0800 (PST) X-Google-Smtp-Source: ABdhPJxVTDbxf0fZx7HzCNBpVwp5pzp+ltNm4iqq6GnzvT2Bfwed0roMZAPX8s5Z7vFQOgl/FZRdEQ== X-Received: by 2002:a37:b347:: with SMTP id c68mr25440302qkf.291.1606775288988; Mon, 30 Nov 2020 14:28:08 -0800 (PST) Received: from [192.168.1.148] (209-6-216-142.s141.c3-0.smr-cbr1.sbo-smr.ma.cable.rcncustomer.com. [209.6.216.142]) by smtp.gmail.com with ESMTPSA id a3sm17134040qtp.63.2020.11.30.14.28.07 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 30 Nov 2020 14:28:08 -0800 (PST) Subject: Re: [C++ patch] Re: Free more of CFG in release_function_body To: Jan Hubicka , Richard Biener Cc: GCC Patches , Richard Biener References: <20201124151605.GA56013@kam.mff.cuni.cz> <20201125140838.GA41776@kam.mff.cuni.cz> <20201125143034.GC41776@kam.mff.cuni.cz> <20201127132622.GB78170@kam.mff.cuni.cz> From: Jason Merrill Message-ID: Date: Mon, 30 Nov 2020 17:28:07 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.3.1 MIME-Version: 1.0 In-Reply-To: <20201127132622.GB78170@kam.mff.cuni.cz> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-14.7 required=5.0 tests=BAYES_00, DKIM_INVALID, DKIM_SIGNED, GIT_PATCH_0, KAM_DMARC_STATUS, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 30 Nov 2020 22:28:13 -0000 On 11/27/20 8:26 AM, Jan Hubicka wrote: >>> On Wed, Nov 25, 2020 at 3:11 PM Jan Hubicka wrote: >>>> >>>>> On Tue, 24 Nov 2020, Jan Hubicka wrote: >>>>> >>>>>> Hi, >>>>>> at the end of processing function body we loop over basic blocks and >>>>>> free all edges while we do not free the rest. I think this is leftover >>>>>> from time eges was not garbage collected and we was not using ggc_free. >>>>>> It makes more sense to free all associated structures (which is >>>>>> importnat for WPA memory footprint). >>>>>> >>>>>> Bootstrapped/regtested x86_64-linux, OK? >>>>> >>>>> OK. >>>> >>>> Unforutnately the patch does not surive LTO bootstrap. The problem is >>>> that we keep DECL_INITIAL that points to blocks and blocks points to >>>> var_decls and these points to SSA_NAMES that points to statements and >>>> those points to basic blocks. >>> >>> VAR_DECLs point to SSA_NAMEs? It's the other way around. We for sure >>> free SSA_NAMEs (well, maybe not explicitely with ggc_free). >> >> I am going to debug this more carefully now. I think it was VAR_DECL >> with variadic type pointing to SSA_NAME. Should be easy to reduct with >> gcac compiler. > > Hi, > it turns out that the pointers to statements leaks through saved scopes > in C++ FE. Scopes seems to point to internal blocks of functions even > after we finish their compiling. > > This patch adds code to free pointers. I tried to clear saved_blocks > but it breaks since C++ finalization uses them, but it does not look > into previous class levels. > > Patch lto-bootstraps/regtestes x86_64-linux with all languages. OK? > > Honza > > * cfg.c (free_block): Call ggc_free on BB itself. > > * cp-tre.eh (cp_tree_c_finish_parsing): Declare. > * semantics.c (finish_translation_unit): Call finish_parsing > * tree.c (cp_tree_c_finish_parsing): New function. > diff --git a/gcc/cfg.c b/gcc/cfg.c > index 529b6ed2105..e8bd1456c9f 100644 > --- a/gcc/cfg.c > +++ b/gcc/cfg.c > @@ -102,8 +102,7 @@ free_block (basic_block bb) > bb->succs = NULL; > vec_free (bb->preds); > bb->preds = NULL; > - /* Do not free BB itself yet since we leak pointers to dead statements > - that points to dead basic blocks. */ > + ggc_free (bb); > } > > /* Free the memory associated with the CFG in FN. */ > diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h > index 021de76e142..665d171d9b0 100644 > --- a/gcc/cp/cp-tree.h > +++ b/gcc/cp/cp-tree.h > @@ -7986,6 +7986,8 @@ struct uid_sensitive_constexpr_evaluation_checker > bool evaluation_restricted_p () const; > }; > > +void cp_tree_c_finish_parsing (); > + > /* In cp-ubsan.c */ > extern void cp_ubsan_maybe_instrument_member_call (tree); > extern void cp_ubsan_instrument_member_accesses (tree *); > diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c > index 5ff70ff4844..e9d17c21985 100644 > --- a/gcc/cp/semantics.c > +++ b/gcc/cp/semantics.c > @@ -3094,6 +3094,7 @@ finish_translation_unit (void) > "%<#pragma omp end declare target%>"); > scope_chain->omp_declare_target_attribute = 0; > } > + cp_tree_c_finish_parsing (); This is too soon for this call; it should be from c_parse_final_cleanups by the call to fini_constexpr, so that it follows template instantiation at EOF. > } > > /* Finish a template type parameter, specified as AGGR IDENTIFIER. > diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c > index 28e591086b3..e63d383c0a3 100644 > --- a/gcc/cp/tree.c > +++ b/gcc/cp/tree.c > @@ -5844,6 +5844,19 @@ maybe_warn_zero_as_null_pointer_constant (tree expr, location_t loc) > return false; > } > > +/* Release memory we no longer need after parsing. */ > +void > +cp_tree_c_finish_parsing () > +{ > + saved_scope *chain = scope_chain; > + while (chain) > + { > + chain->x_previous_class_level = NULL; > + chain = chain->prev; > + } This can just be invalidate_class_lookup_cache (). scope_chain->prev will always be NULL at this point. OK with those changes. > + deleted_copy_types = NULL; > +} > + > #if defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 2007) > /* Complain that some language-specific thing hanging off a tree > node has been accessed improperly. */