Topic: Inline request in function


Author: "Ronald F. Guilmette" <rfg@rahul.net>
Date: 1995/06/24
Raw View
In article <JASON.95Jun18160622@phydeaux.cygnus.com>,
Jason Merrill <jason@cygnus.com> wrote:
>>>>>> Ronald F Guilmette <rfg@rahul.net> writes:
>
>> Given that C++ implementations have already been saddled with the current
>> draft's requirements with respect to inter-translation-unit template
>> instantiation, it seems to be only a modest step to also require C++
>> implementations to perform inlining of functions across translation
>> unit boundaries.
>
>C++ implementations are not currently required to perform inlining *within*
>translation unit boundaries.  Perhaps you only mean to withdraw this
>requirement from the draft:
>
>3 An inline function shall be defined in every translation unit in which
>  it  is used (_basic.def.odr_)

Yes.  Exactly.
--

-- Ron Guilmette, Sunnyvale, CA ---------- RG Consulting -------------------
---- E-mail: rfg@segfault.us.com ----------- Purveyors of Compiler Test ----
---- finger: rfg@rahul.net ----------------- Suites and Bullet-Proof Shoes -





Author: wil@ittpub.nl (Wil Evers)
Date: 1995/06/19
Raw View
In article <3s1qq6$phd@hustle.rahul.net>  Ron Guilmette
(rfg@segfault.us.com) writes:
>
> [snip]
>
> An even more relevant observation is that in C++, template bodies may be
> instantiated across translation units.  The implication of this
requirement
> (of the draft standard) is that all conforming C++ implementations
_must_
> have some sort of persistant ``program library'', not all that different
> from what Ada implementations have provided for many years.
>
> Given that C++ implementations have already been saddled with the
current
> draft's requirements with respect to inter-translation-unit template
> instantiation, it seems to be only a modest step to also require C++
> implementations to perform inlining of functions across translation
> unit boundaries.  Doing so would (of course) have distinct benefits
> for the end-user.

And, if I may add, such a database could also be used to match class
definitions and their corresponding object instantiations. With a bit of
extra syntax, that would enable us to move the gory private members from
the headers to the implementation files without any added runtime
overhead...

- Wil





Author: "Ronald F. Guilmette" <rfg@rahul.net>
Date: 1995/06/18
Raw View
In article <1995Jun13.214218.28431@nlm.nih.gov>,
Bob Kline Phoenix Contract <bkline@cortex.nlm.nih.gov> wrote:
>Per Gunnar Hanso (pergh@stud.idb.hist.no) wrote:
>: Steve Clamage (clamage@Eng.Sun.COM) wrote:
>: : In article m54@astfgl.idb.hist.no, pergh@stud.idb.hist.no
>: : (Per Gunnar Hanso) writes:
>: : >In C++ there is one thing I'd like to see. A way to inline a function
>: : >at one specific place in the code. ...
>: : >
>
>: : You can do it already. Write two funtions:
>
>: :  inline T inline_foo( ... ) { ... }
>
>: :  T foo( ... ) { return inline_foo( .. ); }
>
>: Hmm, this is a good way to do it. However, it demands that I have the
>: source of the library. If this was a part of the language, I wouldn't
>: need that.
>
>If the compiler can't see the source for the function you want to
>have expanded inline, there's no way for it to perform the expansion.

By ``seeing'' I assume that you mean that the compiler must have seen
(past tense) the definition of the function earlier within the same
translation unit.

That is indeed the requirement (for most implementations) today, but I
attribute this limitation only to tradition, and not to any overriding
technical impossibility.

In Ada, it is a common thing to inline a function whose body is provided
within some totally separate translation unit... assuming of course that
the separate unit in question was compiled some time _prior_ to the code
which make the call to the inlinable function in question.

An even more relevant observation is that in C++, template bodies may be
instantiated across translation units.  The implication of this requirement
(of the draft standard) is that all conforming C++ implementations _must_
have some sort of persistant ``program library'', not all that different
from what Ada implementations have provided for many years.

Given that C++ implementations have already been saddled with the current
draft's requirements with respect to inter-translation-unit template
instantiation, it seems to be only a modest step to also require C++
implementations to perform inlining of functions across translation
unit boundaries.  Doing so would (of course) have distinct benefits
for the end-user.

--

-- Ron Guilmette, Sunnyvale, CA ---------- RG Consulting -------------------
---- E-mail: rfg@segfault.us.com ----------- Purveyors of Compiler Test ----
---- finger: rfg@rahul.net ----------------- Suites and Bullet-Proof Shoes -





Author: jason@cygnus.com (Jason Merrill)
Date: 1995/06/18
Raw View
>>>>> Ronald F Guilmette <rfg@rahul.net> writes:

> Given that C++ implementations have already been saddled with the current
> draft's requirements with respect to inter-translation-unit template
> instantiation, it seems to be only a modest step to also require C++
> implementations to perform inlining of functions across translation
> unit boundaries.

C++ implementations are not currently required to perform inlining *within*
translation unit boundaries.  Perhaps you only mean to withdraw this
requirement from the draft:

3 An inline function shall be defined in every translation unit in which
  it  is used (_basic.def.odr_)

Jason





Author: bkline@cortex.nlm.nih.gov (Bob Kline Phoenix Contract)
Date: 1995/06/13
Raw View
Per Gunnar Hanso (pergh@stud.idb.hist.no) wrote:
: Steve Clamage (clamage@Eng.Sun.COM) wrote:
: : In article m54@astfgl.idb.hist.no, pergh@stud.idb.hist.no
: : (Per Gunnar Hanso) writes:
: : >In C++ there is one thing I'd like to see. A way to inline a function
: : >at one specific place in the code. ...
: : >

: : You can do it already. Write two funtions:

: :  inline T inline_foo( ... ) { ... }

: :  T foo( ... ) { return inline_foo( .. ); }

: Hmm, this is a good way to do it. However, it demands that I have the
: source of the library. If this was a part of the language, I wouldn't
: need that.

If the compiler can't see the source for the function you want to
have expanded inline, there's no way for it to perform the expansion.

--
/*----------------------------------------------------------------------*/
/* Bob Kline                                       Stream International */
/* bob_kline@stream.com               formerly Corporate Software, Inc. */
/* voice: (703) 522-0820 x-311                      fax: (703) 522-5407 */
/*----------------------------------------------------------------------*/





Author: maxtal@Physics.usyd.edu.au (John Max Skaller)
Date: 1995/06/07
Raw View
In article <3r0n5s$m54@astfgl.idb.hist.no>,
Per Gunnar Hanso <pergh@stud.idb.hist.no> wrote:
>In C++ there is one thing I'd like to see. A way to inline a function
>at one specific place in the code.

 It might be interesting to discover how smart compilers are.

 #include <iostream.h>
 inline int f(int i) { return i+1; }
 int (*g)(int) = f;
 main() {
  cout << f(1) << endl;
  cout << (*&f)(1) << endl;
  cout << g(1) << endl;
 }

How many compilers are smart enough to inline all 3 calls?


--
        JOHN (MAX) SKALLER,         INTERNET:maxtal@suphys.physics.su.oz.au
 Maxtal Pty Ltd,
        81A Glebe Point Rd, GLEBE   Mem: SA IT/9/22,SC22/WG21
        NSW 2037, AUSTRALIA     Phone: 61-2-566-2189





Author: kevinl@fangorn.cs.monash.edu.au (Kevin Lentin)
Date: 1995/06/08
Raw View
John Max Skaller (maxtal@Physics.usyd.edu.au) wrote:
>  It might be interesting to discover how smart compilers are.
>
>  #include <iostream.h>
>  inline int f(int i) { return i+1; }
>  int (*g)(int) = f;
>  main() {
>   cout << f(1) << endl;
>   cout << (*&f)(1) << endl;
>   cout << g(1) << endl;
>  }
>
> How many compilers are smart enough to inline all 3 calls?

Well, gcc (2.5.7) won't even compile the second one.
Using -O2, it inlines the first one as:
register = 2
call << operator

The third involves putting 1 in a register, doing the indirect function
call, and then moving the result from one register to another before
calling the << operator. Bit disappointing.

2.6.3 gives the same code. It is, however, able to compile the second call.
It generates identical code to the first call (save for one clr
instruction between the calls).

--
[==================================================================]
[ Kevin Lentin                   |___/~\__/~\___/~~~~\__/~\__/~\_| ]
[ kevinl@cs.monash.edu.au        |___/~\/~\_____/~\______/~\/~\__| ]
[ Macintrash: 'Just say NO!'     |___/~\__/~\___/~~~~\____/~~\___| ]
[==================================================================]





Author: kanze@lts.sel.alcatel.de (James Kanze US/ESC 60/3/141 #40763)
Date: 1995/06/08
Raw View
In article <D9tqt7.68F@ucc.su.OZ.AU> maxtal@Physics.usyd.edu.au (John
Max Skaller) writes:

|> In article <3r0n5s$m54@astfgl.idb.hist.no>,
|> Per Gunnar Hanso <pergh@stud.idb.hist.no> wrote:
|> >In C++ there is one thing I'd like to see. A way to inline a function
|> >at one specific place in the code.

|>  It might be interesting to discover how smart compilers are.

|>  #include <iostream.h>
|>  inline int f(int i) { return i+1; }
|>  int (*g)(int) = f;
|>  main() {
|>   cout << f(1) << endl;
|>   cout << (*&f)(1) << endl;
|>   cout << g(1) << endl;
|>  }

|> How many compilers are smart enough to inline all 3 calls?

It would generally require either inter-module flow analysis in order
to inline case 3, and I don't know of many compilers which do such.
(Note that `g' is a global variable which could eventually be modified
by one of the functions called in evaluating the first to statements.)
--
James Kanze         Tel.: (+33) 88 14 49 00        email: kanze@gabi-soft.fr
GABI Software, Sarl., 8 rue des Francs-Bourgeois, F-67000 Strasbourg, France
Conseils en informatique industrielle --
                              -- Beratung in industrieller Datenverarbeitung







Author: pergh@stud.idb.hist.no (Per Gunnar Hanso)
Date: 1995/06/08
Raw View
Steve Clamage (clamage@Eng.Sun.COM) wrote:
: In article m54@astfgl.idb.hist.no, pergh@stud.idb.hist.no
: (Per Gunnar Hanso) writes:
: >In C++ there is one thing I'd like to see. A way to inline a function
: >at one specific place in the code. ...
: >

: You can do it already. Write two funtions:

:  inline T inline_foo( ... ) { ... }

:  T foo( ... ) { return inline_foo( .. ); }

Hmm, this is a good way to do it. However, it demands that I have the
source of the library. If this was a part of the language, I wouldn't
need that.

Thanks for the workaround though, I'll use it :-)


pergh
--
Per Gunnar Hans                      |    Only dead fish swim downstream.
Trondheim College of Engineering   |     __    <><    <><   ><>
Norway                             |    <__><      <><         <><





Author: clamage@Eng.Sun.COM (Steve Clamage)
Date: 1995/06/06
Raw View
In article m54@astfgl.idb.hist.no, pergh@stud.idb.hist.no (Per Gunnar Hanso) writes:
>In C++ there is one thing I'd like to see. A way to inline a function
>at one specific place in the code. ...
>
>
>Where it is nessessary with speed, I get the function inline, and elsewhere
>I call it like a normal function. I miss this functionality every now and
>then.

You can do it already. Write two funtions:

 inline T inline_foo( ... ) { ... }

 T foo( ... ) { return inline_foo( .. ); }

---
Steve Clamage, stephen.clamage@eng.sun.com







Author: pergh@stud.idb.hist.no (Per Gunnar Hanso)
Date: 1995/06/06
Raw View
In C++ there is one thing I'd like to see. A way to inline a function
at one specific place in the code. It's easy to explain with a sample:

void Swap(int& A, int& B)
{
  int Temp = A;
  A = B;
  B = Temp;
}

int main()
{
  int Table[20002];
  for (int i = 0; i < 20000; i++) {
    inline Swap(Table[i],Table[i+1]);
  }
  Swap(Table[0], Table[20001]);
}


Where it is nessessary with speed, I get the function inline, and elsewhere
I call it like a normal function. I miss this functionality every now and
then.

If anybody knows who is working on the standard for C++, please feel free
to give them this idea.


pergh
--
Per Gunnar Hans                      |    Only dead fish swim downstream.
Trondheim College of Engineering   |     __    <><    <><   ><>
Norway                             |    <__><      <><         <><