[LLVMdev] Implementing sizeof

Chris Lattner sabre at nondot.org
Fri Jul 27 12:27:18 PDT 2007


Check out http://nondot.org/sabre/LLVMNotes

-Chris

http://nondot.org/sabre
http://llvm.org

On Jul 27, 2007, at 12:00 PM, Sarah Thompson <thompson at email.arc.nasa.gov 
 > wrote:

> Hi folks,
>
> Assuming that I'm writing a pass and that for bizarre reasons I need  
> to
> programmatically do the equivalent of a C/C++ sizeof on a Value (or a
> Type, it doesn't matter which really), yielding a result in bytes,  
> what
> is the known-safe way to do this? I notice that doing something like
>
> struct thingy
> {
>    ... some stuff ...
> };
>
> ...
>    printf("Size = %d", sizeof(thingy));
> ...
>
> turns into a constant at the bitcode disassembly level, which is fair
> enough but I can't rely on the source passing down information like  
> that
> -- I have to be able to work purely at the opt pass level. One of the 
> transformations I need to do is turn load and store instructions into
> model-checker-specific intrinsics so I can track memory modifications
> efficiently, but just having the address isn't enough, I really need  
> the
> size too. Or are reads and writes always guaranteed to be simple  
> types,
> so the bit width (as given by the Type::getPrimitiveSizeInBits()  
> member
> function) divided by 8 and rounded up if necessary  is enough? (The
> latter works well for me too, I just don't want to mess myself up by
> making assumptions).
>
> As usual, thank you in  advance.
>
> Sarah
> _______________________________________________
> 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