* [Patch] Fortran: Cleanup OpenMP match{o,s,do,ds} macros
@ 2022-06-30 12:30 Tobias Burnus
2022-06-30 12:51 ` Jakub Jelinek
0 siblings, 1 reply; 2+ messages in thread
From: Tobias Burnus @ 2022-06-30 12:30 UTC (permalink / raw)
To: Jakub Jelinek, gcc-patches, fortran
[-- Attachment #1: Type: text/plain, Size: 558 bytes --]
I initially thought that I need another set of macros - and started with
this cleanup. I then realized that I don't.
However, I still wonder whether this cleanup makes sense even if only
4 macros are affected.
OK for mainline - or should I put that patch into the bin?
Tobias
-----------------
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955
[-- Attachment #2: omp-match-macro.diff --]
[-- Type: text/x-patch, Size: 4790 bytes --]
Fortran: Cleanup OpenMP match{o,s,do,ds} macros
Create match_internal as universal macro and use it to
define match{o,s,do,ds}
gcc/fortran/ChangeLog:
* parse.cc (match_internal): New macro.
(matcho, matchs, matchds, matchdo): Use it.
diff --git a/gcc/fortran/parse.cc b/gcc/fortran/parse.cc
index 7356d1b5a3a..ebe27a7569f 100644
--- a/gcc/fortran/parse.cc
+++ b/gcc/fortran/parse.cc
@@ -745,81 +745,58 @@ decode_oacc_directive (void)
return ST_GET_FCN_CHARACTERISTICS;
}
-/* Like match, but set a flag simd_matched if keyword matched
- and if spec_only, goto do_spec_only without actually matching. */
-#define matchs(keyword, subr, st) \
- do { \
- match m2; \
- if (spec_only && gfc_match (keyword) == MATCH_YES) \
- goto do_spec_only; \
- if ((m2 = match_word_omp_simd (keyword, subr, &old_locus, \
- &simd_matched)) == MATCH_YES) \
- { \
- ret = st; \
- goto finish; \
- } \
- else if (m2 == MATCH_ERROR) \
- goto error_handling; \
- else \
- undo_new_statement (); \
+/* Like match, but with some special handling:
+ - dosimd - if false, don't do anything if not -fopenmp,
+ otherwise do match_word_omp_simd matching
+ - if dospec_only: if spec_only, goto do_spec_only after matching.
+
+ If the directive matched but the clauses failed, do not start
+ matching the next directive in the same switch statement. */
+
+#define match_internal(match_simd, match_spec_only, keyword, subr, st) \
+ do { \
+ match m2; \
+ if (!match_simd && !flag_openmp) \
+ ; \
+ else if (match_spec_only \
+ && spec_only \
+ && gfc_match (keyword) == MATCH_YES) \
+ goto do_spec_only; \
+ else if (!match_simd \
+ && ((m2 = match_word (keyword, subr, &old_locus)) \
+ == MATCH_YES)) \
+ { \
+ ret = st; \
+ goto finish; \
+ } \
+ else if (match_simd \
+ && (m2 = match_word_omp_simd (keyword, subr, &old_locus, \
+ &simd_matched)) == MATCH_YES) \
+ { \
+ ret = st; \
+ goto finish; \
+ } \
+ else if (m2 == MATCH_ERROR) \
+ goto error_handling; \
+ else \
+ undo_new_statement (); \
} while (0)
-/* Like match, but don't match anything if not -fopenmp
- and if spec_only, goto do_spec_only without actually matching. */
-/* If the directive matched but the clauses failed, do not start
- matching the next directive in the same switch statement. */
-#define matcho(keyword, subr, st) \
- do { \
- match m2; \
- if (!flag_openmp) \
- ; \
- else if (spec_only && gfc_match (keyword) == MATCH_YES) \
- goto do_spec_only; \
- else if ((m2 = match_word (keyword, subr, &old_locus)) \
- == MATCH_YES) \
- { \
- ret = st; \
- goto finish; \
- } \
- else if (m2 == MATCH_ERROR) \
- goto error_handling; \
- else \
- undo_new_statement (); \
- } while (0)
+/* Like match. Does simd matching; sets flag simd_matched if keyword matched. */
+#define matchds(keyword, subr, st) \
+ match_internal(true, false, keyword, subr, st)
-/* Like match, but set a flag simd_matched if keyword matched. */
-#define matchds(keyword, subr, st) \
- do { \
- match m2; \
- if ((m2 = match_word_omp_simd (keyword, subr, &old_locus, \
- &simd_matched)) == MATCH_YES) \
- { \
- ret = st; \
- goto finish; \
- } \
- else if (m2 == MATCH_ERROR) \
- goto error_handling; \
- else \
- undo_new_statement (); \
- } while (0)
+/* Like matchds, but also honors spec_only. */
+#define matchs(keyword, subr, st) \
+ match_internal(true, true, keyword, subr, st)
/* Like match, but don't match anything if not -fopenmp. */
-#define matchdo(keyword, subr, st) \
- do { \
- match m2; \
- if (!flag_openmp) \
- ; \
- else if ((m2 = match_word (keyword, subr, &old_locus)) \
- == MATCH_YES) \
- { \
- ret = st; \
- goto finish; \
- } \
- else if (m2 == MATCH_ERROR) \
- goto error_handling; \
- else \
- undo_new_statement (); \
- } while (0)
+#define matchdo(keyword, subr, st) \
+ match_internal(false, false, keyword, subr, st)
+
+/* Like matchdo, but also honors spec_only. */
+#define matcho(keyword, subr, st) \
+ match_internal(false, true, keyword, subr, st)
static gfc_statement
decode_omp_directive (void)
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [Patch] Fortran: Cleanup OpenMP match{o,s,do,ds} macros
2022-06-30 12:30 [Patch] Fortran: Cleanup OpenMP match{o,s,do,ds} macros Tobias Burnus
@ 2022-06-30 12:51 ` Jakub Jelinek
0 siblings, 0 replies; 2+ messages in thread
From: Jakub Jelinek @ 2022-06-30 12:51 UTC (permalink / raw)
To: Tobias Burnus; +Cc: gcc-patches, fortran
On Thu, Jun 30, 2022 at 02:30:24PM +0200, Tobias Burnus wrote:
> OK for mainline - or should I put that patch into the bin?
Not sure, the other match* macros also aren't wrappers
around another macro and with the internal macro it means we'll
need to parse more many times (even when we then fold the conditions quite
early).
> +/* Like match, but with some special handling:
> + - dosimd - if false, don't do anything if not -fopenmp,
> + otherwise do match_word_omp_simd matching
> + - if dospec_only: if spec_only, goto do_spec_only after matching.
> +
> + If the directive matched but the clauses failed, do not start
> + matching the next directive in the same switch statement. */
> +
> +#define match_internal(match_simd, match_spec_only, keyword, subr, st) \
It at least should be matcho_internal or have the OpenMP stuff in the name
somehow, because it is quite OpenMP specific and isn't used by match or
matcha etc.
> +/* Like match. Does simd matching; sets flag simd_matched if keyword matched. */
Twice missing 2 spaces after .
Jakub
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-06-30 12:51 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-30 12:30 [Patch] Fortran: Cleanup OpenMP match{o,s,do,ds} macros Tobias Burnus
2022-06-30 12:51 ` Jakub Jelinek
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).