[LLVMdev] Generating New Functions
John Criswell
criswell at illinois.edu
Mon Oct 14 07:22:18 PDT 2013
On 10/14/13 5:53 AM, Abhinash Jain wrote:
> How can I generate a new function at compile time and insert some instruction
> onto it, through llvm pass.
> eg.
>
> 1) %y = alloca i32, align 4
> 2) %z = alloca i32, align 4
> 3) %t = alloca i32, align 4
> 4) %2 = load i32* %y, align 4
> 5) %3 = load i32* %z, align 4
> 6) %add = add nsw i32 %2, %3
> 7) %4 = load i32* %t, align 4
> 8) %add1 = add nsw i32 %add, %4
> 9) store i32 %add1, i32* %x, align 4
>
> whenever I see a store instruction, I want to generate a new function and
> insert/copy all instruction (from 1 to 9) on that generated function.
You should consult the doxygen documentation on llvm::Function to
determine how to create new functions. For most LLVM objects, there is
either a new method or a static Create/create method that will create
the objects. The doxygen docs contain the list of methods for each
class and will usually have the information for which you're looking:
http://llvm.org/doxygen/classllvm_1_1Function.html
As for copying instructions into a new function, look at the functions
in lib/Transforms/Utils/CloneFunction.cpp (note that the pathname of the
file may have moved; this is its location in LLVM 3.2).
-- John T.
>
>
>
> --
> View this message in context: http://llvm.1065342.n5.nabble.com/Generating-New-Functions-tp62038.html
> Sent from the LLVM - Dev mailing list archive at Nabble.com.
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
More information about the llvm-dev
mailing list