This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Re: [FORTRAN PATCH] Reduce gfc_match_strings usage (part 2)
Tobias Schlüter wrote:
Presumably the biggest speedup can be obtained by eating ',' followed by
whitespace before the call to gfc_match_strings in decl.c:2161, and
matching double colons separately, as this is a case where valid code
will have to backup insanely often.
I was overestimating gfc_match-strings' badness when I wrote this: as
gfc_match_strings will only read each source character once, there's no
backing up between matching individual strings, and the performance gain
of my suggested approach would be much smaller than I had thought: the
only differences would be that one comparison against a NULL pointer
(for DECL_COLON) would be omitted per loop iteration, and the comparison
of the first few characters against ", " would only be done once.
Nevertheless, I implemented my suggestion in the attached patch, and I
would be grateful if you could check its effect on the profile, FX.
Patch built on i386-darwin, so far it holds up against the testsuite.
Thanks,
- Tobi
2007-03-11 Tobias Schlüter <tobi@gcc.gnu.org>
* decl.c (decls): Only keep attributes in array, remove
leading ", ".
(match_attr_spec): Match double colon and attribute separators
separately from attributes.
Index: gcc/fortran/decl.c
===================================================================
--- gcc/fortran/decl.c (revision 122819)
+++ gcc/fortran/decl.c (working copy)
@@ -2118,24 +2118,23 @@ match_attr_spec (void)
#define NUM_DECL GFC_DECL_END
static mstring decls[] = {
- minit (", allocatable", DECL_ALLOCATABLE),
- minit (", dimension", DECL_DIMENSION),
- minit (", external", DECL_EXTERNAL),
- minit (", intent ( in )", DECL_IN),
- minit (", intent ( out )", DECL_OUT),
- minit (", intent ( in out )", DECL_INOUT),
- minit (", intrinsic", DECL_INTRINSIC),
- minit (", optional", DECL_OPTIONAL),
- minit (", parameter", DECL_PARAMETER),
- minit (", pointer", DECL_POINTER),
- minit (", protected", DECL_PROTECTED),
- minit (", private", DECL_PRIVATE),
- minit (", public", DECL_PUBLIC),
- minit (", save", DECL_SAVE),
- minit (", target", DECL_TARGET),
- minit (", value", DECL_VALUE),
- minit (", volatile", DECL_VOLATILE),
- minit ("::", DECL_COLON),
+ minit ("allocatable", DECL_ALLOCATABLE),
+ minit ("dimension", DECL_DIMENSION),
+ minit ("external", DECL_EXTERNAL),
+ minit ("intent ( in )", DECL_IN),
+ minit ("intent ( out )", DECL_OUT),
+ minit ("intent ( in out )", DECL_INOUT),
+ minit ("intrinsic", DECL_INTRINSIC),
+ minit ("optional", DECL_OPTIONAL),
+ minit ("parameter", DECL_PARAMETER),
+ minit ("pointer", DECL_POINTER),
+ minit ("protected", DECL_PROTECTED),
+ minit ("private", DECL_PRIVATE),
+ minit ("public", DECL_PUBLIC),
+ minit ("save", DECL_SAVE),
+ minit ("target", DECL_TARGET),
+ minit ("value", DECL_VALUE),
+ minit ("volatile", DECL_VOLATILE),
minit (NULL, DECL_NONE)
};
@@ -2158,8 +2157,21 @@ match_attr_spec (void)
for (;;)
{
+ gfc_gobble_whitespace ();
+ if (gfc_match ("::") == MATCH_YES)
+ {
+ d = DECL_COLON;
+ break;
+ }
+
+ if (gfc_match (", ") != MATCH_YES)
+ {
+ d = DECL_NONE;
+ break;
+ }
+
d = (decl_types) gfc_match_strings (decls);
- if (d == DECL_NONE || d == DECL_COLON)
+ if (d == DECL_NONE)
break;
seen[d]++;