IR sizeof?

Is there a way to get the size of a type in the IR assembly code? I know
the size must be known since alloca and getelementptr both implicitly
use it, but I don't see any way to get access to the size directly.

I know my final compiler will have to get the size itself, but I'm just
doing some simple tests directly in assembly now and am hoping there is
an easy way to get the size of a structure.

Does this help?

http://nondot.org/sabre/LLVMNotes/SizeOf-OffsetOf-VariableSizedStructs.txt

You might want to look at the output of
llvm::ConstantExpr::getSizeOf(Type*) (e.g. using dump()):
http://llvm.org/docs/doxygen/html/classllvm_1_1ConstantExpr.html#a778163e6ec80716a12ab3282cb97f0d9

David

Look in DerivedTypes.h and see if you can find anything that will help you there. For structs you will need to account for padding and be careful about bitfields, but there should be functions to help you calculate a total size of a struct.

-Krzysztof

Yes, that is what I was looking for. I figured I could probably use
getelementptr but seeing the example is really helpful.