summaryrefslogtreecommitdiffstats
path: root/src/glsl/opt_copy_propagation_elements.cpp
Commit message (Collapse)AuthorAgeFilesLines
* glsl: Reduce memory consumption of copy propagation passes.Kenneth Graunke2015-02-171-3/+13
| | | | | | | | | | | | | | | | | | | | | | | | | opt_copy_propagation and opt_copy_propagation_elements create new ACP and Kill sets each time they enter a new control flow block. For if blocks, they also copy the entire existing ACP set contents into the new set. When we exit the control flow block, we discard the new sets. However, we weren't freeing them - so they lived on until the pass finished. This can waste a lot of memory (57MB on one pessimal shader). This patch makes the pass allocate ACP entries using this->acp as the memory context, and Kill entries out of this->kill. It also steals kill entries when moving them from the inner kill list to the parent. It then frees the lists, including their contents. v2: Move ralloc_free(this->acp) just before this->acp = orig_acp (suggested by Eric Anholt). Signed-off-by: Kenneth Graunke <kenneth@whitecape.org> Reviewed-by: Eric Anholt <eric@anholt.net> Reviewed-by: Ian Romanick <ian.d.romanick@intel.com> Cc: "10.5 10.4" <mesa-stable@lists.freedesktop.org>
* glsl: Report progress from opt_copy_propagation_elements().Kenneth Graunke2014-09-031-0/+1
| | | | | | | It's been altering the tree and reporting "false" since January 2011. Signed-off-by: Kenneth Graunke <kenneth@whitecape.org> Reviewed-by: Matt Turner <mattst88@gmail.com>
* glsl: Skip rewriting instructions in opt_cpe when unnecessary.Kenneth Graunke2014-09-031-0/+10
| | | | | | | | | | | | Previously, opt_copy_propagation_elements would always rewrite the instruction stream, even if was the same thing as before. In order to report progress correctly, we'll need to bail if the suggested replacement is identical (or equivalent) to the original code. This also introduced unnecessary noop swizzles, as far as I can tell. Signed-off-by: Kenneth Graunke <kenneth@whitecape.org> Reviewed-by: Matt Turner <mattst88@gmail.com>
* glsl: Initialize source_chan in opt_copy_propagation_elements.Kenneth Graunke2014-09-031-1/+1
| | | | | | | | | | | Previously, if chans < 4, we passed uninitialized stack garbage to the ir_swizzle constructor for the excess components. Thankfully, it ignores that data, as it's unnecessary, so no harm actually comes of it. However, it's obviously better to initialize it. Signed-off-by: Kenneth Graunke <kenneth@whitecape.org> Reviewed-by: Matt Turner <mattst88@gmail.com>
* glsl: Use typed foreach_in_list_safe instead of foreach_list_safe.Matt Turner2014-07-011-7/+3
| | | | Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
* glsl: Use typed foreach_in_list instead of foreach_list.Matt Turner2014-07-011-5/+2
| | | | Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
* glsl: Clean up "unused parameter" warningsIan Romanick2014-03-281-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ../../src/glsl/builtin_functions.cpp:72:1: warning: unused parameter 'state' [-Wunused-parameter] ../../src/glsl/ir_clone.cpp:31:1: warning: unused parameter 'ht' [-Wunused-parameter] ../../src/glsl/ir_equals.cpp:44:1: warning: unused parameter 'ir' [-Wunused-parameter] ../../src/glsl/ir_equals.cpp:50:1: warning: unused parameter 'ignore' [-Wunused-parameter] ../../src/glsl/ir_equals.cpp:68:1: warning: unused parameter 'ignore' [-Wunused-parameter] ../../src/glsl/ir_print_visitor.cpp:149:6: warning: unused parameter 'ir' [-Wunused-parameter] ../../src/glsl/ir_print_visitor.cpp:556:1: warning: unused parameter 'ir' [-Wunused-parameter] ../../src/glsl/ir_print_visitor.cpp:562:1: warning: unused parameter 'ir' [-Wunused-parameter] ../../src/glsl/link_uniforms.cpp:213:1: warning: unused parameter 'record_type' [-Wunused-parameter] ../../src/glsl/loop_analysis.cpp:225:1: warning: unused parameter 'ir' [-Wunused-parameter] ../../src/glsl/loop_unroll.cpp:73:30: warning: unused parameter 'ir' [-Wunused-parameter] ../../src/glsl/loop_unroll.cpp:79:30: warning: unused parameter 'ir' [-Wunused-parameter] ../../src/glsl/loop_unroll.cpp:85:30: warning: unused parameter 'ir' [-Wunused-parameter] ../../src/glsl/opt_copy_propagation_elements.cpp:189:1: warning: unused parameter 'ir' [-Wunused-parameter] ../../src/glsl/opt_cse.cpp:402:1: warning: unused parameter 'ir' [-Wunused-parameter] ../../src/glsl/opt_dead_code_local.cpp:117:30: warning: unused parameter 'ir' [-Wunused-parameter] ../../src/glsl/opt_redundant_jumps.cpp:53:1: warning: unused parameter 'ir' [-Wunused-parameter] ../../src/glsl/opt_vectorize.cpp:301:1: warning: unused parameter 'ir' [-Wunused-parameter] Signed-off-by: Ian Romanick <ian.d.romanick@intel.com> Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
* glsl: Use a new foreach_two_lists macro for walking two lists at once.Kenneth Graunke2014-01-131-5/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When handling function calls, we often want to walk through the list of formal parameters and list of actual parameters at the same time. (Both are guaranteed to be the same length.) Previously, we used a pattern of: exec_list_iterator 1st_iter = <1st list>.iterator(); foreach_iter(exec_list_iterator, 2nd_iter, <2nd list>) { ... 1st_iter.next(); } This was awkward, since you had to manually iterate through one of the two lists. This patch introduces a foreach_two_lists macro which safely walks through two lists at the same time, so you can simply do: foreach_two_lists(1st_node, <1st list>, 2nd_node, <2nd list>) { ... } v2: Rename macro from foreach_list2 to foreach_two_lists, as suggested by Ian Romanick. Signed-off-by: Kenneth Graunke <kenneth@whitecape.org> Reviewed-by: Matt Turner <mattst88@gmail.com> Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
* glsl: Cast ir_call parameters to ir_rvalue, not ir_instruction.Kenneth Graunke2014-01-131-1/+1
| | | | | | | | | | A function call's parameters are always rvalues. ir_rvalue may not always be a subclass of ir_instruction in the future, so we should use the right one. Signed-off-by: Kenneth Graunke <kenneth@whitecape.org> Reviewed-by: Matt Turner <mattst88@gmail.com> Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
* glsl: Convert piles of foreach_iter to the newer foreach_list macro.Kenneth Graunke2014-01-131-4/+4
| | | | | | | | | | | | | foreach_iter and exec_list_iterators have been deprecated for some time now; we just hadn't ever bothered to convert code to the newer foreach_list and foreach_list_safe macros. In these cases, we aren't editing the list, so we can use foreach_list rather than foreach_list_safe. Signed-off-by: Kenneth Graunke <kenneth@whitecape.org> Reviewed-by: Matt Turner <mattst88@gmail.com> Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
* glsl: move variables in to ir_variable::data, part ITapani Pälli2013-12-121-2/+2
| | | | | | | | | | This patch moves following bitfields in to the data structure: used, assigned, how_declared, mode, interpolation, origin_upper_left, pixel_center_integer Signed-off-by: Tapani Pälli <tapani.palli@intel.com> Reviewed-by: Paul Berry <stereotype441@gmail.com>
* glsl: Eliminate ambiguity between function ins/outs and shader ins/outsPaul Berry2013-01-241-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch replaces the three ir_variable_mode enums: - ir_var_in - ir_var_out - ir_var_inout with the following five: - ir_var_shader_in - ir_var_shader_out - ir_var_function_in - ir_var_function_out - ir_var_function_inout This eliminates a frustrating ambiguity: it used to be impossible to tell whether an ir_var_{in,out} variable was a shader in/out or a function in/out without seeing where the variable was declared in the IR. This complicated some optimization and lowering passes, and would have become a problem for implementing varying structs. In the lisp-style serialization of GLSL IR to strings performed by ir_print_visitor.cpp and ir_reader.cpp, I've retained the names "in", "out", and "inout" for function parameters, to avoid introducing code churn to the src/glsl/builtins/ir/ directory. Note: a couple of comments in the code seemed to indicate that we were planning for a possible future in which geometry shaders could have shader-scope inout variables. Our GLSL grammar rejects shader-scope inout variables, and I've been unable to find any evidence in the GLSL standards documents (or extensions) that this will ever be allowed, so I've eliminated these comments. Reviewed-by: Carl Worth <cworth@cworth.org> Reviewed-by: Jordan Justen <jordan.l.justen@intel.com> Reviewed-by: Eric Anholt <eric@anholt.net>
* glsl: Put a bunch of optimization visitors under anonymous namespaces.Eric Anholt2012-06-111-0/+4
| | | | | | | | | | | | | | | | | 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. Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
* glsl: Initialize member variable in ir_copy_propagation_elements_visitor.Vinson Lee2012-04-301-0/+1
| | | | | | | Fix uninitialized scalar field defect reported by Coverity. Signed-off-by: Vinson Lee <vlee@freedesktop.org> Reviewed-by: Eric Anholt <eric@anholt.net>
* glsl: Remove ir_call::get_callee() and set_callee().Kenneth Graunke2012-04-021-1/+1
| | | | | | | | | | | | | Previously, set_callee() performed some assertions about the type of the ir_call; protecting the bare pointer ensured these checks would be run. However, ir_call no longer has a type, so the getter and setter methods don't actually do anything useful. Remove them in favor of accessing callee directly, as is done with most other fields in our IR. Signed-off-by: Kenneth Graunke <kenneth@whitecape.org> Reviewed-by: Eric Anholt <eric@anholt.net> Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
* glsl: Fix copy_propagation_elements bug in handling self-copies.Eric Anholt2012-01-101-1/+14
| | | | | | | | | | | | | | We were doing the kill of the updated channels, then adding our copy to the list of available stuff to copy. But if the copy was updating its own source channels, we didn't notice, breaking this code: R0.xyzw = arg0 + arg1; R0.xyzw = R0.wwwx; gl_FragColor.xyzw = clamp(R0.xyzw, 0.0, 1.0); Fixes piglit glsl-copy-propagation-self-2. Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
* glsl: fix glsl optimization infinite loop from copy_propagation_elementsAndy Clayton2012-01-091-0/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | The trick was to produce an assignment in the IR along the lines of: (assign (xyzw) (var_ref R0) (swiz wwww (var_ref R0) )) which occurs only rarely even in code that looks like it should do this, because of the assignment temporaries generated in ast_to_hir. From the IR above, this optimization pass would then propagate references of R0 into R0.wwww (seems reasonable), but without this patch, a later reference of R0.wwww would see R0 first, turning that into R0.wwww.wwww, which triggered opt_swizzle_swizzle, and then we looped back to this code to do it again. Avoid that by skipping over the usual ir_rvalue visitor's ir_swizzle hook, so that we get handle_rvalue() on the ir_swizzle itself, not its referenced value. Looking at only the swizzle will always optimize away at least as much as looking at the swizzle's refererenced value. We now still claim to propagate r0.w into r0.w, but at least we don't trigger the loop. v2: Rewrite commit message (changes by anholt) Fixes piglit glsl-copy-propagation-self-1 Fixes https://bugs.freedesktop.org/show_bug.cgi?id=34006
* glsl/opt_cpe: Fix a crash when a kill kills for two reasons.Eric Anholt2011-04-131-1/+3
| | | | | | | Fixes glsl-copy-propagation-loop-2 when this optimization pass is re-enabled. Reported-by: David Lamparter <equinox@diac24.net>
* glsl/opt_cpe: Kill when the assignment isn't something we recognize.Eric Anholt2011-04-131-2/+9
| | | | | | | | | A few GLES2 tests tripped over this when using array dereferences to hit channels on the LHS (see piglit test glsl-copy-propagation-vector-indexing). We wouldn't find the ir_dereference_variable, and assume that that meant that it wasn't an assignment to a scalar/vector, and thus not notice that the variable had been changed.
* glsl: Remove extra checks for constant true assignment conditions.Eric Anholt2011-02-041-5/+2
| | | | These are already stripped by opt_constant_folding.cpp.
* glsl: Add a new opt_copy_propagation variant that does it channel-wise.Eric Anholt2011-02-041-0/+461
This patch cleans up many of the extra copies in GLSL IR introduced by i965's scalarizing passes. It doesn't result in a statistically significant performance difference on nexuiz high settings (n=3) or my demo (n=10), due to brw_fs.cpp's register coalescing covering most of those extra moves anyway. However, it does make the debug of wine's GLSL shaders much more tractable, and reduces instruction count of glsl-fs-convolution-2 from 376 to 288.