diff options
author | Brian Paul <brianp@vmware.com> | 2010-05-14 13:22:45 -0600 |
---|---|---|
committer | Brian Paul <brianp@vmware.com> | 2010-05-14 13:23:41 -0600 |
commit | 11b7c4b1ac0093781f6631c17a5441bea0be93d4 (patch) | |
tree | 1ad2b0fa2699672702504abfddd609bb9141213e /src/gallium/auxiliary/gallivm/lp_bld_type.c | |
parent | 9a0ff95425ab291374368cc0968ab674729f66f3 (diff) | |
download | external_mesa3d-11b7c4b1ac0093781f6631c17a5441bea0be93d4.zip external_mesa3d-11b7c4b1ac0093781f6631c17a5441bea0be93d4.tar.gz external_mesa3d-11b7c4b1ac0093781f6631c17a5441bea0be93d4.tar.bz2 |
gallivm: added lp_sizeof_llvm_type()
Diffstat (limited to 'src/gallium/auxiliary/gallivm/lp_bld_type.c')
-rw-r--r-- | src/gallium/auxiliary/gallivm/lp_bld_type.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_type.c b/src/gallium/auxiliary/gallivm/lp_bld_type.c index 37d278d..70ac755 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_type.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_type.c @@ -239,6 +239,43 @@ lp_wider_type(struct lp_type type) /** + * Return the size of the LLVMType in bits. + * XXX this function doesn't necessarily handle all LLVM types. + */ +unsigned +lp_sizeof_llvm_type(LLVMTypeRef t) +{ + LLVMTypeKind k = LLVMGetTypeKind(t); + + switch (k) { + case LLVMIntegerTypeKind: + return LLVMGetIntTypeWidth(t); + case LLVMFloatTypeKind: + return 8 * sizeof(float); + case LLVMDoubleTypeKind: + return 8 * sizeof(double); + case LLVMVectorTypeKind: + { + LLVMTypeRef elem = LLVMGetElementType(t); + unsigned len = LLVMGetVectorSize(t); + return len * lp_sizeof_llvm_type(elem); + } + break; + case LLVMArrayTypeKind: + { + LLVMTypeRef elem = LLVMGetElementType(t); + unsigned len = LLVMGetArrayLength(t); + return len * lp_sizeof_llvm_type(elem); + } + break; + default: + assert(0 && "Unexpected type in lp_get_llvm_type_size()"); + return 0; + } +} + + +/** * Return string name for a LLVMTypeKind. Useful for debugging. */ const char * |