From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 108823858C74 for ; Tue, 1 Feb 2022 15:27:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 108823858C74 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-661-zo0IfCuIPu-OcgN6-M7Sng-1; Tue, 01 Feb 2022 10:27:47 -0500 X-MC-Unique: zo0IfCuIPu-OcgN6-M7Sng-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3FB155F9CE; Tue, 1 Feb 2022 15:27:46 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.125]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A65D210A4B34; Tue, 1 Feb 2022 15:27:45 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.16.1/8.16.1) with ESMTPS id 211FRg0p3415203 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 1 Feb 2022 16:27:42 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.16.1/8.16.1/Submit) id 211FReQH3415202; Tue, 1 Feb 2022 16:27:40 +0100 Date: Tue, 1 Feb 2022 16:27:40 +0100 From: Jakub Jelinek To: Segher Boessenkool , David Edelsohn Cc: gcc-patches@gcc.gnu.org, Bill Schmidt Subject: [PATCH] rs6000: Fix up PCH on powerpc* [PR104323] Message-ID: <20220201152740.GX2646553@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-5.2 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 01 Feb 2022 15:27:53 -0000 Hi! 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 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). Bootstrapped/regtested on powerpc64le-linux, ok for trunk? 2022-02-01 Jakub Jelinek 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. --- gcc/config/rs6000/t-rs6000.jj 2022-01-18 11:58:59.245986871 +0100 +++ gcc/config/rs6000/t-rs6000 2022-02-01 12:25:32.945144092 +0100 @@ -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) $< --- gcc/config/rs6000/rs6000-gen-builtins.cc.jj 2022-01-18 11:58:59.218987257 +0100 +++ gcc/config/rs6000/rs6000-gen-builtins.cc 2022-02-01 12:52:57.632188253 +0100 @@ -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. */ @@ -2453,11 +2413,17 @@ write_fntype_init (char *str) char *buf = strdup (str); if (tf_found) - fprintf (init_file, " if (float128_type_node)\n "); + fprintf (init_file, + " tree %s = NULL_TREE;\n if (float128_type_node)\n ", + buf); else if (dfp_found) - fprintf (init_file, " if (dfloat64_type_node)\n "); + fprintf (init_file, + " tree %s = NULL_TREE;\n if (dfloat64_type_node)\n ", + buf); + else + fprintf (init_file, " tree "); - fprintf (init_file, " %s\n = build_function_type_list (", buf); + 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 +2457,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 +2810,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 +2829,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; } Jakub