Do not leak SSANAMES in lto streamer
authorJan Hubicka <jh@suse.cz>
Mon, 23 Nov 2020 15:52:36 +0000 (16:52 +0100)
committerJan Hubicka <jh@suse.cz>
Mon, 23 Nov 2020 15:53:25 +0000 (16:53 +0100)
* lto-streamer-in.c (input_cfg): Do not init ssa operands.
(input_function): Do not init tree_ssa and set in_ssa_p.
(input_ssa_names): Do it here.
* tree-ssa.c (init_tree_ssa): Add additional SIZE parameter, default
to 0
* tree-ssanames.c (init_ssanames): Do not round size up to 50, allocate
precisely.
* tree-ssa.h (init_tree_ssa): Update prototype.

gcc/lto-streamer-in.c
gcc/tree-ssa.c
gcc/tree-ssa.h
gcc/tree-ssanames.c

index 64037f7..a20d64b 100644 (file)
@@ -1017,7 +1017,6 @@ input_cfg (class lto_input_block *ib, class data_in *data_in,
   int index;
 
   init_empty_tree_cfg_for_function (fn);
-  init_ssa_operands (fn);
 
   profile_status_for_fn (fn) = streamer_read_enum (ib, profile_status_d,
                                                   PROFILE_LAST);
@@ -1144,7 +1143,9 @@ input_ssa_names (class lto_input_block *ib, class data_in *data_in,
   unsigned int i, size;
 
   size = streamer_read_uhwi (ib);
-  init_ssanames (fn, size);
+  init_tree_ssa (fn, size);
+  cfun->gimple_df->in_ssa_p = true;
+  init_ssa_operands (fn);
 
   i = streamer_read_uhwi (ib);
   while (i)
@@ -1384,9 +1385,6 @@ input_function (tree fn_decl, class data_in *data_in,
 
   push_struct_function (fn_decl);
   fn = DECL_STRUCT_FUNCTION (fn_decl);
-  init_tree_ssa (fn);
-  /* We input IL in SSA form.  */
-  cfun->gimple_df->in_ssa_p = true;
 
   gimple_register_cfg_hooks ();
 
index b44361f..a575979 100644 (file)
@@ -1218,15 +1218,16 @@ err:
 #  pragma GCC diagnostic pop
 #endif
 
-/* Initialize global DFA and SSA structures.  */
+/* Initialize global DFA and SSA structures.
+   If SIZE is non-zero allocated ssa names array of a given size.  */
 
 void
-init_tree_ssa (struct function *fn)
+init_tree_ssa (struct function *fn, int size)
 {
   fn->gimple_df = ggc_cleared_alloc<gimple_df> ();
   fn->gimple_df->default_defs = hash_table<ssa_name_hasher>::create_ggc (20);
   pt_solution_reset (&fn->gimple_df->escaped);
-  init_ssanames (fn, 0);
+  init_ssanames (fn, size);
 }
 
 /* Deallocate memory associated with SSA data structures for FNDECL.  */
index 79f2b13..7e7fa4a 100644 (file)
@@ -45,7 +45,7 @@ extern void insert_debug_temps_for_defs (gimple_stmt_iterator *);
 extern void reset_debug_uses (gimple *);
 extern void release_defs_bitset (bitmap toremove);
 extern void verify_ssa (bool, bool);
-extern void init_tree_ssa (function *);
+extern void init_tree_ssa (function *, int size = 0);
 extern void delete_tree_ssa (function *);
 extern bool tree_ssa_useless_type_conversion (tree);
 extern tree tree_ssa_strip_useless_type_conversions (tree);
index 6ac97fe..ec4681f 100644 (file)
@@ -77,10 +77,10 @@ unsigned int ssa_name_nodes_created;
 void
 init_ssanames (struct function *fn, int size)
 {
-  if (size < 50)
-    size = 50;
-
-  vec_alloc (SSANAMES (fn), size);
+  if (!size)
+    vec_alloc (SSANAMES (fn), 50);
+  else
+    vec_safe_reserve (SSANAMES (fn), size, true);
 
   /* Version 0 is special, so reserve the first slot in the table.  Though
      currently unused, we may use version 0 in alias analysis as part of