[LLVMdev] Dereference PointerType?

Daniel Waterworth da.waterworth at googlemail.com
Tue Oct 20 02:31:31 PDT 2009


Hello,

I'm wondering if it's possible to dereference a PointerType. I have an
AllocaInst and although I can find the number of elements allocated, (using
Instruction::getOperand(0)), I can't find a way to get the size of each
element. What I'd like to do is:

AllocaInst *alloca;

PointerType *ptr_type = dynamic_cast<PointerType*>(alloca);
assert(ptr_type);
Type *allocated_type = ptr_type->dereference(); // this is the operation
that doesn't seem to exist.
size_t size;
if (isa<PointerType>(allocated_type)) {
  size = sizeof(void*) * 8;
} else {
  size = allocated_type->getPrimitiveSizeInBits();
}
// size now equals the size (in bits) of the type allocated

If it doesn't exist, how do you manage without it? Is there another way to
write the above code?

Thanks,

Daniel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20091020/a35e4e62/attachment.html>


More information about the llvm-dev mailing list