nir/builder_opcodes: Remove nir_build_ prefixed helpers
authorKonstantin Seurer <konstantin.seurer@gmail.com>
Mon, 26 Jun 2023 12:23:08 +0000 (14:23 +0200)
committerMarge Bot <emma+marge@anholt.net>
Tue, 27 Jun 2023 17:37:54 +0000 (17:37 +0000)
This patch decreases the size of nir_builder_opcodes.h from 14292 loc to
13763 loc.

nir_build_ versions are still needed if the nir_ is a custom helper.
Intrinsics which need such a helper have to be added to
build_prefixed_intrinsics.

Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23858>

src/compiler/nir/nir_builder_opcodes_h.py

index 688884b..81aec09 100644 (file)
@@ -33,6 +33,12 @@ def src_list(num_srcs):
 
 def needs_num_components(opcode):
    return "replicated" in opcode.name
+
+def intrinsic_prefix(name):
+   if name in build_prefixed_intrinsics:
+      return 'nir_build'
+   else:
+      return 'nir'
 %>
 
 % for name, opcode in sorted(opcodes.items()):
@@ -155,16 +161,18 @@ _nir_build_${name}(nir_builder *build${intrinsic_decl_list(opcode)})
 % for name, opcode in sorted(INTR_OPCODES.items()):
 % if opcode.indices:
 #ifdef __cplusplus
-#define nir_build_${name}(build${intrinsic_macro_list(opcode)}, ...) ${'\\\\'}
+#define ${intrinsic_prefix(name)}_${name}(build${intrinsic_macro_list(opcode)}, ...) ${'\\\\'}
 _nir_build_${name}(build${intrinsic_macro_list(opcode)}, _nir_${name}_indices{0, __VA_ARGS__})
 #else
-#define nir_build_${name}(build${intrinsic_macro_list(opcode)}, ...) ${'\\\\'}
+#define ${intrinsic_prefix(name)}_${name}(build${intrinsic_macro_list(opcode)}, ...) ${'\\\\'}
 _nir_build_${name}(build${intrinsic_macro_list(opcode)}, (struct _nir_${name}_indices){0, __VA_ARGS__})
 #endif
 % else:
-#define nir_build_${name} _nir_build_${name}
+#define nir_${name} _nir_build_${name}
 % endif
+% if name in build_prefixed_intrinsics:
 #define nir_${name} nir_build_${name}
+% endif
 % endfor
 
 % for name in ['flt', 'fge', 'feq', 'fneu']:
@@ -203,9 +211,26 @@ from nir_opcodes import opcodes, type_size, type_base_type
 from nir_intrinsics import INTR_OPCODES, WRITE_MASK, ALIGN_MUL
 from mako.template import Template
 
+# List of intrinsics that also need a nir_build_ prefixed factory macro.
+build_prefixed_intrinsics = [
+   "load_deref",
+   "store_deref",
+   "copy_deref",
+   "memcpy_deref",
+
+   "load_param",
+
+   "load_global",
+   "load_global_constant",
+   "store_global",
+
+   "deref_mode_is",
+]
+
 print(Template(template).render(opcodes=opcodes,
                                 type_size=type_size,
                                 type_base_type=type_base_type,
                                 INTR_OPCODES=INTR_OPCODES,
                                 WRITE_MASK=WRITE_MASK,
-                                ALIGN_MUL=ALIGN_MUL))
+                                ALIGN_MUL=ALIGN_MUL,
+                                build_prefixed_intrinsics=build_prefixed_intrinsics))