How do I get the size of a Type at compile time?

From LLVM

Jump to: navigation, search

Keywords: sizeof(Type), getSize(Type), TargetData, getTypeSizeInBits

The size of a Type can be computed at compile time by using the getTypeStoreSize, getTypeSizeInBits and other similar functions in the TargetData object emitted by ExecutionEngine::getTargetData.

Code example:

//getTypeSize - returns the number of bytes required to store an instance of 'type'.
uint64_t getTypeSize(ExecutionEngine *TheEE, Type *type) {
    TargetData *td = TheEE->getTargetData();
    return td->getTypeStoreSize(type);
}
Personal tools