rs6000: Fix up PCH on powerpc* [PR104323]
As mentioned in the PR and as can be seen on: --- gcc/testsuite/gcc.dg/pch/pr104323-1.c.jj 2022-02-01 13:06:00.163192414 +0100 +++ gcc/testsuite/gcc.dg/pch/pr104323-1.c 2022-02-01 13:13:41.226712735 +0100 @@ -0,0 +1,16 @@ +/* PR target/104323 */ +/* { dg-require-effective-target powerpc_altivec_ok } */ +/* { dg-options "-maltivec" } */ + +#include "pr104323-1.h" + +__vector int a1 = { 100, 200, 300, 400 }; +__vector int a2 = { 500, 600, 700, 800 }; +__vector int r; + +int +main () +{ + r = vec_add (a1, a2); + return 0; +} --- gcc/testsuite/gcc.dg/pch/pr104323-1.hs.jj 2022-02-01 13:06:03.180149978 +0100 +++ gcc/testsuite/gcc.dg/pch/pr104323-1.hs 2022-02-01 13:12:30.175706620 +0100 @@ -0,0 +1,5 @@ +/* PR target/104323 */ +/* { dg-require-effective-target powerpc_altivec_ok } */ +/* { dg-options "-maltivec" } */ + +#include <altivec.h> testcase which I'm not including into testsuite because for some reason the test fails on non-powerpc* targets (is done even on those and fails because of missing altivec.h etc.), PCH is broken on powerpc*-*-* since the new builtin generator has been introduced. The generator contains or emits comments like: /* #### Cannot mark this as a GC root because only pointer types can be marked as GTY((user)) and be GC roots. All trees in here are kept alive by other globals, so not a big deal. Alternatively, we could change the enum fields to ints and cast them in and out to avoid requiring a GTY((user)) designation, but that seems unnecessarily gross. */ Having the fntypes stored in other GC roots can work fine for GC, ggc_collect will then always mark them and so they won't disappear from the tables, but it definitely doesn't work for PCH, which when the arrays with fntype members aren't GTY marked means on PCH write we create copies of those FUNCTION_TYPEs and store in *.gch that the GC roots should be updated, but don't store that rs6000_builtin_info[?].fntype etc. should be updated. When PCH is read again, the blob is read at some other address, GC roots are updated, rs6000_builtin_info[?].fntype contains garbage pointers (GC freed pointers with random data, or random unrelated types or other trees). The following patch fixes that. It stops any user markings because that is totally unnecessary, just skips fields we don't need to mark and adds GTY(()) to the 2 array variables. We can get rid of all those global vars for the fn types, they can be now automatic vars. With the patch we get { &rs6000_instance_info[0].fntype, 1 * (RS6000_INST_MAX), sizeof (rs6000_instance_info[0]), >_ggc_mx_tree_node, >_pch_nx_tree_node }, { &rs6000_builtin_info[0].fntype, 1 * (RS6000_BIF_MAX), sizeof (rs6000_builtin_info[0]), >_ggc_mx_tree_node, >_pch_nx_tree_node }, as the new roots which is exactly what we want and significantly more compact than countless { &uv2di_ftype_pudi_usi, 1, sizeof (uv2di_ftype_pudi_usi), >_ggc_mx_tree_node, >_pch_nx_tree_node }, { &uv2di_ftype_lg_puv2di, 1, sizeof (uv2di_ftype_lg_puv2di), >_ggc_mx_tree_node, >_pch_nx_tree_node }, { &uv2di_ftype_lg_pudi, 1, sizeof (uv2di_ftype_lg_pudi), >_ggc_mx_tree_node, >_pch_nx_tree_node }, { &uv2di_ftype_di_puv2di, 1, sizeof (uv2di_ftype_di_puv2di), >_ggc_mx_tree_node, >_pch_nx_tree_node }, cases (822 of these instead of just those 4 shown). 2022-02-01 Jakub Jelinek <jakub@redhat.com> PR target/104323 * config/rs6000/t-rs6000 (EXTRA_GTYPE_DEPS): Append rs6000-builtins.h rather than $(srcdir)/config/rs6000/rs6000-builtins.def. * config/rs6000/rs6000-gen-builtins.cc (write_decls): Don't use GTY((user)) for struct bifdata and struct ovlddata. Instead add GTY((skip(""))) to members with pointer and enum types that don't need to be tracked. Add GTY(()) to rs6000_builtin_info and rs6000_instance_info declarations. Don't emit gt_ggc_mx and gt_pch_nx declarations. (write_extern_fntype, write_fntype): Remove. (write_fntype_init): Emit the fntype vars as automatic vars instead of file scope ones. (write_header_file): Don't iterate with write_extern_fntype. (write_init_file): Don't iterate with write_fntype. Don't emit gt_ggc_mx and gt_pch_nx definitions.
This commit is contained in:
parent
8a37897862
commit
fa882c3e3b
@ -2255,20 +2255,20 @@ write_decls (void)
|
||||
fprintf (header_file, "};\n\n");
|
||||
|
||||
fprintf (header_file, "#define PPC_MAXRESTROPNDS 3\n");
|
||||
fprintf (header_file, "struct GTY((user)) bifdata\n");
|
||||
fprintf (header_file, "struct GTY(()) bifdata\n");
|
||||
fprintf (header_file, "{\n");
|
||||
fprintf (header_file, " const char *bifname;\n");
|
||||
fprintf (header_file, " bif_enable enable;\n");
|
||||
fprintf (header_file, " const char *GTY((skip(\"\"))) bifname;\n");
|
||||
fprintf (header_file, " bif_enable GTY((skip(\"\"))) enable;\n");
|
||||
fprintf (header_file, " tree fntype;\n");
|
||||
fprintf (header_file, " insn_code icode;\n");
|
||||
fprintf (header_file, " insn_code GTY((skip(\"\"))) icode;\n");
|
||||
fprintf (header_file, " int nargs;\n");
|
||||
fprintf (header_file, " int bifattrs;\n");
|
||||
fprintf (header_file, " int restr_opnd[PPC_MAXRESTROPNDS];\n");
|
||||
fprintf (header_file, " restriction restr[PPC_MAXRESTROPNDS];\n");
|
||||
fprintf (header_file, " restriction GTY((skip(\"\"))) restr[PPC_MAXRESTROPNDS];\n");
|
||||
fprintf (header_file, " int restr_val1[PPC_MAXRESTROPNDS];\n");
|
||||
fprintf (header_file, " int restr_val2[PPC_MAXRESTROPNDS];\n");
|
||||
fprintf (header_file, " const char *attr_string;\n");
|
||||
fprintf (header_file, " rs6000_gen_builtins assoc_bif;\n");
|
||||
fprintf (header_file, " const char *GTY((skip(\"\"))) attr_string;\n");
|
||||
fprintf (header_file, " rs6000_gen_builtins GTY((skip(\"\"))) assoc_bif;\n");
|
||||
fprintf (header_file, "};\n\n");
|
||||
|
||||
fprintf (header_file, "#define bif_init_bit\t\t(0x00000001)\n");
|
||||
@ -2343,21 +2343,15 @@ write_decls (void)
|
||||
"#define bif_is_ibmld(x)\t((x).bifattrs & bif_ibmld_bit)\n");
|
||||
fprintf (header_file, "\n");
|
||||
|
||||
/* #### Cannot mark this as a GC root because only pointer types can
|
||||
be marked as GTY((user)) and be GC roots. All trees in here are
|
||||
kept alive by other globals, so not a big deal. Alternatively,
|
||||
we could change the enum fields to ints and cast them in and out
|
||||
to avoid requiring a GTY((user)) designation, but that seems
|
||||
unnecessarily gross. */
|
||||
fprintf (header_file,
|
||||
"extern bifdata rs6000_builtin_info[RS6000_BIF_MAX];\n\n");
|
||||
"extern GTY(()) bifdata rs6000_builtin_info[RS6000_BIF_MAX];\n\n");
|
||||
|
||||
fprintf (header_file, "struct GTY((user)) ovlddata\n");
|
||||
fprintf (header_file, "struct GTY(()) ovlddata\n");
|
||||
fprintf (header_file, "{\n");
|
||||
fprintf (header_file, " const char *bifname;\n");
|
||||
fprintf (header_file, " rs6000_gen_builtins bifid;\n");
|
||||
fprintf (header_file, " const char *GTY((skip(\"\"))) bifname;\n");
|
||||
fprintf (header_file, " rs6000_gen_builtins GTY((skip(\"\"))) bifid;\n");
|
||||
fprintf (header_file, " tree fntype;\n");
|
||||
fprintf (header_file, " ovlddata *next;\n");
|
||||
fprintf (header_file, " ovlddata *GTY((skip(\"\"))) next;\n");
|
||||
fprintf (header_file, "};\n\n");
|
||||
|
||||
fprintf (header_file, "struct ovldrecord\n");
|
||||
@ -2367,14 +2361,7 @@ write_decls (void)
|
||||
fprintf (header_file, "};\n\n");
|
||||
|
||||
fprintf (header_file,
|
||||
"/* #### Cannot mark this as a GC root because only pointer\n"
|
||||
" types can be marked as GTY((user)) and be GC roots. All\n"
|
||||
" trees in here are kept alive by other globals, so not a big\n"
|
||||
" deal. Alternatively, we could change the enum fields to ints\n"
|
||||
" and cast them in and out to avoid requiring a GTY((user))\n"
|
||||
" designation, but that seems unnecessarily gross. */\n");
|
||||
fprintf (header_file,
|
||||
"extern ovlddata rs6000_instance_info[RS6000_INST_MAX];\n");
|
||||
"extern GTY(()) ovlddata rs6000_instance_info[RS6000_INST_MAX];\n");
|
||||
fprintf (header_file, "extern ovldrecord rs6000_overload_info[];\n\n");
|
||||
|
||||
fprintf (header_file, "extern void rs6000_init_generated_builtins ();\n\n");
|
||||
@ -2383,33 +2370,6 @@ write_decls (void)
|
||||
fprintf (header_file,
|
||||
"extern tree rs6000_builtin_decl (unsigned, "
|
||||
"bool ATTRIBUTE_UNUSED);\n\n");
|
||||
fprintf (header_file,
|
||||
"extern void gt_ggc_mx (bifdata *bd);\n");
|
||||
fprintf (header_file,
|
||||
"extern void gt_pch_nx (bifdata *bd);\n");
|
||||
fprintf (header_file,
|
||||
"extern void gt_pch_nx (bifdata *bd, gt_pointer_operator op, "
|
||||
"void *cookie);\n");
|
||||
fprintf (header_file,
|
||||
"extern void gt_ggc_mx (ovlddata *od);\n");
|
||||
fprintf (header_file,
|
||||
"extern void gt_pch_nx (ovlddata *od);\n");
|
||||
fprintf (header_file,
|
||||
"extern void gt_pch_nx (ovlddata *od, gt_pointer_operator op, "
|
||||
"void *cookie);\n");
|
||||
}
|
||||
|
||||
/* Callback functions used for generating trees for function types. */
|
||||
void
|
||||
write_extern_fntype (char *str)
|
||||
{
|
||||
fprintf (header_file, "extern GTY(()) tree %s;\n", str);
|
||||
}
|
||||
|
||||
void
|
||||
write_fntype (char *str)
|
||||
{
|
||||
fprintf (init_file, "tree %s;\n", str);
|
||||
}
|
||||
|
||||
/* Comparator for bsearch on the type map. */
|
||||
@ -2452,12 +2412,17 @@ write_fntype_init (char *str)
|
||||
/* Avoid side effects of strtok on the original string by using a copy. */
|
||||
char *buf = strdup (str);
|
||||
|
||||
if (tf_found)
|
||||
fprintf (init_file, " if (float128_type_node)\n ");
|
||||
else if (dfp_found)
|
||||
fprintf (init_file, " if (dfloat64_type_node)\n ");
|
||||
if (tf_found || dfp_found)
|
||||
fprintf (init_file, " tree %s = NULL_TREE;\n", buf);
|
||||
else
|
||||
fprintf (init_file, " tree ");
|
||||
|
||||
fprintf (init_file, " %s\n = build_function_type_list (", buf);
|
||||
if (tf_found)
|
||||
fprintf (init_file, " if (float128_type_node)\n ");
|
||||
else if (dfp_found)
|
||||
fprintf (init_file, " if (dfloat64_type_node)\n ");
|
||||
|
||||
fprintf (init_file, "%s\n = build_function_type_list (", buf);
|
||||
tok = strtok (buf, "_");
|
||||
write_type_node (tok, tf_found || dfp_found);
|
||||
tok = strtok (0, "_");
|
||||
@ -2491,8 +2456,6 @@ write_header_file (void)
|
||||
|
||||
write_decls ();
|
||||
|
||||
/* Write function type list declarators to the header file. */
|
||||
rbt_inorder_callback (&fntype_rbt, fntype_rbt.rbt_root, write_extern_fntype);
|
||||
fprintf (header_file, "\n");
|
||||
fprintf (header_file, "\n#endif\n");
|
||||
|
||||
@ -2846,9 +2809,6 @@ write_init_file (void)
|
||||
write_bif_static_init ();
|
||||
write_ovld_static_init ();
|
||||
|
||||
rbt_inorder_callback (&fntype_rbt, fntype_rbt.rbt_root, write_fntype);
|
||||
fprintf (init_file, "\n");
|
||||
|
||||
fprintf (init_file, "void\n");
|
||||
fprintf (init_file, "rs6000_init_generated_builtins ()\n");
|
||||
fprintf (init_file, "{\n");
|
||||
@ -2868,33 +2828,6 @@ write_init_file (void)
|
||||
|
||||
fprintf (init_file, "}\n\n");
|
||||
|
||||
fprintf (init_file,
|
||||
"void gt_ggc_mx (bifdata *bd)\n");
|
||||
fprintf (init_file,
|
||||
"{\n gt_ggc_mx (bd->fntype);\n}\n\n");
|
||||
fprintf (init_file,
|
||||
"void gt_pch_nx (bifdata *bd)\n");
|
||||
fprintf (init_file,
|
||||
"{\n gt_pch_nx (bd->fntype);\n}\n\n");
|
||||
fprintf (init_file,
|
||||
"void gt_pch_nx (bifdata *bd, gt_pointer_operator op, "
|
||||
"void *cookie)\n");
|
||||
fprintf (init_file,
|
||||
"{\n op(&(bd->fntype), NULL, cookie);\n}\n\n");
|
||||
fprintf (init_file,
|
||||
"void gt_ggc_mx (ovlddata *od)\n");
|
||||
fprintf (init_file,
|
||||
"{\n gt_ggc_mx (od->fntype);\n}\n\n");
|
||||
fprintf (init_file,
|
||||
"void gt_pch_nx (ovlddata *od)\n");
|
||||
fprintf (init_file,
|
||||
"{\n gt_pch_nx (od->fntype);\n}\n\n");
|
||||
fprintf (init_file,
|
||||
"void gt_pch_nx (ovlddata *od, gt_pointer_operator op, "
|
||||
"void *cookie)\n");
|
||||
fprintf (init_file,
|
||||
"{\n op(&(od->fntype), NULL, cookie);\n}\n");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,7 @@
|
||||
TM_H += $(srcdir)/config/rs6000/rs6000-cpus.def
|
||||
TM_H += $(srcdir)/config/rs6000/rs6000-modes.h
|
||||
PASSES_EXTRA += $(srcdir)/config/rs6000/rs6000-passes.def
|
||||
EXTRA_GTYPE_DEPS += $(srcdir)/config/rs6000/rs6000-builtins.def
|
||||
EXTRA_GTYPE_DEPS += rs6000-builtins.h
|
||||
|
||||
rs6000-pcrel-opt.o: $(srcdir)/config/rs6000/rs6000-pcrel-opt.cc
|
||||
$(COMPILE) $<
|
||||
|
Loading…
Reference in New Issue
Block a user