diff --git a/src/gallium/auxiliary/gallivm/lp_bld_type.c b/src/gallium/auxiliary/gallivm/lp_bld_type.c index a261ae98143..db91f50ff48 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_type.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_type.c @@ -33,20 +33,23 @@ #include "lp_bld_init.h" #include "lp_bld_limits.h" + +/* + * Return a scalar LLVMTypeRef corresponding to the given lp_type. + */ LLVMTypeRef -lp_build_elem_type(struct gallivm_state *gallivm, struct lp_type type) +lp_build_elem_type(const struct gallivm_state *gallivm, struct lp_type type) { if (type.floating) { - switch(type.width) { + switch (type.width) { case 16: - return lp_has_fp16() ? LLVMHalfTypeInContext(gallivm->context) : LLVMInt16TypeInContext(gallivm->context); - break; + return lp_has_fp16() + ? LLVMHalfTypeInContext(gallivm->context) + : LLVMInt16TypeInContext(gallivm->context); case 32: return LLVMFloatTypeInContext(gallivm->context); - break; case 64: return LLVMDoubleTypeInContext(gallivm->context); - break; default: assert(0); return LLVMFloatTypeInContext(gallivm->context); @@ -58,8 +61,11 @@ lp_build_elem_type(struct gallivm_state *gallivm, struct lp_type type) } +/* + * Return a vector LLVMTypeRef corresponding to the given lp_type. + */ LLVMTypeRef -lp_build_vec_type(struct gallivm_state *gallivm,struct lp_type type) +lp_build_vec_type(const struct gallivm_state *gallivm, struct lp_type type) { LLVMTypeRef elem_type = lp_build_elem_type(gallivm, type); if (type.length == 1) @@ -78,27 +84,32 @@ lp_build_vec_type(struct gallivm_state *gallivm,struct lp_type type) boolean lp_check_elem_type(struct lp_type type, LLVMTypeRef elem_type) { - LLVMTypeKind elem_kind; - assert(elem_type); - if(!elem_type) + if (!elem_type) return FALSE; - elem_kind = LLVMGetTypeKind(elem_type); + const LLVMTypeKind elem_kind = LLVMGetTypeKind(elem_type); if (type.floating) { - switch(type.width) { + switch (type.width) { case 16: - if(elem_kind != (lp_has_fp16() ? LLVMHalfTypeKind : LLVMIntegerTypeKind)) + if (elem_kind != (lp_has_fp16() + ? LLVMHalfTypeKind : LLVMIntegerTypeKind)) { + debug_printf("%s:%d: type is not 16 bits\n", __FILE__, __LINE__); return FALSE; + } break; case 32: - if(elem_kind != LLVMFloatTypeKind) + if (elem_kind != LLVMFloatTypeKind) { + debug_printf("%s:%d: type is not float\n", __FILE__, __LINE__); return FALSE; + } break; case 64: - if(elem_kind != LLVMDoubleTypeKind) + if (elem_kind != LLVMDoubleTypeKind) { + debug_printf("%s:%d: type is not double\n", __FILE__, __LINE__); return FALSE; + } break; default: assert(0); @@ -106,11 +117,17 @@ lp_check_elem_type(struct lp_type type, LLVMTypeRef elem_type) } } else { - if(elem_kind != LLVMIntegerTypeKind) + if (elem_kind != LLVMIntegerTypeKind) { + debug_printf("%s:%d: element is not integer\n", __FILE__, __LINE__); return FALSE; + } - if(LLVMGetIntTypeWidth(elem_type) != type.width) + if (LLVMGetIntTypeWidth(elem_type) != type.width) { + debug_printf("%s:%d: type width mismatch %d != %d\n", + __FILE__, __LINE__, + LLVMGetIntTypeWidth(elem_type), type.width); return FALSE; + } } return TRUE; @@ -120,22 +137,25 @@ lp_check_elem_type(struct lp_type type, LLVMTypeRef elem_type) boolean lp_check_vec_type(struct lp_type type, LLVMTypeRef vec_type) { - LLVMTypeRef elem_type; - assert(vec_type); - if(!vec_type) + if (!vec_type) return FALSE; if (type.length == 1) return lp_check_elem_type(type, vec_type); - if(LLVMGetTypeKind(vec_type) != LLVMVectorTypeKind) + if (LLVMGetTypeKind(vec_type) != LLVMVectorTypeKind) { + printf("%s:%d: kind is not vector\n", __FILE__, __LINE__); return FALSE; + } - if(LLVMGetVectorSize(vec_type) != type.length) + if (LLVMGetVectorSize(vec_type) != type.length) { + printf("%s:%d: vector size mismatch %d != expected %d\n", __FILE__, __LINE__, + LLVMGetVectorSize(vec_type), type.length); return FALSE; + } - elem_type = LLVMGetElementType(vec_type); + LLVMTypeRef elem_type = LLVMGetElementType(vec_type); return lp_check_elem_type(type, elem_type); } @@ -144,27 +164,27 @@ lp_check_vec_type(struct lp_type type, LLVMTypeRef vec_type) boolean lp_check_value(struct lp_type type, LLVMValueRef val) { - LLVMTypeRef vec_type; - assert(val); - if(!val) + if (!val) return FALSE; - vec_type = LLVMTypeOf(val); + LLVMTypeRef vec_type = LLVMTypeOf(val); return lp_check_vec_type(type, vec_type); } LLVMTypeRef -lp_build_int_elem_type(struct gallivm_state *gallivm, struct lp_type type) +lp_build_int_elem_type(const struct gallivm_state *gallivm, + struct lp_type type) { return LLVMIntTypeInContext(gallivm->context, type.width); } LLVMTypeRef -lp_build_int_vec_type(struct gallivm_state *gallivm, struct lp_type type) +lp_build_int_vec_type(const struct gallivm_state *gallivm, + struct lp_type type) { LLVMTypeRef elem_type = lp_build_int_elem_type(gallivm, type); if (type.length == 1) diff --git a/src/gallium/auxiliary/gallivm/lp_bld_type.h b/src/gallium/auxiliary/gallivm/lp_bld_type.h index 9c7dc252166..5412d823c2a 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_type.h +++ b/src/gallium/auxiliary/gallivm/lp_bld_type.h @@ -341,11 +341,11 @@ lp_type_ufixed(unsigned width, unsigned total_width) LLVMTypeRef -lp_build_elem_type(struct gallivm_state *gallivm, struct lp_type type); +lp_build_elem_type(const struct gallivm_state *gallivm, struct lp_type type); LLVMTypeRef -lp_build_vec_type(struct gallivm_state *gallivm, struct lp_type type); +lp_build_vec_type(const struct gallivm_state *gallivm, struct lp_type type); boolean @@ -361,11 +361,13 @@ lp_check_value(struct lp_type type, LLVMValueRef val); LLVMTypeRef -lp_build_int_elem_type(struct gallivm_state *gallivm, struct lp_type type); +lp_build_int_elem_type(const struct gallivm_state *gallivm, + struct lp_type type); LLVMTypeRef -lp_build_int_vec_type(struct gallivm_state *gallivm, struct lp_type type); +lp_build_int_vec_type(const struct gallivm_state *gallivm, + struct lp_type type); static inline struct lp_type