[LLVMdev] function inlining threshold ?
Misha Brukman
brukman at cs.uiuc.edu
Mon Jul 4 20:04:47 PDT 2005
On Mon, Jul 04, 2005 at 03:32:39PM -0500, Long Fei wrote:
> 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 ?)
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.
--
Misha Brukman :: http://misha.brukman.net :: http://llvm.cs.uiuc.edu
More information about the llvm-dev
mailing list