I defined int a = 5
; in the source code, and I transform the source to LLVM IR:
%a = alloca i32, align 4
store i32 5, i32* %a, align 4
I want to insert int b = a;
by writing a pass. I compile int a=5; int b=a
into LLVM IR, it load "a" first, then store it. I also checked the doxygen, in which the LoadInst is LoadInst (Value *Ptr, const Twine &NameStr, Instruction *InsertBefore)
Still, I don't know how to get the Value
of "a".
How to get a variable value?
In LLVM IR the sequence
without any optimization, is translated as
This corresponds to two
AllocaInst
s, twoStoreInst
s and aLoadInst
as followswarning: untested/uncompiled pseudocode ahead
You're probably being confused since the instruction is the value in LLVM API thanks to a well-designed inheritance hierarchy.