0

I am a newbie to LLVM IR, and I am trying to simulate some x86 instructions in LLVM IR.

Here is a simple case:

move %eax, %ebx

However, I didn't find any corresponding mov opcode after looking at the materials at here and here.

So my question is :

  1. If I want to simulate the mov opcode using LLVM IR? What should I do?

  2. I am new to LLVM IR, and probably I would spend a long time on this "simulation" work, what should be the best reference about LLVM IR?

I really appreciate if anyone can give me some help. Thanks!

lllllllllllll
  • 8,519
  • 9
  • 45
  • 80

2 Answers2

6

There is no equivalent to the mov instruction. LLVM IR is in SSA (Static Single Assignment) form, which means that each register is assigned a value exactly once. There are an unlimited number of (virtual) registers -- each operation creates a new one as needed.

It's unclear what you mean by simulating x86 instructions, but if it suits you, you could allocate memory on the stack for a local variable for each register (using the alloca instruction), and use the load and store instructions to copy values between them.

Ismail Badawi
  • 36,054
  • 7
  • 85
  • 97
0

If you need to move the value of one LLVM IR register into another, you can employ bitcast instruction:

; %a contains 64bit integer value
%a = i64 ...

; Copy / move the value of %a into %b
%b = bitcast i64 %a to i64

For more detail, see: https://llvm.org/docs/LangRef.html#bitcast-to-instruction

Ales Teska
  • 1,198
  • 1
  • 17
  • 38