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]

PATCH for sibcalls on i386


Dear gcc hackers,

This patch is a follow-up to a discussion I had with several people on
the main gcc list not too long ago.

    (See also http://gcc.gnu.org/ml/gcc/2002-09/threads.html#00298)

I'm trying to make sibcall optimisation more general and I'm starting out
with the very common i386 platform.

Attached is a patch to gcc-3.2 that adds a few new call patterns to the
i386 machine description which allow sibcall optimisation for indirect
calls.  For example, it is possible to optimise the following code:

 extern int bar (int, int);
 void (*ptr) (int, int);
 void foo (int a, int b)
 {
   ptr = bar;
   return (*ptr) (a, b);
 }

Also, possible is:

 extern int bar (int, int);
 int (*ptr) (int, int);
 int foo (int a, int b)
 {
   ptr = bar;
   return (*ptr) (a, b);
 }

Etc.  I hope the idea is clear.

BRIEF OUTLINE:
--------------
I'm overriding the "fndecl == NULL_TREE" check in "calls.c" and cover it
in FUNCTION_OK_FOR_SIBCALL instead.  The macro will decide whether an
indirect call is a candidate for sibcall optimisation and if so, the
changed machine descriptions may be put into place at the end of
compilation.  Non-i386 architectures, however, still check for fndecl in
"calls.c", because they do not yet allow any indirect calls at all!  So,
the patch doesn't break anthing, as far as I know.

I'm aware that the patch is too small to actually make a huge difference
on gcc as a whole, but if the concept proves useful, then it could be
applied to other architectures as well and we could remove the test
"fndecl == NULL_TREE" totally from the file "calls.c".

However, it's a starting point and hopefully someone's able to give me
at least some feedback on this.

Thanks in advance,
Andreas.

Attachment: sibcall_patch.diff
Description: Text document


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