[LLVMdev] How to Load a Value?

Jeffrey Yasskin jyasskin at google.com
Thu Apr 8 10:53:39 PDT 2010


%2 is an i32, so you don't need to load it before using it. If you
were writing in C, the load instruction you're trying to add would be
like:

int two = atoi(...);
... loaded_two = *two;

which doesn't make any sense.

On Thu, Apr 8, 2010 at 10:40 AM, Zheng Wang <jason.wangz at gmail.com> wrote:
> 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
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>




More information about the llvm-dev mailing list