comp.lang.ada
 help / color / mirror / Atom feed
From: dewar@cs.nyu.edu (Robert Dewar)
Subject: Re: Q: inlining
Date: 1996/06/16
Date: 1996-06-16T00:00:00+00:00	[thread overview]
Message-ID: <dewar.834938536@schonberg> (raw)
In-Reply-To: JSA.96Jun15185352@organon.com


Jon Anthony said (of inter-unit inlining):

"It can, yes.  I'm not sure if this is working in GNAT 3.05 yet or not."

Certainly it is! Once again Robert consults his secret source of GNAT
information (namely the standard documentation in gnatinfo.txt :-)
and provides the full answer:

Inlining of Subprograms
-----------------------

A call to a subprogram in the current unit is inlined if all the following
conditions are met:

    o  The optimization level is at least -O1

    o  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.

    o  The call occurs after the definition of the body of the subprogram.

    o  Either pragma Inline applies to the subprogram, or it is very 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 be true.

    o  The optimization level is at least -O1

    o  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.

    o  The call appears in a body (not in a package spec).

    o  There is a pragma Inline for the subprogram

    o  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 Main procedure 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, then 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,
then 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 GCC switch -fno-inline 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
the -fno-inline switch is used.


------------------
All this is in the section:

PERFORMANCE CONSIDERATIONS

which contains lots of useful stuff. In fact there is all sorts of
useful stuff in gnatinfo.txt, recommended reading for all GNAT users!





  reply	other threads:[~1996-06-16  0:00 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-06-15  0:00 Q: inlining Hannes Haug
1996-06-15  0:00 ` Jon S Anthony
1996-06-16  0:00   ` Robert Dewar [this message]
1996-06-17  0:00   ` Tucker Taft
1996-06-18  0:00   ` Jon S Anthony
1996-06-16  0:00 ` Hannes Haug
1996-06-18  0:00 ` Jon S Anthony
1996-06-19  0:00   ` Tucker Taft
1996-06-20  0:00     ` Robert Dewar
1996-06-20  0:00 ` Hannes Haug
1996-06-20  0:00   ` Robert Dewar
1996-06-24  0:00 ` Hannes Haug
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox