tags:

views:

53

answers:

2

I don't know how feasible it is and how sensible is this question here.

Is there any changes that we can make in makefile to recommend GCC inline all the function although the functions are not inlined during the declaration or nowhere in the source file.

+1  A: 

The gcc -finline_functions option sounds like it might do what you want. Here is some documentation. If your makefile defines a CFLAGS variable, that would be the place to put it.

Jim Lewis
@Jim, thanks for your answer. i will try it and keep on updating.
thetna
@Jim, i tried the way you have mentioned here. it worked for only a single soruce code file. how about the a number of source code files which are included to one another?
thetna
@thetna: It's hard to say anything more without knowing how your project is structured, and what you've tried so far. But Michał Trybus makes a good point -- function inlining doesn't work across translation units; the function definition has to be available in each source file, for example by putting the function definition in a .h file and including it in each .c file. If your project isn't already structured like this, the -finline_functions option won't do much, as you've seen...you'll need to rearrange the code.
Jim Lewis
+2  A: 

There are a few ways you can make gcc inline functions. One of them is the option -finline-functions, which will make gcc inline "simple" functions. The compiler uses some heuristics to determine whether the function is small enough to be inlined. However, the user has some control over this algorithm through -finline-limit. Read the gcc manual to find the actual values you need.

When inlining functions you should remember that obviously not all functions can be inlined (the simplest example being recursive functions) and the compiler can inline only functions defined within the same translation unit. Also, it is worth mentioning that -finline-functions is on by default at -O3, so just -O3 may sometimes be your solution.

In the makefile you will have to add the right options to all calls to gcc. In a well written makefile you'll easily spot variables with other gcc options, where you can simply place your own.

Michał Trybus
@michal, thanks for your answer. i will be trying it and keep on updating.
thetna
@michal, i tried the way you have mentioned here. it worked for only a single soruce code file. how about the a number of source code files which are included to one another?
thetna
If some source files are indeed included to the one you compile with `-finline-functions`, everything which the compiler (and you, by using proper options) allows should be properly inlined. In real situations, though, files are compiled separately, and a function defined in one file won't be inlined in a different one, as the compiler doesn't know its definition when compiling the latter. The only way to make sure a function can be always inlined is to add the whole definition to a header file and make sure it's included in all files which use that function. You can't do it with a Makefile.
Michał Trybus