Instrumenting LLVM IR


I am writing an LLVM Pass in which i need to manipulate code.

I need to delete particular lines of code, insert new lines of code and manipulate code . Can anyone guide me on how to go about this?

In particular I would like to know how to do the following things:

  1. How to do I write an LLVM Pass which knows which particular lines of code i need to delete?

  2. How do i insert a line of code, for example inserting a function call like “foo(a)” , and how do i specify which place to insert this function call?

  3. How do i manipulate existing code, such as for example changing “foo(a)” to “foo(b)”?

Thanks and Regards,