glsl: Hide many classes local to individual .cpp files in anon namespaces.

This gives the compiler the chance to inline and not export class symbols
even in the absence of LTO.  Saves about 60kb on disk.

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Ian Romanick <ian.d.romanick@.intel.com>
This commit is contained in:
Eric Anholt
2013-09-20 11:03:44 -07:00
parent 07572621bc
commit 10ef949424
33 changed files with 126 additions and 2 deletions

View File

@@ -304,6 +304,8 @@ tex3d_lod(const _mesa_glsl_parse_state *state)
/******************************************************************************/
namespace {
/**
* builtin_builder: A singleton object representing the core of the built-in
* function module.
@@ -521,6 +523,8 @@ private:
/** @} */
};
} /* anonymous namespace */
/**
* Core builtin_builder functionality:
* @{

View File

@@ -127,6 +127,8 @@
#include "program/hash_table.h"
#include "program.h"
namespace {
struct call_node : public exec_node {
class function *func;
};
@@ -222,6 +224,8 @@ public:
bool progress;
};
} /* anonymous namespace */
static void
destroy_links(exec_list *list, function *f)
{

View File

@@ -30,6 +30,8 @@
#include "ir.h"
#include "glsl_symbol_table.h"
namespace {
/**
* Visitor used to import function prototypes
*
@@ -99,6 +101,7 @@ private:
void *mem_ctx;
};
} /* anonymous namespace */
/**
* Import function prototypes from one IR tree into another

View File

@@ -28,6 +28,8 @@
const static bool debug = false;
namespace {
class ir_reader {
public:
ir_reader(_mesa_glsl_parse_state *);
@@ -66,6 +68,8 @@ private:
ir_dereference_variable *read_var_ref(s_expression *);
};
} /* anonymous namespace */
ir_reader::ir_reader(_mesa_glsl_parse_state *state) : state(state)
{
this->mem_ctx = state;

View File

@@ -42,6 +42,8 @@
#include "ir_visitor.h"
#include "glsl_types.h"
namespace {
class ir_set_program_inouts_visitor : public ir_hierarchical_visitor {
public:
ir_set_program_inouts_visitor(struct gl_program *prog, GLenum shader_type)
@@ -67,6 +69,8 @@ private:
GLenum shader_type;
};
} /* anonymous namespace */
static inline bool
is_shader_inout(ir_variable *var)
{

View File

@@ -38,6 +38,8 @@
#include "program/hash_table.h"
#include "glsl_types.h"
namespace {
class ir_validate : public ir_hierarchical_visitor {
public:
ir_validate()
@@ -81,6 +83,7 @@ public:
struct hash_table *ht;
};
} /* anonymous namespace */
ir_visitor_status
ir_validate::visit(ir_dereference_variable *ir)

View File

@@ -34,6 +34,8 @@ find_matching_signature(const char *name, const exec_list *actual_parameters,
gl_shader **shader_list, unsigned num_shaders,
bool use_builtin);
namespace {
class call_link_visitor : public ir_hierarchical_visitor {
public:
call_link_visitor(gl_shader_program *prog, gl_shader *linked,
@@ -273,6 +275,7 @@ private:
hash_table *locals;
};
} /* anonymous namespace */
/**
* Searches a list of shaders for a particular function definition

View File

@@ -29,6 +29,8 @@
#include "main/hash_table.h"
#include "program.h"
namespace {
class ubo_visitor : public program_resource_visitor {
public:
ubo_visitor(void *mem_ctx, gl_uniform_buffer_variable *variables,
@@ -147,6 +149,8 @@ private:
}
};
} /* anonymous namespace */
struct block {
const glsl_type *type;
bool has_instance_name;

View File

@@ -168,6 +168,8 @@ program_resource_visitor::visit_field(const glsl_struct_field *field)
/* empty */
}
namespace {
/**
* Class to help calculate the storage requirements for a set of uniforms
*
@@ -272,6 +274,8 @@ private:
struct string_to_uint_map *map;
};
} /* anonymous namespace */
/**
* Class to help parcel out pieces of backing storage to uniforms
*

View File

@@ -597,6 +597,7 @@ store_tfeedback_info(struct gl_context *ctx, struct gl_shader_program *prog,
return true;
}
namespace {
/**
* Data structure recording the relationship between outputs of one shader
@@ -689,6 +690,7 @@ private:
const bool consumer_is_fs;
};
} /* anonymous namespace */
varying_matches::varying_matches(bool disable_varying_packing,
bool consumer_is_fs)

View File

@@ -82,6 +82,8 @@ extern "C" {
void linker_error(gl_shader_program *, const char *, ...);
namespace {
/**
* Visitor that determines whether or not a variable is ever written.
*/
@@ -275,6 +277,7 @@ private:
bool found;
};
} /* anonymous namespace */
void
linker_error(gl_shader_program *prog, const char *fmt, ...)

View File

@@ -102,6 +102,7 @@ loop_variable_state::insert(ir_if *if_stmt)
return t;
}
namespace {
class loop_analysis : public ir_hierarchical_visitor {
public:
@@ -128,6 +129,7 @@ public:
exec_list state;
};
} /* anonymous namespace */
loop_analysis::loop_analysis(loop_state *loops)
: loops(loops), if_statement_depth(0), current_assignment(NULL)

View File

@@ -151,6 +151,7 @@ calculate_iterations(ir_rvalue *from, ir_rvalue *to, ir_rvalue *increment,
return (valid_loop) ? iter_value : -1;
}
namespace {
class loop_control_visitor : public ir_hierarchical_visitor {
public:
@@ -167,6 +168,7 @@ public:
bool progress;
};
} /* anonymous namespace */
ir_visitor_status
loop_control_visitor::visit_leave(ir_loop *ir)

View File

@@ -25,6 +25,8 @@
#include "loop_analysis.h"
#include "ir_hierarchical_visitor.h"
namespace {
class loop_unroll_visitor : public ir_hierarchical_visitor {
public:
loop_unroll_visitor(loop_state *state, unsigned max_iterations)
@@ -42,6 +44,7 @@ public:
unsigned max_iterations;
};
} /* anonymous namespace */
static bool
is_break(ir_instruction *ir)

View File

@@ -50,6 +50,8 @@
#include "ir.h"
#include "program/prog_instruction.h" /* For WRITEMASK_* */
namespace {
class lower_clip_distance_visitor : public ir_rvalue_visitor {
public:
lower_clip_distance_visitor()
@@ -81,6 +83,7 @@ public:
ir_variable *new_clip_distance_var;
};
} /* anonymous namespace */
/**
* Replace any declaration of gl_ClipDistance as an array of floats with a

View File

@@ -108,6 +108,8 @@
#include "glsl_types.h"
#include "ir.h"
namespace {
class lower_discard_visitor : public ir_hierarchical_visitor {
public:
lower_discard_visitor()
@@ -120,6 +122,7 @@ public:
bool progress;
};
} /* anonymous namespace */
bool
lower_discard(exec_list *instructions)

View File

@@ -48,6 +48,8 @@
#include "ir.h"
#include "program/hash_table.h"
namespace {
class lower_discard_flow_visitor : public ir_hierarchical_visitor {
public:
lower_discard_flow_visitor(ir_variable *discarded)
@@ -71,6 +73,8 @@ public:
void *mem_ctx;
};
} /* anonymous namespace */
ir_visitor_status
lower_discard_flow_visitor::visit_enter(ir_loop_jump *ir)
{

View File

@@ -49,6 +49,8 @@
#include "ir.h"
#include "program/hash_table.h"
namespace {
class ir_if_to_cond_assign_visitor : public ir_hierarchical_visitor {
public:
ir_if_to_cond_assign_visitor(unsigned max_depth)
@@ -76,6 +78,8 @@ public:
struct hash_table *condition_variables;
};
} /* anonymous namespace */
bool
lower_if_to_cond_assign(exec_list *instructions, unsigned max_depth)
{

View File

@@ -109,6 +109,8 @@
using namespace ir_builder;
namespace {
class lower_instructions_visitor : public ir_hierarchical_visitor {
public:
lower_instructions_visitor(unsigned lower)
@@ -133,6 +135,8 @@ private:
void ldexp_to_arith(ir_expression *);
};
} /* anonymous namespace */
/**
* Determine if a particular type of lowering should occur
*/

View File

@@ -133,6 +133,8 @@ enum jump_strength
strength_return
};
namespace {
struct block_record
{
/* minimum jump strength (of lowered IR, not pre-lowering IR)
@@ -992,6 +994,8 @@ lower_continue:
}
};
} /* anonymous namespace */
bool
do_lower_jumps(exec_list *instructions, bool pull_out_jumps, bool lower_sub_return, bool lower_main_return, bool lower_continue, bool lower_break)
{

View File

@@ -35,6 +35,8 @@
#include "ir_expression_flattening.h"
#include "glsl_types.h"
namespace {
class ir_mat_op_to_vec_visitor : public ir_hierarchical_visitor {
public:
ir_mat_op_to_vec_visitor()
@@ -63,6 +65,8 @@ public:
bool made_progress;
};
} /* anonymous namespace */
static bool
mat_op_to_vec_predicate(ir_instruction *ir)
{

View File

@@ -65,6 +65,8 @@
#include "ir_rvalue_visitor.h"
#include "program/hash_table.h"
namespace {
class flatten_named_interface_blocks_declarations : public ir_rvalue_visitor
{
public:
@@ -83,6 +85,8 @@ public:
virtual void handle_rvalue(ir_rvalue **rvalue);
};
} /* anonymous namespace */
void
flatten_named_interface_blocks_declarations::run(exec_list *instructions)
{

View File

@@ -37,6 +37,8 @@
* main() function to copy the final values to the actual shader outputs.
*/
namespace {
class output_read_remover : public ir_hierarchical_visitor {
protected:
/**
@@ -55,6 +57,8 @@ public:
virtual ir_visitor_status visit_leave(class ir_function_signature *);
};
} /* anonymous namespace */
/**
* Hash function for the output variables - computes the hash of the name.
* NOTE: We're using the name string to ensure that the hash doesn't depend

View File

@@ -148,6 +148,8 @@
#include "ir.h"
#include "ir_optimization.h"
namespace {
/**
* Visitor that performs varying packing. For each varying declared in the
* shader, this visitor determines whether it needs to be packed. If so, it
@@ -230,6 +232,8 @@ private:
exec_list *out_instructions;
};
} /* anonymous namespace */
lower_packed_varyings_visitor::lower_packed_varyings_visitor(
void *mem_ctx, unsigned location_base, unsigned locations_used,
ir_variable_mode mode, unsigned gs_input_vertices,

View File

@@ -37,6 +37,8 @@
#include "ir.h"
namespace {
class lower_texture_projection_visitor : public ir_hierarchical_visitor {
public:
lower_texture_projection_visitor()
@@ -49,6 +51,8 @@ public:
bool progress;
};
} /* anonymous namespace */
ir_visitor_status
lower_texture_projection_visitor::visit_leave(ir_texture *ir)
{

View File

@@ -122,6 +122,7 @@ is_array_or_matrix(const ir_rvalue *ir)
return (ir->type->is_array() || ir->type->is_matrix());
}
namespace {
/**
* Replace a dereference of a variable with a specified r-value
*
@@ -512,6 +513,8 @@ public:
}
};
} /* anonymous namespace */
bool
lower_variable_index_to_cond_assign(exec_list *instructions,
bool lower_input,

View File

@@ -41,6 +41,8 @@
#include "ir_optimization.h"
#include "glsl_types.h"
namespace {
/**
* Visitor class for replacing expressions with ir_constant values.
*/
@@ -69,6 +71,8 @@ public:
bool progress;
};
} /* anonymous namespace */
ir_rvalue *
ir_vec_index_to_cond_assign_visitor::convert_vec_index_to_cond_assign(void *mem_ctx,
ir_rvalue *orig_vector,

View File

@@ -39,6 +39,8 @@
* Visitor class for replacing expressions with ir_constant values.
*/
namespace {
class ir_vec_index_to_swizzle_visitor : public ir_hierarchical_visitor {
public:
ir_vec_index_to_swizzle_visitor()
@@ -58,6 +60,8 @@ public:
bool progress;
};
} /* anonymous namespace */
ir_rvalue *
ir_vec_index_to_swizzle_visitor::convert_vector_extract_to_swizzle(ir_rvalue *ir)
{

View File

@@ -31,6 +31,8 @@
#include "ir.h"
#include "ir_rvalue_visitor.h"
namespace {
class lower_vector_visitor : public ir_rvalue_visitor {
public:
lower_vector_visitor() : progress(false)
@@ -48,6 +50,8 @@ public:
bool progress;
};
} /* anonymous namespace */
/**
* Determine if an IR expression tree looks like an extended swizzle
*

View File

@@ -27,6 +27,8 @@
using namespace ir_builder;
namespace {
class vector_insert_visitor : public ir_rvalue_visitor {
public:
vector_insert_visitor(bool lower_nonconstant_index)
@@ -48,6 +50,7 @@ public:
bool lower_nonconstant_index;
};
} /* anonymous namespace */
void
vector_insert_visitor::handle_rvalue(ir_rvalue **rv)

View File

@@ -40,6 +40,8 @@
static bool debug = false;
namespace {
namespace opt_array_splitting {
class variable_entry : public exec_node
@@ -77,6 +79,7 @@ public:
};
} /* namespace */
using namespace opt_array_splitting;
/**
@@ -112,6 +115,8 @@ public:
void *mem_ctx;
};
} /* namespace */
variable_entry *
ir_array_reference_visitor::get_variable_entry(ir_variable *var)
{

View File

@@ -52,6 +52,7 @@
#include "glsl_types.h"
#include "link_varyings.h"
namespace {
/**
* This obtains detailed information about built-in varyings from shader code.
@@ -397,6 +398,7 @@ private:
ir_variable *new_fog;
};
} /* anonymous namespace */
static void
lower_texcoord_array(exec_list *ir, const varying_info_visitor *info)

View File

@@ -57,11 +57,13 @@ extern "C" {
#include "program/sampler.h"
}
static int swizzle_for_size(int size);
namespace {
class src_reg;
class dst_reg;
static int swizzle_for_size(int size);
/**
* This struct is a corresponding struct to Mesa prog_src_register, with
* wider fields.
@@ -129,6 +131,8 @@ public:
src_reg *reladdr;
};
} /* anonymous namespace */
src_reg::src_reg(dst_reg reg)
{
this->file = reg.file;
@@ -147,6 +151,8 @@ dst_reg::dst_reg(src_reg reg)
this->reladdr = reg.reladdr;
}
namespace {
class ir_to_mesa_instruction : public exec_node {
public:
DECLARE_RZALLOC_CXX_OPERATORS(ir_to_mesa_instruction)
@@ -316,6 +322,8 @@ public:
void *mem_ctx;
};
} /* anonymous namespace */
static src_reg undef_src = src_reg(PROGRAM_UNDEFINED, 0, NULL);
static dst_reg undef_dst = dst_reg(PROGRAM_UNDEFINED, SWIZZLE_NOOP);
@@ -2407,6 +2415,8 @@ print_program(struct prog_instruction *mesa_instructions,
}
}
namespace {
class add_uniform_to_shader : public program_resource_visitor {
public:
add_uniform_to_shader(struct gl_shader_program *shader_program,
@@ -2436,6 +2446,8 @@ private:
gl_shader_type shader_type;
};
} /* anonymous namespace */
void
add_uniform_to_shader::visit_field(const glsl_type *type, const char *name,
bool row_major)