1bf215546Sopenharmony_ci/*
2bf215546Sopenharmony_ci * Copyright © 2010 Intel Corporation
3bf215546Sopenharmony_ci *
4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
5bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
6bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation
7bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
9bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions:
10bf215546Sopenharmony_ci *
11bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next
12bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the
13bf215546Sopenharmony_ci * Software.
14bf215546Sopenharmony_ci *
15bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20bf215546Sopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21bf215546Sopenharmony_ci * DEALINGS IN THE SOFTWARE.
22bf215546Sopenharmony_ci */
23bf215546Sopenharmony_ci
24bf215546Sopenharmony_ci/**
25bf215546Sopenharmony_ci * \file ir_optimization.h
26bf215546Sopenharmony_ci *
27bf215546Sopenharmony_ci * Prototypes for optimization passes to be called by the compiler and drivers.
28bf215546Sopenharmony_ci */
29bf215546Sopenharmony_ci
30bf215546Sopenharmony_ci#ifndef GLSL_IR_OPTIMIZATION_H
31bf215546Sopenharmony_ci#define GLSL_IR_OPTIMIZATION_H
32bf215546Sopenharmony_ci
33bf215546Sopenharmony_cistruct gl_linked_shader;
34bf215546Sopenharmony_cistruct gl_shader_program;
35bf215546Sopenharmony_ci
36bf215546Sopenharmony_ci/* Operations for lower_instructions() */
37bf215546Sopenharmony_ci#define SUB_TO_ADD_NEG     0x01
38bf215546Sopenharmony_ci#define LDEXP_TO_ARITH     0x80
39bf215546Sopenharmony_ci#define CARRY_TO_ARITH     0x100
40bf215546Sopenharmony_ci#define BORROW_TO_ARITH    0x200
41bf215546Sopenharmony_ci#define DOPS_TO_DFRAC      0x800
42bf215546Sopenharmony_ci#define DFREXP_DLDEXP_TO_ARITH    0x1000
43bf215546Sopenharmony_ci#define BIT_COUNT_TO_MATH         0x02000
44bf215546Sopenharmony_ci#define EXTRACT_TO_SHIFTS         0x04000
45bf215546Sopenharmony_ci#define INSERT_TO_SHIFTS          0x08000
46bf215546Sopenharmony_ci#define REVERSE_TO_SHIFTS         0x10000
47bf215546Sopenharmony_ci#define FIND_LSB_TO_FLOAT_CAST    0x20000
48bf215546Sopenharmony_ci#define FIND_MSB_TO_FLOAT_CAST    0x40000
49bf215546Sopenharmony_ci#define IMUL_HIGH_TO_MUL          0x80000
50bf215546Sopenharmony_ci#define SQRT_TO_ABS_SQRT          0x200000
51bf215546Sopenharmony_ci
52bf215546Sopenharmony_ci/* Operations for lower_64bit_integer_instructions() */
53bf215546Sopenharmony_ci#define DIV64                     (1U << 0)
54bf215546Sopenharmony_ci#define MOD64                     (1U << 1)
55bf215546Sopenharmony_ci
56bf215546Sopenharmony_ci/**
57bf215546Sopenharmony_ci * \see class lower_packing_builtins_visitor
58bf215546Sopenharmony_ci */
59bf215546Sopenharmony_cienum lower_packing_builtins_op {
60bf215546Sopenharmony_ci   LOWER_PACK_UNPACK_NONE               = 0x0000,
61bf215546Sopenharmony_ci
62bf215546Sopenharmony_ci   LOWER_PACK_SNORM_2x16                = 0x0001,
63bf215546Sopenharmony_ci   LOWER_UNPACK_SNORM_2x16              = 0x0002,
64bf215546Sopenharmony_ci
65bf215546Sopenharmony_ci   LOWER_PACK_UNORM_2x16                = 0x0004,
66bf215546Sopenharmony_ci   LOWER_UNPACK_UNORM_2x16              = 0x0008,
67bf215546Sopenharmony_ci
68bf215546Sopenharmony_ci   LOWER_PACK_HALF_2x16                 = 0x0010,
69bf215546Sopenharmony_ci   LOWER_UNPACK_HALF_2x16               = 0x0020,
70bf215546Sopenharmony_ci
71bf215546Sopenharmony_ci   LOWER_PACK_SNORM_4x8                 = 0x0040,
72bf215546Sopenharmony_ci   LOWER_UNPACK_SNORM_4x8               = 0x0080,
73bf215546Sopenharmony_ci
74bf215546Sopenharmony_ci   LOWER_PACK_UNORM_4x8                 = 0x0100,
75bf215546Sopenharmony_ci   LOWER_UNPACK_UNORM_4x8               = 0x0200,
76bf215546Sopenharmony_ci
77bf215546Sopenharmony_ci   LOWER_PACK_USE_BFI                   = 0x0400,
78bf215546Sopenharmony_ci   LOWER_PACK_USE_BFE                   = 0x0800,
79bf215546Sopenharmony_ci};
80bf215546Sopenharmony_ci
81bf215546Sopenharmony_cibool do_common_optimization(exec_list *ir, bool linked,
82bf215546Sopenharmony_ci                            const struct gl_shader_compiler_options *options,
83bf215546Sopenharmony_ci                            bool native_integers);
84bf215546Sopenharmony_ci
85bf215546Sopenharmony_cibool ir_constant_fold(ir_rvalue **rvalue);
86bf215546Sopenharmony_ci
87bf215546Sopenharmony_cibool do_rebalance_tree(exec_list *instructions);
88bf215546Sopenharmony_cibool do_algebraic(exec_list *instructions, bool native_integers,
89bf215546Sopenharmony_ci                  const struct gl_shader_compiler_options *options);
90bf215546Sopenharmony_cibool do_constant_folding(exec_list *instructions);
91bf215546Sopenharmony_cibool do_constant_variable(exec_list *instructions);
92bf215546Sopenharmony_cibool do_constant_variable_unlinked(exec_list *instructions);
93bf215546Sopenharmony_cibool do_copy_propagation_elements(exec_list *instructions);
94bf215546Sopenharmony_cibool do_constant_propagation(exec_list *instructions);
95bf215546Sopenharmony_cibool do_dead_code(exec_list *instructions);
96bf215546Sopenharmony_cibool do_dead_code_local(exec_list *instructions);
97bf215546Sopenharmony_cibool do_dead_code_unlinked(exec_list *instructions);
98bf215546Sopenharmony_cibool do_dead_functions(exec_list *instructions);
99bf215546Sopenharmony_cibool opt_flip_matrices(exec_list *instructions);
100bf215546Sopenharmony_cibool do_function_inlining(exec_list *instructions);
101bf215546Sopenharmony_cibool 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);
102bf215546Sopenharmony_cibool do_if_simplification(exec_list *instructions);
103bf215546Sopenharmony_cibool opt_flatten_nested_if_blocks(exec_list *instructions);
104bf215546Sopenharmony_cibool do_mat_op_to_vec(exec_list *instructions);
105bf215546Sopenharmony_cibool do_minmax_prune(exec_list *instructions);
106bf215546Sopenharmony_cibool do_structure_splitting(exec_list *instructions);
107bf215546Sopenharmony_cibool do_tree_grafting(exec_list *instructions);
108bf215546Sopenharmony_cibool do_vec_index_to_cond_assign(exec_list *instructions);
109bf215546Sopenharmony_cibool do_vec_index_to_swizzle(exec_list *instructions);
110bf215546Sopenharmony_cibool lower_discard(exec_list *instructions);
111bf215546Sopenharmony_civoid lower_discard_flow(exec_list *instructions);
112bf215546Sopenharmony_cibool lower_instructions(exec_list *instructions, unsigned what_to_lower);
113bf215546Sopenharmony_cibool lower_clip_cull_distance(struct gl_shader_program *prog,
114bf215546Sopenharmony_ci                              gl_linked_shader *shader);
115bf215546Sopenharmony_civoid lower_output_reads(unsigned stage, exec_list *instructions);
116bf215546Sopenharmony_cibool lower_packing_builtins(exec_list *instructions, int op_mask);
117bf215546Sopenharmony_cibool lower_vector_insert(exec_list *instructions, bool lower_nonconstant_index);
118bf215546Sopenharmony_cibool lower_vector_derefs(gl_linked_shader *shader);
119bf215546Sopenharmony_civoid lower_named_interface_blocks(void *mem_ctx, gl_linked_shader *shader);
120bf215546Sopenharmony_cibool optimize_split_arrays(exec_list *instructions, bool linked);
121bf215546Sopenharmony_civoid optimize_dead_builtin_variables(exec_list *instructions,
122bf215546Sopenharmony_ci                                     enum ir_variable_mode other);
123bf215546Sopenharmony_cibool lower_tess_level(gl_linked_shader *shader);
124bf215546Sopenharmony_ci
125bf215546Sopenharmony_cibool lower_vertex_id(gl_linked_shader *shader);
126bf215546Sopenharmony_cibool lower_cs_derived(gl_linked_shader *shader);
127bf215546Sopenharmony_cibool lower_blend_equation_advanced(gl_linked_shader *shader, bool coherent);
128bf215546Sopenharmony_ci
129bf215546Sopenharmony_cibool lower_builtins(exec_list *instructions);
130bf215546Sopenharmony_cibool lower_subroutine(exec_list *instructions, struct _mesa_glsl_parse_state *state);
131bf215546Sopenharmony_cibool propagate_invariance(exec_list *instructions);
132bf215546Sopenharmony_ci
133bf215546Sopenharmony_cinamespace ir_builder { class ir_factory; };
134bf215546Sopenharmony_ci
135bf215546Sopenharmony_ciir_variable *compare_index_block(ir_builder::ir_factory &body,
136bf215546Sopenharmony_ci                                 ir_variable *index,
137bf215546Sopenharmony_ci                                 unsigned base, unsigned components);
138bf215546Sopenharmony_ci
139bf215546Sopenharmony_cibool lower_64bit_integer_instructions(exec_list *instructions,
140bf215546Sopenharmony_ci                                      unsigned what_to_lower);
141bf215546Sopenharmony_ci
142bf215546Sopenharmony_civoid lower_precision(const struct gl_shader_compiler_options *options,
143bf215546Sopenharmony_ci                     exec_list *instructions);
144bf215546Sopenharmony_ci
145bf215546Sopenharmony_ci#endif /* GLSL_IR_OPTIMIZATION_H */
146