[LLVMdev] Why are LLVM libraries enormous?
nicolas.capens at gmail.com
Thu Jul 29 05:05:19 PDT 2010
I've had some success analyzing the binary size by making Visual C++
generate a .map file. This basically tells you at what binary offset each
function is located in the exe or dll. By subtracting the offset of the next
function you get the actual binary size of each function (including
alignment). Then you can aggregate these by class or by object file and sort
by size to get a real idea of where the big code is.
If I recall correctly, I got the JIT down to about 2 MB using information
collected from the .map file. This still included some optimization passes.
Unfortunately a lot of features are fairly tightly interwoven. If you don't
need support for debugging, exceptions, garbage collection, intrinsics,
arbitrary precision integers and/or vectors, I bet you could get it way
smaller. But it would take considerable effort to pry loose. Also, some
passes can do a lot of things which you might not be interested in. For
example instcomb is huge but you probably only need a handful of the
possible combinations to make your JIT code a lot faster. Most of the
optimizations can be performed statically in the high-level language anyway
(e.g. replacing a division by 2 by a shift right).
So I'm quite convinced that LLVM can be made smaller than 1 MB, but it will
take some custom work. With a good test suite you can systematically cut
things out and ensure everything keeps working. Unfortunately it will become
infeasible to merge patches from main development into your local tree, so
you won't benefit from any advances or bug fixes there. But if you're happy
with LLVM 2.7's functionality, now and later, then this is a feasible option
if you have a couple months to do the custom work.
From: llvmdev-bounces at cs.uiuc.edu [mailto:llvmdev-bounces at cs.uiuc.edu] On
Behalf Of David Piepgrass
Sent: Wednesday, July 28, 2010 18:01
To: Óscar Fuentes; llvmdev at cs.uiuc.edu
Subject: Re: [LLVMdev] Why are LLVM libraries enormous?
> Why do you care about the size of library files?
I assumed dynamic libraries and static libraries were similar in size, but I
just checked some of my own static libraries and they are indeed much larger
than the executables they compile to. Sorry, it just never occurred to me
that they would be much different.
> > Anyway, in the same example I mentioned that the size of HowToUseJIT
> > (an executable) is very large (15.4 MB debug, 3.4 MB release); as is
> > small example, I'd expect any real-world executable to be larger.
> Of course a real-world project would be larger, but not on a "linear"
> proportion compared to HowToUseJIT. That example application pulls a
> chunk from the LLVM libraries. That is what makes it large, not the
> in howtousejit.cpp. My compiler, for instance, is anything but a toy
> application and is 5.7 MB.
> > and whether it is possible to construct an example less than 1 MB.
> A LLVM JIT compiler for x86 under 1 MB? I doubt it is possible without
> a major rewriting of LLVM.
Even with no optimizations? Drat. That means I can't use it.
It's too bad nobody's written a utility to profile the sizes of C++
classes/functions... that would sure help an investigation like this. A
question at StackOverflow didn't turn up any such utility:
LLVM Developers mailing list
LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu
More information about the llvm-dev