The (black?) art of inlining...

Daniel Lohmann daniel.lohmann@informatik.uni-erlangen.de
Mon Jun 25 20:56:00 GMT 2007



Jim Marshall schrieb:
> I have some code which we have been compiling with GCC 3.2.2 (yes its 
> old). We recently added Solaris SPARC which has GCC 3.4.6. I have a 
> couple of functions that I would prefer to be inline all the time. On 
> GCC 3.2.2 I receive no warnings when I compile my code (which makes me 
> believe these functions are inlined). I am using the following compile 
> options:
> 
> cc -o /home/jmars/server/lib/schema.o   -O3 -finline-functions 
> -fmerge-constants -fexpensive-optimizations -Wuninitialized -fpic -c 
> -Werror -Winline -Wformat -Wno-return-type 
> -Werror-implicit-function-declaration -Wparentheses -Wredundant-decls 
> -m32 -msse -minline-all-stringops -finline -D_UNICODE -DUNICODE 
> -D_COMPILE_UNIX -D__USE_POSIX -D_GNU_SOURCE -DTHREAD_SAFE -D_REENTRANT 
> -D_LINUX -I./include -DWSI_EXPAT_BUILD 
> -I/home/jmars/server/private/include -I/home/jmars/api/include 
> -I/home/jmars/utils/include -I/home/jmars/common/lib/include 
> -I/home/jmars/202/wsi/thirdparty/expat/include -D_USE_GC 
> ./src/cimxml_schema.c
> 
> and I get the following warning (this is with GCC 4.1.1 on Linux FC 6) - 
> (I don't have direct access to my Sparc machine but the warning was 
> similar)
> 
> ./src/schema.c: In function ‘scope_encodeformat’:
> /home/jmars/server/api/include/apiext.h:382: warning: inlining failed in 
> call to ‘freeValidMemory’: --param inline-unit-growth limit reached
> ./src/schema.c:3285: warning: called from here
> make[2]: *** [/home/jmars/proto/temp/server/lib/schema.o] Error 1
> 
> The function is question is (in this case INLINE is defined as #define 
> INLINE inline):
> 
> static INLINE void freeValidMemory(void* vptr, wsi_heap heap)
> {
>     if (vptr != NULL)
>     {
>         /* if we are finding leaks, make sure we always call GC_free */
>         if (GC_find_leak == 0)
>         {
>             /* not looking for leaks */
>             size_t ptrSize = GC_size(vptr);
>             if (ptrSize > 0 && ptrSize <= GC_SMALL_SIZE)
>             {
>               /* set the first element to 0 (NULL) */
>                 memset(vptr, 0, 1);
>             } else {
>                 GC_FREE(vptr);
>             }
>         } else {
>             /* looking for leaks, call GC_FREE */
>             GC_FREE(vptr);
>         }
>     }
> }
> 
> Any thoughts on how I can force this function to be inline?

If you want a function to be inlined in any case define it with 
__attribute__((always_inline)).

Another option might be to generally increase the inline limit with 
-finline-limit=<high number>. The default is, AFAIK, 600, so giving it a 
6000 should inline almost everything. Take a look at the inline options in 
the gcc manual.

Daniel



More information about the Gcc-help mailing list