[LLVMdev] Problem in X86 backend

Tim Northover t.p.northover at gmail.com
Mon Oct 27 07:42:13 PDT 2014


Hi,

> I want to add this instruction in one of my machine basic block: mov [rdi], 0
> How can I achieve that with the LLVM api? I tried several stuff, but none works :(

I find the best way to do this when I'm unsure is to get the llvm-mc
tool to assemble my instruction and copy what it produces. Your
instruction is actually ambiguous though: you need to say what size
you want the store to be. I'll assume 32-bit:

$ echo "mov dword ptr [rdi], 0" | llvm-mc -x86-asm-syntax=intel
-output-asm-variant=1 -show-inst
mov dword ptr [rdi], 0      ## <MCInst #1611 MOV32mi
                                        ##  <MCOperand Reg:39>
                                        ##  <MCOperand Imm:1>
                                        ##  <MCOperand Reg:0>
                                        ##  <MCOperand Imm:0>
                                        ##  <MCOperand Reg:0>
                                        ##  <MCOperand Imm:0>>

Now, that looks complicated, but x86 has uniform memory
addressing-modes: those first 5 operands are just specifying that
address and you only have to learn about them once; and the last
operand is the "0" you've written (try playing around a bit with the
input).

As for the addressing, the meaning of each operand is given at the top
of lib/Target/X86/X86BaseInfo.h: 0 == Base, 1 == Scale, 2 == Index, 3
== Disp, 4 == Segment.

Cheers.

Tim.



More information about the llvm-dev mailing list