It may not be the best way to do what I'm trying to do, but it's not useless and bogus. Consider the following: %1 = alloca i32* ; %1 is of type i32**, dereferenced it becomes a type i32* and ; the size of that is sizeof(void *) bytes Having said that I am looking at the target data getTypeAllocSize method. Daniel 2009/10/20 Duncan Sands <baldrick at free.fr>> Óscar Fuentes wrote: > >> Daniel Waterworth <da.waterworth at googlemail.com> writes: >> >> [snip] >> >> Use the getElementType method of PointerType. >> >> 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 >>>> >>> >> This looks suspicious to me. >> > > Probably he wants getTypeAllocSize (available from target data). The > special casing of PointerType is both useless and bogus. > > Ciao, > > Duncan. >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20091020/9ae51bb3/attachment.html>
Daniel Waterworth <da.waterworth at googlemail.com> writes:> It may not be the best way to do what I'm trying to do, but it's not useless > and bogus. Consider the following: > > %1 = alloca i32* ; %1 is of type i32**, dereferenced it becomes a type i32* > and > ; the size of that is sizeof(void *) bytesWhat Duncan says is that any valid method for obtaining the size of a Type should work for a PointerType, which is just another kind of Type.>>>>> 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-- Óscar
I agree, however, I didn't realise there was another method for obtaining the size until Duncan, correctly, pointed one out. I have since changed my code to use the getAllocSize method. Thanks, Daniel 2009/10/20 Óscar Fuentes <ofv at wanadoo.es>> Daniel Waterworth <da.waterworth at googlemail.com> writes: > > > It may not be the best way to do what I'm trying to do, but it's not > useless > > and bogus. Consider the following: > > > > %1 = alloca i32* ; %1 is of type i32**, dereferenced it becomes a type > i32* > > and > > ; the size of that is sizeof(void *) bytes > > What Duncan says is that any valid method for obtaining the size of a > Type should work for a PointerType, which is just another kind of Type. > > >>>>> 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 > > -- > Óscar > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20091020/94fe705c/attachment.html>
Hi Daniel,> It may not be the best way to do what I'm trying to do, but it's not > useless and bogus. Consider the following: > > %1 = alloca i32* ; %1 is of type i32**, dereferenced it becomes a type > i32* and > ; the size of that is sizeof(void *) bytesit is useless because getTypeAllocSize will handle any type, including pointer types. It is bogus because your code assumes that the LLVM bitcode is targeting your own machine, i.e. that sizeof(void*) as given by your machine is correct for the target. This may or may not be the case, but it is something best avoided. Ciao, Duncan.
I'm writing a function pass that is run before an ExecutionEngine Jit's the code. Therefore I can assume that my machine is the correct target. It is never the case that the pass would be run and then stored. Daniel 2009/10/20 Duncan Sands <baldrick at free.fr>> Hi Daniel, > > It may not be the best way to do what I'm trying to do, but it's not >> useless and bogus. Consider the following: >> >> %1 = alloca i32* ; %1 is of type i32**, dereferenced it becomes a type >> i32* and >> ; the size of that is sizeof(void *) bytes >> > > it is useless because getTypeAllocSize will handle any type, including > pointer types. It is bogus because your code assumes that the LLVM > bitcode is targeting your own machine, i.e. that sizeof(void*) as given > by your machine is correct for the target. This may or may not be the > case, but it is something best avoided. > > Ciao, > > Duncan. >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20091020/06609793/attachment.html>