function inlining threshold ?

I am using llvm for source-to-source inlining. So I did:

% llvm-gcc file_a.c file_b.c ... file_n.c -o file
% opt -inline -inline-threshold=1000 < file.bc | llc -march=c > outfile.c

Can anyone tell me how llvm determines if a function should be inlined, and what roll does "inline-threshold" play ? (Does the example mean that if the function body has fewer than 1000 instructions, then it should be inlined ?)

thanks,
--Long

The LLVM inliner structure is implemented in
llvm/lib/Transforms/IPO/Inliner.cpp which is a base implementation.
There, you can see that -inline-threshold is a switch that provides
value to InlineLimit which is used to initialize InlineThreshold member
variable.

This is compared with the output of getInlineCost() which is a virtual
function. Currently, the inliner implemented in LLVM is
InlineSimple.cpp in the same directory, which adds cost to functions if
they have recursive calls, allocas, and other features, but at the end,
you'll notice that it weighs each instruction as 5 with each basic block
as 20.

I've omitted many details, see SimpleInliner::getInlineCost() in
llvm/lib/Transforms/IPO/InlineSimple.cpp for complete calculation.

Another thing that may be useful: passing -debug-only=inline will cause the inliner to print out the perceived costs of inlining at each call site and the decisions it makes.

-Chris