Re: Inlining functions with loops

jplevyak@violet-femmes.cs.uiuc.edu (John B. Plevyak)
Thu, 30 Nov 1995 18:31:28 GMT

          From comp.compilers

Related articles
Inlining functions with loops mpr@absoft.com (Michael Rice) (1995-11-29)
Re: Inlining functions with loops jplevyak@violet-femmes.cs.uiuc.edu (1995-11-30)
Re: Inlining functions with loops meissner@cygnus.com (Michael Meissner) (1995-11-30)
Re: Inlining functions with loops preston@tera.com (1995-11-30)
Re: Inlining functions with loops ayers@apollo.hp.com (1995-11-30)
Re: Inlining functions with loops cdg@nullstone.com (1995-12-01)
Re: Inlining functions with loops jeremy@suede.sw.oz.au (1995-12-01)
Inlining functions with loops dave@occl-cam.demon.co.uk (Dave Lloyd) (1995-12-01)
[7 later articles]
| List of all articles for this month |
Newsgroups: comp.compilers
From: jplevyak@violet-femmes.cs.uiuc.edu (John B. Plevyak)
Keywords: optimize, C++
Organization: University of Illinois at Urbana
References: 95-11-241
Date: Thu, 30 Nov 1995 18:31:28 GMT

Michael Rice (mpr@absoft.com) wrote:
: All C++ compilers that I am aware of will not inline a function if it
: contains any type of loop. Is anyone aware of ANY C++ compiler that
: will do this?


The Concert compiler for ICC++ (a concurrent dialect of C++) does.


: I believe the basic problem is the inability to convert such a function
: to a suitable expression tree.


This presumes that inlining is done at the expression level.
Inlining can be done at the intermediate code level, for example
3 address code or (as in our compiler) a control dependence graph (CDG)
in static single assignment form (SSA). e.g.


int x;
int foo (int i) { for(;i--;) printf("foo"); return x; }


int main() {
    printf("main %d\n",foo(2);
}


becomes:


int foo(int i) {
    MOVE "foo" temp_string
    PHI i0 = i,i1 WHILE i0
        i1 = CALL - i0 1
        dummy = CALL printf temp_string
    MOVE x return_value
}


int main() {
    MOVE 2 arg
    result = CALL foo arg
    MOVE "main %d\n" temp_string
    dummy = CALL printf temp_string result
}


The function is then inlined by substitution for the call:


int main() {
    MOVE 2 arg
! MOVE arg i
! MOVE "foo" temp_string
! PHI i0 = i,i1 WHILE i0
! i1 = CALL - i0 1
! dummy = CALL printf temp_string
! MOVE x return_value
! MOVE return_value result
    MOVE "main %d\n" temp_string
    dummy = CALL printf temp_string result
}


Further optimization can proceed to cleanup the extra moves,
unroll the loop or whatever.


--
    John Plevyak (plevyak@uiuc.edu) (217) 244-7116 PGP KeyID: 0x051130BD
                          Concurrent Systems Architecture Group
                    University of Illinois at Urbana-Champaign
      2233 Digital Computer Lab, 1304 West Springfield, Urbana, IL 61801
<A HREF="http://www-csag.cs.uiuc.edu/individual/jplevyak">My Home Page</A>
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.