From 11b7c4b1ac0093781f6631c17a5441bea0be93d4 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Fri, 14 May 2010 13:22:45 -0600 Subject: [PATCH] gallivm: added lp_sizeof_llvm_type() --- src/gallium/auxiliary/gallivm/lp_bld_type.c | 37 +++++++++++++++++++++ src/gallium/auxiliary/gallivm/lp_bld_type.h | 4 +++ 2 files changed, 41 insertions(+) diff --git a/src/gallium/auxiliary/gallivm/lp_bld_type.c b/src/gallium/auxiliary/gallivm/lp_bld_type.c index 37d278d2379..70ac755bbb1 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_type.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_type.c @@ -238,6 +238,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. */ diff --git a/src/gallium/auxiliary/gallivm/lp_bld_type.h b/src/gallium/auxiliary/gallivm/lp_bld_type.h index b3f9e9175d3..17819d4d32a 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_type.h +++ b/src/gallium/auxiliary/gallivm/lp_bld_type.h @@ -316,6 +316,10 @@ struct lp_type lp_wider_type(struct lp_type type); +unsigned +lp_sizeof_llvm_type(LLVMTypeRef t); + + const char * lp_typekind_name(LLVMTypeKind t); -- 2.30.2