Re: GCC 3.4 and broken inlining.

From: Alexandre Oliva (aoliva_at_redhat.com)
Date: 07/10/04

  • Next message: Trond Myklebust: "Re: umount() and NFS races in 2.4.26"
    To: ncunningham@linuxmail.org
    Date:	10 Jul 2004 18:33:40 -0300
    
    

    On Jul 9, 2004, Nigel Cunningham <ncunningham@linuxmail.org> wrote:

    > I do think that functions being declared inline when they can't be
    > inlined is wrong

    The problem is not when they can or cannot be inlined. The inline
    keyword has nothing to do with that. It's a hint to the compiler,
    that means that inlining the function is likely to be profitable.
    But, like the `register' keyword, it's just a hint. And, unlike the
    `register' keyword, it doesn't make certain operations on objects
    marked with it ill-formed (e.g., you can't take the address of an
    register variable, but you can take the address of an inline
    function).

    The issue with inlining that makes it important for the compiler to
    have something to say on the decision is that several aspects of the
    profit from expanding the function inline is often machine-dependent.
    It depends on the ABI (calling conventions), on how slow call
    instructions are, on how important instruction cache hits are, etc.
    Sure enough, GCC doesn't take all of this into account, so its
    heuristics sometimes get it wrong. But it's getting better.

    Meanwhile, you should probably distinguish between must-inline,
    should-inline, may-inline, should-not-inline and must-not-inline
    functions. Attribute always_inline covers the must-inline case; the
    inline keyword covers the may-inline'case. The absence of the inline
    keyword implies `should-not-inline', and attribute noinline covers
    must-not-inline. should-inline can't be expressed today, and if
    may-inline doesn't get the desired effect, you may feel tempted to
    abuse always_inline, but I suggest you to do so using a different
    macro, such that, if GCC ever introduces a new attribute that's a
    stronger hint to inlining that doesn't error out if it can't be done,
    you can easily switch to it.

    -- 
    Alexandre Oliva             http://www.ic.unicamp.br/~oliva/
    Red Hat Compiler Engineer   aoliva@{redhat.com, gcc.gnu.org}
    Free Software Evangelist  oliva@{lsd.ic.unicamp.br, gnu.org}
    -
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.kernel.org
    More majordomo info at  http://vger.kernel.org/majordomo-info.html
    Please read the FAQ at  http://www.tux.org/lkml/
    

  • Next message: Trond Myklebust: "Re: umount() and NFS races in 2.4.26"

    Relevant Pages

    • Re: Experiences using "register"
      ... Because it adversely affects code size is one thing I can think of ... inlining may even decrease the code size. ... The main purpose of inline is to take away the function call and return ... Again the standard inline keyword is like register: ...
      (comp.lang.c)
    • Re: Best charting package
      ... You're right about the property inlining, but it is present only in the ... ..NET framework 2.0 and to a certain level - for example having a simple ... Inline functions / properties are badly missing. ... MSVC would ignore the register ...
      (microsoft.public.dotnet.framework.windowsforms.controls)
    • Re: Experiences using "register"
      ... Naturally there are exceptions to these rules. ... An exception example for "register" is when we want a specific portion ... "register" keyword is used 'properly'. ... An exception example for "inline" is when we want a large function with ...
      (comp.lang.c)
    • Re: inline
      ... normal inline function definition - Stand-alone object code is always ... Where will be the practical use/application of these ('static inline ... Most compilers are smart about inlining and only use inline as a hint, ... register allocators work better on smaller functions with low register ...
      (comp.arch.embedded)
    • Re: about inline functions
      ... such as taking a pointer to the function, especially if that pointer is passed ... which 'inline' is a good idea, it's often the case that simply declaring it ... static' without the 'inline' keyword is sufficient to allow the compiler to ... neither keyword guarantees) is the removal of the external definition, ...
      (comp.lang.c)