[LLVMdev] Retrieving Underlying Type from AllocaInst

Curtis Faith curtis at curtisfaith.com
Thu May 27 21:57:35 PDT 2010


Is there a recommended way to retrieve the original type from an AllocaInst object?

For example, I am creating alloca instructions using the IRBuilder interface like:

alloca = builder.CreateAlloca( Type::getDoubleTy( context ), 0, variableName.c_str() );

and I place the alloca into a symbol table.

Later when I am generating instructions for an assignment operation, I want to check the type of the variable allocated with the CreateAlloca instruction so I can see if I need to do type conversion before the store instruction, However, I cannot simply use:

alloca->getType()->isDoubleTy() etc.

because this doesn't return true in the above case. The ID of the Ty member of  the VTy member of the alloca is PointerTyID instead of DoubleTyID as the construction for AllocaInst::AllocaInst seems to create a PointerType pointing to the original type.

I was hoping for a member function of the alloca that would return the original type that was passed to CreateAlloca.  I can test for a PointerTyID and then perform a cast to PointerType and then call the getElementType() function on the PointerType but that seems a bit messy. 

Thanks in advance,

Curtis
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20100528/1bef64a5/attachment.html>


More information about the llvm-dev mailing list