1

Is there anyway to use -fwhole-program optimization with gcc4ti? I tried concatenating all of my source files together and using it, but I was told there was an "undefined reference to __main". I then tried adding the externally_visible attribute to my main function, but I still got the same error.

To see if it would have any benefit, I manually made all of the functions in the concatenated source file static, and got a binary that was 11% smaller.

2

To use -fwhole-program --combine with GCC4TI, or TIGCC, you need to call the appropriate programs one by one, and not forget to add a call to `patcher` in-between. If you're using TPRs, `tprbuilder -v` can show you the sequence of commands, which you need to adapt.
A while ago, I have done that on TI-Chess, and -fwhole-program --combine also produced a binary that was, IIRC, between 10% and 15% smaller. I don't remember ATM what I did exactly to overcome the "undefined reference to __main", but I know it was only two or three small changes, such as a one-liner change to one of the headers and/or renaming _main to __main.

There's one significant problem, though: reliability (rather, lack thereof). -fwhole-program --combine are buggy, i.e. you can see more Internal Compiler Errors than the usual with those modes, and invalid generated code happens once in a while.
Since it's unreliable, hardly anybody tries using Inter-Procedural Optimization with GCC, so it remains somewhat buggy... and therefore, hardly anybody uses it.

To sum up: you can do it, but beware.
If you're applying it to programs that have very few users, and you are willing to put up with occasional incorrect behaviour and crashes, go ahead.
If you're planning to distribute your programs on ticalc, be prepared to spend more time testing before releasing, and deal with hate mail, even if you explicitly write in the README (as pretty much everybody else is doing, anyway) that "as any ASM or BASIC program, this can crash your calculator"), because people don't read READMEs wink
avatar
Membre de la TI-Chess Team.
Co-mainteneur de GCC4TI (documentation en ligne de GCC4TI), TIEmu et TILP.
Co-admin de TI-Planet.

3

Lionel Debroux (./2) :
There's one significant problem, though: reliability (rather, lack thereof). -fwhole-program --combine are buggy, i.e. you can see more Internal Compiler Errors than the usual with those modes, and invalid generated code happens once in a while.


Is this also true if I only use -fwhole-program and not --combine? I know I have read about people having trouble with --combine, but I thought -fwhole-program just made all functions static (and if optimizing static functions is buggy, then I'm in big trouble, anyway). My program has no name collisions, so I can easily just cat everything together before compiling.

4

Is this also true if I only use -fwhole-program and not --combine?

Not that I know of, the buggy switch is --combine.
I put -fwhole-program and --combine together because that's what yields the best optimization, but -fwhole-program alone is a safe(r) choice smile
avatar
Membre de la TI-Chess Team.
Co-mainteneur de GCC4TI (documentation en ligne de GCC4TI), TIEmu et TILP.
Co-admin de TI-Planet.

5

The problem with -fwhole-program without --combine is that it only works if you follow some absymal coding practices (such as #include of .c files, code in header files or the "one big .c file" antipattern). And if you're already willing to butcher your code that way, you may just as well explicitly mark all your functions static.
avatar
Mes news pour calculatrices TI: Ti-Gen
Mes projets PC pour calculatrices TI: TIGCC, CalcForge (CalcForgeLP, Emu-TIGCC)
Mes chans IRC: #tigcc et #inspired sur irc.freequest.net (UTF-8)

Liberté, Égalité, Fraternité

6

Kevin Kofler (./5) :
The problem with -fwhole-program without --combine is that it only works if you follow some absymal coding practices (such as #include of .c files, code in header files or the "one big .c file" antipattern). And if you're already willing to butcher your code that way, you may just as well explicitly mark all your functions static.


Well, I do none of those. What I can do, however, is cat all my .c files together and compile the result. This puts the ugliness into the build step, which I'm not too upset about. Especially if it results in a smaller bin size, better performance, and not having to worry about --combine making mistakes.

7

Catting all your .c files together is "one big .c file". Making it in the compilation step is all the more ugly (e.g. some #include or #define in one .c file will have global effects).
avatar
Mes news pour calculatrices TI: Ti-Gen
Mes projets PC pour calculatrices TI: TIGCC, CalcForge (CalcForgeLP, Emu-TIGCC)
Mes chans IRC: #tigcc et #inspired sur irc.freequest.net (UTF-8)

Liberté, Égalité, Fraternité