Menu

#86 SDCC 3.4.0 not optimize code size STM8

None
closed
None
1
2015-08-11
2014-09-06
No

SDCC 3.4.0 does not optimize the unused functions, variables and constants. As a result, the hex file size is 18,8kb, and the IAR generates a hex file size 2,5kb.

-------------- Build: Release in test (compiler: Small Device C Compiler)---------------

sdcc.exe -mstm8 --opt-code-size -I"C:\Program Files\SDCC\include" -c main.c -o obj\Release\main.rel
sdcc.exe -L"C:\Program Files\SDCC\lib" -o bin\Release\test.ihx -mstm8 -DSTM8S003 --opt-code-size -lstm8 --out-fmt-ihx obj\Release\main.rel
Output file is bin\Release\test.ihx with size 18.82 KB
Running project post-build steps
cmd /c "packihx <bin\\Release\\test.ihx>bin\Release\test.hex"
packihx: read 253 lines, wrote 503: OK.

This main.c - used only function LCD_init ()

| #define SYSCLK 1000000UL
|
| #include <stm8 STM8L151K4.h="">
| #include <stm8 STM8_SDCC.h="">
| #include "STM8_KS0108_CFG.h"
| #include "STM8_KS0108.h"
|
|
| void main(void)
| {
| LCD_init();
| while(1);
| }

ASM file size is 115,217kb

Why don't work optimization with STM8 CPU?

Thanks in advance!

P.S. I tried all possible COMMAND LINE OPTIONS and SDCC version with STM8 support. Flash size of my CPU is only 16kb

1 Attachments

Discussion

  • Pavlo Kharchenko

    When i compile with --noinvariant --nolospre i see next:
    -------------- Build: Release in test (compiler: Small Device C Compiler)---------------

    sdcc.exe -mstm8 -DSTM8S003 --opt-code-size --noinvariant --nolospre -I"C:\Program Files\SDCC\include" -c main.c -o obj\Release\main.rel
    Warning: Non-connected liverange found and extended to connected component of the CFG:iTemp1. Please contact sdcc authors with source code to reproduce.
    Warning: Non-connected liverange found and extended to connected component of the CFG:iTemp7. Please contact sdcc authors with source code to reproduce.
    Warning: Non-connected liverange found and extended to connected component of the CFG:iTemp6. Please contact sdcc authors with source code to reproduce.
    Warning: Non-connected liverange found and extended to connected component of the CFG:iTemp16. Please contact sdcc authors with source code to reproduce.
    Warning: Non-connected liverange found and extended to connected component of the CFG:iTemp16. Please contact sdcc authors with source code to reproduce.
    Warning: Non-connected liverange found and extended to connected component of the CFG:iTemp16. Please contact sdcc authors with source code to reproduce.
    Warning: Non-connected liverange found and extended to connected component of the CFG:iTemp16. Please contact sdcc authors with source code to reproduce.
    Warning: Non-connected liverange found and extended to connected component of the CFG:iTemp2. Please contact sdcc authors with source code to reproduce.
    Warning: Non-connected liverange found and extended to connected component of the CFG:iTemp2. Please contact sdcc authors with source code to reproduce.
    Warning: Non-connected liverange found and extended to connected component of the CFG:iTemp16. Please contact sdcc authors with source code to reproduce.
    Warning: Non-connected liverange found and extended to connected component of the CFG:iTemp16. Please contact sdcc authors with source code to reproduce.
    Warning: Non-connected liverange found and extended to connected component of the CFG:iTemp16. Please contact sdcc authors with source code to reproduce.
    Warning: Non-connected liverange found and extended to connected component of the CFG:iTemp16. Please contact sdcc authors with source code to reproduce.
    sdcc.exe -L"C:\Program Files\SDCC\lib" -o bin\Release\test.ihx -mstm8 -DSTM8S003 --opt-code-size --noinvariant --nolospre -lstm8 --out-fmt-ihx obj\Release\main.rel
    Output file is bin\Release\test.ihx with size 18.72 KB
    Running project post-build steps
    cmd /c "packihx <bin\\Release\\test.ihx>bin\Release\test.hex"
    packihx: read 252 lines, wrote 500: OK.
    Process terminated with status 0 (0 minute(s), 4 second(s))
    0 error(s), 0 warning(s) (0 minute(s), 4 second(s))

     
  • Ben Shi

    Ben Shi - 2014-09-08

    I thought you have encountered two different problems:

    1. The internal non-fatal errors by --noinvariant --nolospre
    2. You code size needs to be reduced

    For the first problem, I have no idea. For the second, the lack of removal of unused functions & variables is not specific to stm8, but exists on other ports.

    I tried the attached a.c with stm8, mcs51 and z80. The unused function sqs() remains on all of them.

     
  • Philipp Klaus Krause

    There are 2 aspects to removinf unused fuctios:

    1) static functions. The compiler could kow if these are called, and could remove them. Currently not implemented.
    2) Other functions. The compiler cannot know if they are unused, and thus cannot remove them. The linker can know if they are unused, and can remove them. For that to happen, the unused functions need to be in a library (preferably one function per module, as each module will be pulled in as soon as there is a used function in the module).

    Philipp

     
  • Ben Shi

    Ben Shi - 2014-09-08

    Do you mean that put each function into an isolated .c file, and then build the lib ? Is it easy for sdld to do the unused functions removal without such a special process?

     
    • Philipp Klaus Krause

      Yes. One file per function, then build a lib.
      Otherwise sdld can't be sure what can be removed. Consider e.g. a module containing two functions, the first called from the program. sdld cannot know if the second can be safely removed, since the first function could reference the second one in ways not visible to sdld (such as relative jumps).

      Philipp

       

      Last edit: Philipp Klaus Krause 2014-09-08
  • Ben Shi

    Ben Shi - 2014-09-08

    I tried gcc with the attached a.c (-O2 level opimization), that the unused function ab1234() was not removed else. So there might be other reasons that code size of IAR is quite smaller than SDCC ? (I have no available IAR to test)

     
    • dukelec

      dukelec - 2015-03-23

      Unused functions eliminated by GCC with `LDOPT := ,--gc-sections' option(stm32 project), full Makefile attached FYI.

       
  • Maarten Brock

    Maarten Brock - 2014-09-08

    Have you tried with LTO (Link Time Optimization) in gcc/ld? Nevertheless, this is no easy feature.

     
  • Adrien Prost-Boucle

    I confirm on pic14 unused static functions are not removed.
    For a compiler, this should be be easy feature. I really miss this: adding #if 0 everywhere to test implementations, and updating them coherently, is a pain.

    Compilation just fails because device size is exceeded. So it's not just futile feature.
    Suggest creating a separate ticket so this issue can be seen under appropriate title.

     
  • Philipp Klaus Krause

    Opened RFE #452 for this.

    Philipp

     
  • Philipp Klaus Krause

    • status: open --> closed
    • assigned_to: Philipp Klaus Krause
    • Group: -->
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.