This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch, fortran] PR46331 Compilation time long with simple function in array constructor


On Wednesday 10 November 2010 00:14:20 Jerry DeLisle wrote:
> After some discussion on IRC I have arrived at the attached patch with
> Mikael's help. We found some inconsistency between setting of
> sym->attr.pure and setting of e->value.function.isym->pure.  Mikael came
> up with the suggested fix for that and this new patch passes regression
> testing and is easier to follow.  I got rid of the static
> check_specification_function and just in-lined that part in the only place
> that it was used.
> 
> OK for trunk?
> 
> Regards,
> 
> Jerry
> 
> PS Thanks Mikael and for those curious, the -fdump-tree-original files size
> drops from 1.4 Mbytes to under 4kbytes on the original test case.
> 
> 2010-11-09  Jerry DeLisle  <jvdelisle@gcc.gnu.org>
> 	    Mikael Morin   <mikael@gcc.gnu.org>
> 
> 	PR fortran/46331
> 	* intrinsic.c: Correctly set the pure attributes for intrinsic
> 	functions.
> 	* expr.c (check_specification_function): Remove this function and move
> 	its code into gfc_is_constant_expr. (gfc_is_constant_expr): Change the
> 	order of checks by checking for non-constant arguments first.  Then,
> 	check for initialization functions, followed by intrinsics.
> 
> 
> pr46331-c.diff
> Index: expr.c
> ===================================================================
> --- expr.c      (revision 166469)
> +++ expr.c      (working copy)
> @@ -868,31 +868,6 @@ done:
>  }
>  
>  
> -static match
> -check_specification_function (gfc_expr *e)
> -{
> -  gfc_symbol *sym;
> -
> -  if (!e->symtree)
> -    return MATCH_NO;
> -
> -  sym = e->symtree->n.sym;
> -
> -  /* F95, 7.1.6.2; F2003, 7.1.7  */
> -  if (sym
> -      && sym->attr.function
> -      && sym->attr.pure
> -      && !sym->attr.intrinsic
> -      && !sym->attr.recursive
> -      && sym->attr.proc != PROC_INTERNAL
> -      && sym->attr.proc != PROC_ST_FUNCTION
> -      && sym->attr.proc != PROC_UNKNOWN
> -      && sym->formal == NULL)
> -    return MATCH_YES;
> -
> -  return MATCH_NO;
> -}
> -
>  /* Function to determine if an expression is constant or not.  This
>     function expects that the expression has already been simplified.  */
>  
> @@ -901,6 +876,7 @@ gfc_is_constant_expr (gfc_expr *e)
>  {
>    gfc_constructor *c;
>    gfc_actual_arglist *arg;
> +  gfc_symbol *sym;
>  
>    if (e == NULL)
>      return 1;
> @@ -918,22 +894,41 @@ gfc_is_constant_expr (gfc_expr *e)
>      case EXPR_FUNCTION:
>      case EXPR_PPC:
>      case EXPR_COMPCALL:
> -      /* Specification functions are constant.  */
> -      if (check_specification_function (e) == MATCH_YES)
> -       return 1;
> -
>        /* Call to intrinsic with at least one argument.  */
>        if (e->value.function.isym && e->value.function.actual)
>         {
>           for (arg = e->value.function.actual; arg; arg = arg->next)
>             if (!gfc_is_constant_expr (arg->expr))
>               return 0;
> -
> -         return 1;
>         }
> -      else
> -       return 0;
>  
> +      /* Make sure we have a symbol.  */
> +      gcc_assert (e->symtree);
> +
> +      sym = e->symtree->n.sym;
> +    
> +      /* Specification functions are constant.  */
> +      /* F95, 7.1.6.2; F2003, 7.1.7  */
> +      if (sym
> +         && sym->attr.function
> +         && sym->attr.pure
> +         && !sym->attr.intrinsic
> +         && !sym->attr.recursive
> +         && sym->attr.proc != PROC_INTERNAL
> +         && sym->attr.proc != PROC_ST_FUNCTION
> +         && sym->attr.proc != PROC_UNKNOWN
> +         && sym->formal == NULL)
> +       return 1;
> +
> +      if (e->value.function.isym
> +         && (e->value.function.isym->elemental
> +         || e->value.function.isym->pure
> +         || e->value.function.isym->inquiry
> +         || e->value.function.isym->transformational))
> +       return 1;
As now the pure flag is set with cl != CLASS_IMPURE, checking the pure flag 
only should be sufficient. I don't really care, so Jerry, you can keep this 
version (which you have regression tested I suppose ?) if you prefer it. 
Please indent more the three || conditions.

OK with the above comment. Thanks for the patch (and for your patience)
Mikael


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]