$(GLSL_SRCDIR)/nir/nir_lower_system_values.c \
$(GLSL_SRCDIR)/nir/nir_lower_variables_scalar.c \
$(GLSL_SRCDIR)/nir/nir_lower_vec_to_movs.c \
+ $(GLSL_SRCDIR)/nir/nir_metadata.c \
$(GLSL_SRCDIR)/nir/nir_opcodes.c \
$(GLSL_SRCDIR)/nir/nir_opcodes.h \
$(GLSL_SRCDIR)/nir/nir_opt_copy_propagate.c \
exec_list_push_tail(&shader->functions, &func->node);
exec_list_make_empty(&func->overload_list);
func->name = name;
+ func->shader = shader;
return func;
}
impl->return_var = NULL;
impl->reg_alloc = 0;
impl->ssa_alloc = 0;
- impl->block_index_dirty = true;
- impl->dominance_dirty = true;
+ impl->valid_metadata = nir_metadata_none;
/* create start & end blocks */
nir_block *start_block = nir_block_create(mem_ctx);
unlink_block_successors(block);
nir_function_impl *impl = nir_cf_node_get_function(&block->cf_node);
- impl->dominance_dirty = true;
+ nir_metadata_dirty(impl, nir_metadata_none);
if (jump_instr->type == nir_jump_break ||
jump_instr->type == nir_jump_continue) {
}
nir_function_impl *impl = nir_cf_node_get_function(&block->cf_node);
- impl->dominance_dirty = true;
+ nir_metadata_dirty(impl, nir_metadata_none);
}
/**
}
nir_function_impl *impl = nir_cf_node_get_function(node);
- impl->block_index_dirty = true;
- impl->dominance_dirty = true;
+ nir_metadata_dirty(impl, nir_metadata_none);
}
void
}
nir_function_impl *impl = nir_cf_node_get_function(node);
- impl->block_index_dirty = true;
- impl->dominance_dirty = true;
+ nir_metadata_dirty(impl, nir_metadata_none);
}
void
nir_cf_node_remove(nir_cf_node *node)
{
nir_function_impl *impl = nir_cf_node_get_function(node);
- impl->block_index_dirty = true;
+ nir_metadata_dirty(impl, nir_metadata_none);
if (node->type == nir_cf_node_block) {
/*
{
unsigned index = 0;
- if (!impl->block_index_dirty)
+ if (impl->valid_metadata & nir_metadata_block_index)
return;
nir_foreach_block(impl, index_block, &index);
impl->num_blocks = index;
- impl->block_index_dirty = false;
}
static void
#include "GL/gl.h" /* GLenum */
#include "util/ralloc.h"
#include "main/mtypes.h"
+#include "main/bitset.h"
#include "nir_types.h"
#include <stdio.h>
struct nir_function_overload;
struct nir_function;
+struct nir_shader;
/**
#define nir_loop_last_cf_node(loop) \
exec_node_data(nir_cf_node, exec_list_get_tail(&(loop)->body), node)
+/**
+ * Various bits of metadata that can may be created or required by
+ * optimization and analysis passes
+ */
+typedef enum {
+ nir_metadata_none = 0x0,
+ nir_metadata_block_index = 0x1,
+ nir_metadata_dominance = 0x2,
+} nir_metadata;
+
typedef struct {
nir_cf_node cf_node;
/* total number of basic blocks, only valid when block_index_dirty = false */
unsigned num_blocks;
- bool block_index_dirty;
- bool dominance_dirty;
+ nir_metadata valid_metadata;
} nir_function_impl;
#define nir_cf_node_next(_node) \
struct exec_list overload_list;
const char *name;
+ struct nir_shader *shader;
} nir_function;
#define nir_function_first_overload(func) \
/** removes a control flow node, doing any cleanup necessary */
void nir_cf_node_remove(nir_cf_node *node);
+/** requests that the given pieces of metadata be generated */
+void nir_metadata_require(nir_function_impl *impl, nir_metadata required);
+/** dirties all but the preserved metadata */
+void nir_metadata_dirty(nir_function_impl *impl, nir_metadata preserved);
+
/** creates an instruction with default swizzle/writemask/etc. with NULL registers */
nir_alu_instr *nir_alu_instr_create(void *mem_ctx, nir_op op);
void
nir_calc_dominance_impl(nir_function_impl *impl)
{
- if (!impl->dominance_dirty)
+ if (impl->valid_metadata & nir_metadata_dominance)
return;
- nir_index_blocks(impl);
+ nir_metadata_require(impl, nir_metadata_block_index);
dom_state state;
state.impl = impl;
impl->start_block->imm_dom = NULL;
calc_dom_children(impl);
-
- impl->dominance_dirty = false;
}
void
--- /dev/null
+/*
+ * Copyright © 2014 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ * Authors:
+ * Jason Ekstrand (jason@jlekstrand.net)
+ */
+
+#include "nir.h"
+
+/*
+ * Handles management of the metadata.
+ */
+
+void
+nir_metadata_require(nir_function_impl *impl, nir_metadata required)
+{
+#define NEEDS_UPDATE(X) ((required & ~impl->valid_metadata) & (X))
+
+ if (NEEDS_UPDATE(nir_metadata_block_index))
+ nir_index_blocks(impl);
+ if (NEEDS_UPDATE(nir_metadata_dominance))
+ nir_calc_dominance_impl(impl);
+
+#undef NEEDS_UPDATE
+
+ impl->valid_metadata |= required;
+}
+
+void
+nir_metadata_dirty(nir_function_impl *impl, nir_metadata preserved)
+{
+ impl->valid_metadata &= preserved;
+}