tree-optimization/97630 - fix SLP cycle memory leak
This fixes SLP cycles leaking memory by maintaining a double-linked list of allocatd SLP nodes we can zap when we free the alloc pool. 2020-12-02 Richard Biener <rguenther@suse.de> PR tree-optimization/97630 * tree-vectorizer.h (_slp_tree::next_node, _slp_tree::prev_node): New. (vect_slp_init): Declare. (vect_slp_fini): Likewise. * tree-vectorizer.c (vectorize_loops): Call vect_slp_init/fini. (pass_slp_vectorize::execute): Likewise. * tree-vect-slp.c (vect_slp_init): New. (vect_slp_fini): Likewise. (slp_first_node): New global. (_slp_tree::_slp_tree): Link node into the SLP tree list. (_slp_tree::~_slp_tree): Delink node from the SLP tree list.
This commit is contained in:
parent
bad800c03d
commit
feb93adf76
@ -48,11 +48,28 @@ along with GCC; see the file COPYING3. If not see
|
||||
#include "cfganal.h"
|
||||
#include "tree-eh.h"
|
||||
#include "tree-cfg.h"
|
||||
#include "alloc-pool.h"
|
||||
|
||||
static bool vectorizable_slp_permutation (vec_info *, gimple_stmt_iterator *,
|
||||
slp_tree, stmt_vector_for_cost *);
|
||||
|
||||
object_allocator<_slp_tree> *slp_tree_pool;
|
||||
static object_allocator<_slp_tree> *slp_tree_pool;
|
||||
static slp_tree slp_first_node;
|
||||
|
||||
void
|
||||
vect_slp_init (void)
|
||||
{
|
||||
slp_tree_pool = new object_allocator<_slp_tree> ("SLP nodes");
|
||||
}
|
||||
|
||||
void
|
||||
vect_slp_fini (void)
|
||||
{
|
||||
while (slp_first_node)
|
||||
delete slp_first_node;
|
||||
delete slp_tree_pool;
|
||||
slp_tree_pool = NULL;
|
||||
}
|
||||
|
||||
void *
|
||||
_slp_tree::operator new (size_t n)
|
||||
@ -73,6 +90,11 @@ _slp_tree::operator delete (void *node, size_t n)
|
||||
|
||||
_slp_tree::_slp_tree ()
|
||||
{
|
||||
this->prev_node = NULL;
|
||||
if (slp_first_node)
|
||||
slp_first_node->prev_node = this;
|
||||
this->next_node = slp_first_node;
|
||||
slp_first_node = this;
|
||||
SLP_TREE_SCALAR_STMTS (this) = vNULL;
|
||||
SLP_TREE_SCALAR_OPS (this) = vNULL;
|
||||
SLP_TREE_VEC_STMTS (this) = vNULL;
|
||||
@ -94,6 +116,12 @@ _slp_tree::_slp_tree ()
|
||||
|
||||
_slp_tree::~_slp_tree ()
|
||||
{
|
||||
if (this->prev_node)
|
||||
this->prev_node->next_node = this->next_node;
|
||||
else
|
||||
slp_first_node = this->next_node;
|
||||
if (this->next_node)
|
||||
this->next_node->prev_node = this->prev_node;
|
||||
SLP_TREE_CHILDREN (this).release ();
|
||||
SLP_TREE_SCALAR_STMTS (this).release ();
|
||||
SLP_TREE_SCALAR_OPS (this).release ();
|
||||
|
@ -1171,7 +1171,7 @@ vectorize_loops (void)
|
||||
if (vect_loops_num <= 1)
|
||||
return 0;
|
||||
|
||||
slp_tree_pool = new object_allocator<_slp_tree> ("SLP nodes for vect");
|
||||
vect_slp_init ();
|
||||
|
||||
if (cfun->has_simduid_loops)
|
||||
note_simd_array_uses (&simd_array_to_simduid_htab);
|
||||
@ -1295,8 +1295,7 @@ vectorize_loops (void)
|
||||
shrink_simd_arrays (simd_array_to_simduid_htab, simduid_to_vf_htab);
|
||||
delete simduid_to_vf_htab;
|
||||
cfun->has_simduid_loops = false;
|
||||
delete slp_tree_pool;
|
||||
slp_tree_pool = NULL;
|
||||
vect_slp_fini ();
|
||||
|
||||
if (num_vectorized_loops > 0)
|
||||
{
|
||||
@ -1432,12 +1431,11 @@ pass_slp_vectorize::execute (function *fun)
|
||||
}
|
||||
}
|
||||
|
||||
slp_tree_pool = new object_allocator<_slp_tree> ("SLP nodes for slp");
|
||||
vect_slp_init ();
|
||||
|
||||
vect_slp_function (fun);
|
||||
|
||||
delete slp_tree_pool;
|
||||
slp_tree_pool = NULL;
|
||||
vect_slp_fini ();
|
||||
|
||||
if (!in_loop_pipeline)
|
||||
{
|
||||
|
@ -26,7 +26,6 @@ typedef class _stmt_vec_info *stmt_vec_info;
|
||||
#include "tree-data-ref.h"
|
||||
#include "tree-hash-traits.h"
|
||||
#include "target.h"
|
||||
#include "alloc-pool.h"
|
||||
|
||||
|
||||
/* Used for naming of new temporaries. */
|
||||
@ -116,8 +115,6 @@ typedef hash_map<tree_operand_hash,
|
||||
************************************************************************/
|
||||
typedef struct _slp_tree *slp_tree;
|
||||
|
||||
extern object_allocator<_slp_tree> *slp_tree_pool;
|
||||
|
||||
/* A computation tree of an SLP instance. Each node corresponds to a group of
|
||||
stmts to be packed in a SIMD stmt. */
|
||||
struct _slp_tree {
|
||||
@ -172,6 +169,10 @@ struct _slp_tree {
|
||||
|
||||
/* Return memory to slp_tree_pool. */
|
||||
static void operator delete (void *, size_t);
|
||||
|
||||
/* Linked list of nodes to release when we free the slp_tree_pool. */
|
||||
slp_tree next_node;
|
||||
slp_tree prev_node;
|
||||
};
|
||||
|
||||
/* The enum describes the type of operations that an SLP instance
|
||||
@ -1963,6 +1964,8 @@ extern int vect_get_known_peeling_cost (loop_vec_info, int, int *,
|
||||
extern tree cse_and_gimplify_to_preheader (loop_vec_info, tree);
|
||||
|
||||
/* In tree-vect-slp.c. */
|
||||
extern void vect_slp_init (void);
|
||||
extern void vect_slp_fini (void);
|
||||
extern void vect_free_slp_instance (slp_instance);
|
||||
extern bool vect_transform_slp_perm_load (vec_info *, slp_tree, vec<tree>,
|
||||
gimple_stmt_iterator *, poly_uint64,
|
||||
|
Loading…
x
Reference in New Issue
Block a user