[llvm-dev] How to insert a function call after certain instructions for x86 backend

John Criswell via llvm-dev llvm-dev at lists.llvm.org
Fri Mar 18 06:31:33 PDT 2016


On 3/18/16 6:42 AM, Zhiyu Xie via llvm-dev wrote:
> Hi all,
>       I am trying to instrument a program to insert a function 
> call after SP-Update instructions. SP-Update instructions are those 
> modify the esp register such as mov esp, eax ; xchg eax, esp ; add 
> esp, [eax+0x20] and so on. It seems that I should dig into the back 
> end. But which representation of instructions should I focus on? 
> MachineInstr or MCInst or other class?

You should write a MachineFunctionPass and operate and the MachineInstr 
level.  Your pass will need to be integrated into the LLVM code 
generator for your target.


> Where is the definitions of all opcodes and registers?

For MachineInstr's, registers are just numbers, and there are constants 
(e.g., Reg::RAX, IIRC) that represent the various registers.

You can look at the control-flow integrity pass for a dated (but I think 
still useful) example of how to write a MachineFunctionPass. It is at 
https://github.com/jtcriswell/SVA/blob/master/llvm/lib/Target/X86/X86CFIOptPass.cpp.

> In which part of the back end should I inspect the instructions?  And 
> How to insert a function call? May I use MachineInstrBuilder::BuildMI ?

BuildMI is what you want.

> I am so sorry to ask so many questions because I am a newbie to LLVM. 
> I would appreciate it if any one coulld help me.

If you have not done so already, you should read the document on "How to 
Write an LLVM Pass" and the document on the code generator (the one that 
briefly explains MachineInstr's).  You should also make use of the 
doxygen documentation.

Regards,

John Criswell

>
>
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev


-- 
John Criswell
Assistant Professor
Department of Computer Science, University of Rochester
http://www.cs.rochester.edu/u/criswell

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160318/af54ea25/attachment-0001.html>


More information about the llvm-dev mailing list