From facf0354cfdaa555f376311b9d3c8fec79747f09 Mon Sep 17 00:00:00 2001 From: Martin Liska Date: Tue, 27 Nov 2018 14:06:48 +0100 Subject: Support simd function declarations via a pre-include. 2018-11-27 Martin Liska * config/gnu-user.h (TARGET_F951_OPTIONS): New. * gcc.c (find_fortran_preinclude_file): New function to handle Fortran pre-include. 2018-11-27 Martin Liska * decl.c (gfc_match_gcc_builtin): New function. * gfortran.h (struct vect_builtin_tuple): New. (gfc_adjust_builtins): Likewise. * lang-specs.h (TARGET_F951_OPTIONS): New. (F951_OPTIONS): Use it. * lang.opt: Add new option -fpre-include. * match.h (gfc_match_gcc_builtin): Declare new function. * parse.c (decode_gcc_attribute): Handle builtin. (parse_progunit): Call gfc_adjust_builtins. * scanner.c (gfc_new_file): Load pre-included header file when provided. * trans-intrinsic.c (add_simd_flag_for_built_in): New. (gfc_adjust_builtins): Likewise. 2018-11-27 Martin Liska * gfortran.dg/simd-builtins-1.f90: New test. * gfortran.dg/simd-builtins-1.h: New test. * gfortran.dg/simd-builtins-2.f90: New test. * gfortran.dg/simd-builtins-3.f90: New test. * gfortran.dg/simd-builtins-3.h: New test. * gfortran.dg/simd-builtins-4.f: New test. * gfortran.dg/simd-builtins-4.h: New test. * gfortran.dg/simd-builtins-5.f: New test. * gfortran.dg/simd-builtins-6.f90: New test. From-SVN: r266509 --- gcc/fortran/decl.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'gcc/fortran/decl.c') diff --git a/gcc/fortran/decl.c b/gcc/fortran/decl.c index 2b77d95..ac86798 100644 --- a/gcc/fortran/decl.c +++ b/gcc/fortran/decl.c @@ -98,6 +98,9 @@ bool gfc_matching_function; /* Set upon parsing a !GCC$ unroll n directive for use in the next loop. */ int directive_unroll = -1; +/* Map of middle-end built-ins that should be vectorized. */ +hash_map *gfc_vectorized_builtins; + /* If a kind expression of a component of a parameterized derived type is parameterized, temporarily store the expression here. */ static gfc_expr *saved_kind_expr = NULL; @@ -11243,3 +11246,41 @@ gfc_match_gcc_unroll (void) gfc_error ("Syntax error in !GCC$ UNROLL directive at %C"); return MATCH_ERROR; } + +/* Match a !GCC$ builtin (b) attributes simd flags form: + + The parameter b is name of a middle-end built-in. + Flags are one of: + - (empty) + - inbranch + - notinbranch + + When we come here, we have already matched the !GCC$ builtin string. */ +match +gfc_match_gcc_builtin (void) +{ + char builtin[GFC_MAX_SYMBOL_LEN + 1]; + + if (gfc_match (" ( %n ) attributes simd", builtin) != MATCH_YES) + return MATCH_ERROR; + + gfc_simd_clause clause = SIMD_NONE; + if (gfc_match (" ( notinbranch ) ") == MATCH_YES) + clause = SIMD_NOTINBRANCH; + else if (gfc_match (" ( inbranch ) ") == MATCH_YES) + clause = SIMD_INBRANCH; + + if (gfc_vectorized_builtins == NULL) + gfc_vectorized_builtins = new hash_map (); + + char *r = XNEWVEC (char, strlen (builtin) + 32); + sprintf (r, "__builtin_%s", builtin); + + bool existed; + int &value = gfc_vectorized_builtins->get_or_insert (r, &existed); + value |= clause; + if (existed) + free (r); + + return MATCH_YES; +} -- cgit v1.1