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]

Re: i386 PIC improvement for static functions.


>  > TREE_ADDRESSABLE appears to be set in some situations which don't
>  > require loading the pic register.  For example expand_call has:
> Right, but I don't think either of those two cases are all that common.

My read of expand_call is that:

	  if (!flag_no_inline
	      && fndecl != current_function_decl
	      && DECL_INLINE (fndecl)
	      && DECL_SAVED_INSNS (fndecl)
	      && RTX_INTEGRATED_P (DECL_SAVED_INSNS (fndecl)))
	    is_integrable = 1;

checks to see if this call is to a function which it may be possible
to integrate into the current function.  It requires that DECL_INLINE
be true for the function being called.  Otherwise:

	  else if (! TREE_ADDRESSABLE (fndecl))
	    {
	      /* In case this function later becomes inlinable,
		 record that there was already a non-inline call to it.

		 Use abstraction instead of setting TREE_ADDRESSABLE
		 directly.  */
	      if (DECL_INLINE (fndecl) && warn_inline && !flag_no_inline
		  && optimize > 0)
		{
		  warning_with_decl (fndecl, "can't inline call to `%s'");
		  warning ("called from here");
		}
	      mark_addressable (fndecl);
	    }

ensures that the function being called is marked as TREE_ADDRESSABLE.

Later:

  /* Cater to broken compilers.  */
  if (aggregate_value_p (exp))
    {
      /* This call returns a big structure.  */
      is_const = 0;

#ifdef PCC_STATIC_STRUCT_RETURN
      {
	pcc_struct_value = 1;
	/* Easier than making that case work right.  */
	if (is_integrable)
	  {
	    /* In case this is a static function, note that it has been
	       used.  */
	    if (! TREE_ADDRESSABLE (fndecl))
	      mark_addressable (fndecl);
	    is_integrable = 0;
	  }
      }

checks to see PCC_STATIC_STRUCT_RETURN is defined and a structure is being
returned in which case the function being called is marked as TREE_ADDRESSABLE.

Finally:

      /* If inlining failed, mark FNDECL as needing to be compiled
	 separately after all.  If function was declared inline,
	 give a warning.  */
      if (DECL_INLINE (fndecl) && warn_inline && !flag_no_inline
	  && optimize > 0 && ! TREE_ADDRESSABLE (fndecl))
	{
	  warning_with_decl (fndecl, "inlining failed in call to `%s'");
	  warning ("called from here");
	}
      mark_addressable (fndecl);

handles the case of a failed attempt to inline the function being called by
marking it as TREE_ADDRESSABLE.

In summary it appears that the only time a function being called will not
be marked as TREE_ADDRESSABLE is if it always gets inlined (in which case
the issue of optimizing the prologue is moot) or if fndecl == 0.  This
seems to be supported by the behavior observed when running cc1 in gdb
with break points at the calls to mark_addressable in expand_call when
compiling:

  int a;

  static void
  add(int b)
    {

    a += b;
    }

  void
  func(int c)
    {

    add(c);
    }

-- John
-------------------------------------------------------------------------
|   Feith Systems  |   Voice: 1-215-646-8000  |  Email: john@feith.com  |
|    John Wehle    |     Fax: 1-215-540-5495  |                         |
-------------------------------------------------------------------------



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