[LLVMdev] How to handle nested procedures?

Chris Lattner sabre at nondot.org
Sun Aug 22 18:36:25 PDT 2004


On Sun, 22 Aug 2004, Jeff Cohen wrote:
> > functions.  The struct idea is probably a good LLVM way to do it.  In a
> > normal compiler you would use displays or access links, which basically
> > consist of having some way to refer to the stack frame of a parent function.
> > The struct would be acheiving the same thing.

Yup Patrick is right, either using lambda lifting, displays, etc to
implement this.  We don't plan to have direct support for it in LLVM.

> I was concerned that if the optimizer inlined inner, it would not be
> able to eliminate all the overhead introduced by this scheme.  So I ran
> a test.  I simulated the above with the following C code:

...

> This produces:
>
> int %outer(int %a) {
> entry:
> 	%tmp.4.i = shl int %a, ubyte 1		; <int> [#uses=1]
> 	ret int %tmp.4.i
> }

Not bad :)

> Function inner isn't even emitted (no doubt a consequence of being
> static, as an inner method shouldn't have external visibility).  I can't
> complain :-)

Yup, it got emitted but then later deleted by the optimizer (exactly
because it was marked static/internal.  This is certainly the right way to
implement this in an LLVM-targetting compiler.

-Chris

-- 
http://llvm.org/
http://nondot.org/sabre/




More information about the llvm-dev mailing list