llvmpipe: Debug helper function to name llvm intermediate values.
authorJosé Fonseca <jfonseca@vmware.com>
Tue, 18 Aug 2009 19:23:35 +0000 (20:23 +0100)
committerJosé Fonseca <jfonseca@vmware.com>
Sat, 29 Aug 2009 08:21:34 +0000 (09:21 +0100)
src/gallium/drivers/llvmpipe/lp_bld_blend_aos.c
src/gallium/drivers/llvmpipe/lp_bld_debug.h
src/gallium/drivers/llvmpipe/lp_bld_tgsi_soa.c
src/gallium/drivers/llvmpipe/lp_state_blend.c
src/gallium/drivers/llvmpipe/lp_state_fs.c
src/gallium/drivers/llvmpipe/lp_test_blend.c

index 880235bc00964ebde891735cce2ba894be64c45c..87ba456065396eb1f55c63e6834a83822d0813ca 100644 (file)
@@ -42,6 +42,7 @@
 #include "lp_bld_logic.h"
 #include "lp_bld_swizzle.h"
 #include "lp_bld_blend.h"
+#include "lp_bld_debug.h"
 
 
 /**
@@ -326,10 +327,8 @@ lp_build_blend_aos(LLVMBuilderRef builder,
    src_term = lp_build_blend_factor(&bld, src, blend->rgb_src_factor, blend->alpha_src_factor, alpha_swizzle);
    dst_term = lp_build_blend_factor(&bld, dst, blend->rgb_dst_factor, blend->alpha_dst_factor, alpha_swizzle);
 
-#ifdef DEBUG
-   LLVMSetValueName(src_term, "src_term");
-   LLVMSetValueName(dst_term, "dst_term");
-#endif
+   lp_build_name(src_term, "src_term");
+   lp_build_name(dst_term, "dst_term");
 
    if(blend->rgb_func == blend->alpha_func) {
       return lp_build_blend_func(&bld.base, blend->rgb_func, src_term, dst_term);
index d83652504bba95d7a4ecc9dea083b204749e4b47..ecdafef76d065424032ec9e9e1f9baf7e04fa6f4 100644 (file)
 #define LP_BLD_DEBUG_H
 
 
+#include <llvm-c/Core.h>
+
+#include "pipe/p_compiler.h"
+#include "util/u_string.h"
+
+
+static INLINE void
+lp_build_name(LLVMValueRef val, const char *format, ...)
+{
+#ifdef DEBUG
+   char name[32];
+   va_list ap;
+   va_start(ap, format);
+   util_vsnprintf(name, sizeof name, format, ap);
+   va_end(ap);
+   LLVMSetValueName(val, name);
+#else
+   (void)val;
+   (void)format;
+#endif
+}
+
+
 void
 lp_disassemble(const void* func);
 
index b7b1df9adeda9dc837704b46d32c3e59ac3204d6..451915f23f648e1c59098c6046055ba65b94b006 100644 (file)
@@ -42,6 +42,7 @@
 #include "lp_bld_logic.h"
 #include "lp_bld_swizzle.h"
 #include "lp_bld_tgsi.h"
+#include "lp_bld_debug.h"
 
 
 #define LP_MAX_TEMPS 256
@@ -1353,10 +1354,11 @@ emit_declaration(
                LLVMValueRef a0;
                LLVMValueRef dadx;
                LLVMValueRef dady;
-               char name[32];
 
                switch( decl->Declaration.Interpolate ) {
                case TGSI_INTERPOLATE_PERSPECTIVE:
+                  /* fall-through */
+
                case TGSI_INTERPOLATE_LINEAR: {
                   LLVMValueRef dadx_ptr = LLVMBuildGEP(builder, bld->dadx_ptr, &index, 1, "");
                   LLVMValueRef dady_ptr = LLVMBuildGEP(builder, bld->dady_ptr, &index, 1, "");
@@ -1364,18 +1366,16 @@ emit_declaration(
                   dady = LLVMBuildLoad(builder, dady_ptr, "");
                   dadx = lp_build_broadcast_scalar(&bld->base, dadx);
                   dady = lp_build_broadcast_scalar(&bld->base, dady);
-                  util_snprintf(name, sizeof name, "dadx_%u.%c", attrib, "xyzw"[chan]);
-                  LLVMSetValueName(dadx, name);
-                  util_snprintf(name, sizeof name, "dady_%u.%c", attrib, "xyzw"[chan]);
-                  LLVMSetValueName(dady, name);
+                  lp_build_name(dadx, "dadx_%u.%c", attrib, "xyzw"[chan]);
+                  lp_build_name(dady, "dady_%u.%c", attrib, "xyzw"[chan]);
+                  /* fall-through */
                }
 
                case TGSI_INTERPOLATE_CONSTANT: {
                   LLVMValueRef a0_ptr = LLVMBuildGEP(builder, bld->a0_ptr, &index, 1, "");
                   a0 = LLVMBuildLoad(builder, a0_ptr, "");
                   a0 = lp_build_broadcast_scalar(&bld->base, a0);
-                  util_snprintf(name, sizeof name, "a0_%u.%c", attrib, "xyzw"[chan]);
-                  LLVMSetValueName(a0, name);
+                  lp_build_name(a0, "a0_%u.%c", attrib, "xyzw"[chan]);
                   break;
                }
 
@@ -1397,8 +1397,7 @@ emit_declaration(
                   input = lp_build_mul(&bld->base, input, bld->oow);
                }
 
-               util_snprintf(name, sizeof name, "input%u.%c", attrib, "xyzw"[chan]);
-               LLVMSetValueName(input, name);
+               lp_build_name(input, "input%u.%c", attrib, "xyzw"[chan]);
             }
 
             bld->inputs[attrib][chan] = input;
index 487146bcd4d084499ca0f11bb675699c2eab12a8..d1c8536acf7c32d7033755715b62cff54b443a4d 100644 (file)
@@ -66,10 +66,6 @@ blend_generate(struct llvmpipe_screen *screen,
    LLVMValueRef con[4];
    LLVMValueRef dst[4];
    LLVMValueRef res[4];
-   char src_name[5] = "src?";
-   char con_name[5] = "con?";
-   char dst_name[5] = "dst?";
-   char res_name[5] = "res?";
    unsigned i;
 
    type.value = 0;
@@ -105,18 +101,21 @@ blend_generate(struct llvmpipe_screen *screen,
 
    for(i = 0; i < 4; ++i) {
       LLVMValueRef index = LLVMConstInt(LLVMInt32Type(), i, 0);
-      con_name[3] = dst_name[3] = src_name[3] = "rgba"[i];
-      src[i] = LLVMBuildLoad(builder, LLVMBuildGEP(builder, src_ptr, &index, 1, ""), src_name);
-      con[i] = LLVMBuildLoad(builder, LLVMBuildGEP(builder, const_ptr, &index, 1, ""), con_name);
-      dst[i] = LLVMBuildLoad(builder, LLVMBuildGEP(builder, dst_ptr, &index, 1, ""), dst_name);
+
+      src[i] = LLVMBuildLoad(builder, LLVMBuildGEP(builder, src_ptr, &index, 1, ""), "");
+      con[i] = LLVMBuildLoad(builder, LLVMBuildGEP(builder, const_ptr, &index, 1, ""), "");
+      dst[i] = LLVMBuildLoad(builder, LLVMBuildGEP(builder, dst_ptr, &index, 1, ""), "");
+
+      lp_build_name(src[i], "src.%c", "rgba"[i]);
+      lp_build_name(con[i], "con.%c", "rgba"[i]);
+      lp_build_name(dst[i], "dst.%c", "rgba"[i]);
    }
 
    lp_build_blend_soa(builder, &blend->base, type, src, dst, con, res);
 
    for(i = 0; i < 4; ++i) {
       LLVMValueRef index = LLVMConstInt(LLVMInt32Type(), i, 0);
-      res_name[3] = "rgba"[i];
-      LLVMSetValueName(res[i], res_name);
+      lp_build_name(res[i], "res.%c", "rgba"[i]);
       res[i] = lp_build_select(&bld, mask, res[i], dst[i]);
       LLVMBuildStore(builder, res[i], LLVMBuildGEP(builder, dst_ptr, &index, 1, ""));
    }
index fd93d6f9b42919576975d61c191eab3ffa48510e..1397f948b2753a50236bd5abc28e17979a579fbb 100644 (file)
@@ -67,7 +67,6 @@ shader_generate(struct llvmpipe_screen *screen,
    LLVMValueRef pos[NUM_CHANNELS];
    LLVMValueRef outputs[PIPE_MAX_SHADER_OUTPUTS][NUM_CHANNELS];
    LLVMValueRef mask;
-   char name[32];
    unsigned i, j;
 
    type.value = 0;
@@ -106,14 +105,14 @@ shader_generate(struct llvmpipe_screen *screen,
    mask_ptr = LLVMGetParam(shader->function, 6);
    samplers_ptr = LLVMGetParam(shader->function, 7);
 
-   LLVMSetValueName(pos_ptr, "pos");
-   LLVMSetValueName(a0_ptr, "a0");
-   LLVMSetValueName(dadx_ptr, "dadx");
-   LLVMSetValueName(dady_ptr, "dady");
-   LLVMSetValueName(consts_ptr, "consts");
-   LLVMSetValueName(outputs_ptr, "outputs");
-   LLVMSetValueName(mask_ptr, "mask");
-   LLVMSetValueName(samplers_ptr, "samplers");
+   lp_build_name(pos_ptr, "pos");
+   lp_build_name(a0_ptr, "a0");
+   lp_build_name(dadx_ptr, "dadx");
+   lp_build_name(dady_ptr, "dady");
+   lp_build_name(consts_ptr, "consts");
+   lp_build_name(outputs_ptr, "outputs");
+   lp_build_name(mask_ptr, "mask");
+   lp_build_name(samplers_ptr, "samplers");
 
    block = LLVMAppendBasicBlock(shader->function, "entry");
    builder = LLVMCreateBuilder();
@@ -121,8 +120,8 @@ shader_generate(struct llvmpipe_screen *screen,
 
    for(j = 0; j < NUM_CHANNELS; ++j) {
       LLVMValueRef index = LLVMConstInt(LLVMInt32Type(), j, 0);
-      util_snprintf(name, sizeof name, "pos.%c", "xyzw"[j]);
-      pos[j] = LLVMBuildLoad(builder, LLVMBuildGEP(builder, pos_ptr, &index, 1, ""), name);
+      pos[j] = LLVMBuildLoad(builder, LLVMBuildGEP(builder, pos_ptr, &index, 1, ""), "");
+      lp_build_name(pos[j], "pos.%c", "xyzw"[j]);
    }
 
    memset(outputs, 0, sizeof outputs);
@@ -135,8 +134,8 @@ shader_generate(struct llvmpipe_screen *screen,
       for(j = 0; j < NUM_CHANNELS; ++j) {
          if(outputs[i][j]) {
             LLVMValueRef index = LLVMConstInt(LLVMInt32Type(), i*NUM_CHANNELS + j, 0);
-            util_snprintf(name, sizeof name, "output%u.%c", i, "xyzw"[j]);
-            LLVMBuildStore(builder, outputs[i][j], LLVMBuildGEP(builder, outputs_ptr, &index, 1, name));
+            LLVMBuildStore(builder, outputs[i][j], LLVMBuildGEP(builder, outputs_ptr, &index, 1, ""));
+            lp_build_name(pos[j], "output%u.%c", i, "xyzw"[j]);
          }
       }
    }
index 0b6d2da590abe63e6ef12fdf4ae6e2c6e87e4a5e..8dfad468e3cca1dcaaeecee0c6b706c8cbb2f41f 100644 (file)
@@ -193,7 +193,7 @@ add_blend_test(LLVMModuleRef module,
 
       res = lp_build_blend_aos(builder, blend, type, src, dst, con, 3);
 
-      LLVMSetValueName(res, "res");
+      lp_build_name(res, "res");
 
       LLVMBuildStore(builder, res, res_ptr);
    }
@@ -203,26 +203,23 @@ add_blend_test(LLVMModuleRef module,
       LLVMValueRef dst[4];
       LLVMValueRef con[4];
       LLVMValueRef res[4];
-      char src_name[5] = "src?";
-      char dst_name[5] = "dst?";
-      char con_name[5] = "con?";
-      char res_name[5] = "res?";
       unsigned i;
 
       for(i = 0; i < 4; ++i) {
          LLVMValueRef index = LLVMConstInt(LLVMInt32Type(), i, 0);
-         con_name[3] = dst_name[3] = src_name[3] = "rgba"[i];
-         src[i] = LLVMBuildLoad(builder, LLVMBuildGEP(builder, src_ptr, &index, 1, ""), src_name);
-         dst[i] = LLVMBuildLoad(builder, LLVMBuildGEP(builder, dst_ptr, &index, 1, ""), dst_name);
-         con[i] = LLVMBuildLoad(builder, LLVMBuildGEP(builder, const_ptr, &index, 1, ""), con_name);
+         src[i] = LLVMBuildLoad(builder, LLVMBuildGEP(builder, src_ptr, &index, 1, ""), "");
+         dst[i] = LLVMBuildLoad(builder, LLVMBuildGEP(builder, dst_ptr, &index, 1, ""), "");
+         con[i] = LLVMBuildLoad(builder, LLVMBuildGEP(builder, const_ptr, &index, 1, ""), "");
+         lp_build_name(src[i], "src.%c", "rgba"[i]);
+         lp_build_name(con[i], "con.%c", "rgba"[i]);
+         lp_build_name(dst[i], "dst.%c", "rgba"[i]);
       }
 
       lp_build_blend_soa(builder, blend, type, src, dst, con, res);
 
       for(i = 0; i < 4; ++i) {
          LLVMValueRef index = LLVMConstInt(LLVMInt32Type(), i, 0);
-         res_name[3] = "rgba"[i];
-         LLVMSetValueName(res[i], res_name);
+         lp_build_name(res[i], "res.%c", "rgba"[i]);
          LLVMBuildStore(builder, res[i], LLVMBuildGEP(builder, res_ptr, &index, 1, ""));
       }
    }