diff options
author | marha <marha@users.sourceforge.net> | 2011-08-29 14:48:31 +0200 |
---|---|---|
committer | marha <marha@users.sourceforge.net> | 2011-08-29 14:48:31 +0200 |
commit | 924a6ffc82a7af0ca311af711ea2cf973dc6ff15 (patch) | |
tree | f5ee6d0aaf321029a4abb12c3c051c0434dde308 /mesalib/src/glsl/lower_if_to_cond_assign.cpp | |
parent | 8e57a7fcbf736b8e437baf0bbccb93095d97617f (diff) | |
parent | 01df5d59e56a1b060568f8cad2e89f7eea22fc70 (diff) | |
download | vcxsrv-924a6ffc82a7af0ca311af711ea2cf973dc6ff15.tar.gz vcxsrv-924a6ffc82a7af0ca311af711ea2cf973dc6ff15.tar.bz2 vcxsrv-924a6ffc82a7af0ca311af711ea2cf973dc6ff15.zip |
Merge remote-tracking branch 'origin/released'
Conflicts:
apps/xwininfo/configure.ac
apps/xwininfo/xwininfo.c
libX11/configure.ac
libX11/specs/libX11/AppC.xml
libX11/specs/libX11/AppD.xml
libX11/specs/libX11/CH03.xml
libX11/specs/libX11/CH04.xml
libX11/specs/libX11/CH05.xml
libX11/specs/libX11/CH06.xml
libX11/specs/libX11/CH07.xml
libX11/specs/libX11/CH08.xml
libX11/specs/libX11/CH09.xml
libX11/specs/libX11/CH11.xml
libX11/specs/libX11/CH12.xml
libX11/specs/libX11/CH13.xml
libX11/specs/libX11/CH14.xml
libX11/specs/libX11/CH15.xml
libX11/specs/libX11/CH16.xml
libxcb/configure.ac
libxcb/src/c_client.py
libxcb/src/xcb_auth.c
libxcb/src/xcb_util.c
mesalib/common.py
mesalib/configs/linux-dri
mesalib/docs/GL3.txt
mesalib/docs/download.html
mesalib/docs/install.html
mesalib/include/GL/internal/dri_interface.h
mesalib/scons/custom.py
mesalib/scons/gallium.py
mesalib/src/gallium/auxiliary/util/u_math.h
mesalib/src/gallium/auxiliary/util/u_vbuf_mgr.c
mesalib/src/glsl/ast_function.cpp
mesalib/src/glsl/ast_to_hir.cpp
mesalib/src/glsl/glcpp/glcpp-parse.y
mesalib/src/glsl/glsl_parser_extras.cpp
mesalib/src/glsl/glsl_parser_extras.h
mesalib/src/glsl/ir.cpp
mesalib/src/glsl/ir.h
mesalib/src/glsl/ir_clone.cpp
mesalib/src/glsl/ir_print_visitor.cpp
mesalib/src/glsl/ir_validate.cpp
mesalib/src/glsl/linker.cpp
mesalib/src/glsl/main.cpp
mesalib/src/glsl/opt_tree_grafting.cpp
mesalib/src/mapi/glapi/gen/Makefile
mesalib/src/mapi/glapi/gen/gl_XML.py
mesalib/src/mapi/glapi/gen/gl_table.py
mesalib/src/mapi/glapi/glapi_mapi_tmp.h
mesalib/src/mapi/glapi/glapi_sparc.S
mesalib/src/mapi/glapi/glapi_x86-64.S
mesalib/src/mapi/glapi/glapi_x86.S
mesalib/src/mapi/glapi/glapitemp.h
mesalib/src/mapi/glapi/glprocs.h
mesalib/src/mapi/mapi/u_thread.c
mesalib/src/mapi/mapi/u_thread.h
mesalib/src/mesa/SConscript
mesalib/src/mesa/drivers/common/driverfuncs.c
mesalib/src/mesa/drivers/windows/gldirect/dglcontext.c
mesalib/src/mesa/main/api_arrayelt.c
mesalib/src/mesa/main/bufferobj.c
mesalib/src/mesa/main/compiler.h
mesalib/src/mesa/main/dd.h
mesalib/src/mesa/main/dlist.c
mesalib/src/mesa/main/enums.c
mesalib/src/mesa/main/es_generator.py
mesalib/src/mesa/main/fbobject.c
mesalib/src/mesa/main/imports.h
mesalib/src/mesa/main/mtypes.h
mesalib/src/mesa/main/pbo.c
mesalib/src/mesa/main/remap_helper.h
mesalib/src/mesa/main/shared.c
mesalib/src/mesa/main/texgetimage.c
mesalib/src/mesa/main/teximage.c
mesalib/src/mesa/main/uniforms.c
mesalib/src/mesa/program/ir_to_mesa.cpp
mesalib/src/mesa/program/prog_optimize.c
mesalib/src/mesa/program/register_allocate.c
mesalib/src/mesa/program/register_allocate.h
mesalib/src/mesa/sources.mak
mesalib/src/mesa/state_tracker/st_cb_bufferobjects.c
mesalib/src/mesa/state_tracker/st_cb_texture.c
mesalib/src/mesa/state_tracker/st_texture.h
mesalib/src/mesa/swrast/s_context.c
mesalib/src/mesa/tnl/t_draw.c
mesalib/src/mesa/vbo/vbo_exec_array.c
mesalib/src/mesa/vbo/vbo_save_api.c
pixman/pixman/pixman-arm-common.h
pixman/pixman/pixman-fast-path.c
pixman/pixman/pixman-inlines.h
pixman/test/Makefile.am
pixman/test/utils.c
pixman/test/utils.h
xorg-server/configure.ac
xorg-server/fb/fbblt.c
xorg-server/hw/xquartz/darwin.c
xorg-server/xkeyboard-config/symbols/de
Diffstat (limited to 'mesalib/src/glsl/lower_if_to_cond_assign.cpp')
-rw-r--r-- | mesalib/src/glsl/lower_if_to_cond_assign.cpp | 141 |
1 files changed, 96 insertions, 45 deletions
diff --git a/mesalib/src/glsl/lower_if_to_cond_assign.cpp b/mesalib/src/glsl/lower_if_to_cond_assign.cpp index b637eb4fe..7b89a1539 100644 --- a/mesalib/src/glsl/lower_if_to_cond_assign.cpp +++ b/mesalib/src/glsl/lower_if_to_cond_assign.cpp @@ -47,6 +47,7 @@ #include "glsl_types.h" #include "ir.h" +#include "program/hash_table.h" class ir_if_to_cond_assign_visitor : public ir_hierarchical_visitor { public: @@ -55,6 +56,14 @@ public: this->progress = false; this->max_depth = max_depth; this->depth = 0; + + this->condition_variables = hash_table_ctor(0, hash_table_pointer_hash, + hash_table_pointer_compare); + } + + ~ir_if_to_cond_assign_visitor() + { + hash_table_dtor(this->condition_variables); } ir_visitor_status visit_enter(ir_if *); @@ -63,6 +72,8 @@ public: bool progress; unsigned max_depth; unsigned depth; + + struct hash_table *condition_variables; }; bool @@ -94,40 +105,43 @@ check_control_flow(ir_instruction *ir, void *data) void move_block_to_cond_assign(void *mem_ctx, - ir_if *if_ir, ir_variable *cond_var, bool then) + ir_if *if_ir, ir_rvalue *cond_expr, + exec_list *instructions, + struct hash_table *ht) { - exec_list *instructions; - - if (then) { - instructions = &if_ir->then_instructions; - } else { - instructions = &if_ir->else_instructions; - } - - foreach_iter(exec_list_iterator, iter, *instructions) { - ir_instruction *ir = (ir_instruction *)iter.get(); + foreach_list_safe(node, instructions) { + ir_instruction *ir = (ir_instruction *) node; if (ir->ir_type == ir_type_assignment) { ir_assignment *assign = (ir_assignment *)ir; - ir_rvalue *cond_expr; - ir_dereference *deref = new(mem_ctx) ir_dereference_variable(cond_var); - - if (then) { - cond_expr = deref; - } else { - cond_expr = new(mem_ctx) ir_expression(ir_unop_logic_not, - glsl_type::bool_type, - deref, - NULL); - } - if (!assign->condition) { - assign->condition = cond_expr; - } else { - assign->condition = new(mem_ctx) ir_expression(ir_binop_logic_and, - glsl_type::bool_type, - cond_expr, - assign->condition); + if (hash_table_find(ht, assign) == NULL) { + hash_table_insert(ht, assign, assign); + + /* If the LHS of the assignment is a condition variable that was + * previously added, insert an additional assignment of false to + * the variable. + */ + const bool assign_to_cv = + hash_table_find(ht, assign->lhs->variable_referenced()) != NULL; + + if (!assign->condition) { + if (assign_to_cv) { + assign->rhs = + new(mem_ctx) ir_expression(ir_binop_logic_and, + glsl_type::bool_type, + cond_expr->clone(mem_ctx, NULL), + assign->rhs); + } else { + assign->condition = cond_expr->clone(mem_ctx, NULL); + } + } else { + assign->condition = + new(mem_ctx) ir_expression(ir_binop_logic_and, + glsl_type::bool_type, + cond_expr->clone(mem_ctx, NULL), + assign->condition); + } } } @@ -142,6 +156,7 @@ ir_if_to_cond_assign_visitor::visit_enter(ir_if *ir) { (void) ir; this->depth++; + return visit_continue; } @@ -153,9 +168,7 @@ ir_if_to_cond_assign_visitor::visit_leave(ir_if *ir) return visit_continue; bool found_control_flow = false; - ir_variable *cond_var; ir_assignment *assign; - ir_dereference_variable *deref; /* Check that both blocks don't contain anything we can't support. */ foreach_iter(exec_list_iterator, then_iter, ir->then_instructions) { @@ -171,24 +184,62 @@ ir_if_to_cond_assign_visitor::visit_leave(ir_if *ir) void *mem_ctx = ralloc_parent(ir); - /* Store the condition to a variable so the assignment conditions are - * simpler. + /* Store the condition to a variable. Move all of the instructions from + * the then-clause of the if-statement. Use the condition variable as a + * condition for all assignments. */ - cond_var = new(mem_ctx) ir_variable(glsl_type::bool_type, - "if_to_cond_assign_condition", - ir_var_temporary); - ir->insert_before(cond_var); - - deref = new(mem_ctx) ir_dereference_variable(cond_var); - assign = new(mem_ctx) ir_assignment(deref, - ir->condition, NULL); + ir_variable *const then_var = + new(mem_ctx) ir_variable(glsl_type::bool_type, + "if_to_cond_assign_then", + ir_var_temporary); + ir->insert_before(then_var); + + ir_dereference_variable *then_cond = + new(mem_ctx) ir_dereference_variable(then_var); + + assign = new(mem_ctx) ir_assignment(then_cond, ir->condition); ir->insert_before(assign); - /* Now, move all of the instructions out of the if blocks, putting - * conditions on assignments. + move_block_to_cond_assign(mem_ctx, ir, then_cond, + &ir->then_instructions, + this->condition_variables); + + /* Add the new condition variable to the hash table. This allows us to + * find this variable when lowering other (enclosing) if-statements. + */ + hash_table_insert(this->condition_variables, then_var, then_var); + + /* If there are instructions in the else-clause, store the inverse of the + * condition to a variable. Move all of the instructions from the + * else-clause if the if-statement. Use the (inverse) condition variable + * as a condition for all assignments. */ - move_block_to_cond_assign(mem_ctx, ir, cond_var, true); - move_block_to_cond_assign(mem_ctx, ir, cond_var, false); + if (!ir->else_instructions.is_empty()) { + ir_variable *const else_var = + new(mem_ctx) ir_variable(glsl_type::bool_type, + "if_to_cond_assign_else", + ir_var_temporary); + ir->insert_before(else_var); + + ir_dereference_variable *else_cond = + new(mem_ctx) ir_dereference_variable(else_var); + + ir_rvalue *inverse = + new(mem_ctx) ir_expression(ir_unop_logic_not, + then_cond->clone(mem_ctx, NULL)); + + assign = new(mem_ctx) ir_assignment(else_cond, inverse); + ir->insert_before(assign); + + move_block_to_cond_assign(mem_ctx, ir, else_cond, + &ir->else_instructions, + this->condition_variables); + + /* Add the new condition variable to the hash table. This allows us to + * find this variable when lowering other (enclosing) if-statements. + */ + hash_table_insert(this->condition_variables, else_var, else_var); + } ir->remove(); |