2 * Copyright © 2014 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 * Jason Ekstrand (jason@jlekstrand.net)
33 #define NIR_SEARCH_MAX_VARIABLES 16
36 nir_search_value_expression
,
37 nir_search_value_variable
,
38 nir_search_value_constant
,
39 } nir_search_value_type
;
42 nir_search_value_type type
;
48 nir_search_value value
;
50 /** The variable index; Must be less than NIR_SEARCH_MAX_VARIABLES */
53 /** Indicates that the given variable must be a constant
55 * This is only allowed in search expressions and indicates that the
56 * given variable is only allowed to match constant values.
60 /** Indicates that the given variable must have a certain type
62 * This is only allowed in search expressions and indicates that the
63 * given variable is only allowed to match values that come from an ALU
64 * instruction with the given output type. A type of nir_type_void
65 * means it can match any type.
67 * Note: A variable that is both constant and has a non-void type will
68 * never match anything.
72 /** Optional condition fxn ptr
74 * This is only allowed in search expressions, and allows additional
75 * constraints to be placed on the match. Typically used for 'is_constant'
76 * variables to require, for example, power-of-two in order for the search
79 bool (*cond
)(nir_alu_instr
*instr
, unsigned src
,
80 unsigned num_components
, const uint8_t *swizzle
);
81 } nir_search_variable
;
84 nir_search_value value
;
93 } nir_search_constant
;
96 nir_search_value value
;
98 /* When set on a search expression, the expression will only match an SSA
99 * value that does *not* have the exact bit set. If unset, the exact bit
100 * on the SSA value is ignored.
105 const nir_search_value
*srcs
[4];
107 /** Optional condition fxn ptr
109 * This allows additional constraints on expression matching, it is
110 * typically used to match an expressions uses such as the number of times
111 * the expression is used, and whether its used by an if.
113 bool (*cond
)(nir_alu_instr
*instr
);
114 } nir_search_expression
;
116 NIR_DEFINE_CAST(nir_search_value_as_variable
, nir_search_value
,
117 nir_search_variable
, value
,
118 type
, nir_search_value_variable
)
119 NIR_DEFINE_CAST(nir_search_value_as_constant
, nir_search_value
,
120 nir_search_constant
, value
,
121 type
, nir_search_value_constant
)
122 NIR_DEFINE_CAST(nir_search_value_as_expression
, nir_search_value
,
123 nir_search_expression
, value
,
124 type
, nir_search_value_expression
)
127 nir_replace_instr(nir_alu_instr
*instr
, const nir_search_expression
*search
,
128 const nir_search_value
*replace
, void *mem_ctx
);
130 #endif /* _NIR_SEARCH_ */