public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] ipa: call destructors on lattices before freeing them (PR 113476)
@ 2024-02-12 17:39 Martin Jambor
  2024-02-12 17:50 ` Jan Hubicka
  0 siblings, 1 reply; 9+ messages in thread
From: Martin Jambor @ 2024-02-12 17:39 UTC (permalink / raw)
  To: GCC Patches; +Cc: Richard Biener, Jan Hubicka

Hi,

In PR 113476 we have discovered that ipcp_param_lattices is no longer
a POD and should be destructed.  This patch does that, calling
destructor on each element of the array containing them when the
corresponding summary of a node is freed.  An alternative would be to
change the XCNEWVEC-and-placement-new to initializations in
constructors of all things in ipcp_param_lattices and then simply use
normal operators new and delete.  I am not sure, the initialization
through XCNEWVEC may be a bit more efficient although that is probably
not a big concern.  In the end, I opted for a simpler solution for
stage 4.

I have verified that valgrind no longer reports lost memory blocks
allocated within ipcp_vr_lattice::meet_with_1 on the preprocessed source
(dwarf2out.i) attached to Bugzilla.  The patch also passes bootstrap and
LTO bootstrap and testing on x86_64-linux.

OK for master?

Thanks,

Martin


gcc/ChangeLog:

2024-02-09  Martin Jambor  <mjambor@suse.cz>

	PR tree-optimization/113476
	* ipa-prop.h (ipa_node_params::~ipa_node_params): Moved...
	* ipa-cp.cc (ipa_node_params::~ipa_node_params): ...here.  Added
	destruction of lattices.
---
 gcc/ipa-cp.cc  | 17 +++++++++++++++++
 gcc/ipa-prop.h |  9 ---------
 2 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/gcc/ipa-cp.cc b/gcc/ipa-cp.cc
index e85477df32d..9864ff052de 100644
--- a/gcc/ipa-cp.cc
+++ b/gcc/ipa-cp.cc
@@ -399,6 +399,23 @@ public:
   bool virt_call;
 };
 
+/* Destructor of node function summary, placed here because it mainly must
+   destruct value range lattices not known outside of this source file.  */
+
+ipa_node_params::~ipa_node_params ()
+{
+  if (lattices)
+    {
+      int count = ipa_get_param_count (this);
+      for (int i = 0; i < count; i++)
+	lattices[i].~ipcp_param_lattices ();
+      free (lattices);
+    }
+  vec_free (descriptors);
+  known_csts.release ();
+  known_contexts.release ();
+}
+
 /* Allocation pools for values and their sources in ipa-cp.  */
 
 object_allocator<ipcp_value<tree> > ipcp_cst_values_pool
diff --git a/gcc/ipa-prop.h b/gcc/ipa-prop.h
index 9c78dc9f486..fe401640824 100644
--- a/gcc/ipa-prop.h
+++ b/gcc/ipa-prop.h
@@ -670,15 +670,6 @@ ipa_node_params::ipa_node_params ()
 {
 }
 
-inline
-ipa_node_params::~ipa_node_params ()
-{
-  free (lattices);
-  vec_free (descriptors);
-  known_csts.release ();
-  known_contexts.release ();
-}
-
 /* Intermediate information that we get from alias analysis about a particular
    parameter in a particular basic_block.  When a parameter or the memory it
    references is marked modified, we use that information in all dominated
-- 
2.43.0


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2024-02-20 10:20 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-12 17:39 [PATCH] ipa: call destructors on lattices before freeing them (PR 113476) Martin Jambor
2024-02-12 17:50 ` Jan Hubicka
2024-02-12 18:17   ` Martin Jambor
2024-02-12 20:22     ` Jan Hubicka
2024-02-13 17:49       ` Martin Jambor
2024-02-19 15:04         ` [PATCH] ipa: Convert lattices from pure array to vector " Martin Jambor
2024-02-20  7:11           ` Richard Biener
2024-02-20 10:20           ` Jan Hubicka
2024-02-14  9:52   ` [PATCH] ipa: call destructors on lattices before freeing them " Martin Jambor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).