comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@shell01.TheWorld.com>
Subject: Re: When shoul Pragma Inline be used?
Date: 23 Feb 2003 17:00:51 -0500
Date: 2003-02-23T17:00:51-05:00	[thread overview]
Message-ID: <wccadgmhd2k.fsf@shell01.TheWorld.com> (raw)
In-Reply-To: 3E590DC1.5000005@acm.org

Jeffrey Carter <jrcarter@acm.org> writes:

> A general rule I learned is: Inline small subprograms if your program
> has tight time constraints. "Small" is not precisely defined; you have
> to decide how many statements is too many. Some compilers will
> automatically inline calls to small subprograms. Such compilers must
> have a precise definition of "small", probably based on the size of the
> object code.

I think such compilers usually measure the size of some low-level
intermediate code, rather than the object code itself.  It amounts to
more-or-less the same thing.

But note that in some cases the size of the object code can change
dramatically due to inlining.  For example:

    function F(X: Some_Enum_Type) return Integer is
    begin
        case X is
            when Red => return 17;
            when Green => ...
            when ...
            ... -- 100 more lines of code
        end case;
    end F;

While F is probably too big for inlining just looking at the amount of
code in the body of F, a call like "F(Red)", if inlined, will boil down
to just the literal number "17" (assuming the optimizer is smart
enough).

The advice given elsewhere in this thread, to measure the speed-effects
of pragma Inline, is good.  If your compiler doesn't inline
automatically, guess where to put pragmas Inline (based on size of code
and other issues), and measure the effect.

- Bob



  reply	other threads:[~2003-02-23 22:00 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-02-23 14:33 When shoul Pragma Inline be used? Preben Randhol
2003-02-23 17:26 ` Bobby D. Bryant
2003-02-23 21:05   ` tmoran
2003-02-23 18:07 ` Jeffrey Carter
2003-02-23 22:00   ` Robert A Duff [this message]
2003-02-24  9:29   ` Preben Randhol
replies disabled

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