[llvm-dev] [help] How to speed up compilation?

Renato Golin via llvm-dev llvm-dev at lists.llvm.org
Tue Oct 18 07:51:27 PDT 2016


On 18 October 2016 at 15:31, Sunghyun Park via llvm-dev
<llvm-dev at lists.llvm.org> wrote:
> (Compiles by using 'make' command without 'make clean' previous compilation)
> Sometimes my machine is frozen because of the compilation and dead after
> couple of hours.

Hi Sung,

That's, unfortunately, expected. If you change a top-level header (one
that's included from too many other files), you can easily trigger a
huge chain of dependencies and re-compile the whole thing.

The freezing is due to extreme memory consumption, most likely from the linker.


> Any suggestion to speed up my compilation methodology?

A few hints:

1. Use "ninja" instead of "make", as it's *a lot* smarter in getting
rid of non-existing dependencies.
2. Use CCache. Even if make or ninja can't detect a dependency doesn't
exist, CCache can detect that the file is identical and the command
line too, so it just reuses the cached copy. Very fast rebuilds!
3. Compile using shared libraries, not static linking (CMake's
-DBUILD_SHARED_LIBS=True), as this will reduce re-linking all the
objects into all the executables. This will reduce the number of steps
and freezing.
4. Use a faster linker like "gold" or LLD (if it works for your
target), as they're not just faster but use a lot less memory. This
will help with freezing and speed.
5. If you have low memory, consider using CMake's
-DLLVM_PARALLEL_LINK_JOBS=N, with N = min(amount of RAM in GB, CPU
cores). Some link jobs can take up to 1GB. This will get rid of
freezing, but will make it a bit slower. Adjust the value until it's
fast enough and doesn't freeze.

Hope that helps.

cheers,
--renato


More information about the llvm-dev mailing list