[LLVMdev] how to call opt tool from within interpreter

Skye Wanderman-Milne skye at cloudera.com
Mon Jan 20 14:27:41 PST 2014


Hi Marwa,

Check out FunctionPassManager<http://llvm.org/docs/doxygen/html/classllvm_1_1FunctionPassManager.html>.
You can add passes to an FPM and then run it over a function, which will
cause the function to be transformed (you can use
CloneFunction()<http://llvm.org/docs/doxygen/html/namespacellvm.html#aabb040f50a7e75ad8d58bfc5d95636a4>
if
you don't want to modify the original function). I just had to do this to
perform loop unrolling on a function, and the resulting code looked
something like:

ValueToValueMapTy vmap;
Function* fn_copy = llvm::CloneFunction(fn, vmap, false);
FunctionPassManager fn_pass_manager(module);

fn_pass_manager.add(createScalarReplAggregatesPass(-1, false));
fn_pass_manager.add(createLoopRotatePass());
fn_pass_manager.add(createLoopUnrollPass());

fn_pass_manager.doInitialization();
bool change = fn_pass_manager.run(fn_copy);
fn_pass_manager.doFinalization();

You can also write your own passes to be run with the pass manager, see Writing
an LLVM Pass <http://llvm.org/docs/WritingAnLLVMPass.html>.

Hope that helps,
Skye




On Fri, Jan 17, 2014 at 10:18 AM, marwayusuf at feng.bu.edu.eg <
marwayusuf at feng.bu.edu.eg> wrote:

>  Dear All
>
> Is there a way to call opt tool from within interpreter to transform some
> function's IR code?
>
> Note: not necessarily opt tool. What I need is to apply some arbitrary
> transformation on IR and get back the transformed IR for some function.
>
> Thanks in advance.
>
>
>  Regards,
> Marwa Yusuf
> Teaching Assistant - Computer Engineering Department
> Faculty of Engineering - Benha University
> E-JUST MSc Student
> Computer Science & Engineering Dept.
>
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140120/bd22afb6/attachment.html>


More information about the llvm-dev mailing list