Skip to content

nir: Add some generic helpers for writing lowering passes

Faith Ekstrand requested to merge gfxstrand/mesa:review/nir-lower-helper into master

Every lowering pass in NIR has a bunch of boilerplate to do the same thing. Some of those things, SSA def replacement in particular, can be a bit tricky in certain cases. This MR adds a newlowering pass helper that works in termsl of a couple of call-backs and handles all sorts of corner cases for you:

  1. Replacing a SSA def with a ALU series that uses that SSA def
  2. Rewriting the sources of an instruction and otherwise leaving it alone
  3. Replacing a SSA def with a sequence that includes control-flow
  4. Replacing a SSA def with a sequence that needs additional lowering by the same pass. This case is handled by running the same lowing on the newly inserted instructions.

This MR also updates a few passes to use the new helpers. In particular, it updates 64-bit integer and floating-point lowering which take advantage of point 4 above. The final commit gets rid of the 64-bit lowering loop in brw_nir.c and st_glsl_to_nir.c.

Edited by Faith Ekstrand

Merge request reports