Re: [Mesa-dev] [PATCH 1/3] ac: add ac_count_scratch_private_memory()

2018-03-05 Thread Dave Airlie
On 2 March 2018 at 07:12, Samuel Pitoiset  wrote:
> Imported from RadeonSI.

For the series

Reviewed-by: Dave Airlie 
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 1/3] ac: add ac_count_scratch_private_memory()

2018-03-01 Thread Samuel Pitoiset
Imported from RadeonSI.

Signed-off-by: Samuel Pitoiset 
---
 src/amd/common/ac_llvm_util.c| 31 +++
 src/amd/common/ac_llvm_util.h|  3 +++
 src/gallium/drivers/radeonsi/si_shader.c | 32 
 3 files changed, 38 insertions(+), 28 deletions(-)

diff --git a/src/amd/common/ac_llvm_util.c b/src/amd/common/ac_llvm_util.c
index b88c4e4979..3530bf088b 100644
--- a/src/amd/common/ac_llvm_util.c
+++ b/src/amd/common/ac_llvm_util.c
@@ -24,10 +24,12 @@
  */
 /* based on pieces from si_pipe.c and radeon_llvm_emit.c */
 #include "ac_llvm_util.h"
+#include "ac_llvm_build.h"
 #include "util/bitscan.h"
 #include 
 #include 
 #include "c11/threads.h"
+#include "util/u_math.h"
 
 #include 
 #include 
@@ -207,3 +209,32 @@ ac_llvm_add_target_dep_function_attr(LLVMValueRef F,
snprintf(str, sizeof(str), "%i", value);
LLVMAddTargetDependentFunctionAttr(F, name, str);
 }
+
+unsigned
+ac_count_scratch_private_memory(LLVMValueRef function)
+{
+   unsigned private_mem_vgprs = 0;
+
+   /* Process all LLVM instructions. */
+   LLVMBasicBlockRef bb = LLVMGetFirstBasicBlock(function);
+   while (bb) {
+   LLVMValueRef next = LLVMGetFirstInstruction(bb);
+
+   while (next) {
+   LLVMValueRef inst = next;
+   next = LLVMGetNextInstruction(next);
+
+   if (LLVMGetInstructionOpcode(inst) != LLVMAlloca)
+   continue;
+
+   LLVMTypeRef type = LLVMGetElementType(LLVMTypeOf(inst));
+   /* No idea why LLVM aligns allocas to 4 elements. */
+   unsigned alignment = LLVMGetAlignment(inst);
+   unsigned dw_size = align(ac_get_type_size(type) / 4, 
alignment);
+   private_mem_vgprs += dw_size;
+   }
+   bb = LLVMGetNextBasicBlock(bb);
+   }
+
+   return private_mem_vgprs;
+}
diff --git a/src/amd/common/ac_llvm_util.h b/src/amd/common/ac_llvm_util.h
index 3cf385a33e..5329bb1b70 100644
--- a/src/amd/common/ac_llvm_util.h
+++ b/src/amd/common/ac_llvm_util.h
@@ -105,6 +105,9 @@ ac_get_store_intr_attribs(bool writeonly_memory)
  AC_FUNC_ATTR_WRITEONLY;
 }
 
+unsigned
+ac_count_scratch_private_memory(LLVMValueRef function);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/src/gallium/drivers/radeonsi/si_shader.c 
b/src/gallium/drivers/radeonsi/si_shader.c
index 2a50b266f6..74bd435124 100644
--- a/src/gallium/drivers/radeonsi/si_shader.c
+++ b/src/gallium/drivers/radeonsi/si_shader.c
@@ -5957,32 +5957,6 @@ static void si_optimize_vs_outputs(struct 
si_shader_context *ctx)
   >info.nr_param_exports);
 }
 
-static void si_count_scratch_private_memory(struct si_shader_context *ctx)
-{
-   ctx->shader->config.private_mem_vgprs = 0;
-
-   /* Process all LLVM instructions. */
-   LLVMBasicBlockRef bb = LLVMGetFirstBasicBlock(ctx->main_fn);
-   while (bb) {
-   LLVMValueRef next = LLVMGetFirstInstruction(bb);
-
-   while (next) {
-   LLVMValueRef inst = next;
-   next = LLVMGetNextInstruction(next);
-
-   if (LLVMGetInstructionOpcode(inst) != LLVMAlloca)
-   continue;
-
-   LLVMTypeRef type = LLVMGetElementType(LLVMTypeOf(inst));
-   /* No idea why LLVM aligns allocas to 4 elements. */
-   unsigned alignment = LLVMGetAlignment(inst);
-   unsigned dw_size = align(ac_get_type_size(type) / 4, 
alignment);
-   ctx->shader->config.private_mem_vgprs += dw_size;
-   }
-   bb = LLVMGetNextBasicBlock(bb);
-   }
-}
-
 static void si_init_exec_from_input(struct si_shader_context *ctx,
unsigned param, unsigned bitoffset)
 {
@@ -6929,8 +6903,10 @@ int si_compile_tgsi_shader(struct si_screen *sscreen,
si_optimize_vs_outputs();
 
if ((debug && debug->debug_message) ||
-   si_can_dump_shader(sscreen, ctx.type))
-   si_count_scratch_private_memory();
+   si_can_dump_shader(sscreen, ctx.type)) {
+   ctx.shader->config.private_mem_vgprs =
+   ac_count_scratch_private_memory(ctx.main_fn);
+   }
 
/* Compile to bytecode. */
r = si_compile_llvm(sscreen, >binary, >config, tm,
-- 
2.16.2

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev