gcc size problem

B

ben

Hi everyone!

It is the first time I used google groups to post a message so I don't
know if my post is in the right place. Anyway, I have a question about
gcc-2.95.3.

I use it to compile a program written in C++. It compiles fine but the
problem I have is the size it takes.

The question I have is the following : how can I be sure that gcc
performs all optimization steps I put in my Makefile (-Os...). Indeed,
in gcc-3.2 man pages (I know it's not the same version but I have this
last at home!) I have seen that if a file was too big or too complex,
gcc refused to perform optimization steps. In order to see if some
steps was disabled, I would like to add "-Wdisabled-optimizations" in
my Makefile but unfortunately this flag doesn't exist with gcc-2.95.3.

Do you know if some options could give me any responses?

Here is the size of my big(?) file :
soapC.cpp : 2.7Mo (approximately 70000 lines!!!)

I send you a little part of the generated code :
<code>
SOAP_FMAC3 void SOAP_FMAC4 soap_serialize__QName(struct soap *soap,
char *const*a)
{
soap_reference(soap, *a, SOAP_TYPE__QName);
}

SOAP_FMAC3 void SOAP_FMAC4 soap_mark__QName(struct soap *soap, char
*const*a)
{
soap_reference(soap, *a, SOAP_TYPE__QName);
}

SOAP_FMAC3 int SOAP_FMAC4 soap_put__QName(struct soap *soap, char
*const*a, const char *tag, const char *type)
{
int i = soap_embed_element(soap, (void*)a, tag, SOAP_TYPE__QName);
soap_out__QName(soap, tag, i, a, type);
return soap_putindependent(soap);
}

SOAP_FMAC3 int SOAP_FMAC4 soap_out__QName(struct soap *soap, const
char *tag, int id, char *const*a, const char *type)
{
return soap_outstring(soap, tag, id, a, type, SOAP_TYPE__QName);
}

SOAP_FMAC3 char ** SOAP_FMAC4 soap_get__QName(struct soap *soap, char
**p, const char *tag, const char *type)
{
if ((p = soap_in__QName(soap, tag, p, type)))
soap_getindependent(soap);
return p;
}
</code>

you can see that functions are not very long. That implies there is a
lot of functions in my file. SOAP_FMAC3... are defined as macros.

Hope you will help me...

Thanks.

Ben
 
V

Victor Bazarov

ben said:
It is the first time I used google groups to post a message so I don't
know if my post is in the right place. Anyway, I have a question about
gcc-2.95.3.

You should also try gnu.g++.help.
I use it to compile a program written in C++. It compiles fine but the
problem I have is the size it takes.

The question I have is the following : how can I be sure that gcc
performs all optimization steps I put in my Makefile (-Os...).

The simplest way is to compare two compilation results, one made with
the optimisation steps, the other made without them.

Also, if performance is your goal, use a profiler with a test program
to understand how your code performs. It also helps to have some kind
of performance goals, otherwise what would you compare it with? Of
course, again, you could compare the optimised version with the one
without optimisations.
Indeed,
in gcc-3.2 man pages (I know it's not the same version but I have this
last at home!) I have seen that if a file was too big or too complex,
gcc refused to perform optimization steps. In order to see if some
steps was disabled, I would like to add "-Wdisabled-optimizations" in
my Makefile but unfortunately this flag doesn't exist with gcc-2.95.3.

Do you know if some options could give me any responses?

Compiler options are OT here, but do post to gnu.g++.help, they must
be able to help.
Here is the size of my big(?) file :
soapC.cpp : 2.7Mo (approximately 70000 lines!!!) [...]

Can't you split it into several files?

IMO 70000 lines of code is a bit on the unmanageable side. Yes, if
your code is _generated_ from some other information, you may not have
an option to split it, I realise that.

The code you posted is not enough to make any conclusions about the
possibility to optimise it. Functions that consist of a couple of
statements can never be optimised well, unless they are called in
your other code, then you might want to declare them 'inline'. Even
then the compiler doesn't have to inline them.

V
 
B

ben

Victor Bazarov said:
You should also try gnu.g++.help.

First, thanks for your ideas, I will try to post on this forum.


The simplest way is to compare two compilation results, one made with
the optimisation steps, the other made without them.

I still did that step. It returned a difference of 450ko between two
configurations :

first : options : -O3
second : options : -Os -finline-functions -fwritable-strings

anyway, I have some other tests to do in that way. Thanks again!
Also, if performance is your goal, use a profiler with a test program
to understand how your code performs. It also helps to have some kind
of performance goals, otherwise what would you compare it with? Of
course, again, you could compare the optimised version with the one
without optimisations.

Can you explain what do you think when you speak about a "profiler"? I
have lot of tests still written. All of them worked fine with my
program. The problems about performance come from the fact my program
is going to be included on an embedded system. It includes a binary
which have to be as tiny as possible.
The code you posted is not enough to make any conclusions about the
possibility to optimise it. Functions that consist of a couple of
statements can never be optimised well, unless they are called in
your other code, then you might want to declare them 'inline'. Even
then the compiler doesn't have to inline them.

For sure the code I post is not enough, but it's not easy to post
more. Indeed file is composed of functions based on the same model. As
I said before, I compiled my program with -finline-functions. Is it
enough, is it right?

Bye.
Ben.
 
L

Lionel B

ben said:
The question I have is the following : how can I be sure that gcc
performs all optimization steps I put in my Makefile (-Os...).
Indeed, in gcc-3.2 man pages (I know it's not the same version but
I have this last at home!) I have seen that if a file was too big
or too complex, gcc refused to perform optimization steps. In order
to see if some steps was disabled, I would like to add
"-Wdisabled-optimizations" in my Makefile but unfortunately this
flag doesn't exist with gcc-2.95.3.

This may be stating the obvious, but do you have the option to upgrade
your gcc (to 3.3 or 3.4 series)? Optimization is (supposed to be)
handled much better in post-2.95 versions.
 
B

Buster

ben said:
first : options : -O3
second : options : -Os -finline-functions -fwritable-strings

Try passing the "-O3" flag (to the compiler and linker) and the
"-s" flag (to the linker only).
 
P

puppet_sock

[email protected] (ben) wrote in message news: said:
Can you explain what do you think when you speak about a "profiler"?

There are various software evaluation tools that could be called
a profiler. The basic notion is, you want to be able to tell how
much time, and possibly how much memory or other resources, a code
is using doing various tasks. That way, you can concentrate on
making the parts that use the most time faster. Here's a simple
example:

5000 lines of code:
- lines 1 through 2000, code spends 5 percent of time in
- lines 2001 through 2100, code spends 80 percent of time in
- lines 2101 through 5000, code spends 15 percent of time in

If you could make the performance of lines 2001 through 2100
twice as good, you could save 40 percent of program time.
It may be a lot of work to do that, or it may require some
complicated, hard to maintain coding methods. But that's
clearly the place to concentrate efforts, as that's where
most of the time is taken.

If it were the same amount of work "per line" then the first
2000 lines of code are clearly not as important regarding
optimizing. And the last 2900 lines are more important than
the first 2000, but not nearly as important as 2001 through 2100.

So a profiler is very important for tuning code performance.
It tells you where you can get the most return on your effort.

Various profilers work in various ways. One common way is to
add "instrumentation" to your code. The tool will examine your
code and find branch points, function calls, etc., and make
a new version of the code with various logging capabilities added.
This modified code can then be compiled as usual, then run.
The extra lines of code the profiler added will then output the
tracking information.

Also, you may be able to request other resources be tracked.
So, if your project requires limits on memory, or other resource,
some profilers will let you track them. That way, you can get
a clear idea of where to work the hardest on optimizing.
Socks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,161
Latest member
GertrudeMa
Top