About instrumenting/rewriting X86 instructions

Hi all,

I plan to use LLVM to instrument/rewrite X86 instructions during the compilation of a program.
For example, insert checking target instructions before jmp instructions, or rewrite a instruction to prevent code using a specific register.

I think the work should be done at the CodeGen phase, but I'm not quite clear how can I start.
Can anyone give me some suggestions?

Thanks very much,