[LLVMdev] inserting a fucntion call at the end of basic bloc

Duncan Sands baldrick at free.fr
Mon Apr 25 03:01:07 PDT 2011


Hi Nabila,

> My problem is how to call a method
> suppose this fucntion
> void A(int x)
> {
>    x=x+1;
>
> }
>
> should i define this function and declare it at the beginig of the module and
> create for it a basic bloc?

you can just declare the function (i.e. no need to give it a body), and call it.
You can then link with an object file that defines it.  This is simpler than
injecting the function into each module (though that is easy to do too).

> and then how to call it before each basic bloc terminitor

Use an IRBuilder.  Pass the basic block terminator to SetInsertPoint.  Use one
of the CreateCall IRBuilder methods to insert a call instruction.

Ciao, Duncan.

>
>     ...
>
>      > i tried to see an example with the demo, i saw that it instead of calling the
>      > function, it repeats all the instruction that are existing in the function
>      > Any help?
>
>     Turn off optimization in the demo (optimization level "None").
>
>     Ciao, Duncan.
>     _______________________________________________
>     LLVM Developers mailing list
>     LLVMdev at cs.uiuc.edu <mailto: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