how to build a faster gcc working on a specific project
Thu Jun 28 12:31:00 GMT 2018
问 题 wrote on 06/27/2018 05:33 AM:
> I am working on a project with millions of LOC, which needs really long time to compile. I know gcc has a technique called profile guided optimization(PGO) which makes the compiled program run faster by using some training data. So I am wondering if I can use my project to train gcc while compiling gcc itself. I know gcc provides a make option 'make profiledbootstrap' to train the compiler, but how can I use my own project to train gcc?
> I do know some other techniques like distcc and ccache to speed up compiling, but here I want to focus on gcc.
> ���� Outlook<http://aka.ms/weboutlook>
Let me summarize: you have 3 problem areas you want to optimize:
1) build time of the compiler,
2) build time of your application project,
3) run time of your application project.
Not sure if you can use your own project as training data while building the
compiler, but I would suggest the following:
1) Build the new compiler
- by disabling debugging info (-g0 -DNDEBUG) in all *FLAGS, ie.
- with -pipe and additional options for optimizations, like
(where applicable for your CPU & OS; if your OS is Linux see cat
/proc/cpuinfo for supported CPU features)
- with --disable-bootstrap as then the build goes much faster (12 minutes
vs. 111 minutes here)
- use make -j, or in a script use twice the number of CPU cores for # of
parallel make jobs, ie.:
nThr=$(getconf _NPROCESSORS_ONLN) ; nThr=$(( $nThr * 2 )) ; make -j $nThr
2) Repeat step 1 by now building the new compiler by itself :-) instead of by
the (old) system compiler that was used in step 1, by setting the following
vars pointing to the new compiler:
../gcc_trunk/configure -v \
That way, after generating a fast compiler you can then optimize
your own project. Possibly you can use most of the above options,
and as you mentioned also PGO (I've no experience yet with that,
but it sounds very promising), and also using the precompiled headers
feature (but this requires a careful reorganisation of the #include statements
in the source files; best is to put them all into an own pch.hpp file and
include that as the very first statement in the source file ...).
More information about the Gcc-help