Generating New Functions

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Generating New Functions

Abhinash Jain
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.
Reply | Threaded
Open this post in threaded view
|

Re: Generating New Functions

John Criswell-4
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
> [hidden email]         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev

_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: Generating New Functions

Abhinash Jain
>>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).

Thnx for ur reply,
I already visited this links and cpp file, but things are not helping me the way I wanted to.
Can you be a bit specific on it?