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 C55DC38133E4 for ; Mon, 30 May 2022 11:33:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C55DC38133E4 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-247-GmM9FVIENE2U_eLid08L6g-1; Mon, 30 May 2022 07:33:58 -0400 X-MC-Unique: GmM9FVIENE2U_eLid08L6g-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E55B2101A54E; Mon, 30 May 2022 11:33:57 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.33.36.77]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AA5D52166B2A; Mon, 30 May 2022 11:33:57 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 24UBXtW33614151 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Mon, 30 May 2022 13:33:55 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 24UBXsbu3614150; Mon, 30 May 2022 13:33:54 +0200 Date: Mon, 30 May 2022 13:33:54 +0200 From: Jakub Jelinek To: Kwok Cheung Yeung Cc: gcc-patches Subject: Re: [PATCH 4/7] openmp: Add support for streaming metadirectives and resolving them after LTO Message-ID: Reply-To: Jakub Jelinek References: <0813fb26-b6ec-0a39-11aa-4a4687947531@codesourcery.com> MIME-Version: 1.0 In-Reply-To: <0813fb26-b6ec-0a39-11aa-4a4687947531@codesourcery.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 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=-3.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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: Mon, 30 May 2022 11:34:01 -0000 On Fri, Dec 10, 2021 at 05:36:20PM +0000, Kwok Cheung Yeung wrote: > 2021-12-10 Kwok Cheung Yeung > > gcc/ > * Makefile.in (OBJS): Add omp-expand-metadirective.o. > * gimple-streamer-in.c (input_gimple_stmt): Add case for > GIMPLE_OMP_METADIRECTIVE. Handle metadirective labels. > * gimple-streamer-out.c (output_gimple_stmt): Likewise. > * omp-expand-metadirective.cc: New. > * passes.def: Add pass_omp_expand_metadirective. > * tree-pass.h (make_pass_omp_expand_metadirective): New prototype. > --- > gcc/Makefile.in | 1 + > gcc/gimple-streamer-in.c | 10 ++ > gcc/gimple-streamer-out.c | 6 + > gcc/omp-expand-metadirective.cc | 191 ++++++++++++++++++++++++++++++++ > gcc/passes.def | 1 + > gcc/tree-pass.h | 1 + > 6 files changed, 210 insertions(+) > create mode 100644 gcc/omp-expand-metadirective.cc > > @@ -151,6 +151,7 @@ input_gimple_stmt (class lto_input_block *ib, class data_in *data_in, > case GIMPLE_COND: > case GIMPLE_GOTO: > case GIMPLE_DEBUG: > + case GIMPLE_OMP_METADIRECTIVE: > for (i = 0; i < num_ops; i++) > { > tree *opp, op = stream_read_tree (ib, data_in); > @@ -188,6 +189,15 @@ input_gimple_stmt (class lto_input_block *ib, class data_in *data_in, > else > gimple_call_set_fntype (call_stmt, stream_read_tree (ib, data_in)); > } > + if (gomp_metadirective *metadirective_stmt > + = dyn_cast (stmt)) > + { > + gimple_alloc_omp_metadirective (metadirective_stmt); > + for (i = 0; i < num_ops; i++) > + gimple_omp_metadirective_set_label (metadirective_stmt, i, > + stream_read_tree (ib, > + data_in)); > + } Ah, sorry for the comment about LTO streaming, here it is. > --- /dev/null > +++ b/gcc/omp-expand-metadirective.cc > @@ -0,0 +1,191 @@ > +/* Expand an OpenMP metadirective. > + > + Copyright (C) 2021 Free Software Foundation, Inc. We have 2022 now... > + Missing function comment. > +static void > +omp_expand_metadirective (function *fun, basic_block bb) > +{ > + gimple *stmt = last_stmt (bb); > + vec candidates > + = omp_resolve_metadirective (stmt); > + > + /* This is the last chance for the metadirective to be resolved. */ > + if (candidates.is_empty ()) > + gcc_unreachable (); gcc_assert (!candidates.is_empty ()); ? > + /* opt_pass methods: */ > + virtual bool gate (function *) > + { > + return (flag_openmp); Useless ()s around it. But much more importantly, I don't really like this to be a separate pass, walking the whole IL once more is expensive, even when you restrict it to just flag_openmp. Late declare variant resolving is done in the (now a little bit misnamed) pass_omp_device_lower. The gate of that pass is right now: return (!(fun->curr_properties & PROP_gimple_lomp_dev) || (flag_openmp && cgraph_node::get (fun->decl)->calls_declare_variant_alt)); so it would be nice to track (conservatively) whether current function has any metadirectives in it which aren't yet resolved (but perhaps the calls_declare_variant_alt bit could be abused for that too) andin that case also deal with those. You can surely gather them in the omp-offload.cc pass and then call a function in your new file to handle that. Jakub