More space efficient virtual function calls

mike stump mrs@windriver.com
Sun Jul 7 15:45:00 GMT 2002


> From: "Wink Saville" <wink@saville.com>
> To: <gcc@gcc.gnu.org>
> Date: Sat, 6 Jul 2002 17:29:11 -0700

> I was wondering if there was switch in gcc that would cause it to
> generate smaller code when invoking virtual functions.

Most likely not, other than -Os.

> Is this already possible with an existing switch/pragma?

No.

> Is this practical?

Yes.

> Would most of the modifications be need to needed to the front end, back end
> or both?

It could be done in the port file.

> Could someone point me to the places I would need to change to try this out?

Sure.

Just create a peephole to find the code you want to replace:

>     LDR    R1,[R4]        /* Fetch the vtable pointer */
>     MOV    R0,R4        /* R0 = this */
>     MOV LR, PC          /* Set of the link register */
>     LDR PC,[R1, #4]  /* Call virtual function 1, the second entry */

and replace it with what you want:

>     LDR    R0,R4    /* R0 = this */
>     BL    __VTFunc1     /* Branch and Link to virtual thunk function 1  */

[ or whatever the right version is ], and do this when -Os is given.
You should then be able to `see' the compiler generate this code.
Then you will discover there is no definition for __VTFunc1, and you
will discover you want to added it to the .asm or .s file for the port
so it will wind up in libgcc.a.  Or, you can put it in a linkonce
section if the port supports it, and always emit them in each unit,
or, after you discover what longcall is, you might want to do it as
private in each unit.  I might recommend the last alternative.



More information about the Gcc mailing list