performancellvmlibtomcrypt

LLVM Slower when pass activated


I use LLVM to compile libtomcrypt, it's very fast (a few seconds) but when I use a blank pass (just a module pass that does nothing), it's very slow (several minute).

Someone know why?

I use Fedora 19.

The LLVM I use is LLVM 3.4 in release build.

Thanks


Solution

  • I can think of two ways in which an empty module pass can negatively impact compile-time:

    1. Pass Ordering

    Module passes force a sort of synchronization point on a pass manager. So for example, let's say you have the following:

    1. Function pass A
    2. Function pass B

    On a module with two functions f() and g(). The pass manager can (and will) first run A and B on f(), and only then A and B on g(). This is useful, among other reasons, for memory locality. However, if you add a module pass:

    1. Function pass A
    2. Module pass
    3. Function pass B

    Then you force the pass manager to first run A on both functions, then the module pass, and then B on both functions.

    2. Invalidating Previous Results

    From the documentation:

    If a pass does not implement the getAnalysisUsage method, it defaults to not having any prerequisite passes, and invalidating all other passes.

    So if your runOnModule method returns true, the pass manager considers every previous analysis pass as invalid, forcing rerunning them if they are needed later on.

    For a more complete picture, I recommend reading the documentation for a full explanation on what a pass manager does.