[LLVMdev] Clarification regarding the LLVM IR.
Tim Northover
t.p.northover at gmail.com
Sun Aug 18 10:30:57 PDT 2013
Hi James,
> The only instructions that can work on the values on the stack or on the
> heap are LOAD and STORE.
That's more or less true. If your variable is in memory then you have
to load it before doing operations and store it back afterwards. There
are one or two other instructions that can perform loads and stores
though (atomicrmw, certain intrinsics, ...).
> %local = alloca i32, align 4
> %1 = add nsw i32* %local, 291
To add 291 to this local variable you'd write:
%curVal = load i32* %local
%newVal = add i32 %curVal, 291
store i32 %newVal, i32* %local
Optimizations (one called mem2reg in the first instance) will normally
get rid of the implied inefficiency in loading and storing everything.
Tim.
More information about the llvm-dev
mailing list