Skip to content

Commit 9d5b6b2

Browse files
committed
Fix GGC
1 parent 7f2995c commit 9d5b6b2

8 files changed

+73
-5
lines changed

gcc/ipa-fnsummary.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4986,4 +4986,6 @@ void
49864986
ipa_fnsummary_cc_finalize (void)
49874987
{
49884988
ipa_free_fn_summary ();
4989+
// TODO: this commit contains many fixes that don't necessarily help fixing the bug in the GC. Remove those fixes.
4990+
ipa_free_size_summary ();
49894991
}

gcc/ipa-icf.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3656,3 +3656,12 @@ make_pass_ipa_icf (gcc::context *ctxt)
36563656
{
36573657
return new ipa_icf::pass_ipa_icf (ctxt);
36583658
}
3659+
3660+
/* Reset all state within ipa-icf.cc so that we can rerun the compiler
3661+
within the same process. For use by toplev::finalize. */
3662+
3663+
void
3664+
ipa_icf_cc_finalize (void)
3665+
{
3666+
ipa_icf::optimizer = NULL;
3667+
}

gcc/ipa-profile.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,3 +1065,13 @@ make_pass_ipa_profile (gcc::context *ctxt)
10651065
{
10661066
return new pass_ipa_profile (ctxt);
10671067
}
1068+
1069+
/* Reset all state within ipa-profile.cc so that we can rerun the compiler
1070+
within the same process. For use by toplev::finalize. */
1071+
1072+
void
1073+
ipa_profile_cc_finalize (void)
1074+
{
1075+
delete call_sums;
1076+
call_sums = NULL;
1077+
}

gcc/ipa-prop.cc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6001,5 +6001,23 @@ ipcp_transform_function (struct cgraph_node *node)
60016001
return modified_mem_access ? TODO_update_ssa_only_virtuals : 0;
60026002
}
60036003

6004+
/* Reset all state within ipa-prop.cc so that we can rerun the compiler
6005+
within the same process. For use by toplev::finalize. */
6006+
6007+
void
6008+
ipa_prop_cc_finalize (void)
6009+
{
6010+
if (function_insertion_hook_holder)
6011+
symtab->remove_cgraph_insertion_hook (function_insertion_hook_holder);
6012+
function_insertion_hook_holder = NULL;
6013+
6014+
if (ipa_edge_args_sum)
6015+
ggc_delete (ipa_edge_args_sum);
6016+
ipa_edge_args_sum = NULL;
6017+
6018+
if (ipa_node_params_sum)
6019+
ggc_delete (ipa_node_params_sum);
6020+
ipa_node_params_sum = NULL;
6021+
}
60046022

60056023
#include "gt-ipa-prop.h"

gcc/ipa-prop.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,6 +1162,8 @@ bool ipcp_get_parm_bits (tree, tree *, widest_int *);
11621162
bool unadjusted_ptr_and_unit_offset (tree op, tree *ret,
11631163
poly_int64 *offset_ret);
11641164

1165+
void ipa_prop_cc_finalize (void);
1166+
11651167
/* From tree-sra.cc: */
11661168
tree build_ref_for_offset (location_t, tree, poly_int64, bool, tree,
11671169
gimple_stmt_iterator *, bool);

gcc/ipa-sra.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4540,5 +4540,17 @@ make_pass_ipa_sra (gcc::context *ctxt)
45404540
return new pass_ipa_sra (ctxt);
45414541
}
45424542

4543+
/* Reset all state within ipa-sra.cc so that we can rerun the compiler
4544+
within the same process. For use by toplev::finalize. */
4545+
4546+
void
4547+
ipa_sra_cc_finalize (void)
4548+
{
4549+
if (func_sums)
4550+
ggc_delete (func_sums);
4551+
func_sums = NULL;
4552+
delete call_sums;
4553+
call_sums = NULL;
4554+
}
45434555

45444556
#include "gt-ipa-sra.h"

gcc/ipa-utils.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ bool ipa_make_function_pure (cgraph_node *, bool, bool);
5555

5656
/* In ipa-profile.cc */
5757
bool ipa_propagate_frequency (struct cgraph_node *node);
58+
void ipa_profile_cc_finalize (void);
59+
60+
/* In ipa-icf.cc */
61+
void ipa_icf_cc_finalize (void);
62+
63+
/* In ipa-sra.cc */
64+
void ipa_sra_cc_finalize (void);
5865

5966
/* In ipa-devirt.cc */
6067

gcc/toplev.cc

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ along with GCC; see the file COPYING3. If not see
7575
#include "symbol-summary.h"
7676
#include "tree-vrp.h"
7777
#include "ipa-prop.h"
78+
#include "ipa-utils.h"
7879
#include "gcse.h"
7980
#include "omp-offload.h"
8081
#include "edit-context.h"
@@ -1079,11 +1080,14 @@ general_init (const char *argv0, bool init_signals)
10791080
init_ggc ();
10801081
init_stringpool ();
10811082
input_location = UNKNOWN_LOCATION;
1082-
line_table = ggc_alloc<line_maps> ();
1083-
linemap_init (line_table, BUILTINS_LOCATION);
1084-
line_table->reallocator = realloc_for_line_map;
1085-
line_table->round_alloc_size = ggc_round_alloc_size;
1086-
line_table->default_range_bits = 5;
1083+
if (!line_table)
1084+
{
1085+
line_table = ggc_alloc<line_maps> ();
1086+
linemap_init (line_table, BUILTINS_LOCATION);
1087+
line_table->reallocator = realloc_for_line_map;
1088+
line_table->round_alloc_size = ggc_round_alloc_size;
1089+
line_table->default_range_bits = 5;
1090+
}
10871091
init_ttree ();
10881092

10891093
/* Initialize register usage now so switches may override. */
@@ -2327,7 +2331,11 @@ toplev::finalize (void)
23272331
ipa_fnsummary_cc_finalize ();
23282332
ipa_modref_cc_finalize ();
23292333
ipa_edge_modifications_finalize ();
2334+
ipa_icf_cc_finalize ();
23302335

2336+
ipa_prop_cc_finalize ();
2337+
ipa_profile_cc_finalize ();
2338+
ipa_sra_cc_finalize ();
23312339
cgraph_cc_finalize ();
23322340
cgraphunit_cc_finalize ();
23332341
symtab_thunks_cc_finalize ();

0 commit comments

Comments
 (0)