ac/llvm: add helpers to get pointer types of ac_arg

Reviewed-by: Qiang Yu <yuq825@gmail.com>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Acked-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19035>
This commit is contained in:
Pierre-Eric Pelloux-Prayer
2022-10-05 17:41:04 +02:00
committed by Marge Bot
parent 5dcc2c216b
commit fab476bd11
2 changed files with 51 additions and 20 deletions

View File

@@ -2828,6 +2828,29 @@ LLVMValueRef ac_find_lsb(struct ac_llvm_context *ctx, LLVMTypeRef dst_type, LLVM
LLVMConstInt(ctx->i32, -1, 0), lsb, ""); LLVMConstInt(ctx->i32, -1, 0), lsb, "");
} }
LLVMTypeRef ac_arg_type_to_pointee_type(struct ac_llvm_context *ctx, enum ac_arg_type type) {
switch (type) {
case AC_ARG_CONST_PTR:
return ctx->i8;
break;
case AC_ARG_CONST_FLOAT_PTR:
return ctx->f32;
break;
case AC_ARG_CONST_PTR_PTR:
return ac_array_in_const32_addr_space(ctx->i8);
break;
case AC_ARG_CONST_DESC_PTR:
return ctx->v4i32;
break;
case AC_ARG_CONST_IMAGE_PTR:
return ctx->v8i32;
default:
/* Other ac_arg_type values aren't pointers. */
assert(false);
return NULL;
}
}
LLVMTypeRef ac_array_in_const_addr_space(LLVMTypeRef elem_type) LLVMTypeRef ac_array_in_const_addr_space(LLVMTypeRef elem_type)
{ {
return LLVMPointerType(elem_type, AC_ADDR_SPACE_CONST); return LLVMPointerType(elem_type, AC_ADDR_SPACE_CONST);
@@ -4493,37 +4516,37 @@ void ac_build_export_prim(struct ac_llvm_context *ctx, const struct ac_ngg_prim
static LLVMTypeRef arg_llvm_type(enum ac_arg_type type, unsigned size, struct ac_llvm_context *ctx) static LLVMTypeRef arg_llvm_type(enum ac_arg_type type, unsigned size, struct ac_llvm_context *ctx)
{ {
if (type == AC_ARG_FLOAT) { LLVMTypeRef base;
return size == 1 ? ctx->f32 : LLVMVectorType(ctx->f32, size); switch (type) {
} else if (type == AC_ARG_INT) { case AC_ARG_FLOAT:
return size == 1 ? ctx->i32 : LLVMVectorType(ctx->i32, size); return size == 1 ? ctx->f32 : LLVMVectorType(ctx->f32, size);
} else { case AC_ARG_INT:
LLVMTypeRef ptr_type; return size == 1 ? ctx->i32 : LLVMVectorType(ctx->i32, size);
switch (type) {
case AC_ARG_CONST_PTR: case AC_ARG_CONST_PTR:
ptr_type = ctx->i8; base = ctx->i8;
break; break;
case AC_ARG_CONST_FLOAT_PTR: case AC_ARG_CONST_FLOAT_PTR:
ptr_type = ctx->f32; base = ctx->f32;
break; break;
case AC_ARG_CONST_PTR_PTR: case AC_ARG_CONST_PTR_PTR:
ptr_type = ac_array_in_const32_addr_space(ctx->i8); base = ac_array_in_const32_addr_space(ctx->i8);
break; break;
case AC_ARG_CONST_DESC_PTR: case AC_ARG_CONST_DESC_PTR:
ptr_type = ctx->v4i32; base = ctx->v4i32;
break; break;
case AC_ARG_CONST_IMAGE_PTR: case AC_ARG_CONST_IMAGE_PTR:
ptr_type = ctx->v8i32; base = ctx->v8i32;
break; break;
default: default:
unreachable("unknown arg type"); return NULL;
} }
if (size == 1) {
return ac_array_in_const32_addr_space(ptr_type); assert(base);
} else { if (size == 1) {
assert(size == 2); return ac_array_in_const32_addr_space(base);
return ac_array_in_const_addr_space(ptr_type); } else {
} assert(size == 2);
return ac_array_in_const_addr_space(base);
} }
} }

View File

@@ -575,12 +575,20 @@ LLVMValueRef ac_pack_edgeflags_for_export(struct ac_llvm_context *ctx,
LLVMValueRef ac_pack_prim_export(struct ac_llvm_context *ctx, const struct ac_ngg_prim *prim); LLVMValueRef ac_pack_prim_export(struct ac_llvm_context *ctx, const struct ac_ngg_prim *prim);
void ac_build_export_prim(struct ac_llvm_context *ctx, const struct ac_ngg_prim *prim); void ac_build_export_prim(struct ac_llvm_context *ctx, const struct ac_ngg_prim *prim);
LLVMTypeRef ac_arg_type_to_pointee_type(struct ac_llvm_context *ctx, enum ac_arg_type type);
static inline LLVMValueRef ac_get_arg(struct ac_llvm_context *ctx, struct ac_arg arg) static inline LLVMValueRef ac_get_arg(struct ac_llvm_context *ctx, struct ac_arg arg)
{ {
assert(arg.used); assert(arg.used);
return LLVMGetParam(ctx->main_function, arg.arg_index); return LLVMGetParam(ctx->main_function, arg.arg_index);
} }
static inline LLVMTypeRef ac_get_arg_pointee_type(struct ac_llvm_context *ctx, const struct ac_shader_args *args, struct ac_arg arg)
{
assert(arg.used);
return ac_arg_type_to_pointee_type(ctx, args->args[arg.arg_index].type);
}
enum ac_llvm_calling_convention enum ac_llvm_calling_convention
{ {
AC_LLVM_AMDGPU_VS = 87, AC_LLVM_AMDGPU_VS = 87,