Search code examples
c++llvm

How to insert a function in LLVM module


I am writing an LLVM pass, where I clone some functions by calling llvm::CloneFunction. Now I also want to insert those functions in the module. How can I do that?


Solution

    • Create a new function with Function::Create or by other means. A Function's constructors accept a module into which to insert the new function.
    • Clone a function into that new function with CloneFunctionInto, or just copy over the BBs you need.