gallivm: asst. clean-ups in lp_bld_type.[ch]

Signed-off-by: Brian Paul <brianp@vmware.com>
Reviewed-by: Roland Scheidegger <sroland@vmware.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16937>
This commit is contained in:
Brian Paul 2022-05-17 09:28:45 -06:00 committed by Marge Bot
parent 7111d20832
commit 059afb8a90
2 changed files with 55 additions and 33 deletions

View file

@ -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)

View file

@ -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