CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

PCH optimization of unused functions

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Laurent Chouinard



Joined: 12 Sep 2003
Posts: 43

View user's profile Send private message

PCH optimization of unused functions
PostPosted: Mon Oct 15, 2007 12:16 pm     Reply with quote

I am currently writing code to add to my programs the ability to receive a new firmware through TCP/IP.

I made various elegant hacks to achieve this, such as faking boot code, freezing rom areas to replace with my own boot loaders, and such and such.

All is good and dandy, except for ROM optimization. Since the boot loader code cannot possibly be called by the program itself, it lies somewhere in the ROM but it never "used". This is good, I want that. But by playing with that, I came to the conclusion that the compiler will actually compile any function found, regardless of use.

This is good for my bootloader, since I want it to be compiled into ROM even though the program does not call it, but realizing this, I wonder about the rest of my code. Since this project is vast and I've been working on it for a year, how many functions do I have lying around, not used because I changed my mind along the way, and that are still compiled into the ROM and using valuable space?

Is there a way to find a list of "Unused functions"? The compiler already warns me about unused RAM variables, so I always read those and then proceed to, if applicable, remove them to free up space. What about functions?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Oct 15, 2007 12:31 pm     Reply with quote

Quote:

I came to the conclusion that the compiler will actually compile
any function found, regardless of use.

That's not true.

Compile the following test program. I used vs. 4.058, but any version
will work for this test.
Code:

#include <18F452.h>
#fuses XT,NOWDT,NOPROTECT,BROWNOUT,PUT,NOLVP
#use delay(clock=4000000) 

int8 test(void)
{
char c;

c = 0x55;

return(c);
}

//==========================
void main()
{

while(1);     


Here's the .LST file output. The test() function is not compiled.
Code:

0000:  GOTO   0004
... #include <18F452.h> 
... // Standard Header file for the PIC18F452 device //
... #device PIC18F452
... #list
... 
... #fuses XT,NOWDT,NOPROTECT,BROWNOUT,PUT,NOLVP 
... #use delay(clock=4000000)   
... 
... int8 test(void)
... {
... char c;
... 
... c = 0x55;
... 
... return(c);
... }
... 
... 
... //==================================== 
... void main() 
... { 
0004:  CLRF   FF8
0006:  BCF    FD0.7
0008:  CLRF   FEA
000A:  CLRF   FE9
000C:  BSF    FC1.0
000E:  BSF    FC1.1
0010:  BSF    FC1.2
0012:  BCF    FC1.3
... 
... 
... 
... while(1);       
0014:  BRA    0014
... }     
Laurent Chouinard



Joined: 12 Sep 2003
Posts: 43

View user's profile Send private message

PostPosted: Mon Oct 15, 2007 12:52 pm     Reply with quote

I understand your test shows exactly what should be happening, but why would a whole include file loaded with 5 functions that are never referenced to anywhere would still be compiled?

One thing to mention, I specify ROM locations for these functions such as:

Code:
#org 0x1e000, 0x1fffe default
void LotsOfStuffHere(void) {
...
}

#org default


Does that force the compiler to compile the code regardless of calls? Because I am absolutely positive that the code is not called and it is compiled because the ROM size is considerable larger, the HEX file shows my functions located at the expected addresses, and the LST file shows all the functions compiled nicely in the rom range specified as well.
Laurent Chouinard



Joined: 12 Sep 2003
Posts: 43

View user's profile Send private message

PostPosted: Mon Oct 15, 2007 12:56 pm     Reply with quote

Update:

Yes. That is exactly why. I just tried it with a blank test program and, indeed, if rom locations are specified, code is compiled. Otherwise, if function is not called, it's not compiled.

So thank you, my question is answered.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group