[LLVMdev] Wondering how best to run inlining on a single function.

Chris Lattner clattner at apple.com
Tue May 26 18:05:16 PDT 2009

On May 26, 2009, at 3:15 PM, Jeffrey Yasskin wrote:

> In Unladen Swallow we (intend to) compile each function as we
> determine it's hot. To "compile" a function means to translate it from
> CPython bytecode to LLVM IR, optimize the IR using a
> FunctionPassManager, and JIT the IR to machine code. We'd like to
> include inlining among our optimizations. Currently the Inliner is a
> CallGraphSCCPass, which can only be run by the (Module)PassManager and
> which will try to inline calls into every function in the module,
> including functions we've already optimized. This seems like it will
> waste time.
> I think that, because we optimize every Python function as we generate
> it, it makes sense to write a SingleFunctionInliner (is there a better
> name?) that acts as a FunctionPass and add that to our normal
> FunctionPassManager. Can you guys see anything that will go wrong if I
> do that? Is there a better way, or an option that doesn't involve
> writing new code?

Hi Jeffrey,

Does this need to be an actual pass?  You can just call the  
InlineFunction API to inline individual call sites as needed, check  
out llvm/Transforms/Utils/Cloning.h.  CloneAndPruneFunctionInto is a  
particularly useful function if you're doing argument specialization,  
because it is very efficient at handling this (better than inlining a  
bunch of code and then deleting it as dead later).


More information about the llvm-dev mailing list