#define LOWER_MUL_HIGH (1 << 0)
static bool
-lower_alu_instr(nir_alu_instr *instr, nir_builder *b)
+lower_alu_instr(nir_builder *b, nir_instr *instr_, UNUSED void *cb_data)
{
+ if (instr_->type != nir_instr_type_alu)
+ return false;
+
+ nir_alu_instr *instr = nir_instr_as_alu(instr_);
+
nir_ssa_def *lowered = NULL;
assert(instr->dest.dest.is_ssa);
bool
nir_lower_alu(nir_shader *shader)
{
- bool progress = false;
-
if (!shader->options->lower_bitfield_reverse &&
!shader->options->lower_mul_high)
return false;
- nir_foreach_function(function, shader) {
- if (function->impl) {
- nir_builder builder;
- nir_builder_init(&builder, function->impl);
-
- nir_foreach_block(block, function->impl) {
- nir_foreach_instr_safe(instr, block) {
- if (instr->type == nir_instr_type_alu) {
- progress = lower_alu_instr(nir_instr_as_alu(instr),
- &builder) || progress;
- }
- }
- }
-
- if (progress) {
- nir_metadata_preserve(function->impl,
- nir_metadata_block_index |
- nir_metadata_dominance);
- }
- }
- }
-
- return progress;
+ return nir_shader_instructions_pass(shader, lower_alu_instr,
+ nir_metadata_block_index |
+ nir_metadata_dominance,
+ NULL);
}