spirv/nir: parse function control and store in nir.
authorDave Airlie <airlied@redhat.com>
Mon, 26 Oct 2020 04:35:55 +0000 (14:35 +1000)
committerMarge Bot <emma+marge@anholt.net>
Tue, 12 Sep 2023 01:57:50 +0000 (01:57 +0000)
This just lets the nir access the inline/dont inline attributes

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

src/compiler/nir/nir.c
src/compiler/nir/nir.h
src/compiler/nir/nir_clone.c
src/compiler/nir/nir_print.c
src/compiler/nir/nir_serialize.c
src/compiler/spirv/vtn_cfg.c

index c52906b..9748f9e 100644 (file)
@@ -485,6 +485,8 @@ nir_function_create(nir_shader *shader, const char *name)
    func->impl = NULL;
    func->is_entrypoint = false;
    func->is_preamble = false;
+   func->dont_inline = false;
+   func->should_inline = false;
 
    return func;
 }
index 566173d..9809596 100644 (file)
@@ -3322,6 +3322,9 @@ typedef struct nir_function {
 
    bool is_entrypoint;
    bool is_preamble;
+   /* from SPIR-V function control */
+   bool should_inline;
+   bool dont_inline; /* from SPIR-V */
 } nir_function;
 
 typedef enum {
index 0e8ea70..0257120 100644 (file)
@@ -665,6 +665,8 @@ nir_function_clone(nir_shader *ns, const nir_function *fxn)
    }
    nfxn->is_entrypoint = fxn->is_entrypoint;
    nfxn->is_preamble = fxn->is_preamble;
+   nfxn->should_inline = fxn->should_inline;
+   nfxn->dont_inline = fxn->dont_inline;
 
    /* At first glance, it looks like we should clone the function_impl here.
     * However, call instructions need to be able to reference at least the
index 5b77934..48fa157 100644 (file)
@@ -2148,8 +2148,9 @@ print_function(nir_function *function, print_state *state)
 {
    FILE *fp = state->fp;
 
-   fprintf(fp, "decl_function %s (%d params)", function->name,
-           function->num_params);
+   fprintf(fp, "decl_function %s (%d params) %s", function->name,
+           function->num_params, function->dont_inline ? "(noinline)" :
+           function->should_inline ? "(inline)" : "");
 
    fprintf(fp, "\n");
 
index 831920d..5d783ec 100644 (file)
@@ -1887,6 +1887,10 @@ write_function(write_ctx *ctx, const nir_function *fxn)
       flags |= 0x4;
    if (fxn->impl)
       flags |= 0x8;
+   if (fxn->should_inline)
+      flags |= 0x10;
+   if (fxn->dont_inline)
+      flags |= 0x20;
    blob_write_uint32(ctx->blob, flags);
    if (fxn->name)
       blob_write_string(ctx->blob, fxn->name);
@@ -1931,6 +1935,8 @@ read_function(read_ctx *ctx)
    fxn->is_preamble = flags & 0x2;
    if (flags & 0x8)
       fxn->impl = NIR_SERIALIZE_FUNC_HAS_IMPL;
+   fxn->should_inline = flags & 0x10;
+   fxn->dont_inline = flags & 0x20;
 }
 
 static void
index 072065f..6882e9f 100644 (file)
@@ -201,6 +201,9 @@ vtn_cfg_handle_prepass_instruction(struct vtn_builder *b, SpvOp opcode,
       if (func_type->return_type->base_type != vtn_base_type_void)
          num_params++;
 
+      func->should_inline = b->func->control & SpvFunctionControlInlineMask;
+      func->dont_inline = b->func->control & SpvFunctionControlDontInlineMask;
+
       func->num_params = num_params;
       func->params = ralloc_array(b->shader, nir_parameter, num_params);