A call to a subprogram in the current unit is inlined if all the following conditions are met:
The optimization level is at least -O1.
The called subprogram is suitable for inlining: It must be small enough and not contain nested subprograms or anything else that gcc cannot support in inlined subprograms.
The call occurs after the definition of the body of the subprogram.
Either pragma Inline applies to the subprogram or it is small and automatic inlining (optimization level -O3) is specified.
Calls to subprograms in with'ed units are normally not inlined. To achieve this level of inlining, the following conditions must all be true:
The optimization level is at least -O1.
The called subprogram is suitable for inlining: It must be small enough and not contain nested subprograms or anything else gcc cannot support in inlined subprograms.
The call appears in a body (not in a package spec).
There is a pragma Inline for the subprogram.
The -gnatn switch is used in the gcc command line.
Note that specifying the -gnatn switch causes additional compilation dependencies. Consider the following:
package R is procedure Q; pragma Inline Q; end R; package body R is ... end R; with R; procedure Main is begin ... R.Q; end Main;
With the default behavior (no -gnatn switch specified), the compilation of the subprogram Main depends only on its own source, main.adb, and the spec of the package in file r.ads. This means that editing the body of R does not require recompiling Main.
On the other hand, the call R.Q is not inlined under these circumstances. If the -gnatn switch is present when Main is compiled, the call will be inlined if the body of Q is small enough, but now Main depends on the body of R in r.adb as well as the spec. This means that if the body is edited, the main program must be recompiled. Note that this extra dependency occurs whether or not the call is in fact inlined by gcc.
Note: The -fno-inline switch can be used to prevent all inlining. This switch overrides all other conditions and ensures that no inlining occurs. The extra dependencies resulting from -gnatn will still be active, even if this switch is used to suppress the resulting inlining actions.