mov instruction in LLVM IR

We are working on a new front-end for LLVM IR for a low level language; The input has mov from one scalar to another and we would like to represent these in LLVM IR. being new to LLVM I am not sure if there is a way to represent this since I couldnt find a mov instr.

Thanks

Do you know how to do the action you seek in C? If yes, just compile with clang or llvm-gcc at -O4 and then read the output directly for the operations to use.

LLVM IR doesn't require copy instructions: because LLVM IR is in SSA
form, a copy would always be identical to the original value. See
also http://llvm.org/docs/tutorial/LangImpl7.html#memory .

-Eli

The input language is at assembly level, and the location akin to a %temp ( a virtual register if you will) and contains moves from one virtual to another. Though these are not like memory but I could represent them as local variables and do loads and stores; so I dont know how to represent it in C except as local variables.

Hi,

A way to handle moves is to have an array mapping virtual regs to the llvm instructions
which compute them. Then a
dr ← sr
move can be handled by doing
reg_to_inst [dr] = reg_to_inst [sr].

And whenever sr is used as an input to an operation, use reg_to_inst [sr] instead.

Zoltan

The input language is at assembly level,

And C makes for an excellent assembler:

$ cat s.c
main() {
   volatile register int i, j;
   i = j;
}
$ clang -O4 s.c -o - -S
; ModuleID = 's.c'
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
target triple = "x86_64-apple-darwin10.0"

define i32 @main() nounwind readnone {
entry:
  %i = alloca i32, align 4 ; <i32*> [#uses=1]
  %j = alloca i32, align 4 ; <i32*> [#uses=1]
  %tmp = volatile load i32* %j ; <i32> [#uses=1]
  volatile store i32 %tmp, i32* %i
  ret i32 undef
}

? Since you didn't give enough information on how the above is different from what you want to do, I can't do better.

you can use an add with zero, if you dont think you are adding redundancy.

Loading from and storing to an alloca is the correct way to model this in LLVM IR. In SSA form, variable are immutable—as if all were declared 'const' in C. Only memory locations are mutable.

Mid-level optimizations will eliminate the loads and stores to the stack slot where possible (i.e., the address of the alloca does not escape the function).

— Gordon

If you want to move from one vreg to another, you can always perform a
"bitcast" on the RHS and assign to the LHS (bitcasting to the same
type, of course). Though first you should ask yourself why you want to
do that and not simply just use the RHS.

-bw

Indeed that is the closest to what I want to do, without the volatile. I was hoping I could represent it directly without using local variables, but that might be the simplest way and since the address of these is never taken, LLVM can clean them up as one might hope.

Thanks
Vinod

Note that "X + 0.0" is not a noop for floating point.

-Chris