Menu

#414 Remove unused static objects at compile time (inline!)

None
open
nobody
None
5
2023-08-10
2014-09-24
No

If something is static, we can remove it at compile time if unused. This is an important feature for inline functions: static inline functions are meant to be a better replacement for many macros. But sdcc currently does generate function definitions for them even if all uses are inlined. This makes them very inefficient in sdcc.

Philipp

P.S.: This might also make it easier to implement __func__, since it could be just added early in compilation and would then be removed if unused.

P.P.S.: This feature will also be useful for static const variables: When we can replace all uses by immediates, we would not need storage space for them (making them as effient as macros).

Related

Bugs: #2962

Discussion

  • Maarten Brock

    Maarten Brock - 2014-09-25

    The way SDCC currently parses the source is to generate code immediately in the first and only pass. This means that the static (inline) function is generated while parsing the definition. At that point it is still unknown if the function will be unused at the end of the source file. If we keep this behavior the only option is to suppress the actual output to the .asm file at the end.

    Another consequence of this behavior is that we cannot generate the external linkage variant of an inline function if the extern inline declaration appears after the inline definition. This is not completely C99 compliant.

    E.g.

    extern int foo(int a);              // no "inline definition", gives external linkage
    inline int foo(int a) { return a; } // generates the external linkage implementation
    inline int bar(int a) { return a; } // still an "inline definition" during parsing
    extern int bar(int a);              // oops, it turns out to have external linkage
    

    Maybe we can detect that bar is not yet generated at the last line and start generating it at that point still.

     
  • Philipp Klaus Krause

    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -2,6 +2,6 @@
    
     Philipp
    
    -P.S.: This might also make it easier to implement __func__, since it could be just added early in compilation and would then be removed if unused.
    +P.S.: This might also make it easier to implement \_\_func\_\_, since it could be just added early in compilation and would then be removed if unused.
    
     P.P.S.: This feature will also be useful for static const variables: When we can replace all uses by immediates, we would not need storage space for them (making them as effient as macros).
    
    • Group: -->
     
  • Philipp Klaus Krause

    __func__ has since been implemented, so that part of the feature request is no longer relevant.

    Philipp

     

Log in to post a comment.

MongoDB Logo MongoDB