Search code examples
c++llvmllvm-c++-api

Inline a particular function call with LLVM


Given an llvm::CallInst *, how can I tell the inliner to inline this particular call. I could mark the target function as AlwaysInline and that will inline the call but it will also inline every call. Maybe there’s some way to invoke the inliner on a particular call while I’m emitting it? Inlining all calls within a basic block would work too.


Solution

  • You can use the InlineFunction utility present in llvm/Transforms/Utils/Cloning.h. It can accept a CallInst* as an argument:

    llvm::CallInst* call = /* ... */;
    llvm::InlineFunctionInfo ifi;
    
    llvm::InlineFunction(call, ifi);