I’m holding a Type* in my hand. How do I find out its size (the size objects of this type will occupy in memory) in bits / bytes? I see all kinds of methods allowing me to get “primitive” or “scalar” size, but that won’t help me with aggregate types…
I’m holding a Type* in my hand. How do I find out its size
Share
The size depends on the target (for several reasons, alignment being one of them).
In LLVM versions 3.2 and above, you need to use DataLayout, in particular its
getTypeAllocSizemethod. This returns the size in bytes, there’s also a bit version namedgetTypeAllocSizeInBits. ADataLayoutinstance can be obtained by creating it from the current module:DataLayout* TD = new DataLayout(M).With LLVM up to version 3.1 (including), use
TargetDatainstead ofDataLayout. It exposes the samegetTypeAllocSizemethods, though.