LLVM footprint

What is the expected footprint of a tool using the LLVM JIT?

I have created a simple project that uses the LLVM C++ API to JIT calls to
XPCOM method signature... it works well, but the component DLL is very large
(Linux x86-74, 5.8MB optimized and stripped). Is this normal? Am I linking
to "too much" or not using the correct link flags?

Note that I'm not using the LLVM build system, I'm using the Mozilla build
system and manually pulling in the libraries I needed to resolve symbols...

The makefile is here:
http://hg.mozilla.org/users/bsmedberg_mozilla.com/llvm-test/?file/e021a9901b98/Makefile.in

EXTRA_DSO_LDOPTS = \
  $(XPCOM_GLUE_LDOPTS) \
  $(NSPR_LIBS) \
  -L$(LLVM_PREFIX)/lib \
  $(LLVM_PREFIX)/lib/LLVMJIT.o \
  $(LLVM_PREFIX)/lib/LLVMExecutionEngine.o \
  $(LLVM_PREFIX)/lib/LLVMInterpreter.o \
  $(LLVM_PREFIX)/lib/LLVMX86.o \
  -lLLVMTarget \
  -lLLVMCodeGen \
  -lLLVMScalarOpts \
  -lLLVMAnalysis \
  -lLLVMTransformUtils \
  -lLLVMSelectionDAG \
  -lLLVMAnalysis \
  -lLLVMCore \
  -lLLVMSupport \
  -lLLVMSystem \
  $(NULL)

and the C++ code is here:
http://hg.mozilla.org/users/bsmedberg_mozilla.com/llvm-test/?file/e021a9901b98/LLVMTest.cpp

Note that because this is a sharedlib I had to configure LLVM with
- --enable-pic --enable-optimize, but I used no other configure options...
should I have? Are there features that can be disabled to reduce footprint?

- --BDS

- --

Benjamin Smedberg
Platform Guru
Mozilla Corporation
benjamin@smedbergs.us
http://benjamin.smedbergs.us/

What is the expected footprint of a tool using the LLVM JIT?

Right now it's ~1.5 to 2M for one platform, at least on darwin.

I have created a simple project that uses the LLVM C++ API to JIT calls to XPCOM method signature... it works well, but the component DLL is very large (Linux x86-74, 5.8MB optimized and stripped). Is this normal? Am I linking to "too much" or not using the correct link flags?

That is large. I'd suggest using the output of the llvm-config tool to pass the right options to the linker:

$ llvm-config --libs --ldflags jit native
-L/Volumes/ProjectsDisk/cvs/llvm/Debug/lib -lpthread -lltdl -lm
/Volumes/ProjectsDisk/cvs/llvm/Debug/lib/LLVMPowerPC.o -lLLVMSelectionDAG -lLLVMCodeGen -lLLVMScalarOpts -lLLVMTransformUtils -lLLVMipa -lLLVMAnalysis /Volumes/ProjectsDisk/cvs/llvm/Debug/lib/LLVMJIT.o /Volumes/ProjectsDisk/cvs/llvm/Debug/lib/LLVMExecutionEngine.o -lLLVMTarget -lLLVMCore -lLLVMSupport -lLLVMSystem

(this is on a ppc/darwin system).

Note that I'm not using the LLVM build system, I'm using the Mozilla build
system and manually pulling in the libraries I needed to resolve symbols...

That should be fine.

Note that because this is a sharedlib I had to configure LLVM with
- --enable-pic --enable-optimize, but I used no other configure options...
should I have? Are there features that can be disabled to reduce footprint?

LLVM uses a lot of strings in assertion messages. building with 'ENABLE_OPTIMIZED=1 DISABLE_ASSERTIONS=1' will give a significantly smaller build than just an optimized build. Also, there are lots of options for strip that you can play with.

Finally, there is still a lot that can be done to reduce code size. For example, building a JIT links in the .s file printers in, and they have non-trivial size (big string tables etc). It would be great to refactor the code to avoid things like this. I wouldn't be surprised if we could shrink the size of a JIT down by another 30% or so.

-Chris

Chris Lattner wrote:

Finally, there is still a lot that can be done to reduce code size. For
example, building a JIT links in the .s file printers in, and they have
non-trivial size (big string tables etc). It would be great to refactor
the code to avoid things like this. I wouldn't be surprised if we could
shrink the size of a JIT down by another 30% or so.

These are great tips, thanks... is it possible to avoid linking the
interpreter as well? That is, I'm pretty sure I always want to JIT code and
never interpret it, but it looks like I currently have to pay a codesize
penalty for the interpreter anyway.

Right now this is personal experimentation, but if Mozilla decides to use te
LLVM JIT for some of our Mozilla2 projects we'll definitely be contributing
to reduce the footprint as much as possible, as well as the MSVC thiscall
support I mentioned before.

- --BDS

- --

Benjamin Smedberg
Platform Guru
Mozilla Corporation
benjamin@smedbergs.us
http://benjamin.smedbergs.us/

These are great tips, thanks... is it possible to avoid linking the
interpreter as well? That is, I'm pretty sure I always want to JIT code and
never interpret it, but it looks like I currently have to pay a codesize
penalty for the interpreter anyway.

Yep, specifying 'jit' as a component doesn't pull in the interpreter, you need to specify "native jit interpreter" to llvm-config to get both.

Right now this is personal experimentation, but if Mozilla decides to use te
LLVM JIT for some of our Mozilla2 projects we'll definitely be contributing
to reduce the footprint as much as possible, as well as the MSVC thiscall
support I mentioned before.

Excellent!

-Chris