2010-05-05 10:37:25 -07:00
|
|
|
/*
|
|
|
|
* Copyright © 2010 Intel Corporation
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice (including the next
|
|
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
* Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2010-07-26 22:50:29 -07:00
|
|
|
* \file ir_optimization.h
|
2010-05-05 10:37:25 -07:00
|
|
|
*
|
|
|
|
* Prototypes for optimization passes to be called by the compiler and drivers.
|
|
|
|
*/
|
|
|
|
|
2010-11-18 17:54:07 -08:00
|
|
|
/* Operations for lower_instructions() */
|
2011-08-27 18:32:58 -05:00
|
|
|
#define SUB_TO_ADD_NEG 0x01
|
|
|
|
#define DIV_TO_MUL_RCP 0x02
|
|
|
|
#define EXP_TO_EXP2 0x04
|
|
|
|
#define POW_TO_EXP2 0x08
|
|
|
|
#define LOG_TO_LOG2 0x10
|
|
|
|
#define MOD_TO_FRACT 0x20
|
|
|
|
#define INT_DIV_TO_MUL_RCP 0x40
|
2012-12-01 23:49:26 -08:00
|
|
|
#define LRP_TO_ARITH 0x80
|
2013-04-09 22:43:05 -07:00
|
|
|
#define BITFIELD_INSERT_TO_BFM_BFI 0x100
|
2010-11-18 17:54:07 -08:00
|
|
|
|
2012-11-19 15:15:32 -08:00
|
|
|
/**
|
|
|
|
* \see class lower_packing_builtins_visitor
|
|
|
|
*/
|
|
|
|
enum lower_packing_builtins_op {
|
|
|
|
LOWER_PACK_UNPACK_NONE = 0x0000,
|
|
|
|
|
|
|
|
LOWER_PACK_SNORM_2x16 = 0x0001,
|
|
|
|
LOWER_UNPACK_SNORM_2x16 = 0x0002,
|
|
|
|
|
|
|
|
LOWER_PACK_UNORM_2x16 = 0x0004,
|
|
|
|
LOWER_UNPACK_UNORM_2x16 = 0x0008,
|
|
|
|
|
|
|
|
LOWER_PACK_HALF_2x16 = 0x0010,
|
|
|
|
LOWER_UNPACK_HALF_2x16 = 0x0020,
|
|
|
|
|
|
|
|
LOWER_PACK_HALF_2x16_TO_SPLIT = 0x0040,
|
|
|
|
LOWER_UNPACK_HALF_2x16_TO_SPLIT = 0x0080,
|
2013-01-21 15:31:00 -08:00
|
|
|
|
|
|
|
LOWER_PACK_SNORM_4x8 = 0x0100,
|
|
|
|
LOWER_UNPACK_SNORM_4x8 = 0x0200,
|
|
|
|
|
|
|
|
LOWER_PACK_UNORM_4x8 = 0x0400,
|
|
|
|
LOWER_UNPACK_UNORM_4x8 = 0x0800,
|
2012-11-19 15:15:32 -08:00
|
|
|
};
|
|
|
|
|
2011-10-21 11:17:39 -07:00
|
|
|
bool do_common_optimization(exec_list *ir, bool linked,
|
|
|
|
bool uniform_locations_assigned,
|
|
|
|
unsigned max_unroll_iterations);
|
2010-08-10 13:06:49 -07:00
|
|
|
|
2010-07-26 22:50:29 -07:00
|
|
|
bool do_algebraic(exec_list *instructions);
|
2010-05-05 11:45:30 -07:00
|
|
|
bool do_constant_folding(exec_list *instructions);
|
2010-05-12 12:10:41 -07:00
|
|
|
bool do_constant_variable(exec_list *instructions);
|
|
|
|
bool do_constant_variable_unlinked(exec_list *instructions);
|
2010-05-05 11:45:30 -07:00
|
|
|
bool do_copy_propagation(exec_list *instructions);
|
2011-01-25 10:28:13 +10:00
|
|
|
bool do_copy_propagation_elements(exec_list *instructions);
|
2010-08-09 17:03:46 -07:00
|
|
|
bool do_constant_propagation(exec_list *instructions);
|
2011-10-21 11:17:39 -07:00
|
|
|
bool do_dead_code(exec_list *instructions, bool uniform_locations_assigned);
|
2010-05-05 10:37:25 -07:00
|
|
|
bool do_dead_code_local(exec_list *instructions);
|
2010-07-27 11:28:26 -07:00
|
|
|
bool do_dead_code_unlinked(exec_list *instructions);
|
2010-08-05 10:09:12 -07:00
|
|
|
bool do_dead_functions(exec_list *instructions);
|
2010-05-05 11:45:30 -07:00
|
|
|
bool do_function_inlining(exec_list *instructions);
|
glsl: add continue/break/return unification/elimination pass (v2)
Changes in v2:
- Base class renamed to ir_control_flow_visitor
- Tried to comply with coding style
This is a new pass that supersedes ir_if_return and "lowers" jumps
to if/else structures.
Currently it causes no regressions on softpipe and nv40, but I'm not sure
whether the piglit glsl tests are thorough enough, so consider this
experimental.
It can be asked to:
1. Pull jumps out of ifs where possible
2. Remove all "continue"s, replacing them with an "execute flag"
3. Replace all "break" with a single conditional one at the end of the loop
4. Replace all "return"s with a single return at the end of the function,
for the main function and/or other functions
This gives several great benefits:
1. All functions can be inlined after this pass
2. nv40 and other pre-DX10 chips without "continue" can be supported
3. nv30 and other pre-DX10 chips with no control flow at all are better supported
Note that for full effect we should also teach the unroller to unroll
loops with a fixed maximum number of iterations but with the canonical
conditional "break" that this pass will insert if asked to.
Continues are lowered by adding a per-loop "execute flag", initialized to
TRUE, that when cleared inhibits all execution until the end of the loop.
Breaks are lowered to continues, plus setting a "break flag" that is checked
at the end of the loop, and trigger the unique "break".
Returns are lowered to breaks/continues, plus adding a "return flag" that
causes loops to break again out of their enclosing loops until all the
loops are exited: then the "execute flag" logic will ignore everything
until the end of the function.
Note that "continue" and "return" can also be implemented by adding
a dummy loop and using break.
However, this is bad for hardware with limited nesting depth, and
prevents further optimization, and thus is not currently performed.
2010-09-07 00:24:08 +02:00
|
|
|
bool do_lower_jumps(exec_list *instructions, bool pull_out_jumps = true, bool lower_sub_return = true, bool lower_main_return = false, bool lower_continue = false, bool lower_break = false);
|
2010-09-30 20:07:27 -07:00
|
|
|
bool do_lower_texture_projection(exec_list *instructions);
|
2010-05-05 11:45:30 -07:00
|
|
|
bool do_if_simplification(exec_list *instructions);
|
2013-04-03 23:56:57 -07:00
|
|
|
bool opt_flatten_nested_if_blocks(exec_list *instructions);
|
2010-11-24 22:02:26 -08:00
|
|
|
bool do_discard_simplification(exec_list *instructions);
|
2010-12-27 00:22:38 -08:00
|
|
|
bool lower_if_to_cond_assign(exec_list *instructions, unsigned max_depth = 0);
|
2010-07-12 11:04:07 -07:00
|
|
|
bool do_mat_op_to_vec(exec_list *instructions);
|
2010-08-13 07:16:38 -07:00
|
|
|
bool do_noop_swizzle(exec_list *instructions);
|
2010-08-05 11:01:09 -07:00
|
|
|
bool do_structure_splitting(exec_list *instructions);
|
2010-05-11 12:34:21 -07:00
|
|
|
bool do_swizzle_swizzle(exec_list *instructions);
|
2010-07-30 17:04:49 -07:00
|
|
|
bool do_tree_grafting(exec_list *instructions);
|
2010-07-06 17:53:32 -07:00
|
|
|
bool do_vec_index_to_cond_assign(exec_list *instructions);
|
2010-05-11 11:31:09 -07:00
|
|
|
bool do_vec_index_to_swizzle(exec_list *instructions);
|
2010-11-25 01:09:26 -08:00
|
|
|
bool lower_discard(exec_list *instructions);
|
2012-05-15 12:27:15 +01:00
|
|
|
void lower_discard_flow(exec_list *instructions);
|
2010-11-18 17:54:07 -08:00
|
|
|
bool lower_instructions(exec_list *instructions, unsigned what_to_lower);
|
2010-09-09 15:20:09 -07:00
|
|
|
bool lower_noise(exec_list *instructions);
|
2010-09-16 14:40:26 +02:00
|
|
|
bool lower_variable_index_to_cond_assign(exec_list *instructions,
|
|
|
|
bool lower_input, bool lower_output, bool lower_temp, bool lower_uniform);
|
2010-11-16 12:01:42 -08:00
|
|
|
bool lower_quadop_vector(exec_list *instructions, bool dont_lower_swz);
|
2012-12-04 11:11:02 -08:00
|
|
|
bool lower_clip_distance(gl_shader *shader);
|
2012-01-03 02:08:32 -08:00
|
|
|
void lower_output_reads(exec_list *instructions);
|
2012-11-19 15:15:32 -08:00
|
|
|
bool lower_packing_builtins(exec_list *instructions, int op_mask);
|
2012-07-11 08:26:31 -07:00
|
|
|
void lower_ubo_reference(struct gl_shader *shader, exec_list *instructions);
|
2012-12-09 15:25:38 -08:00
|
|
|
void lower_packed_varyings(void *mem_ctx, unsigned location_base,
|
|
|
|
unsigned locations_used, ir_variable_mode mode,
|
|
|
|
gl_shader *shader);
|
2010-09-13 14:25:26 -07:00
|
|
|
bool optimize_redundant_jumps(exec_list *instructions);
|
2010-10-02 22:57:17 -07:00
|
|
|
bool optimize_split_arrays(exec_list *instructions, bool linked);
|
2011-07-18 18:48:39 -07:00
|
|
|
|
|
|
|
ir_rvalue *
|
|
|
|
compare_index_block(exec_list *instructions, ir_variable *index,
|
|
|
|
unsigned base, unsigned components, void *mem_ctx);
|