From: Scott D. Anderson
Subject: inlining functions
Date: 
Message-ID: <ANDERSON.95May6170703@earhart.cs.umass.edu>
Inlining functions works a little differently in "modern" Common Lisps than it
works on my Lisp Machine, but I think I've got the hang of it, except for one
question: how can I limit the pervasiveness of inlining?

Imagine that I have a function FOO that will be called in N places.  Because of
FOO's code size, I don't want to inline it in all N places, I just want to
inline it in K places.  Because N>>K, I don't want to put a (declare (notinline
foo)) in all of the N-K places.  I'd rather just put the (declare (inline foo))
in the K places where I want that to happen.  However, in order for inlining to
work at all, I have to (declaim (inline foo)), which means that my inline
declarations are redundant and my notinline declarations are necessary.  Am I
making any sense?

To quote from CLtL2, page 229: "... the inline declaration specifier serves two
distinct purposes: it indicates not only that affected calls to the specified
functions should be expanded in-line, but also that affected definitions of the
specified functions must be recorded for possible use in performing such
expansions."  I want the latter purpose, but not the former.

Example:

(declaim (inline foo))
(defun foo (x) ... something moderately hairy ...)

(defun bar ()
  (declare (inline foo))  ; this is redundant but I'd like it required
  (foo 3))

(defun baz ()
  (declare (notinline foo))  ; this is required but I'd like it redundant
  (foo 4))

Is there some portable mechanism for having the notation I want?  What if I
declaim the function notinline right after the definition?  At that point, the
compiler will (presumably) have saved the definition and now won't inline it
anywhere.  But will the compiler throw away the definition?

I'd appreciate any help on this.  Thanks.

Scott D. Anderson
········@cs.umass.edu
From: Barry Margolin
Subject: Re: inlining functions
Date: 
Message-ID: <3oh7qf$e5u@tools.near.net>
In article <·····················@earhart.cs.umass.edu> ········@cs.umass.edu writes:
]Imagine that I have a function FOO that will be called in N places.  Because of
]FOO's code size, I don't want to inline it in all N places, I just want to
]inline it in K places.  Because N>>K, I don't want to put a (declare (notinline
]foo)) in all of the N-K places.  I'd rather just put the (declare (inline foo))
]in the K places where I want that to happen.  However, in order for inlining to
]work at all, I have to (declaim (inline foo)), which means that my inline
]declarations are redundant and my notinline declarations are necessary.  Am I
]making any sense?

Pur a (declaim (inline foo)) right before the function definition, and
(declaim (notinline foo)) right after it.  The first one should cause the
compiler to remember the expansion, while the second one should keep it
from expanding except where you put an explicit INLINE declaration.

-- 
Barry Margolin
BBN Planet Corporation, Cambridge, MA
······@bbnplanet.com