gallivm: Make it possible to disable some optimization shortcuts in release builds
[mesa.git] / src / gallium / auxiliary / gallivm / lp_bld_init.c
index 1f0a01cde6717ade94d243acb9ae7d2215367e8a..e8bca5bc3afce7210149cb5b100efd99ea1814c3 100644 (file)
@@ -59,6 +59,17 @@ static const bool use_mcjit = USE_MCJIT;
 static bool use_mcjit = FALSE;
 #endif
 
+unsigned gallivm_perf = 0;
+
+static const struct debug_named_value lp_bld_perf_flags[] = {
+   { "no_brilinear", GALLIVM_PERF_NO_BRILINEAR, "disable brilinear optimization" },
+   { "no_rho_approx", GALLIVM_PERF_NO_RHO_APPROX, "disable rho_approx optimization" },
+   { "no_quad_lod", GALLIVM_PERF_NO_QUAD_LOD, "disable quad_lod optimization" },
+   { "nopt",   GALLIVM_PERF_NO_OPT, "disable optimization passes to speed up shader compilation" },
+   { "no_filter_hacks", GALLIVM_PERF_NO_BRILINEAR | GALLIVM_PERF_NO_RHO_APPROX |
+     GALLIVM_PERF_NO_QUAD_LOD, "disable filter optimization hacks" },
+   DEBUG_NAMED_VALUE_END
+};
 
 #ifdef DEBUG
 unsigned gallivm_debug = 0;
@@ -67,11 +78,7 @@ static const struct debug_named_value lp_bld_debug_flags[] = {
    { "tgsi",   GALLIVM_DEBUG_TGSI, NULL },
    { "ir",     GALLIVM_DEBUG_IR, NULL },
    { "asm",    GALLIVM_DEBUG_ASM, NULL },
-   { "nopt",   GALLIVM_DEBUG_NO_OPT, NULL },
    { "perf",   GALLIVM_DEBUG_PERF, NULL },
-   { "no_brilinear", GALLIVM_DEBUG_NO_BRILINEAR, NULL },
-   { "no_rho_approx", GALLIVM_DEBUG_NO_RHO_APPROX, NULL },
-   { "no_quad_lod", GALLIVM_DEBUG_NO_QUAD_LOD, NULL },
    { "gc",     GALLIVM_DEBUG_GC, NULL },
    { "dumpbc", GALLIVM_DEBUG_DUMP_BC, NULL },
    DEBUG_NAMED_VALUE_END
@@ -136,7 +143,7 @@ create_pass_manager(struct gallivm_state *gallivm)
       free(td_str);
    }
 
-   if ((gallivm_debug & GALLIVM_DEBUG_NO_OPT) == 0) {
+   if ((gallivm_perf & GALLIVM_PERF_NO_OPT) == 0) {
       /*
        * TODO: Evaluate passes some more - keeping in mind
        * both quality of generated code and compile times.
@@ -240,7 +247,7 @@ init_gallivm_engine(struct gallivm_state *gallivm)
       char *error = NULL;
       int ret;
 
-      if (gallivm_debug & GALLIVM_DEBUG_NO_OPT) {
+      if (gallivm_perf & GALLIVM_PERF_NO_OPT) {
          optlevel = None;
       }
       else {
@@ -420,6 +427,8 @@ lp_build_init(void)
    gallivm_debug = debug_get_option_gallivm_debug();
 #endif
 
+   gallivm_perf = debug_get_flags_option("GALLIVM_PERF", lp_bld_perf_flags, 0 );
+
    lp_set_target_options();
 
    util_cpu_detect();
@@ -589,10 +598,10 @@ gallivm_compile_module(struct gallivm_state *gallivm)
       LLVMWriteBitcodeToFile(gallivm->module, filename);
       debug_printf("%s written\n", filename);
       debug_printf("Invoke as \"opt %s %s | llc -O%d %s%s\"\n",
-                   gallivm_debug & GALLIVM_DEBUG_NO_OPT ? "-mem2reg" :
+                   gallivm_debug & GALLIVM_PERF_NO_OPT ? "-mem2reg" :
                    "-sroa -early-cse -simplifycfg -reassociate "
                    "-mem2reg -constprop -instcombine -gvn",
-                   filename, gallivm_debug & GALLIVM_DEBUG_NO_OPT ? 0 : 2,
+                   filename, gallivm_debug & GALLIVM_PERF_NO_OPT ? 0 : 2,
                    (HAVE_LLVM >= 0x0305) ? "[-mcpu=<-mcpu option>] " : "",
                    "[-mattr=<-mattr option(s)>]");
    }