elif isinstance(val, Expression):
return val
elif isinstance(val, str):
- return Variable(val, name_base, varset)
+ return Variable(val, name_base, varset, algebraic_pass)
elif isinstance(val, (bool, float, int)):
return Constant(val, name_base)
${val.index}, /* ${val.var_name} */
${'true' if val.is_constant else 'false'},
${val.type() or 'nir_type_invalid' },
- ${val.cond if val.cond else 'NULL'},
+ ${val.cond_index},
${val.swizzle()},
% elif isinstance(val, Expression):
${'true' if val.inexact else 'false'}, ${'true' if val.exact else 'false'},
r"$")
class Variable(Value):
- def __init__(self, val, name, varset):
+ def __init__(self, val, name, varset, algebraic_pass):
Value.__init__(self, val, name, "variable")
m = _var_name_re.match(val)
assert self.var_name != 'False'
self.is_constant = m.group('const') is not None
- self.cond = m.group('cond')
+ self.cond_index = get_cond_index(algebraic_pass.variable_cond, m.group('cond'))
self.required_type = m.group('type')
self._bit_size = int(m.group('bits')) if m.group('bits') else None
self.swiz = m.group('swiz')
};
% endif
+% if variable_cond:
+static const nir_search_variable_cond ${pass_name}_variable_cond[] = {
+% for cond in variable_cond:
+ ${cond[0]},
+% endfor
+};
+% endif
+
% for state_id, state_xforms in enumerate(automaton.state_patterns):
% if state_xforms: # avoid emitting a 0-length array for MSVC
static const struct transform ${pass_name}_state${state_id}_xforms[] = {
.pass_op_table = ${pass_name}_pass_op_table,
.values = ${pass_name}_values,
.expression_cond = ${ pass_name + "_expression_cond" if expression_cond else "NULL" },
+ .variable_cond = ${ pass_name + "_variable_cond" if variable_cond else "NULL" },
};
bool
self.opcode_xforms = defaultdict(lambda : [])
self.pass_name = pass_name
self.expression_cond = {}
+ self.variable_cond = {}
error = False
condition_list=condition_list,
automaton=self.automaton,
expression_cond = sorted(self.expression_cond.items(), key=lambda kv: kv[1]),
+ variable_cond = sorted(self.variable_cond.items(), key=lambda kv: kv[1]),
get_c_opcode=get_c_opcode,
itertools=itertools)
*/
nir_alu_type type;
- /** Optional condition fxn ptr
+ /** Optional table->variable_cond[] fxn ptr index
*
* This is only allowed in search expressions, and allows additional
* constraints to be placed on the match. Typically used for 'is_constant'
* variables to require, for example, power-of-two in order for the search
* to match.
*/
- bool (*cond)(struct hash_table *range_ht, const nir_alu_instr *instr,
- unsigned src, unsigned num_components, const uint8_t *swizzle);
+ int16_t cond_index;
/** Swizzle (for replace only) */
uint8_t swizzle[NIR_MAX_VEC_COMPONENTS];
} nir_search_value_union;
typedef bool (*nir_search_expression_cond)(nir_alu_instr *instr);
+typedef bool (*nir_search_variable_cond)(struct hash_table *range_ht,
+ const nir_alu_instr *instr,
+ unsigned src, unsigned num_components,
+ const uint8_t *swizzle);
/* Generated data table for an algebraic optimization pass. */
typedef struct {
* nir_search_expression->cond.
*/
const nir_search_expression_cond *expression_cond;
+
+ /**
+ * Array of condition functions for variables, referenced by
+ * nir_search_variable->cond.
+ */
+ const nir_search_variable_cond *variable_cond;
} nir_algebraic_table;
/* Note: these must match the start states created in