librelist archives

« back to archive

ModulePass with llvm-py

ModulePass with llvm-py

From:
Jun Koi
Date:
2012-07-10 @ 03:44
hi everybody,

sorry if this is not directly related to Numba, but i am the user of
llvm-py, and Travis suggested me to ask my questions here, since there
are lots of llvm-py users.

my problem is like this: i am writing some simple LLVM module pass in
C++, and now want to write that in llvm-py. the problem is that i am
not quite sure if it is even possible to do that, knowing that llvm-py
is still not quite mature yet.

my simple LLVM pass is like below. the question is: is it possible to
do this with llvm-py, and if so, how?

any help is highly appreciated. i am still new to llvm-py, so please
be gentle, thanks :-)

best,
Jun

////
class MyPass : public ModulePass, public InstVisitor<MyPass> {
        public:
                bool runOnModule(Module &M); { /* do smt .. */ }
                void visitBranchInst(BranchInst &I); { /* do smt */ }
}

Re: ModulePass with llvm-py

From:
Jun Koi
Date:
2012-07-12 @ 07:32
On Tue, Jul 10, 2012 at 11:44 AM, Jun Koi <junkoi2004@gmail.com> wrote:
> hi everybody,
>
> sorry if this is not directly related to Numba, but i am the user of
> llvm-py, and Travis suggested me to ask my questions here, since there
> are lots of llvm-py users.
>
> my problem is like this: i am writing some simple LLVM module pass in
> C++, and now want to write that in llvm-py. the problem is that i am
> not quite sure if it is even possible to do that, knowing that llvm-py
> is still not quite mature yet.
>
> my simple LLVM pass is like below. the question is: is it possible to
> do this with llvm-py, and if so, how?
>
> any help is highly appreciated. i am still new to llvm-py, so please
> be gentle, thanks :-)
>

please, anybody tell me how to inherit the InstVisitor class for a
LLVM pass with llvm-py?

thanks!
Jun



> ////
> class MyPass : public ModulePass, public InstVisitor<MyPass> {
>         public:
>                 bool runOnModule(Module &M); { /* do smt .. */ }
>                 void visitBranchInst(BranchInst &I); { /* do smt */ }
> }

Re: [numba] Re: ModulePass with llvm-py

From:
Siu Kwan Lam
Date:
2012-07-12 @ 16:08
On 07/12/2012 12:32 AM, Jun Koi wrote:
> On Tue, Jul 10, 2012 at 11:44 AM, Jun Koi <junkoi2004@gmail.com> wrote:
>> hi everybody,
>>
>> sorry if this is not directly related to Numba, but i am the user of
>> llvm-py, and Travis suggested me to ask my questions here, since there
>> are lots of llvm-py users.
>>
>> my problem is like this: i am writing some simple LLVM module pass in
>> C++, and now want to write that in llvm-py. the problem is that i am
>> not quite sure if it is even possible to do that, knowing that llvm-py
>> is still not quite mature yet.
>>
>> my simple LLVM pass is like below. the question is: is it possible to
>> do this with llvm-py, and if so, how?
>>
>> any help is highly appreciated. i am still new to llvm-py, so please
>> be gentle, thanks :-)
>>
> please, anybody tell me how to inherit the InstVisitor class for a
> LLVM pass with llvm-py?
>
> thanks!
> Jun
>
>
>
>> ////
>> class MyPass : public ModulePass, public InstVisitor<MyPass> {
>>          public:
>>                  bool runOnModule(Module &M); { /* do smt .. */ }
>>                  void visitBranchInst(BranchInst &I); { /* do smt */ }
>> }

Hi,

I do not think llvm-py allows one to write passes with it.  The 
userguide says the following:
"Although llvm-py does not allow you to write your own passes, it does 
allow you to navigate the entire IR at any stage, and perform any 
transforms on it as you like."

I also searched through the source tree for "InstVisitor" and 
"ModulePass".  Neither of them are exposed to python.

It seems the current easiest way is to implement your own visitor in python.

Regards,
Siu