16255a1f4c6425aa311c90e9dc7fca41c34e8dc2bEric Anholt/*
26255a1f4c6425aa311c90e9dc7fca41c34e8dc2bEric Anholt * Copyright © 2010 Intel Corporation
36255a1f4c6425aa311c90e9dc7fca41c34e8dc2bEric Anholt *
46255a1f4c6425aa311c90e9dc7fca41c34e8dc2bEric Anholt * Permission is hereby granted, free of charge, to any person obtaining a
56255a1f4c6425aa311c90e9dc7fca41c34e8dc2bEric Anholt * copy of this software and associated documentation files (the "Software"),
66255a1f4c6425aa311c90e9dc7fca41c34e8dc2bEric Anholt * to deal in the Software without restriction, including without limitation
76255a1f4c6425aa311c90e9dc7fca41c34e8dc2bEric Anholt * the rights to use, copy, modify, merge, publish, distribute, sublicense,
86255a1f4c6425aa311c90e9dc7fca41c34e8dc2bEric Anholt * and/or sell copies of the Software, and to permit persons to whom the
96255a1f4c6425aa311c90e9dc7fca41c34e8dc2bEric Anholt * Software is furnished to do so, subject to the following conditions:
106255a1f4c6425aa311c90e9dc7fca41c34e8dc2bEric Anholt *
116255a1f4c6425aa311c90e9dc7fca41c34e8dc2bEric Anholt * The above copyright notice and this permission notice (including the next
126255a1f4c6425aa311c90e9dc7fca41c34e8dc2bEric Anholt * paragraph) shall be included in all copies or substantial portions of the
136255a1f4c6425aa311c90e9dc7fca41c34e8dc2bEric Anholt * Software.
146255a1f4c6425aa311c90e9dc7fca41c34e8dc2bEric Anholt *
156255a1f4c6425aa311c90e9dc7fca41c34e8dc2bEric Anholt * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
166255a1f4c6425aa311c90e9dc7fca41c34e8dc2bEric Anholt * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
176255a1f4c6425aa311c90e9dc7fca41c34e8dc2bEric Anholt * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
186255a1f4c6425aa311c90e9dc7fca41c34e8dc2bEric Anholt * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
196255a1f4c6425aa311c90e9dc7fca41c34e8dc2bEric Anholt * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
206255a1f4c6425aa311c90e9dc7fca41c34e8dc2bEric Anholt * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
216255a1f4c6425aa311c90e9dc7fca41c34e8dc2bEric Anholt * DEALINGS IN THE SOFTWARE.
226255a1f4c6425aa311c90e9dc7fca41c34e8dc2bEric Anholt */
236255a1f4c6425aa311c90e9dc7fca41c34e8dc2bEric Anholt
246255a1f4c6425aa311c90e9dc7fca41c34e8dc2bEric Anholt
256255a1f4c6425aa311c90e9dc7fca41c34e8dc2bEric Anholt/**
26832aad989e3d319a8aaac046aa49df25da134d82Eric Anholt * \file ir_optimization.h
276255a1f4c6425aa311c90e9dc7fca41c34e8dc2bEric Anholt *
286255a1f4c6425aa311c90e9dc7fca41c34e8dc2bEric Anholt * Prototypes for optimization passes to be called by the compiler and drivers.
296255a1f4c6425aa311c90e9dc7fca41c34e8dc2bEric Anholt */
306255a1f4c6425aa311c90e9dc7fca41c34e8dc2bEric Anholt
3163684a9ae7a66f68df1f2c68cd9358e5622122a3Kenneth Graunke/* Operations for lower_instructions() */
32478034f34a59969103237eb78bc82f9e70fe81c2Bryan Cain#define SUB_TO_ADD_NEG     0x01
33478034f34a59969103237eb78bc82f9e70fe81c2Bryan Cain#define DIV_TO_MUL_RCP     0x02
34478034f34a59969103237eb78bc82f9e70fe81c2Bryan Cain#define EXP_TO_EXP2        0x04
35478034f34a59969103237eb78bc82f9e70fe81c2Bryan Cain#define POW_TO_EXP2        0x08
36478034f34a59969103237eb78bc82f9e70fe81c2Bryan Cain#define LOG_TO_LOG2        0x10
37478034f34a59969103237eb78bc82f9e70fe81c2Bryan Cain#define MOD_TO_FRACT       0x20
38478034f34a59969103237eb78bc82f9e70fe81c2Bryan Cain#define INT_DIV_TO_MUL_RCP 0x40
3963684a9ae7a66f68df1f2c68cd9358e5622122a3Kenneth Graunke
401d5d67f8adac9f94715de9804adb536d9a7ec5eeIan Romanickbool do_common_optimization(exec_list *ir, bool linked,
411d5d67f8adac9f94715de9804adb536d9a7ec5eeIan Romanick			    bool uniform_locations_assigned,
421d5d67f8adac9f94715de9804adb536d9a7ec5eeIan Romanick			    unsigned max_unroll_iterations);
432f4fe151681a6f6afe1d452eece6cf4144f44e49Eric Anholt
44832aad989e3d319a8aaac046aa49df25da134d82Eric Anholtbool do_algebraic(exec_list *instructions);
45bdd9b1f3ffa2a195d983816adfeca20480256119Eric Anholtbool do_constant_folding(exec_list *instructions);
4665122e9e8038488e8c586eb609e434a90188de27Eric Anholtbool do_constant_variable(exec_list *instructions);
4765122e9e8038488e8c586eb609e434a90188de27Eric Anholtbool do_constant_variable_unlinked(exec_list *instructions);
48bdd9b1f3ffa2a195d983816adfeca20480256119Eric Anholtbool do_copy_propagation(exec_list *instructions);
49e31266ed3e3667c043bc5ad1abd65cfdb0fa7fdbEric Anholtbool do_copy_propagation_elements(exec_list *instructions);
508bebbeb7c5b26ec9166a4644a2c051238d18509bEric Anholtbool do_constant_propagation(exec_list *instructions);
511d5d67f8adac9f94715de9804adb536d9a7ec5eeIan Romanickbool do_dead_code(exec_list *instructions, bool uniform_locations_assigned);
526255a1f4c6425aa311c90e9dc7fca41c34e8dc2bEric Anholtbool do_dead_code_local(exec_list *instructions);
5366d4c65ee2c311ea0c71c39a28456d0c11798d6bEric Anholtbool do_dead_code_unlinked(exec_list *instructions);
542e853ca23c8670246dd4efcee0706f68097652f7Eric Anholtbool do_dead_functions(exec_list *instructions);
55bdd9b1f3ffa2a195d983816adfeca20480256119Eric Anholtbool do_function_inlining(exec_list *instructions);
563361cbac2a883818efeb2b3e27405eeefce60f63Luca Barbieribool 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);
57aae338104fa6022b8b1d6b22c7ad1115b252b9b6Eric Anholtbool do_lower_texture_projection(exec_list *instructions);
58bdd9b1f3ffa2a195d983816adfeca20480256119Eric Anholtbool do_if_simplification(exec_list *instructions);
599a1d063c6d679c2155f5eb80f1cb94368d36bf2cKenneth Graunkebool do_discard_simplification(exec_list *instructions);
609ac6a9b2fa45debac63f2e2b20d78c4776d06e37Kenneth Graunkebool lower_if_to_cond_assign(exec_list *instructions, unsigned max_depth = 0);
616d8a0a0aadaafbab02dffcf7f89eb0210dd37b2eEric Anholtbool do_mat_op_to_vec(exec_list *instructions);
628f8cdbfba43550d0b8985fb087961864e4cd92b6Eric Anholtbool do_noop_swizzle(exec_list *instructions);
637f7eaf0285d011f7cc7e1a63133184a50b24ecaaEric Anholtbool do_structure_splitting(exec_list *instructions);
6449a5d5c4f5bf6e8d6ba344e8496d1d1fa0b4586dEric Anholtbool do_swizzle_swizzle(exec_list *instructions);
65784695442c415cf0be882434a25671ecfb635d34Eric Anholtbool do_tree_grafting(exec_list *instructions);
66a36334be02cb0a2b834667116bfeb680bf365857Eric Anholtbool do_vec_index_to_cond_assign(exec_list *instructions);
67b145e903694fa932ab1e0d955e889555193ab604Eric Anholtbool do_vec_index_to_swizzle(exec_list *instructions);
68940df10100d740ef27fa39026fd51c3199ed3d62Kenneth Graunkebool lower_discard(exec_list *instructions);
69e88f9b9546119db83e19b1bdd2bc9db45058cebdJosé Fonsecavoid lower_discard_flow(exec_list *instructions);
7063684a9ae7a66f68df1f2c68cd9358e5622122a3Kenneth Graunkebool lower_instructions(exec_list *instructions, unsigned what_to_lower);
71547131ac8750acabd030972fc768705c13d19ef7Ian Romanickbool lower_noise(exec_list *instructions);
72a6ecd1c3724a78b76ab9e81ea39632f1279021f8Ian Romanickbool lower_variable_index_to_cond_assign(exec_list *instructions,
73a6ecd1c3724a78b76ab9e81ea39632f1279021f8Ian Romanick    bool lower_input, bool lower_output, bool lower_temp, bool lower_uniform);
7411d6f1c69871d0b7edc28f639256460839fccd2dIan Romanickbool lower_quadop_vector(exec_list *instructions, bool dont_lower_swz);
75c06e32596735074536b0e613cbddb1c5fd7b367aPaul Berrybool lower_clip_distance(exec_list *instructions);
766d4b35c03619148cde89bc5eedaac3288001edd3Vincent Lejeunevoid lower_output_reads(exec_list *instructions);
77a75f2681d26aecad185895c1c2f13dd542281ff9Eric Anholtvoid lower_ubo_reference(struct gl_shader *shader, exec_list *instructions);
788f2214f4892acb994d13531d555196bd8f242dadIan Romanickbool optimize_redundant_jumps(exec_list *instructions);
7960177d5e2aec07ed6386a6935b118a356d58c4ecEric Anholtbool optimize_split_arrays(exec_list *instructions, bool linked);
8090cc372400e1f5869baabd841823bbf9296d7b01Ian Romanick
8190cc372400e1f5869baabd841823bbf9296d7b01Ian Romanickir_rvalue *
8290cc372400e1f5869baabd841823bbf9296d7b01Ian Romanickcompare_index_block(exec_list *instructions, ir_variable *index,
8390cc372400e1f5869baabd841823bbf9296d7b01Ian Romanick		    unsigned base, unsigned components, void *mem_ctx);
84