[Mesa-dev] [PATCH 8/8] glsl: Put a bunch of optimization visitors under anonymous namespaces.

Eric Anholt eric at anholt.net
Wed May 30 10:56:36 PDT 2012


Because these classes are used entirely from their own source files
and not from separate DSOs, the linker gets to produce massively less
code.  This cuts about 13k of text in the libdricore case.  In the
non-libdricore case, the additional linkage information allows the
compiler to inline some code, so libglsl.a size actually increases by
about 300 bytes.

For a dricore build, improves shader_runner runtime on
glsl-fs-copy-propagation-texcoords-1 by 0.21% +/- 0.03% (n=353574,
outliers removed).  No statistically significant difference with n=322
on glslparsertest on a yofrankie shader intended to test compiler
performance.
---
 src/glsl/opt_algebraic.cpp                 |    4 ++++
 src/glsl/opt_constant_folding.cpp          |    4 ++++
 src/glsl/opt_constant_propagation.cpp      |    4 ++++
 src/glsl/opt_constant_variable.cpp         |    4 ++++
 src/glsl/opt_copy_propagation.cpp          |    4 ++++
 src/glsl/opt_copy_propagation_elements.cpp |    4 ++++
 src/glsl/opt_dead_code_local.cpp           |    3 +++
 src/glsl/opt_dead_functions.cpp            |    3 +++
 src/glsl/opt_function_inlining.cpp         |    3 +++
 src/glsl/opt_if_simplification.cpp         |    4 ++++
 src/glsl/opt_noop_swizzle.cpp              |    4 ++++
 src/glsl/opt_redundant_jumps.cpp           |    4 ++++
 src/glsl/opt_structure_splitting.cpp       |    4 ++++
 src/glsl/opt_swizzle_swizzle.cpp           |    4 ++++
 src/glsl/opt_tree_grafting.cpp             |    4 ++++
 15 files changed, 57 insertions(+)

diff --git a/src/glsl/opt_algebraic.cpp b/src/glsl/opt_algebraic.cpp
index cade961..d397612 100644
--- a/src/glsl/opt_algebraic.cpp
+++ b/src/glsl/opt_algebraic.cpp
@@ -34,6 +34,8 @@
 #include "ir_optimization.h"
 #include "glsl_types.h"
 
+namespace {
+
 /**
  * Visitor class for replacing expressions with ir_constant values.
  */
@@ -68,6 +70,8 @@ public:
    bool progress;
 };
 
+} /* unnamed namespace */
+
 static inline bool
 is_vec_zero(ir_constant *ir)
 {
diff --git a/src/glsl/opt_constant_folding.cpp b/src/glsl/opt_constant_folding.cpp
index dcad599..7d94d48 100644
--- a/src/glsl/opt_constant_folding.cpp
+++ b/src/glsl/opt_constant_folding.cpp
@@ -32,6 +32,8 @@
 #include "ir_optimization.h"
 #include "glsl_types.h"
 
+namespace {
+
 /**
  * Visitor class for replacing expressions with ir_constant values.
  */
@@ -56,6 +58,8 @@ public:
    bool progress;
 };
 
+} /* unnamed namespace */
+
 void
 ir_constant_folding_visitor::handle_rvalue(ir_rvalue **rvalue)
 {
diff --git a/src/glsl/opt_constant_propagation.cpp b/src/glsl/opt_constant_propagation.cpp
index 2601b52..c5ae36b 100644
--- a/src/glsl/opt_constant_propagation.cpp
+++ b/src/glsl/opt_constant_propagation.cpp
@@ -41,6 +41,8 @@
 #include "ir_optimization.h"
 #include "glsl_types.h"
 
+namespace {
+
 class acp_entry : public exec_node
 {
 public:
@@ -450,6 +452,8 @@ ir_constant_propagation_visitor::add_constant(ir_assignment *ir)
    this->acp->push_tail(entry);
 }
 
+} /* unnamed namespace */
+
 /**
  * Does a constant propagation pass on the code present in the instruction stream.
  */
diff --git a/src/glsl/opt_constant_variable.cpp b/src/glsl/opt_constant_variable.cpp
index f3bc867..1bbaf8e 100644
--- a/src/glsl/opt_constant_variable.cpp
+++ b/src/glsl/opt_constant_variable.cpp
@@ -37,6 +37,8 @@
 #include "ir_optimization.h"
 #include "glsl_types.h"
 
+namespace {
+
 struct assignment_entry {
    exec_node link;
    int assignment_count;
@@ -55,6 +57,8 @@ public:
    exec_list list;
 };
 
+} /* unnamed namespace */
+
 static struct assignment_entry *
 get_assignment_entry(ir_variable *var, exec_list *list)
 {
diff --git a/src/glsl/opt_copy_propagation.cpp b/src/glsl/opt_copy_propagation.cpp
index 923619d..2952ce5 100644
--- a/src/glsl/opt_copy_propagation.cpp
+++ b/src/glsl/opt_copy_propagation.cpp
@@ -38,6 +38,8 @@
 #include "ir_optimization.h"
 #include "glsl_types.h"
 
+namespace {
+
 class acp_entry : public exec_node
 {
 public:
@@ -107,6 +109,8 @@ public:
    void *mem_ctx;
 };
 
+} /* unnamed namespace */
+
 ir_visitor_status
 ir_copy_propagation_visitor::visit_enter(ir_function_signature *ir)
 {
diff --git a/src/glsl/opt_copy_propagation_elements.cpp b/src/glsl/opt_copy_propagation_elements.cpp
index 11d9d7b..de9f4ef 100644
--- a/src/glsl/opt_copy_propagation_elements.cpp
+++ b/src/glsl/opt_copy_propagation_elements.cpp
@@ -49,6 +49,8 @@
 
 static bool debug = false;
 
+namespace {
+
 class acp_entry : public exec_node
 {
 public:
@@ -135,6 +137,8 @@ public:
    void *shader_mem_ctx;
 };
 
+} /* unnamed namespace */
+
 ir_visitor_status
 ir_copy_propagation_elements_visitor::visit_enter(ir_function_signature *ir)
 {
diff --git a/src/glsl/opt_dead_code_local.cpp b/src/glsl/opt_dead_code_local.cpp
index 4af78a7..8c31802 100644
--- a/src/glsl/opt_dead_code_local.cpp
+++ b/src/glsl/opt_dead_code_local.cpp
@@ -40,6 +40,8 @@
 
 static bool debug = false;
 
+namespace {
+
 class assignment_entry : public exec_node
 {
 public:
@@ -138,6 +140,7 @@ public:
    ir_hierarchical_visitor *visitor;
 };
 
+} /* unnamed namespace */
 
 /**
  * Adds an entry to the available copy list if it's a plain assignment
diff --git a/src/glsl/opt_dead_functions.cpp b/src/glsl/opt_dead_functions.cpp
index f503493..cd3b2c1 100644
--- a/src/glsl/opt_dead_functions.cpp
+++ b/src/glsl/opt_dead_functions.cpp
@@ -32,6 +32,8 @@
 #include "ir_expression_flattening.h"
 #include "glsl_types.h"
 
+namespace {
+
 class signature_entry : public exec_node
 {
 public:
@@ -67,6 +69,7 @@ public:
    void *mem_ctx;
 };
 
+} /* unnamed namespace */
 
 signature_entry *
 ir_dead_functions_visitor::get_signature_entry(ir_function_signature *sig)
diff --git a/src/glsl/opt_function_inlining.cpp b/src/glsl/opt_function_inlining.cpp
index 4ff4d97..f9f5bd4 100644
--- a/src/glsl/opt_function_inlining.cpp
+++ b/src/glsl/opt_function_inlining.cpp
@@ -39,6 +39,8 @@ do_sampler_replacement(exec_list *instructions,
 		       ir_variable *sampler,
 		       ir_dereference *deref);
 
+namespace {
+
 class ir_function_inlining_visitor : public ir_hierarchical_visitor {
 public:
    ir_function_inlining_visitor()
@@ -60,6 +62,7 @@ public:
    bool progress;
 };
 
+} /* unnamed namespace */
 
 bool
 do_function_inlining(exec_list *instructions)
diff --git a/src/glsl/opt_if_simplification.cpp b/src/glsl/opt_if_simplification.cpp
index 7e88208..e1a23d9 100644
--- a/src/glsl/opt_if_simplification.cpp
+++ b/src/glsl/opt_if_simplification.cpp
@@ -30,6 +30,8 @@
 
 #include "ir.h"
 
+namespace {
+
 class ir_if_simplification_visitor : public ir_hierarchical_visitor {
 public:
    ir_if_simplification_visitor()
@@ -43,6 +45,8 @@ public:
    bool made_progress;
 };
 
+} /* unnamed namespace */
+
 /* We only care about the top level "if" instructions, so don't
  * descend into expressions.
  */
diff --git a/src/glsl/opt_noop_swizzle.cpp b/src/glsl/opt_noop_swizzle.cpp
index 0a906aa..693719e 100644
--- a/src/glsl/opt_noop_swizzle.cpp
+++ b/src/glsl/opt_noop_swizzle.cpp
@@ -35,6 +35,8 @@
 #include "ir_print_visitor.h"
 #include "glsl_types.h"
 
+namespace {
+
 class ir_noop_swizzle_visitor : public ir_rvalue_visitor {
 public:
    ir_noop_swizzle_visitor()
@@ -46,6 +48,8 @@ public:
    bool progress;
 };
 
+} /* unnamed namespace */
+
 void
 ir_noop_swizzle_visitor::handle_rvalue(ir_rvalue **rvalue)
 {
diff --git a/src/glsl/opt_redundant_jumps.cpp b/src/glsl/opt_redundant_jumps.cpp
index f350fa9..8606dcb 100644
--- a/src/glsl/opt_redundant_jumps.cpp
+++ b/src/glsl/opt_redundant_jumps.cpp
@@ -28,6 +28,8 @@
 
 #include "ir.h"
 
+namespace {
+
 class redundant_jumps_visitor : public ir_hierarchical_visitor {
 public:
    redundant_jumps_visitor()
@@ -42,6 +44,8 @@ public:
    bool progress;
 };
 
+} /* unnamed namespace */
+
 /* We only care about the top level instructions, so don't descend
  * into expressions.
  */
diff --git a/src/glsl/opt_structure_splitting.cpp b/src/glsl/opt_structure_splitting.cpp
index a21238d..60eec53 100644
--- a/src/glsl/opt_structure_splitting.cpp
+++ b/src/glsl/opt_structure_splitting.cpp
@@ -38,6 +38,8 @@
 #include "ir_rvalue_visitor.h"
 #include "glsl_types.h"
 
+namespace {
+
 static bool debug = false;
 
 // XXX using variable_entry2 here to avoid collision (MSVC multiply-defined
@@ -307,6 +309,8 @@ ir_structure_splitting_visitor::visit_leave(ir_assignment *ir)
    return visit_continue;
 }
 
+} /* unnamed namespace */
+
 bool
 do_structure_splitting(exec_list *instructions)
 {
diff --git a/src/glsl/opt_swizzle_swizzle.cpp b/src/glsl/opt_swizzle_swizzle.cpp
index bc442fa..7564c6b 100644
--- a/src/glsl/opt_swizzle_swizzle.cpp
+++ b/src/glsl/opt_swizzle_swizzle.cpp
@@ -32,6 +32,8 @@
 #include "ir_optimization.h"
 #include "glsl_types.h"
 
+namespace {
+
 class ir_swizzle_swizzle_visitor : public ir_hierarchical_visitor {
 public:
    ir_swizzle_swizzle_visitor()
@@ -44,6 +46,8 @@ public:
    bool progress;
 };
 
+} /* unnamed namespace */
+
 ir_visitor_status
 ir_swizzle_swizzle_visitor::visit_enter(ir_swizzle *ir)
 {
diff --git a/src/glsl/opt_tree_grafting.cpp b/src/glsl/opt_tree_grafting.cpp
index d86eab8..25b18ea 100644
--- a/src/glsl/opt_tree_grafting.cpp
+++ b/src/glsl/opt_tree_grafting.cpp
@@ -54,6 +54,8 @@
 #include "ir_optimization.h"
 #include "glsl_types.h"
 
+namespace {
+
 static bool debug = false;
 
 class ir_tree_grafting_visitor : public ir_hierarchical_visitor {
@@ -369,6 +371,8 @@ tree_grafting_basic_block(ir_instruction *bb_first,
    }
 }
 
+} /* unnamed namespace */
+
 /**
  * Does a copy propagation pass on the code present in the instruction stream.
  */
-- 
1.7.10



More information about the mesa-dev mailing list