[Mesa-dev] [PATCH 04/15] glsl: Modify dead function removal to only operate on built-in functions

Ian Romanick idr at freedesktop.org
Thu Sep 15 22:12:37 UTC 2016


From: Ian Romanick <ian.d.romanick at intel.com>

This will be used in the stand-alone compiler.

Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
---
 src/compiler/glsl/glsl_parser_extras.cpp |  2 +-
 src/compiler/glsl/ir_optimization.h      |  2 +-
 src/compiler/glsl/opt_dead_functions.cpp | 11 +++++++----
 src/compiler/glsl/test_optpass.cpp       |  2 +-
 4 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/src/compiler/glsl/glsl_parser_extras.cpp b/src/compiler/glsl/glsl_parser_extras.cpp
index 29eba13..807bf3f 100644
--- a/src/compiler/glsl/glsl_parser_extras.cpp
+++ b/src/compiler/glsl/glsl_parser_extras.cpp
@@ -2043,7 +2043,7 @@ do_common_optimization(exec_list *ir, bool linked,
 
    if (linked) {
       OPT(do_function_inlining, ir, false);
-      OPT(do_dead_functions, ir);
+      OPT(do_dead_functions, ir, false);
       OPT(do_structure_splitting, ir);
    }
    propagate_invariance(ir);
diff --git a/src/compiler/glsl/ir_optimization.h b/src/compiler/glsl/ir_optimization.h
index 26f13f1..20c17e3 100644
--- a/src/compiler/glsl/ir_optimization.h
+++ b/src/compiler/glsl/ir_optimization.h
@@ -100,7 +100,7 @@ void do_dead_builtin_varyings(struct gl_context *ctx,
 bool do_dead_code(exec_list *instructions, bool uniform_locations_assigned);
 bool do_dead_code_local(exec_list *instructions);
 bool do_dead_code_unlinked(exec_list *instructions);
-bool do_dead_functions(exec_list *instructions);
+bool do_dead_functions(exec_list *instructions, bool only_builtins);
 bool opt_flip_matrices(exec_list *instructions);
 bool do_function_inlining(exec_list *instructions, bool only_builtins);
 bool do_lower_jumps(exec_list *instructions, bool pull_out_jumps = true, bool lower_sub_return = true, bool lower_main_return = false, bool lower_continue = false, bool lower_break = false);
diff --git a/src/compiler/glsl/opt_dead_functions.cpp b/src/compiler/glsl/opt_dead_functions.cpp
index 2e90b65..4b58bc9 100644
--- a/src/compiler/glsl/opt_dead_functions.cpp
+++ b/src/compiler/glsl/opt_dead_functions.cpp
@@ -49,7 +49,8 @@ public:
 
 class ir_dead_functions_visitor : public ir_hierarchical_visitor {
 public:
-   ir_dead_functions_visitor()
+   ir_dead_functions_visitor(bool only_builtins)
+      : only_builtins(only_builtins)
    {
       this->mem_ctx = ralloc_context(NULL);
    }
@@ -66,6 +67,7 @@ public:
 
    /* List of signature_entry */
    exec_list signature_list;
+   bool only_builtins;
    void *mem_ctx;
 };
 
@@ -94,7 +96,8 @@ ir_dead_functions_visitor::visit_enter(ir_function_signature *ir)
       entry->used = true;
    }
 
-
+   if (only_builtins && !ir->is_builtin())
+      entry->used = true;
 
    return visit_continue;
 }
@@ -111,9 +114,9 @@ ir_dead_functions_visitor::visit_enter(ir_call *ir)
 }
 
 bool
-do_dead_functions(exec_list *instructions)
+do_dead_functions(exec_list *instructions, bool only_builtins)
 {
-   ir_dead_functions_visitor v;
+   ir_dead_functions_visitor v(only_builtins);
    bool progress = false;
 
    visit_list_elements(&v, instructions);
diff --git a/src/compiler/glsl/test_optpass.cpp b/src/compiler/glsl/test_optpass.cpp
index 3771a89..3659c8b 100644
--- a/src/compiler/glsl/test_optpass.cpp
+++ b/src/compiler/glsl/test_optpass.cpp
@@ -85,7 +85,7 @@ do_optimization(struct exec_list *ir, const char *optimization,
    } else if (strcmp(optimization, "do_dead_code_unlinked") == 0) {
       return do_dead_code_unlinked(ir);
    } else if (strcmp(optimization, "do_dead_functions") == 0) {
-      return do_dead_functions(ir);
+      return do_dead_functions(ir, false);
    } else if (strcmp(optimization, "do_function_inlining") == 0) {
       return do_function_inlining(ir, false);
    } else if (sscanf(optimization,
-- 
2.5.5



More information about the mesa-dev mailing list