gallivm: added lp_sizeof_llvm_type()
authorBrian Paul <brianp@vmware.com>
Fri, 14 May 2010 19:22:45 +0000 (13:22 -0600)
committerBrian Paul <brianp@vmware.com>
Fri, 14 May 2010 19:23:41 +0000 (13:23 -0600)
src/gallium/auxiliary/gallivm/lp_bld_type.c
src/gallium/auxiliary/gallivm/lp_bld_type.h

index 37d278d23797a51e98770257f0967f5a73cf0b1f..70ac755bbb1b6c9fe4a7782e4d23fc2a0a04c462 100644 (file)
@@ -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.
  */
index b3f9e9175d39234502213942ebe46a70c51f1196..17819d4d32a3ab1d144539fbb000f63fc4a9984f 100644 (file)
@@ -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);