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
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
On Mon, 4 Jul 2005, Misha Brukman wrote:> 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 -- http://nondot.org/sabre/ http://llvm.cs.uiuc.edu/
Possibly Parallel Threads
- [LLVMdev] function inlining threshold ?
- [TSAN] LLVM statistics and pass initialization trigger race detection
- [LLVMdev] Does the gcc frontend do inlining or deadcode elimination ?
- [LLVMdev] Does the gcc frontend do inlining or deadcode elimination ?
- rsync 3.0.2 with --fileflags on FreeBSD: cannot rsync hardlinked immutable files