[LLVMdev] How to Load a Value?
Zheng Wang
jason.wangz at gmail.com
Thu Apr 8 10:40:26 PDT 2010
Hello,
I have a problem of generating a load instruction. The LLVM bytecode is:
------------------------
entry:
...
%2 = call i32 (...)* @atoi(i8*%1) nounwind
/*<- Insertpos*/
...
--
bb1:
..
%5 = icmp sgt i32 %2, %i.0
...
-----------------
Now I have
pb: pointer to the Value object of *%2* of bb1.
Here, I want to generate a load instruction and I did it as:
new LoadInst(pb, "load_2", InsertPos);
where InsertPos points to the position immediately after "%2 = call
i32 (...)* @atoi(i8*%1) nounwind".
BUT I got a runtime error as:
"
include/llvm/Support/Casting.h:199: typename llvm::cast_retty<To,
From>::ret_type llvm::cast(const Y&) [with X = llvm::PointerType, Y =
const llvm::Type*]: Assertion `isa<X>(Val) && "cast<Ty>() argument of
incompatible type!"' failed."
This is because LoadInst is implemented as:
LoadInst::LoadInst(Value *Ptr, const Twine &Name, BasicBlock *InsertAE)
: UnaryInstruction(cast<PointerType>(Ptr->getType())->getElementType(),
Load, Ptr, InsertAE)
{
...
}
and pb->getType() is not a "PointerType"!!! WHY? Is it because it is a
function call? In this situation, how can I load %2 assuming it has
been load before.
Can anybody gives me some hints?
Cheers,
Zheng
More information about the llvm-dev
mailing list