From patchwork Mon Oct 4 18:27:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 45794 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8B6F53858010 for ; Mon, 4 Oct 2021 18:28:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8B6F53858010 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1633372090; bh=ZXn+EmCRMs0nsYssaDhh5POQn1/tRy2WuKEpkcE6GuQ=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=l/BS2lNLBgsmZT3Zyi6X5rWJAk8lIIa6T6T1pB/d0RGcvXwAZONCLOj859R3EgOrV 2W6KWShqFHTHiG015DgWfsNV8cvOcg6HeUP+waSNYcQ5ErzKq8S5uT7g4AbdCBZO3H h5RNI6oGUeP8udTrii7gDM61cmAZg63/zEMen1Z0= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id 13F313857C59 for ; Mon, 4 Oct 2021 18:27:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 13F313857C59 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-524-7uCxptmXOKuK2ejbVqfcoA-1; Mon, 04 Oct 2021 14:27:11 -0400 X-MC-Unique: 7uCxptmXOKuK2ejbVqfcoA-1 Received: by mail-qk1-f200.google.com with SMTP id bk9-20020a05620a1a0900b0045df00f93a9so24847734qkb.1 for ; Mon, 04 Oct 2021 11:27:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent :content-language:to:cc:from:subject; bh=8Y8QiETIrcrNmJX7F749KbewyZAv9mpmOFEDSckrdOA=; b=bbJr4S5CgF0r+QkVMhff8ILE8MNupHiOl/VG+TOIrA3u7/8zz4K/w5WnmmarQoU1oz +iUeYOIzxnfoR0Kv7Muj26YOb+uBoRLn5SocHvhhaIYCNy+iUk34CwUvDfGCkImJE4XL 234Ub2gl3Ap8qYz+QXF0m1UH3mbYdEnwew1z57JBSjxAvhu9vzwAy7TyysTdoH7fr5SD 1jmJEnMLx0uRV6Ke3OUrvXkCynVe3DkD5UTrlL6Zg9lvWb8RJsvge/7VQFGxPJQmrYzg 2VdLCpdGCZo+U/IolRZZYdlDD01BPRtHTzK1SYI0qy+6RG3KrwAnNCyeErYAGfQ7wXJn 4KEw== X-Gm-Message-State: AOAM530PQ5DJKnkHKWb763/SXjXsm1s1/RzVCiVAK7Jnb7XdkbYsQKxr 89nSyjY8XLkLFW9wG6/xt7Rk006ataWVDYAWQ++6CFYHIqCq02eRb0+3us/+pH7TgaL6c4jifkx eHduzVR4Hx1JmItboQ4DYOqu3ENpd2VYRn03oJkHVHTxrD9FrB5lMGQorvh0P7EvAGg== X-Received: by 2002:a37:2e82:: with SMTP id u124mr11393614qkh.58.1633372030428; Mon, 04 Oct 2021 11:27:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJziMnLGTyy5x/AjcCTIpy2bMTi9wVZWla3+aq2xgmuBXgpMApffODhjW4Oa/cPK/FWSdfkBGQ== X-Received: by 2002:a37:2e82:: with SMTP id u124mr11393593qkh.58.1633372030078; Mon, 04 Oct 2021 11:27:10 -0700 (PDT) Received: from [192.168.1.149] (130-44-159-43.s15913.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.159.43]) by smtp.gmail.com with ESMTPSA id g21sm8841557qtq.53.2021.10.04.11.27.08 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 04 Oct 2021 11:27:09 -0700 (PDT) Message-ID: <30daf345-6fd4-5fb4-d0a6-754b48d9b441@redhat.com> Date: Mon, 4 Oct 2021 14:27:08 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.1.2 To: gcc-patches List Subject: [PATCH RFA] vec: Fix --enable-gather-detailed-mem-stats X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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-Patchwork-Original-From: Jason Merrill via Gcc-patches From: Jason Merrill Reply-To: Jason Merrill Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" When r12-4038 introduced the global auto_vec save_opt_decoded_options, it broke compilers configured with --enable-gather-detailed-mem-stats, due to the memory descriptors getting discarded before the auto_vec was destroyed. Attached below are two approaches to making this work, either by using the init_priority attribute, or turning vec_mem_desc into a singleton function. I prefer the first one, primarily because it doesn't require auto_vec variables to force immediate allocation. It relies on a G++ extension, but I figure that's OK for code that is only exercised with a debugging configure flag. Thoughts? Either one OK for trunk? From 7641bceec2cb53e76c57bd70c38f390610bb82b6 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Fri, 1 Oct 2021 16:09:57 -0400 Subject: [PATCH 2/2] vec: make vec_mem_desc a singleton function To: gcc-patches@gcc.gnu.org When r12-4038 introduced the global auto_vec save_opt_decoded_options, it broke compilers configured with --enable-gather-detailed-mem-stats due to the memory descriptors getting discarded before the auto_vec was destroyed. We can fix the ordering of construction/destruction by turning vec_mem_desc into a singleton function. For this to work, the construction of save_opt_decoded_options needs to allocate immediately, so that allocation calls vec_mem_desc. gcc/ChangeLog: * vec.c (vec_mem_desc): Change to function. (vec_prefix::register_overhead): Adjust. (vec_prefix::release_overhead): Adjust. (dump_vec_loc_statistics): Adjust. * toplev.c (save_opt_decoded_options): Allocate. --- gcc/toplev.c | 7 ++++++- gcc/vec.c | 28 +++++++++++++++------------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/gcc/toplev.c b/gcc/toplev.c index ec9f998a49b..727a9972dd0 100644 --- a/gcc/toplev.c +++ b/gcc/toplev.c @@ -122,7 +122,12 @@ struct cl_decoded_option *save_decoded_options; unsigned int save_decoded_options_count; /* Vector of saved Optimization decoded command line options. */ -auto_vec save_opt_decoded_options; +auto_vec save_opt_decoded_options +#if GATHER_STATISTICS +/* Force allocation so vec_mem_desc is called. */ +(1) +#endif +; /* Used to enable -fvar-tracking, -fweb and -frename-registers according to optimize in process_options (). */ diff --git a/gcc/vec.c b/gcc/vec.c index 715460397c6..4858753223c 100644 --- a/gcc/vec.c +++ b/gcc/vec.c @@ -110,13 +110,15 @@ public: size_t m_element_size; }; -/* Vector memory description. */ -#if GATHER_STATISTICS -/* With --enable-gather-detailed-mem-stats, this needs to be constructed before - any auto_vec variables. The number 237 is entirely arbitrary. */ -[[gnu::init_priority (237)]] -#endif -static mem_alloc_description vec_mem_desc; +/* Vector memory description. This is a singleton function rather than a + variable so that the object's [cd]tor are properly ordered relative to any + auto_vec variables. */ +static mem_alloc_description & +vec_mem_desc () +{ + static mem_alloc_description m; + return m; +} /* Account the overhead. */ @@ -124,10 +126,10 @@ void vec_prefix::register_overhead (void *ptr, size_t elements, size_t element_size MEM_STAT_DECL) { - vec_mem_desc.register_descriptor (ptr, VEC_ORIGIN, false + vec_mem_desc ().register_descriptor (ptr, VEC_ORIGIN, false FINAL_PASS_MEM_STAT); vec_usage *usage - = vec_mem_desc.register_instance_overhead (elements * element_size, ptr); + = vec_mem_desc ().register_instance_overhead (elements * element_size, ptr); usage->m_element_size = element_size; usage->m_items += elements; if (usage->m_items_peak < usage->m_items) @@ -140,10 +142,10 @@ void vec_prefix::release_overhead (void *ptr, size_t size, size_t elements, bool in_dtor MEM_STAT_DECL) { - if (!vec_mem_desc.contains_descriptor_for_instance (ptr)) - vec_mem_desc.register_descriptor (ptr, VEC_ORIGIN, + if (!vec_mem_desc ().contains_descriptor_for_instance (ptr)) + vec_mem_desc ().register_descriptor (ptr, VEC_ORIGIN, false FINAL_PASS_MEM_STAT); - vec_usage *usage = vec_mem_desc.release_instance_overhead (ptr, size, + vec_usage *usage = vec_mem_desc ().release_instance_overhead (ptr, size, in_dtor); usage->m_items -= elements; } @@ -178,7 +180,7 @@ vec_prefix::calculate_allocation_1 (unsigned alloc, unsigned desired) void dump_vec_loc_statistics (void) { - vec_mem_desc.dump (VEC_ORIGIN); + vec_mem_desc ().dump (VEC_ORIGIN); } #if CHECKING_P -- 2.27.0