This is the mail archive of the gcc@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]

questions about improving i386 PIC code


Consider:

  static int
  compare(int a, int b)
    {

    return a > b ? a : b;
    }

  static int
  local_function(int a, int b)
    {

    return compare(a, b);
    }

  int
  global_function(int a, int b)
    {

    return local_function(a, b);
    }

The resulting assembler for local_function when compiling PIC is:

	.type	 _local_function,@function
_local_function:
	pushl %ebp
	movl %esp,%ebp
	pushl %ebx
	call L5
L5:
	popl %ebx
	addl $_GLOBAL_OFFSET_TABLE_+[.-L5],%ebx
	pushl 12(%ebp)
	pushl 8(%ebp)
	call _compare@PLT
	movl -4(%ebp),%ebx
	leave
	ret

It seems to me that local_function shouldn't need to reload
the pic register (%ebx) since it's only called from another
function in the same source file.

What's the feasibility / ramifications of deferring generating
the assembler code for static functions until all other functions
have been compiled?  This way we can detect if the function is
only referenced in calls in which case the pic register doesn't
need to be reloaded.

Assuming that this makes sense ... any pointers at what code
I should be examining in order to:

  1) Defer outputting static functions.

  2) Detect if a static function is used in some fashion
     other than by being called.

I look forward to hearing other thoughts / suggestions on the
subject.

-- 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]