[Mesa-dev] [PATCH v2] glsl: Enable debug prints for do_common_optimization
Timothy Arceri
timothy.arceri at collabora.com
Fri Jan 22 02:53:03 PST 2016
On Thu, 2016-01-21 at 23:35 -0800, Jordan Justen wrote:
> Signed-off-by: Jordan Justen <jordan.l.justen at intel.com>
> ---
>
> I tested a release build. I think v1 produced comparable code to
> before the patch, but it was a bit larger. I found that this v2 code
> would produce identical code to our current code for release builds.
>
> Timothy, should I add your r-b for v2?
Yes, looks good to me.
>
> src/glsl/glsl_parser_extras.cpp | 81 +++++++++++++++++++++++++------
> ----------
> 1 file changed, 49 insertions(+), 32 deletions(-)
>
> diff --git a/src/glsl/glsl_parser_extras.cpp
> b/src/glsl/glsl_parser_extras.cpp
> index 1d74db5..1c1bf78 100644
> --- a/src/glsl/glsl_parser_extras.cpp
> +++ b/src/glsl/glsl_parser_extras.cpp
> @@ -1864,59 +1864,76 @@ do_common_optimization(exec_list *ir, bool
> linked,
> const struct gl_shader_compiler_options
> *options,
> bool native_integers)
> {
> + const bool debug = false;
> GLboolean progress = GL_FALSE;
>
> - progress = lower_instructions(ir, SUB_TO_ADD_NEG) || progress;
> +#define OPT(PASS, ...) do { \
> + if (debug) { \
> + printf("START GLSL optimization %s\n", #PASS); \
> + const bool opt_progress = PASS(__VA_ARGS__); \
> + progress = opt_progress || progress; \
> + if (opt_progress) \
> + _mesa_print_ir(stdout, ir, NULL); \
> + printf("GLSL optimization %s: %s progress\n", \
> + #PASS, opt_progress ? "made" : "no"); \
> + } else { \
> + progress = PASS(__VA_ARGS__) || progress; \
> + } \
> + } while (false)
> +
> + OPT(lower_instructions, ir, SUB_TO_ADD_NEG);
>
> if (linked) {
> - progress = do_function_inlining(ir) || progress;
> - progress = do_dead_functions(ir) || progress;
> - progress = do_structure_splitting(ir) || progress;
> + OPT(do_function_inlining, ir);
> + OPT(do_dead_functions, ir);
> + OPT(do_structure_splitting, ir);
> }
> - progress = do_if_simplification(ir) || progress;
> - progress = opt_flatten_nested_if_blocks(ir) || progress;
> - progress = opt_conditional_discard(ir) || progress;
> - progress = do_copy_propagation(ir) || progress;
> - progress = do_copy_propagation_elements(ir) || progress;
> + OPT(do_if_simplification, ir);
> + OPT(opt_flatten_nested_if_blocks, ir);
> + OPT(opt_conditional_discard, ir);
> + OPT(do_copy_propagation, ir);
> + OPT(do_copy_propagation_elements, ir);
>
> if (options->OptimizeForAOS && !linked)
> - progress = opt_flip_matrices(ir) || progress;
> + OPT(opt_flip_matrices, ir);
>
> if (linked && options->OptimizeForAOS) {
> - progress = do_vectorize(ir) || progress;
> + OPT(do_vectorize, ir);
> }
>
> if (linked)
> - progress = do_dead_code(ir, uniform_locations_assigned) ||
> progress;
> + OPT(do_dead_code, ir, uniform_locations_assigned);
> else
> - progress = do_dead_code_unlinked(ir) || progress;
> - progress = do_dead_code_local(ir) || progress;
> - progress = do_tree_grafting(ir) || progress;
> - progress = do_constant_propagation(ir) || progress;
> + OPT(do_dead_code_unlinked, ir);
> + OPT(do_dead_code_local, ir);
> + OPT(do_tree_grafting, ir);
> + OPT(do_constant_propagation, ir);
> if (linked)
> - progress = do_constant_variable(ir) || progress;
> + OPT(do_constant_variable, ir);
> else
> - progress = do_constant_variable_unlinked(ir) || progress;
> - progress = do_constant_folding(ir) || progress;
> - progress = do_minmax_prune(ir) || progress;
> - progress = do_rebalance_tree(ir) || progress;
> - progress = do_algebraic(ir, native_integers, options) ||
> progress;
> - progress = do_lower_jumps(ir) || progress;
> - progress = do_vec_index_to_swizzle(ir) || progress;
> - progress = lower_vector_insert(ir, false) || progress;
> - progress = do_swizzle_swizzle(ir) || progress;
> - progress = do_noop_swizzle(ir) || progress;
> -
> - progress = optimize_split_arrays(ir, linked) || progress;
> - progress = optimize_redundant_jumps(ir) || progress;
> + OPT(do_constant_variable_unlinked, ir);
> + OPT(do_constant_folding, ir);
> + OPT(do_minmax_prune, ir);
> + OPT(do_rebalance_tree, ir);
> + OPT(do_algebraic, ir, native_integers, options);
> + OPT(do_lower_jumps, ir);
> + OPT(do_vec_index_to_swizzle, ir);
> + OPT(lower_vector_insert, ir, false);
> + OPT(do_swizzle_swizzle, ir);
> + OPT(do_noop_swizzle, ir);
> +
> + OPT(optimize_split_arrays, ir, linked);
> + OPT(optimize_redundant_jumps, ir);
>
> loop_state *ls = analyze_loop_variables(ir);
> if (ls->loop_found) {
> - progress = set_loop_controls(ir, ls) || progress;
> - progress = unroll_loops(ir, ls, options) || progress;
> + OPT(set_loop_controls, ir, ls);
> + OPT(unroll_loops, ir, ls, options);
> }
> delete ls;
>
> +#undef OPT
> +
> return progress;
> }
>
More information about the mesa-dev
mailing list