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.
You might want to look at the output of
llvm::ConstantExpr::getSizeOf(Type*) (e.g. using dump()):
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.
Yes, that is what I was looking for. I figured I could probably use
getelementptr but seeing the example is really helpful.