summaryrefslogtreecommitdiffstats
path: root/src/glsl/loop_analysis.cpp
Commit message (Collapse)AuthorAgeFilesLines
* glsl/loops: Move some analysis from loop_controls to loop_analysis.Paul Berry2013-12-091-0/+69
| | | | | | | | | | | | | | | | | | | | Previously, the sole responsibility of loop_analysis was to find all the variables referenced in the loop that are either loop constant or induction variables, and find all of the simple if statements that might terminate the loop. The remainder of the analysis necessary to determine how many times a loop executed was performed by loop_controls. This patch makes loop_analysis also responsible for determining the number of iterations after which each loop terminator will terminate the loop, and for figuring out which terminator will terminate the loop first (I'm calling this the "limiting terminator"). This will allow loop unrolling to make use of information that was previously only visible from loop_controls, namely the identity of the limiting terminator. Reviewed-by: Ian Romanick <[email protected]>
* glsl/loops: Allocate loop_terminator using new(mem_ctx) syntax.Paul Berry2013-12-091-1/+1
| | | | | | | | Patches to follow will introduce code into the loop_terminator constructor. Allocating loop_terminator using new(mem_ctx) syntax will ensure that the constructor runs. Reviewed-by: Ian Romanick <[email protected]>
* glsl/loops: Remove unused fields iv_scale and biv from loop_variable class.Paul Berry2013-12-091-2/+0
| | | | | | | | | These fields were part of some planned optimizations that never materialized. Remove them for now to simplify things; if we ever get round to adding the optimizations that would require them, we can always re-introduce them. Reviewed-by: Ian Romanick <[email protected]>
* glsl: In loop analysis, handle unconditional second assignment.Paul Berry2013-12-091-3/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Previously, loop analysis would set this->conditional_or_nested_assignment based on the most recently visited assignment to the variable. As a result, if a vaiable was assigned to more than once in a loop, the flag might be set incorrectly. For example, in a loop like this: int x; for (int i = 0; i < 3; i++) { if (i == 0) x = 10; ... x = 20; ... } loop analysis would have incorrectly concluded that all assignments to x were unconditional. In practice this was a benign bug, because conditional_or_nested_assignment is only used to disqualify variables from being considered as loop induction variables or loop constant variables, and having multiple assignments also disqualifies a variable from being considered as either of those things. Still, we should get the analysis correct to avoid future confusion. Reviewed-by: Jordan Justen <[email protected]> Reviewed-by: Ian Romanick <[email protected]>
* glsl: Fix handling of function calls inside nested loops.Paul Berry2013-12-091-7/+7
| | | | | | | | | | | | | | | | | | | | | Previously, when visiting an ir_call, loop analysis would only mark the innermost enclosing loop as containing a call. As a result, when encountering a loop like this: for (i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { foo(); } } it would incorrectly conclude that the outer loop ran three times. (This is not certain; if foo() modifies i, then the outer loop might run more or fewer times). Fixes piglit test "vs-call-in-nested-loop.shader_test". Reviewed-by: Jordan Justen <[email protected]> Reviewed-by: Ian Romanick <[email protected]>
* glsl: Fix loop analysis of nested loops.Paul Berry2013-12-091-13/+21
| | | | | | | | | | | | | | | | | | | | Previously, when visiting a variable dereference, loop analysis would only consider its effect on the innermost enclosing loop. As a result, when encountering a loop like this: for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { ... i = 2; } } it would incorrectly conclude that the outer loop ran three times. Fixes piglit test "vs-inner-loop-modifies-outer-loop-var.shader_test". Reviewed-by: Jordan Justen <[email protected]> Reviewed-by: Ian Romanick <[email protected]>
* glsl: Extract functions from loop_analysis::visit(ir_dereference_variable *).Paul Berry2013-12-091-25/+67
| | | | | | | This function is about to get more complex. Reviewed-by: Jordan Justen <[email protected]> Reviewed-by: Ian Romanick <[email protected]>
* glsl: Hide many classes local to individual .cpp files in anon namespaces.Eric Anholt2013-09-231-0/+2
| | | | | | | | 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 <[email protected]> Reviewed-by: Ian Romanick <[email protected]>
* glsl: Handle empty if statement encountered during loop analysis.Paul Berry2013-07-251-1/+2
| | | | | | | | | | | | | | | | | | | | | The is_loop_terminator() function was asserting that the following kind of if statement could never occur: if (...) { } else { } (presumably based on the assumption that such an if statement would be eliminated by previous optimization stages). But that isn't the case--it's possible that previous optimization stages might simplify more complex code down to this empty if statement, in which case it won't be eliminated until the next time through the optimization loop. So is_loop_terminator() needs to handle it. Fortunately it's easy to handle--it's not a loop terminator because it does nothing. Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=64330 CC: [email protected] Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Change loop_analysis to not look like a resource leakIan Romanick2013-02-071-7/+6
| | | | | | | | | | | | | | | Previously the loop_state was allocated in the loop_analysis constructor, but not freed in the (nonexistent) destructor. Moving the allocation of the loop_state makes this code appear less sketchy. Either way, there is no actual leak. The loop_state is freed by the single caller of analyze_loop_variables. Signed-off-by: Ian Romanick <[email protected]> Cc: Dave Airlie <[email protected]> Reviewed-by: Matt Turner <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]> Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=57753
* glsl: Don't trust loop analysis in the presence of function calls.Kenneth Graunke2012-04-021-0/+28
| | | | | | | | | | | | | | | | | | | | | Function calls may have side effects that alter variables used inside the loop. In the fragment shader, they may even terminate the shader. This means our analysis about loop-constant or induction variables may be completely wrong. In general it's impossible to determine whether they actually do or not (due to the halting problem), so we'd need to perform conservative static analysis. For now, it's not worth the complexity: most functions will be inlined, at which point we can unroll them successfully. Fixes Piglit tests: - shaders/glsl-fs-unroll-out-param - shaders/glsl-fs-unroll-side-effect NOTE: This is a candidate for release branches. Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Ian Romanick <[email protected]>
* Convert everything from the talloc API to the ralloc API.Kenneth Graunke2011-01-311-7/+7
|
* glsl: Skip the rest of loop unrolling if no loops were found.Eric Anholt2011-01-181-0/+3
| | | | | Shaves 1.6% (+/- 1.0%) off of ff_fragment_shader glean texCombine time (n=5).
* glsl: Free the loop state context when we free the loop state.Eric Anholt2010-11-111-0/+1
| | | | | | | | Since this was talloced off of NULL instead of the compile state, it was a real leak over the course of the program. Noticed with valgrind --leak-check=full --show-reachable=yes. We should really change these passes to generally get the compile context as an argument so simple mistakes like this stop mattering.
* glsl2: Early return with visit_continue in ↵Ian Romanick2010-09-071-1/+1
| | | | | | | | | | | | loop_analysis::visit(ir_dereference_variable *) Returning early with visit_continue_with_parent prevented the then-statements and else-statements of if-statements such as the following from being processed: if (some_var) { ... } else { ... } Fixes piglit test case glsl-fs-loop-nested-if and bugzilla #30030.
* glsl2: Use as_constant some places instead of constant_expression_valueIan Romanick2010-09-031-1/+1
| | | | | | | | | | | The places where constant_expression_value are still used in loop analysis are places where a new expression tree is created and constant folding won't have happened. This is used, for example, when we try to determine the maximal loop iteration count. Based on review comments by Eric. "...rely on constant folding to have done its job, instead of going all through the subtree again when it wasn't a constant."
* glsl2: Track the number of ir_loop_jump instructions that are in a loopIan Romanick2010-09-031-0/+17
|
* glsl2: Add module to analyze variables used in loopsIan Romanick2010-09-031-0/+479
This is the first step eventually leading to loop unrolling.