[Mesa-dev] [PATCH 11/16] gallium/radeon: always do the full store in store_value_to_array

Nicolai Hähnle nhaehnle at gmail.com
Wed Aug 10 19:23:36 UTC 2016


From: Nicolai Hähnle <nicolai.haehnle at amd.com>

Doing the write-back of the temporary vector in radeon_llvm_emit_store makes
no sense.

This also allows us to get rid of get_alloca_for_array.
---
 .../drivers/radeon/radeon_setup_tgsi_llvm.c        | 77 ++++++++--------------
 1 file changed, 28 insertions(+), 49 deletions(-)

diff --git a/src/gallium/drivers/radeon/radeon_setup_tgsi_llvm.c b/src/gallium/drivers/radeon/radeon_setup_tgsi_llvm.c
index 87fc07e..d8ab5b0 100644
--- a/src/gallium/drivers/radeon/radeon_setup_tgsi_llvm.c
+++ b/src/gallium/drivers/radeon/radeon_setup_tgsi_llvm.c
@@ -149,37 +149,20 @@ get_array_range(struct lp_build_tgsi_context *bld_base,
 			get_temp_array(bld_base, reg_index, reg);
 		if (array)
 			return array->range;
 	}
 
 	range.First = 0;
 	range.Last = bld_base->info->file_max[File];
 	return range;
 }
 
-static LLVMValueRef get_alloca_for_array(struct lp_build_tgsi_context *bld_base,
-					 unsigned file,
-					 unsigned index,
-					 const struct tgsi_ind_register *reg)
-{
-	const struct radeon_llvm_array *array;
-
-	if (file != TGSI_FILE_TEMPORARY)
-		return NULL;
-
-	array = get_temp_array(bld_base, index, reg);
-	if (!array)
-		return NULL;
-
-	return array->alloca;
-}
-
 static LLVMValueRef
 emit_array_index(struct lp_build_tgsi_soa_context *bld,
 		 const struct tgsi_ind_register *reg,
 		 unsigned offset)
 {
 	struct gallivm_state *gallivm = bld->bld_base.base.gallivm;
 
 	if (!reg) {
 		return lp_build_const_int32(gallivm, offset);
 	}
@@ -299,44 +282,67 @@ load_value_from_array(struct lp_build_tgsi_context *bld_base,
 		struct tgsi_declaration_range range =
 			get_array_range(bld_base, file, reg_index, reg_indirect);
 		LLVMValueRef index =
 			emit_array_index(bld, reg_indirect, reg_index - range.First);
 		LLVMValueRef array =
 			emit_array_fetch(bld_base, file, type, range, swizzle);
 		return LLVMBuildExtractElement(builder, array, index, "");
 	}
 }
 
-static LLVMValueRef
+static void
 store_value_to_array(struct lp_build_tgsi_context *bld_base,
 		     LLVMValueRef value,
 		     unsigned file,
 		     unsigned chan_index,
 		     unsigned reg_index,
 		     const struct tgsi_ind_register *reg_indirect)
 {
 	struct radeon_llvm_context *ctx = radeon_llvm_context(bld_base);
 	struct lp_build_tgsi_soa_context *bld = lp_soa_context(bld_base);
 	struct gallivm_state *gallivm = bld_base->base.gallivm;
 	LLVMBuilderRef builder = gallivm->builder;
 	LLVMValueRef ptr;
 
 	ptr = get_pointer_into_array(ctx, file, chan_index, reg_index, reg_indirect);
 	if (ptr) {
 		LLVMBuildStore(builder, value, ptr);
-		return NULL;
 	} else {
+		unsigned i, size;
 		struct tgsi_declaration_range range = get_array_range(bld_base, file, reg_index, reg_indirect);
 		LLVMValueRef index = emit_array_index(bld, reg_indirect, reg_index - range.First);
 		LLVMValueRef array =
 			emit_array_fetch(bld_base, file, TGSI_TYPE_FLOAT, range, chan_index);
-		return LLVMBuildInsertElement(builder, array, value, index, "");
+		LLVMValueRef temp_ptr;
+
+		array = LLVMBuildInsertElement(builder, array, value, index, "");
+
+		size = range.Last - range.First + 1;
+		for (i = 0; i < size; ++i) {
+			switch(file) {
+			case TGSI_FILE_OUTPUT:
+				temp_ptr = bld->outputs[i + range.First][chan_index];
+				break;
+
+			case TGSI_FILE_TEMPORARY:
+				if (range.First + i >= ctx->temps_count)
+					continue;
+				temp_ptr = ctx->temps[(i + range.First) * TGSI_NUM_CHANNELS + chan_index];
+				break;
+
+			default:
+				continue;
+			}
+			value = LLVMBuildExtractElement(builder, array,
+				lp_build_const_int32(gallivm, i), "");
+			LLVMBuildStore(builder, value, temp_ptr);
+		}
 	}
 }
 
 LLVMValueRef radeon_llvm_emit_fetch(struct lp_build_tgsi_context *bld_base,
 				    const struct tgsi_full_src_register *reg,
 				    enum tgsi_opcode_type type,
 				    unsigned swizzle)
 {
 	struct radeon_llvm_context *ctx = radeon_llvm_context(bld_base);
 	struct lp_build_tgsi_soa_context *bld = lp_soa_context(bld_base);
@@ -637,51 +643,24 @@ void radeon_llvm_emit_store(struct lp_build_tgsi_context *bld_base,
 		if (reg->Register.File == TGSI_FILE_ADDRESS) {
 			temp_ptr = bld->addr[reg->Register.Index][chan_index];
 			LLVMBuildStore(builder, value, temp_ptr);
 			continue;
 		}
 
 		if (!tgsi_type_is_64bit(dtype))
 			value = bitcast(bld_base, TGSI_TYPE_FLOAT, value);
 
 		if (reg->Register.Indirect) {
-			struct tgsi_declaration_range range = get_array_range(bld_base,
-				reg->Register.File, reg->Register.Index, &reg->Indirect);
-
-        		unsigned i, size = range.Last - range.First + 1;
 			unsigned file = reg->Register.File;
 			unsigned reg_index = reg->Register.Index;
-			LLVMValueRef array = store_value_to_array(bld_base, value, file, chan_index,
-			                                          reg_index, &reg->Indirect);
-	                if (get_alloca_for_array(bld_base, file, reg_index, &reg->Indirect)) {
-				continue;
-			}
-        		for (i = 0; i < size; ++i) {
-				switch(reg->Register.File) {
-				case TGSI_FILE_OUTPUT:
-					temp_ptr = bld->outputs[i + range.First][chan_index];
-					break;
-
-				case TGSI_FILE_TEMPORARY:
-					if (range.First + i >= ctx->temps_count)
-						continue;
-					temp_ptr = ctx->temps[(i + range.First) * TGSI_NUM_CHANNELS + chan_index];
-					break;
-
-				default:
-					continue;
-				}
-				value = LLVMBuildExtractElement(builder, array, 
-					lp_build_const_int32(gallivm, i), "");
-				LLVMBuildStore(builder, value, temp_ptr);
-			}
-
+			store_value_to_array(bld_base, value, file, chan_index,
+					     reg_index, &reg->Indirect);
 		} else {
 			switch(reg->Register.File) {
 			case TGSI_FILE_OUTPUT:
 				temp_ptr = bld->outputs[reg->Register.Index][chan_index];
 				if (tgsi_type_is_64bit(dtype))
 					temp_ptr2 = bld->outputs[reg->Register.Index][chan_index + 1];
 				break;
 
 			case TGSI_FILE_TEMPORARY:
 			{
-- 
2.7.4



More information about the mesa-dev mailing list