Re: [r15-3834 Regression] FAIL: c-c++-common/gomp/declare-variant-duplicates.c (test for excess errors) on Linux/x86_64
On 9/24/24 14:08, haochen.jiang wrote: On Linux/x86_64, 96246bff0bcd9e5cdec9e6cf811ee3db4997f6d4 is the first bad commit commit 96246bff0bcd9e5cdec9e6cf811ee3db4997f6d4 Author: Sandra Loosemore Date: Fri Sep 6 20:58:13 2024 + OpenMP: Check additional restrictions on context selector properties caused FAIL: c-c++-common/gomp/declare-variant-duplicates.c (test for errors, line 11) FAIL: c-c++-common/gomp/declare-variant-duplicates.c (test for excess errors) with GCC configured with ../../gcc/configure --prefix=/export/users/haochenj/src/gcc-bisect/master/master/r15-3834/usr --enable-clocale=gnu --with-system-zlib --with-demangler-in-ld --with-fpmath=sse --enable-languages=c,c++,fortran --enable-cet --without-isl --enable-libmpx x86_64-linux --disable-bootstrap To reproduce: $ cd {build_dir}/gcc && make check RUNTESTFLAGS="gomp.exp=c-c++-common/gomp/declare-variant-duplicates.c --target_board='unix{-m32}'" $ cd {build_dir}/gcc && make check RUNTESTFLAGS="gomp.exp=c-c++-common/gomp/declare-variant-duplicates.c --target_board='unix{-m32\ -march=cascadelake}'" It turns out the problem here is that with -m32, "i386" is defined as a built-in preprocessor macro :-O so it cannot be used as an identifier. I've pushed the attached patch to adjust the testcase not to do that. -Sandra From 6935bddd8f90dde6009a1b8dea9745788ceeefb1 Mon Sep 17 00:00:00 2001 From: Sandra Loosemore Date: Wed, 25 Sep 2024 02:59:53 + Subject: [PATCH] OpenMP: Fix testsuite failure on x86 with -m32 The testcase decare-variant-duplicates.c added in commit 96246bff0bcd9e5cdec9e6cf811ee3db4997f6d4 failed on 32-bit x86 because on that target "i386" is defined as a preprocessor macro and cannot be used as an identifier. Fixed by rewriting that test not to do that. gcc/testsuite/ChangeLog * c-c++-common/gomp/declare-variant-duplicates.c: Avoid using "i386" as an identifier. --- gcc/testsuite/c-c++-common/gomp/declare-variant-duplicates.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gcc/testsuite/c-c++-common/gomp/declare-variant-duplicates.c b/gcc/testsuite/c-c++-common/gomp/declare-variant-duplicates.c index 47d34fc52e2..9f319c72449 100644 --- a/gcc/testsuite/c-c++-common/gomp/declare-variant-duplicates.c +++ b/gcc/testsuite/c-c++-common/gomp/declare-variant-duplicates.c @@ -8,6 +8,6 @@ extern int f4 (int); #pragma omp declare variant (f1) match (device={kind(cpu,gpu,"cpu")}) /* { dg-error "trait-property .cpu. specified more than once" } */ #pragma omp declare variant (f2) match (device={isa(sse4,"avx",avx)}) /* { dg-error "trait-property .avx. specified more than once" } */ -#pragma omp declare variant (f3) match (device={arch(x86_64,i386,aarch64,"i386")}) /* { dg-error "trait-property .i386. specified more than once" } */ +#pragma omp declare variant (f3) match (device={arch(x86_64,"i386",aarch64,"x86_64")}) /* { dg-error "trait-property .x86_64. specified more than once" } */ #pragma omp declare variant (f4) match (implementation={vendor(llvm,gnu,"arm",gnu)}) /* { dg-error "trait-property .gnu. specified more than once" } */ int f (int); -- 2.25.1
Re: [PATCH v3 08/12] OpenMP: Reject other properties with kind(any)
On 9/21/24 22:52, Jakub Jelinek wrote: On Sat, Sep 21, 2024 at 08:08:29PM -0600, Sandra Loosemore wrote: On 9/20/24 01:41, Jakub Jelinek wrote: + + /* Check for unknown properties. */ if (omp_ts_map[ts_code].valid_properties == NULL) continue; - Why? Why what? I made this change because when I added another check in this loop I was temporarily confused about the control flow and I thought this would help. If you're asking why it's doing the null check here, it's because it doesn't make sense to check properties on all selectors, like properties that can have implementation-defined values for other compilers. I meant why the empty line was removed? To make it more clear that the null check is part of the code chunk to diagnose unknown properties -- each of which is now formatted the same way, with a blank line, comment to explain what it's doing, and no blank lines within the chunk. -Sandra
Re: [PATCH v3 08/12] OpenMP: Reject other properties with kind(any)
On 9/20/24 01:41, Jakub Jelinek wrote: + + /* Check for unknown properties. */ if (omp_ts_map[ts_code].valid_properties == NULL) continue; - Why? Why what? I made this change because when I added another check in this loop I was temporarily confused about the control flow and I thought this would help. If you're asking why it's doing the null check here, it's because it doesn't make sense to check properties on all selectors, like properties that can have implementation-defined values for other compilers. -Sandra
Re: [PATCH v3 03/12] libgomp: runtime support for target_device selector
On 9/9/24 04:46, Tobias Burnus wrote: I wonder whether we should do something like the following. [The following is a mix between compile code and generated code, for illustrative purpose.] Inside the compiler do: #ifndef ACCEL_COMPILER intr = 0; if (targetm.omp.device_kind_arch_isa != NULL) r = targetm.omp.device_kind_arch_isa (omp_device_{kind,arch,isa}, val); if (dev_num && TREE_CODE (dev_num) == INTEGER_CST) { if (dev_num < -1 /* INVALID_DEVICE or nonconforming */) → 0 if (dev_num == initial_device) → r } /* The '? :' condition is a compile time condition. */ d = ? : omp_get_default_device (); if (d < -1) → 0 else if (d == -1 || d == omp_get_initial_device ()) → r else → GOMP_get_device_kind_arch_isa (d, kind, arch, isa) #else /* VARIANT 1: Assume that neither reverse offload nor nested target occurs. */ →targetm.omp.device_kind_arch_isa (kind, arch, isa) /* VARIANT 2 - d = ? : omp_get_default_device (); if (d == omp_get_device_num ()) →targetm.omp.device_kind_arch_isa (kind, arch, isa) else /* Cannot really do anything here - and as no nested target is permitted, use 'false'. */ → 0 #endif * * * And on the libgomp side GOMP_get_device_kind_arch_isa → plugin code. H. I've fleshed out my own idea a bit, that would entirely get rid of the libgomp runtime support. Leaving aside cases that can be trivially determined (offloading is disabled, the device number is an expression that can be statically determined to refer to the host or an invalid device, kind/arch/isa don't match any enabled offload target), I think the predicate of the more general case for target_device={device_num (NUM), kind(KIND), arch(ARCH), isa(ISA)} can be expressed (using GCC statement expression syntax) as ({ int matches; #pragma omp target device (NUM) matches = magic_cookie (KIND, ARCH, ISA) matches; }) where magic_cookie is either a built-in or new gimple code. I think the gimplifier is probably the right place to do the above transformation, and the magic_cookie expansion would happen during (or at least at the same point in compilation as) late metadirective resolution; IOW, in the offload compiler). That part can call targetm.omp.device_kind_arch_isa to resolve the whole works into a constant true/false, similar to how the "device" selector is handled in the offload compiler, rather than into any runtime routine. The gimplifier can issue a "sorry" if the target_device selector appears in a target region, if this seems like something that should not/can not reasonably be supported. Does this seem like a plausible way to continue? Of course I might run into some unanticipated difficulty in implementation but it would be helpful to know if I'm totally barking up the wrong tree here before I waste too much time continuing down this path. -Sandra
Re: [PATCH v3 08/12] OpenMP: Reject other properties with kind(any)
On 9/9/24 14:55, Sandra Loosemore wrote: On 9/9/24 05:01, Jakub Jelinek wrote: I think also testing the device={kind(any,any)} and device={kind("any",any)} and device={kind(any,"any"))} would be useful. Hmmm, it looks like GCC does not presently check for the restriction "Each trait-property may only be specified once in a trait selector other than those in the construct selector set." I'll have to re-work the patch again to add that. :-S Here's the revised patch, covering both restrictions. OK to commit? -Sandra From 6dabf26a4e893b93a38a5e791d70719429687bc5 Mon Sep 17 00:00:00 2001 From: Sandra Loosemore Date: Fri, 6 Sep 2024 20:58:13 + Subject: [PATCH] OpenMP: Check additional restrictions on context selector properties TR13 (pre-6.0) of the OpenMP spec says: "Each trait-property may only be specified once in a trait selector other than those in the construct selector set." and "If trait-property any is specified in the kind trait-selector of the device selector set or the target_device selector sets, no other trait-property may be specified in the same selector set." These restrictions (with slightly different wording) date back to OpenMP 5.1, but were not in 5.0 which was the basis for GCC's implementation. This patch adds a diagnostic, adds new testcases, and fixes some older testcases that include now-invalid selectors. gcc/ChangeLog * omp-general.cc (omp_check_context_selector): Reject other properties in the same selector set with kind(any). Also reject duplicate name-list properties. gcc/testsuite/ChangeLog * c-c++-common/gomp/declare-variant-10.c: Fix broken tests. * c-c++-common/gomp/declare-variant-3.c: Likewise. * c-c++-common/gomp/declare-variant-9.c: Likewise. * c-c++-common/gomp/declare-variant-any.c: New. * c-c++-common/gomp/declare-variant-duplicates.c: New. * gfortran.dg/gomp/declare-variant-10.f90: Fix broken tests. * gfortran.dg/gomp/declare-variant-3.f90: Likewise. * gfortran.dg/gomp/declare-variant-9.f90: Likewise. * gfortran.dg/gomp/declare-variant-any.f90: New. * gfortran.dg/gomp/declare-variant-duplicates.f90: New. --- gcc/omp-general.cc| 64 ++- .../c-c++-common/gomp/declare-variant-10.c| 4 +- .../c-c++-common/gomp/declare-variant-3.c | 10 +-- .../c-c++-common/gomp/declare-variant-9.c | 4 +- .../c-c++-common/gomp/declare-variant-any.c | 17 + .../gomp/declare-variant-duplicates.c | 13 .../gfortran.dg/gomp/declare-variant-10.f90 | 4 +- .../gfortran.dg/gomp/declare-variant-3.f90| 12 +--- .../gfortran.dg/gomp/declare-variant-9.f90| 2 +- .../gfortran.dg/gomp/declare-variant-any.f90 | 40 .../gomp/declare-variant-duplicates.f90 | 30 + 11 files changed, 176 insertions(+), 24 deletions(-) create mode 100644 gcc/testsuite/c-c++-common/gomp/declare-variant-any.c create mode 100644 gcc/testsuite/c-c++-common/gomp/declare-variant-duplicates.c create mode 100644 gcc/testsuite/gfortran.dg/gomp/declare-variant-any.f90 create mode 100644 gcc/testsuite/gfortran.dg/gomp/declare-variant-duplicates.f90 diff --git a/gcc/omp-general.cc b/gcc/omp-general.cc index 0b61335dba4..599cfbc4338 100644 --- a/gcc/omp-general.cc +++ b/gcc/omp-general.cc @@ -1288,6 +1288,8 @@ omp_check_context_selector (location_t loc, tree ctx) for (tree tss = ctx; tss; tss = TREE_CHAIN (tss)) { enum omp_tss_code tss_code = OMP_TSS_CODE (tss); + bool saw_any_prop = false; + bool saw_other_prop = false; /* We can parse this, but not handle it yet. */ if (tss_code == OMP_TRAIT_SET_TARGET_DEVICE) @@ -1324,9 +1326,61 @@ omp_check_context_selector (location_t loc, tree ctx) else ts_seen[ts_code] = true; + /* If trait-property "any" is specified in the "kind" + trait-selector of the "device" selector set or the + "target_device" selector sets, no other trait-property + may be specified in the same selector set. */ + if (ts_code == OMP_TRAIT_DEVICE_KIND) + for (tree p = OMP_TS_PROPERTIES (ts); p; p = TREE_CHAIN (p)) + { + const char *prop = omp_context_name_list_prop (p); + if (!prop) + continue; + else if (strcmp (prop, "any") == 0) + saw_any_prop = true; + else + saw_other_prop = true; + } + /* It seems slightly suspicious that the spec's language covers + the device_num selector too, but + target_device={device_num(whatever),kind(any)} + is probably not terribly useful anyway. */ + else if (ts_code == OMP_TRAIT_DEVICE_ARCH + || ts_code == OMP_TRAIT_DEVICE_ISA + || ts_code == OMP_TRAIT_DEVICE_NUM) + saw_other_prop = true; + + /* Each trait-property can only be specified once in a trait-selector + other than the construct selector set. FIXME: only handles + name-list properties, n
Re: [PATCH v3 08/12] OpenMP: Reject other properties with kind(any)
On 9/9/24 05:01, Jakub Jelinek wrote: I think also testing the device={kind(any,any)} and device={kind("any",any)} and device={kind(any,"any"))} would be useful. Hmmm, it looks like GCC does not presently check for the restriction "Each trait-property may only be specified once in a trait selector other than those in the construct selector set." I'll have to re-work the patch again to add that. :-S -Sandra
Re: [PATCH v3 08/12] OpenMP: Reject other properties with kind(any)
On 8/16/24 06:58, Jakub Jelinek wrote: If this can apply (perhaps with small fuzz) to vanilla trunk, guess it can be committed right now, doesn't need to wait for the rest of the metadirective patch set. OK. I've tested the slightly cleaned-up version of the patch which is attached; I'll push it in the next day or two if there is no further objection. -SandraFrom 23a82bea26805f2a430354d56b444d5bb7eaed3f Mon Sep 17 00:00:00 2001 From: Sandra Loosemore Date: Fri, 6 Sep 2024 20:58:13 + Subject: [PATCH] OpenMP: Reject other properties with kind(any) TR13 (pre-6.0) of the OpenMP spec says: "If trait-property any is specified in the kind trait-selector of the device selector set or the target_device selector sets, no other trait-property may be specified in the same selector set." This restriction dates back to OpenMP 5.1 (where it had slightly different wording). GCC's implementation was based on the 5.0 spec, and several testcases include selectors that are now considered invalid. This patch adds a diagnostic and fixes the testcases. gcc/ChangeLog * omp-general.cc (omp_check_context_selector): Reject other properties in the same selector set with kind(any). gcc/testsuite/ChangeLog * c-c++-common/gomp/declare-variant-10.c: Fix broken tests. * c-c++-common/gomp/declare-variant-3.c: Likewise. * c-c++-common/gomp/declare-variant-9.c: Likewise. * c-c++-common/gomp/declare-variant-any.c: New. * gfortran.dg/gomp/declare-variant-10.f90: Fix broken tests. * gfortran.dg/gomp/declare-variant-3.f90: Likewise. * gfortran.dg/gomp/declare-variant-9.f90: Likewise. * gfortran.dg/gomp/declare-variant-any.f90: New. --- gcc/omp-general.cc| 35 +++ .../c-c++-common/gomp/declare-variant-10.c| 4 +-- .../c-c++-common/gomp/declare-variant-3.c | 10 ++ .../c-c++-common/gomp/declare-variant-9.c | 4 +-- .../c-c++-common/gomp/declare-variant-any.c | 10 ++ .../gfortran.dg/gomp/declare-variant-10.f90 | 4 +-- .../gfortran.dg/gomp/declare-variant-3.f90| 12 ++- .../gfortran.dg/gomp/declare-variant-9.f90| 2 +- .../gfortran.dg/gomp/declare-variant-any.f90 | 28 +++ 9 files changed, 86 insertions(+), 23 deletions(-) create mode 100644 gcc/testsuite/c-c++-common/gomp/declare-variant-any.c create mode 100644 gcc/testsuite/gfortran.dg/gomp/declare-variant-any.f90 diff --git a/gcc/omp-general.cc b/gcc/omp-general.cc index 0b61335dba4..aa53c00bec5 100644 --- a/gcc/omp-general.cc +++ b/gcc/omp-general.cc @@ -1288,6 +1288,8 @@ omp_check_context_selector (location_t loc, tree ctx) for (tree tss = ctx; tss; tss = TREE_CHAIN (tss)) { enum omp_tss_code tss_code = OMP_TSS_CODE (tss); + bool saw_any_prop = false; + bool saw_other_prop = false; /* We can parse this, but not handle it yet. */ if (tss_code == OMP_TRAIT_SET_TARGET_DEVICE) @@ -1324,6 +1326,31 @@ omp_check_context_selector (location_t loc, tree ctx) else ts_seen[ts_code] = true; + + /* If trait-property "any" is specified in the "kind" + trait-selector of the "device" selector set or the + "target_device" selector sets, no other trait-property + may be specified in the same selector set. */ + if (ts_code == OMP_TRAIT_DEVICE_KIND) + for (tree p = OMP_TS_PROPERTIES (ts); p; p = TREE_CHAIN (p)) + { + const char *prop = omp_context_name_list_prop (p); + if (!prop) + continue; + else if (strcmp (prop, "any") == 0) + saw_any_prop = true; + else + saw_other_prop = true; + } + /* It seems slightly suspicious that the spec's language covers + the device_num selector too, but + target_device={device_num(whatever),kind(any)} + is probably not terribly useful anyway. */ + else if (ts_code == OMP_TRAIT_DEVICE_ARCH + || ts_code == OMP_TRAIT_DEVICE_ISA + || ts_code == OMP_TRAIT_DEVICE_NUM) + saw_other_prop = true; + if (omp_ts_map[ts_code].valid_properties == NULL) continue; @@ -1376,6 +1403,14 @@ omp_check_context_selector (location_t loc, tree ctx) break; } } + + if (saw_any_prop && saw_other_prop) + { + error_at (loc, + "no other trait-property may be specified " + "in the same selector set with %"); + return error_mark_node; + } } return ctx; } diff --git a/gcc/testsuite/c-c++-common/gomp/declare-variant-10.c b/gcc/testsuite/c-c++-common/gomp/declare-variant-10.c index 2b8a39425b1..e77693430d1 100644 --- a/gcc/testsuite/c-c++-common/gomp/declare-variant-10.c +++ b/gcc/testsuite/c-c++-common/gomp/declare-variant-10.c @@ -7,7 +7,7 @@ void f01 (void); #pragma omp declare variant (f01) match (device={isa(avx512f,avx512bw)}) void f02 (void); void f03 (void); -#pragma omp declare variant (f03) match (device={kind("any"),arch(x86_64),isa(avx512f,avx512bw)}) +#pragma
Re: [PATCH v3 04/12] OpenMP: C front end support for metadirectives
On 8/16/24 04:30, Jakub Jelinek wrote: On Sat, Jul 20, 2024 at 02:42:23PM -0600, Sandra Loosemore wrote: --- a/gcc/c/c-parser.cc +++ b/gcc/c/c-parser.cc @@ -263,9 +263,24 @@ struct GTY(()) c_parser { otherwise NULL. */ vec *in_omp_attribute_pragma; + /* When in_omp_attribute_pragma is non-null, these fields save the values + of the tokens and tokens_avail fields, so that they can be restored + after parsing the attribute. Note that parsing the body of a + metadirective uses its own save/restore mechanism as those can be + nested with or without the attribute pragmas in the body. */ +c_token * GTY((skip)) save_tokens; +unsigned int save_tokens_avail; The indentation of the above 2 is wrong. Plus if those members are for metadirective parsing, their names are too generic. They are not for metadirective parsing, they are to generalize the state-saving for OpenMP attribute-syntax directives that are converted to pragmas. It's related to this patch hunk: @@ -6846,7 +6884,6 @@ c_parser_handle_statement_omp_attributes (c_parser *parser , tree &attrs, return false; unsigned int tokens_avail = parser->tokens_avail; - gcc_assert (parser->tokens == &parser->tokens_buf[0]); tokens++; vec *toks = NULL; and the multiple instances like this: @@ -1307,8 +1322,10 @@ c_parser_skip_until_found (c_parser *parser, c_token *token = c_parser_peek_token (parser); if (token->type == CPP_EOF) { - parser->tokens = &parser->tokens_buf[0]; - parser->tokens_avail = token->flags; + parser->tokens = parser->save_tokens; + parser->save_tokens = NULL; + parser->tokens_avail = parser->save_tokens_avail; + parser->save_tokens_avail = 0; parser->in_omp_attribute_pragma = NULL; } } where there presently is a hard-wired assumption that omp attribute pragma parsing is the *only* thing that messes with what parser->tokens points to. Metadirectives need to maintain a separate token stream too, and attribute-syntax pragma directives can appear inside a metadirective, so fixing this somehow is necessary. Due to the control flow of parsing the attribute-syntax pragmas it's not possible to save the state it needs in local variables on the stack, so hanging it off the parser object is about the only choice. But more importantly, for something parsed really rarely, wouldn't it be better to just add a single pointer to a new structure that contains all you need for metadirective parsing? Do you want me to create separate new data structures for both the attribute-syntax pragma parsing, and the metadirective-specific bits? And maybe submit the attribute-syntax pragma parsing state changes as its own patch separate from the metadirective pieces? -Sandra
Re: [PATCH] Libquadmath: update doc for some constants
On 8/27/24 11:06, Tobias Burnus wrote: Hi FX, FX Coudert wrote: Give it’s a doc patch, I think it might fall under the obvious rule, and will commit in a week if there is no objection. The patch clearly fixes a bug in the current specification and is fine, I just wonder … * libquadmath.texi (M_LOG2Eq, M_LOG10Eq, M_2_PIq): Fix description of these constants. diff --git a/libquadmath/libquadmath.texi b/libquadmath/libquadmath.texi index dc2a9ff374b..ce4accf6421 100644 --- a/libquadmath/libquadmath.texi +++ b/libquadmath/libquadmath.texi … @item @code{M_PI_2q}: pi divided by two @item @code{M_PI_4q}: pi divided by four @item @code{M_1_PIq}: one over pi -@item @code{M_2_PIq}: one over two pi +@item @code{M_2_PIq}: two over pi @item @code{M_2_SQRTPIq}: two over square root of pi @item @code{M_SQRT2q}: square root of 2 @item @code{M_SQRT1_2q}: one over square root of 2 ... whether we should change the "over" which somehow sounds odd. "two divided by pi" sounds better to me than "two over pi". I do note, however, that the following documentation uses a slightly different wording: "M_2_PI -Two times the reciprocal of pi." https://www.gnu.org/software/libc/manual/html_node/Mathematical-Constants.html Hence, while I am fine with the change, I think we should replace the "over" wording (multiple times) and move either to "divided by" or [(…times) the reciprocal of". I agree. I don't have a preference for which is better, but being consistent with other documentation might be a winning argument. Alas, Texinfo has lousy support for formatting mathematical equations, so that's not an option. -Sandra
Re: [patch] libgomp.texi: Document supported OpenMP 'interop' types for nvptx and gcn
On 8/24/24 09:13, Tobias Burnus wrote: +@node Foreign-runtime support for AMD GPUs +@subsection OpenMP @code{interop} -- Foreign-Runtime Support for AMD GPUs Em-dash in Texinfo is three dashes with no surrounding spaces. I believe that the libgomp manual uses the incorrect markup you have here in its usual template for documenting specific runtime routines (and I'm not telling you to change that everywhere), but that's not how you're using it here. +An interoperability object of OpenMP @code{interop} type can be obtained using +the @code{interop} directive; supported as foreign runtimes are HIP +(C++ Heterogeneous-Compute Interface for Portability) and HSA (Heterogeneous +System Architecture). If no @code{prefer_type} argument has been specified, +HIP is used. + +The following properties can then be extracted using the @ref{Interoperability +Routines}. Each listed property name has an associated named constant, It would be much better to rewrite this in the active voice, phrasing as "you can do X" instead of "X can be done", and "GCC supports the foreign runtimes ..." instead of the awkward "supported as foreign runtimes are ...". Also, "if no @code{prefer_type} argument has been specified" argument to what? Looking it up in the spec, it appears that is actually a modifier to the @code{init} clause of the @code{interop} directive? I think this needs to be said explicitly. +consisting of @code{omp_ipr_} followed by the property name. The following s/@code/@samp/ (as already noted in my comments on your previous patch) +table uses ``@emph{int}'', ``@emph{str}'' and ``@emph{ptr}'' to denote the +routine to be used to obtain the property value. Ugh, we should never be using literal quotes for markup purposes. :-( I'd say just use @samp instead of @emph here. +Available properties for an HIP interop object: +@multitable @columnfractions .30 .30 .30 +@headitem Property @tab data type@tab value (if constant) +@item @code{fr_id} @tab @samp{omp_interop_fr_t} @emph{(int)} @tab @samp{omp_fr_hip} +@item @code{fr_name}@tab @samp{const char *} @emph{(str)} @tab @samp{hip} +@item @code{vendor} @tab @samp{int} @emph{(int)} @tab @samp{1} +@item @code{vendor_name}@tab @samp{const char *} @emph{(str)} @tab @samp{amd} +@item @code{device_num} @tab @samp{int} @emph{(int)} @tab +@item @code{platform} @tab N/A @tab +@item @code{device} @tab @samp{hipDevice_t} @emph{(int)} @tab +@item @code{device_context} @tab @samp{hipCtx_t} @emph{(ptr)} @tab +@item @code{targetsync} @tab @samp{hipStream_t} @emph{(ptr)} @tab +@end multitable Ugh, again. :-( You have 4 columns in the table that you are trying to format into 3, and I think you really want to have 5 columns (property name, constant name, data type, accessor function, and value). And I think you are going to overflow the right margin for PDF output of the manual if you try making the table that wide. Can you instead format it as a vertical table for each property, like @table @code @item fr_id @table @asis @item Named constant: @code{omp_ipr_fr_id} @item Data type: @code{omp_interop_fr_t} @item Accessor: @code{omp_get_interop_int} @item Property value: @code{omp_fr_hip} @end table ... @end table I don't think the @samp and @emph markup you have is helpful, just use @code for all the fields. Similarly for all the other tables in your patch. Also, here: +@node Foreign-runtime support for Nvidia GPUs +@subsection OpenMP @code{interop} -- Foreign-Runtime Support for Nvidia GPUs + +An interoperability object of OpenMP @code{interop} type can be obtained using +the @code{interop} directive; supported as foreign runtimes are the CUDA +runtime API, the CUDA driver API, and the C++ Heterogeneous-Compute Interface +for Portability (HIP), which is -- for CUDA-based systems -- a very thin layer +on top of the CUDA APIs. If no @code{prefer_type} argument has been specified, +the CUDA runtime API is used. You have more problems with incorrect em-dash markup (the ones in the body of the paragraph are certainly incorrect Texinfo usage even if you want to argue about the one in the @subsection name), use of the passive voice, and @code{prefer_type} confusion, as previously noted. -Sandra
Re: [patch][v2] libgomp.texi: Document OpenMP's Interoperability Routines
On 8/23/24 07:03, Tobias Burnus wrote: Add documentation for OpenMP's interoperability routines. I have only a few copy-editing type comments. +Implementation remark: In GCC, the Fortran interface differs from the one shown +below: the function has C binding, @var{interop} is passed by value and an +integer of @code{c_int} kind is returnd, permitting to have the same ABI as the s/returnd/returned/ (this seems to be the only instance in the patch) s/permitting to have/which permits use of/g (multiple instances) +C function. This does not affect the usage of the function when GCC's +@code{omp_lib} module or @code{omp_lib.h} header is used. Stepping back to consider this from a higher-level perspective, shouldn't the interface documented in the GCC manual reflect what GCC implements, rather than what the spec says that is explicitly *not* what is implemented? Or is the way you have documented this consistent with the way other libgomp features that don't strictly conform to the spec have already been documented? +The @code{omp_get_interop_name} function returns the name of the property +itself as string; for the properties specified by the OpenMP specification, +the name matches the name of the named constant with the @code{omp_ipr_} +prefix removed. That should be @samp{omp_ipr_}, not @code markup. +In GCC, this function returns the C/C++ data type for this property or the name of the C/C++ data type +@samp{N/A} if this property is not available for the given foreign runtime. @code{"N/A"}, I think. (It's a string literal, right?) +If @var{interop} is @code{omp_interop_none} or for invalid property values, +a null pointer is returned. The the effect of running this routine in a s/The the/The/ +The @code{omp_get_interop_rc_desc} function returns a string value describing +the @var{ret_code} in human readable form. s/human readable form/human-readable form/ I know the libgomp manual uses different formatting conventions than the GCC manual or other Texinfo manuals. Have you inspected the formatted output to make sure it's what you expect and consistent with the rest of the document? -Sandra
Re: [PATCH v3 02/12] OpenMP: middle-end support for metadirectives
On 8/10/24 02:02, Jakub Jelinek wrote: On Sat, Aug 10, 2024 at 09:18:24AM +0200, Jakub Jelinek wrote: On Fri, Aug 09, 2024 at 07:12:48PM +0200, Jakub Jelinek wrote: --- a/gcc/gimple.def +++ b/gcc/gimple.def @@ -398,6 +398,13 @@ DEFGSCODE(GIMPLE_OMP_TEAMS, "gimple_omp_teams", GSS_OMP_PARALLEL_LAYOUT) CLAUSES is an OMP_CLAUSE chain holding the associated clauses. */ DEFGSCODE(GIMPLE_OMP_ORDERED, "gimple_omp_ordered", GSS_OMP_SINGLE_LAYOUT) +/* GIMPLE_OMP_METADIRECTIVE represents #pragma omp metadirective. */ +DEFGSCODE(GIMPLE_OMP_METADIRECTIVE, "gimple_omp_metadirective", + GSS_OMP_METADIRECTIVE) + +DEFGSCODE(GIMPLE_OMP_METADIRECTIVE_VARIANT, + "gimple_omp_variant", GSS_OMP_METADIRECTIVE_VARIANT) + Oh, and I wonder if there shouldn't be a different representation of this in GIMPLE. GIMPLE_OMP_METADIRECTIVE in the patch seems to have both the TREE_LISTs for the variants and the labels. We already have a construct which can have a set of labels, GIMPLE_SWITCH, and tons of optimizations available for it. Can't GIMPLE_OMP_METADIRECTIVE be just the list of TREE_LISTs for the variants which sets some integer SSA_NAME with a GIMPLE_SWITCH next to it which picks what code will be used? And, to simplify the SSA scanners, perhaps have the device_num and condition operands hoisted to separate ops. So, ops[0] would be the output, artificial integer result used in GIMPLE_SWITCH, ops[1] say condition SSA_NAME (if dynamic condition isn't used, then boolean_true_node), ops[2] say device_num SSA_NAME (if unused some negative INTEGER_CST which can't otherwise happen)? Perhaps we'd want to avoid GIMPLE_SWITCH lowering if the controlling SSA_NAME has GIMPLE_OMP_METADIRECTIVE def_stmt (because we expect it to fold into a constant), but otherwise other GIMPLE_SWITCH optimizations might be ok. What do you think? Or am I missing something? Please ignore the part about dynamic condition/device_num, each variant obviously will have its own. But the rest stands. I think I understand the general idea you're getting at. Just FYI, as part of addressing this, I'm going to do some patch refactoring to incorporate some further changes to GIMPLE_OMP_METADIRECTIVE that I had in part 9 of the series, where I extended it to also handle the call-site dispatch for "#pragma omp declare variant" with dynamic selectors. I was never very happy about using the original name GIMPLE_OMP_METADIRECTIVE for both things, and looking at it now I think GIMPLE_OMP_VARIANT_DIRECTIVE is probably a better choice. WDYT? -Sandra
Re: [PATCH v3 01/12] OpenMP: metadirective tree data structures and front-end interfaces
On 8/9/24 10:42, Jakub Jelinek wrote: Why needs omp-general.h the move in GTFILES etc.? Will just moving those definitions be ok? I just double-checked that. The Makefile.in change to reorder omp-general.h in GTFILES is because of moving the definition of score_wide_int there from omp-general.cc. Otherwise the gtype processing seems to be confused by getting the two files in the wrong order: /path/to/gcc/omp-general.h:96: type `score_wide_int' previously defined /path/to/gcc/omp-general.cc:2436: previously defined here make[3]: *** [Makefile:2979: s-gtype] Error 1 I'll add a note to the changelog line for that to explain what it's for. Otherwise LGTM. Thanks for the review! -Sandra
Re: [PING^4][PATCH v2] docs: Update function multiversioning documentation
On 8/13/24 11:18, Andrew Carlotti wrote: I'm still waiting for review for this patch. I've asked Richard Sandiford about it, and he'd like a docs maintainer to review the patch (so I've cc'd the rest of them now as well). I'm sorry, I've seen this patch go by before, but every time I've looked at it I get confused by which patch hunk belongs to which section, and tracking which are just moving text around and which are new, and I haven't had the time to build the manual with the patch and compare the changed sections. So I can't comment right now on whether the organization changes are OK. Not being familiar with the functionality, I don't think I have anything intelligent to say about it from a technical perspective, either. Has someone else reviewed this for correctness already? I did look it over again for other problems, and this is what jumped out at me. The reference to a requirement for ELF and GLIBC 2.23 buried in an implementation details discussion concerns me. If this feature doesn't work on non-ELF or non-GLIBC targets (Windows, bare-metal, Android...) that's not an implementation detail, it's user-visible restriction and needs to be documented up front. Please get rid of all the future tense ("will") and write in the present tense, assuming all the documented functionality is presently implemented. :-) There are multiple places where you need to do s/at runtime/at run time/g per https://gcc.gnu.org/codingconventions.html#Spelling Also please s/target specific version/target-specific version/ In this paragraph: +In the above example, four versions of function foo are created. The first +version of @samp{foo}, with the target attribute @samp{"default"}, is the +default version. This version gets executed when no other target specific +version qualifies for execution on a particular platform. Other versions of +@samp{foo} are created by using the same function signature but with a +different target string. The function @samp{foo} can be called or a pointer to +it can be taken just like for a regular function. GCC takes care of doing the +dispatching to call the right version at runtime. I believe all of these @samp{} things should be @code{}, and you missed adding markup to the first instance of "foo". And here +Function multiversioning is implemented using the STT_GNU_IFUNC symbol type @code{STT_GNU_IFUNC}, please. -Sandra
Re: [PATCH] doc: Editorial changes in -fprofile-partial-training
On 8/10/24 13:24, Gerald Pfeifer wrote: +With @code{-fprofile-use} all portions of programs not executed during +training runs are optimized aggressively for size rather than speed. +In some cases it is not practical to train all possible hot paths in +the program. (For example, a program may contain functions specific to +a given hardware and training may not cover all hardware configurations +the program later runs on.) With @code{-fprofile-partial-training} +profile feedback will be ignored for all functions not executed during +the training, them being optimized as if they were compiled without +profile feedback. This leads to better performance when the training +is not representative at the cost of significantly bigger code. Hmmm, this is still pretty confusing; I had to read this 3 or 4 times before I realized that the first sentence was describing behavior *without* this option instead of what the option does. :-S I suggest putting the most important info first, maybe like This option modifies the behavior of @option{-fprofile-use} on functions that were not executed during training runs. Normally @option{-fprofile-use} causes such functions to be optimized aggressively for size; @option{-fprofile-partial-training} instead causes them to be optimized as if they were compiled without profile feedback. This option is useful when it is not practical to train all possible hot paths in the program. (For example, a program may contain functions specific to a given hardware and training may not cover all hardware configurations the program later runs on.) In cases where the training runs are not representative, this option improves performance at the cost of significantly larger code. -Sandra
Re: [Patch] libgomp.texi: Update implementation status table for OpenMP TR13
On 8/8/24 06:21, Tobias Burnus wrote: Update for the very recently released TR13. Unsurprisingly, most item are still unimplemented. → https://www.openmp.org/specifications/ → Technical Report 13 Comments, suggestions, typo fixes? — If not, I will commit it later today. I've got a few things... @item @code{workdistribute} directive for Fortran @tab N - @tab Renamed just after TR12; added in TR12 as @code{coexecute} + @tab Intermittendly known as @code{coexecute} "Intermittendly" isn't a word. I'm not sure what you're trying to say here, but I don't think we need to document things that are not part of any official standard and were never implemented in GCC. +@item Deprecation of the @code{target_data_op}, @code{target}, + @code{target_map and target_submit} callbacks and as value that + @code{set_callback} must return @tab N @tab Do you mean "@code{target_map} and @code{target_submit}"? And s/as value/as values/ (since there are more than one). +@item The @code{values ompt_target_data_transfer_to_device}, + @code{ompt_target_data_transfer_from_device}, + @code{ompt_target_data_transfer_to_device_async} and + @code{ompt_target_data_transfer_from_device_async} were deprecated > + @tab N @tab Doesn't say what the things with these names are. How about "The enumerators for the @code{target_data_op} OMPT type were deprecated." -Sandra
Re: [Patch] libgomp/libgomp.texi: Mention -fno-builtin-omp_is_initial_device
On 8/8/24 06:20, Jakub Jelinek wrote: On Thu, Aug 08, 2024 at 02:18:48PM +0200, Tobias Burnus wrote: Document -fno-builtin-omp_is_initial_device as discussed: Jakub Jelinek wrote: RFC: Should be document this new built-in some where? If so, where? As part of the routine description in libgomp.texi? Or in extend.texi (or even invoke.texi)? I think libgomp.texi in the omp_is_initial_device description, mention that the compiler folds it by default and that if that is undesirable, there is this option to use. Unless there are wording suggestions, I will commit it later today. Tobias libgomp/libgomp.texi: Mention -fno-builtin-omp_is_initial_device libgomp/ChangeLog: * libgomp.texi (omp_is_initial_device): Mention -fno-builtin-omp_is_initial_device and folding by default. LGTM. Me too. -Sandra
Re: [Patch] libgomp.texi: Update 'Device Information Routines' section
On 7/29/24 06:12, Tobias Burnus wrote: I recently stumbled over omp_get_default_device returning -1 (= omp_initial_device) vs. returning omp_get_num_devices(). Thus, it makes sense to document this properly. I also updated some wording and made a tiny step to documenting the missing functions by adding a title to the commented @menu items. → https://gcc.gnu.org/onlinedocs/libgomp/#toc-OpenMP-Runtime-Library-Routines for the current wording. Comments or suggestions before I commit it? Looks OK to me, although I'd suggest s/without device clause/without a device clause/g. -Sandra
Re: [PATCH v3 01/12] OpenMP: metadirective tree data structures and front-end interfaces
On 7/25/24 08:00, Tobias Burnus wrote: Hi Sandra, thanks for your patch. (Disclaimer: I have not finished reading through your patch.) Some upfront generic remarks: [* When first compiling it (incremental build), I did run into the issue that OMP_METADIRECTIVE_CHECK wasn't declared. Thus, there seems to be a dependency issue causing that tree-check.h might generated after code that includes tree.h is processed. (Unrelated to your patch itself, but for completeness …)] I've never run into this. Are you saying some .cc file is missing a makefile dependency on tree-check.h? Which one? Or is it tree-check.h that is missing a dependency on something else and failing to get regenerated? Or both? * Not required right now, but eventually we need to check whether https://gcc.gnu.org/PR112779 is fully fixed by this patch set or whether follow-up work is required (and if so which). There is also PR107067 for a Fortran ICE. * There are some not-implemented/FIXME comments in the patches for missing features. I think we should ensure that those won't get forgotten, e.g. by filing PRs for those. – For declare variant, some PRs might already exist. Can you eventually take care of the last two items? Yes. (For the last item: e.g. 'target_device' for declare_variant, for which 'sorry' already existed.) * * * I might have asked the following question before – and you might have answered it already: Sandra Loosemore wrote: This patch adds the OMP_METADIRECTIVE tree node and shared tree-level support for manipulating metadirectives. It defines/exposes interfaces that will be used in subsequent patches that add front-end and middle-end support, but nothing generates these nodes yet. I have to admit that I do not understand the part: + else if (set == OMP_TRAIT_SET_TARGET_DEVICE) +/* The target_device set is dynamic, so treat it as always + resolvable. */ +continue; + The current code has 3 states: * 0 - if a trait is false; this directly returns as it cannot be fixed later * 1 - if the all traits are known to match (initial value) * -1 - if one trait cannot be evaluated, either because it is too early (e.g. during parsing) or because it is a dynamic context selector. Your last assertion is wrong. The comments on the top of omp_context_selector_matches explicitly *say* "Dynamic properties (which are evaluated at run-time) should always return 1." This is because dynamic selectors are *always* candidates, which are then scored and sorted according to the rules in the spec for the metadirective and declare variant constructs. Maybe the problem is the name of the function Would it help if I renamed it from "omp_context_selector_matches" to "omp_context_selector_is_candidate"? @@ -1804,6 +1834,12 @@ omp_context_selector_matches (tree ctx) case OMP_TRAIT_USER_CONDITION: if (set == OMP_TRAIT_SET_USER) for (tree p = OMP_TS_PROPERTIES (ts); p; p = TREE_CHAIN (p)) if (OMP_TP_NAME (p) == NULL_TREE) { + /* OpenMP 5.1 allows non-constant conditions for + metadirectives. */ + if (metadirective_p + && !tree_fits_shwi_p (OMP_TP_VALUE (p))) + break; + if (integer_zerop (OMP_TP_VALUE (p))) return 0; if (integer_nonzerop (OMP_TP_VALUE (p))) break; ret = -1; } * Comment wording: Please change to imply >= 5.1 not == 5.0 * Comment: I don't see why the non-const only applies to metadirectives; the OpenMP >= 5.1 seems to imply that it is also valid for declare variant. Thus, I would change the wording. The first 7 patches in the posted set implement support for dynamic selectors in metadirectives. Dynamic selector support for declare variant comes in the later patches, which further modify this code. If you'd find it easier to review, I can smash everything together into one gigantic patch (or some smaller number of patches), but I fear it would make everything harder to review given the amount of removed or moved around. Alternatively, trying to split it into more but smaller incremental patches is problematical due to inter-dependencies and, again, multiple patches touching the same bits of code, adding and removing temporary stubs, etc. * The current code seems to already handle non-const values as expected. ... except that it changes "res" to -1, while the idea seems to be not to modify 'ret' in this case for metadirectives. (Why? Same question as above). This gets back to same point as earlier, dynamic selectors are always candidates. According to the spec, the "user" selector is dynamic if the "condition" is not a constant, so
[PATCH v3 07/12] OpenMP: Fortran front-end support for metadirectives.
etadirective test. * gfortran.dg/gomp/pure-2.f90: Remove metadirective test. libgomp/ChangeLog * testsuite/libgomp.fortran/metadirective-1.f90: New. * testsuite/libgomp.fortran/metadirective-2.f90: New. * testsuite/libgomp.fortran/metadirective-3.f90: New. * testsuite/libgomp.fortran/metadirective-4.f90: New. * testsuite/libgomp.fortran/metadirective-5.f90: New. * testsuite/libgomp.fortran/metadirective-6.f90: New. Co-Authored-By: Kwok Cheung Yeung Co-Authored-By: Sandra Loosemore Co-Authored-By: Tobias Burnus Co-Authored-By: Paul-Antoine Arras --- gcc/fortran/decl.cc | 29 + gcc/fortran/dump-parse-tree.cc| 21 + gcc/fortran/gfortran.h| 21 +- gcc/fortran/io.cc | 2 +- gcc/fortran/match.h | 2 + gcc/fortran/openmp.cc | 294 +++-- gcc/fortran/parse.cc | 578 +++--- gcc/fortran/parse.h | 8 +- gcc/fortran/resolve.cc| 6 + gcc/fortran/st.cc | 4 + gcc/fortran/symbol.cc | 25 +- gcc/fortran/trans-decl.cc | 5 +- gcc/fortran/trans-openmp.cc | 233 --- gcc/fortran/trans-stmt.h | 1 + gcc/fortran/trans.cc | 1 + .../gfortran.dg/gomp/metadirective-1.f90 | 55 ++ .../gfortran.dg/gomp/metadirective-10.f90 | 40 ++ .../gfortran.dg/gomp/metadirective-11.f90 | 33 + .../gfortran.dg/gomp/metadirective-2.f90 | 62 ++ .../gfortran.dg/gomp/metadirective-3.f90 | 34 ++ .../gfortran.dg/gomp/metadirective-4.f90 | 39 ++ .../gfortran.dg/gomp/metadirective-5.f90 | 30 + .../gfortran.dg/gomp/metadirective-6.f90 | 31 + .../gfortran.dg/gomp/metadirective-7.f90 | 36 ++ .../gfortran.dg/gomp/metadirective-8.f90 | 22 + .../gfortran.dg/gomp/metadirective-9.f90 | 30 + .../gomp/metadirective-construct.f90 | 260 .../gomp/metadirective-no-score.f90 | 122 gcc/testsuite/gfortran.dg/gomp/pure-1.f90 | 7 + gcc/testsuite/gfortran.dg/gomp/pure-2.f90 | 8 - .../libgomp.fortran/metadirective-1.f90 | 61 ++ .../libgomp.fortran/metadirective-2.f90 | 40 ++ .../libgomp.fortran/metadirective-3.f90 | 29 + .../libgomp.fortran/metadirective-4.f90 | 46 ++ .../libgomp.fortran/metadirective-5.f90 | 44 ++ .../libgomp.fortran/metadirective-6.f90 | 58 ++ 36 files changed, 1952 insertions(+), 365 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/gomp/metadirective-1.f90 create mode 100644 gcc/testsuite/gfortran.dg/gomp/metadirective-10.f90 create mode 100644 gcc/testsuite/gfortran.dg/gomp/metadirective-11.f90 create mode 100644 gcc/testsuite/gfortran.dg/gomp/metadirective-2.f90 create mode 100644 gcc/testsuite/gfortran.dg/gomp/metadirective-3.f90 create mode 100644 gcc/testsuite/gfortran.dg/gomp/metadirective-4.f90 create mode 100644 gcc/testsuite/gfortran.dg/gomp/metadirective-5.f90 create mode 100644 gcc/testsuite/gfortran.dg/gomp/metadirective-6.f90 create mode 100644 gcc/testsuite/gfortran.dg/gomp/metadirective-7.f90 create mode 100644 gcc/testsuite/gfortran.dg/gomp/metadirective-8.f90 create mode 100644 gcc/testsuite/gfortran.dg/gomp/metadirective-9.f90 create mode 100644 gcc/testsuite/gfortran.dg/gomp/metadirective-construct.f90 create mode 100644 gcc/testsuite/gfortran.dg/gomp/metadirective-no-score.f90 create mode 100644 libgomp/testsuite/libgomp.fortran/metadirective-1.f90 create mode 100644 libgomp/testsuite/libgomp.fortran/metadirective-2.f90 create mode 100644 libgomp/testsuite/libgomp.fortran/metadirective-3.f90 create mode 100644 libgomp/testsuite/libgomp.fortran/metadirective-4.f90 create mode 100644 libgomp/testsuite/libgomp.fortran/metadirective-5.f90 create mode 100644 libgomp/testsuite/libgomp.fortran/metadirective-6.f90 diff --git a/gcc/fortran/decl.cc b/gcc/fortran/decl.cc index b8308aeee55..b6633a913e7 100644 --- a/gcc/fortran/decl.cc +++ b/gcc/fortran/decl.cc @@ -8422,6 +8422,7 @@ gfc_match_end (gfc_statement *st) case COMP_CONTAINS: case COMP_DERIVED_CONTAINS: +case COMP_OMP_BEGIN_METADIRECTIVE: state = gfc_state_stack->previous->state; block_name = gfc_state_stack->previous->sym == NULL ? NULL : gfc_state_stack->previous->sym->name; @@ -8429,6 +8430,28 @@ gfc_match_end (gfc_statement *st) && gfc_state_stack->previous->sym->abr_modproc_decl; break; +case COMP_OMP_METADIRECTIVE: + { + /* Metadirectives can be nested, so we need to drill down to the + first state that is not COMP_OMP_METADIRECTIVE. */ + gfc_state_data *state_data = gfc_state_stack; + + d
[PATCH v3 11/12] OpenMP: Update "declare target"/OpenMP context interaction
The code and test case previously implemented the OpenMP 5.0 spec, which said in section 2.3.1: "For functions within a declare target block, the target trait is added to the beginning of the set..." In OpenMP 5.1, this was changed to "For device routines, the target trait is added to the beginning of the set..." In OpenMP 5.2 and TR12, it says: "For procedures that are determined to be target function variants by a declare target directive..." The definition of "device routine" in OpenMP 5.1 is confusing, but certainly the intent of the later versions of the spec is clear that it doesn't just apply to functions within a begin declare target/end declare target block. The only use of the "omp declare target block" function attribute was to support the 5.0 language, so it can be removed. This patch changes the context augmentation to use the "omp declare target" attribute instead. gcc/c-family/ChangeLog * c-attribs.cc (c_common_gnu_attributes): Delete "omp declare target block". gcc/c/ChangeLog * c-decl.cc (c_decl_attributes): Don't add "omp declare target block". gcc/cp/decl2.cc * decl2.cc (cplus_decl_attributes): Don't add "omp declare target block". gcc/ChangeLog * omp-general.cc (omp_complete_construct_context): Check "omp declare target" attribute, not "omp declare target block". gcc/testsuite/ChangeLog * c-c++-common/gomp/declare-target-indirect-2.c : Adjust expected output for removal of "omp declare target block". * c-c++-common/gomp/declare-variant-8.c: Likewise, the variant call to f20 is now resolved differently. * c-c++-common/gomp/reverse-offload-1.c: Adjust expected output. * gfortran.dg/gomp/declare-variant-8.f90: Likewise, both f18 and f20 now resolve to the variant. Delete obsolete comments. --- gcc/c-family/c-attribs.cc| 2 -- gcc/c/c-decl.cc | 8 ++-- gcc/cp/decl2.cc | 9 ++--- gcc/omp-general.cc | 2 +- .../c-c++-common/gomp/declare-target-indirect-2.c| 10 +- gcc/testsuite/c-c++-common/gomp/declare-variant-8.c | 4 ++-- gcc/testsuite/c-c++-common/gomp/reverse-offload-1.c | 2 +- gcc/testsuite/gfortran.dg/gomp/declare-variant-8.f90 | 12 ++-- 8 files changed, 15 insertions(+), 34 deletions(-) diff --git a/gcc/c-family/c-attribs.cc b/gcc/c-family/c-attribs.cc index f9b229aba7f..7f74c25d3d7 100644 --- a/gcc/c-family/c-attribs.cc +++ b/gcc/c-family/c-attribs.cc @@ -574,8 +574,6 @@ const struct attribute_spec c_common_gnu_attributes[] = handle_omp_declare_target_attribute, NULL }, { "omp declare target nohost", 0, 0, true, false, false, false, handle_omp_declare_target_attribute, NULL }, - { "omp declare target block", 0, 0, true, false, false, false, - handle_omp_declare_target_attribute, NULL }, { "non overlapping", 0, 0, true, false, false, false, handle_non_overlapping_attribute, NULL }, { "alloc_align", 1, 1, false, true, true, false, diff --git a/gcc/c/c-decl.cc b/gcc/c/c-decl.cc index 97f1d346835..e2a62bf2d56 100644 --- a/gcc/c/c-decl.cc +++ b/gcc/c/c-decl.cc @@ -5418,12 +5418,8 @@ c_decl_attributes (tree *node, tree attributes, int flags) attributes = tree_cons (get_identifier ("omp declare target implicit"), NULL_TREE, attributes); else - { - attributes = tree_cons (get_identifier ("omp declare target"), - NULL_TREE, attributes); - attributes = tree_cons (get_identifier ("omp declare target block"), - NULL_TREE, attributes); - } + attributes = tree_cons (get_identifier ("omp declare target"), + NULL_TREE, attributes); if (TREE_CODE (*node) == FUNCTION_DECL) { int device_type diff --git a/gcc/cp/decl2.cc b/gcc/cp/decl2.cc index 6d674684931..da881e9e797 100644 --- a/gcc/cp/decl2.cc +++ b/gcc/cp/decl2.cc @@ -1781,13 +1781,8 @@ cplus_decl_attributes (tree *decl, tree attributes, int flags) = tree_cons (get_identifier ("omp declare target implicit"), NULL_TREE, attributes); else - { - attributes = tree_cons (get_identifier ("omp declare target"), - NULL_TREE, attributes); - attributes - = tree_cons (get_identifier ("omp declare target block"), -NULL_TREE, attributes); - } + attributes = tree_cons (get_identifier ("omp declare target"), + NULL_TREE, attributes); if (TREE_CODE (*decl) == FUNCTION_DECL) {
[PATCH v3 09/12] OpenMP: Extend dynamic selector support to declare variant
This patch extends the mechanisms previously added to support dynamic selectors in metavariant constructs to also apply to "declare variant". The front-end mechanisms used to handle "declare variant" via attributes attached to the function decls remain the same, but the gimplifier now uses the same internal data structures and helper functions as metadirective to score and sort "declare variant" alternatives, and constructs a gomp_metadirective node for variant calls that cannot be resolved at gimplification time. During late resolution, this gomp_metadirective is processed in exactly the same way as for real metadirectives. During implementation of this functionality, a number of bugs were discovered in the previous selector scoring and matching code: * Metadirective resolution was failing to account for scoring in "declare simd" clones, and was also relying on calling a function to match construct constructors that's only useful during gimplification during late resolution long after that pass. * The construct constructor scoring was previously implemented backwards from the specification (PR114596); a number of testcases were also broken in the same way as the implementation. * The special rules for matching simdlen and aligned properties on simd selectors were not implemented (nor were these properties on metadirectives being rejected per the OpenMP spec). This patch includes a new implementation of this functionality that has cleaner interfaces and is hopefully(!) easier to correlate to requirements of the OpenMP specification. Instead of relying on the gimplifier to score construct selectors, the scoring code has been consolidated in omp-general.cc with the gimplifier only providing the OpenMP construct context surrounding the metadirective or variant call. This is cached on the gomp_metadirective if necessary for late resolution. An additional improvement added in this patch is that for both metadirective and "declare variant", if late resolution is required the gimplifier now discards all alternatives that are known not to match. Note that this patch leaves a substantial amount of dead code that was used to support the former late "declare variant" resolution strategy, notably the declare_variant_alt and calls_declare_variant_alt flags on cgraph_node and all the code that touches those fields. The next patch in this series removes that unused code. Another issue not addressed in this patch is the special scoping rules for expressions in "declare variant" dynamic selectors, which is still under discussion in PR113904. We expect this to be fixed separately. gcc/c/ChangeLog * c-parser.c (c_parser_omp_context_selector): Remove metadirective_p parameter and conditionalization. (c_parser_omp_context_selector_specification): Remove metadirective_p parameter and adjust call not to pass it on. (c_finish_omp_declare_variant): Adjust arguments on calls to c_parser_omp_context_selector_specification and omp_context_selector_matches. (c_parser_omp_metadirective): Likewise. gcc/cp/ChangeLog * cp-tree.h (struct saved_scope): Add new field x_processing_omp_trait_property_expr. (processing_omp_trait_property_expr): Define * decl.cc (omp_declare_variant_finalize_one): Adjust arguments to omp_context_selector_matches. * parser.cc (cp_parser_omp_context_selector): Remove metadirective_p argument and conditionalization. (cp_parser_omp_context_selector_specification): Remove metadirective_p argument and adjust call not to pass it on. (cp_finish_omp_declare_variant): Adjust arguments on call to above. (cp_parser_omp_metadirective): Likewise. * pt.cc (tsubst_omp_context_selector): Adjust error behavior. (tsubst_stmt): Adjust call to omp_context_selector_matches. * semantics.cc (finish_id_expression_1): Do not diagnose error for use of parameter in declare variant selector here. gcc/fortran/ChangeLog * trans-openmp.cc (gfc_trans_omp_declare_variant): Adjust arguments to omp_context_selector_matches. (gfc_trans_omp_metadirective): Likewise. gcc/Changelog * gimple-streamer-in.cc (input_gimple_stmt): Restore gomp_metadirective context. * gimple-streamer-out.cc (output_gimple_stmt): Save gomp_metadirective context. * gimple.cc (gimple_build_omp_metadirective): Initialize gomp_metadirective context. * gimple.def (GIMPLE_OMP_METADIRECTIVE): Update comments. * gimple.h (gomp_metadirective): Add context field and update comments. (gimple_omp_metadirective_context): New. (gimple_omp_metadirective_set_context): New. * gimplify.cc (omp_resolved_variant_calls): New. (gimplify_variant_call_expr): New. (gimplify_call_expr): Adjust parameters. Call gimplify_variant_call_expr to handle declar
[PATCH v3 10/12] OpenMP: Remove dead code from declare variant reimplementation
After reimplementing late resolution of "declare variant" to use the same mechanisms as metadirective, the declare_variant_alt and calls_declare_variant_alt flags on struct cgraph_node are no longer used by anything. For the purposes of marking functions that need late resolution, the has_metadirectives flag has replaced calls_declare_variant_alt. Likewise struct omp_declare_variant_entry, struct omp_declare_variant_base_entry, and the hash tables used to store these structures are no longer needed, since the information needed for late resolution is now stored in the gomp_metadirective nodes. There are no functional changes in this patch, just removing dead code. gcc/ChangeLog * cgraph.cc (symbol_table::create_edge): Don't set calls_declare_variant_alt in the caller. * cgraph.h (struct cgraph_node): Remove declare_variant_alt and calls_declare_variant_alt flags. * cgraphclones.cc (cgraph_node::create_clone): Don't copy calls_declare_variant_alt bit. * ipa-free-lang-data.cc (free_lang_data_in_decl): Adjust code referencing declare_variant_alt bit. * ipa.cc (symbol_table::remove_unreachable_nodes): Likewise. * lto-cgraph.cc (lto_output_node): Remove references to deleted bits. (output_refs): Adjust code referencing declare_variant_alt bit. (input_overwrite_node): Remove references to deleted bits. (input_refs): Adjust code referencing declare_variant_alt bit. * lto-streamer-out.cc (lto_output): Likewise. * lto-streamer.h (omp_lto_output_declare_variant_alt): Delete. (omp_lto_input_declare_variant_alt): Delete. * lto/lto-partition.cc (lto_balanced_map): Adjust code referencing deleted declare_variant_alt bit. * omp-expand.cc (expand_omp_target): Use has_metadirectives bit to trigger pass_omp_device_lower instead of calls_declare_variant_alt. * omp-general.cc (struct omp_declare_variant_entry): Delete. (struct omp_declare_variant_base_entry): Delete. (struct omp_declare_variant_hasher): Delete. (omp_declare_variant_hasher::hash): Delete. (omp_declare_variant_hasher::equal): Delete. (omp_declare_variants): Delete. (omp_declare_variant_alt_hasher): Delete. (omp_declare_variant_alt_hasher::hash): Delete. (omp_declare_variant_alt_hasher::equal): Delete. (omp_declare_variant_alt): Delete. (omp_lto_output_declare_variant_alt): Delete. (omp_lto_input_declare_variant_alt): Delete. (includes): Delete unnecessary include of gt-omp-general.h. * omp-offload.cc (execute_omp_device_lower): Remove references to deleted bit. (pass_omp_device_lower::gate): Likewise. * omp-simd-clone.cc (simd_clone_create): Likewise. * passes.cc (ipa_write_summaries): Likeise. * symtab.cc (symtab_node::get_partitioning_class): Likewise. * tree-inline.cc (expand_call_inline): Likewise. (tree_function_versioning): Likewise. --- gcc/cgraph.cc | 2 - gcc/cgraph.h | 11 +- gcc/cgraphclones.cc | 1 - gcc/ipa-free-lang-data.cc | 2 +- gcc/ipa.cc| 3 - gcc/lto-cgraph.cc | 10 -- gcc/lto-streamer-out.cc | 3 +- gcc/lto-streamer.h| 6 -- gcc/lto/lto-partition.cc | 5 +- gcc/omp-expand.cc | 2 +- gcc/omp-general.cc| 217 -- gcc/omp-offload.cc| 8 +- gcc/omp-simd-clone.cc | 2 - gcc/passes.cc | 3 +- gcc/symtab.cc | 2 +- gcc/tree-inline.cc| 4 - 16 files changed, 10 insertions(+), 271 deletions(-) diff --git a/gcc/cgraph.cc b/gcc/cgraph.cc index 473d8410bc9..103bc2c0332 100644 --- a/gcc/cgraph.cc +++ b/gcc/cgraph.cc @@ -931,8 +931,6 @@ symbol_table::create_edge (cgraph_node *caller, cgraph_node *callee, caller->decl); else edge->in_polymorphic_cdtor = caller->thunk; - if (callee) -caller->calls_declare_variant_alt |= callee->declare_variant_alt; if (callee && symtab->state != LTO_STREAMING && edge->callee->comdat_local_p ()) diff --git a/gcc/cgraph.h b/gcc/cgraph.h index 6653ce19c3e..dd210842df7 100644 --- a/gcc/cgraph.h +++ b/gcc/cgraph.h @@ -897,10 +897,8 @@ struct GTY((tag ("SYMTAB_FUNCTION"))) cgraph_node : public symtab_node split_part (false), indirect_call_target (false), local (false), versionable (false), can_change_signature (false), redefined_extern_inline (false), tm_may_enter_irr (false), - ipcp_clone (false), declare_variant_alt (false), - calls_declare_variant_alt (false), gc_candidate (false), - called_by_ifunc_resolver (false), - has_metadirectives (false), + ipcp_clone (false), gc_candidate (false), + called_by_ifunc_resolver (false), has_metadirectives (false), m_uid (uid), m_summary_id (-1)
[PATCH v3 06/12] OpenMP: common c/c++ testcases for metadirectives
gcc/testsuite/ChangeLog * c-c++-common/gomp/attrs-metadirective-1.c: New. * c-c++-common/gomp/attrs-metadirective-2.c: New. * c-c++-common/gomp/attrs-metadirective-3.c: New. * c-c++-common/gomp/attrs-metadirective-4.c: New. * c-c++-common/gomp/attrs-metadirective-5.c: New. * c-c++-common/gomp/attrs-metadirective-6.c: New. * c-c++-common/gomp/attrs-metadirective-7.c: New. * c-c++-common/gomp/attrs-metadirective-8.c: New. * c-c++-common/gomp/metadirective-1.c: New. * c-c++-common/gomp/metadirective-2.c: New. * c-c++-common/gomp/metadirective-3.c: New. * c-c++-common/gomp/metadirective-4.c: New. * c-c++-common/gomp/metadirective-5.c: New. * c-c++-common/gomp/metadirective-6.c: New. * c-c++-common/gomp/metadirective-7.c: New. * c-c++-common/gomp/metadirective-8.c: New. * c-c++-common/gomp/metadirective-construct.c: New. * c-c++-common/gomp/metadirective-device.c: New. * c-c++-common/gomp/metadirective-no-score.c: New. * c-c++-common/gomp/metadirective-target-device.c: New. libgomp/ChangeLog * testsuite/libgomp.c-c++-common/metadirective-1.c: New. * testsuite/libgomp.c-c++-common/metadirective-2.c: New. * testsuite/libgomp.c-c++-common/metadirective-3.c: New. * testsuite/libgomp.c-c++-common/metadirective-4.c: New. * testsuite/libgomp.c-c++-common/metadirective-5.c: New. * testsuite/libgomp.c-c++-common/metadirective-target-device.c: New. Co-Authored-By: Kwok Cheung Yeung Co-Authored-By: Sandra Loosemore --- .../c-c++-common/gomp/attrs-metadirective-1.c | 41 .../c-c++-common/gomp/attrs-metadirective-2.c | 75 .../c-c++-common/gomp/attrs-metadirective-3.c | 32 .../c-c++-common/gomp/attrs-metadirective-4.c | 41 .../c-c++-common/gomp/attrs-metadirective-5.c | 25 +++ .../c-c++-common/gomp/attrs-metadirective-6.c | 32 .../c-c++-common/gomp/attrs-metadirective-7.c | 32 .../c-c++-common/gomp/attrs-metadirective-8.c | 17 ++ .../c-c++-common/gomp/metadirective-1.c | 52 + .../c-c++-common/gomp/metadirective-2.c | 74 .../c-c++-common/gomp/metadirective-3.c | 31 +++ .../c-c++-common/gomp/metadirective-4.c | 40 .../c-c++-common/gomp/metadirective-5.c | 24 +++ .../c-c++-common/gomp/metadirective-6.c | 31 +++ .../c-c++-common/gomp/metadirective-7.c | 31 +++ .../c-c++-common/gomp/metadirective-8.c | 16 ++ .../gomp/metadirective-construct.c| 177 ++ .../c-c++-common/gomp/metadirective-device.c | 147 +++ .../gomp/metadirective-no-score.c | 95 ++ .../gomp/metadirective-target-device.c| 147 +++ .../libgomp.c-c++-common/metadirective-1.c| 35 .../libgomp.c-c++-common/metadirective-2.c| 41 .../libgomp.c-c++-common/metadirective-3.c| 34 .../libgomp.c-c++-common/metadirective-4.c| 52 + .../libgomp.c-c++-common/metadirective-5.c| 46 + .../metadirective-target-device.c | 63 +++ 26 files changed, 1431 insertions(+) create mode 100644 gcc/testsuite/c-c++-common/gomp/attrs-metadirective-1.c create mode 100644 gcc/testsuite/c-c++-common/gomp/attrs-metadirective-2.c create mode 100644 gcc/testsuite/c-c++-common/gomp/attrs-metadirective-3.c create mode 100644 gcc/testsuite/c-c++-common/gomp/attrs-metadirective-4.c create mode 100644 gcc/testsuite/c-c++-common/gomp/attrs-metadirective-5.c create mode 100644 gcc/testsuite/c-c++-common/gomp/attrs-metadirective-6.c create mode 100644 gcc/testsuite/c-c++-common/gomp/attrs-metadirective-7.c create mode 100644 gcc/testsuite/c-c++-common/gomp/attrs-metadirective-8.c create mode 100644 gcc/testsuite/c-c++-common/gomp/metadirective-1.c create mode 100644 gcc/testsuite/c-c++-common/gomp/metadirective-2.c create mode 100644 gcc/testsuite/c-c++-common/gomp/metadirective-3.c create mode 100644 gcc/testsuite/c-c++-common/gomp/metadirective-4.c create mode 100644 gcc/testsuite/c-c++-common/gomp/metadirective-5.c create mode 100644 gcc/testsuite/c-c++-common/gomp/metadirective-6.c create mode 100644 gcc/testsuite/c-c++-common/gomp/metadirective-7.c create mode 100644 gcc/testsuite/c-c++-common/gomp/metadirective-8.c create mode 100644 gcc/testsuite/c-c++-common/gomp/metadirective-construct.c create mode 100644 gcc/testsuite/c-c++-common/gomp/metadirective-device.c create mode 100644 gcc/testsuite/c-c++-common/gomp/metadirective-no-score.c create mode 100644 gcc/testsuite/c-c++-common/gomp/metadirective-target-device.c create mode 100644 libgomp/testsuite/libgomp.c-c++-common/metadirective-1.c create mode 100644 libgomp/testsuite/libgomp.c-c++-common/metadirective-2.c create mode 100644 libgomp/testsuite/libgomp.c-c++-common/metadirective-3.c create mode 100644 libgomp/testsuite/libgomp.c-c
[PATCH v3 05/12] OpenMP: C++ front-end support for metadirectives
This patch adds C++ support for metadirectives. It uses the c-family support committed with the corresponding C front end patch to do early parse-time metadirective resolution when possible. Additional C/C++ common testcases are provided in a subsequent patch in the series. gcc/cp/ChangeLog * parser.cc (cp_parser_skip_to_end_of_block_or_statement): Add metadirective_p parameter, use it to control brace/parentheses behavior for metadirectives. (mangle_metadirective_region_label): New. (cp_parser_label_for_labeled_statement): Use it. (cp_parser_jump_statement): Likewise. (cp_parser_omp_context_selector): Add metadirective_p parameter, use it to control error behavior for non-constant exprs properties. (cp_parser_omp_context_selector_specification): Add metadirective_p parameter, use it for cp_parser_omp_context_selector call. (cp_finish_omp_declare_variant): Adjust call to cp_parser_omp_context_selector_specification. (analyze_metadirective_body): New. (cp_parser_omp_metadirective): New. (cp_parser_pragma): Handle PRAGMA_OMP_METADIRECTIVE. * parser.h (struct cp_parser): Add fields for metadirective parsing state. * pt.cc (tsubst_omp_context_selector): New. (tsubst_stmt): Handle OMP_METADIRECTIVE. libgomp/ChangeLog * testsuite/libgomp.c++/metadirective-template-1.C: New. * testsuite/libgomp.c++/metadirective-template-2.C: New. * testsuite/libgomp.c++/metadirective-template-3.C: New. Co-Authored-By: Kwok Cheung Yeung Co-Authored-By: Sandra Loosemore --- gcc/cp/parser.cc | 524 +- gcc/cp/parser.h | 7 + gcc/cp/pt.cc | 119 .../libgomp.c++/metadirective-template-1.C| 37 ++ .../libgomp.c++/metadirective-template-2.C| 41 ++ .../libgomp.c++/metadirective-template-3.C| 41 ++ 6 files changed, 756 insertions(+), 13 deletions(-) create mode 100644 libgomp/testsuite/libgomp.c++/metadirective-template-1.C create mode 100644 libgomp/testsuite/libgomp.c++/metadirective-template-2.C create mode 100644 libgomp/testsuite/libgomp.c++/metadirective-template-3.C diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index 045b3fe7a5b..d4358ab35a1 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -3003,7 +3003,7 @@ static void cp_parser_skip_to_end_of_statement static void cp_parser_consume_semicolon_at_end_of_statement (cp_parser *); static void cp_parser_skip_to_end_of_block_or_statement - (cp_parser *); + (cp_parser *, bool = false); static bool cp_parser_skip_to_closing_brace (cp_parser *); static bool cp_parser_skip_entire_template_parameter_list @@ -4196,9 +4196,11 @@ cp_parser_consume_semicolon_at_end_of_statement (cp_parser *parser) have consumed a non-nested `;'. */ static void -cp_parser_skip_to_end_of_block_or_statement (cp_parser* parser) +cp_parser_skip_to_end_of_block_or_statement (cp_parser* parser, +bool metadirective_p) { int nesting_depth = 0; + int bracket_depth = 0; /* Unwind generic function template scope if necessary. */ if (parser->fully_implicit_function_template_p) @@ -4220,7 +4222,7 @@ cp_parser_skip_to_end_of_block_or_statement (cp_parser* parser) case CPP_SEMICOLON: /* Stop if this is an unnested ';'. */ - if (!nesting_depth) + if (!nesting_depth && (!metadirective_p || bracket_depth <= 0)) nesting_depth = -1; break; @@ -4239,6 +4241,19 @@ cp_parser_skip_to_end_of_block_or_statement (cp_parser* parser) nesting_depth++; break; + case CPP_OPEN_PAREN: + /* Track parentheses in case the statement is a standalone 'for' +statement - we want to skip over the semicolons separating the +operands. */ + if (metadirective_p && nesting_depth == 0) + bracket_depth++; + break; + + case CPP_CLOSE_PAREN: + if (metadirective_p && nesting_depth == 0) + bracket_depth--; + break; + case CPP_KEYWORD: if (!cp_token_is_module_directive (token)) break; @@ -13021,6 +13036,18 @@ attr_chainon (tree attrs, tree attr) return chainon (attrs, attr); } + +/* Helper function for cp_parser_label: mangle a metadirective region + label NAME. */ +static tree +mangle_metadirective_region_label (cp_parser *parser, tree name) +{ + const char *old_name = IDENTIFIER_POINTER (name); + char *new_name = (char *) alloca (strlen (old_name) + 32); + sprintf (new_name, "%s_MDR%u", old_name, parser->metadirective_region_num); + return get_identifier (new_name); +} + /* Parse the label for a labeled-statement, i.e. label: @@ -13123,7 +13150,12 @@ cp_par
[PATCH v3 12/12] OpenMP: Update documentation of metadirective implementation status.
libgomp/ChangeLog * libgomp.texi (OpenMP 5.0): Mark metadirective and declare variant as implemented. (OpenMP 5.1): Mark target_device as supported. Add changed interaction between declare target and OpenMP context and dynamic selector support. (OpenMP 5.2): Mark otherwise clause as supported, note that default is also still accepted. --- libgomp/libgomp.texi | 21 ++--- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/libgomp/libgomp.texi b/libgomp/libgomp.texi index 4b9459048d1..829e2c87387 100644 --- a/libgomp/libgomp.texi +++ b/libgomp/libgomp.texi @@ -192,9 +192,8 @@ The OpenMP 4.5 specification is fully supported. @item Array shaping @tab N @tab @item Array sections with non-unit strides in C and C++ @tab N @tab @item Iterators @tab Y @tab -@item @code{metadirective} directive @tab N @tab -@item @code{declare variant} directive - @tab P @tab @emph{simd} traits not handled correctly +@item @code{metadirective} directive @tab Y @tab +@item @code{declare variant} directive @tab Y @tab @item @var{target-offload-var} ICV and @code{OMP_TARGET_OFFLOAD} env variable @tab Y @tab @item Nested-parallel changes to @var{max-active-levels-var} ICV @tab Y @tab @@ -289,8 +288,8 @@ The OpenMP 4.5 specification is fully supported. @headitem Description @tab Status @tab Comments @item OpenMP directive as C++ attribute specifiers @tab Y @tab @item @code{omp_all_memory} reserved locator @tab Y @tab -@item @emph{target_device trait} in OpenMP Context @tab N @tab -@item @code{target_device} selector set in context selectors @tab N @tab +@item @emph{target_device trait} in OpenMP Context @tab Y +@item @code{target_device} selector set in context selectors @tab Y @tab @item C/C++'s @code{declare variant} directive: elision support of preprocessed code @tab N @tab @item @code{declare variant}: new clauses @code{adjust_args} and @@ -366,6 +365,12 @@ to address of matching mapped list item per 5.1, Sect. 2.21.7.2 @tab N @tab @item @code{device_type(nohost)}/@code{device_type(host)} for variables @tab N @tab @item @code{present} modifier to the @code{map}, @code{to} and @code{from} clauses @tab Y @tab +@item Changed interaction between @code{declare target} and OpenMP context + @tab Y @tab +@item Dynamic selector support in @code{metadirective} @tab Y @tab +@item Dynamic selector support in @code{declare variant} @tab P + @tab Fortran rejects non-constant expressions in dynamic selectors; + C/C++ reject expressions using argument variables. @end multitable @@ -413,8 +418,10 @@ to address of matching mapped list item per 5.1, Sect. 2.21.7.2 @tab N @tab @item Deprecation of traits array following the allocator_handle expression in @code{uses_allocators} @tab N @tab @item New @code{otherwise} clause as alias for @code{default} on metadirectives - @tab N @tab -@item Deprecation of @code{default} clause on metadirectives @tab N @tab + @tab Y @tab +@item Deprecation of @code{default} clause on metadirectives @tab N + @tab Both @code{otherwise} and @code{default} are accepted + without diagnostics. @item Deprecation of delimited form of @code{declare target} @tab N @tab @item Reproducible semantics changed for @code{order(concurrent)} @tab N @tab @item @code{allocate} and @code{firstprivate} clauses on @code{scope} -- 2.25.1
[PATCH v3 04/12] OpenMP: C front end support for metadirectives
This patch adds support to the C front end to parse OpenMP metadirective constructs. It includes support for early parse-time resolution of metadirectives (when possible) that will also be used by the C++ front end. Additional common C/C++ testcases are in a later patch in the series. gcc/c-family/ChangeLog * c-common.h (enum c_omp_directive_kind): Add C_OMP_DIR_META. (c_omp_expand_metadirective): Declare. * c-gimplify.cc: Include omp-general.h. (genericize_omp_metadirective_stmt): New. (c_genericize_control_stmt): Call it. * c-omp.cc (c_omp_directives): Add "metadirective" and fix commented-out stubs for the begin/end form. (c_omp_expand_metadirective_r): New. (c_omp_expand_metadirective): New. * c-pragma.cc (omp_pragmas): Add "metadirective". * c-pragma.h (enum pragma_kind): Add PRAGMA_OMP_METADIRECTIVE. gcc/c/ChangeLog * c-parser.cc (struct c_parser): Add save_tokens and save_tokens_avail fields for saving lookahead state and fields for metadirective parsing. (c_parser_skip_until_found): Restore state using new fields. (c_parser_skip_to_pragma_eol): Likewise. (c_parser_skip_to_end_of_block_or_statement): Add metadirective_p parameter; use it to control brace and parentheses behavior. (c_parser_handle_statement_omp_attributes): Save state using new c_parser fields. (mangle_metadirective_region_label): New. (c_parser_label, c_parser_statement_after_labels): Use it. (c_parser_pragma): Handle metadirective. (c_parser_omp_context_selector): Add metadirective_p flag, use it to gate support for non-constant user condition. (c_parser_omp_context_selector_specification): Add metadirective_p argument. (c_parser_finish_omp_declare_variant): Adjust call to above. (c_maybe_parse_omp_decl): Save state using new c_parser fields. (analyze_metadirective_body): New. (c_parser_omp_metadirective): New. gcc/testsuite/ChangeLog * gcc.dg/gomp/metadirective-1.c: New. Co-Authored-By: Kwok Cheung Yeung Co-Authored-By: Sandra Loosemore --- gcc/c-family/c-common.h | 4 +- gcc/c-family/c-gimplify.cc | 27 + gcc/c-family/c-omp.cc | 60 ++- gcc/c-family/c-pragma.cc| 1 + gcc/c-family/c-pragma.h | 1 + gcc/c/c-parser.cc | 524 +++- gcc/testsuite/gcc.dg/gomp/metadirective-1.c | 15 + 7 files changed, 605 insertions(+), 27 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/gomp/metadirective-1.c diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h index ccaea27c2b9..588a298a9a2 100644 --- a/gcc/c-family/c-common.h +++ b/gcc/c-family/c-common.h @@ -1399,7 +1399,8 @@ enum c_omp_directive_kind { C_OMP_DIR_CONSTRUCT, C_OMP_DIR_DECLARATIVE, C_OMP_DIR_UTILITY, - C_OMP_DIR_INFORMATIONAL + C_OMP_DIR_INFORMATIONAL, + C_OMP_DIR_META }; struct c_omp_directive { @@ -1413,6 +1414,7 @@ extern const struct c_omp_directive c_omp_directives[]; extern const struct c_omp_directive *c_omp_categorize_directive (const char *, const char *, const char *); +extern tree c_omp_expand_metadirective (vec &); /* Return next tree in the chain for chain_next walking of tree nodes. */ inline tree diff --git a/gcc/c-family/c-gimplify.cc b/gcc/c-family/c-gimplify.cc index 3e29766e092..897c3328f8e 100644 --- a/gcc/c-family/c-gimplify.cc +++ b/gcc/c-family/c-gimplify.cc @@ -43,6 +43,7 @@ along with GCC; see the file COPYING3. If not see #include "context.h" #include "tree-pass.h" #include "internal-fn.h" +#include "omp-general.h" /* The gimplification pass converts the language-dependent trees (ld-trees) emitted by the parser into language-independent trees @@ -485,6 +486,27 @@ genericize_omp_for_stmt (tree *stmt_p, int *walk_subtrees, void *data, finish_bc_block (&OMP_FOR_BODY (stmt), bc_continue, clab); } +/* Genericize a OMP_METADIRECTIVE node *STMT_P. */ + +static void +genericize_omp_metadirective_stmt (tree *stmt_p, int *walk_subtrees, + void *data, walk_tree_fn func, + walk_tree_lh lh) +{ + tree stmt = *stmt_p; + + for (tree variant = OMP_METADIRECTIVE_VARIANTS (stmt); + variant != NULL_TREE; + variant = TREE_CHAIN (variant)) +{ + walk_tree_1 (&OMP_METADIRECTIVE_VARIANT_DIRECTIVE (variant), + func, data, NULL, lh); + walk_tree_1 (&OMP_METADIRECTIVE_VARIANT_BODY (variant), + func, data, NULL, lh); +} + + *walk_subtrees = 0; +} /* Lower structured control flow tree
[PATCH v3 08/12] OpenMP: Reject other properties with kind(any)
The OpenMP spec says: "If trait-property any is specified in the kind trait-selector of the device selector set or the target_device selector sets, no other trait-property may be specified in the same selector set." GCC was not previously enforcing this restriction and several testcases included such valid constructs. This patch fixes it. gcc/ChangeLog * omp-general.cc (omp_check_context_selector): Reject other properties in the same selector set with kind(any). gcc/testsuite/ChangeLog * c-c++-common/gomp/declare-variant-10.c: Fix broken tests. * c-c++-common/gomp/declare-variant-3.c: Likewise. * c-c++-common/gomp/declare-variant-9.c: Likewise. * c-c++-common/gomp/declare-variant-any.c: New. * gfortran.dg/gomp/declare-variant-10.f90: Fix broken tests. * gfortran.dg/gomp/declare-variant-3.f90: Likewise. * gfortran.dg/gomp/declare-variant-9.f90: Likewise. * gfortran.dg/gomp/declare-variant-any.f90: Likewise. --- gcc/omp-general.cc| 31 +++ .../c-c++-common/gomp/declare-variant-10.c| 4 +-- .../c-c++-common/gomp/declare-variant-3.c | 10 ++ .../c-c++-common/gomp/declare-variant-9.c | 4 +-- .../c-c++-common/gomp/declare-variant-any.c | 10 ++ .../gfortran.dg/gomp/declare-variant-10.f90 | 4 +-- .../gfortran.dg/gomp/declare-variant-3.f90| 12 ++- .../gfortran.dg/gomp/declare-variant-9.f90| 2 +- .../gfortran.dg/gomp/declare-variant-any.f90 | 28 + 9 files changed, 82 insertions(+), 23 deletions(-) create mode 100644 gcc/testsuite/c-c++-common/gomp/declare-variant-any.c create mode 100644 gcc/testsuite/gfortran.dg/gomp/declare-variant-any.f90 diff --git a/gcc/omp-general.cc b/gcc/omp-general.cc index 87a245ec8b3..12f178c5a2d 100644 --- a/gcc/omp-general.cc +++ b/gcc/omp-general.cc @@ -1288,6 +1288,8 @@ omp_check_context_selector (location_t loc, tree ctx, bool metadirective_p) for (tree tss = ctx; tss; tss = TREE_CHAIN (tss)) { enum omp_tss_code tss_code = OMP_TSS_CODE (tss); + bool saw_any_prop = false; + bool saw_other_prop = false; /* FIXME: not implemented yet. */ if (!metadirective_p && tss_code == OMP_TRAIT_SET_TARGET_DEVICE) @@ -1325,6 +1327,27 @@ omp_check_context_selector (location_t loc, tree ctx, bool metadirective_p) else ts_seen[ts_code] = true; + + /* If trait-property "any" is specified in the "kind" +trait-selector of the "device" selector set or the +"target_device" selector sets, no other trait-property +may be specified in the same selector set. */ + if (ts_code == OMP_TRAIT_DEVICE_KIND) + for (tree p = OMP_TS_PROPERTIES (ts); p; p = TREE_CHAIN (p)) + { + const char *prop = omp_context_name_list_prop (p); + if (!prop) + continue; + else if (strcmp (prop, "any") == 0) + saw_any_prop = true; + else + saw_other_prop = true; + } + else if (ts_code == OMP_TRAIT_DEVICE_ARCH + || ts_code == OMP_TRAIT_DEVICE_ISA + || ts_code == OMP_TRAIT_DEVICE_NUM) + saw_other_prop = true; + if (omp_ts_map[ts_code].valid_properties == NULL) continue; @@ -1377,6 +1400,14 @@ omp_check_context_selector (location_t loc, tree ctx, bool metadirective_p) break; } } + + if (saw_any_prop && saw_other_prop) + { + error_at (loc, + "no other trait-property may be specified " + "in the same selector set with %"); + return error_mark_node; + } } return ctx; } diff --git a/gcc/testsuite/c-c++-common/gomp/declare-variant-10.c b/gcc/testsuite/c-c++-common/gomp/declare-variant-10.c index 2b8a39425b1..e77693430d1 100644 --- a/gcc/testsuite/c-c++-common/gomp/declare-variant-10.c +++ b/gcc/testsuite/c-c++-common/gomp/declare-variant-10.c @@ -7,7 +7,7 @@ void f01 (void); #pragma omp declare variant (f01) match (device={isa(avx512f,avx512bw)}) void f02 (void); void f03 (void); -#pragma omp declare variant (f03) match (device={kind("any"),arch(x86_64),isa(avx512f,avx512bw)}) +#pragma omp declare variant (f03) match (device={arch(x86_64),isa(avx512f,avx512bw)}) void f04 (void); void f05 (void); #pragma omp declare variant (f05) match (device={kind(gpu)}) @@ -28,7 +28,7 @@ void f15 (void); #pragma omp declare variant (f15) match (device={isa(sse4,ssse3),arch(i386)}) void f16 (void); void f17 (void); -#pragma omp declare variant (f17) match (device={kind(any,fpga)}) +#pragma omp declare variant (f17) match (device={kind(fpga)}) void f18 (void); #pragma omp declare target diff --git a/gcc/testsuite/c-c++-common/gomp/declare-variant-3.c b/gcc/testsuite/c-c++-common/gomp/declare-variant-3.c index f5
[PATCH v3 02/12] OpenMP: middle-end support for metadirectives
This patch adds middle-end support for OpenMP metadirectives. Some context selectors can be resolved during gimplification, but others need to be deferred until the omp_device_lower pass, which requires that cgraph, LTO streaming, inlining, etc all know about this construct as well. gcc/ChangeLog * cgraph.h (struct cgraph_node): Add has_metadirectives flag. * cgraphclones.cc (cgraph_node::create_clone): Copy has_metadirectives flag. * doc/gimple.texi (Class hierarchy of GIMPLE statements): Document gomp_metadirective and gomp_variant. * gimple-low.cc (lower_omp_metadirective): New. (lower_stmt): Call it. * gimple-pretty-print.cc (dump_gimple_omp_metadirective): New. (pp_gimple_stmt_1): Call it. * gimple-streamer-in.cc (input_gimple_stmt): Handle GIMPLE_OMP_METADIRECTIVE. * gimple-streamer-out.cc (output_gimple_stmt): Likewise. * gimple-walk.cc (walk_gimple_op): Likewise. (walk_gimple_stmt): Likewise. * gimple.cc (gimple_alloc_omp_metadirective): New. (gimple_build_omp_metadirective): New. (gimple_build_omp_variant): New. * gimple.def (GIMPLE_OMP_METADIRECTIVE): New. (GIMPLE_OMP_METADIRECTIVE_VARIANT): New. * gimple.h (gomp_variant, gomp_metadirective): New. (is_a_helper ::test): New. (is_a_helper ::test): New. (is_a_helper ::test): New. (is_a_helper ::test): New. (gimple_alloc_omp_metadirective): New. (gimple_build_omp_metadirective): New. (gimple_build_omp_variant): New. (gimple_has_substatements): Handle GIMPLE_OMP_METADIRECTIVE. (gimple_has_ops): Likewise. (gimple_omp_metadirective_label): New. (gimple_omp_metadirective_set_label): New. (gimple_omp_variants): New. (gimple_omp_metadirective_set_variants): New. (gimple_return_set_retval): Handle GIMPLE_OMP_METADIRECTIVE. * gimplify.cc (is_gimple_stmt): HANDLE OMP_METADIRECTIVE. (expand_omp_metadirective): New. (gimplify_omp_metadirective): New. (gimplify_expr): Call it. * gsstruct.def (GSS_OMP_METADIRECTIVE): New. (GSS_OMP_METADIRECTIVE_VARIANT): New. * lto-cgraph.cc (lto_output_node): Handle has_metadirectives flag. (input_overwrite_node): Likewise. * omp-expand.cc (expand_omp_target): Propagate has_metadirectives flag. (build_omp_regions_1): Handle GIMPLE_OMP_METADIRECTIVE. (omp_make_gimple_edges): Likewise. * omp-general.cc (omp_late_resolve_metadirective): New. * omp-general.h (omp_late_resolve_metadirective): Declare. * omp-low.cc (struct omp_context): Add next_clone field. (new_omp_context): Handle next_clone field. (clone_omp_context): New. (delete_omp_context): Delete clones. (create_omp_child_function): Propagate has_metadirectives bit. (scan_omp_metadirective): New. (scan_omp_1_stmt): Handle GIMPLE_OMP_METADIRECTIVE. (lower_omp_metadirective): New. (lower_omp_1): Handle GIMPLE_OMP_METADIRECTIVE. Warn about direct calls to offloadable functions containing metadirectives. * omp-offload.cc: Include cfganal.h and cfghooks.h. (omp_expand_metadirective): New. (execute_omp_device_lower): Handle metadirectives. (pass_omp_device_lower::gate): Check has_metadirectives bit. * omp-simd-clone.cc (simd_clone_create): Propagate has_metadirectives flag. * tree-cfg.cc (cleanup_dead_labels): Handle GIMPLE_OMP_METADIRECTIVE. (gimple_redirect_edge_and_branch): Likewise. * tree-inline.cc (remap_gimple_stmt): Handle GIMPLE_OMP_METADIRECTIVE. (estimate_num_instructions): Likewise. (expand_call_inline): Propagate has_metadirectives flag. (tree_function_versioning): Likewise. * tree-nested.cc (convert_nonlocal_reference_stmt): Handle GIMPLE_OMP_METADIRECTIVE specially. (convert_local_reference_stmt): Likewise. (convert_tramp_reference_stmt): Likewise. (convert_gimple_call): Likewise. * tree-ssa-operands.cc: Include omp-general.h. (operands_scanner::parse_ssa_operands): Handle GIMPLE_OMP_METADIRECTIVE. Co-Authored-By: Kwok Cheung Yeung Co-Authored-By: Sandra Loosemore Co-Authored-By: Marcel Vollweiler --- gcc/cgraph.h | 3 + gcc/cgraphclones.cc| 1 + gcc/doc/gimple.texi| 6 ++ gcc/gimple-low.cc | 36 gcc/gimple-pretty-print.cc | 78 gcc/gimple-streamer-in.cc | 10 ++ gcc/gimple-streamer-out.cc | 6 ++ gcc/gimple-walk.cc | 28 ++ gcc/gimple.cc | 35 +++ gcc/gimple.def | 7 ++ gcc/gimple.h | 100 +++- gcc/gimplify.cc| 184 + gcc/gsstruct.def
[PATCH v3 03/12] libgomp: runtime support for target_device selector
This patch implements the libgomp runtime support for the dynamic target_device selector via the GOMP_evaluate_target_device function. include/ChangeLog * cuda/cuda.h (CUdevice_attribute): Add definitions for CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR and CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MINOR. libgomp/ChangeLog * Makefile.am (libgomp_la_SOURCES): Add selector.c. * Makefile.in: Regenerate. * config/gcn/selector.c: New. * config/linux/selector.c: New. * config/linux/x86/selector.c: New. * config/nvptx/selector.c: New. * libgomp-plugin.h (GOMP_OFFLOAD_evaluate_device): New. * libgomp.h (struct gomp_device_descr): Add evaluate_device_func field. * libgomp.map (GOMP_5.1.3): New, add GOMP_evaluate_target_device. * libgomp.texi (OpenMP Context Selectors): Document dynamic selector matching of kind/arch/isa. * libgomp_g.h (GOMP_evaluate_current_device): New. (GOMP_evaluate_target_device): New. * oacc-host.c (host_evaluate_device): New. (host_openacc_exec): Initialize evaluate_device_func field to host_evaluate_device. * plugin/plugin-gcn.c (gomp_match_selectors): New. (gomp_match_isa): New. (GOMP_OFFLOAD_evaluate_device): New. * plugin/plugin-nvptx.c (struct ptx_device): Add compute_major and compute_minor fields. (nvptx_open_device): Read compute capability information from device. (gomp_match_selectors): New. (gomp_match_selector): New. (CHECK_ISA): New macro. (GOMP_OFFLOAD_evaluate_device): New. * selector.c: New. * target.c (GOMP_evaluate_target_device): New. (gomp_load_plugin_for_device): Load evaluate_device plugin function. Co-Authored-By: Kwok Cheung Yeung Co-Authored-By: Sandra Loosemore --- include/cuda/cuda.h | 2 + libgomp/Makefile.am | 2 +- libgomp/Makefile.in | 5 +- libgomp/config/gcn/selector.c | 102 +++ libgomp/config/linux/selector.c | 65 + libgomp/config/linux/x86/selector.c | 406 libgomp/config/nvptx/selector.c | 77 ++ libgomp/libgomp-plugin.h| 2 + libgomp/libgomp.h | 1 + libgomp/libgomp.map | 5 + libgomp/libgomp.texi| 18 +- libgomp/libgomp_g.h | 8 + libgomp/oacc-host.c | 11 + libgomp/plugin/plugin-gcn.c | 52 libgomp/plugin/plugin-nvptx.c | 82 ++ libgomp/selector.c | 64 + libgomp/target.c| 22 ++ 17 files changed, 918 insertions(+), 6 deletions(-) create mode 100644 libgomp/config/gcn/selector.c create mode 100644 libgomp/config/linux/selector.c create mode 100644 libgomp/config/linux/x86/selector.c create mode 100644 libgomp/config/nvptx/selector.c create mode 100644 libgomp/selector.c diff --git a/include/cuda/cuda.h b/include/cuda/cuda.h index 804d08ca57e..81545c2ebef 100644 --- a/include/cuda/cuda.h +++ b/include/cuda/cuda.h @@ -83,6 +83,8 @@ typedef enum { CU_DEVICE_ATTRIBUTE_MAX_THREADS_PER_MULTIPROCESSOR = 39, CU_DEVICE_ATTRIBUTE_ASYNC_ENGINE_COUNT = 40, CU_DEVICE_ATTRIBUTE_UNIFIED_ADDRESSING = 41, + CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR = 75, + CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MINOR = 76, CU_DEVICE_ATTRIBUTE_MAX_REGISTERS_PER_MULTIPROCESSOR = 82, CU_DEVICE_ATTRIBUTE_PAGEABLE_MEMORY_ACCESS = 88 } CUdevice_attribute; diff --git a/libgomp/Makefile.am b/libgomp/Makefile.am index 855f0affddf..ba2dd0bb3c2 100644 --- a/libgomp/Makefile.am +++ b/libgomp/Makefile.am @@ -70,7 +70,7 @@ libgomp_la_SOURCES = alloc.c atomic.c barrier.c critical.c env.c error.c \ target.c splay-tree.c libgomp-plugin.c oacc-parallel.c oacc-host.c \ oacc-init.c oacc-mem.c oacc-async.c oacc-plugin.c oacc-cuda.c \ priority_queue.c affinity-fmt.c teams.c allocator.c oacc-profiling.c \ - oacc-target.c target-indirect.c + oacc-target.c target-indirect.c selector.c include $(top_srcdir)/plugin/Makefrag.am diff --git a/libgomp/Makefile.in b/libgomp/Makefile.in index da902f3daca..b5d704992fc 100644 --- a/libgomp/Makefile.in +++ b/libgomp/Makefile.in @@ -219,7 +219,7 @@ am_libgomp_la_OBJECTS = alloc.lo atomic.lo barrier.lo critical.lo \ oacc-parallel.lo oacc-host.lo oacc-init.lo oacc-mem.lo \ oacc-async.lo oacc-plugin.lo oacc-cuda.lo priority_queue.lo \ affinity-fmt.lo teams.lo allocator.lo oacc-profiling.lo \ - oacc-target.lo target-indirect.lo $(am__objects_1) + oacc-target.lo target-indirect.lo selector.lo $(am__objects_1) libgomp_la_OBJECTS = $(am_libgomp_la_OBJECTS) AM_V_P = $(am__v_P_@AM_V@) am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) @@ -552,7 +552,7 @@ libgomp_la_SOURCES = alloc.c atomic.c barrier.c critical.c env.c \ oacc-parallel.c oacc
[PATCH v3 01/12] OpenMP: metadirective tree data structures and front-end interfaces
This patch adds the OMP_METADIRECTIVE tree node and shared tree-level support for manipulating metadirectives. It defines/exposes interfaces that will be used in subsequent patches that add front-end and middle-end support, but nothing generates these nodes yet. This patch also adds compile-time support for dynamic context selectors (the target_device selector set and the condition selector of the user selector set) for metadirectives only. The "declare variant" directive still supports only static selectors. gcc/ChangeLog * Makefile.in (GTFILES): Move omp-general.h earlier in the list. * builtin-types.def (BT_FN_BOOL_INT_CONST_PTR_CONST_PTR_CONST_PTR): New. * doc/generic.texi (OpenMP): Document OMP_METADIRECTIVE and context selector interfaces. * omp-builtins.def (BUILT_IN_GOMP_EVALUATE_TARGET_DEVICE): New. * omp-general.cc (omp_check_context_selector): Add metadirective_p parameter, use it to conditionalize target_device support. (make_omp_metadirective_variant): New. (omp_context_selector_matches): Add metadirective_p and delay_p parameters, use them to control things that can only be matched late. Handle OMP_TRAIT_SET_TARGET_DEVICE. (score_wide_int): Move definition to omp-general.h. (omp_encode_kind_arch_isa_props): New. (omp_dynamic_cond): New. (omp_context_compute_score): Handle OMP_TRAIT_SET_TARGET_DEVICE. (omp_resolve_late_declare_variant, omp_resolve_declare_variant): Adjust calls to omp_context_selector_matches. (sort_variant): New. (omp_get_dynamic_candidates): New. (omp_early_resolve_metadirective): New. * omp-general.h (score_wide_int): Moved here from omp-general.cc. (struct omp_variant): New. (OMP_METADIRECTIVE_VARIANT_SELECTOR): New. (OMP_METADIRECTIVE_VARIANT_DIRECTIVE): New. (OMP_METADIRECTIVE_VARIANT_BODY): New. (make_omp_metadirective_variant): Declare. (omp_check_context_selector): Adjust to match definition. (omp_context_selector_matches): Likewise. (omp_early_resolve_metadirective): New. * tree-pretty-print.cc (dump_omp_context_selector): Remove static qualifier. (dump_generic_node): Handle OMP_METADIRECTIVE. * tree-pretty-print.h (dump_omp_context_selector): Declare. * tree.def (OMP_METADIRECTIVE): New. * tree.h (OMP_METADIRECTIVE_VARIANTS): New. gcc/c/ChangeLog * c-parser.cc (c_finish_omp_declare_variant): Update calls to omp_check_context_selector and omp_context_selector_matches. gcc/cp/ChangeLog * decl.cc (omp_declare_variant_finalize_one): Update call to omp_context_selector_matches to pass additional arguments. * parser.cc (cp_finish_omp_declare_variant): Likewise for omp_check_context_selector. gcc/fortran/ChangeLog * trans-openmp.cc (gfc_trans_omp_declare_variant): Update calls to omp_check_context_selector and omp_context_selector_matches. * types.def (BT_FN_BOOL_INT_CONST_PTR_CONST_PTR_CONST_PTR): New. Co-Authored-By: Kwok Cheung Yeung Co-Authored-By: Sandra Loosemore --- gcc/Makefile.in | 2 +- gcc/builtin-types.def | 2 + gcc/c/c-parser.cc | 4 +- gcc/cp/decl.cc | 2 +- gcc/cp/parser.cc| 2 +- gcc/doc/generic.texi| 32 gcc/fortran/trans-openmp.cc | 4 +- gcc/fortran/types.def | 2 + gcc/omp-builtins.def| 3 + gcc/omp-general.cc | 364 ++-- gcc/omp-general.h | 31 ++- gcc/tree-pretty-print.cc| 36 +++- gcc/tree-pretty-print.h | 2 + gcc/tree.def| 6 + gcc/tree.h | 3 + 15 files changed, 468 insertions(+), 27 deletions(-) diff --git a/gcc/Makefile.in b/gcc/Makefile.in index f4bb4a88cf3..55641fffcaa 100644 --- a/gcc/Makefile.in +++ b/gcc/Makefile.in @@ -2880,6 +2880,7 @@ GTFILES = $(CPPLIB_H) $(srcdir)/input.h $(srcdir)/coretypes.h \ $(srcdir)/tree-ssa-operands.h \ $(srcdir)/tree-profile.cc $(srcdir)/tree-nested.cc \ $(srcdir)/omp-offload.h \ + $(srcdir)/omp-general.h \ $(srcdir)/omp-general.cc \ $(srcdir)/omp-low.cc \ $(srcdir)/targhooks.cc $(out_file) $(srcdir)/passes.cc \ @@ -2906,7 +2907,6 @@ GTFILES = $(CPPLIB_H) $(srcdir)/input.h $(srcdir)/coretypes.h \ $(srcdir)/ipa-strub.cc \ $(srcdir)/internal-fn.h \ $(srcdir)/calls.cc \ - $(srcdir)/omp-general.h \ $(srcdir)/analyzer/analyzer-language.cc \ @all_gtfiles@ diff --git a/gcc/builtin-types.def b/gcc/builtin-types.def index c97d6bad1de..605a38ab84d 100644 --- a/gcc/builtin-types.def +++ b/gcc/builtin-types.def @@ -878,6 +878,8 @@ DEF_FUNCTION_TYPE_4 (BT_FN_VOID_UINT_PTR_INT_PTR, BT_VOID, BT_INT, BT_PTR, BT_INT, BT_PTR) DEF_FUNCTION_TYPE_4 (BT_FN_BOOL_UINT_UINT
[PATCH v3 00/12] Metadirective support + "declare variant" improvements
This is a revised version of the patch set I last posted in late May: https://gcc.gnu.org/pipermail/gcc-patches/2024-May/653066.html Aside from rebasing the patch set so it applies cleanly to mainline head again, I incorporated a few small code cleanups and testsuite fixes I'd collected, plus a few more substantive improvements: - I changed the metadirective pretty-printers to use "otherwise" instead of the now-deprecated "default" clause, as Tobias suggested in his review of the previous version of part 1, and made corresponding tweaks to the test cases that were examining the dump output. - I also re-did the device_num support for the target_device selector along the lines suggested by Tobias (simplifying the libgomp support and adding a conditional to the generated code), and added a new testcase for that. - When I was working on something else I observed that the C front end now has support for attribute-syntax directives; when I originally implemented that for metadirectives on the OG13 branch about a year ago, only C++ had general support for attribute syntax. My C++ testcases failed to "just work" in C because the lookahead save/restore mechanism for attribute directives collided with the token caching used by metadirective for parsing the body. So I fixed that, now the testcases work in both languages. Also note the lists of improvements and bug fixes for previous versions of the patch set, which I won't duplicate here. I realize this is a large and complicated patch set with many dependencies between the pieces (and I have another layer on top of this in the works to support "begin declare variant"). If the maintainers would find it easier to review if I refactored the pieces in some other way, please let me know what would help to expedite the process. I'd really like to get these patches in somehow or another, so I don't have to continue to spend so much time maintaining them out of tree. :-S -Sandra Sandra Loosemore (12): OpenMP: metadirective tree data structures and front-end interfaces OpenMP: middle-end support for metadirectives libgomp: runtime support for target_device selector OpenMP: C front end support for metadirectives OpenMP: C++ front-end support for metadirectives OpenMP: common c/c++ testcases for metadirectives OpenMP: Fortran front-end support for metadirectives. OpenMP: Reject other properties with kind(any) OpenMP: Extend dynamic selector support to declare variant OpenMP: Remove dead code from declare variant reimplementation OpenMP: Update "declare target"/OpenMP context interaction OpenMP: Update documentation of metadirective implementation status. gcc/Makefile.in |2 +- gcc/builtin-types.def |2 + gcc/c-family/c-attribs.cc |2 - gcc/c-family/c-common.h |4 +- gcc/c-family/c-gimplify.cc| 27 + gcc/c-family/c-omp.cc | 60 +- gcc/c-family/c-pragma.cc |1 + gcc/c-family/c-pragma.h |1 + gcc/c/c-decl.cc |8 +- gcc/c/c-parser.cc | 508 +++- gcc/cgraph.cc |2 - gcc/cgraph.h | 12 +- gcc/cgraphclones.cc |2 +- gcc/cp/cp-tree.h |2 + gcc/cp/decl.cc|2 +- gcc/cp/decl2.cc |9 +- gcc/cp/parser.cc | 526 - gcc/cp/parser.h |7 + gcc/cp/pt.cc | 120 + gcc/cp/semantics.cc |3 +- gcc/doc/generic.texi | 32 + gcc/doc/gimple.texi |6 + gcc/fortran/decl.cc | 29 + gcc/fortran/dump-parse-tree.cc| 21 + gcc/fortran/gfortran.h| 21 +- gcc/fortran/io.cc |2 +- gcc/fortran/match.h |2 + gcc/fortran/openmp.cc | 294 ++- gcc/fortran/parse.cc | 578 +++-- gcc/fortran/parse.h |8 +- gcc/fortran/resolve.cc|6 + gcc/fortran/st.cc |4 + gcc/fortran/symbol.cc | 25 +- gcc/fortran/trans-decl.cc |5 +- gcc/fortran/trans-openmp.cc | 238 +- gcc/fortran/trans-stmt.h |1 + gcc/fortran/trans.cc |1 + gcc/fortran/types.def |2 + gcc/gimple-low.cc | 36 + gcc/gimple-
Re: [PATCH v2 01/12] OpenMP: metadirective tree data structures and front-end interfaces
On 7/16/24 06:53, Tobias Burnus wrote: Question: Is now everything clear - or are you still confused by my writing? Well, I still do not understand why backward compatibility concerns specific to some other directive should affect the ABI for a new directive that does not have any current libgomp runtime support, but I suggest that in the interest of efficiently moving forward with this you just tell me what ABI you want me to implement and I will re-do the code that way. I *thought* I had followed your previous suggestion in the current version of the patches, but apparently I guessed wrong, so I'd appreciate it if you were more explicit about exactly what the compiler/runtime interface should be, and if there are specific things that should be happening in either the generated code or the runtime, you make it clear what goes in which side of the interface. -Sandra
Re: [PATCH v2 01/12] OpenMP: metadirective tree data structures and front-end interfaces
On 5/31/24 06:22, Tobias Burnus wrote: I have to admit that I don't really see the use of metadirective_p as … int -omp_context_selector_matches (tree ctx) +omp_context_selector_matches (tree ctx, bool metadirective_p, bool delay_p) ... + if (metadirective_p && delay_p) + return -1; I do see why the resolution of KIND/ARCH/ISA should be delayed – for both variant/metadirective as long as the code is run by the host and the device. Except that we could exclude, e.g., 'kind(FPGA)' early on as we don't support it at all. But once the device code is split off, I don't see why we can't expand the DEVICE clause right away for both variant and metadirective – while for 'target_device', we cannot do much until runtime – except of excluding things like 'kind(fpga)' – or excluding all 'arch' known not to be supported neither by the host nor by any enabled offload devices. Thus, I see why there is a 'delay_p', but not why there is a 'metadirective_p'. But I might have missed something important ... Yeah, omp_context_selector_matches() is pretty substantially revised in part 9 of the posted patch set -- among other things, to remove the metadirective_p parameter. The current split between patches isn't ideal but this is such a huge patch set already (with more pieces in the works to support "begin declare variant") that refactoring them would be a lot of work and probably result in something even more challenging to review. :-S case OMP_TRAIT_USER_CONDITION: if (set == OMP_TRAIT_SET_USER) for (tree p = OMP_TS_PROPERTIES (ts); p; p = TREE_CHAIN (p)) if (OMP_TP_NAME (p) == NULL_TREE) { + /* OpenMP 5.1 allows non-constant conditions for + metadirectives. */ + if (metadirective_p + && !tree_fits_shwi_p (OMP_TP_VALUE (p))) + break; if (integer_zerop (OMP_TP_VALUE (p))) return 0; if (integer_nonzerop (OMP_TP_VALUE (p))) break; ret = -1; } (BTW: I am happy to be enlightened as I likely have miss some fine print.) Regarding the comment: True, but shouldn't this be handled before by issuing an error when such a clause is used in 'declare variant', i.e. only occur when metadirective_p is/can be true? The error diagnostic is handled during parsing in the respective front ends (parts 4, 5, and 7 of the series). Besides, I have to admit that I do not understand the new code. The current code has: constant zero → whole selector known to be false ("return 0"); nonzero constant → keep current state, i.e. either 'true' (1) or don't known ('-1') and continue; otherwise (not const) → set to "don't know" (-1) and continue with the next item. That seems to make also sense for metadirectives. But your patch changes this to keep current state if a variable. In that case, '1' is used if this is the only item or the previous condition is true. Or "-1" when the previous item is "don't know" (-1). - I think that doesn't make sense and it should always return -1 for a run time value. -1 doesn't really mean "don't know". It means "don't know YET". For the purposes of omp_context_selector_matches, a dynamic selector always matches in the sense that they all need to be included in the list of replacement candidates. Additionally, I wonder why you use tree_fits_shwi_p instead of a simple 'TREE_CODE (OMP_TP_VALUE (p)) != INTEGER_CST'. It does not seem to matter here, but '(uint128_t)-1' looks like a valid condition and valid constant, which integer_nonzerop should handled but if the hwi is 128bit wide, it won't fit into a signed variable. (As integer_nonzerop and the current code both do "break;" it won't change the result of the current code.) The existing code for parsing "declare variant" context selectors already uses tree_fits_shwi_p. (See e.g. c_parser_omp_context_selector in gcc/c/c-parser.cc.) If there's a better idiom for checking for a constant I'll certainly use it, but I was trying to be consistent with what I thought was standard practice already. :-S * * * +static tree +omp_dynamic_cond (tree ctx) +{ ... + /* The user condition is not dynamic if it is constant. */ + if (!tree_fits_shwi_p (TREE_VALUE (expr_list))) Any reason for using tree_fits_shwi_p instead of INTEGER_CST? Here, (uint128_t)-1 could make a difference … Same here. + /* omp_initial_device is -1, omp_invalid_device is -4; choose + a value that isn't otherwise defined to indicate the default + device. */ + device_num = build_int_cst (integer_type_node, -2); Don't do this - we do it differently for 'target' and it should do the same. Some value usage history: Wait, in your January review comments on an earlier version of this patch y
Re: gcc: docs: Fix documentation of two hooks
On 7/1/24 11:39, Matthew Malcomson wrote: Ping plus some extra people on Cc since I wasn't sure who to ask for review. (Adding maintainers for `middle-end` plus Richard S). gcc/ChangeLog: * doc/tm.texi (function_attribute_inlinable_p, unspec_may_trap_p): Update documentation. * target.def (function_attribute_inlinable_p, unspec_may_trap_p): Update documentation. I have no particular knowledge of these target hooks, but doc/tm.texi is a generated file that is created by sucking the doc strings in target.def into the skeleton in doc/tm.texi.in. You should not be editing it directly to update for changed target hooks, just regenerating it. If that's what you already did, your ChangeLog should just indicate that you did so instead of mentioning specific things you changed, like: * doc/tm.texi: Regenerated. -Sandra
[PATCH, obvious] Fix PR c/115587, uninitialized variable in c_parser_omp_loop_nest
This function had a reference to an uninitialized variable on the error path. The problem was diagnosed by clang but not gcc. It seems the cleanest solution is to initialize all the loop-clause variables at the point of declaration rather than at different places in the code. The C++ front end didn't have this problem, but I've made similar changes there to keep the code in sync. gcc/c/ChangeLog: PR c/115587 * c-parser.cc (c_parser_omp_loop_nest): Move initializations to point of declaration. gcc/cp/ChangeLog: PR c/115587 * parser.cc (cp_parser_omp_loop_nest): Move initializations to point of declaration. --- gcc/c/c-parser.cc | 4 +--- gcc/cp/parser.cc | 8 ++-- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc index e83e9c683f7..33643ec910a 100644 --- a/gcc/c/c-parser.cc +++ b/gcc/c/c-parser.cc @@ -22430,7 +22430,7 @@ static tree c_parser_omp_unroll (location_t, c_parser *, bool *); static tree c_parser_omp_loop_nest (c_parser *parser, bool *if_p) { - tree decl, cond, incr, init; + tree decl = NULL_TREE, cond = NULL_TREE, incr = NULL_TREE, init = NULL_TREE; tree body = NULL_TREE; matching_parens parens; bool moreloops; @@ -22619,7 +22619,6 @@ c_parser_omp_loop_nest (c_parser *parser, bool *if_p) } /* Parse the loop condition. */ - cond = NULL_TREE; if (c_parser_next_token_is_not (parser, CPP_SEMICOLON)) { location_t cond_loc = c_parser_peek_token (parser)->location; @@ -22652,7 +22651,6 @@ c_parser_omp_loop_nest (c_parser *parser, bool *if_p) c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); /* Parse the increment expression. */ - incr = NULL_TREE; if (c_parser_next_token_is_not (parser, CPP_CLOSE_PAREN)) { location_t incr_loc = c_parser_peek_token (parser)->location; diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index e7409b856f1..e5f16fe963d 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -45153,8 +45153,8 @@ static tree cp_parser_omp_tile (cp_parser *, cp_token *, bool *); static tree cp_parser_omp_loop_nest (cp_parser *parser, bool *if_p) { - tree decl, cond, incr, init; - tree orig_init, real_decl, orig_decl; + tree decl = NULL_TREE, cond = NULL_TREE, incr = NULL_TREE, init = NULL_TREE; + tree orig_init = NULL_TREE, real_decl = NULL_TREE, orig_decl = NULL_TREE; tree init_block, body_block; tree init_placeholder, body_placeholder; tree init_scope; @@ -45324,8 +45324,6 @@ cp_parser_omp_loop_nest (cp_parser *parser, bool *if_p) if (!parens.require_open (parser)) return NULL; - init = orig_init = decl = real_decl = orig_decl = NULL_TREE; - init_placeholder = build_stmt (input_location, EXPR_STMT, integer_zero_node); vec_safe_push (omp_for_parse_state->init_placeholderv, init_placeholder); @@ -45501,12 +45499,10 @@ cp_parser_omp_loop_nest (cp_parser *parser, bool *if_p) } } - cond = NULL; if (cp_lexer_next_token_is_not (parser->lexer, CPP_SEMICOLON)) cond = cp_parser_omp_for_cond (parser, decl, omp_for_parse_state->code); cp_parser_require (parser, CPP_SEMICOLON, RT_SEMICOLON); - incr = NULL; if (cp_lexer_next_token_is_not (parser->lexer, CPP_CLOSE_PAREN)) { /* If decl is an iterator, preserve the operator on decl -- 2.25.1
Re: [PATCH 27/52] nios2: Remove macros {FLOAT,DOUBLE,LONG_DOUBLE}_TYPE_SIZE
On 6/2/24 21:01, Kewen Lin wrote: This is to remove macros {FLOAT,{,LONG_}DOUBLE}_TYPE_SIZE defines in nios2 port. gcc/ChangeLog: * config/nios2/nios2.h (FLOAT_TYPE_SIZE): Remove. (DOUBLE_TYPE_SIZE): Likewise. (LONG_DOUBLE_TYPE_SIZE): Likewise. Fine with me, but somewhat redundant since I'm still planning to remove the entire nios2 back end this release cycle. -Sandra
Re: [committed] nvptx, libgfortran: Switch out of "minimal" mode
On 6/6/24 06:06, Tobias Burnus wrote: Hi Thomas, regarding the commit r15-1070-g3a4775d4403f2e / https://gcc.gnu.org/r15-1070 First, thanks for adding I/O support to nvptx offloading. I have a wording nit, to be confirmed by a native speaker: --- a/libgomp/libgomp.texi +++ b/libgomp/libgomp.texi ... +@item I/O within OpenMP target regions and OpenACC compute regions is supported + using the C library @code{printf} functions. + Additionally, the Fortran @code{print}/@code{write} statements are + supported within OpenMP target regions, but not yet OpenACC compute + regions. @c The latter needs 'GOMP_NVPTX_NATIVE_GPU_THREAD_STACK_SIZE'. I think an "in" (or 'within') is missing before OpenACC. Yes, "...not yet within OpenACC compute regions", please. -Sandra
[PATCH v2 10/12] OpenMP: Remove dead code from declare variant reimplementation
After reimplementing late resolution of "declare variant" to use the same mechanisms as metadirective, the declare_variant_alt and calls_declare_variant_alt flags on struct cgraph_node are no longer used by anything. For the purposes of marking functions that need late resolution, the has_metadirectives flag has replaced calls_declare_variant_alt. Likewise struct omp_declare_variant_entry, struct omp_declare_variant_base_entry, and the hash tables used to store these structures are no longer needed, since the information needed for late resolution is now stored in the gomp_metadirective nodes. There are no functional changes in this patch, just removing dead code. gcc/ChangeLog * cgraph.cc (symbol_table::create_edge): Don't set calls_declare_variant_alt in the caller. * cgraph.h (struct cgraph_node): Remove declare_variant_alt and calls_declare_variant_alt flags. * cgraphclones.cc (cgraph_node::create_clone): Don't copy calls_declare_variant_alt bit. * ipa-free-lang-data.cc (free_lang_data_in_decl): Adjust code referencing declare_variant_alt bit. * ipa.cc (symbol_table::remove_unreachable_nodes): Likewise. * lto-cgraph.cc (lto_output_node): Remove references to deleted bits. (output_refs): Adjust code referencing declare_variant_alt bit. (input_overwrite_node): Remove references to deleted bits. (input_refs): Adjust code referencing declare_variant_alt bit. * lto-streamer-out.cc (lto_output): Likewise. * lto-streamer.h (omp_lto_output_declare_variant_alt): Delete. (omp_lto_input_declare_variant_alt): Delete. * lto/lto-partition.cc (lto_balanced_map): Adjust code referencing deleted declare_variant_alt bit. * omp-expand.cc (expand_omp_target): Use has_metadirectives bit to trigger pass_omp_device_lower instead of calls_declare_variant_alt. * omp-general.cc (struct omp_declare_variant_entry): Delete. (struct omp_declare_variant_base_entry): Delete. (struct omp_declare_variant_hasher): Delete. (omp_declare_variant_hasher::hash): Delete. (omp_declare_variant_hasher::equal): Delete. (omp_declare_variants): Delete. (omp_declare_variant_alt_hasher): Delete. (omp_declare_variant_alt_hasher::hash): Delete. (omp_declare_variant_alt_hasher::equal): Delete. (omp_declare_variant_alt): Delete. (omp_lto_output_declare_variant_alt): Delete. (omp_lto_input_declare_variant_alt): Delete. (includes): Delete unnecessary include of gt-omp-general.h. * omp-offload.cc (execute_omp_device_lower): Remove references to deleted bit. (pass_omp_device_lower::gate): Likewise. * omp-simd-clone.cc (simd_clone_create): Likewise. * passes.cc (ipa_write_summaries): Likeise. * symtab.cc (symtab_node::get_partitioning_class): Likewise. * tree-inline.cc (expand_call_inline): Likewise. (tree_function_versioning): Likewise. --- gcc/cgraph.cc | 2 - gcc/cgraph.h | 11 +- gcc/cgraphclones.cc | 1 - gcc/ipa-free-lang-data.cc | 2 +- gcc/ipa.cc| 3 - gcc/lto-cgraph.cc | 10 -- gcc/lto-streamer-out.cc | 3 +- gcc/lto-streamer.h| 6 -- gcc/lto/lto-partition.cc | 5 +- gcc/omp-expand.cc | 2 +- gcc/omp-general.cc| 218 -- gcc/omp-offload.cc| 8 +- gcc/omp-simd-clone.cc | 2 - gcc/passes.cc | 3 +- gcc/symtab.cc | 2 +- gcc/tree-inline.cc| 4 - 16 files changed, 10 insertions(+), 272 deletions(-) diff --git a/gcc/cgraph.cc b/gcc/cgraph.cc index 473d8410bc9..103bc2c0332 100644 --- a/gcc/cgraph.cc +++ b/gcc/cgraph.cc @@ -931,8 +931,6 @@ symbol_table::create_edge (cgraph_node *caller, cgraph_node *callee, caller->decl); else edge->in_polymorphic_cdtor = caller->thunk; - if (callee) -caller->calls_declare_variant_alt |= callee->declare_variant_alt; if (callee && symtab->state != LTO_STREAMING && edge->callee->comdat_local_p ()) diff --git a/gcc/cgraph.h b/gcc/cgraph.h index 6653ce19c3e..dd210842df7 100644 --- a/gcc/cgraph.h +++ b/gcc/cgraph.h @@ -897,10 +897,8 @@ struct GTY((tag ("SYMTAB_FUNCTION"))) cgraph_node : public symtab_node split_part (false), indirect_call_target (false), local (false), versionable (false), can_change_signature (false), redefined_extern_inline (false), tm_may_enter_irr (false), - ipcp_clone (false), declare_variant_alt (false), - calls_declare_variant_alt (false), gc_candidate (false), - called_by_ifunc_resolver (false), - has_metadirectives (false), + ipcp_clone (false), gc_candidate (false), + called_by_ifunc_resolver (false), has_metadirectives (false), m_uid (uid), m_summary_id (-1)
[PATCH v2 11/12] OpenMP: Update "declare target"/OpenMP context interaction
The code and test case previously implemented the OpenMP 5.0 spec, which said in section 2.3.1: "For functions within a declare target block, the target trait is added to the beginning of the set..." In OpenMP 5.1, this was changed to "For device routines, the target trait is added to the beginning of the set..." In OpenMP 5.2 and TR12, it says: "For procedures that are determined to be target function variants by a declare target directive..." The definition of "device routine" in OpenMP 5.1 is confusing, but certainly the intent of the later versions of the spec is clear that it doesn't just apply to functions within a begin declare target/end declare target block. The only use of the "omp declare target block" function attribute was to support the 5.0 language, so it can be removed. This patch changes the context augmentation to use the "omp declare target" attribute instead. gcc/c-family/ChangeLog * c-attribs.cc (c_common_gnu_attributes): Delete "omp declare target block". gcc/c/ChangeLog * c-decl.cc (c_decl_attributes): Don't add "omp declare target block". gcc/cp/decl2.cc * decl2.cc (cplus_decl_attributes): Don't add "omp declare target block". gcc/ChangeLog * omp-general.cc (omp_complete_construct_context): Check "omp declare target" attribute, not "omp declare target block". gcc/testsuite/ChangeLog * c-c++-common/gomp/declare-target-indirect-2.c : Adjust expected output for removal of "omp declare target block". * c-c++-common/gomp/declare-variant-8.c: Likewise, the variant call to f20 is now resolved differently. * c-c++-common/gomp/reverse-offload-1.c: Adjust expected output. * gfortran.dg/gomp/declare-variant-8.f90: Likewise, both f18 and f20 now resolve to the variant. Delete obsolete comments. --- gcc/c-family/c-attribs.cc| 2 -- gcc/c/c-decl.cc | 8 ++-- gcc/cp/decl2.cc | 9 ++--- gcc/omp-general.cc | 2 +- .../c-c++-common/gomp/declare-target-indirect-2.c| 10 +- gcc/testsuite/c-c++-common/gomp/declare-variant-8.c | 4 ++-- gcc/testsuite/c-c++-common/gomp/reverse-offload-1.c | 2 +- gcc/testsuite/gfortran.dg/gomp/declare-variant-8.f90 | 12 ++-- 8 files changed, 15 insertions(+), 34 deletions(-) diff --git a/gcc/c-family/c-attribs.cc b/gcc/c-family/c-attribs.cc index 04e39b41bdf..582d99ada1b 100644 --- a/gcc/c-family/c-attribs.cc +++ b/gcc/c-family/c-attribs.cc @@ -570,8 +570,6 @@ const struct attribute_spec c_common_gnu_attributes[] = handle_omp_declare_target_attribute, NULL }, { "omp declare target nohost", 0, 0, true, false, false, false, handle_omp_declare_target_attribute, NULL }, - { "omp declare target block", 0, 0, true, false, false, false, - handle_omp_declare_target_attribute, NULL }, { "non overlapping", 0, 0, true, false, false, false, handle_non_overlapping_attribute, NULL }, { "alloc_align", 1, 1, false, true, true, false, diff --git a/gcc/c/c-decl.cc b/gcc/c/c-decl.cc index b691b91b3db..20cdb647f57 100644 --- a/gcc/c/c-decl.cc +++ b/gcc/c/c-decl.cc @@ -5431,12 +5431,8 @@ c_decl_attributes (tree *node, tree attributes, int flags) attributes = tree_cons (get_identifier ("omp declare target implicit"), NULL_TREE, attributes); else - { - attributes = tree_cons (get_identifier ("omp declare target"), - NULL_TREE, attributes); - attributes = tree_cons (get_identifier ("omp declare target block"), - NULL_TREE, attributes); - } + attributes = tree_cons (get_identifier ("omp declare target"), + NULL_TREE, attributes); if (TREE_CODE (*node) == FUNCTION_DECL) { int device_type diff --git a/gcc/cp/decl2.cc b/gcc/cp/decl2.cc index 7baff46a192..8b5f2006b3b 100644 --- a/gcc/cp/decl2.cc +++ b/gcc/cp/decl2.cc @@ -1781,13 +1781,8 @@ cplus_decl_attributes (tree *decl, tree attributes, int flags) = tree_cons (get_identifier ("omp declare target implicit"), NULL_TREE, attributes); else - { - attributes = tree_cons (get_identifier ("omp declare target"), - NULL_TREE, attributes); - attributes - = tree_cons (get_identifier ("omp declare target block"), -NULL_TREE, attributes); - } + attributes = tree_cons (get_identifier ("omp declare target"), + NULL_TREE, attributes); if (TREE_CODE (*decl) == FUNCTION_DECL) {
[PATCH v2 06/12] OpenMP: common c/c++ testcases for metadirectives
gcc/testsuite/ChangeLog * c-c++-common/gomp/metadirective-1.c: New. * c-c++-common/gomp/metadirective-2.c: New. * c-c++-common/gomp/metadirective-3.c: New. * c-c++-common/gomp/metadirective-4.c: New. * c-c++-common/gomp/metadirective-5.c: New. * c-c++-common/gomp/metadirective-6.c: New. * c-c++-common/gomp/metadirective-7.c: New. * c-c++-common/gomp/metadirective-8.c: New. * c-c++-common/gomp/metadirective-construct.c: New. * c-c++-common/gomp/metadirective-device.c: New. * c-c++-common/gomp/metadirective-no-score.c: New. * c-c++-common/gomp/metadirective-target-device.c: New. libgomp/ChangeLog * testsuite/libgomp.c-c++-common/metadirective-1.c: New. * testsuite/libgomp.c-c++-common/metadirective-2.c: New. * testsuite/libgomp.c-c++-common/metadirective-3.c: New. * testsuite/libgomp.c-c++-common/metadirective-4.c: New. * testsuite/libgomp.c-c++-common/metadirective-5.c: New. Co-Authored-By: Kwok Cheung Yeung Co-Authored-By: Sandra Loosemore --- .../c-c++-common/gomp/metadirective-1.c | 52 + .../c-c++-common/gomp/metadirective-2.c | 74 .../c-c++-common/gomp/metadirective-3.c | 31 +++ .../c-c++-common/gomp/metadirective-4.c | 40 .../c-c++-common/gomp/metadirective-5.c | 24 +++ .../c-c++-common/gomp/metadirective-6.c | 31 +++ .../c-c++-common/gomp/metadirective-7.c | 31 +++ .../c-c++-common/gomp/metadirective-8.c | 16 ++ .../gomp/metadirective-construct.c| 177 ++ .../c-c++-common/gomp/metadirective-device.c | 147 +++ .../gomp/metadirective-no-score.c | 95 ++ .../gomp/metadirective-target-device.c| 147 +++ .../libgomp.c-c++-common/metadirective-1.c| 35 .../libgomp.c-c++-common/metadirective-2.c| 41 .../libgomp.c-c++-common/metadirective-3.c| 34 .../libgomp.c-c++-common/metadirective-4.c| 52 + .../libgomp.c-c++-common/metadirective-5.c| 46 + 17 files changed, 1073 insertions(+) create mode 100644 gcc/testsuite/c-c++-common/gomp/metadirective-1.c create mode 100644 gcc/testsuite/c-c++-common/gomp/metadirective-2.c create mode 100644 gcc/testsuite/c-c++-common/gomp/metadirective-3.c create mode 100644 gcc/testsuite/c-c++-common/gomp/metadirective-4.c create mode 100644 gcc/testsuite/c-c++-common/gomp/metadirective-5.c create mode 100644 gcc/testsuite/c-c++-common/gomp/metadirective-6.c create mode 100644 gcc/testsuite/c-c++-common/gomp/metadirective-7.c create mode 100644 gcc/testsuite/c-c++-common/gomp/metadirective-8.c create mode 100644 gcc/testsuite/c-c++-common/gomp/metadirective-construct.c create mode 100644 gcc/testsuite/c-c++-common/gomp/metadirective-device.c create mode 100644 gcc/testsuite/c-c++-common/gomp/metadirective-no-score.c create mode 100644 gcc/testsuite/c-c++-common/gomp/metadirective-target-device.c create mode 100644 libgomp/testsuite/libgomp.c-c++-common/metadirective-1.c create mode 100644 libgomp/testsuite/libgomp.c-c++-common/metadirective-2.c create mode 100644 libgomp/testsuite/libgomp.c-c++-common/metadirective-3.c create mode 100644 libgomp/testsuite/libgomp.c-c++-common/metadirective-4.c create mode 100644 libgomp/testsuite/libgomp.c-c++-common/metadirective-5.c diff --git a/gcc/testsuite/c-c++-common/gomp/metadirective-1.c b/gcc/testsuite/c-c++-common/gomp/metadirective-1.c new file mode 100644 index 000..37b56237531 --- /dev/null +++ b/gcc/testsuite/c-c++-common/gomp/metadirective-1.c @@ -0,0 +1,52 @@ +/* { dg-do compile } */ + +#define N 100 + +void f (int a[], int b[], int c[]) +{ + int i; + + #pragma omp metadirective \ + default (teams loop) \ + default (parallel loop) /* { dg-error "too many 'otherwise' or 'default' clauses in 'metadirective'" } */ +for (i = 0; i < N; i++) c[i] = a[i] * b[i]; + + #pragma omp metadirective \ + otherwise (teams loop) \ + default (parallel loop) /* { dg-error "too many 'otherwise' or 'default' clauses in 'metadirective'" } */ +for (i = 0; i < N; i++) c[i] = a[i] * b[i]; + + #pragma omp metadirective \ + otherwise (teams loop) \ + otherwise (parallel loop) /* { dg-error "too many 'otherwise' or 'default' clauses in 'metadirective'" } */ +for (i = 0; i < N; i++) c[i] = a[i] * b[i]; + + #pragma omp metadirective \ + default (bad_directive) /* { dg-error "unknown directive name before '\\)' token" } */ +for (i = 0; i < N; i++) c[i] = a[i] * b[i]; + + #pragma omp metadirective \ + default (teams loop) \ + where (device={arch("nvptx")}: parallel loop) /* { dg-error "'where' is not valid for 'metadirective'"
[PATCH v2 09/12] OpenMP: Extend dynamic selector support to declare variant
This patch extends the mechanisms previously added to support dynamic selectors in metavariant constructs to also apply to "declare variant". The front-end mechanisms used to handle "declare variant" via attributes attached to the function decls remain the same, but the gimplifier now uses the same internal data structures and helper functions as metadirective to score and sort "declare variant" alternatives, and constructs a gomp_metadirective node for variant calls that cannot be resolved at gimplification time. During late resolution, this gomp_metadirective is processed in exactly the same way as for real metadirectives. During implementation of this functionality, a number of bugs were discovered in the previous selector scoring and matching code: * Metadirective resolution was failing to account for scoring in "declare simd" clones, and was also relying on calling a function to match construct constructors that's only useful during gimplification during late resolution long after that pass. * The construct constructor scoring was previously implemented backwards from the specification (PR114596); a number of testcases were also broken in the same way as the implementation. * The special rules for matching simdlen and aligned properties on simd selectors were not implemented (nor were these properties on metadirectives being rejected per the OpenMP spec). This patch includes a new implementation of this functionality that has cleaner interfaces and is hopefully(!) easier to correlate to requirements of the OpenMP specification. Instead of relying on the gimplifier to score construct selectors, the scoring code has been consolidated in omp-general.cc with the gimplifier only providing the OpenMP construct context surrounding the metadirective or variant call. This is cached on the gomp_metadirective if necessary for late resolution. An additional improvement added in this patch is that for both metadirective and "declare variant", if late resolution is required the gimplifier now discards all alternatives that are known not to match. Note that this patch leaves a substantial amount of dead code that was used to support the former late "declare variant" resolution strategy, notably the declare_variant_alt and calls_declare_variant_alt flags on cgraph_node and all the code that touches those fields. The next patch in this series removes that unused code. Another issue not addressed in this patch is the special scoping rules for expressions in "declare variant" dynamic selectors, which is still under discussion in PR113904. We expect this to be fixed separately. gcc/c/ChangeLog * c-parser.c (c_parser_omp_context_selector): Remove metadirective_p parameter and conditionalization. (c_parser_omp_context_selector_specification): Remove metadirective_p parameter and adjust call not to pass it on. (c_finish_omp_declare_variant): Adjust arguments on calls to c_parser_omp_context_selector_specification and omp_context_selector_matches. (c_parser_omp_metadirective): Likewise. gcc/cp/ChangeLog * cp-tree.h (struct saved_scope): Add new field x_processing_omp_trait_property_expr. (processing_omp_trait_property_expr): Define * decl.cc (omp_declare_variant_finalize_one): Adjust arguments to omp_context_selector_matches. * parser.cc (cp_parser_omp_context_selector): Remove metadirective_p argument and conditionalization. (cp_parser_omp_context_selector_specification): Remove metadirective_p argument and adjust call not to pass it on. (cp_finish_omp_declare_variant): Adjust arguments on call to above. (cp_parser_omp_metadirective): Likewise. * pt.cc (tsubst_omp_context_selector): Adjust error behavior. (tsubst_stmt): Adjust call to omp_context_selector_matches. * semantics.cc (finish_id_expression_1): Do not diagnose error for use of parameter in declare variant selector here. gcc/fortran/ChangeLog * trans-openmp.cc (gfc_trans_omp_declare_variant): Adjust arguments to omp_context_selector_matches. (gfc_trans_omp_metadirective): Likewise. gcc/Changelog * gimple-streamer-in.cc (input_gimple_stmt): Restore gomp_metadirective context. * gimple-streamer-out.cc (output_gimple_stmt): Save gomp_metadirective context. * gimple.cc (gimple_build_omp_metadirective): Initialize gomp_metadirective context. * gimple.def (GIMPLE_OMP_METADIRECTIVE): Update comments. * gimple.h (gomp_metadirective): Add context field and update comments. (gimple_omp_metadirective_context): New. (gimple_omp_metadirective_set_context): New. * gimplify.cc (omp_resolved_variant_calls): New. (gimplify_variant_call_expr): New. (gimplify_call_expr): Adjust parameters. Call gimplify_variant_call_expr to handle declar
[PATCH v2 07/12] OpenMP: Fortran front-end support for metadirectives.
etadirective test. * gfortran.dg/gomp/pure-2.f90: Remove metadirective test. libgomp/ChangeLog * testsuite/libgomp.fortran/metadirective-1.f90: New. * testsuite/libgomp.fortran/metadirective-2.f90: New. * testsuite/libgomp.fortran/metadirective-3.f90: New. * testsuite/libgomp.fortran/metadirective-4.f90: New. * testsuite/libgomp.fortran/metadirective-5.f90: New. * testsuite/libgomp.fortran/metadirective-6.f90: New. Co-Authored-By: Kwok Cheung Yeung Co-Authored-By: Sandra Loosemore Co-Authored-By: Tobias Burnus Co-Authored-By: Paul-Antoine Arras --- gcc/fortran/decl.cc | 29 + gcc/fortran/dump-parse-tree.cc| 21 + gcc/fortran/gfortran.h| 20 +- gcc/fortran/io.cc | 2 +- gcc/fortran/match.h | 2 + gcc/fortran/openmp.cc | 294 +++-- gcc/fortran/parse.cc | 571 +++--- gcc/fortran/parse.h | 8 +- gcc/fortran/resolve.cc| 6 + gcc/fortran/st.cc | 4 + gcc/fortran/symbol.cc | 25 +- gcc/fortran/trans-decl.cc | 5 +- gcc/fortran/trans-openmp.cc | 233 --- gcc/fortran/trans-stmt.h | 1 + gcc/fortran/trans.cc | 1 + .../gfortran.dg/gomp/metadirective-1.f90 | 55 ++ .../gfortran.dg/gomp/metadirective-10.f90 | 40 ++ .../gfortran.dg/gomp/metadirective-11.f90 | 33 + .../gfortran.dg/gomp/metadirective-2.f90 | 62 ++ .../gfortran.dg/gomp/metadirective-3.f90 | 34 ++ .../gfortran.dg/gomp/metadirective-4.f90 | 39 ++ .../gfortran.dg/gomp/metadirective-5.f90 | 30 + .../gfortran.dg/gomp/metadirective-6.f90 | 31 + .../gfortran.dg/gomp/metadirective-7.f90 | 36 ++ .../gfortran.dg/gomp/metadirective-8.f90 | 22 + .../gfortran.dg/gomp/metadirective-9.f90 | 30 + .../gomp/metadirective-construct.f90 | 260 .../gomp/metadirective-no-score.f90 | 122 gcc/testsuite/gfortran.dg/gomp/pure-1.f90 | 7 + gcc/testsuite/gfortran.dg/gomp/pure-2.f90 | 8 - .../libgomp.fortran/metadirective-1.f90 | 61 ++ .../libgomp.fortran/metadirective-2.f90 | 40 ++ .../libgomp.fortran/metadirective-3.f90 | 29 + .../libgomp.fortran/metadirective-4.f90 | 46 ++ .../libgomp.fortran/metadirective-5.f90 | 44 ++ .../libgomp.fortran/metadirective-6.f90 | 58 ++ 36 files changed, 1947 insertions(+), 362 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/gomp/metadirective-1.f90 create mode 100644 gcc/testsuite/gfortran.dg/gomp/metadirective-10.f90 create mode 100644 gcc/testsuite/gfortran.dg/gomp/metadirective-11.f90 create mode 100644 gcc/testsuite/gfortran.dg/gomp/metadirective-2.f90 create mode 100644 gcc/testsuite/gfortran.dg/gomp/metadirective-3.f90 create mode 100644 gcc/testsuite/gfortran.dg/gomp/metadirective-4.f90 create mode 100644 gcc/testsuite/gfortran.dg/gomp/metadirective-5.f90 create mode 100644 gcc/testsuite/gfortran.dg/gomp/metadirective-6.f90 create mode 100644 gcc/testsuite/gfortran.dg/gomp/metadirective-7.f90 create mode 100644 gcc/testsuite/gfortran.dg/gomp/metadirective-8.f90 create mode 100644 gcc/testsuite/gfortran.dg/gomp/metadirective-9.f90 create mode 100644 gcc/testsuite/gfortran.dg/gomp/metadirective-construct.f90 create mode 100644 gcc/testsuite/gfortran.dg/gomp/metadirective-no-score.f90 create mode 100644 libgomp/testsuite/libgomp.fortran/metadirective-1.f90 create mode 100644 libgomp/testsuite/libgomp.fortran/metadirective-2.f90 create mode 100644 libgomp/testsuite/libgomp.fortran/metadirective-3.f90 create mode 100644 libgomp/testsuite/libgomp.fortran/metadirective-4.f90 create mode 100644 libgomp/testsuite/libgomp.fortran/metadirective-5.f90 create mode 100644 libgomp/testsuite/libgomp.fortran/metadirective-6.f90 diff --git a/gcc/fortran/decl.cc b/gcc/fortran/decl.cc index b8308aeee55..b6633a913e7 100644 --- a/gcc/fortran/decl.cc +++ b/gcc/fortran/decl.cc @@ -8422,6 +8422,7 @@ gfc_match_end (gfc_statement *st) case COMP_CONTAINS: case COMP_DERIVED_CONTAINS: +case COMP_OMP_BEGIN_METADIRECTIVE: state = gfc_state_stack->previous->state; block_name = gfc_state_stack->previous->sym == NULL ? NULL : gfc_state_stack->previous->sym->name; @@ -8429,6 +8430,28 @@ gfc_match_end (gfc_statement *st) && gfc_state_stack->previous->sym->abr_modproc_decl; break; +case COMP_OMP_METADIRECTIVE: + { + /* Metadirectives can be nested, so we need to drill down to the + first state that is not COMP_OMP_METADIRECTIVE. */ + gfc_state_data *state_data = gfc_state_stack; + + d
[PATCH v2 12/12] OpenMP: Update documentation of metadirective implementation status.
libgomp/ChangeLog * libgomp.texi (OpenMP 5.0): Mark metadirective and declare variant as implemented. (OpenMP 5.1): Mark target_device as supported. Add changed interaction between declare target and OpenMP context and dynamic selector support. (OpenMP 5.2): Mark otherwise clause as supported, note that default is also still accepted. --- libgomp/libgomp.texi | 21 ++--- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/libgomp/libgomp.texi b/libgomp/libgomp.texi index 43048da4d6e..af7af63c504 100644 --- a/libgomp/libgomp.texi +++ b/libgomp/libgomp.texi @@ -192,9 +192,8 @@ The OpenMP 4.5 specification is fully supported. @item Array shaping @tab N @tab @item Array sections with non-unit strides in C and C++ @tab N @tab @item Iterators @tab Y @tab -@item @code{metadirective} directive @tab N @tab -@item @code{declare variant} directive - @tab P @tab @emph{simd} traits not handled correctly +@item @code{metadirective} directive @tab Y @tab +@item @code{declare variant} directive @tab Y @tab @item @var{target-offload-var} ICV and @code{OMP_TARGET_OFFLOAD} env variable @tab Y @tab @item Nested-parallel changes to @var{max-active-levels-var} ICV @tab Y @tab @@ -289,8 +288,8 @@ The OpenMP 4.5 specification is fully supported. @headitem Description @tab Status @tab Comments @item OpenMP directive as C++ attribute specifiers @tab Y @tab @item @code{omp_all_memory} reserved locator @tab Y @tab -@item @emph{target_device trait} in OpenMP Context @tab N @tab -@item @code{target_device} selector set in context selectors @tab N @tab +@item @emph{target_device trait} in OpenMP Context @tab Y +@item @code{target_device} selector set in context selectors @tab Y @tab @item C/C++'s @code{declare variant} directive: elision support of preprocessed code @tab N @tab @item @code{declare variant}: new clauses @code{adjust_args} and @@ -366,6 +365,12 @@ to address of matching mapped list item per 5.1, Sect. 2.21.7.2 @tab N @tab @item @code{device_type(nohost)}/@code{device_type(host)} for variables @tab N @tab @item @code{present} modifier to the @code{map}, @code{to} and @code{from} clauses @tab Y @tab +@item Changed interaction between @code{declare target} and OpenMP context + @tab Y @tab +@item Dynamic selector support in @code{metadirective} @tab Y @tab +@item Dynamic selector support in @code{declare variant} @tab P + @tab Fortran rejects non-constant expressions in dynamic selectors; + C/C++ reject expressions using argument variables. @end multitable @@ -413,8 +418,10 @@ to address of matching mapped list item per 5.1, Sect. 2.21.7.2 @tab N @tab @item Deprecation of traits array following the allocator_handle expression in @code{uses_allocators} @tab N @tab @item New @code{otherwise} clause as alias for @code{default} on metadirectives - @tab N @tab -@item Deprecation of @code{default} clause on metadirectives @tab N @tab + @tab Y @tab +@item Deprecation of @code{default} clause on metadirectives @tab N + @tab Both @code{otherwise} and @code{default} are accepted + without diagnostics. @item Deprecation of delimited form of @code{declare target} @tab N @tab @item Reproducible semantics changed for @code{order(concurrent)} @tab N @tab @item @code{allocate} and @code{firstprivate} clauses on @code{scope} -- 2.25.1
[PATCH v2 03/12] libgomp: runtime support for target_device selector
This patch implements the libgomp runtime support for the dynamic target_device selector via the GOMP_evaluate_target_device function. include/ChangeLog * cuda/cuda.h (CUdevice_attribute): Add definitions for CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR and CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MINOR. libgomp/ChangeLog * Makefile.am (libgomp_la_SOURCES): Add selector.c. * Makefile.in: Regenerate. * config/gcn/selector.c: New. * config/linux/selector.c: New. * config/linux/x86/selector.c: New. * config/nvptx/selector.c: New. * libgomp-plugin.h (GOMP_OFFLOAD_evaluate_device): New. * libgomp.h (struct gomp_device_descr): Add evaluate_device_func field. * libgomp.map (GOMP_5.1.3): New, add GOMP_evaluate_target_device. * libgomp.texi (OpenMP Context Selectors): Document dynamic selector matching of kind/arch/isa. * libgomp_g.h (GOMP_evaluate_current_device): New. (GOMP_evaluate_target_device): New. * oacc-host.c (host_evaluate_device): New. (host_openacc_exec): Initialize evaluate_device_func field to host_evaluate_device. * plugin/plugin-gcn.c (gomp_match_selectors): New. (gomp_match_isa): New. (GOMP_OFFLOAD_evaluate_device): New. * plugin/plugin-nvptx.c (struct ptx_device): Add compute_major and compute_minor fields. (nvptx_open_device): Read compute capability information from device. (gomp_match_selectors): New. (gomp_match_selector): New. (CHECK_ISA): New macro. (GOMP_OFFLOAD_evaluate_device): New. * selector.c: New. * target.c (GOMP_evaluate_target_device): New. (gomp_load_plugin_for_device): Load evaluate_device plugin function. Co-Authored-By: Kwok Cheung Yeung Co-Authored-By: Sandra Loosemore --- include/cuda/cuda.h | 2 + libgomp/Makefile.am | 2 +- libgomp/Makefile.in | 5 +- libgomp/config/gcn/selector.c | 102 +++ libgomp/config/linux/selector.c | 65 + libgomp/config/linux/x86/selector.c | 406 libgomp/config/nvptx/selector.c | 77 ++ libgomp/libgomp-plugin.h| 2 + libgomp/libgomp.h | 1 + libgomp/libgomp.map | 5 + libgomp/libgomp.texi| 18 +- libgomp/libgomp_g.h | 8 + libgomp/oacc-host.c | 11 + libgomp/plugin/plugin-gcn.c | 52 libgomp/plugin/plugin-nvptx.c | 82 ++ libgomp/selector.c | 64 + libgomp/target.c| 40 +++ 17 files changed, 936 insertions(+), 6 deletions(-) create mode 100644 libgomp/config/gcn/selector.c create mode 100644 libgomp/config/linux/selector.c create mode 100644 libgomp/config/linux/x86/selector.c create mode 100644 libgomp/config/nvptx/selector.c create mode 100644 libgomp/selector.c diff --git a/include/cuda/cuda.h b/include/cuda/cuda.h index 0dca4b3a5c0..a775450df03 100644 --- a/include/cuda/cuda.h +++ b/include/cuda/cuda.h @@ -83,6 +83,8 @@ typedef enum { CU_DEVICE_ATTRIBUTE_MAX_THREADS_PER_MULTIPROCESSOR = 39, CU_DEVICE_ATTRIBUTE_ASYNC_ENGINE_COUNT = 40, CU_DEVICE_ATTRIBUTE_UNIFIED_ADDRESSING = 41, + CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR = 75, + CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MINOR = 76, CU_DEVICE_ATTRIBUTE_MAX_REGISTERS_PER_MULTIPROCESSOR = 82 } CUdevice_attribute; diff --git a/libgomp/Makefile.am b/libgomp/Makefile.am index 855f0affddf..ba2dd0bb3c2 100644 --- a/libgomp/Makefile.am +++ b/libgomp/Makefile.am @@ -70,7 +70,7 @@ libgomp_la_SOURCES = alloc.c atomic.c barrier.c critical.c env.c error.c \ target.c splay-tree.c libgomp-plugin.c oacc-parallel.c oacc-host.c \ oacc-init.c oacc-mem.c oacc-async.c oacc-plugin.c oacc-cuda.c \ priority_queue.c affinity-fmt.c teams.c allocator.c oacc-profiling.c \ - oacc-target.c target-indirect.c + oacc-target.c target-indirect.c selector.c include $(top_srcdir)/plugin/Makefrag.am diff --git a/libgomp/Makefile.in b/libgomp/Makefile.in index da902f3daca..b5d704992fc 100644 --- a/libgomp/Makefile.in +++ b/libgomp/Makefile.in @@ -219,7 +219,7 @@ am_libgomp_la_OBJECTS = alloc.lo atomic.lo barrier.lo critical.lo \ oacc-parallel.lo oacc-host.lo oacc-init.lo oacc-mem.lo \ oacc-async.lo oacc-plugin.lo oacc-cuda.lo priority_queue.lo \ affinity-fmt.lo teams.lo allocator.lo oacc-profiling.lo \ - oacc-target.lo target-indirect.lo $(am__objects_1) + oacc-target.lo target-indirect.lo selector.lo $(am__objects_1) libgomp_la_OBJECTS = $(am_libgomp_la_OBJECTS) AM_V_P = $(am__v_P_@AM_V@) am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) @@ -552,7 +552,7 @@ libgomp_la_SOURCES = alloc.c atomic.c barrier.c critical.c env.c \ oacc-parallel.c oacc-host.c oacc-init.c oacc-mem.c \ oacc-async.c
[PATCH v2 02/12] OpenMP: middle-end support for metadirectives
This patch adds middle-end support for OpenMP metadirectives. Some context selectors can be resolved during gimplification, but others need to be deferred until the omp_device_lower pass, which requires that cgraph, LTO streaming, inlining, etc all know about this construct as well. gcc/ChangeLog * cgraph.h (struct cgraph_node): Add has_metadirectives flag. * cgraphclones.cc (cgraph_node::create_clone): Copy has_metadirectives flag. * doc/gimple.texi (Class hierarchy of GIMPLE statements): Document gomp_metadirective and gomp_variant. * gimple-low.cc (lower_omp_metadirective): New. (lower_stmt): Call it. * gimple-pretty-print.cc (dump_gimple_omp_metadirective): New. (pp_gimple_stmt_1): Call it. * gimple-streamer-in.cc (input_gimple_stmt): Handle GIMPLE_OMP_METADIRECTIVE. * gimple-streamer-out.cc (output_gimple_stmt): Likewise. * gimple-walk.cc (walk_gimple_op): Likewise. (walk_gimple_stmt): Likewise. * gimple.cc (gimple_alloc_omp_metadirective): New. (gimple_build_omp_metadirective): New. (gimple_build_omp_variant): New. * gimple.def (GIMPLE_OMP_METADIRECTIVE): New. (GIMPLE_OMP_METADIRECTIVE_VARIANT): New. * gimple.h (gomp_variant, gomp_metadirective): New. (is_a_helper ::test): New. (is_a_helper ::test): New. (is_a_helper ::test): New. (is_a_helper ::test): New. (gimple_alloc_omp_metadirective): New. (gimple_build_omp_metadirective): New. (gimple_build_omp_variant): New. (gimple_has_substatements): Handle GIMPLE_OMP_METADIRECTIVE. (gimple_has_ops): Likewise. (gimple_omp_metadirective_label): New. (gimple_omp_metadirective_set_label): New. (gimple_omp_variants): New. (gimple_omp_metadirective_set_variants): New. (gimple_return_set_retval): Handle GIMPLE_OMP_METADIRECTIVE. * gimplify.cc (is_gimple_stmt): HANDLE OMP_METADIRECTIVE. (expand_omp_metadirective): New. (gimplify_omp_metadirective): New. (gimplify_expr): Call it. * gsstruct.def (GSS_OMP_METADIRECTIVE): New. (GSS_OMP_METADIRECTIVE_VARIANT): New. * lto-cgraph.cc (lto_output_node): Handle has_metadirectives flag. (input_overwrite_node): Likewise. * omp-expand.cc (expand_omp_target): Propagate has_metadirectives flag. (build_omp_regions_1): Handle GIMPLE_OMP_METADIRECTIVE. (omp_make_gimple_edges): Likewise. * omp-general.cc (omp_late_resolve_metadirective): New. * omp-general.h (omp_late_resolve_metadirective): Declare. * omp-low.cc (struct omp_context): Add next_clone field. (new_omp_context): Handle next_clone field. (clone_omp_context): New. (delete_omp_context): Delete clones. (create_omp_child_function): Propagate has_metadirectives bit. (scan_omp_metadirective): New. (scan_omp_1_stmt): Handle GIMPLE_OMP_METADIRECTIVE. (lower_omp_metadirective): New. (lower_omp_1): Handle GIMPLE_OMP_METADIRECTIVE. Warn about direct calls to offloadable functions containing metadirectives. * omp-offload.cc: Include cfganal.h and cfghooks.h. (omp_expand_metadirective): New. (execute_omp_device_lower): Handle metadirectives. (pass_omp_device_lower::gate): Check has_metadirectives bit. * omp-simd-clone.cc (simd_clone_create): Propagate has_metadirectives flag. * tree-cfg.cc (cleanup_dead_labels): Handle GIMPLE_OMP_METADIRECTIVE. (gimple_redirect_edge_and_branch): Likewise. * tree-inline.cc (remap_gimple_stmt): Handle GIMPLE_OMP_METADIRECTIVE. (estimate_num_instructions): Likewise. (expand_call_inline): Propagate has_metadirectives flag. (tree_function_versioning): Likewise. * tree-nested.cc (convert_nonlocal_reference_stmt): Handle GIMPLE_OMP_METADIRECTIVE specially. (convert_local_reference_stmt): Likewise. (convert_tramp_reference_stmt): Likewise. (convert_gimple_call): Likewise. * tree-ssa-operands.cc: Include omp-general.h. (operands_scanner::parse_ssa_operands): Handle GIMPLE_OMP_METADIRECTIVE. Co-Authored-By: Kwok Cheung Yeung Co-Authored-By: Sandra Loosemore Co-Authored-By: Marcel Vollweiler --- gcc/cgraph.h | 3 + gcc/cgraphclones.cc| 1 + gcc/doc/gimple.texi| 6 ++ gcc/gimple-low.cc | 36 gcc/gimple-pretty-print.cc | 78 gcc/gimple-streamer-in.cc | 10 ++ gcc/gimple-streamer-out.cc | 6 ++ gcc/gimple-walk.cc | 28 ++ gcc/gimple.cc | 35 +++ gcc/gimple.def | 7 ++ gcc/gimple.h | 100 +++- gcc/gimplify.cc| 184 + gcc/gsstruct.def
[PATCH v2 08/12] OpenMP: Reject other properties with kind(any)
The OpenMP spec says: "If trait-property any is specified in the kind trait-selector of the device selector set or the target_device selector sets, no other trait-property may be specified in the same selector set." GCC was not previously enforcing this restriction and several testcases included such valid constructs. This patch fixes it. gcc/ChangeLog * omp-general.cc (omp_check_context_selector): Reject other properties in the same selector set with kind(any). gcc/testsuite/ChangeLog * c-c++-common/gomp/declare-variant-10.c: Fix broken tests. * c-c++-common/gomp/declare-variant-3.c: Likewise. * c-c++-common/gomp/declare-variant-9.c: Likewise. * c-c++-common/gomp/declare-variant-any.c: New. * gfortran.dg/gomp/declare-variant-10.f90: Fix broken tests. * gfortran.dg/gomp/declare-variant-3.f90: Likewise. * gfortran.dg/gomp/declare-variant-9.f90: Likewise. * gfortran.dg/gomp/declare-variant-any.f90: Likewise. --- gcc/omp-general.cc| 31 +++ .../c-c++-common/gomp/declare-variant-10.c| 4 +-- .../c-c++-common/gomp/declare-variant-3.c | 10 ++ .../c-c++-common/gomp/declare-variant-9.c | 4 +-- .../c-c++-common/gomp/declare-variant-any.c | 10 ++ .../gfortran.dg/gomp/declare-variant-10.f90 | 4 +-- .../gfortran.dg/gomp/declare-variant-3.f90| 12 ++- .../gfortran.dg/gomp/declare-variant-9.f90| 2 +- .../gfortran.dg/gomp/declare-variant-any.f90 | 28 + 9 files changed, 82 insertions(+), 23 deletions(-) create mode 100644 gcc/testsuite/c-c++-common/gomp/declare-variant-any.c create mode 100644 gcc/testsuite/gfortran.dg/gomp/declare-variant-any.f90 diff --git a/gcc/omp-general.cc b/gcc/omp-general.cc index 6f36b5d163f..23072b10d75 100644 --- a/gcc/omp-general.cc +++ b/gcc/omp-general.cc @@ -1277,6 +1277,8 @@ omp_check_context_selector (location_t loc, tree ctx, bool metadirective_p) for (tree tss = ctx; tss; tss = TREE_CHAIN (tss)) { enum omp_tss_code tss_code = OMP_TSS_CODE (tss); + bool saw_any_prop = false; + bool saw_other_prop = false; /* FIXME: not implemented yet. */ if (!metadirective_p && tss_code == OMP_TRAIT_SET_TARGET_DEVICE) @@ -1314,6 +1316,27 @@ omp_check_context_selector (location_t loc, tree ctx, bool metadirective_p) else ts_seen[ts_code] = true; + + /* If trait-property "any" is specified in the "kind" +trait-selector of the "device" selector set or the +"target_device" selector sets, no other trait-property +may be specified in the same selector set. */ + if (ts_code == OMP_TRAIT_DEVICE_KIND) + for (tree p = OMP_TS_PROPERTIES (ts); p; p = TREE_CHAIN (p)) + { + const char *prop = omp_context_name_list_prop (p); + if (!prop) + continue; + else if (strcmp (prop, "any") == 0) + saw_any_prop = true; + else + saw_other_prop = true; + } + else if (ts_code == OMP_TRAIT_DEVICE_ARCH + || ts_code == OMP_TRAIT_DEVICE_ISA + || ts_code == OMP_TRAIT_DEVICE_NUM) + saw_other_prop = true; + if (omp_ts_map[ts_code].valid_properties == NULL) continue; @@ -1366,6 +1389,14 @@ omp_check_context_selector (location_t loc, tree ctx, bool metadirective_p) break; } } + + if (saw_any_prop && saw_other_prop) + { + error_at (loc, + "no other trait-property may be specified " + "in the same selector set with %"); + return error_mark_node; + } } return ctx; } diff --git a/gcc/testsuite/c-c++-common/gomp/declare-variant-10.c b/gcc/testsuite/c-c++-common/gomp/declare-variant-10.c index 2b8a39425b1..e77693430d1 100644 --- a/gcc/testsuite/c-c++-common/gomp/declare-variant-10.c +++ b/gcc/testsuite/c-c++-common/gomp/declare-variant-10.c @@ -7,7 +7,7 @@ void f01 (void); #pragma omp declare variant (f01) match (device={isa(avx512f,avx512bw)}) void f02 (void); void f03 (void); -#pragma omp declare variant (f03) match (device={kind("any"),arch(x86_64),isa(avx512f,avx512bw)}) +#pragma omp declare variant (f03) match (device={arch(x86_64),isa(avx512f,avx512bw)}) void f04 (void); void f05 (void); #pragma omp declare variant (f05) match (device={kind(gpu)}) @@ -28,7 +28,7 @@ void f15 (void); #pragma omp declare variant (f15) match (device={isa(sse4,ssse3),arch(i386)}) void f16 (void); void f17 (void); -#pragma omp declare variant (f17) match (device={kind(any,fpga)}) +#pragma omp declare variant (f17) match (device={kind(fpga)}) void f18 (void); #pragma omp declare target diff --git a/gcc/testsuite/c-c++-common/gomp/declare-variant-3.c b/gcc/testsuite/c-c++-common/gomp/declare-variant-3.c index f5
[PATCH v2 05/12] OpenMP: C++ front-end support for metadirectives
This patch adds C++ support for metadirectives. It uses the c-family support committed with the corresponding C front end patch to do early parse-time metadirective resolution when possible. Additional C/C++ common testcases are provided in a subsequent patch in the series. gcc/cp/ChangeLog * parser.cc (cp_parser_skip_to_end_of_block_or_statement): Add metadirective_p parameter, use it to control brace/parentheses behavior for metadirectives. (mangle_metadirective_region_label): New. (cp_parser_label_for_labeled_statement): Use it. (cp_parser_jump_statement): Likewise. (cp_parser_omp_context_selector): Add metadirective_p parameter, use it to control error behavior for non-constant exprs properties. (cp_parser_omp_context_selector_specification): Add metadirective_p parameter, use it for cp_parser_omp_context_selector call. (cp_finish_omp_declare_variant): Adjust call to cp_parser_omp_context_selector_specification. (analyze_metadirective_body): New. (cp_parser_omp_metadirective): New. (cp_parser_pragma): Handle PRAGMA_OMP_METADIRECTIVE. * parser.h (struct cp_parser): Add fields for metadirective parsing state. * pt.cc (tsubst_omp_context_selector): New. (tsubst_stmt): Handle OMP_METADIRECTIVE. gcc/testsuite/ChangeLog * g++.dg/gomp/attrs-metadirective-1.C: New. * g++.dg/gomp/attrs-metadirective-2.C: New. * g++.dg/gomp/attrs-metadirective-3.C: New. * g++.dg/gomp/attrs-metadirective-4.C: New. * g++.dg/gomp/attrs-metadirective-5.C: New. * g++.dg/gomp/attrs-metadirective-6.C: New. * g++.dg/gomp/attrs-metadirective-7.C: New. * g++.dg/gomp/attrs-metadirective-8.C: New. libgomp/ChangeLog * testsuite/libgomp.c++/metadirective-template-1.C: New. * testsuite/libgomp.c++/metadirective-template-2.C: New. * testsuite/libgomp.c++/metadirective-template-3.C: New. Co-Authored-By: Kwok Cheung Yeung Co-Authored-By: Sandra Loosemore --- gcc/cp/parser.cc | 524 +- gcc/cp/parser.h | 7 + gcc/cp/pt.cc | 119 .../g++.dg/gomp/attrs-metadirective-1.C | 40 ++ .../g++.dg/gomp/attrs-metadirective-2.C | 74 +++ .../g++.dg/gomp/attrs-metadirective-3.C | 31 ++ .../g++.dg/gomp/attrs-metadirective-4.C | 41 ++ .../g++.dg/gomp/attrs-metadirective-5.C | 24 + .../g++.dg/gomp/attrs-metadirective-6.C | 31 ++ .../g++.dg/gomp/attrs-metadirective-7.C | 31 ++ .../g++.dg/gomp/attrs-metadirective-8.C | 16 + .../libgomp.c++/metadirective-template-1.C| 37 ++ .../libgomp.c++/metadirective-template-2.C| 41 ++ .../libgomp.c++/metadirective-template-3.C| 41 ++ 14 files changed, 1044 insertions(+), 13 deletions(-) create mode 100644 gcc/testsuite/g++.dg/gomp/attrs-metadirective-1.C create mode 100644 gcc/testsuite/g++.dg/gomp/attrs-metadirective-2.C create mode 100644 gcc/testsuite/g++.dg/gomp/attrs-metadirective-3.C create mode 100644 gcc/testsuite/g++.dg/gomp/attrs-metadirective-4.C create mode 100644 gcc/testsuite/g++.dg/gomp/attrs-metadirective-5.C create mode 100644 gcc/testsuite/g++.dg/gomp/attrs-metadirective-6.C create mode 100644 gcc/testsuite/g++.dg/gomp/attrs-metadirective-7.C create mode 100644 gcc/testsuite/g++.dg/gomp/attrs-metadirective-8.C create mode 100644 libgomp/testsuite/libgomp.c++/metadirective-template-1.C create mode 100644 libgomp/testsuite/libgomp.c++/metadirective-template-2.C create mode 100644 libgomp/testsuite/libgomp.c++/metadirective-template-3.C diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index 8f3d566aa25..30461d241a2 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -3003,7 +3003,7 @@ static void cp_parser_skip_to_end_of_statement static void cp_parser_consume_semicolon_at_end_of_statement (cp_parser *); static void cp_parser_skip_to_end_of_block_or_statement - (cp_parser *); + (cp_parser *, bool = false); static bool cp_parser_skip_to_closing_brace (cp_parser *); static bool cp_parser_skip_entire_template_parameter_list @@ -4192,9 +4192,11 @@ cp_parser_consume_semicolon_at_end_of_statement (cp_parser *parser) have consumed a non-nested `;'. */ static void -cp_parser_skip_to_end_of_block_or_statement (cp_parser* parser) +cp_parser_skip_to_end_of_block_or_statement (cp_parser* parser, +bool metadirective_p) { int nesting_depth = 0; + int bracket_depth = 0; /* Unwind generic function template scope if necessary. */ if (parser->fully_implicit_function_template_p) @@ -4216,7 +4218,7 @@ cp_parser_skip_to_end_of_block_or_statement (cp_parser* parser) case CPP_SEMICOLON: /* Stop if this is an unnested ';'. */ - if (!nesting_d
[PATCH v2 04/12] OpenMP: C front end support for metadirectives
This patch adds support to the C front end to parse OpenMP metadirective constructs. It includes support for early parse-time resolution of metadirectives (when possible) that will also be used by the C++ front end. Additional common C/C++ testcases are in a later patch in the series. gcc/c-family/ChangeLog * c-common.h (enum c_omp_directive_kind): Add C_OMP_DIR_META. (c_omp_expand_metadirective): Declare. * c-gimplify.cc: Include omp-general.h. (genericize_omp_metadirective_stmt): New. (c_genericize_control_stmt): Call it. * c-omp.cc (c_omp_directives): Add "metadirective" and fix commented-out stubs for the begin/end form. (c_omp_expand_metadirective_r): New. (c_omp_expand_metadirective): New. * c-pragma.cc (omp_pragmas): Add "metadirective". * c-pragma.h (enum pragma_kind): Add PRAGMA_OMP_METADIRECTIVE. gcc/c/ChangeLog * c-parser.cc (struct c_parser): Add new fields for metadirectives. (c_parser_skip_to_end_of_block_or_statement): Add metadirective_p parameter; use it to control brace and parentheses behavior. (mangle_metadirective_region_label): New. (c_parser_label, c_parser_statement_after_labels): Use it. (c_parser_pragma): Handle metadirective. (c_parser_omp_context_selector): Add metadirective_p flag, use it to gate support for non-constant user condition. (c_parser_omp_context_selector_specification): Add metadirective_p argument. (c_parser_finish_omp_declare_variant): Adjust call to above. (analyze_metadirective_body): New. (c_parser_omp_metadirective): New. gcc/testsuite/ChangeLog * gcc.dg/gomp/metadirective-1.c: New. Co-Authored-By: Kwok Cheung Yeung Co-Authored-By: Sandra Loosemore --- gcc/c-family/c-common.h | 4 +- gcc/c-family/c-gimplify.cc | 27 ++ gcc/c-family/c-omp.cc | 60 ++- gcc/c-family/c-pragma.cc| 1 + gcc/c-family/c-pragma.h | 1 + gcc/c/c-parser.cc | 489 +++- gcc/testsuite/gcc.dg/gomp/metadirective-1.c | 15 + 7 files changed, 577 insertions(+), 20 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/gomp/metadirective-1.c diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h index 2d5f5399885..03f62571531 100644 --- a/gcc/c-family/c-common.h +++ b/gcc/c-family/c-common.h @@ -1391,7 +1391,8 @@ enum c_omp_directive_kind { C_OMP_DIR_CONSTRUCT, C_OMP_DIR_DECLARATIVE, C_OMP_DIR_UTILITY, - C_OMP_DIR_INFORMATIONAL + C_OMP_DIR_INFORMATIONAL, + C_OMP_DIR_META }; struct c_omp_directive { @@ -1405,6 +1406,7 @@ extern const struct c_omp_directive c_omp_directives[]; extern const struct c_omp_directive *c_omp_categorize_directive (const char *, const char *, const char *); +extern tree c_omp_expand_metadirective (vec &); /* Return next tree in the chain for chain_next walking of tree nodes. */ inline tree diff --git a/gcc/c-family/c-gimplify.cc b/gcc/c-family/c-gimplify.cc index 494da49791d..c53aca60bcf 100644 --- a/gcc/c-family/c-gimplify.cc +++ b/gcc/c-family/c-gimplify.cc @@ -43,6 +43,7 @@ along with GCC; see the file COPYING3. If not see #include "context.h" #include "tree-pass.h" #include "internal-fn.h" +#include "omp-general.h" /* The gimplification pass converts the language-dependent trees (ld-trees) emitted by the parser into language-independent trees @@ -485,6 +486,27 @@ genericize_omp_for_stmt (tree *stmt_p, int *walk_subtrees, void *data, finish_bc_block (&OMP_FOR_BODY (stmt), bc_continue, clab); } +/* Genericize a OMP_METADIRECTIVE node *STMT_P. */ + +static void +genericize_omp_metadirective_stmt (tree *stmt_p, int *walk_subtrees, + void *data, walk_tree_fn func, + walk_tree_lh lh) +{ + tree stmt = *stmt_p; + + for (tree variant = OMP_METADIRECTIVE_VARIANTS (stmt); + variant != NULL_TREE; + variant = TREE_CHAIN (variant)) +{ + walk_tree_1 (&OMP_METADIRECTIVE_VARIANT_DIRECTIVE (variant), + func, data, NULL, lh); + walk_tree_1 (&OMP_METADIRECTIVE_VARIANT_BODY (variant), + func, data, NULL, lh); +} + + *walk_subtrees = 0; +} /* Lower structured control flow tree nodes, such as loops. The STMT_P, WALK_SUBTREES, and DATA arguments are as for the walk_tree_fn @@ -533,6 +555,11 @@ c_genericize_control_stmt (tree *stmt_p, int *walk_subtrees, void *data, genericize_omp_for_stmt (stmt_p, walk_subtrees, data, func, lh); break; +case OMP_METADIRECTIVE: + genericize_omp_metadirective_stmt (stmt_p, walk_subt
[PATCH v2 01/12] OpenMP: metadirective tree data structures and front-end interfaces
This patch adds the OMP_METADIRECTIVE tree node and shared tree-level support for manipulating metadirectives. It defines/exposes interfaces that will be used in subsequent patches that add front-end and middle-end support, but nothing generates these nodes yet. This patch also adds compile-time support for dynamic context selectors (the target_device selector set and the condition selector of the user selector set) for metadirectives only. The "declare variant" directive still supports only static selectors. gcc/ChangeLog * Makefile.in (GTFILES): Move omp-general.h earlier in the list. * builtin-types.def (BT_FN_BOOL_INT_CONST_PTR_CONST_PTR_CONST_PTR): New. * doc/generic.texi (OpenMP): Document OMP_METADIRECTIVE and context selector interfaces. * omp-builtins.def (BUILT_IN_GOMP_EVALUATE_TARGET_DEVICE): New. * omp-general.cc (omp_check_context_selector): Add metadirective_p parameter, use it to conditionalize target_device support. (make_omp_metadirective_variant): New. (omp_context_selector_matches): Add metadirective_p and delay_p parameters, use them to control things that can only be matched late. Handle OMP_TRAIT_SET_TARGET_DEVICE. (score_wide_int): Move definition to omp-general.h. (omp_encode_kind_arch_isa_props): New. (omp_dynamic_cond): New. (omp_context_compute_score): Handle OMP_TRAIT_SET_TARGET_DEVICE. (omp_resolve_late_declare_variant, omp_resolve_declare_variant): Adjust calls to omp_context_selector_matches. (sort_variant): New. (omp_get_dynamic_candidates): New. (omp_early_resolve_metadirective): New. * omp-general.h (score_wide_int): Moved here from omp-general.cc. (struct omp_variant): New. (OMP_METADIRECTIVE_VARIANT_SELECTOR): New. (OMP_METADIRECTIVE_VARIANT_DIRECTIVE): New. (OMP_METADIRECTIVE_VARIANT_BODY): New. (make_omp_metadirective_variant): Declare. (omp_check_context_selector): Adjust to match definition. (omp_context_selector_matches): Likewise. (omp_early_resolve_metadirective): New. * tree-pretty-print.cc (dump_omp_context_selector): Remove static qualifier. (dump_generic_node): Handle OMP_METADIRECTIVE. * tree-pretty-print.h (dump_omp_context_selector): Declare. * tree.def (OMP_METADIRECTIVE): New. * tree.h (OMP_METADIRECTIVE_VARIANTS): New. gcc/c/ChangeLog * c-parser.cc (c_finish_omp_declare_variant): Update calls to omp_check_context_selector and omp_context_selector_matches. gcc/cp/ChangeLog * decl.cc (omp_declare_variant_finalize_one): Update call to omp_context_selector_matches to pass additional arguments. * parser.cc (cp_finish_omp_declare_variant): Likewise for omp_check_context_selector. gcc/fortran/ChangeLog * trans-openmp.cc (gfc_trans_omp_declare_variant): Update calls to omp_check_context_selector and omp_context_selector_matches. * types.def (BT_FN_BOOL_INT_CONST_PTR_CONST_PTR_CONST_PTR): New. Co-Authored-By: Kwok Cheung Yeung Co-Authored-By: Sandra Loosemore --- gcc/Makefile.in | 2 +- gcc/builtin-types.def | 2 + gcc/c/c-parser.cc | 4 +- gcc/cp/decl.cc | 2 +- gcc/cp/parser.cc| 2 +- gcc/doc/generic.texi| 32 gcc/fortran/trans-openmp.cc | 4 +- gcc/fortran/types.def | 2 + gcc/omp-builtins.def| 3 + gcc/omp-general.cc | 357 ++-- gcc/omp-general.h | 31 +++- gcc/tree-pretty-print.cc| 36 +++- gcc/tree-pretty-print.h | 2 + gcc/tree.def| 6 + gcc/tree.h | 3 + 15 files changed, 461 insertions(+), 27 deletions(-) diff --git a/gcc/Makefile.in b/gcc/Makefile.in index a7f15694c34..d08889a3cec 100644 --- a/gcc/Makefile.in +++ b/gcc/Makefile.in @@ -2869,6 +2869,7 @@ GTFILES = $(CPPLIB_H) $(srcdir)/input.h $(srcdir)/coretypes.h \ $(srcdir)/tree-ssa-operands.h \ $(srcdir)/tree-profile.cc $(srcdir)/tree-nested.cc \ $(srcdir)/omp-offload.h \ + $(srcdir)/omp-general.h \ $(srcdir)/omp-general.cc \ $(srcdir)/omp-low.cc \ $(srcdir)/targhooks.cc $(out_file) $(srcdir)/passes.cc \ @@ -2895,7 +2896,6 @@ GTFILES = $(CPPLIB_H) $(srcdir)/input.h $(srcdir)/coretypes.h \ $(srcdir)/ipa-strub.cc \ $(srcdir)/internal-fn.h \ $(srcdir)/calls.cc \ - $(srcdir)/omp-general.h \ $(srcdir)/analyzer/analyzer-language.cc \ @all_gtfiles@ diff --git a/gcc/builtin-types.def b/gcc/builtin-types.def index c97d6bad1de..605a38ab84d 100644 --- a/gcc/builtin-types.def +++ b/gcc/builtin-types.def @@ -878,6 +878,8 @@ DEF_FUNCTION_TYPE_4 (BT_FN_VOID_UINT_PTR_INT_PTR, BT_VOID, BT_INT, BT_PTR, BT_INT, BT_PTR) DEF_FUNCTION_TYPE_4 (BT_FN_BOOL_UINT_UINT
[PATCH v2 00/12] OpenMP: Metadirective support + "declare variant" improvements
This is an updated version of the patch series I posted a few weeks ago: https://gcc.gnu.org/pipermail/gcc-patches/2024-May/650725.html I won't duplicate the full list of things implemented/fixed here from the original patch mail. The incremental changes since then include: * I rebased the entire patch series against mainline head, as the previous set wouldn't apply cleanly any more. * I have fixed the previously-noted test regression in declare-variant-1.f90. (The fix is the new patch hunks to tree-nested.cc that I have folded into part 2.) * While working on that, I also made some tweaks to the raw-format pretty print support, also incorporated into part 2. * After I posted the previous patch set, the Linaro CI testbot reported a failure in c-c++-common/gomp/declare-variant-13.c on aarch64. That should be fixed now too (incorporated into part 9). So, other than rebasing, the only substantive changes from the last version are in parts 2 and 9. I'm still reserving the previously-noted problems related to PR113904 for some future follow-up work. This is already a large patch set and it would be helpful to get it reviewed before layering on more changes to "declare variant" that touch the same code. -Sandra Sandra Loosemore (12): OpenMP: metadirective tree data structures and front-end interfaces OpenMP: middle-end support for metadirectives libgomp: runtime support for target_device selector OpenMP: C front end support for metadirectives OpenMP: C++ front-end support for metadirectives OpenMP: common c/c++ testcases for metadirectives OpenMP: Fortran front-end support for metadirectives. OpenMP: Reject other properties with kind(any) OpenMP: Extend dynamic selector support to declare variant OpenMP: Remove dead code from declare variant reimplementation OpenMP: Update "declare target"/OpenMP context interaction OpenMP: Update documentation of metadirective implementation status. gcc/Makefile.in |2 +- gcc/builtin-types.def |2 + gcc/c-family/c-attribs.cc |2 - gcc/c-family/c-common.h |4 +- gcc/c-family/c-gimplify.cc| 27 + gcc/c-family/c-omp.cc | 60 +- gcc/c-family/c-pragma.cc |1 + gcc/c-family/c-pragma.h |1 + gcc/c/c-decl.cc |8 +- gcc/c/c-parser.cc | 473 +++- gcc/cgraph.cc |2 - gcc/cgraph.h | 12 +- gcc/cgraphclones.cc |2 +- gcc/cp/cp-tree.h |2 + gcc/cp/decl.cc|2 +- gcc/cp/decl2.cc |9 +- gcc/cp/parser.cc | 526 - gcc/cp/parser.h |7 + gcc/cp/pt.cc | 120 + gcc/cp/semantics.cc |3 +- gcc/doc/generic.texi | 32 + gcc/doc/gimple.texi |6 + gcc/fortran/decl.cc | 29 + gcc/fortran/dump-parse-tree.cc| 21 + gcc/fortran/gfortran.h| 20 +- gcc/fortran/io.cc |2 +- gcc/fortran/match.h |2 + gcc/fortran/openmp.cc | 294 ++- gcc/fortran/parse.cc | 571 +++-- gcc/fortran/parse.h |8 +- gcc/fortran/resolve.cc|6 + gcc/fortran/st.cc |4 + gcc/fortran/symbol.cc | 25 +- gcc/fortran/trans-decl.cc |5 +- gcc/fortran/trans-openmp.cc | 238 +- gcc/fortran/trans-stmt.h |1 + gcc/fortran/trans.cc |1 + gcc/fortran/types.def |2 + gcc/gimple-low.cc | 36 + gcc/gimple-pretty-print.cc| 78 + gcc/gimple-streamer-in.cc | 13 + gcc/gimple-streamer-out.cc| 10 + gcc/gimple-walk.cc| 28 + gcc/gimple.cc | 36 + gcc/gimple.def|8 + gcc/gimple.h | 122 +- gcc/gimplify.cc | 574 +++-- gcc/gimplify.h|2 +- gcc/gsstruct.def |2 + gcc/ipa-free-lang-data.cc |2 +- gcc/ipa.cc|3 - gcc/lto-cgraph.cc | 12 +- gcc/lto-streamer-out.cc
Re: [Patch] Fortran: invoke.texi - link to OpenCoarrays.org + mention libcaf_single
On 5/19/24 02:01, Tobias Burnus wrote: I noticed that gfortran's coarray support did not link to the http://www.opencoarrays.org/ > [snip] diff --git a/gcc/fortran/invoke.texi b/gcc/fortran/invoke.texi index 40e8e4a7cdd..78a2910b8d8 100644 --- a/gcc/fortran/invoke.texi +++ b/gcc/fortran/invoke.texi @@ -1753,7 +1753,10 @@ Single-image mode, i.e. @code{num_images()} is always one. @item @samp{lib} Library-based coarray parallelization; a suitable GNU Fortran coarray -library needs to be linked. +library needs to be linked such as @url{http://opencoarrays.org}. This would read better as library such as @url{http://opencoarrays.org} needs to be linked. +Alternatively, GCC's @code{libcaf_single} library can be linked, +albeit it only supports a single image. + @end table OK with that tweak. -Sandra
[PATCH 09/12] OpenMP: Extend dynamic selector support to declare variant
This patch extends the mechanisms previously added to support dynamic selectors in metavariant constructs to also apply to "declare variant". The front-end mechanisms used to handle "declare variant" via attributes attached to the function decls remain the same, but the gimplifier now uses the same internal data structures and helper functions as metadirective to score and sort "declare variant" alternatives, and constructs a gomp_metadirective node for variant calls that cannot be resolved at gimplification time. During late resolution, this gomp_metadirective is processed in exactly the same way as for real metadirectives. During implementation of this functionality, a number of bugs were discovered in the previous selector scoring and matching code: * Metadirective resolution was failing to account for scoring in "declare simd" clones, and was also relying on calling a function to match construct constructors that's only useful during gimplification during late resolution long after that pass. * The construct constructor scoring was previously implemented backwards from the specification (PR114596); a number of testcases were also broken in the same way as the implementation. * The special rules for matching simdlen and aligned properties on simd selectors were not implemented (nor were these properties on metadirectives being rejected per the OpenMP spec). This patch includes a new implementation of this functionality that has cleaner interfaces and is hopefully(!) easier to correlate to requirements of the OpenMP specification. Instead of relying on the gimplifier to score construct selectors, the scoring code has been consolidated in omp-general.cc with the gimplifier only providing the OpenMP construct context surrounding the metadirective or variant call. This is cached on the gomp_metadirective if necessary for late resolution. An additional improvement added in this patch is that for both metadirective and "declare variant", if late resolution is required the gimplifier now discards all alternatives that are known not to match. Note that this patch leaves a substantial amount of dead code that was used to support the former late "declare variant" resolution strategy, notably the declare_variant_alt and calls_declare_variant_alt flags on cgraph_node and all the code that touches those fields. The next patch in this series removes that unused code. Another issue not addressed in this patch is the special scoping rules for expressions in "declare variant" dynamic selectors, which is still under discussion in PR113904. We expect this to be fixed separately. gcc/c/ChangeLog * c-parser.c (c_parser_omp_context_selector): Remove metadirective_p parameter and conditionalization. (c_parser_omp_context_selector_specification): Remove metadirective_p parameter and adjust call not to pass it on. (c_finish_omp_declare_variant): Adjust arguments on calls to c_parser_omp_context_selector_specification and omp_context_selector_matches. (c_parser_omp_metadirective): Likewise. gcc/cp/ChangeLog * cp-tree.h (struct saved_scope): Add new field x_processing_omp_trait_property_expr. (processing_omp_trait_property_expr): Define * decl.cc (omp_declare_variant_finalize_one): Adjust arguments to omp_context_selector_matches. * parser.cc (cp_parser_omp_context_selector): Remove metadirective_p argument and conditionalization. (cp_parser_omp_context_selector_specification): Remove metadirective_p argument and adjust call not to pass it on. (cp_finish_omp_declare_variant): Adjust arguments on call to above. (cp_parser_omp_metadirective): Likewise. * pt.cc (tsubst_omp_context_selector): Adjust error behavior. (tsubst_stmt): Adjust call to omp_context_selector_matches. * semantics.cc (finish_id_expression_1): Do not diagnose error for use of parameter in declare variant selector here. gcc/fortran/ChangeLog * trans-openmp.cc (gfc_trans_omp_declare_variant): Adjust arguments to omp_context_selector_matches. (gfc_trans_omp_metadirective): Likewise. gcc/Changelog * gimple-streamer-in.cc (input_gimple_stmt): Restore gomp_metadirective context. * gimple-streamer-out.cc (output_gimple_stmt): Save gomp_metadirective context. * gimple.cc (gimple_build_omp_metadirective): Initialize gomp_metadirective context. * gimple.def (GIMPLE_OMP_METADIRECTIVE): Update comments. * gimple.h (gomp_metadirective): Add context field and update comments. (gimple_omp_metadirective_context): New. (gimple_omp_metadirective_set_context): New. * gimplify.cc (omp_resolved_variant_calls): New. (gimplify_variant_call_expr): New. (gimplify_call_expr): Adjust parameters. Call gimplify_variant_call_expr to handle declar
[PATCH 07/12] OpenMP: Fortran front-end support for metadirectives.
etadirective test. * gfortran.dg/gomp/pure-2.f90: Remove metadirective test. libgomp/ChangeLog * testsuite/libgomp.fortran/metadirective-1.f90: New. * testsuite/libgomp.fortran/metadirective-2.f90: New. * testsuite/libgomp.fortran/metadirective-3.f90: New. * testsuite/libgomp.fortran/metadirective-4.f90: New. * testsuite/libgomp.fortran/metadirective-5.f90: New. * testsuite/libgomp.fortran/metadirective-6.f90: New. Co-Authored-By: Kwok Cheung Yeung Co-Authored-By: Sandra Loosemore Co-Authored-By: Tobias Burnus Co-Authored-By: Paul-Antoine Arras --- gcc/fortran/decl.cc | 29 + gcc/fortran/dump-parse-tree.cc| 21 + gcc/fortran/gfortran.h| 20 +- gcc/fortran/io.cc | 2 +- gcc/fortran/match.h | 2 + gcc/fortran/openmp.cc | 294 +++-- gcc/fortran/parse.cc | 571 +++--- gcc/fortran/parse.h | 8 +- gcc/fortran/resolve.cc| 6 + gcc/fortran/st.cc | 4 + gcc/fortran/symbol.cc | 25 +- gcc/fortran/trans-decl.cc | 5 +- gcc/fortran/trans-openmp.cc | 233 --- gcc/fortran/trans-stmt.h | 1 + gcc/fortran/trans.cc | 1 + .../gfortran.dg/gomp/metadirective-1.f90 | 55 ++ .../gfortran.dg/gomp/metadirective-10.f90 | 40 ++ .../gfortran.dg/gomp/metadirective-11.f90 | 33 + .../gfortran.dg/gomp/metadirective-2.f90 | 62 ++ .../gfortran.dg/gomp/metadirective-3.f90 | 34 ++ .../gfortran.dg/gomp/metadirective-4.f90 | 39 ++ .../gfortran.dg/gomp/metadirective-5.f90 | 30 + .../gfortran.dg/gomp/metadirective-6.f90 | 31 + .../gfortran.dg/gomp/metadirective-7.f90 | 36 ++ .../gfortran.dg/gomp/metadirective-8.f90 | 22 + .../gfortran.dg/gomp/metadirective-9.f90 | 30 + .../gomp/metadirective-construct.f90 | 260 .../gomp/metadirective-no-score.f90 | 122 gcc/testsuite/gfortran.dg/gomp/pure-1.f90 | 7 + gcc/testsuite/gfortran.dg/gomp/pure-2.f90 | 8 - .../libgomp.fortran/metadirective-1.f90 | 61 ++ .../libgomp.fortran/metadirective-2.f90 | 40 ++ .../libgomp.fortran/metadirective-3.f90 | 29 + .../libgomp.fortran/metadirective-4.f90 | 46 ++ .../libgomp.fortran/metadirective-5.f90 | 44 ++ .../libgomp.fortran/metadirective-6.f90 | 58 ++ 36 files changed, 1947 insertions(+), 362 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/gomp/metadirective-1.f90 create mode 100644 gcc/testsuite/gfortran.dg/gomp/metadirective-10.f90 create mode 100644 gcc/testsuite/gfortran.dg/gomp/metadirective-11.f90 create mode 100644 gcc/testsuite/gfortran.dg/gomp/metadirective-2.f90 create mode 100644 gcc/testsuite/gfortran.dg/gomp/metadirective-3.f90 create mode 100644 gcc/testsuite/gfortran.dg/gomp/metadirective-4.f90 create mode 100644 gcc/testsuite/gfortran.dg/gomp/metadirective-5.f90 create mode 100644 gcc/testsuite/gfortran.dg/gomp/metadirective-6.f90 create mode 100644 gcc/testsuite/gfortran.dg/gomp/metadirective-7.f90 create mode 100644 gcc/testsuite/gfortran.dg/gomp/metadirective-8.f90 create mode 100644 gcc/testsuite/gfortran.dg/gomp/metadirective-9.f90 create mode 100644 gcc/testsuite/gfortran.dg/gomp/metadirective-construct.f90 create mode 100644 gcc/testsuite/gfortran.dg/gomp/metadirective-no-score.f90 create mode 100644 libgomp/testsuite/libgomp.fortran/metadirective-1.f90 create mode 100644 libgomp/testsuite/libgomp.fortran/metadirective-2.f90 create mode 100644 libgomp/testsuite/libgomp.fortran/metadirective-3.f90 create mode 100644 libgomp/testsuite/libgomp.fortran/metadirective-4.f90 create mode 100644 libgomp/testsuite/libgomp.fortran/metadirective-5.f90 create mode 100644 libgomp/testsuite/libgomp.fortran/metadirective-6.f90 diff --git a/gcc/fortran/decl.cc b/gcc/fortran/decl.cc index b8308aeee55..b6633a913e7 100644 --- a/gcc/fortran/decl.cc +++ b/gcc/fortran/decl.cc @@ -8422,6 +8422,7 @@ gfc_match_end (gfc_statement *st) case COMP_CONTAINS: case COMP_DERIVED_CONTAINS: +case COMP_OMP_BEGIN_METADIRECTIVE: state = gfc_state_stack->previous->state; block_name = gfc_state_stack->previous->sym == NULL ? NULL : gfc_state_stack->previous->sym->name; @@ -8429,6 +8430,28 @@ gfc_match_end (gfc_statement *st) && gfc_state_stack->previous->sym->abr_modproc_decl; break; +case COMP_OMP_METADIRECTIVE: + { + /* Metadirectives can be nested, so we need to drill down to the + first state that is not COMP_OMP_METADIRECTIVE. */ + gfc_state_data *state_data = gfc_state_stack; + + d
[PATCH 11/12] OpenMP: Update "declare target"/OpenMP context interaction
The code and test case previously implemented the OpenMP 5.0 spec, which said in section 2.3.1: "For functions within a declare target block, the target trait is added to the beginning of the set..." In OpenMP 5.1, this was changed to "For device routines, the target trait is added to the beginning of the set..." In OpenMP 5.2 and TR12, it says: "For procedures that are determined to be target function variants by a declare target directive..." The definition of "device routine" in OpenMP 5.1 is confusing, but certainly the intent of the later versions of the spec is clear that it doesn't just apply to functions within a begin declare target/end declare target block. The only use of the "omp declare target block" function attribute was to support the 5.0 language, so it can be removed. This patch changes the context augmentation to use the "omp declare target" attribute instead. gcc/c-family/ChangeLog * c-attribs.cc (c_common_gnu_attributes): Delete "omp declare target block". gcc/c/ChangeLog * c-decl.cc (c_decl_attributes): Don't add "omp declare target block". gcc/cp/decl2.cc * decl2.cc (cplus_decl_attributes): Don't add "omp declare target block". gcc/ChangeLog * omp-general.cc (omp_complete_construct_context): Check "omp declare target" attribute, not "omp declare target block". gcc/testsuite/ChangeLog * c-c++-common/gomp/declare-target-indirect-2.c : Adjust expected output for removal of "omp declare target block". * c-c++-common/gomp/declare-variant-8.c: Likewise, the variant call to f20 is now resolved differently. * c-c++-common/gomp/reverse-offload-1.c: Adjust expected output. * gfortran.dg/gomp/declare-variant-8.f90: Likewise, both f18 and f20 now resolve to the variant. Delete obsolete comments. --- gcc/c-family/c-attribs.cc| 2 -- gcc/c/c-decl.cc | 8 ++-- gcc/cp/decl2.cc | 9 ++--- gcc/omp-general.cc | 2 +- .../c-c++-common/gomp/declare-target-indirect-2.c| 10 +- gcc/testsuite/c-c++-common/gomp/declare-variant-8.c | 4 ++-- gcc/testsuite/c-c++-common/gomp/reverse-offload-1.c | 2 +- gcc/testsuite/gfortran.dg/gomp/declare-variant-8.f90 | 12 ++-- 8 files changed, 15 insertions(+), 34 deletions(-) diff --git a/gcc/c-family/c-attribs.cc b/gcc/c-family/c-attribs.cc index 04e39b41bdf..582d99ada1b 100644 --- a/gcc/c-family/c-attribs.cc +++ b/gcc/c-family/c-attribs.cc @@ -570,8 +570,6 @@ const struct attribute_spec c_common_gnu_attributes[] = handle_omp_declare_target_attribute, NULL }, { "omp declare target nohost", 0, 0, true, false, false, false, handle_omp_declare_target_attribute, NULL }, - { "omp declare target block", 0, 0, true, false, false, false, - handle_omp_declare_target_attribute, NULL }, { "non overlapping", 0, 0, true, false, false, false, handle_non_overlapping_attribute, NULL }, { "alloc_align", 1, 1, false, true, true, false, diff --git a/gcc/c/c-decl.cc b/gcc/c/c-decl.cc index 52af8f32998..4ab7cd86030 100644 --- a/gcc/c/c-decl.cc +++ b/gcc/c/c-decl.cc @@ -5414,12 +5414,8 @@ c_decl_attributes (tree *node, tree attributes, int flags) attributes = tree_cons (get_identifier ("omp declare target implicit"), NULL_TREE, attributes); else - { - attributes = tree_cons (get_identifier ("omp declare target"), - NULL_TREE, attributes); - attributes = tree_cons (get_identifier ("omp declare target block"), - NULL_TREE, attributes); - } + attributes = tree_cons (get_identifier ("omp declare target"), + NULL_TREE, attributes); if (TREE_CODE (*node) == FUNCTION_DECL) { int device_type diff --git a/gcc/cp/decl2.cc b/gcc/cp/decl2.cc index 806a2a4bc69..028105a5b26 100644 --- a/gcc/cp/decl2.cc +++ b/gcc/cp/decl2.cc @@ -1777,13 +1777,8 @@ cplus_decl_attributes (tree *decl, tree attributes, int flags) = tree_cons (get_identifier ("omp declare target implicit"), NULL_TREE, attributes); else - { - attributes = tree_cons (get_identifier ("omp declare target"), - NULL_TREE, attributes); - attributes - = tree_cons (get_identifier ("omp declare target block"), -NULL_TREE, attributes); - } + attributes = tree_cons (get_identifier ("omp declare target"), + NULL_TREE, attributes); if (TREE_CODE (*decl) == FUNCTION_DECL) {
[PATCH 10/12] OpenMP: Remove dead code from declare variant reimplementation
After reimplementing late resolution of "declare variant" to use the same mechanisms as metadirective, the declare_variant_alt and calls_declare_variant_alt flags on struct cgraph_node are no longer used by anything. For the purposes of marking functions that need late resolution, the has_metadirectives flag has replaced calls_declare_variant_alt. Likewise struct omp_declare_variant_entry, struct omp_declare_variant_base_entry, and the hash tables used to store these structures are no longer needed, since the information needed for late resolution is now stored in the gomp_metadirective nodes. There are no functional changes in this patch, just removing dead code. gcc/ChangeLog * cgraph.cc (symbol_table::create_edge): Don't set calls_declare_variant_alt in the caller. * cgraph.h (struct cgraph_node): Remove declare_variant_alt and calls_declare_variant_alt flags. * cgraphclones.cc (cgraph_node::create_clone): Don't copy calls_declare_variant_alt bit. * ipa-free-lang-data.cc (free_lang_data_in_decl): Adjust code referencing declare_variant_alt bit. * ipa.cc (symbol_table::remove_unreachable_nodes): Likewise. * lto-cgraph.cc (lto_output_node): Remove references to deleted bits. (output_refs): Adjust code referencing declare_variant_alt bit. (input_overwrite_node): Remove references to deleted bits. (input_refs): Adjust code referencing declare_variant_alt bit. * lto-streamer-out.cc (lto_output): Likewise. * lto-streamer.h (omp_lto_output_declare_variant_alt): Delete. (omp_lto_input_declare_variant_alt): Delete. * lto/lto-partition.cc (lto_balanced_map): Adjust code referencing deleted declare_variant_alt bit. * omp-expand.cc (expand_omp_target): Use has_metadirectives bit to trigger pass_omp_device_lower instead of calls_declare_variant_alt. * omp-general.cc (struct omp_declare_variant_entry): Delete. (struct omp_declare_variant_base_entry): Delete. (struct omp_declare_variant_hasher): Delete. (omp_declare_variant_hasher::hash): Delete. (omp_declare_variant_hasher::equal): Delete. (omp_declare_variants): Delete. (omp_declare_variant_alt_hasher): Delete. (omp_declare_variant_alt_hasher::hash): Delete. (omp_declare_variant_alt_hasher::equal): Delete. (omp_declare_variant_alt): Delete. (omp_lto_output_declare_variant_alt): Delete. (omp_lto_input_declare_variant_alt): Delete. (includes): Delete unnecessary include of gt-omp-general.h. * omp-offload.cc (execute_omp_device_lower): Remove references to deleted bit. (pass_omp_device_lower::gate): Likewise. * omp-simd-clone.cc (simd_clone_create): Likewise. * passes.cc (ipa_write_summaries): Likeise. * symtab.cc (symtab_node::get_partitioning_class): Likewise. * tree-inline.cc (expand_call_inline): Likewise. (tree_function_versioning): Likewise. --- gcc/cgraph.cc | 2 - gcc/cgraph.h | 11 +- gcc/cgraphclones.cc | 1 - gcc/ipa-free-lang-data.cc | 2 +- gcc/ipa.cc| 3 - gcc/lto-cgraph.cc | 10 -- gcc/lto-streamer-out.cc | 3 +- gcc/lto-streamer.h| 6 -- gcc/lto/lto-partition.cc | 5 +- gcc/omp-expand.cc | 2 +- gcc/omp-general.cc| 218 -- gcc/omp-offload.cc| 8 +- gcc/omp-simd-clone.cc | 2 - gcc/passes.cc | 3 +- gcc/symtab.cc | 2 +- gcc/tree-inline.cc| 4 - 16 files changed, 10 insertions(+), 272 deletions(-) diff --git a/gcc/cgraph.cc b/gcc/cgraph.cc index 473d8410bc9..103bc2c0332 100644 --- a/gcc/cgraph.cc +++ b/gcc/cgraph.cc @@ -931,8 +931,6 @@ symbol_table::create_edge (cgraph_node *caller, cgraph_node *callee, caller->decl); else edge->in_polymorphic_cdtor = caller->thunk; - if (callee) -caller->calls_declare_variant_alt |= callee->declare_variant_alt; if (callee && symtab->state != LTO_STREAMING && edge->callee->comdat_local_p ()) diff --git a/gcc/cgraph.h b/gcc/cgraph.h index 6653ce19c3e..dd210842df7 100644 --- a/gcc/cgraph.h +++ b/gcc/cgraph.h @@ -897,10 +897,8 @@ struct GTY((tag ("SYMTAB_FUNCTION"))) cgraph_node : public symtab_node split_part (false), indirect_call_target (false), local (false), versionable (false), can_change_signature (false), redefined_extern_inline (false), tm_may_enter_irr (false), - ipcp_clone (false), declare_variant_alt (false), - calls_declare_variant_alt (false), gc_candidate (false), - called_by_ifunc_resolver (false), - has_metadirectives (false), + ipcp_clone (false), gc_candidate (false), + called_by_ifunc_resolver (false), has_metadirectives (false), m_uid (uid), m_summary_id (-1)
[PATCH 05/12] OpenMP: C++ front-end support for metadirectives
This patch adds C++ support for metadirectives. It uses the c-family support committed with the corresponding C front end patch to do early parse-time metadirective resolution when possible. Additional C/C++ common testcases are provided in a subsequent patch in the series. gcc/cp/ChangeLog * parser.cc (cp_parser_skip_to_end_of_block_or_statement): Add metadirective_p parameter, use it to control brace/parentheses behavior for metadirectives. (mangle_metadirective_region_label): New. (cp_parser_label_for_labeled_statement): Use it. (cp_parser_jump_statement): Likewise. (cp_parser_omp_context_selector): Add metadirective_p parameter, use it to control error behavior for non-constant exprs properties. (cp_parser_omp_context_selector_specification): Add metadirective_p parameter, use it for cp_parser_omp_context_selector call. (cp_finish_omp_declare_variant): Adjust call to cp_parser_omp_context_selector_specification. (analyze_metadirective_body): New. (cp_parser_omp_metadirective): New. (cp_parser_pragma): Handle PRAGMA_OMP_METADIRECTIVE. * parser.h (struct cp_parser): Add fields for metadirective parsing state. * pt.cc (tsubst_omp_context_selector): New. (tsubst_stmt): Handle OMP_METADIRECTIVE. gcc/testsuite/ChangeLog * g++.dg/gomp/attrs-metadirective-1.C: New. * g++.dg/gomp/attrs-metadirective-2.C: New. * g++.dg/gomp/attrs-metadirective-3.C: New. * g++.dg/gomp/attrs-metadirective-4.C: New. * g++.dg/gomp/attrs-metadirective-5.C: New. * g++.dg/gomp/attrs-metadirective-6.C: New. * g++.dg/gomp/attrs-metadirective-7.C: New. * g++.dg/gomp/attrs-metadirective-8.C: New. libgomp/ChangeLog * testsuite/libgomp.c++/metadirective-template-1.C: New. * testsuite/libgomp.c++/metadirective-template-2.C: New. * testsuite/libgomp.c++/metadirective-template-3.C: New. Co-Authored-By: Kwok Cheung Yeung Co-Authored-By: Sandra Loosemore --- gcc/cp/parser.cc | 524 +- gcc/cp/parser.h | 7 + gcc/cp/pt.cc | 119 .../g++.dg/gomp/attrs-metadirective-1.C | 40 ++ .../g++.dg/gomp/attrs-metadirective-2.C | 74 +++ .../g++.dg/gomp/attrs-metadirective-3.C | 31 ++ .../g++.dg/gomp/attrs-metadirective-4.C | 41 ++ .../g++.dg/gomp/attrs-metadirective-5.C | 24 + .../g++.dg/gomp/attrs-metadirective-6.C | 31 ++ .../g++.dg/gomp/attrs-metadirective-7.C | 31 ++ .../g++.dg/gomp/attrs-metadirective-8.C | 16 + .../libgomp.c++/metadirective-template-1.C| 37 ++ .../libgomp.c++/metadirective-template-2.C| 41 ++ .../libgomp.c++/metadirective-template-3.C| 41 ++ 14 files changed, 1044 insertions(+), 13 deletions(-) create mode 100644 gcc/testsuite/g++.dg/gomp/attrs-metadirective-1.C create mode 100644 gcc/testsuite/g++.dg/gomp/attrs-metadirective-2.C create mode 100644 gcc/testsuite/g++.dg/gomp/attrs-metadirective-3.C create mode 100644 gcc/testsuite/g++.dg/gomp/attrs-metadirective-4.C create mode 100644 gcc/testsuite/g++.dg/gomp/attrs-metadirective-5.C create mode 100644 gcc/testsuite/g++.dg/gomp/attrs-metadirective-6.C create mode 100644 gcc/testsuite/g++.dg/gomp/attrs-metadirective-7.C create mode 100644 gcc/testsuite/g++.dg/gomp/attrs-metadirective-8.C create mode 100644 libgomp/testsuite/libgomp.c++/metadirective-template-1.C create mode 100644 libgomp/testsuite/libgomp.c++/metadirective-template-2.C create mode 100644 libgomp/testsuite/libgomp.c++/metadirective-template-3.C diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index 8b819b2ebfd..4bb9b086095 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -3001,7 +3001,7 @@ static void cp_parser_skip_to_end_of_statement static void cp_parser_consume_semicolon_at_end_of_statement (cp_parser *); static void cp_parser_skip_to_end_of_block_or_statement - (cp_parser *); + (cp_parser *, bool = false); static bool cp_parser_skip_to_closing_brace (cp_parser *); static bool cp_parser_skip_entire_template_parameter_list @@ -4177,9 +4177,11 @@ cp_parser_consume_semicolon_at_end_of_statement (cp_parser *parser) have consumed a non-nested `;'. */ static void -cp_parser_skip_to_end_of_block_or_statement (cp_parser* parser) +cp_parser_skip_to_end_of_block_or_statement (cp_parser* parser, +bool metadirective_p) { int nesting_depth = 0; + int bracket_depth = 0; /* Unwind generic function template scope if necessary. */ if (parser->fully_implicit_function_template_p) @@ -4201,7 +4203,7 @@ cp_parser_skip_to_end_of_block_or_statement (cp_parser* parser) case CPP_SEMICOLON: /* Stop if this is an unnested ';'. */ - if (!nesting_d
[PATCH 06/12] OpenMP: common c/c++ testcases for metadirectives
gcc/testsuite/ChangeLog * c-c++-common/gomp/metadirective-1.c: New. * c-c++-common/gomp/metadirective-2.c: New. * c-c++-common/gomp/metadirective-3.c: New. * c-c++-common/gomp/metadirective-4.c: New. * c-c++-common/gomp/metadirective-5.c: New. * c-c++-common/gomp/metadirective-6.c: New. * c-c++-common/gomp/metadirective-7.c: New. * c-c++-common/gomp/metadirective-8.c: New. * c-c++-common/gomp/metadirective-construct.c: New. * c-c++-common/gomp/metadirective-device.c: New. * c-c++-common/gomp/metadirective-no-score.c: New. * c-c++-common/gomp/metadirective-target-device.c: New. libgomp/ChangeLog * testsuite/libgomp.c-c++-common/metadirective-1.c: New. * testsuite/libgomp.c-c++-common/metadirective-2.c: New. * testsuite/libgomp.c-c++-common/metadirective-3.c: New. * testsuite/libgomp.c-c++-common/metadirective-4.c: New. * testsuite/libgomp.c-c++-common/metadirective-5.c: New. Co-Authored-By: Kwok Cheung Yeung Co-Authored-By: Sandra Loosemore --- .../c-c++-common/gomp/metadirective-1.c | 52 + .../c-c++-common/gomp/metadirective-2.c | 74 .../c-c++-common/gomp/metadirective-3.c | 31 +++ .../c-c++-common/gomp/metadirective-4.c | 40 .../c-c++-common/gomp/metadirective-5.c | 24 +++ .../c-c++-common/gomp/metadirective-6.c | 31 +++ .../c-c++-common/gomp/metadirective-7.c | 31 +++ .../c-c++-common/gomp/metadirective-8.c | 16 ++ .../gomp/metadirective-construct.c| 177 ++ .../c-c++-common/gomp/metadirective-device.c | 147 +++ .../gomp/metadirective-no-score.c | 95 ++ .../gomp/metadirective-target-device.c| 147 +++ .../libgomp.c-c++-common/metadirective-1.c| 35 .../libgomp.c-c++-common/metadirective-2.c| 41 .../libgomp.c-c++-common/metadirective-3.c| 34 .../libgomp.c-c++-common/metadirective-4.c| 52 + .../libgomp.c-c++-common/metadirective-5.c| 46 + 17 files changed, 1073 insertions(+) create mode 100644 gcc/testsuite/c-c++-common/gomp/metadirective-1.c create mode 100644 gcc/testsuite/c-c++-common/gomp/metadirective-2.c create mode 100644 gcc/testsuite/c-c++-common/gomp/metadirective-3.c create mode 100644 gcc/testsuite/c-c++-common/gomp/metadirective-4.c create mode 100644 gcc/testsuite/c-c++-common/gomp/metadirective-5.c create mode 100644 gcc/testsuite/c-c++-common/gomp/metadirective-6.c create mode 100644 gcc/testsuite/c-c++-common/gomp/metadirective-7.c create mode 100644 gcc/testsuite/c-c++-common/gomp/metadirective-8.c create mode 100644 gcc/testsuite/c-c++-common/gomp/metadirective-construct.c create mode 100644 gcc/testsuite/c-c++-common/gomp/metadirective-device.c create mode 100644 gcc/testsuite/c-c++-common/gomp/metadirective-no-score.c create mode 100644 gcc/testsuite/c-c++-common/gomp/metadirective-target-device.c create mode 100644 libgomp/testsuite/libgomp.c-c++-common/metadirective-1.c create mode 100644 libgomp/testsuite/libgomp.c-c++-common/metadirective-2.c create mode 100644 libgomp/testsuite/libgomp.c-c++-common/metadirective-3.c create mode 100644 libgomp/testsuite/libgomp.c-c++-common/metadirective-4.c create mode 100644 libgomp/testsuite/libgomp.c-c++-common/metadirective-5.c diff --git a/gcc/testsuite/c-c++-common/gomp/metadirective-1.c b/gcc/testsuite/c-c++-common/gomp/metadirective-1.c new file mode 100644 index 000..37b56237531 --- /dev/null +++ b/gcc/testsuite/c-c++-common/gomp/metadirective-1.c @@ -0,0 +1,52 @@ +/* { dg-do compile } */ + +#define N 100 + +void f (int a[], int b[], int c[]) +{ + int i; + + #pragma omp metadirective \ + default (teams loop) \ + default (parallel loop) /* { dg-error "too many 'otherwise' or 'default' clauses in 'metadirective'" } */ +for (i = 0; i < N; i++) c[i] = a[i] * b[i]; + + #pragma omp metadirective \ + otherwise (teams loop) \ + default (parallel loop) /* { dg-error "too many 'otherwise' or 'default' clauses in 'metadirective'" } */ +for (i = 0; i < N; i++) c[i] = a[i] * b[i]; + + #pragma omp metadirective \ + otherwise (teams loop) \ + otherwise (parallel loop) /* { dg-error "too many 'otherwise' or 'default' clauses in 'metadirective'" } */ +for (i = 0; i < N; i++) c[i] = a[i] * b[i]; + + #pragma omp metadirective \ + default (bad_directive) /* { dg-error "unknown directive name before '\\)' token" } */ +for (i = 0; i < N; i++) c[i] = a[i] * b[i]; + + #pragma omp metadirective \ + default (teams loop) \ + where (device={arch("nvptx")}: parallel loop) /* { dg-error "'where' is not valid for 'metadirective'"
[PATCH 08/12] OpenMP: Reject other properties with kind(any)
The OpenMP spec says: "If trait-property any is specified in the kind trait-selector of the device selector set or the target_device selector sets, no other trait-property may be specified in the same selector set." GCC was not previously enforcing this restriction and several testcases included such valid constructs. This patch fixes it. gcc/ChangeLog * omp-general.cc (omp_check_context_selector): Reject other properties in the same selector set with kind(any). gcc/testsuite/ChangeLog * c-c++-common/gomp/declare-variant-10.c: Fix broken tests. * c-c++-common/gomp/declare-variant-3.c: Likewise. * c-c++-common/gomp/declare-variant-9.c: Likewise. * c-c++-common/gomp/declare-variant-any.c: New. * gfortran.dg/gomp/declare-variant-10.f90: Fix broken tests. * gfortran.dg/gomp/declare-variant-3.f90: Likewise. * gfortran.dg/gomp/declare-variant-9.f90: Likewise. * gfortran.dg/gomp/declare-variant-any.f90: Likewise. --- gcc/omp-general.cc| 31 +++ .../c-c++-common/gomp/declare-variant-10.c| 4 +-- .../c-c++-common/gomp/declare-variant-3.c | 10 ++ .../c-c++-common/gomp/declare-variant-9.c | 4 +-- .../c-c++-common/gomp/declare-variant-any.c | 10 ++ .../gfortran.dg/gomp/declare-variant-10.f90 | 4 +-- .../gfortran.dg/gomp/declare-variant-3.f90| 12 ++- .../gfortran.dg/gomp/declare-variant-9.f90| 2 +- .../gfortran.dg/gomp/declare-variant-any.f90 | 28 + 9 files changed, 82 insertions(+), 23 deletions(-) create mode 100644 gcc/testsuite/c-c++-common/gomp/declare-variant-any.c create mode 100644 gcc/testsuite/gfortran.dg/gomp/declare-variant-any.f90 diff --git a/gcc/omp-general.cc b/gcc/omp-general.cc index 6f36b5d163f..23072b10d75 100644 --- a/gcc/omp-general.cc +++ b/gcc/omp-general.cc @@ -1277,6 +1277,8 @@ omp_check_context_selector (location_t loc, tree ctx, bool metadirective_p) for (tree tss = ctx; tss; tss = TREE_CHAIN (tss)) { enum omp_tss_code tss_code = OMP_TSS_CODE (tss); + bool saw_any_prop = false; + bool saw_other_prop = false; /* FIXME: not implemented yet. */ if (!metadirective_p && tss_code == OMP_TRAIT_SET_TARGET_DEVICE) @@ -1314,6 +1316,27 @@ omp_check_context_selector (location_t loc, tree ctx, bool metadirective_p) else ts_seen[ts_code] = true; + + /* If trait-property "any" is specified in the "kind" +trait-selector of the "device" selector set or the +"target_device" selector sets, no other trait-property +may be specified in the same selector set. */ + if (ts_code == OMP_TRAIT_DEVICE_KIND) + for (tree p = OMP_TS_PROPERTIES (ts); p; p = TREE_CHAIN (p)) + { + const char *prop = omp_context_name_list_prop (p); + if (!prop) + continue; + else if (strcmp (prop, "any") == 0) + saw_any_prop = true; + else + saw_other_prop = true; + } + else if (ts_code == OMP_TRAIT_DEVICE_ARCH + || ts_code == OMP_TRAIT_DEVICE_ISA + || ts_code == OMP_TRAIT_DEVICE_NUM) + saw_other_prop = true; + if (omp_ts_map[ts_code].valid_properties == NULL) continue; @@ -1366,6 +1389,14 @@ omp_check_context_selector (location_t loc, tree ctx, bool metadirective_p) break; } } + + if (saw_any_prop && saw_other_prop) + { + error_at (loc, + "no other trait-property may be specified " + "in the same selector set with %"); + return error_mark_node; + } } return ctx; } diff --git a/gcc/testsuite/c-c++-common/gomp/declare-variant-10.c b/gcc/testsuite/c-c++-common/gomp/declare-variant-10.c index 2b8a39425b1..e77693430d1 100644 --- a/gcc/testsuite/c-c++-common/gomp/declare-variant-10.c +++ b/gcc/testsuite/c-c++-common/gomp/declare-variant-10.c @@ -7,7 +7,7 @@ void f01 (void); #pragma omp declare variant (f01) match (device={isa(avx512f,avx512bw)}) void f02 (void); void f03 (void); -#pragma omp declare variant (f03) match (device={kind("any"),arch(x86_64),isa(avx512f,avx512bw)}) +#pragma omp declare variant (f03) match (device={arch(x86_64),isa(avx512f,avx512bw)}) void f04 (void); void f05 (void); #pragma omp declare variant (f05) match (device={kind(gpu)}) @@ -28,7 +28,7 @@ void f15 (void); #pragma omp declare variant (f15) match (device={isa(sse4,ssse3),arch(i386)}) void f16 (void); void f17 (void); -#pragma omp declare variant (f17) match (device={kind(any,fpga)}) +#pragma omp declare variant (f17) match (device={kind(fpga)}) void f18 (void); #pragma omp declare target diff --git a/gcc/testsuite/c-c++-common/gomp/declare-variant-3.c b/gcc/testsuite/c-c++-common/gomp/declare-variant-3.c index f5
[PATCH 04/12] OpenMP: C front end support for metadirectives
This patch adds support to the C front end to parse OpenMP metadirective constructs. It includes support for early parse-time resolution of metadirectives (when possible) that will also be used by the C++ front end. Additional common C/C++ testcases are in a later patch in the series. gcc/c-family/ChangeLog * c-common.h (enum c_omp_directive_kind): Add C_OMP_DIR_META. (c_omp_expand_metadirective): Declare. * c-gimplify.cc: Include omp-general.h. (genericize_omp_metadirective_stmt): New. (c_genericize_control_stmt): Call it. * c-omp.cc (c_omp_directives): Add "metadirective" and fix commented-out stubs for the begin/end form. (c_omp_expand_metadirective_r): New. (c_omp_expand_metadirective): New. * c-pragma.cc (omp_pragmas): Add "metadirective". * c-pragma.h (enum pragma_kind): Add PRAGMA_OMP_METADIRECTIVE. gcc/c/ChangeLog * c-parser.cc (struct c_parser): Add new fields for metadirectives. (c_parser_skip_to_end_of_block_or_statement): Add metadirective_p parameter; use it to control brace and parentheses behavior. (mangle_metadirective_region_label): New. (c_parser_label, c_parser_statement_after_labels): Use it. (c_parser_pragma): Handle metadirective. (c_parser_omp_context_selector): Add metadirective_p flag, use it to gate support for non-constant user condition. (c_parser_omp_context_selector_specification): Add metadirective_p argument. (c_parser_finish_omp_declare_variant): Adjust call to above. (analyze_metadirective_body): New. (c_parser_omp_metadirective): New. gcc/testsuite/ChangeLog * gcc.dg/gomp/metadirective-1.c: New. Co-Authored-By: Kwok Cheung Yeung Co-Authored-By: Sandra Loosemore --- gcc/c-family/c-common.h | 4 +- gcc/c-family/c-gimplify.cc | 27 ++ gcc/c-family/c-omp.cc | 60 ++- gcc/c-family/c-pragma.cc| 1 + gcc/c-family/c-pragma.h | 1 + gcc/c/c-parser.cc | 489 +++- gcc/testsuite/gcc.dg/gomp/metadirective-1.c | 15 + 7 files changed, 577 insertions(+), 20 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/gomp/metadirective-1.c diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h index 2d5f5399885..03f62571531 100644 --- a/gcc/c-family/c-common.h +++ b/gcc/c-family/c-common.h @@ -1391,7 +1391,8 @@ enum c_omp_directive_kind { C_OMP_DIR_CONSTRUCT, C_OMP_DIR_DECLARATIVE, C_OMP_DIR_UTILITY, - C_OMP_DIR_INFORMATIONAL + C_OMP_DIR_INFORMATIONAL, + C_OMP_DIR_META }; struct c_omp_directive { @@ -1405,6 +1406,7 @@ extern const struct c_omp_directive c_omp_directives[]; extern const struct c_omp_directive *c_omp_categorize_directive (const char *, const char *, const char *); +extern tree c_omp_expand_metadirective (vec &); /* Return next tree in the chain for chain_next walking of tree nodes. */ inline tree diff --git a/gcc/c-family/c-gimplify.cc b/gcc/c-family/c-gimplify.cc index 494da49791d..c53aca60bcf 100644 --- a/gcc/c-family/c-gimplify.cc +++ b/gcc/c-family/c-gimplify.cc @@ -43,6 +43,7 @@ along with GCC; see the file COPYING3. If not see #include "context.h" #include "tree-pass.h" #include "internal-fn.h" +#include "omp-general.h" /* The gimplification pass converts the language-dependent trees (ld-trees) emitted by the parser into language-independent trees @@ -485,6 +486,27 @@ genericize_omp_for_stmt (tree *stmt_p, int *walk_subtrees, void *data, finish_bc_block (&OMP_FOR_BODY (stmt), bc_continue, clab); } +/* Genericize a OMP_METADIRECTIVE node *STMT_P. */ + +static void +genericize_omp_metadirective_stmt (tree *stmt_p, int *walk_subtrees, + void *data, walk_tree_fn func, + walk_tree_lh lh) +{ + tree stmt = *stmt_p; + + for (tree variant = OMP_METADIRECTIVE_VARIANTS (stmt); + variant != NULL_TREE; + variant = TREE_CHAIN (variant)) +{ + walk_tree_1 (&OMP_METADIRECTIVE_VARIANT_DIRECTIVE (variant), + func, data, NULL, lh); + walk_tree_1 (&OMP_METADIRECTIVE_VARIANT_BODY (variant), + func, data, NULL, lh); +} + + *walk_subtrees = 0; +} /* Lower structured control flow tree nodes, such as loops. The STMT_P, WALK_SUBTREES, and DATA arguments are as for the walk_tree_fn @@ -533,6 +555,11 @@ c_genericize_control_stmt (tree *stmt_p, int *walk_subtrees, void *data, genericize_omp_for_stmt (stmt_p, walk_subtrees, data, func, lh); break; +case OMP_METADIRECTIVE: + genericize_omp_metadirective_stmt (stmt_p, walk_subt
[PATCH 12/12] OpenMP: Update documentation of metadirective implementation status.
libgomp/ChangeLog * libgomp.texi (OpenMP 5.0): Mark metadirective and declare variant as implemented. (OpenMP 5.1): Mark target_device as supported. Add changed interaction between declare target and OpenMP context and dynamic selector support. (OpenMP 5.2): Mark otherwise clause as supported, note that default is also still accepted. --- libgomp/libgomp.texi | 21 ++--- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/libgomp/libgomp.texi b/libgomp/libgomp.texi index 43048da4d6e..af7af63c504 100644 --- a/libgomp/libgomp.texi +++ b/libgomp/libgomp.texi @@ -192,9 +192,8 @@ The OpenMP 4.5 specification is fully supported. @item Array shaping @tab N @tab @item Array sections with non-unit strides in C and C++ @tab N @tab @item Iterators @tab Y @tab -@item @code{metadirective} directive @tab N @tab -@item @code{declare variant} directive - @tab P @tab @emph{simd} traits not handled correctly +@item @code{metadirective} directive @tab Y @tab +@item @code{declare variant} directive @tab Y @tab @item @var{target-offload-var} ICV and @code{OMP_TARGET_OFFLOAD} env variable @tab Y @tab @item Nested-parallel changes to @var{max-active-levels-var} ICV @tab Y @tab @@ -289,8 +288,8 @@ The OpenMP 4.5 specification is fully supported. @headitem Description @tab Status @tab Comments @item OpenMP directive as C++ attribute specifiers @tab Y @tab @item @code{omp_all_memory} reserved locator @tab Y @tab -@item @emph{target_device trait} in OpenMP Context @tab N @tab -@item @code{target_device} selector set in context selectors @tab N @tab +@item @emph{target_device trait} in OpenMP Context @tab Y +@item @code{target_device} selector set in context selectors @tab Y @tab @item C/C++'s @code{declare variant} directive: elision support of preprocessed code @tab N @tab @item @code{declare variant}: new clauses @code{adjust_args} and @@ -366,6 +365,12 @@ to address of matching mapped list item per 5.1, Sect. 2.21.7.2 @tab N @tab @item @code{device_type(nohost)}/@code{device_type(host)} for variables @tab N @tab @item @code{present} modifier to the @code{map}, @code{to} and @code{from} clauses @tab Y @tab +@item Changed interaction between @code{declare target} and OpenMP context + @tab Y @tab +@item Dynamic selector support in @code{metadirective} @tab Y @tab +@item Dynamic selector support in @code{declare variant} @tab P + @tab Fortran rejects non-constant expressions in dynamic selectors; + C/C++ reject expressions using argument variables. @end multitable @@ -413,8 +418,10 @@ to address of matching mapped list item per 5.1, Sect. 2.21.7.2 @tab N @tab @item Deprecation of traits array following the allocator_handle expression in @code{uses_allocators} @tab N @tab @item New @code{otherwise} clause as alias for @code{default} on metadirectives - @tab N @tab -@item Deprecation of @code{default} clause on metadirectives @tab N @tab + @tab Y @tab +@item Deprecation of @code{default} clause on metadirectives @tab N + @tab Both @code{otherwise} and @code{default} are accepted + without diagnostics. @item Deprecation of delimited form of @code{declare target} @tab N @tab @item Reproducible semantics changed for @code{order(concurrent)} @tab N @tab @item @code{allocate} and @code{firstprivate} clauses on @code{scope} -- 2.25.1
[PATCH 03/12] libgomp: runtime support for target_device selector
This patch implements the libgomp runtime support for the dynamic target_device selector via the GOMP_evaluate_target_device function. include/ChangeLog * cuda/cuda.h (CUdevice_attribute): Add definitions for CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR and CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MINOR. libgomp/ChangeLog * Makefile.am (libgomp_la_SOURCES): Add selector.c. * Makefile.in: Regenerate. * config/gcn/selector.c: New. * config/linux/selector.c: New. * config/linux/x86/selector.c: New. * config/nvptx/selector.c: New. * libgomp-plugin.h (GOMP_OFFLOAD_evaluate_device): New. * libgomp.h (struct gomp_device_descr): Add evaluate_device_func field. * libgomp.map (GOMP_5.1.3): New, add GOMP_evaluate_target_device. * libgomp.texi (OpenMP Context Selectors): Document dynamic selector matching of kind/arch/isa. * libgomp_g.h (GOMP_evaluate_current_device): New. (GOMP_evaluate_target_device): New. * oacc-host.c (host_evaluate_device): New. (host_openacc_exec): Initialize evaluate_device_func field to host_evaluate_device. * plugin/plugin-gcn.c (gomp_match_selectors): New. (gomp_match_isa): New. (GOMP_OFFLOAD_evaluate_device): New. * plugin/plugin-nvptx.c (struct ptx_device): Add compute_major and compute_minor fields. (nvptx_open_device): Read compute capability information from device. (gomp_match_selectors): New. (gomp_match_selector): New. (CHECK_ISA): New macro. (GOMP_OFFLOAD_evaluate_device): New. * selector.c: New. * target.c (GOMP_evaluate_target_device): New. (gomp_load_plugin_for_device): Load evaluate_device plugin function. Co-Authored-By: Kwok Cheung Yeung Co-Authored-By: Sandra Loosemore --- include/cuda/cuda.h | 2 + libgomp/Makefile.am | 2 +- libgomp/Makefile.in | 5 +- libgomp/config/gcn/selector.c | 102 +++ libgomp/config/linux/selector.c | 65 + libgomp/config/linux/x86/selector.c | 406 libgomp/config/nvptx/selector.c | 77 ++ libgomp/libgomp-plugin.h| 2 + libgomp/libgomp.h | 1 + libgomp/libgomp.map | 5 + libgomp/libgomp.texi| 18 +- libgomp/libgomp_g.h | 8 + libgomp/oacc-host.c | 11 + libgomp/plugin/plugin-gcn.c | 52 libgomp/plugin/plugin-nvptx.c | 82 ++ libgomp/selector.c | 64 + libgomp/target.c| 40 +++ 17 files changed, 936 insertions(+), 6 deletions(-) create mode 100644 libgomp/config/gcn/selector.c create mode 100644 libgomp/config/linux/selector.c create mode 100644 libgomp/config/linux/x86/selector.c create mode 100644 libgomp/config/nvptx/selector.c create mode 100644 libgomp/selector.c diff --git a/include/cuda/cuda.h b/include/cuda/cuda.h index 0dca4b3a5c0..a775450df03 100644 --- a/include/cuda/cuda.h +++ b/include/cuda/cuda.h @@ -83,6 +83,8 @@ typedef enum { CU_DEVICE_ATTRIBUTE_MAX_THREADS_PER_MULTIPROCESSOR = 39, CU_DEVICE_ATTRIBUTE_ASYNC_ENGINE_COUNT = 40, CU_DEVICE_ATTRIBUTE_UNIFIED_ADDRESSING = 41, + CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR = 75, + CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MINOR = 76, CU_DEVICE_ATTRIBUTE_MAX_REGISTERS_PER_MULTIPROCESSOR = 82 } CUdevice_attribute; diff --git a/libgomp/Makefile.am b/libgomp/Makefile.am index 1871590596d..87658da2d5d 100644 --- a/libgomp/Makefile.am +++ b/libgomp/Makefile.am @@ -72,7 +72,7 @@ libgomp_la_SOURCES = alloc.c atomic.c barrier.c critical.c env.c error.c \ target.c splay-tree.c libgomp-plugin.c oacc-parallel.c oacc-host.c \ oacc-init.c oacc-mem.c oacc-async.c oacc-plugin.c oacc-cuda.c \ priority_queue.c affinity-fmt.c teams.c allocator.c oacc-profiling.c \ - oacc-target.c target-indirect.c + oacc-target.c target-indirect.c selector.c include $(top_srcdir)/plugin/Makefrag.am diff --git a/libgomp/Makefile.in b/libgomp/Makefile.in index 11480d6a953..30e57571404 100644 --- a/libgomp/Makefile.in +++ b/libgomp/Makefile.in @@ -219,7 +219,7 @@ am_libgomp_la_OBJECTS = alloc.lo atomic.lo barrier.lo critical.lo \ oacc-parallel.lo oacc-host.lo oacc-init.lo oacc-mem.lo \ oacc-async.lo oacc-plugin.lo oacc-cuda.lo priority_queue.lo \ affinity-fmt.lo teams.lo allocator.lo oacc-profiling.lo \ - oacc-target.lo target-indirect.lo $(am__objects_1) + oacc-target.lo target-indirect.lo selector.lo $(am__objects_1) libgomp_la_OBJECTS = $(am_libgomp_la_OBJECTS) AM_V_P = $(am__v_P_@AM_V@) am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) @@ -552,7 +552,7 @@ libgomp_la_SOURCES = alloc.c atomic.c barrier.c critical.c env.c \ oacc-parallel.c oacc-host.c oacc-init.c oacc-mem.c \ oacc-async.c
[PATCH 02/12] OpenMP: middle-end support for metadirectives
This patch adds middle-end support for OpenMP metadirectives. Some context selectors can be resolved during gimplification, but others need to be deferred until the omp_device_lower pass, which requires that cgraph, LTO streaming, inlining, etc all know about this construct as well. gcc/ChangeLog * cgraph.h (struct cgraph_node): Add has_metadirectives flag. * cgraphclones.cc (cgraph_node::create_clone): Copy has_metadirectives flag. * doc/gimple.texi (Class hierarchy of GIMPLE statements): Document gomp_metadirective and gomp_variant. * gimple-low.cc (lower_omp_metadirective): New. (lower_stmt): Call it. * gimple-pretty-print.cc (dump_gimple_omp_metadirective): New. (pp_gimple_stmt_1): Call it. * gimple-streamer-in.cc (input_gimple_stmt): Handle GIMPLE_OMP_METADIRECTIVE. * gimple-streamer-out.cc (output_gimple_stmt): Likewise. * gimple-walk.cc (walk_gimple_op): Likewise. (walk_gimple_stmt): Likewise. * gimple.cc (gimple_alloc_omp_metadirective): New. (gimple_build_omp_metadirective): New. (gimple_build_omp_variant): New. * gimple.def (GIMPLE_OMP_METADIRECTIVE): New. (GIMPLE_OMP_METADIRECTIVE_VARIANT): New. * gimple.h (gomp_variant, gomp_metadirective): New. (is_a_helper ::test): New. (is_a_helper ::test): New. (is_a_helper ::test): New. (is_a_helper ::test): New. (gimple_alloc_omp_metadirective): New. (gimple_build_omp_metadirective): New. (gimple_build_omp_variant): New. (gimple_has_substatements): Handle GIMPLE_OMP_METADIRECTIVE. (gimple_has_ops): Likewise. (gimple_omp_metadirective_label): New. (gimple_omp_metadirective_set_label): New. (gimple_omp_variants): New. (gimple_omp_metadirective_set_variants): New. (gimple_return_set_retval): Handle GIMPLE_OMP_METADIRECTIVE. * gimplify.cc (is_gimple_stmt): HANDLE OMP_METADIRECTIVE. (expand_omp_metadirective): New. (gimplify_omp_metadirective): New. (gimplify_expr): Call it. * gsstruct.def (GSS_OMP_METADIRECTIVE): New. (GSS_OMP_METADIRECTIVE_VARIANT): New. * lto-cgraph.cc (lto_output_node): Handle has_metadirectives flag. (input_overwrite_node): Likewise. * omp-expand.cc (expand_omp_target): Propagate has_metadirectives flag. (build_omp_regions_1): Handle GIMPLE_OMP_METADIRECTIVE. (omp_make_gimple_edges): Likewise. * omp-general.cc (omp_late_resolve_metadirective): New. * omp-general.h (omp_late_resolve_metadirective): Declare. * omp-low.cc (struct omp_context): Add next_clone field. (new_omp_context): Handle next_clone field. (clone_omp_context): New. (delete_omp_context): Delete clones. (create_omp_child_function): Propagate has_metadirectives bit. (scan_omp_metadirective): New. (scan_omp_1_stmt): Handle GIMPLE_OMP_METADIRECTIVE. (lower_omp_metadirective): New. (lower_omp_1): Handle GIMPLE_OMP_METADIRECTIVE. Warn about direct calls to offloadable functions containing metadirectives. * omp-offload.cc: Include cfganal.h and cfghooks.h. (omp_expand_metadirective): New. (execute_omp_device_lower): Handle metadirectives. (pass_omp_device_lower::gate): Check has_metadirectives bit. * omp-simd-clone.cc (simd_clone_create): Propagate has_metadirectives flag. * tree-cfg.cc (cleanup_dead_labels): Handle GIMPLE_OMP_METADIRECTIVE. (gimple_redirect_edge_and_branch): Likewise. * tree-inline.cc (remap_gimple_stmt): Handle GIMPLE_OMP_METADIRECTIVE. (estimate_num_instructions): Likewise. (expand_call_inline): Propagate has_metadirectives flag. (tree_function_versioning): Likewise. * tree-ssa-operands.cc: Include omp-general.h. (operands_scanner::parse_ssa_operands): Handle GIMPLE_OMP_METADIRECTIVE. Co-Authored-By: Kwok Cheung Yeung Co-Authored-By: Sandra Loosemore Co-Authored-By: Marcel Vollweiler --- gcc/cgraph.h | 3 + gcc/cgraphclones.cc| 1 + gcc/doc/gimple.texi| 6 ++ gcc/gimple-low.cc | 36 gcc/gimple-pretty-print.cc | 64 + gcc/gimple-streamer-in.cc | 10 ++ gcc/gimple-streamer-out.cc | 6 ++ gcc/gimple-walk.cc | 28 ++ gcc/gimple.cc | 35 +++ gcc/gimple.def | 7 ++ gcc/gimple.h | 100 +++- gcc/gimplify.cc| 184 + gcc/gsstruct.def | 2 + gcc/lto-cgraph.cc | 2 + gcc/omp-expand.cc | 30 ++ gcc/omp-general.cc | 22 + gcc/omp-general.h | 1 + gcc/omp-low.cc | 83 + gcc/omp-offload.cc | 105
[PATCH 01/12] OpenMP: metadirective tree data structures and front-end interfaces
This patch adds the OMP_METADIRECTIVE tree node and shared tree-level support for manipulating metadirectives. It defines/exposes interfaces that will be used in subsequent patches that add front-end and middle-end support, but nothing generates these nodes yet. This patch also adds compile-time support for dynamic context selectors (the target_device selector set and the condition selector of the user selector set) for metadirectives only. The "declare variant" directive still supports only static selectors. gcc/ChangeLog * Makefile.in (GTFILES): Move omp-general.h earlier in the list. * builtin-types.def (BT_FN_BOOL_INT_CONST_PTR_CONST_PTR_CONST_PTR): New. * doc/generic.texi (OpenMP): Document OMP_METADIRECTIVE and context selector interfaces. * omp-builtins.def (BUILT_IN_GOMP_EVALUATE_TARGET_DEVICE): New. * omp-general.cc (omp_check_context_selector): Add metadirective_p parameter, use it to conditionalize target_device support. (make_omp_metadirective_variant): New. (omp_context_selector_matches): Add metadirective_p and delay_p parameters, use them to control things that can only be matched late. Handle OMP_TRAIT_SET_TARGET_DEVICE. (score_wide_int): Move definition to omp-general.h. (omp_encode_kind_arch_isa_props): New. (omp_dynamic_cond): New. (omp_context_compute_score): Handle OMP_TRAIT_SET_TARGET_DEVICE. (omp_resolve_late_declare_variant, omp_resolve_declare_variant): Adjust calls to omp_context_selector_matches. (sort_variant): New. (omp_get_dynamic_candidates): New. (omp_early_resolve_metadirective): New. * omp-general.h (score_wide_int): Moved here from omp-general.cc. (struct omp_variant): New. (OMP_METADIRECTIVE_VARIANT_SELECTOR): New. (OMP_METADIRECTIVE_VARIANT_DIRECTIVE): New. (OMP_METADIRECTIVE_VARIANT_BODY): New. (make_omp_metadirective_variant): Declare. (omp_check_context_selector): Adjust to match definition. (omp_context_selector_matches): Likewise. (omp_early_resolve_metadirective): New. * tree-pretty-print.cc (dump_omp_context_selector): Remove static qualifier. (dump_generic_node): Handle OMP_METADIRECTIVE. * tree-pretty-print.h (dump_omp_context_selector): Declare. * tree.def (OMP_METADIRECTIVE): New. * tree.h (OMP_METADIRECTIVE_VARIANTS): New. gcc/c/ChangeLog * c-parser.cc (c_finish_omp_declare_variant): Update calls to omp_check_context_selector and omp_context_selector_matches. gcc/cp/ChangeLog * decl.cc (omp_declare_variant_finalize_one): Update call to omp_context_selector_matches to pass additional arguments. * parser.cc (cp_finish_omp_declare_variant): Likewise for omp_check_context_selector. gcc/fortran/ChangeLog * trans-openmp.cc (gfc_trans_omp_declare_variant): Update calls to omp_check_context_selector and omp_context_selector_matches. * types.def (BT_FN_BOOL_INT_CONST_PTR_CONST_PTR_CONST_PTR): New. Co-Authored-By: Kwok Cheung Yeung Co-Authored-By: Sandra Loosemore --- gcc/Makefile.in | 2 +- gcc/builtin-types.def | 2 + gcc/c/c-parser.cc | 4 +- gcc/cp/decl.cc | 2 +- gcc/cp/parser.cc| 2 +- gcc/doc/generic.texi| 32 gcc/fortran/trans-openmp.cc | 4 +- gcc/fortran/types.def | 2 + gcc/omp-builtins.def| 3 + gcc/omp-general.cc | 357 ++-- gcc/omp-general.h | 31 +++- gcc/tree-pretty-print.cc| 36 +++- gcc/tree-pretty-print.h | 2 + gcc/tree.def| 6 + gcc/tree.h | 3 + 15 files changed, 461 insertions(+), 27 deletions(-) diff --git a/gcc/Makefile.in b/gcc/Makefile.in index a74761b7ab3..65638c7b5d6 100644 --- a/gcc/Makefile.in +++ b/gcc/Makefile.in @@ -2868,6 +2868,7 @@ GTFILES = $(CPPLIB_H) $(srcdir)/input.h $(srcdir)/coretypes.h \ $(srcdir)/tree-ssa-operands.h \ $(srcdir)/tree-profile.cc $(srcdir)/tree-nested.cc \ $(srcdir)/omp-offload.h \ + $(srcdir)/omp-general.h \ $(srcdir)/omp-general.cc \ $(srcdir)/omp-low.cc \ $(srcdir)/targhooks.cc $(out_file) $(srcdir)/passes.cc \ @@ -2894,7 +2895,6 @@ GTFILES = $(CPPLIB_H) $(srcdir)/input.h $(srcdir)/coretypes.h \ $(srcdir)/ipa-strub.cc \ $(srcdir)/internal-fn.h \ $(srcdir)/calls.cc \ - $(srcdir)/omp-general.h \ $(srcdir)/analyzer/analyzer-language.cc \ @all_gtfiles@ diff --git a/gcc/builtin-types.def b/gcc/builtin-types.def index c97d6bad1de..605a38ab84d 100644 --- a/gcc/builtin-types.def +++ b/gcc/builtin-types.def @@ -878,6 +878,8 @@ DEF_FUNCTION_TYPE_4 (BT_FN_VOID_UINT_PTR_INT_PTR, BT_VOID, BT_INT, BT_PTR, BT_INT, BT_PTR) DEF_FUNCTION_TYPE_4 (BT_FN_BOOL_UINT_UINT
[PATCH 00/12] OpenMP: Metadirective support + "declare variant" improvements
sible to get at least some parts of it committed in a timely manner and reduce the burden of maintaining these patches out of tree. -Sandra Sandra Loosemore (12): OpenMP: metadirective tree data structures and front-end interfaces OpenMP: middle-end support for metadirectives libgomp: runtime support for target_device selector OpenMP: C front end support for metadirectives OpenMP: C++ front-end support for metadirectives OpenMP: common c/c++ testcases for metadirectives OpenMP: Fortran front-end support for metadirectives. OpenMP: Reject other properties with kind(any) OpenMP: Extend dynamic selector support to declare variant OpenMP: Remove dead code from declare variant reimplementation OpenMP: Update "declare target"/OpenMP context interaction OpenMP: Update documentation of metadirective implementation status. gcc/Makefile.in |2 +- gcc/builtin-types.def |2 + gcc/c-family/c-attribs.cc |2 - gcc/c-family/c-common.h |4 +- gcc/c-family/c-gimplify.cc| 27 + gcc/c-family/c-omp.cc | 60 +- gcc/c-family/c-pragma.cc |1 + gcc/c-family/c-pragma.h |1 + gcc/c/c-decl.cc |8 +- gcc/c/c-parser.cc | 473 +++- gcc/cgraph.cc |2 - gcc/cgraph.h | 12 +- gcc/cgraphclones.cc |2 +- gcc/cp/cp-tree.h |2 + gcc/cp/decl.cc|2 +- gcc/cp/decl2.cc |9 +- gcc/cp/parser.cc | 526 - gcc/cp/parser.h |7 + gcc/cp/pt.cc | 120 + gcc/cp/semantics.cc |3 +- gcc/doc/generic.texi | 32 + gcc/doc/gimple.texi |6 + gcc/fortran/decl.cc | 29 + gcc/fortran/dump-parse-tree.cc| 21 + gcc/fortran/gfortran.h| 20 +- gcc/fortran/io.cc |2 +- gcc/fortran/match.h |2 + gcc/fortran/openmp.cc | 294 ++- gcc/fortran/parse.cc | 571 +++-- gcc/fortran/parse.h |8 +- gcc/fortran/resolve.cc|6 + gcc/fortran/st.cc |4 + gcc/fortran/symbol.cc | 25 +- gcc/fortran/trans-decl.cc |5 +- gcc/fortran/trans-openmp.cc | 238 +- gcc/fortran/trans-stmt.h |1 + gcc/fortran/trans.cc |1 + gcc/fortran/types.def |2 + gcc/gimple-low.cc | 36 + gcc/gimple-pretty-print.cc| 64 + gcc/gimple-streamer-in.cc | 13 + gcc/gimple-streamer-out.cc| 10 + gcc/gimple-walk.cc| 28 + gcc/gimple.cc | 36 + gcc/gimple.def|8 + gcc/gimple.h | 122 +- gcc/gimplify.cc | 574 +++-- gcc/gimplify.h|2 +- gcc/gsstruct.def |2 + gcc/ipa-free-lang-data.cc |2 +- gcc/ipa.cc|3 - gcc/lto-cgraph.cc | 12 +- gcc/lto-streamer-out.cc |3 +- gcc/lto-streamer.h|6 - gcc/lto/lto-partition.cc |5 +- gcc/omp-builtins.def |3 + gcc/omp-expand.cc | 32 +- gcc/omp-general.cc| 2033 + gcc/omp-general.h | 50 +- gcc/omp-low.cc| 83 + gcc/omp-offload.cc| 117 +- gcc/omp-simd-clone.cc |3 +- gcc/passes.cc |3 +- gcc/symtab.cc |2 +- .../gomp/declare-target-indirect-2.c | 10 +- .../c-c++-common/gomp/declare-variant-10.c|4 +- .../c-c++-common/gomp/declare-variant-12.c| 14 +- .../c-c++-common/gomp/declare-variant-13.c|6 +- .../c-c++-common/gomp/declare-variant-2.c |4 +- .../c-c++-common/gomp/declare-variant-3.c | 10 +- .../c-c++-common/gomp/declare-variant-8.c |4 +- .../c-c++-common/gomp/declare-variant-9.c |4 +- .../c-c++-common/gomp/declare-variant-any.
[PATCH, obvious] Fix for ICE in tree-nested.cc
I'm planning to push the attached patch to mainline in a couple days, unless someone disputes that it's "obvious" or has some other objection. I think it qualifies because the code immediately following the loop with the bad initializer is already conditionalized on GIMPLE_OMP_TARGET in the same way. I think this patch is a candidate for backporting to the GCC 14 branch once it is unfrozen after the release, too. -SandraFrom 001d166819525dcef43b980298c2f85af77cd8ad Mon Sep 17 00:00:00 2001 From: Sandra Loosemore Date: Mon, 22 Apr 2024 18:24:25 + Subject: [PATCH, obvious] OpenMP: Fix for ICE in tree-nested.cc. Use gimple_omp_target_clauses() instead of gimple_omp_taskreg_clauses() when stmt is GIMPLE_OMP_TARGET, to avoid an as_a<> ICE. The code immediately following this is already conditionalized in the same way. gcc/ChangeLog * tree-nested.cc (convert_tramp_reference_stmt): Use the correct accessor for GIMPLE_OMP_TARGET clauses. --- gcc/tree-nested.cc | 8 +--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/gcc/tree-nested.cc b/gcc/tree-nested.cc index 4e5f3be7676..fc0495d6443 100644 --- a/gcc/tree-nested.cc +++ b/gcc/tree-nested.cc @@ -2906,9 +2906,11 @@ convert_tramp_reference_stmt (gimple_stmt_iterator *gsi, bool *handled_ops_p, continue; decl = i ? get_chain_decl (info) : info->frame_decl; /* Don't add CHAIN.* or FRAME.* twice. */ - for (c = gimple_omp_taskreg_clauses (stmt); - c; - c = OMP_CLAUSE_CHAIN (c)) + if (gimple_code (stmt) == GIMPLE_OMP_TARGET) + c = gimple_omp_target_clauses (stmt); + else + c = gimple_omp_taskreg_clauses (stmt); + for (; c; c = OMP_CLAUSE_CHAIN (c)) if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SHARED) && OMP_CLAUSE_DECL (c) == decl) -- 2.25.1
[committed, wwwdocs] gcc-14/changes.html: nios2 target is obsolete
I've committed the attached patch, per https://gcc.gnu.org/pipermail/gcc/2024-April/243749.html -SandraFrom a6afbd07ee3d669dc6ac396d68a99926a30818f9 Mon Sep 17 00:00:00 2001 From: Sandra Loosemore Date: Mon, 15 Apr 2024 17:17:35 + Subject: [committed, wwwdocs] gcc-14/changes.html: nios2 target is obsolete --- htdocs/gcc-14/changes.html | 4 1 file changed, 4 insertions(+) diff --git a/htdocs/gcc-14/changes.html b/htdocs/gcc-14/changes.html index c98ebe5a..9509487c 100644 --- a/htdocs/gcc-14/changes.html +++ b/htdocs/gcc-14/changes.html @@ -49,6 +49,10 @@ a work-in-progress. unmaintained for quite a while has been declared obsolete in GCC 14. The next release of GCC will have their sources permanently removed. + Support for the nios2*-*- target ports has also been + declared obsolete in GCC 14, and the sources will also be removed + in the next release of GCC. + https://gcc.gnu.org/onlinedocs/gcc/Static-Analyzer-Options.html";>-fanalyzer is still only suitable for analyzing C code. In particular, using it on C++ is unlikely to give meaningful output. -- 2.25.1
[committed] Add nios2*-*-* to the list of obsolete targets
I've committed the attach patch, per https://gcc.gnu.org/pipermail/gcc/2024-April/243749.html -SandraFrom 71ba5a721749174815dec712d113f3afb251deda Mon Sep 17 00:00:00 2001 From: Sandra Loosemore Date: Mon, 8 Apr 2024 14:36:08 + Subject: [committed] Add nios2*-*-* to the list of obsolete targets This patch marks the nios2*-*-* targets obsolete in GCC 14. Intel has EOL'ed this architecture and the maintainers no longer have access to hardware for testing. While the port is still in reasonably good shape at this time, no further testing or updates are planned. gcc/ * config.gcc: Add nios2*-*-* to the list of obsoleted targets. contrib/ * config-list.mk (LIST): --enable-obsolete for nios2*-*-*. --- contrib/config-list.mk | 3 ++- gcc/config.gcc | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/contrib/config-list.mk b/contrib/config-list.mk index 16df66f0fc6..f282cd95c8d 100644 --- a/contrib/config-list.mk +++ b/contrib/config-list.mk @@ -78,7 +78,8 @@ LIST = \ moxie-uclinux moxie-rtems \ msp430-elf msp430-elfbare \ nds32le-elf nds32be-elf \ - nios2-elf nios2-linux-gnu nios2-rtems \ + nios2-elfOPT-enable-obsolete nios2-linux-gnuOPT-enable-obsolete \ + nios2-rtemsOPT-enable-obsolete \ nvptx-none \ or1k-elf or1k-linux-uclibc or1k-linux-musl or1k-rtems \ pdp11-aout \ diff --git a/gcc/config.gcc b/gcc/config.gcc index 5df3c52f8e9..029ad1f1f08 100644 --- a/gcc/config.gcc +++ b/gcc/config.gcc @@ -274,6 +274,7 @@ esac case ${target}${target_min} in *-*-solaris2.11.[0-3]* \ | ia64*-*-*\ + | nios2*-*-*\ ) if test "x$enable_obsolete" != xyes; then echo "*** Configuration ${target}${target_min} is obsolete." >&2 -- 2.25.1
Re: [PATCH] docs: Use @var{S} etc. in Spec File invoke.texi documentation
On 3/27/24 04:57, Jakub Jelinek wrote: Hi! We got internally a question about the Spec File syntax, misunderstanding what is the literal syntax and what are the placeholder variables in the syntax descriptions. The following patch attempts to use @var{S} etc. instead of just S to clarify it stands for any option (or start of option etc.) rather than literal S, say in %{S:X}. At least in HTML documentation it then uses italics. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? Looks good for me, as long as you visually inspected the changed text in the manual and didn't just make sure it still builds. (I generally consider any markup/formatting changes "obvious" as long as they actually look OK.) -Sandra
Re: [PATCH v7] C, ObjC: Add -Wunterminated-string-initialization
On 3/5/24 13:33, Alejandro Colomar wrote: Warn about the following: char s[3] = "foo"; Initializing a char array with a string literal of the same length as the size of the array is usually a mistake. Rarely is the case where one wants to create a non-terminated character sequence from a string literal. In some cases, for writing faster code, one may want to use arrays instead of pointers, since that removes the need for storing an array of pointers apart from the strings themselves. char *log_levels[] = { "info", "warning", "err" }; vs. char log_levels[][7] = { "info", "warning", "err" }; This forces the programmer to specify a size, which might change if a new entry is later added. Having no way to enforce null termination is very dangerous, however, so it is useful to have a warning for this, so that the compiler can make sure that the programmer didn't make any mistakes. This warning catches the bug above, so that the programmer will be able to fix it and write: char log_levels[][8] = { "info", "warning", "err" }; This warning already existed as part of -Wc++-compat, but this patch allows enabling it separately. It is also included in -Wextra, since it may not always be desired (when unterminated character sequences are wanted), but it's likely to be desired in most cases. Since Wc++-compat now includes this warning, the test has to be modified to expect the text of the new warning too, in . The documentation parts of the patch are OK. -Sandra
Re: [Patch] invoke.texi: Add note that -foffload= does not affect device detection
On 3/1/24 17:29, Sandra Loosemore wrote: On 3/1/24 08:23, Tobias Burnus wrote: Aside: Shouldn't all the HTML documents start with a and before the table of content? Currently, it has: Top (GNU libgomp) and the body starts with Short Table of Contents I think this is a bug in the version of texinfo used to produce the HTML content for the GCC web site. Looking at a recent build of my own using Texinfo 6.7, I do see GNU libgomp The manual on the web site says it was produced by "GNU Texinfo 7.0dev". I poked at this a little and apparently you need to fiddle with the SHOW_TITLE or NO_TOP_NODE_OUTPUT customization variables in recent versions of Texinfo in order to get the document title to show up in HTML output. https://www.gnu.org/software/texinfo/manual/texinfo/texinfo.html#index-SHOW_005fTITLE Probably this has to be controlled by a configure check since older Texinfo versions may barf on unknown options. I'm not at a good point to fiddle with this myself right now (I'm deep inside more metadirective/declare variant hacking), also I have no idea how to re-do the HTML manuals linked from the GCC web site to tweak the formatting in this way. I'd think that if we were going to do that, we'd also want to use an official release version of Texinfo instead of a "dev" snapshot. -Sandra
Re: [Patch] invoke.texi: Add note that -foffload= does not affect device detection
On 3/1/24 08:23, Tobias Burnus wrote: Not very often, but do I keep running into issues (fails, segfaults) related to testing programs compiled with a GCC without offload configured and then using the system libraries. - That's equivalent to having the system compiler (or any offload compiler) and compiling with -foffload=disable. The problem is that while the program only contains host code, the run-time library still initializes devices when an API routine - such as omp_get_num_devices - is invoked. This can lead to odd bugs as target regions, obviously, will use host fallback (for any device number) but the API routines will happily operate on the actual devices, which can lead to odd errors. (Likewise issue when compiling for one offload target type and running on a system which has devices of an other type.) I assume that that's not a very common problem, but it can be rather confusing when hitting this issue. Maybe the proposed wording will help others to avoid this pitfall. (Or is this superfluous as -foffload= is not much used and, even if, no one then remembers or finds this none?) Thoughts? Well, I spent a long time looking at this, and my only conclusion is that I don't really understand what the problem you're trying to solve is. If it's problematical to have the runtime know about offload devices the compiled code isn't using, don't users also need to know how to restrict the runtime to a particular set of devices the same way -foffload= lets you do, and not just how to disable offloading in the runtime entirely? It's pretty clearly documented already how -foffload affects the compiler's behavior, and the library's behavior is already documented in its own manual. Maybe what we don't have is a tutorial on how to build/link/run programs using a specific offload device, or on the host? Anyway, I don't really object to the text you want to add, but it makes me more confused instead of less so. :-S * * * It was not clear to me how to refer to libgomp.texi - Should it be 'libgomp' as in 'info libgomp' or the URL https://gcc.gnu.org/onlinedocs/libgomp/ (or filename of the PDF) implies? - Or as 'GNU Offloading and Multi Processing Runtime Library Manual' as named linked to at https://gcc.gnu.org/onlinedocs or on the title page of the the PDF - but that name is not repeated in the info file or the HTML file. - Or even 'GNU libgomp' to mirror a substring in the of the HTML file. I now ended up only implicitly referring that document. The Texinfo input file has "@settitle GNU libgomp". Aside: Shouldn't all the HTML documents start with a and before the table of content? Currently, it has: Top (GNU libgomp) and the body starts with Short Table of Contents I think this is a bug in the version of texinfo used to produce the HTML content for the GCC web site. Looking at a recent build of my own using Texinfo 6.7, I do see GNU libgomp The manual on the web site says it was produced by "GNU Texinfo 7.0dev". -Sandra
Re: [PATCH v5 RESEND] C, ObjC: Add -Wunterminated-string-initialization
On 2/26/24 09:19, Joseph Myers wrote: On Mon, 26 Feb 2024, Alejandro Colomar wrote: The idea seems reasonable, but the patch needs documentation for the new option in invoke.texi. Thanks! Will do. I don't see an obvious order in that file. Where would you put the option? Do you want me to sort(1) it first, and then insert the new option in alphabetic order? Sandra might have a better idea of how the warning options ought to be ordered in the manual. (Obviously, don't mix reordering with any content changes.) Please don't blindly sort the options sections of the manual. They've typically been organized to present general options first (things like -Wpedantic in the warning options section, or -g or -o in the debugging and optimization optimization sections), then more specialized flags for controlling specific individual behaviors. We could do a better job of keeping the latter sublists alphabetized, but in some cases we have also grouped documentation for related options together even if they are not alphabetical, but that needs some manual review and decision-making and should not be mixed with adding new content. We do try to keep the lists in the "Option Summary" section alphabetized except for the general options listed first, though. As far as where to put documentation for new options, I'd say that you should put it in alphabetical order in the appropriate section, unless there is good reason to put it somewhere else, or the alphabetization of the whole section is so messed-up you can't figure out where it should go (putting it at the end is OK in that case, as opposed to some other random location in the list). Remember to add the matching entry in the appropriate "Option Summary" list, and for this option IIUC you also need to add it to the lists of other options enabled by -Wextra and -Wc++-compat. Are we still accepting patches to add new options in stage 4, or is this a stage 1 item? -Sandra
Re: [PATCH v4 5/5] Add documentation for musttail attribute
On 2/2/24 02:09, Andi Kleen wrote: gcc/ChangeLog: * doc/extend.texi: Document [[musttail]] --- gcc/doc/extend.texi | 16 1 file changed, 16 insertions(+) diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index 142e41ab8fbf..866f6c4a9fed 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -9875,6 +9875,22 @@ foo (int x, int y) @code{y} is not actually incremented and the compiler can but does not have to optimize it to just @code{return 42 + 42;}. +@cindex @code{musttail} statement attribute +@item musttail + +The @code{gnu::musttail} or @code{clang::musttail} attribute +can be applied to a return statement that returns the value +of a call to indicate that the call must be a tail call +that does not allocate extra stack space. It took me about 3 attempts to parse this. :-S I think this might be a little better: ...can be applied to a @code{return} statement with a return-value expression that is a function call. It asserts that the call must be a tail call that does not allocate extra stack space. + +@smallexample +[[gnu::musttail]] return foo(); +@end smallexample + +If the compiler cannot generate a tail call it will generate s/will generate/generates/ I'm a big fan of writing in the present tense. ;-) +an error. Tail calls generally require enabling optimization. +On some targets they may not be supported. + @end table @node Attribute Syntax In addition to these changes, at the beginning of this section we have @node Statement Attributes @section Statement Attributes @cindex Statement Attributes GCC allows attributes to be set on null statements. @xref{Attribute Syntax}, for details of the exact syntax for using attributes. [...] Well, we now have an attribute that goes on a non-null statement, so we have to fix this. The documentation for the other statement attributes is already explicit that they go on null statements so those already would be OK if we just removed the "null" restriction here. OTOH, the Attribute Syntax section, in discussing GCC's traditional attribute syntax, says: @subsubheading Statement Attributes In GNU C, an attribute specifier list may appear as part of a null statement. The attribute goes before the semicolon. If "musttail" is only supported in the standard attribute syntax, its new entry in the Statement Attributes node must say that, and the blurb at the top of the node quoted above must say something to the effect that the traditional syntax only allows statement attributes on null statements and attributes on non-null statements are only permitted in the new standard attribute form. -Sandra
[Committed] MAINTAINERS: Update my e-mail address.
ChangeLog/ * MAINTAINERS: Update my e-mail address. --- MAINTAINERS | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MAINTAINERS b/MAINTAINERS index 9d92be1f301..b47e0465852 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -100,7 +100,7 @@ msp430 port Nick Clifton nds32 port Chung-Ju Wu nds32 port Shiva Chen nios2 port Chung-Lin Tang -nios2 port Sandra Loosemore +nios2 port Sandra Loosemore nvptx port Tom de Vries nvptx port Thomas Schwinge or1k port Stafford Horne @@ -228,7 +228,7 @@ build machinery (*.in) Alexandre Oliva build machinery (*.in) Ralf Wildenhues docs co-maintainer Gerald Pfeifer docs co-maintainer Joseph Myers -docs co-maintainer Sandra Loosemore +docs co-maintainer Sandra Loosemore docstring relicensing Gerald Pfeifer docstring relicensing Joseph Myers predict.defJan Hubicka -- 2.34.1
[COMMITTED, obvious] Sort warning options in c-family/c.opt.
In spite of the plea "Please try to keep this file in ASCII collating order" at the top of the file, the sorting of the entries for the various -Wfoo options had increased in entropy. This made it hard to correlate them against e.g. the list of options enabled by -Wall in the manual (see PR90463). This patch is at least a step in the right direction to restore order to the file. I confirmed that no lines were added or removed by these changes, and that the output of "gcc -Q --help=warnings" is unchanged both with or without -Wall added to the command. gcc/c-family/ChangeLog * c.opt: Improve sorting of warning options. --- gcc/c-family/c.opt | 488 ++--- 1 file changed, 244 insertions(+), 244 deletions(-) diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt index 314bd17004f..9c0a28092fc 100644 --- a/gcc/c-family/c.opt +++ b/gcc/c-family/c.opt @@ -303,6 +303,10 @@ Waddress C ObjC C++ ObjC++ Var(warn_address) Warning LangEnabledBy(C ObjC C++ ObjC++,Wall) Warn about suspicious uses of memory addresses. +Waddress-of-packed-member +C ObjC C++ ObjC++ Var(warn_address_of_packed_member) Init(1) Warning +Warn when the address of packed member of struct or union is taken. + Enum Name(warn_aligned_new_level) Type(int) UnknownError(argument %qs to %<-Waligned-new%> not recognized) @@ -358,6 +362,10 @@ Wno-alloca-larger-than C ObjC C++ LTO ObjC++ Alias(Walloca-larger-than=,18446744073709551615EiB,none) Warning Disable Walloca-larger-than= warning. Equivalent to Walloca-larger-than= or larger. +Warith-conversion +C ObjC C++ ObjC++ Var(warn_arith_conv) Warning +Warn if conversion of the result of arithmetic might change the value even though converting the operands cannot. + Warray-bounds= LangEnabledBy(C ObjC C++ LTO ObjC++,Wall,1,0) ; in common.opt @@ -374,10 +382,6 @@ Warray-parameter= C ObjC C++ ObjC++ Joined RejectNegative UInteger Var(warn_array_parameter) IntegerRange(0, 2) LangEnabledBy(C ObjC C++ ObjC++,Wall, 2, 0) Warning Warn about mismatched declarations of array parameters and unsafe accesses to them. -Wzero-length-bounds -C ObjC C++ ObjC++ Var(warn_zero_length_bounds) Warning LangEnabledBy(C ObjC C++ ObjC++,Wall) -Warn about accesses to interior zero-length array members. - Wassign-intercept ObjC ObjC++ Var(warn_assign_intercept) Warning Warn whenever an Objective-C assignment is being intercepted by the garbage collector. @@ -421,10 +425,6 @@ Wbool-operation C ObjC C++ ObjC++ Var(warn_bool_op) Warning LangEnabledBy(C ObjC C++ ObjC++,Wall) Warn about certain operations on boolean expressions. -Wframe-address -C ObjC C++ ObjC++ Var(warn_frame_address) Warning LangEnabledBy(C ObjC C++ ObjC++,Wall) -Warn when __builtin_frame_address or __builtin_return_address is used unsafely. - Wbuiltin-declaration-mismatch C ObjC C++ ObjC++ Var(warn_builtin_declaration_mismatch) Init(1) Warning Warn when a built-in function is declared with the wrong signature. @@ -534,6 +534,14 @@ Wchkp C ObjC C++ ObjC++ Warning WarnRemoved Removed in GCC 9. This switch has no effect. +Wclass-conversion +C++ ObjC++ Var(warn_class_conversion) Init(1) Warning +Warn when a conversion function will never be called due to the type it converts to. + +Wclass-memaccess +C++ ObjC++ Var(warn_class_memaccess) Warning LangEnabledBy(C++ ObjC++, Wall) +Warn for unsafe raw memory writes to objects of class types. + Wclobbered C ObjC C++ ObjC++ Var(warn_clobbered) Warning EnabledBy(Wextra) Warn about variables that might be changed by \"longjmp\" or \"vfork\". @@ -650,6 +658,14 @@ Wdiv-by-zero C ObjC C++ ObjC++ Var(warn_div_by_zero) Init(1) Warning Warn about compile-time integer division by zero. +Wdouble-promotion +C ObjC C++ ObjC++ Var(warn_double_promotion) Warning +Warn about implicit conversions from \"float\" to \"double\". + +Wduplicate-decl-specifier +C ObjC Var(warn_duplicate_decl_specifier) Warning LangEnabledBy(C ObjC,Wall) +Warn when a declaration has duplicate const, volatile, restrict or _Atomic specifier. + Wduplicated-branches C ObjC C++ ObjC++ Var(warn_duplicated_branches) Init(0) Warning Warn about duplicated branches in if-else statements. @@ -662,6 +678,10 @@ Weffc++ C++ ObjC++ Var(warn_ecpp) Warning Warn about violations of Effective C++ style rules. +Welaborated-enum-base +C++ ObjC++ Var(warn_elaborated_enum_base) Warning Init(1) +Warn if an additional enum-base is used in an elaborated-type-specifier. + Wempty-body C ObjC C++ ObjC++ Var(warn_empty_body) Warning EnabledBy(Wextra) Warn about an empty body in an if or else statement. @@ -694,6 +714,10 @@ Wexceptions C++ ObjC++ Var(warn_exceptions) Init(1) Warning Warn when an exception handler is shadowed by another handler. +Wexpansion-to-defined +C ObjC C++ ObjC++ CPP(warn_expansion_to_defined) CppReason(CPP_W_EXPANSION_TO_DEFINED) Var(cpp_warn_expansion_to_defined) Init(0) Warning EnabledBy(Wextra || Wpedantic) +Warn if \"defined\" is used outside #if. + Wex
[COMMITTED] Correct lists of options enabled by -Wall and -Wextra [PR90463]
gcc/ChangeLog PR c++/90463 * doc/invoke.texi (Warning Options): Correct lists of options enabled by -Wall and -Wextra by checking against common.opt and c-family/c.opt. --- gcc/doc/invoke.texi | 79 - 1 file changed, 50 insertions(+), 29 deletions(-) diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 278c931b6a3..676e7ef03d1 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -6202,27 +6202,37 @@ Options} and @ref{Objective-C and Objective-C++ Dialect Options}. @option{-Wall} turns on the following warning flags: @gccoptlist{-Waddress +-Waligned-new @r{(C++ and Objective-C++ only)} -Warray-bounds=1 @r{(only with} @option{-O2}@r{)} -Warray-compare --Warray-parameter=2 @r{(C and Objective-C only)} +-Warray-parameter=2 -Wbool-compare -Wbool-operation --Wc++11-compat -Wc++14-compat +-Wc++11-compat -Wc++14-compat -Wc++17compat -Wc++20compat -Wcatch-value @r{(C++ and Objective-C++ only)} -Wchar-subscripts +-Wclass-memaccess @r{(C++ and Objective-C++ only)} -Wcomment +-Wdangling-else -Wdangling-pointer=2 +-Wdelete-non-virtual-dtor @r{(C++ and Objective-C++ only)} -Wduplicate-decl-specifier @r{(C and Objective-C only)} -Wenum-compare @r{(in C/ObjC; this is on by default in C++)} -Wenum-int-mismatch @r{(C and Objective-C only)} --Wformat --Wformat-overflow --Wformat-truncation --Wint-in-bool-context +-Wformat=1 +-Wformat-contains-nul +-Wformat-diag +-Wformat-extra-args +-Wformat-overflow=1 +-Wformat-truncation=1 +-Wformat-zero-length +-Wframe-address -Wimplicit @r{(C and Objective-C only)} --Wimplicit-int @r{(C and Objective-C only)} -Wimplicit-function-declaration @r{(C and Objective-C only)} --Winit-self @r{(only for C++)} +-Wimplicit-int @r{(C and Objective-C only)} +-Winfinite-recursion +-Winit-self @r{(C++ and Objective-C++ only)} +-Wint-in-bool-context -Wlogical-not-parentheses -Wmain @r{(only for C/ObjC and unless} @option{-ffreestanding}@r{)} -Wmaybe-uninitialized @@ -6230,24 +6240,26 @@ Options} and @ref{Objective-C and Objective-C++ Dialect Options}. -Wmemset-transposed-args -Wmisleading-indentation @r{(only for C/C++)} -Wmismatched-dealloc --Wmismatched-new-delete @r{(only for C/C++)} +-Wmismatched-new-delete @r{(C++ and Objective-C++ only)} -Wmissing-attributes -Wmissing-braces @r{(only for C/ObjC)} -Wmultistatement-macros --Wnarrowing @r{(only for C++)} +-Wnarrowing @r{(C++ and Objective-C++ only)} -Wnonnull -Wnonnull-compare --Wopenmp-simd +-Wopenmp-simd @r{(C and C++ only)} +-Woverloaded-virtual=1 @r{(C++ and Objective-C++ only)} +-Wpacked-not-aligned -Wparentheses --Wpessimizing-move @r{(only for C++)} --Wpointer-sign --Wrange-loop-construct @r{(only for C++)} --Wreorder +-Wpessimizing-move @r{(C++ and Objective-C++ only)} +-Wpointer-sign @r{(only for C/ObjC)} +-Wrange-loop-construct @r{(C++ and Objective-C++ only)} +-Wreorder @r{(C++ and Objective-C++ only)} -Wrestrict -Wreturn-type --Wself-move @r{(only for C++)} +-Wself-move @r{(C++ and Objective-C++ only)} -Wsequence-point --Wsign-compare @r{(only in C++)} +-Wsign-compare @r{(C++ and Objective-C++ only)} -Wsizeof-array-div -Wsizeof-pointer-div -Wsizeof-pointer-memaccess @@ -6258,12 +6270,16 @@ Options} and @ref{Objective-C and Objective-C++ Dialect Options}. -Wtrigraphs -Wuninitialized -Wunknown-pragmas +-Wunused +-Wunused-but-set-variable +-Wunused-const-variable=1 @r{(only for C/ObjC)} -Wunused-function -Wunused-label +-Wunused-local-typedefs -Wunused-value -Wunused-variable -Wuse-after-free=2 --Wvla-parameter @r{(C and Objective-C only)} +-Wvla-parameter -Wvolatile-register-var -Wzero-length-bounds} @@ -6283,27 +6299,32 @@ This enables some extra warning flags that are not enabled by @option{-Wall}. (This option used to be called @option{-W}. The older name is still supported, but the newer name is more descriptive.) -@gccoptlist{-Wclobbered +@gccoptlist{-Wabsolute-value @r{(only for C/ObjC)} +-Walloc-size +-Wcalloc-transposed-args -Wcast-function-type --Wdeprecated-copy @r{(C++ only)} +-Wclobbered +-Wdeprecated-copy @r{(C++ and Objective-C++ only)} -Wempty-body --Wenum-conversion @r{(C only)} --Wignored-qualifiers +-Wenum-conversion @r{(only for C/ObjC)} +-Wexpansion-to-defined +-Wignored-qualifiers @r{(only for C/C++)} -Wimplicit-fallthrough=3 +-Wmaybe-uninitialized -Wmissing-field-initializers --Wmissing-parameter-type @r{(C only)} --Wold-style-declaration @r{(C only)} --Woverride-init --Wsign-compare @r{(C only)} +-Wmissing-parameter-type @r{(C/ObjC only)} +-Wold-style-declaration @r{(C/ObjC only)} +-Woverride-init @r{(C/ObjC only)} +-Wredundant-move @r{(C++ and Objective-C++ only)} +-Wshift-negative-value @r{(in C++11 to C++17 and in C99 and newer)} +-Wsign-compare @r{(C++ and Objective-C++ only)} +-Wsized-deallocation @r{(C++ and Objective-C++ only)} -Wstring-compare --Wredundant-move @r{(only for C++)} -Wtype-limits -Wuninitialized --Wshift-negative-value @r{(in C++11 to
[COMMITTED] Make the manual clearer about what options -Wunused enables [PR90464]
gcc/ChangeLog PR c++/90464 * doc/invoke.texi (Warning Options): Document that -Wunused-parameter isn't enabled by -Wunused unless -Wextra is provided, and that -Wunused does enable -Wunused-const-variable=1 for C. Clarify that -Wunused doesn't enable -Wunused-* options documented as behaving otherwise, and list them explicitly. --- gcc/doc/invoke.texi | 28 ++-- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index f7a6e11d20e..278c931b6a3 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -7598,6 +7598,8 @@ This warning is enabled by @option{-Wall}. @opindex Wno-unused-parameter @item -Wunused-parameter Warn whenever a function parameter is unused aside from its declaration. +This option is not enabled by @code{-Wunused} unless @code{-Wextra} is also +specified. To suppress this warning use the @code{unused} attribute (@pxref{Variable Attributes}). @@ -7624,25 +7626,26 @@ To suppress this warning use the @code{unused} attribute @item -Wunused-const-variable @itemx -Wunused-const-variable=@var{n} Warn whenever a constant static variable is unused aside from its declaration. -@option{-Wunused-const-variable=1} is enabled by @option{-Wunused-variable} -for C, but not for C++. In C this declares variable storage, but in C++ this -is not an error since const variables take the place of @code{#define}s. To suppress this warning use the @code{unused} attribute (@pxref{Variable Attributes}). @table @gcctabopt @item -Wunused-const-variable=1 -This is the warning level that is enabled by @option{-Wunused-variable} for -C. It warns only about unused static const variables defined in the main +Warn about unused static const variables defined in the main compilation unit, but not about static const variables declared in any header included. +@option{-Wunused-const-variable=1} is enabled by either +@option{-Wunused-variable} or @option{-Wunused} for C, but not for +C++. In C this declares variable storage, but in C++ this is not an +error since const variables take the place of @code{#define}s. + @item -Wunused-const-variable=2 This warning level also warns for unused constant static variables in -headers (excluding system headers). This is the warning level of -@option{-Wunused-const-variable} and must be explicitly requested since -in C++ this isn't an error and in C it might be harder to clean up all +headers (excluding system headers). It is equivalent to the short form +@option{-Wunused-const-variable}. This level must be explicitly +requested in both C and C++ because it might be hard to clean up all headers included. @end table @@ -7661,11 +7664,16 @@ This warning is enabled by @option{-Wall}. @opindex Wunused @opindex Wno-unused @item -Wunused -All the above @option{-Wunused} options combined. +All the above @option{-Wunused} options combined, except those documented +as needing to be specified explicitly. In order to get a warning about an unused function parameter, you must either specify @option{-Wextra -Wunused} (note that @option{-Wall} implies -@option{-Wunused}), or separately specify @option{-Wunused-parameter}. +@option{-Wunused}), or separately specify @option{-Wunused-parameter} and/or +@option{-Wunused-but-set-parameter}. + +@option{-Wunused} enables only @option{-Wunused-const-variable=1} rather than +@option{-Wunused-const-variable}, and only for C, not C++. @opindex Wuse-after-free @opindex Wno-use-after-free -- 2.31.1
[COMMITTED] Clean up examples for -Wdangling-pointer [PR109708]
gcc/ChangeLog PR c/109708 * doc/invoke.texi (Warning Options): Fix broken example and clean up/reorganize the others. Also describe what the short-form options mean. --- gcc/doc/invoke.texi | 56 +++-- 1 file changed, 34 insertions(+), 22 deletions(-) diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 930c5dc7236..f7a6e11d20e 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -9423,51 +9423,63 @@ levels but may yield different results with optimization than without. @table @gcctabopt @item -Wdangling-pointer=1 -At level 1 the warning diagnoses only unconditional uses of dangling pointers. -For example +At level 1, the warning diagnoses only unconditional uses of dangling pointers. + +@item -Wdangling-pointer=2 +At level 2, in addition to unconditional uses the warning also diagnoses +conditional uses of dangling pointers. +@end table + +The short form @option{-Wdangling-pointer} is equivalent to +@option{-Wdangling-pointer=2}, while @option{-Wno-dangling-pointer} and +@option{-Wdangling-pointer=0} have the same effect of disabling the warnings. +@option{-Wdangling-pointer=2} is included in @option{-Wall}. + +This example triggers the warning at level 1; the address of the unnamed +temporary is unconditionally referenced outside of its scope. + @smallexample -int f (int c1, int c2, x) +char f (char c1, char c2, char c3) @{ - char *p = strchr ((char[])@{ c1, c2 @}, c3); - // warning: dangling pointer to a compound literal - return p ? *p : 'x'; + char *p; + @{ +p = (char[]) @{ c1, c2, c3 @}; + @} + // warning: using dangling pointer 'p' to an unnamed temporary + return *p; @} @end smallexample + In the following function the store of the address of the local variable -@code{x} in the escaped pointer @code{*p} also triggers the warning. +@code{x} in the escaped pointer @code{*p} triggers the warning at +level 1. + @smallexample void g (int **p) @{ int x = 7; - // warning: storing the address of a local variable in *p + // warning: storing the address of local variable 'x' in '*p' *p = &x; @} @end smallexample -@item -Wdangling-pointer=2 -At level 2, in addition to unconditional uses the warning also diagnoses -conditional uses of dangling pointers. - -For example, because the array @var{a} in the following function is out of -scope when the pointer @var{s} that was set to point is used, the warning -triggers at this level. +In this example, the array @var{a} is out of +scope when the pointer @var{s} is used. Since the code that sets @code{s} +is conditional, the warning triggers at level 2. @smallexample -void f (char *s) +extern void frob (const char *); +void h (char *s) @{ if (!s) @{ char a[12] = "tmpname"; s = a; @} - // warning: dangling pointer to a may be used - strcat (s, ".tmp"); - ... + // warning: dangling pointer 's' to 'a' may be used + frob (s); @} @end smallexample -@end table - -@option{-Wdangling-pointer=2} is included in @option{-Wall}. @opindex Wdate-time @opindex Wno-date-time -- 2.31.1
[COMMITTED] Correct documentation for -Warray-parameter [PR102998]
gcc/ChangeLog PR c/102998 * doc/invoke.texi (Option Summary): Add -Warray-parameter. (Warning Options): Correct/edit discussion of -Warray-parameter to make the first example less confusing, and fill in missing info. --- gcc/doc/invoke.texi | 24 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 313f363f5f2..930c5dc7236 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -332,6 +332,7 @@ Objective-C and Objective-C++ Dialects}. -Wno-aggressive-loop-optimizations -Warith-conversion -Warray-bounds -Warray-bounds=@var{n} -Warray-compare +-Warray-parameter -Warray-parameter=@var{n} -Wno-attributes -Wattribute-alias=@var{n} -Wno-attribute-alias -Wno-attribute-warning -Wbidi-chars=@r{[}none@r{|}unpaired@r{|}any@r{|}ucn@r{]} @@ -8467,25 +8468,28 @@ bool same = arr1 == arr2; @option{-Warray-compare} is enabled by @option{-Wall}. @opindex Wno-array-parameter +@opindex Warray-parameter @item -Warray-parameter @itemx -Warray-parameter=@var{n} -Warn about redeclarations of functions involving arguments of array or +Warn about redeclarations of functions involving parameters of array or pointer types of inconsistent kinds or forms, and enable the detection of out-of-bounds accesses to such parameters by warnings such as @option{-Warray-bounds}. -If the first function declaration uses the array form the bound specified +If the first function declaration uses the array form for a parameter +declaration, the bound specified in the array is assumed to be the minimum number of elements expected to be provided in calls to the function and the maximum number of elements accessed by it. Failing to provide arguments of sufficient size or accessing more than the maximum number of elements may be diagnosed by warnings such -as @option{-Warray-bounds}. At level 1 the warning diagnoses inconsistencies +as @option{-Warray-bounds} or @option{-Wstringop-overflow}. +At level 1, the warning diagnoses inconsistencies involving array parameters declared using the @code{T[static N]} form. -For example, the warning triggers for the following redeclarations because -the first one allows an array of any size to be passed to @code{f} while -the second one with the keyword @code{static} specifies that the array -argument must have at least four elements. +For example, the warning triggers for the second declaration of @code{f} +because the first one with the keyword @code{static} specifies that +the array argument must have at least four elements, while the second +allows an array of any size to be passed to @code{f}. @smallexample void f (int[static 4]); @@ -8493,7 +8497,7 @@ void f (int[]); // warning (inconsistent array form) void g (void) @{ - int *p = (int *)malloc (4); + int *p = (int *)malloc (1 * sizeof (int)); f (p); // warning (array too small) @dots{} @} @@ -8514,6 +8518,10 @@ void g (int[8]);// warning (inconsistent array bound) @option{-Wvla-parameter} option triggers warnings for similar inconsistencies involving Variable Length Array arguments. +The short form of the option @option{-Warray-parameter} is equivalent to +@option{-Warray-parameter=2}. The negative form @option{-Wno-array-parameter} +is equivalent to @option{-Warray-parameter=0}. + @opindex Wattribute-alias @opindex Wno-attribute-alias @item -Wattribute-alias=@var{n} -- 2.31.1
[COMMITTED] More precise documentation for cleanup attribute [PR110029]
gcc/ChangeLog PR c/110029 * doc/extend.texi (Common Variable Attributes): Explain what happens when multiple variables with cleanups are in the same scope. --- gcc/doc/extend.texi | 5 + 1 file changed, 5 insertions(+) diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index 616e26d47dc..0bc586d120e 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -7782,6 +7782,11 @@ with static storage duration. The function must take one parameter, a pointer to a type compatible with the variable. The return value of the function (if any) is ignored. +When multiple variables in the same scope have @code{cleanup} +attributes, at exit from the scope their associated cleanup functions +are run in reverse order of definition (last defined, first +cleanup). + If @option{-fexceptions} is enabled, then @var{cleanup_function} is run during the stack unwinding that happens during the processing of the exception. Note that the @code{cleanup} attribute -- 2.31.1
[COMMITTED] Improve documentation of noinline and noipa attributes [PR108470]
gcc/ChangeLog PR ipa/108470 * doc/extend.texi (Common Function Attributes): Document that noinline also disables some interprocedural optimizations and improve flow to the part about using inline asm instead to disable calls from being optimized away completely. Remove the sentence that says noipa is mainly for internal compiler testing. --- gcc/doc/extend.texi | 17 ++--- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index d879ad544b5..616e26d47dc 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -3666,13 +3666,17 @@ propagation. @cindex @code{noinline} function attribute @item noinline This function attribute prevents a function from being considered for -inlining. +inlining. It also disables some other interprocedural optimizations; it's +preferable to use the more comprehensive @code{noipa} attribute instead +if that is your goal. + @c Don't enumerate the optimizations by name here; we try to be @c future-compatible with this mechanism. -If the function does not have side effects, there are optimizations -other than inlining that cause function calls to be optimized away, -although the function call is live. To keep such calls from being -optimized away, put +Even if a function is declared with the @code{noinline} attribute, +there are optimizations other than inlining that can cause calls to be +optimized away if it does not have side effects, although the function +call is live. To keep such calls from being optimized away, put + @smallexample asm (""); @end smallexample @@ -3691,8 +3695,7 @@ the body. This attribute implies @code{noinline}, @code{noclone} and to a combination of other attributes, because its purpose is to suppress existing and future optimizations employing interprocedural analysis, including those that do not have an attribute suitable for disabling -them individually. This attribute is supported mainly for the purpose -of testing the compiler. +them individually. @cindex @code{nonnull} function attribute @cindex functions with non-null pointer arguments -- 2.31.1
Re: [PATCH] Remove remnant of removed Cygwin options from invoke.texi [PR108521]
On 1/18/24 12:41, Sandra Loosemore wrote: From: Brian Inglis The -mcygwin option for x86 Windows was removed in 2010 by commit 3edeb30d044a4852881c34229e618b34f95b0d9e, but this reference was overlooked. gcc/ChangeLog PR target/108521 * doc/invoke.texi (Option Summary): Remove -mcygwin and -mno-cygwin from x86 Windows Options. Oops, forgot to edit the tag in the patch before mailing. This is committed now. -Sandra
[PATCH] Remove remnant of removed Cygwin options from invoke.texi [PR108521]
From: Brian Inglis The -mcygwin option for x86 Windows was removed in 2010 by commit 3edeb30d044a4852881c34229e618b34f95b0d9e, but this reference was overlooked. gcc/ChangeLog PR target/108521 * doc/invoke.texi (Option Summary): Remove -mcygwin and -mno-cygwin from x86 Windows Options. --- gcc/doc/invoke.texi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 4d43dda9839..0ef2b894ea9 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -1490,7 +1490,7 @@ See RS/6000 and PowerPC Options. -munroll-only-small-loops -mlam=@var{choice}} @emph{x86 Windows Options} -@gccoptlist{-mconsole -mcrtdll=@var{library} -mcygwin -mno-cygwin -mdll +@gccoptlist{-mconsole -mcrtdll=@var{library} -mdll -mnop-fun-dllimport -mthread -municode -mwin32 -mwindows -fno-set-stack-executable} -- 2.31.1
[COMMITTED] Restore documentation for const/volatile functions [PR107942]
In r5-7698-g8648c55f3b703a I accidentally removed the documentation of GCC's special interpretation of const/volatile qualifiers on functions from the function attributes section, thinking this was just a bit-rotten leftover from old versions of GCC. PR107942 points out that this functionality is still present even though the docs are now gone. I decided this material didn't really belong in the function attributes discussion, but a new subsection in the general list of GCC extensions to the C language. And I agree with the comment in the issue that we shouldn't really recommend this usage any more. gcc/ChangeLog PR c/107942 * doc/extend.texi (C Extensions): Add new section to menu. (Function Attributes): Move dangling index entries to (Const and Volatile Functions): New section. --- gcc/doc/extend.texi | 37 +++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index d1893ad860c..d879ad544b5 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -70,6 +70,7 @@ extensions, accepted by GCC in C90 mode and in C++. * Character Escapes:: @samp{\e} stands for the character @key{ESC}. * Alignment:: Determining the alignment of a function, type or variable. * Inline:: Defining inline functions (as fast as macros). +* Const and Volatile Functions :: GCC interprets these specially in C. * Volatiles:: What constitutes an access to a volatile object. * Using Assembly Language with C:: Instructions and extensions for interfacing C with assembler. * Alternate Keywords:: @code{__const__}, @code{__asm__}, etc., for header files. @@ -2522,8 +2523,6 @@ the enclosing block. @section Declaring Attributes of Functions @cindex function attributes @cindex declaring attributes of functions -@cindex @code{volatile} applied to function -@cindex @code{const} applied to function In GNU C and C++, you can use function attributes to specify certain function properties that may help the compiler optimize calls or @@ -10397,6 +10396,40 @@ The definition in the header file causes most calls to the function to be inlined. If any uses of the function remain, they refer to the single copy in the library. +@node Const and Volatile Functions +@section Const and Volatile Functions +@cindex @code{const} applied to function +@cindex @code{volatile} applied to function + +The C standard explicitly leaves the behavior of the @code{const} and +@code{volatile} type qualifiers applied to functions undefined; these +constructs can only arise through the use of @code{typedef}. As an extension, +GCC defines this use of the @code{const} qualifier to have the same meaning +as the GCC @code{const} function attribute, and the @code{volatile} qualifier +to be equivalent to the @code{noreturn} attribute. +@xref{Common Function Attributes}, for more information. + +As examples of this usage, + +@smallexample + +/* @r{Equivalent to:} + void fatal () __attribute__ ((noreturn)); */ +typedef void voidfn (); +volatile voidfn fatal; + +/* @r{Equivalent to:} + extern int square (int) __attribute__ ((const)); */ +typedef int intfn (int); +extern const intfn square; +@end smallexample + +In general, using function attributes instead is preferred, since the +attributes make both the intent of the code and its reliance on a GNU +extension explicit. Additionally, using @code{const} and +@code{volatile} in this way is specific to GNU C and does not work in +GNU C++. + @node Volatiles @section When is a Volatile Object Accessed? @cindex accessing volatiles -- 2.31.1
[COMMITTED] Document negative forms of -Wtsan and -Wxor-used-as-pow [PR110847]
These warnings are enabled by default, thus the manual should document the -no form instead of the positive form. gcc/ChangeLog PR middle-end/110847 * doc/invoke.texi (Option Summary): Document negative forms of -Wtsan and -Wxor-used-as-pow. (Warning Options): Likewise. --- gcc/doc/invoke.texi | 22 +++--- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index a537be66736..4d43dda9839 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -410,7 +410,7 @@ Objective-C and Objective-C++ Dialects}. -Wswitch -Wno-switch-bool -Wswitch-default -Wswitch-enum -Wno-switch-outside-range -Wno-switch-unreachable -Wsync-nand -Wsystem-headers -Wtautological-compare -Wtrampolines -Wtrigraphs --Wtrivial-auto-var-init -Wtsan -Wtype-limits -Wundef +-Wtrivial-auto-var-init -Wno-tsan -Wtype-limits -Wundef -Wuninitialized -Wunknown-pragmas -Wunsuffixed-float-constants -Wunused -Wunused-but-set-parameter -Wunused-but-set-variable @@ -424,7 +424,7 @@ Objective-C and Objective-C++ Dialects}. -Wvector-operation-performance -Wvla -Wvla-larger-than=@var{byte-size} -Wno-vla-larger-than -Wvolatile-register-var -Wwrite-strings --Wxor-used-as-pow +-Wno-xor-used-as-pow -Wzero-length-bounds} @item Static Analyzer Options @@ -9090,14 +9090,13 @@ This warning is enabled by default. @opindex Wtsan @opindex Wno-tsan -@item -Wtsan -Warn about unsupported features in ThreadSanitizer. +@item -Wno-tsan + +Disable warnings about unsupported features in ThreadSanitizer. ThreadSanitizer does not support @code{std::atomic_thread_fence} and can report false positives. -This warning is enabled by default. - @opindex Wtype-limits @opindex Wno-type-limits @item -Wtype-limits @@ -10434,17 +10433,18 @@ and/or writes to register variables. This warning is enabled by @opindex Wxor-used-as-pow @opindex Wno-xor-used-as-pow -@item -Wxor-used-as-pow @r{(C, C++, Objective-C and Objective-C++ only)} -Warn about uses of @code{^}, the exclusive or operator, where it appears -the user meant exponentiation. Specifically, the warning occurs when the +@item -Wno-xor-used-as-pow @r{(C, C++, Objective-C and Objective-C++ only)} +Disable warnings about uses of @code{^}, the exclusive or operator, +where it appears the code meant exponentiation. +Specifically, the warning occurs when the left-hand side is the decimal constant 2 or 10 and the right-hand side is also a decimal constant. In C and C++, @code{^} means exclusive or, whereas in some other languages (e.g. TeX and some versions of BASIC) it means exponentiation. -This warning is enabled by default. It can be silenced by converting one -of the operands to hexadecimal. +This warning can be silenced by converting one of the operands to +hexadecimal as well as by compiling with @option{-Wno-xor-used-as-pow}. @opindex Wdisabled-optimization @opindex Wno-disabled-optimization -- 2.31.1
[COMMITTED] Re-alphabetize attribute tables in extend.texi.
These sections used to be alphabetized, but when I was working on the fix for PR111659 I noticed documentation for some newer attributes had been inserted at random places in the tables instead of maintaining alphabetical order. There's no change to content here, just moving blocks of text around. gcc/ChangeLog * doc/extend.texi (Common Function Attributes): Re-alphabetize the table. (Common Variable Attributes): Likewise. (Common Type Attributes): Likewise. --- gcc/doc/extend.texi | 857 ++-- 1 file changed, 430 insertions(+), 427 deletions(-) diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index 91f0b669b9e..d1893ad860c 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -3028,19 +3028,6 @@ types (@pxref{Variable Attributes}, @pxref{Type Attributes}.) The message attached to the attribute is affected by the setting of the @option{-fmessage-length} option. -@cindex @code{unavailable} function attribute -@item unavailable -@itemx unavailable (@var{msg}) -The @code{unavailable} attribute results in an error if the function -is used anywhere in the source file. This is useful when identifying -functions that have been removed from a particular variation of an -interface. Other than emitting an error rather than a warning, the -@code{unavailable} attribute behaves in the same manner as -@code{deprecated}. - -The @code{unavailable} attribute can also be used for variables and -types (@pxref{Variable Attributes}, @pxref{Type Attributes}.) - @cindex @code{error} function attribute @cindex @code{warning} function attribute @item error ("@var{message}") @@ -3666,6 +3653,10 @@ This attribute locally overrides the @option{-fstack-limit-register} and @option{-fstack-limit-symbol} command-line options; it has the effect of disabling stack limit checking in the function it applies to. +@cindex @code{no_stack_protector} function attribute +@item no_stack_protector +This attribute prevents stack protection code for the function. + @cindex @code{noclone} function attribute @item noclone This function attribute prevents a function from being considered for @@ -3761,63 +3752,6 @@ my_memcpy (void *dest, const void *src, size_t len) __attribute__((nonnull)); @end smallexample -@cindex @code{null_terminated_string_arg} function attribute -@item null_terminated_string_arg -@itemx null_terminated_string_arg (@var{N}) -The @code{null_terminated_string_arg} attribute may be applied to a -function that takes a @code{char *} or @code{const char *} at -referenced argument @var{N}. - -It indicates that the passed argument must be a C-style null-terminated -string. Specifically, the presence of the attribute implies that, if -the pointer is non-null, the function may scan through the referenced -buffer looking for the first zero byte. - -In particular, when the analyzer is enabled (via @option{-fanalyzer}), -if the pointer is non-null, it will simulate scanning for the first -zero byte in the referenced buffer, and potentially emit -@option{-Wanalyzer-use-of-uninitialized-value} -or @option{-Wanalyzer-out-of-bounds} on improperly terminated buffers. - -For example, given the following: - -@smallexample -char *example_1 (const char *p) - __attribute__((null_terminated_string_arg (1))); -@end smallexample - -the analyzer will check that any non-null pointers passed to the function -are validly terminated. - -If the parameter must be non-null, it is appropriate to use both this -attribute and the attribute @code{nonnull}, such as in: - -@smallexample -extern char *example_2 (const char *p) - __attribute__((null_terminated_string_arg (1), - nonnull (1))); -@end smallexample - -See the @code{nonnull} attribute for more information and -caveats. - -If the pointer argument is also referred to by an @code{access} attribute on the -function with @var{access-mode} either @code{read_only} or @code{read_write} -and the latter attribute has the optional @var{size-index} argument -referring to a size argument, this expressses the maximum size of the access. -For example, given: - -@smallexample -extern char *example_fn (const char *p, size_t n) - __attribute__((null_terminated_string_arg (1), - access (read_only, 1, 2), - nonnull (1))); -@end smallexample - -the analyzer will require the first parameter to be non-null, and either -be validly null-terminated, or validly readable up to the size specified by -the second parameter. - @cindex @code{noplt} function attribute @item noplt The @code{noplt} attribute is the counterpart to option @option{-fno-plt}. @@ -3896,6 +3830,63 @@ the standard C library can be guaranteed not to throw an exception with the notable exceptions of @code{qsort} and @code{bsearch} that take function pointer arguments. +@cindex @code{null_terminated_string_arg} function attribute +@item null_terminated_string_arg +@itemx null_terminated_string_ar
[COMMITTED] Clean up documentation for -Wstrict-flex-arrays [PR111659]
gcc/ChangeLog PR middle-end/111659 * doc/extend.texi (Common Variable Attributes): Fix long lines in documentation of strict_flex_array + other minor copy-editing. Add a cross-reference to -Wstrict-flex-arrays. * doc/invoke.texi (Option Summary): Fix whitespace in tables before -fstrict-flex-arrays and -Wstrict-flex-arrays. (C Dialect Options): Combine the docs for the two -fstrict-flex-arrays forms into a single entry. Note this option is for C/C++ only. Add a cross-reference to -Wstrict-flex-arrays. (Warning Options): Note -Wstrict-flex-arrays is for C/C++ only. Minor copy-editing. Add cross references to the strict_flex_array attribute and -fstrict-flex-arrays option. Add note that this option depends on -ftree-vrp. --- gcc/doc/extend.texi | 30 +++--- gcc/doc/invoke.texi | 51 ++--- 2 files changed, 47 insertions(+), 34 deletions(-) diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index 89e823629e3..91f0b669b9e 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -7790,18 +7790,24 @@ are treated as flexible array members. @var{level}=3 is the strictest level, only when the trailing array is declared as a flexible array member per C99 standard onwards (@samp{[]}), it is treated as a flexible array member. -There are two more levels in between 0 and 3, which are provided to support -older codes that use GCC zero-length array extension (@samp{[0]}) or one-element -array as flexible array members (@samp{[1]}): -When @var{level} is 1, the trailing array is treated as a flexible array member -when it is declared as either @samp{[]}, @samp{[0]}, or @samp{[1]}; -When @var{level} is 2, the trailing array is treated as a flexible array member -when it is declared as either @samp{[]}, or @samp{[0]}. - -This attribute can be used with or without the @option{-fstrict-flex-arrays}. -When both the attribute and the option present at the same time, the level of -the strictness for the specific trailing array field is determined by the -attribute. +There are two more levels in between 0 and 3, which are provided to +support older codes that use GCC zero-length array extension +(@samp{[0]}) or one-element array as flexible array members +(@samp{[1]}). When @var{level} is 1, the trailing array is treated as +a flexible array member when it is declared as either @samp{[]}, +@samp{[0]}, or @samp{[1]}; When @var{level} is 2, the trailing array +is treated as a flexible array member when it is declared as either +@samp{[]}, or @samp{[0]}. + +This attribute can be used with or without the +@option{-fstrict-flex-arrays} command-line option. When both the +attribute and the option are present at the same time, the level of +the strictness for the specific trailing array field is determined by +the attribute. + +The @code{strict_flex_array} attribute interacts with the +@option{-Wstrict-flex-arrays} option. @xref{Warning Options}, for more +information. @cindex @code{alloc_size} variable attribute @item alloc_size (@var{position}) diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 43fd3c3a3cd..a537be66736 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -207,7 +207,7 @@ in the following sections. -fopenmp -fopenmp-simd -fopenmp-target-simd-clone@r{[}=@var{device-type}@r{]} -fpermitted-flt-eval-methods=@var{standard} -fplan9-extensions -fsigned-bitfields -funsigned-bitfields --fsigned-char -funsigned-char -fstrict-flex-arrays[=@var{n}] +-fsigned-char -funsigned-char -fstrict-flex-arrays[=@var{n}] -fsso-struct=@var{endianness}} @item C++ Language Options @@ -405,7 +405,7 @@ Objective-C and Objective-C++ Dialects}. -Wstrict-aliasing=n -Wstrict-overflow -Wstrict-overflow=@var{n} -Wstring-compare -Wno-stringop-overflow -Wno-stringop-overread --Wno-stringop-truncation -Wstrict-flex-arrays +-Wno-stringop-truncation -Wstrict-flex-arrays -Wsuggest-attribute=@r{[}pure@r{|}const@r{|}noreturn@r{|}format@r{|}malloc@r{]} -Wswitch -Wno-switch-bool -Wswitch-default -Wswitch-enum -Wno-switch-outside-range -Wno-switch-unreachable -Wsync-nand @@ -2945,22 +2945,22 @@ is always just like one of those two. @opindex fstrict-flex-arrays @opindex fno-strict-flex-arrays -@item -fstrict-flex-arrays -Control when to treat the trailing array of a structure as a flexible array -member for the purpose of accessing the elements of such an array. -The positive form is equivalent to @option{-fstrict-flex-arrays=3}, which is the -strictest. A trailing array is treated as a flexible array member only when it -is declared as a flexible array member per C99 standard onwards. -The negative form is equivalent to @option{-fstrict-flex-arrays=0}, which is the -least strict. All trailing arrays of structures are treated as flexible array -members. - @opindex fstrict-flex-arrays=@var{level} -@item -fstrict-flex-arrays=
[COMMITTED] Move docs for -Wuse-after-free and -Wuseless-cast [PR111693]
These options were categorized as C++ options, but they apply to all C-family languages. gcc/ChangeLog PR c/111693 * doc/invoke.texi (Option Summary): Move -Wuseless-cast from C++ Language Options to Warning Options. Add entry for -Wuse-after-free. (C++ Dialect Options): Move -Wuse-after-free and -Wuseless-cast from here (Warning Options): ...to here. Minor copy-editing to fix typo and grammar. --- gcc/doc/invoke.texi | 158 ++-- 1 file changed, 79 insertions(+), 79 deletions(-) diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 16e31a3c6db..43fd3c3a3cd 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -271,8 +271,7 @@ in the following sections. -Woverloaded-virtual -Wno-pmf-conversions -Wself-move -Wsign-promo -Wsized-deallocation -Wsuggest-final-methods -Wsuggest-final-types -Wsuggest-override --Wno-terminate -Wuseless-cast -Wno-vexing-parse --Wvirtual-inheritance +-Wno-terminate -Wno-vexing-parse -Wvirtual-inheritance -Wno-virtual-move-assign -Wvolatile -Wzero-as-null-pointer-constant} @item Objective-C and Objective-C++ Language Options @@ -420,6 +419,7 @@ Objective-C and Objective-C++ Dialects}. -Wunused-macros -Wunused-parameter -Wno-unused-result -Wunused-value -Wunused-variable +-Wuse-after-free -Wuse-after-free=@var{n} -Wuseless-cast -Wno-varargs -Wvariadic-macros -Wvector-operation-performance -Wvla -Wvla-larger-than=@var{byte-size} -Wno-vla-larger-than @@ -4814,83 +4814,6 @@ annotations. Warn about overriding virtual functions that are not marked with the @code{override} keyword. -@opindex Wuse-after-free -@opindex Wno-use-after-free -@item -Wuse-after-free -@itemx -Wuse-after-free=@var{n} -Warn about uses of pointers to dynamically allocated objects that have -been rendered indeterminate by a call to a deallocation function. -The warning is enabled at all optimization levels but may yield different -results with optimization than without. - -@table @gcctabopt -@item -Wuse-after-free=1 -At level 1 the warning attempts to diagnose only unconditional uses -of pointers made indeterminate by a deallocation call or a successful -call to @code{realloc}, regardless of whether or not the call resulted -in an actual reallocatio of memory. This includes double-@code{free} -calls as well as uses in arithmetic and relational expressions. Although -undefined, uses of indeterminate pointers in equality (or inequality) -expressions are not diagnosed at this level. -@item -Wuse-after-free=2 -At level 2, in addition to unconditional uses, the warning also diagnoses -conditional uses of pointers made indeterminate by a deallocation call. -As at level 2, uses in equality (or inequality) expressions are not -diagnosed. For example, the second call to @code{free} in the following -function is diagnosed at this level: -@smallexample -struct A @{ int refcount; void *data; @}; - -void release (struct A *p) -@{ - int refcount = --p->refcount; - free (p); - if (refcount == 0) -free (p->data); // warning: p may be used after free -@} -@end smallexample -@item -Wuse-after-free=3 -At level 3, the warning also diagnoses uses of indeterminate pointers in -equality expressions. All uses of indeterminate pointers are undefined -but equality tests sometimes appear after calls to @code{realloc} as -an attempt to determine whether the call resulted in relocating the object -to a different address. They are diagnosed at a separate level to aid -legacy code gradually transition to safe alternatives. For example, -the equality test in the function below is diagnosed at this level: -@smallexample -void adjust_pointers (int**, int); - -void grow (int **p, int n) -@{ - int **q = (int**)realloc (p, n *= 2); - if (q == p) -return; - adjust_pointers ((int**)q, n); -@} -@end smallexample -To avoid the warning at this level, store offsets into allocated memory -instead of pointers. This approach obviates needing to adjust the stored -pointers after reallocation. -@end table - -@option{-Wuse-after-free=2} is included in @option{-Wall}. - -@opindex Wuseless-cast -@opindex Wno-useless-cast -@item -Wuseless-cast @r{(C, Objective-C, C++ and Objective-C++ only)} -Warn when an expression is cast to its own type. This warning does not -occur when a class object is converted to a non-reference type as that -is a way to create a temporary: - -@smallexample -struct S @{ @}; -void g (S&&); -void f (S&& arg) -@{ - g (S(arg)); // make arg prvalue so that it can bind to S&& -@} -@end smallexample - @opindex Wconversion-null @opindex Wno-conversion-null @item -Wno-conversion-null @r{(C++ and Objective-C++ only)} @@ -7739,6 +7662,83 @@ In order to get a warning about an unused function parameter, you must either specify @option{-Wextra -Wunused} (note that @option{-Wall} implies @option{-Wunused}), or separately specify @option{-Wunused-parameter}. +@opindex Wu
[COMITTED] Tidy documentation for BPF builtins [PR112973]
gcc/Changelog PR target/112973 * doc/extend.texi (BPF Built-in Functions): Wrap long lines and give the section a light copy-editing pass. --- gcc/doc/extend.texi | 38 -- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index b9129d1b464..89e823629e3 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -16832,19 +16832,27 @@ void __builtin_bfin_ssync (void); The following built-in functions are available for eBPF targets. @defbuiltin{{unsigned long long} __builtin_bpf_load_byte (unsigned long long @var{offset})} -Load a byte from the @code{struct sk_buff} packet data pointed by the register @code{%r6} and return it. +Load a byte from the @code{struct sk_buff} packet data pointed to by the +register @code{%r6}, and return it. @enddefbuiltin @defbuiltin{{unsigned long long} __builtin_bpf_load_half (unsigned long long @var{offset})} -Load 16 bits from the @code{struct sk_buff} packet data pointed by the register @code{%r6} and return it. +Load 16 bits from the @code{struct sk_buff} packet data pointed to by the +register @code{%r6}, and return it. @enddefbuiltin @defbuiltin{{unsigned long long} __builtin_bpf_load_word (unsigned long long @var{offset})} -Load 32 bits from the @code{struct sk_buff} packet data pointed by the register @code{%r6} and return it. +Load 32 bits from the @code{struct sk_buff} packet data pointed to by the +register @code{%r6}, and return it. @enddefbuiltin -@defbuiltin{{void *} __builtin_preserve_access_index (@var{expr})} -BPF Compile Once-Run Everywhere (CO-RE) support. Instruct GCC to generate CO-RE relocation records for any accesses to aggregate data structures (struct, union, array types) in @var{expr}. This builtin is otherwise transparent, the return value is whatever @var{expr} evaluates to. It is also overloaded: @var{expr} may be of any type (not necessarily a pointer), the return type is the same. Has no effect if @code{-mco-re} is not in effect (either specified or implied). +@defbuiltin{@var{type} __builtin_preserve_access_index (@var{type} @var{expr})} +BPF Compile Once-Run Everywhere (CO-RE) support. Instruct GCC to +generate CO-RE relocation records for any accesses to aggregate +data structures (struct, union, array types) in @var{expr}. This builtin +is otherwise transparent; @var{expr} may have any type and its value is +returned. This builtin has no effect if @code{-mco-re} is not in effect +(either specified or implied). @enddefbuiltin @defbuiltin{{unsigned int} __builtin_preserve_field_info (@var{expr}, unsigned int @var{kind})} @@ -16946,36 +16954,38 @@ The return value is the enum value in the target kernel. @defbuiltin{{unsigned int} __builtin_btf_type_id (@var{type}, unsigned int @var{kind})} BPF Compile Once-Run Everywhere (CO-RE) support. This builtin is used to get -the BTF type ID of a specified type. Depending on the @var{kind} argument, it -will either return the ID of the local BTF information, or the BTF type ID in +the BTF type ID of a specified @var{type}. +Depending on the @var{kind} argument, it +either returns the ID of the local BTF information, or the BTF type ID in the target kernel. The following values are supported for @var{kind}: @table @code @item BTF_TYPE_ID_LOCAL = 0 -Return the local BTF type ID. Always succeeds. +Return the local BTF type ID. Always succeeds. @item BTF_TYPE_ID_TARGET = 1 -Return the target BTF type ID. If type does not exist in the target, returns 0. +Return the target BTF type ID. If @var{type} does not exist in the target, +returns 0. @end table @enddefbuiltin @defbuiltin{{unsigned int} __builtin_preserve_type_info (@var{type}, unsigned int @var{kind})} BPF Compile Once-Run Everywhere (CO-RE) support. This builtin performs named type (struct/union/enum/typedef) verifications. The type of verification -dependents on the @var{kind} argument provided. This builtin will always -return 0 if type does not exists in the target kernel. +depends on the @var{kind} argument provided. This builtin always +returns 0 if @var{type} does not exist in the target kernel. The following values are supported for @var{kind}: @table @code @item BTF_TYPE_EXISTS = 0 -Checks if type exists in the target. +Checks if @var{type} exists in the target. @item BTF_TYPE_MATCHES = 1 -Checks if type matches the local definition in the target kernel. +Checks if @var{type} matches the local definition in the target kernel. @item BTF_TYPE_SIZE = 2 -Returns the size of the type within the target. +Returns the size of the @var{type} within the target. @end table @enddefbuiltin -- 2.31.1
Re: [Patch] libgomp.texi: Document omp_pause_resource{,_all} and omp_target_memcpy* (was: [Patch] libgomp.texi: Document omp_pause_resource{,_all})
On 1/14/24 16:15, Tobias Burnus wrote: +@node omp_target_memcpy +@subsection @code{omp_target_memcpy} -- Copy data between devices +@table @asis +@item @emph{Description}: +This routine tests copies @var{length} of bytes of data from the device +identified by device number @var{src_device_num} to device @var{dst_device_num}. Hmmm, I'm sure it's the train's fault :-) but "tests copies" makes no sense, and that's cut-and-pasted multiple times. I think you just mean "copies" in all cases. +@node omp_target_memcpy_rect +@subsection @code{omp_target_memcpy_rect} -- Copy a subvolume of data between devices +@table @asis +@item @emph{Description}: +This routine tests copies a subvolume of data from the device identified by +device number @var{src_device_num} to device @var{dst_device_num}. The +subvolume of a multi-dimensional array of array dimension @var{num_dims} and +each array element has a size of @var{element_size} bytes. The @var{volume} This is kind of garbled. How about rephrasing that second sentence as The array has @var{num_dims} and each array element has a size of @var{element_size} bytes. +array specifies how many elements per dimension will be copied. The full s/will be/are/ +array in number of elements is given by the @var{dst_dimensions} and +@var{src_dimensions} arguments for the array on the destination and source +device, respectively. The offset per dimension to the first element to I think we can simplify that sentence, too, like The full sizes of the destination and source arrays are given by the @var{dst_dimensions} and @var{src_dimensions} arguments, respectively. +be copied is given by the @var{dst_offset} and @var{src_offset} arguments. +The routine returns zero on success and non-zero otherwise. + +The OpenMP only requires that @var{num_dims} up to three is supported. In order s/OpenMP/OpenMP specification/ ? +to find implementation-specific maximally supported number of dimensions, the +routine will return this value when invoked with a NULL pointer to both the s/will return/returns/ either "null pointer" or "@code{NULL}" is preferable to "NULL pointer". +@var{dst} and @var{src} arguments. As GCC supports arbitrary dimensions, it +will return INTMAX. s/will return INTMAX/returns @code{INT_MAX}/ + +The device-number arguments must be conforming device number, the @var{src} and s/number,/numbers,/ +@var{dst} must be either both NULL or any of the following must be fulfilled: same issue with "NULL" here, either "@code{NULL}" or "null pointers". "any" seems unlikely to be useful. Do you mean "all" of the following conditions? +@var{element_size} and @var{num_dims} must be positive, the @var{volume}, offset +and dimension arrays must have at least @var{num_dims} dimensions. +Running this routine in a @code{target} region except on the initial device +is not supported. The part of the patch for omp_target_memcpy_rect_async has very similar problems and needs the same fixes. -Sandra
Re: [Patch] libgomp.texi: Document omp_pause_resource{,_all}
On 1/14/24 07:26, Tobias Burnus wrote: This documents two more OpenMP (5.0) routines, omp_pause_resource and omp_pause_resource_all. Comments, remarks, suggestions - to the patch or the documentation in general? I have some minor nits about typos and copy-editing. I assume the formatting of the interface syntax is consistent with how it's done elsewhere in the manual. +@node Resource Relinquishing Routines +@section Resource Relinquishing Routines + +Routines releasing resources used by the OpenMP runtime. +They have C linkage and do not throw exceptions. + +@menu +* omp_pause_resource:: Release OpenMP ressouces on a device +* omp_pause_resource_all:: Release OpenMP ressouces on all devices s/ressouces/resources/g (there are more instances below) +@end menu + + + +@node omp_pause_resource +@subsection @code{omp_pause_resource} -- Release OpenMP ressouces on a device +@table @asis +@item @emph{Description}: +Free resources used by OpenMP programm and runtime library on and for the s/OpenMP programm/an OpenMP program/g (same mistake below) +device specified by @var{device_num}; on success, zero is returned and non-zero +otherwise. + +The value of @var{device_num} must be valid device number. The effect when s/valid device number/a valid device number/ +invoked from within a @code{target} region is unspecified. + +@item @emph{C/C++}: +@multitable @columnfractions .20 .80 +@item @emph{Prototype}: @tab @code{int omp_pause_resource(omp_pause_resource_t kind, int device_num);} +@end multitable + +@item @emph{Fortran}: +@multitable @columnfractions .20 .80 +@item @emph{Interface}: @tab @code{integer function omp_pause_resource(kind, device_num)} +@item @tab @code{integer (kind=omp_pause_resource_kind) kind} +@item @tab @code{integer device_num} +@end multitable + +@item @emph{Reference}: +@uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.2.43. +@end table + + + +@node omp_pause_resource_all +@subsection @code{omp_pause_resource_all} -- Release OpenMP ressouces on all devices +@table @asis +@item @emph{Description}: +Free resources used by OpenMP programm and runtime library on all devices, including +the host. On success, zero is returned and non-zero otherwise. + +The effect when invoked from within a @code{target} region is unspecified. + +@item @emph{C/C++}: +@multitable @columnfractions .20 .80 +@item @emph{Prototype}: @tab @code{int omp_pause_resource(omp_pause_resource_t kind);} +@end multitable + +@item @emph{Fortran}: +@multitable @columnfractions .20 .80 +@item @emph{Interface}: @tab @code{integer function omp_pause_resource(kind)} +@item @tab @code{integer (kind=omp_pause_resource_kind) kind} +@end multitable + +@item @emph{See also}: +@ref{omp_pause_resource} + +@item @emph{Reference}: +@uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.2.44. +@end table + + Re the content, I see no documentation for omp_pause_resource_t or the equivalent in Fortran, or any hint about what the kind argument is for. I understand this is in the OpenMP spec but if you're going to make users read the spec anyway I wonder what the purpose of the GCC documentation is. :-S If it's to explain implementation-specific features, then it should at least be documenting whether GCC supports additional pause kinds as permitted by the spec. -Sandra
Re: [PATCH v2]: gcc/doc/extend.texi: Update builtin example for __builtin_FILE, __builtin_LINE __builtin_FUNCTION
On 1/10/24 14:28, Jonny Grant wrote: > > 2024-01-10 Jonathan Grant > gcc/ChangeLog: >* doc/extend.texi: Update builtin example for __builtin_FILE > __builtin_LINE __builtin_FUNCTION. > > > >>From 66290eb477dd1a99310ad9972c45391c2a87c1c7 Mon Sep 17 00:00:00 2001 > From: Jonathan Grant > Date: Wed, 29 Nov 2023 11:02:06 + > Subject: [PATCH] gcc/doc: Update builtin example for __builtin_FILE > __builtin_LINE __builtin_FUNCTION > > > Signed-off-by: Jonathan Grant > --- > gcc/doc/extend.texi | 14 -- > 1 file changed, 8 insertions(+), 6 deletions(-) > > diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi > index 1ae589aeb29..f17a4b215de 100644 > --- a/gcc/doc/extend.texi > +++ b/gcc/doc/extend.texi > @@ -14660,20 +14660,22 @@ to @var{F} or the empty string if the call was not made at function > scope. > > For example, in the following, each call to function @code{foo} will > -print a line similar to @code{"file.c:123: foo: message"} with the name > +print a line similar to @code{"file.c:5: foo: message"} with the name Please also s/will print/prints/ > of the file and the line number of the @code{printf} call, the name of > the function @code{foo}, followed by the word @code{message}. > > @smallexample > -const char* > -function (const char *func = __builtin_FUNCTION ()) > +#include > + > +void foo (void) > @{ > - return func; > + printf ("%s:%i: %s: message\n", __builtin_FILE (), __builtin_LINE (), __builtin_FUNCTION ()); > + printf ("%s:%i: %s: message\n", __builtin_FILE (), __builtin_LINE (), __builtin_FUNCTION ()); Is this duplicated code a mistake? As you have it, each call to foo prints *two* lines, not "a line". Maybe you mean to have more than one call to foo instead of more than one line printed per call? If it's intentional, please correct the above descriptive text. Also, I'm pretty sure this line of code is too long to format nicely in the PDF manual (it's well over 80 characters). I'd put a line break after the call to __builtin_FILE (). -Sandra
[Committed] libgcc, nios2: Fix exception handling on nios2 with -fpic
Exception handling on nios2-linux-gnu with -fpic has been broken since revision 790854ea7670f11c14d431c102a49181d2915965, "Use _dl_find_object in _Unwind_Find_FDE". For whatever reason, this doesn't work on nios2. Nios2 uses the GOT address as the base for DW_EH_PE_datarel relocations in PIC; see my previous fix to make this work, revision 2d33dcfe9f0494c9b56a8d704c3d27c5a4329ebc, "Support for GOT-relative DW_EH_PE_datarel encoding". So this may be a horrible bug in the ABI or in my interpretation of it or just glibc's implementation of _dl_find_object for this target, but there's existing code out there that does things this way; and realistically, nobody is going to re-engineer this now that the vendor has EOL'ed the nios2 architecture. So, just skip over the code trying to use _dl_find_object on this target and fall back to the way that works. I plan to backport this patch to the GCC 12 and GCC 13 branches as well. libgcc/ChangeLog * unwind-dw2-fde-dip.c (_Unwind_Find_FDE): Do not try to use _dl_find_object on nios2; it doesn't work. --- libgcc/unwind-dw2-fde-dip.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libgcc/unwind-dw2-fde-dip.c b/libgcc/unwind-dw2-fde-dip.c index 2f2ca35d549..57d0c8812b1 100644 --- a/libgcc/unwind-dw2-fde-dip.c +++ b/libgcc/unwind-dw2-fde-dip.c @@ -543,8 +543,9 @@ _Unwind_Find_FDE (void *pc, struct dwarf_eh_bases *bases) return ret; /* Use DLFO_STRUCT_HAS_EH_DBASE as a proxy for the existence of a glibc-style - _dl_find_object function. */ -#ifdef DLFO_STRUCT_HAS_EH_DBASE + _dl_find_object function. However, do not use _dl_find_object on nios2, + which uses the GOT address as the base for DW_EH_PE_datarel instead. */ +#if defined(DLFO_STRUCT_HAS_EH_DBASE) && !defined(__nios2__) { struct dl_find_object dlfo; if (_dl_find_object (pc, &dlfo) == 0 && dlfo.dlfo_eh_frame != NULL) -- 2.31.1
[PATCH 6/8] OpenMP: common c/c++ testcases for metadirectives
From: Kwok Cheung Yeung gcc/testsuite/ChangeLog * c-c++-common/gomp/metadirective-1.c: New. * c-c++-common/gomp/metadirective-2.c: New. * c-c++-common/gomp/metadirective-3.c: New. * c-c++-common/gomp/metadirective-4.c: New. * c-c++-common/gomp/metadirective-5.c: New. * c-c++-common/gomp/metadirective-6.c: New. * c-c++-common/gomp/metadirective-7.c: New. * c-c++-common/gomp/metadirective-8.c: New. * c-c++-common/gomp/metadirective-construct.c: New. * c-c++-common/gomp/metadirective-device.c: New. * c-c++-common/gomp/metadirective-no-score.c: New. * c-c++-common/gomp/metadirective-target-device.c: New. libgomp/ChangeLog * testsuite/libgomp.c-c++-common/metadirective-1.c: New. * testsuite/libgomp.c-c++-common/metadirective-2.c: New. * testsuite/libgomp.c-c++-common/metadirective-3.c: New. * testsuite/libgomp.c-c++-common/metadirective-4.c: New. * testsuite/libgomp.c-c++-common/metadirective-5.c: New. Co-Authored-By: Sandra Loosemore --- .../c-c++-common/gomp/metadirective-1.c | 52 + .../c-c++-common/gomp/metadirective-2.c | 74 .../c-c++-common/gomp/metadirective-3.c | 31 +++ .../c-c++-common/gomp/metadirective-4.c | 40 .../c-c++-common/gomp/metadirective-5.c | 24 +++ .../c-c++-common/gomp/metadirective-6.c | 31 +++ .../c-c++-common/gomp/metadirective-7.c | 31 +++ .../c-c++-common/gomp/metadirective-8.c | 16 ++ .../gomp/metadirective-construct.c| 177 ++ .../c-c++-common/gomp/metadirective-device.c | 147 +++ .../gomp/metadirective-no-score.c | 95 ++ .../gomp/metadirective-target-device.c| 147 +++ .../libgomp.c-c++-common/metadirective-1.c| 35 .../libgomp.c-c++-common/metadirective-2.c| 41 .../libgomp.c-c++-common/metadirective-3.c| 34 .../libgomp.c-c++-common/metadirective-4.c| 52 + .../libgomp.c-c++-common/metadirective-5.c| 46 + 17 files changed, 1073 insertions(+) create mode 100644 gcc/testsuite/c-c++-common/gomp/metadirective-1.c create mode 100644 gcc/testsuite/c-c++-common/gomp/metadirective-2.c create mode 100644 gcc/testsuite/c-c++-common/gomp/metadirective-3.c create mode 100644 gcc/testsuite/c-c++-common/gomp/metadirective-4.c create mode 100644 gcc/testsuite/c-c++-common/gomp/metadirective-5.c create mode 100644 gcc/testsuite/c-c++-common/gomp/metadirective-6.c create mode 100644 gcc/testsuite/c-c++-common/gomp/metadirective-7.c create mode 100644 gcc/testsuite/c-c++-common/gomp/metadirective-8.c create mode 100644 gcc/testsuite/c-c++-common/gomp/metadirective-construct.c create mode 100644 gcc/testsuite/c-c++-common/gomp/metadirective-device.c create mode 100644 gcc/testsuite/c-c++-common/gomp/metadirective-no-score.c create mode 100644 gcc/testsuite/c-c++-common/gomp/metadirective-target-device.c create mode 100644 libgomp/testsuite/libgomp.c-c++-common/metadirective-1.c create mode 100644 libgomp/testsuite/libgomp.c-c++-common/metadirective-2.c create mode 100644 libgomp/testsuite/libgomp.c-c++-common/metadirective-3.c create mode 100644 libgomp/testsuite/libgomp.c-c++-common/metadirective-4.c create mode 100644 libgomp/testsuite/libgomp.c-c++-common/metadirective-5.c diff --git a/gcc/testsuite/c-c++-common/gomp/metadirective-1.c b/gcc/testsuite/c-c++-common/gomp/metadirective-1.c new file mode 100644 index 000..37b56237531 --- /dev/null +++ b/gcc/testsuite/c-c++-common/gomp/metadirective-1.c @@ -0,0 +1,52 @@ +/* { dg-do compile } */ + +#define N 100 + +void f (int a[], int b[], int c[]) +{ + int i; + + #pragma omp metadirective \ + default (teams loop) \ + default (parallel loop) /* { dg-error "too many 'otherwise' or 'default' clauses in 'metadirective'" } */ +for (i = 0; i < N; i++) c[i] = a[i] * b[i]; + + #pragma omp metadirective \ + otherwise (teams loop) \ + default (parallel loop) /* { dg-error "too many 'otherwise' or 'default' clauses in 'metadirective'" } */ +for (i = 0; i < N; i++) c[i] = a[i] * b[i]; + + #pragma omp metadirective \ + otherwise (teams loop) \ + otherwise (parallel loop) /* { dg-error "too many 'otherwise' or 'default' clauses in 'metadirective'" } */ +for (i = 0; i < N; i++) c[i] = a[i] * b[i]; + + #pragma omp metadirective \ + default (bad_directive) /* { dg-error "unknown directive name before '\\)' token" } */ +for (i = 0; i < N; i++) c[i] = a[i] * b[i]; + + #pragma omp metadirective \ + default (teams loop) \ + where (device={arch("nvptx")}: parallel loop) /* { dg-error "'where' is not valid for 'metadirective'"
[PATCH 8/8] OpenMP: Update documentation of metadirective implementation status.
libgomp/ChangeLog * libgomp.texi (OpenMP 5.0): Mark metadirective as implemented. (OpenMP 5.1): Mark target_device as partially supported. (OpenMP 5.2): Mark otherwise clause as supported, note that default is also still accepted. --- libgomp/libgomp.texi | 15 ++- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/libgomp/libgomp.texi b/libgomp/libgomp.texi index c727850397d..8ef22086653 100644 --- a/libgomp/libgomp.texi +++ b/libgomp/libgomp.texi @@ -192,7 +192,7 @@ The OpenMP 4.5 specification is fully supported. @item Array shaping @tab N @tab @item Array sections with non-unit strides in C and C++ @tab N @tab @item Iterators @tab Y @tab -@item @code{metadirective} directive @tab N @tab +@item @code{metadirective} directive @tab Y @tab @item @code{declare variant} directive @tab P @tab @emph{simd} traits not handled correctly @item @var{target-offload-var} ICV and @code{OMP_TARGET_OFFLOAD} @@ -289,8 +289,11 @@ The OpenMP 4.5 specification is fully supported. @headitem Description @tab Status @tab Comments @item OpenMP directive as C++ attribute specifiers @tab Y @tab @item @code{omp_all_memory} reserved locator @tab Y @tab -@item @emph{target_device trait} in OpenMP Context @tab N @tab -@item @code{target_device} selector set in context selectors @tab N @tab +@item @emph{target_device trait} in OpenMP Context @tab Y +@item @code{target_device} selector set in context selectors @tab P + @tab Supported only for @code{metadirective}. + The @code{declare variant} construct does not yet support dynamic + selectors. @item C/C++'s @code{declare variant} directive: elision support of preprocessed code @tab N @tab @item @code{declare variant}: new clauses @code{adjust_args} and @@ -413,8 +416,10 @@ to address of matching mapped list item per 5.1, Sect. 2.21.7.2 @tab N @tab @item Deprecation of traits array following the allocator_handle expression in @code{uses_allocators} @tab N @tab @item New @code{otherwise} clause as alias for @code{default} on metadirectives - @tab N @tab -@item Deprecation of @code{default} clause on metadirectives @tab N @tab + @tab Y @tab +@item Deprecation of @code{default} clause on metadirectives @tab N + @tab Both @code{otherwise} and @code{default} are accepted + without diagnostics. @item Deprecation of delimited form of @code{declare target} @tab N @tab @item Reproducible semantics changed for @code{order(concurrent)} @tab N @tab @item @code{allocate} and @code{firstprivate} clauses on @code{scope} -- 2.31.1
[PATCH 4/8] OpenMP: C front end support for metadirectives
From: Kwok Cheung Yeung This patch adds support to the C front end to parse OpenMP metadirective constructs. It includes support for early parse-time resolution of metadirectives (when possible) that will also be used by the C++ front end. Additional common C/C++ testcases are in a later patch in the series. gcc/c-family/ChangeLog * c-common.h (enum c_omp_directive_kind): Add C_OMP_DIR_META. (c_omp_expand_metadirective): Declare. * c-gimplify.cc: Include omp-general.h. (genericize_omp_metadirective_stmt): New. (c_genericize_control_stmt): Call it. * c-omp.cc (c_omp_directives): Add "metadirective" and fix commented-out stubs for the begin/end form. (c_omp_expand_metadirective_r): New. (c_omp_expand_metadirective): New. * c-pragma.cc (omp_pragmas): Add "metadirective". * c-pragma.h (enum pragma_kind): Add PRAGMA_OMP_METADIRECTIVE. gcc/c/ChangeLog * c-parser.cc (struct c_parser): Add new fields for metadirectives. (c_parser_skip_to_end_of_block_or_statement): Add metadirective_p parameter; use it to control brace and parentheses behavior. (mangle_metadirective_region_label): New. (c_parser_label, c_parser_statement_after_labels): Use it. (c_parser_pragma): Handle metadirective. (c_parser_omp_context_selector): Add metadirective_p flag, use it to gate support for non-constant user condition. (c_parser_omp_context_selector_specification): Add metadirective_p flag. (c_parser_finish_omp_declare_variant): Adjust call. (analyze_metadirective_body): New. (c_parser_omp_metadirective): New. gcc/testsuite/ChangeLog * gcc.dg/gomp/metadirective-1.c: New. Co-Authored-By: Sandra Loosemore --- gcc/c-family/c-common.h | 4 +- gcc/c-family/c-gimplify.cc | 27 ++ gcc/c-family/c-omp.cc | 60 ++- gcc/c-family/c-pragma.cc| 1 + gcc/c-family/c-pragma.h | 1 + gcc/c/c-parser.cc | 489 +++- gcc/testsuite/gcc.dg/gomp/metadirective-1.c | 15 + 7 files changed, 577 insertions(+), 20 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/gomp/metadirective-1.c diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h index 3c2d75a0027..bad12c8119f 100644 --- a/gcc/c-family/c-common.h +++ b/gcc/c-family/c-common.h @@ -1391,7 +1391,8 @@ enum c_omp_directive_kind { C_OMP_DIR_CONSTRUCT, C_OMP_DIR_DECLARATIVE, C_OMP_DIR_UTILITY, - C_OMP_DIR_INFORMATIONAL + C_OMP_DIR_INFORMATIONAL, + C_OMP_DIR_META }; struct c_omp_directive { @@ -1405,6 +1406,7 @@ extern const struct c_omp_directive c_omp_directives[]; extern const struct c_omp_directive *c_omp_categorize_directive (const char *, const char *, const char *); +extern tree c_omp_expand_metadirective (vec &); /* Return next tree in the chain for chain_next walking of tree nodes. */ inline tree diff --git a/gcc/c-family/c-gimplify.cc b/gcc/c-family/c-gimplify.cc index 494da49791d..c53aca60bcf 100644 --- a/gcc/c-family/c-gimplify.cc +++ b/gcc/c-family/c-gimplify.cc @@ -43,6 +43,7 @@ along with GCC; see the file COPYING3. If not see #include "context.h" #include "tree-pass.h" #include "internal-fn.h" +#include "omp-general.h" /* The gimplification pass converts the language-dependent trees (ld-trees) emitted by the parser into language-independent trees @@ -485,6 +486,27 @@ genericize_omp_for_stmt (tree *stmt_p, int *walk_subtrees, void *data, finish_bc_block (&OMP_FOR_BODY (stmt), bc_continue, clab); } +/* Genericize a OMP_METADIRECTIVE node *STMT_P. */ + +static void +genericize_omp_metadirective_stmt (tree *stmt_p, int *walk_subtrees, + void *data, walk_tree_fn func, + walk_tree_lh lh) +{ + tree stmt = *stmt_p; + + for (tree variant = OMP_METADIRECTIVE_VARIANTS (stmt); + variant != NULL_TREE; + variant = TREE_CHAIN (variant)) +{ + walk_tree_1 (&OMP_METADIRECTIVE_VARIANT_DIRECTIVE (variant), + func, data, NULL, lh); + walk_tree_1 (&OMP_METADIRECTIVE_VARIANT_BODY (variant), + func, data, NULL, lh); +} + + *walk_subtrees = 0; +} /* Lower structured control flow tree nodes, such as loops. The STMT_P, WALK_SUBTREES, and DATA arguments are as for the walk_tree_fn @@ -533,6 +555,11 @@ c_genericize_control_stmt (tree *stmt_p, int *walk_subtrees, void *data, genericize_omp_for_stmt (stmt_p, walk_subtrees, data, func, lh); break; +case OMP_METADIRECTIVE: + genericize_omp_metadirective_stmt (stmt_p, walk_subtrees, data, func, +
[PATCH 5/8] OpenMP: C++ front-end support for metadirectives
From: Kwok Cheung Yeung This patch adds C++ support for metadirectives. It uses the c-family support committed with the corresponding C front end patch to do early parse-time metadirective resolution when possible. Additional C/C++ common testcases are provided in a subsequent patch in the series. gcc/cp/ChangeLog * parser.cc (cp_parser_skip_to_end_of_block_or_statement): Add metadirective_p parameter, use it to control brace/parentheses behavior for metadirectives. (mangle_metadirective_region_label): New. (cp_parser_label_for_labeled_statement): Use it. (cp_parser_jump_statement): Likewise. (cp_parser_omp_context_selector): Add metadirective_p parameter, use it to control error behavior for non-constant exprs properties. (cp_parser_omp_context_selector_specification): Add metadirective_p parameter, use it for cp_parser_omp_context_selector call. (cp_finish_omp_declare_variant): Adjust call to cp_parser_omp_context_selector_specification. (analyze_metadirective_body): New. (cp_parser_omp_metadirective): New. (cp_parser_pragma): Handle PRAGMA_OMP_METADIRECTIVE. * parser.h (struct cp_parser): Add fields for metadirective parsing state. * pt.cc (tsubst_omp_context_selector): New. (tsubst_stmt): Handle OMP_METADIRECTIVE. gcc/testsuite/ChangeLog * g++.dg/gomp/attrs-metadirective-1.C: New. * g++.dg/gomp/attrs-metadirective-2.C: New. * g++.dg/gomp/attrs-metadirective-3.C: New. * g++.dg/gomp/attrs-metadirective-4.C: New. * g++.dg/gomp/attrs-metadirective-5.C: New. * g++.dg/gomp/attrs-metadirective-6.C: New. * g++.dg/gomp/attrs-metadirective-7.C: New. * g++.dg/gomp/attrs-metadirective-8.C: New. libgomp/ChangeLog * testsuite/libgomp.c++/metadirective-template-1.C: New. * testsuite/libgomp.c++/metadirective-template-2.C: New. * testsuite/libgomp.c++/metadirective-template-3.C: New. Co-Authored-By: Sandra Loosemore --- gcc/cp/parser.cc | 524 +- gcc/cp/parser.h | 7 + gcc/cp/pt.cc | 118 .../g++.dg/gomp/attrs-metadirective-1.C | 40 ++ .../g++.dg/gomp/attrs-metadirective-2.C | 74 +++ .../g++.dg/gomp/attrs-metadirective-3.C | 31 ++ .../g++.dg/gomp/attrs-metadirective-4.C | 41 ++ .../g++.dg/gomp/attrs-metadirective-5.C | 24 + .../g++.dg/gomp/attrs-metadirective-6.C | 31 ++ .../g++.dg/gomp/attrs-metadirective-7.C | 31 ++ .../g++.dg/gomp/attrs-metadirective-8.C | 16 + .../libgomp.c++/metadirective-template-1.C| 37 ++ .../libgomp.c++/metadirective-template-2.C| 41 ++ .../libgomp.c++/metadirective-template-3.C| 41 ++ 14 files changed, 1043 insertions(+), 13 deletions(-) create mode 100644 gcc/testsuite/g++.dg/gomp/attrs-metadirective-1.C create mode 100644 gcc/testsuite/g++.dg/gomp/attrs-metadirective-2.C create mode 100644 gcc/testsuite/g++.dg/gomp/attrs-metadirective-3.C create mode 100644 gcc/testsuite/g++.dg/gomp/attrs-metadirective-4.C create mode 100644 gcc/testsuite/g++.dg/gomp/attrs-metadirective-5.C create mode 100644 gcc/testsuite/g++.dg/gomp/attrs-metadirective-6.C create mode 100644 gcc/testsuite/g++.dg/gomp/attrs-metadirective-7.C create mode 100644 gcc/testsuite/g++.dg/gomp/attrs-metadirective-8.C create mode 100644 libgomp/testsuite/libgomp.c++/metadirective-template-1.C create mode 100644 libgomp/testsuite/libgomp.c++/metadirective-template-2.C create mode 100644 libgomp/testsuite/libgomp.c++/metadirective-template-3.C diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index b864a9b5275..4ec4ed8a01c 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -2998,7 +2998,7 @@ static void cp_parser_skip_to_end_of_statement static void cp_parser_consume_semicolon_at_end_of_statement (cp_parser *); static void cp_parser_skip_to_end_of_block_or_statement - (cp_parser *); + (cp_parser *, bool = false); static bool cp_parser_skip_to_closing_brace (cp_parser *); static bool cp_parser_skip_entire_template_parameter_list @@ -4174,9 +4174,11 @@ cp_parser_consume_semicolon_at_end_of_statement (cp_parser *parser) have consumed a non-nested `;'. */ static void -cp_parser_skip_to_end_of_block_or_statement (cp_parser* parser) +cp_parser_skip_to_end_of_block_or_statement (cp_parser* parser, +bool metadirective_p) { int nesting_depth = 0; + int bracket_depth = 0; /* Unwind generic function template scope if necessary. */ if (parser->fully_implicit_function_template_p) @@ -4198,7 +4200,7 @@ cp_parser_skip_to_end_of_block_or_statement (cp_parser* parser) case CPP_SEMICOLON: /* Stop if this is an unnested ';'
[PATCH 7/8] OpenMP: Fortran front-end support for metadirectives.
uct.f90: New. * gfortran.dg/gomp/metadirective-no-score.f90: New. * gfortran.dg/gomp/pure-1.f90: Add metadirective test. * gfortran.dg/gomp/pure-2.f90: Remove metadirective test. libgomp/ChangeLog * testsuite/libgomp.fortran/metadirective-1.f90: New. * testsuite/libgomp.fortran/metadirective-2.f90: New. * testsuite/libgomp.fortran/metadirective-3.f90: New. * testsuite/libgomp.fortran/metadirective-4.f90: New. * testsuite/libgomp.fortran/metadirective-5.f90: New. * testsuite/libgomp.fortran/metadirective-6.f90: New. Co-Authored-By: Sandra Loosemore Co-Authored-By: Tobias Burnus Co-Authored-By: Paul-Antoine Arras --- gcc/fortran/decl.cc | 29 + gcc/fortran/dump-parse-tree.cc| 21 + gcc/fortran/gfortran.h| 24 +- gcc/fortran/io.cc | 2 +- gcc/fortran/match.h | 2 + gcc/fortran/openmp.cc | 265 +++- gcc/fortran/parse.cc | 571 +++--- gcc/fortran/parse.h | 8 +- gcc/fortran/resolve.cc| 6 + gcc/fortran/st.cc | 4 + gcc/fortran/symbol.cc | 25 +- gcc/fortran/trans-decl.cc | 5 +- gcc/fortran/trans-openmp.cc | 239 +--- gcc/fortran/trans-stmt.h | 1 + gcc/fortran/trans.cc | 1 + .../gfortran.dg/gomp/metadirective-1.f90 | 55 ++ .../gfortran.dg/gomp/metadirective-10.f90 | 40 ++ .../gfortran.dg/gomp/metadirective-11.f90 | 33 + .../gfortran.dg/gomp/metadirective-2.f90 | 62 ++ .../gfortran.dg/gomp/metadirective-3.f90 | 34 ++ .../gfortran.dg/gomp/metadirective-4.f90 | 39 ++ .../gfortran.dg/gomp/metadirective-5.f90 | 30 + .../gfortran.dg/gomp/metadirective-6.f90 | 31 + .../gfortran.dg/gomp/metadirective-7.f90 | 36 ++ .../gfortran.dg/gomp/metadirective-8.f90 | 22 + .../gfortran.dg/gomp/metadirective-9.f90 | 30 + .../gomp/metadirective-construct.f90 | 260 .../gomp/metadirective-no-score.f90 | 122 gcc/testsuite/gfortran.dg/gomp/pure-1.f90 | 7 + gcc/testsuite/gfortran.dg/gomp/pure-2.f90 | 8 - .../libgomp.fortran/metadirective-1.f90 | 61 ++ .../libgomp.fortran/metadirective-2.f90 | 40 ++ .../libgomp.fortran/metadirective-3.f90 | 29 + .../libgomp.fortran/metadirective-4.f90 | 46 ++ .../libgomp.fortran/metadirective-5.f90 | 44 ++ .../libgomp.fortran/metadirective-6.f90 | 58 ++ 36 files changed, 1937 insertions(+), 353 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/gomp/metadirective-1.f90 create mode 100644 gcc/testsuite/gfortran.dg/gomp/metadirective-10.f90 create mode 100644 gcc/testsuite/gfortran.dg/gomp/metadirective-11.f90 create mode 100644 gcc/testsuite/gfortran.dg/gomp/metadirective-2.f90 create mode 100644 gcc/testsuite/gfortran.dg/gomp/metadirective-3.f90 create mode 100644 gcc/testsuite/gfortran.dg/gomp/metadirective-4.f90 create mode 100644 gcc/testsuite/gfortran.dg/gomp/metadirective-5.f90 create mode 100644 gcc/testsuite/gfortran.dg/gomp/metadirective-6.f90 create mode 100644 gcc/testsuite/gfortran.dg/gomp/metadirective-7.f90 create mode 100644 gcc/testsuite/gfortran.dg/gomp/metadirective-8.f90 create mode 100644 gcc/testsuite/gfortran.dg/gomp/metadirective-9.f90 create mode 100644 gcc/testsuite/gfortran.dg/gomp/metadirective-construct.f90 create mode 100644 gcc/testsuite/gfortran.dg/gomp/metadirective-no-score.f90 create mode 100644 libgomp/testsuite/libgomp.fortran/metadirective-1.f90 create mode 100644 libgomp/testsuite/libgomp.fortran/metadirective-2.f90 create mode 100644 libgomp/testsuite/libgomp.fortran/metadirective-3.f90 create mode 100644 libgomp/testsuite/libgomp.fortran/metadirective-4.f90 create mode 100644 libgomp/testsuite/libgomp.fortran/metadirective-5.f90 create mode 100644 libgomp/testsuite/libgomp.fortran/metadirective-6.f90 diff --git a/gcc/fortran/decl.cc b/gcc/fortran/decl.cc index 503ecb8d9b5..0ab2e710e78 100644 --- a/gcc/fortran/decl.cc +++ b/gcc/fortran/decl.cc @@ -8404,6 +8404,7 @@ gfc_match_end (gfc_statement *st) case COMP_CONTAINS: case COMP_DERIVED_CONTAINS: +case COMP_OMP_BEGIN_METADIRECTIVE: state = gfc_state_stack->previous->state; block_name = gfc_state_stack->previous->sym == NULL ? NULL : gfc_state_stack->previous->sym->name; @@ -8411,6 +8412,28 @@ gfc_match_end (gfc_statement *st) && gfc_state_stack->previous->sym->abr_modproc_decl; break; +case COMP_OMP_METADIRECTIVE: + { + /* Metadirectives can be nested, so we need to drill down to the + first state that is not COMP_OMP_METADIR
[PATCH 3/8] libgomp: runtime support for target_device selector
From: Kwok Cheung Yeung This patch implements the libgomp runtime support for the dynamic target_device selector via the GOMP_evaluate_target_device function. include/ChangeLog * cuda/cuda.h (CUdevice_attribute): Add definitions for CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR and CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MINOR. libgomp/ChangeLog * Makefile.am (libgomp_la_SOURCES): Add selector.c. * Makefile.am: Regenerate. * config/gcn/selector.c: New. * config/linux/selector.c: New. * config/linux/x86/selector.c: New. * config/nvptx/selector.c: New. * libgomp-plugin.h (GOMP_OFFLOAD_evaluate_device): New. * libgomp.h (struct gomp_device_descr): Add evaluate_device_func field. * libgomp.map (GOMP_5.1): Add GOMP_evaluate_target_device. * libgomp_g.h (GOMP_evaluate_current_device): New. (GOMP_evaluate_target_device): New. * oacc-host.c (host_evaluate_device): New. (host_openacc_exec): Initialize evaluate_device_func field to host_evaluate_device. * plugin/plugin-gcn.c (GOMP_OFFLOAD_evaluate_device): New. * plugin/plugin-nvptx.c (struct ptx_device): Add compute_major and compute_minor fields. (nvptx_open_device): Read compute capability information from device. (CHECK_ISA): New macro. (GOMP_OFFLOAD_evaluate_device): New. * selector.c: New. * target.c (GOMP_evaluate_target_device): New. (gomp_load_plugin_for_device): Load evaluate_device plugin function. --- include/cuda/cuda.h | 2 + libgomp/Makefile.am | 2 +- libgomp/Makefile.in | 5 +- libgomp/config/gcn/selector.c | 57 + libgomp/config/linux/selector.c | 43 libgomp/config/linux/x86/selector.c | 325 libgomp/config/nvptx/selector.c | 65 ++ libgomp/libgomp-plugin.h| 2 + libgomp/libgomp.h | 1 + libgomp/libgomp.map | 1 + libgomp/libgomp_g.h | 8 + libgomp/oacc-host.c | 11 + libgomp/plugin/plugin-gcn.c | 14 ++ libgomp/plugin/plugin-nvptx.c | 45 libgomp/selector.c | 36 +++ libgomp/target.c| 38 16 files changed, 652 insertions(+), 3 deletions(-) create mode 100644 libgomp/config/gcn/selector.c create mode 100644 libgomp/config/linux/selector.c create mode 100644 libgomp/config/linux/x86/selector.c create mode 100644 libgomp/config/nvptx/selector.c create mode 100644 libgomp/selector.c diff --git a/include/cuda/cuda.h b/include/cuda/cuda.h index 114aba4e074..0d57bdd68e9 100644 --- a/include/cuda/cuda.h +++ b/include/cuda/cuda.h @@ -82,6 +82,8 @@ typedef enum { CU_DEVICE_ATTRIBUTE_MAX_THREADS_PER_MULTIPROCESSOR = 39, CU_DEVICE_ATTRIBUTE_ASYNC_ENGINE_COUNT = 40, CU_DEVICE_ATTRIBUTE_UNIFIED_ADDRESSING = 41, + CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR = 75, + CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MINOR = 76, CU_DEVICE_ATTRIBUTE_MAX_REGISTERS_PER_MULTIPROCESSOR = 82 } CUdevice_attribute; diff --git a/libgomp/Makefile.am b/libgomp/Makefile.am index 1871590596d..87658da2d5d 100644 --- a/libgomp/Makefile.am +++ b/libgomp/Makefile.am @@ -72,7 +72,7 @@ libgomp_la_SOURCES = alloc.c atomic.c barrier.c critical.c env.c error.c \ target.c splay-tree.c libgomp-plugin.c oacc-parallel.c oacc-host.c \ oacc-init.c oacc-mem.c oacc-async.c oacc-plugin.c oacc-cuda.c \ priority_queue.c affinity-fmt.c teams.c allocator.c oacc-profiling.c \ - oacc-target.c target-indirect.c + oacc-target.c target-indirect.c selector.c include $(top_srcdir)/plugin/Makefrag.am diff --git a/libgomp/Makefile.in b/libgomp/Makefile.in index 56a6beab867..81de2ddb943 100644 --- a/libgomp/Makefile.in +++ b/libgomp/Makefile.in @@ -219,7 +219,7 @@ am_libgomp_la_OBJECTS = alloc.lo atomic.lo barrier.lo critical.lo \ oacc-parallel.lo oacc-host.lo oacc-init.lo oacc-mem.lo \ oacc-async.lo oacc-plugin.lo oacc-cuda.lo priority_queue.lo \ affinity-fmt.lo teams.lo allocator.lo oacc-profiling.lo \ - oacc-target.lo target-indirect.lo $(am__objects_1) + oacc-target.lo target-indirect.lo selector.lo $(am__objects_1) libgomp_la_OBJECTS = $(am_libgomp_la_OBJECTS) AM_V_P = $(am__v_P_@AM_V@) am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) @@ -552,7 +552,7 @@ libgomp_la_SOURCES = alloc.c atomic.c barrier.c critical.c env.c \ oacc-parallel.c oacc-host.c oacc-init.c oacc-mem.c \ oacc-async.c oacc-plugin.c oacc-cuda.c priority_queue.c \ affinity-fmt.c teams.c allocator.c oacc-profiling.c \ - oacc-target.c target-indirect.c $(am__append_3) + oacc-target.c target-indirect.c selector.c $(am__append_3) # Nvidia PTX OpenACC plugin. @PLUGIN_NVPTX_TRUE@libgomp_plugin_nvptx_version_info = -version-info $(libtool_VERSION) @@ -777,