Bugzilla – Bug 177
[JIT] Functions pointed to by global variables should be lazily compiled!
Last modified: 2003-12-12 01:18:21
You need to log in before you can comment on or make changes to this bug.
The LLVM JIT currently compiles a functions pointed to by global variables immediately, though they probably won't ever be referenced, especially in C++ programs. Here's a simple C program that demonstrates what is going on. Multiply it a thousand fold for a medium-sized C++ program that has vtables pointing to LOTS of functions. --- void bar() {} void baz() {} void (*P1)(void) = bar; // P1 is never used, should not codegen bar void (*P2)(void) = baz; void qux() { P2(); } int main(int argc, char**argv) { if (argc > 1) qux(); } --- Use like so: $ llvmgcc test.c -c -Wa,-disable-inlining $ lli -debug-only=jit test.o <optional arg> Currently I get this on the testcase: $ lli -debug-only=jit test.o Global 'P1' -> 0x84e3808 Global 'P2' -> 0x84e3818 Finished CodeGen of [0x4018e000] Function: bar: 7 bytes of text Finished CodeGen of [0x4018e008] Function: baz: 7 bytes of text Finished CodeGen of [0x4018e010] Function: main: 57 bytes of text WARNING: Cannot resolve fn '__main' using a dummy noop function instead! $ lli -debug-only=jit test.o x Global 'P1' -> 0x84e3808 Global 'P2' -> 0x84e3818 Finished CodeGen of [0x4018e000] Function: bar: 7 bytes of text Finished CodeGen of [0x4018e008] Function: baz: 7 bytes of text Finished CodeGen of [0x4018e010] Function: main: 57 bytes of text WARNING: Cannot resolve fn '__main' using a dummy noop function instead! Finished CodeGen of [0x4018e04c] Function: qux: 16 bytes of text
These patches implement this (for X86. Sparc needs a small patch to implement the new hook): http://mail.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20031208/010113.html http://mail.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20031208/010114.html http://mail.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20031208/010115.html Fixing this speeds up "ll-tblgen --help" from 4.55s to 2.36s, and "ll-opt --help" goes from 18.85s to 7.30s. We now "only" compile 111413 bytes of machine code, instead of 284680 bytes for ll-tblgen. Fixing Bug 135 would also provide another HUGE speedup, because we are initializing 4.23Mbytes of global variables (vtables, rtti info, ...), though they are presumably all completely unreferenced in such a short run. For the testcase in the PR, I now get this, which is what we want: $ lli -debug-only=jit test.o Global 'P1' -> 0x84e44a8 Global 'P2' -> 0x84e44b8 Finished CodeGen of [0x4018dffa] Function stub for: bar: 6 bytes of text Finished CodeGen of [0x4018dff4] Function stub for: baz: 6 bytes of text Finished CodeGen of [0x4018e000] Function: main: 57 bytes of text WARNING: Cannot resolve fn '__main' using a dummy noop function instead! [zion ~]$ lli -debug-only=jit test.o x Global 'P1' -> 0x84e44a8 Global 'P2' -> 0x84e44b8 Finished CodeGen of [0x4018dffa] Function stub for: bar: 6 bytes of text Finished CodeGen of [0x4018dff4] Function stub for: baz: 6 bytes of text Finished CodeGen of [0x4018e000] Function: main: 57 bytes of text WARNING: Cannot resolve fn '__main' using a dummy noop function instead! Finished CodeGen of [0x4018e03c] Function: qux: 16 bytes of text Finished CodeGen of [0x4018e04c] Function: baz: 7 bytes of text -Chris