glsl2: Give IR nodes a type field.
This is a big deal for debugging if nothing else ("what class is this ir_instruction, really?"), but is also nice for avoiding building a whole visitor or an if (node->as_whatever() || node->as_other_thing()) chain.
This commit is contained in:
@@ -29,6 +29,7 @@
|
|||||||
ir_assignment::ir_assignment(ir_rvalue *lhs, ir_rvalue *rhs,
|
ir_assignment::ir_assignment(ir_rvalue *lhs, ir_rvalue *rhs,
|
||||||
ir_rvalue *condition)
|
ir_rvalue *condition)
|
||||||
{
|
{
|
||||||
|
this->ir_type = ir_type_assignment;
|
||||||
this->lhs = lhs;
|
this->lhs = lhs;
|
||||||
this->rhs = rhs;
|
this->rhs = rhs;
|
||||||
this->condition = condition;
|
this->condition = condition;
|
||||||
@@ -38,6 +39,7 @@ ir_assignment::ir_assignment(ir_rvalue *lhs, ir_rvalue *rhs,
|
|||||||
ir_expression::ir_expression(int op, const struct glsl_type *type,
|
ir_expression::ir_expression(int op, const struct glsl_type *type,
|
||||||
ir_rvalue *op0, ir_rvalue *op1)
|
ir_rvalue *op0, ir_rvalue *op1)
|
||||||
{
|
{
|
||||||
|
this->ir_type = ir_type_expression;
|
||||||
this->type = type;
|
this->type = type;
|
||||||
this->operation = ir_expression_operation(op);
|
this->operation = ir_expression_operation(op);
|
||||||
this->operands[0] = op0;
|
this->operands[0] = op0;
|
||||||
@@ -190,7 +192,7 @@ ir_expression::get_operator(const char *str)
|
|||||||
|
|
||||||
ir_constant::ir_constant()
|
ir_constant::ir_constant()
|
||||||
{
|
{
|
||||||
/* empty */
|
this->ir_type = ir_type_constant;
|
||||||
}
|
}
|
||||||
|
|
||||||
ir_constant::ir_constant(const struct glsl_type *type,
|
ir_constant::ir_constant(const struct glsl_type *type,
|
||||||
@@ -199,36 +201,42 @@ ir_constant::ir_constant(const struct glsl_type *type,
|
|||||||
assert((type->base_type >= GLSL_TYPE_UINT)
|
assert((type->base_type >= GLSL_TYPE_UINT)
|
||||||
&& (type->base_type <= GLSL_TYPE_BOOL));
|
&& (type->base_type <= GLSL_TYPE_BOOL));
|
||||||
|
|
||||||
|
this->ir_type = ir_type_constant;
|
||||||
this->type = type;
|
this->type = type;
|
||||||
memcpy(& this->value, data, sizeof(this->value));
|
memcpy(& this->value, data, sizeof(this->value));
|
||||||
}
|
}
|
||||||
|
|
||||||
ir_constant::ir_constant(float f)
|
ir_constant::ir_constant(float f)
|
||||||
{
|
{
|
||||||
|
this->ir_type = ir_type_constant;
|
||||||
this->type = glsl_type::float_type;
|
this->type = glsl_type::float_type;
|
||||||
this->value.f[0] = f;
|
this->value.f[0] = f;
|
||||||
}
|
}
|
||||||
|
|
||||||
ir_constant::ir_constant(unsigned int u)
|
ir_constant::ir_constant(unsigned int u)
|
||||||
{
|
{
|
||||||
|
this->ir_type = ir_type_constant;
|
||||||
this->type = glsl_type::uint_type;
|
this->type = glsl_type::uint_type;
|
||||||
this->value.u[0] = u;
|
this->value.u[0] = u;
|
||||||
}
|
}
|
||||||
|
|
||||||
ir_constant::ir_constant(int i)
|
ir_constant::ir_constant(int i)
|
||||||
{
|
{
|
||||||
|
this->ir_type = ir_type_constant;
|
||||||
this->type = glsl_type::int_type;
|
this->type = glsl_type::int_type;
|
||||||
this->value.i[0] = i;
|
this->value.i[0] = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
ir_constant::ir_constant(bool b)
|
ir_constant::ir_constant(bool b)
|
||||||
{
|
{
|
||||||
|
this->ir_type = ir_type_constant;
|
||||||
this->type = glsl_type::bool_type;
|
this->type = glsl_type::bool_type;
|
||||||
this->value.b[0] = b;
|
this->value.b[0] = b;
|
||||||
}
|
}
|
||||||
|
|
||||||
ir_constant::ir_constant(const ir_constant *c, unsigned i)
|
ir_constant::ir_constant(const ir_constant *c, unsigned i)
|
||||||
{
|
{
|
||||||
|
this->ir_type = ir_type_constant;
|
||||||
this->type = c->type->get_base_type();
|
this->type = c->type->get_base_type();
|
||||||
|
|
||||||
switch (this->type->base_type) {
|
switch (this->type->base_type) {
|
||||||
@@ -242,6 +250,7 @@ ir_constant::ir_constant(const ir_constant *c, unsigned i)
|
|||||||
|
|
||||||
ir_constant::ir_constant(const struct glsl_type *type, exec_list *value_list)
|
ir_constant::ir_constant(const struct glsl_type *type, exec_list *value_list)
|
||||||
{
|
{
|
||||||
|
this->ir_type = ir_type_constant;
|
||||||
this->type = type;
|
this->type = type;
|
||||||
|
|
||||||
/* FINISHME: Support array types. */
|
/* FINISHME: Support array types. */
|
||||||
@@ -454,6 +463,7 @@ ir_constant::has_value(const ir_constant *c) const
|
|||||||
|
|
||||||
ir_dereference_variable::ir_dereference_variable(ir_variable *var)
|
ir_dereference_variable::ir_dereference_variable(ir_variable *var)
|
||||||
{
|
{
|
||||||
|
this->ir_type = ir_type_dereference_variable;
|
||||||
this->var = var;
|
this->var = var;
|
||||||
this->type = (var != NULL) ? var->type : glsl_type::error_type;
|
this->type = (var != NULL) ? var->type : glsl_type::error_type;
|
||||||
}
|
}
|
||||||
@@ -462,6 +472,7 @@ ir_dereference_variable::ir_dereference_variable(ir_variable *var)
|
|||||||
ir_dereference_array::ir_dereference_array(ir_rvalue *value,
|
ir_dereference_array::ir_dereference_array(ir_rvalue *value,
|
||||||
ir_rvalue *array_index)
|
ir_rvalue *array_index)
|
||||||
{
|
{
|
||||||
|
this->ir_type = ir_type_dereference_array;
|
||||||
this->array_index = array_index;
|
this->array_index = array_index;
|
||||||
this->set_array(value);
|
this->set_array(value);
|
||||||
}
|
}
|
||||||
@@ -472,6 +483,7 @@ ir_dereference_array::ir_dereference_array(ir_variable *var,
|
|||||||
{
|
{
|
||||||
void *ctx = talloc_parent(var);
|
void *ctx = talloc_parent(var);
|
||||||
|
|
||||||
|
this->ir_type = ir_type_dereference_array;
|
||||||
this->array_index = array_index;
|
this->array_index = array_index;
|
||||||
this->set_array(new(ctx) ir_dereference_variable(var));
|
this->set_array(new(ctx) ir_dereference_variable(var));
|
||||||
}
|
}
|
||||||
@@ -500,6 +512,7 @@ ir_dereference_array::set_array(ir_rvalue *value)
|
|||||||
ir_dereference_record::ir_dereference_record(ir_rvalue *value,
|
ir_dereference_record::ir_dereference_record(ir_rvalue *value,
|
||||||
const char *field)
|
const char *field)
|
||||||
{
|
{
|
||||||
|
this->ir_type = ir_type_dereference_record;
|
||||||
this->record = value;
|
this->record = value;
|
||||||
this->field = field;
|
this->field = field;
|
||||||
this->type = (this->record != NULL)
|
this->type = (this->record != NULL)
|
||||||
@@ -512,6 +525,7 @@ ir_dereference_record::ir_dereference_record(ir_variable *var,
|
|||||||
{
|
{
|
||||||
void *ctx = talloc_parent(var);
|
void *ctx = talloc_parent(var);
|
||||||
|
|
||||||
|
this->ir_type = ir_type_dereference_record;
|
||||||
this->record = new(ctx) ir_dereference_variable(var);
|
this->record = new(ctx) ir_dereference_variable(var);
|
||||||
this->field = field;
|
this->field = field;
|
||||||
this->type = (this->record != NULL)
|
this->type = (this->record != NULL)
|
||||||
@@ -624,6 +638,7 @@ ir_swizzle::ir_swizzle(ir_rvalue *val, unsigned x, unsigned y, unsigned z,
|
|||||||
: val(val)
|
: val(val)
|
||||||
{
|
{
|
||||||
const unsigned components[4] = { x, y, z, w };
|
const unsigned components[4] = { x, y, z, w };
|
||||||
|
this->ir_type = ir_type_swizzle;
|
||||||
this->init_mask(components, count);
|
this->init_mask(components, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -631,11 +646,13 @@ ir_swizzle::ir_swizzle(ir_rvalue *val, const unsigned *comp,
|
|||||||
unsigned count)
|
unsigned count)
|
||||||
: val(val)
|
: val(val)
|
||||||
{
|
{
|
||||||
|
this->ir_type = ir_type_swizzle;
|
||||||
this->init_mask(comp, count);
|
this->init_mask(comp, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
ir_swizzle::ir_swizzle(ir_rvalue *val, ir_swizzle_mask mask)
|
ir_swizzle::ir_swizzle(ir_rvalue *val, ir_swizzle_mask mask)
|
||||||
{
|
{
|
||||||
|
this->ir_type = ir_type_swizzle;
|
||||||
this->val = val;
|
this->val = val;
|
||||||
this->mask = mask;
|
this->mask = mask;
|
||||||
this->type = glsl_type::get_instance(val->type->base_type,
|
this->type = glsl_type::get_instance(val->type->base_type,
|
||||||
@@ -736,6 +753,7 @@ ir_variable::ir_variable(const struct glsl_type *type, const char *name)
|
|||||||
shader_in(false), shader_out(false),
|
shader_in(false), shader_out(false),
|
||||||
mode(ir_var_auto), interpolation(ir_var_smooth), array_lvalue(false)
|
mode(ir_var_auto), interpolation(ir_var_smooth), array_lvalue(false)
|
||||||
{
|
{
|
||||||
|
this->ir_type = ir_type_variable;
|
||||||
this->type = type;
|
this->type = type;
|
||||||
this->name = talloc_strdup(this, name);
|
this->name = talloc_strdup(this, name);
|
||||||
this->location = -1;
|
this->location = -1;
|
||||||
@@ -775,7 +793,7 @@ ir_variable::component_slots() const
|
|||||||
ir_function_signature::ir_function_signature(const glsl_type *return_type)
|
ir_function_signature::ir_function_signature(const glsl_type *return_type)
|
||||||
: return_type(return_type), is_defined(false), _function(NULL)
|
: return_type(return_type), is_defined(false), _function(NULL)
|
||||||
{
|
{
|
||||||
/* empty */
|
this->ir_type = ir_type_function_signature;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -825,6 +843,7 @@ ir_function_signature::replace_parameters(exec_list *new_params)
|
|||||||
|
|
||||||
ir_function::ir_function(const char *name)
|
ir_function::ir_function(const char *name)
|
||||||
{
|
{
|
||||||
|
this->ir_type = ir_type_function;
|
||||||
this->name = talloc_strdup(this, name);
|
this->name = talloc_strdup(this, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -41,11 +41,34 @@ extern "C" {
|
|||||||
#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
|
#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
enum ir_node_type {
|
||||||
|
ir_type_unset,
|
||||||
|
ir_type_variable,
|
||||||
|
ir_type_assignment,
|
||||||
|
ir_type_call,
|
||||||
|
ir_type_constant,
|
||||||
|
ir_type_dereference_array,
|
||||||
|
ir_type_dereference_record,
|
||||||
|
ir_type_dereference_variable,
|
||||||
|
ir_type_discard,
|
||||||
|
ir_type_expression,
|
||||||
|
ir_type_function,
|
||||||
|
ir_type_function_signature,
|
||||||
|
ir_type_if,
|
||||||
|
ir_type_loop,
|
||||||
|
ir_type_loop_jump,
|
||||||
|
ir_type_return,
|
||||||
|
ir_type_swizzle,
|
||||||
|
ir_type_texture,
|
||||||
|
ir_type_max, /**< maximum ir_type enum number, for validation */
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class of all IR instructions
|
* Base class of all IR instructions
|
||||||
*/
|
*/
|
||||||
class ir_instruction : public exec_node {
|
class ir_instruction : public exec_node {
|
||||||
public:
|
public:
|
||||||
|
enum ir_node_type ir_type;
|
||||||
const struct glsl_type *type;
|
const struct glsl_type *type;
|
||||||
|
|
||||||
class ir_constant *constant_expression_value();
|
class ir_constant *constant_expression_value();
|
||||||
@@ -84,7 +107,7 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
ir_instruction()
|
ir_instruction()
|
||||||
{
|
{
|
||||||
/* empty */
|
ir_type = ir_type_unset;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -410,7 +433,7 @@ public:
|
|||||||
ir_if(ir_rvalue *condition)
|
ir_if(ir_rvalue *condition)
|
||||||
: condition(condition)
|
: condition(condition)
|
||||||
{
|
{
|
||||||
/* empty */
|
ir_type = ir_type_if;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ir_if *clone(struct hash_table *ht) const;
|
virtual ir_if *clone(struct hash_table *ht) const;
|
||||||
@@ -442,7 +465,7 @@ class ir_loop : public ir_instruction {
|
|||||||
public:
|
public:
|
||||||
ir_loop() : from(NULL), to(NULL), increment(NULL), counter(NULL)
|
ir_loop() : from(NULL), to(NULL), increment(NULL), counter(NULL)
|
||||||
{
|
{
|
||||||
/* empty */
|
ir_type = ir_type_loop;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ir_loop *clone(struct hash_table *ht) const;
|
virtual ir_loop *clone(struct hash_table *ht) const;
|
||||||
@@ -664,6 +687,7 @@ public:
|
|||||||
ir_call(ir_function_signature *callee, exec_list *actual_parameters)
|
ir_call(ir_function_signature *callee, exec_list *actual_parameters)
|
||||||
: callee(callee)
|
: callee(callee)
|
||||||
{
|
{
|
||||||
|
ir_type = ir_type_call;
|
||||||
assert(callee->return_type != NULL);
|
assert(callee->return_type != NULL);
|
||||||
type = callee->return_type;
|
type = callee->return_type;
|
||||||
actual_parameters->move_nodes_to(& this->actual_parameters);
|
actual_parameters->move_nodes_to(& this->actual_parameters);
|
||||||
@@ -726,7 +750,7 @@ private:
|
|||||||
ir_call()
|
ir_call()
|
||||||
: callee(NULL)
|
: callee(NULL)
|
||||||
{
|
{
|
||||||
/* empty */
|
this->ir_type = ir_type_call;
|
||||||
}
|
}
|
||||||
|
|
||||||
ir_function_signature *callee;
|
ir_function_signature *callee;
|
||||||
@@ -746,7 +770,7 @@ class ir_jump : public ir_instruction {
|
|||||||
protected:
|
protected:
|
||||||
ir_jump()
|
ir_jump()
|
||||||
{
|
{
|
||||||
/* empty */
|
ir_type = ir_type_unset;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -755,13 +779,13 @@ public:
|
|||||||
ir_return()
|
ir_return()
|
||||||
: value(NULL)
|
: value(NULL)
|
||||||
{
|
{
|
||||||
/* empty */
|
this->ir_type = ir_type_return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ir_return(ir_rvalue *value)
|
ir_return(ir_rvalue *value)
|
||||||
: value(value)
|
: value(value)
|
||||||
{
|
{
|
||||||
/* empty */
|
this->ir_type = ir_type_return;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ir_return *clone(struct hash_table *) const;
|
virtual ir_return *clone(struct hash_table *) const;
|
||||||
@@ -804,6 +828,7 @@ public:
|
|||||||
|
|
||||||
ir_loop_jump(jump_mode mode)
|
ir_loop_jump(jump_mode mode)
|
||||||
{
|
{
|
||||||
|
this->ir_type = ir_type_loop_jump;
|
||||||
this->mode = mode;
|
this->mode = mode;
|
||||||
this->loop = loop;
|
this->loop = loop;
|
||||||
}
|
}
|
||||||
@@ -841,6 +866,7 @@ class ir_discard : public ir_jump {
|
|||||||
public:
|
public:
|
||||||
ir_discard()
|
ir_discard()
|
||||||
{
|
{
|
||||||
|
this->ir_type = ir_type_discard;
|
||||||
this->condition = NULL;
|
this->condition = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -898,7 +924,7 @@ public:
|
|||||||
ir_texture(enum ir_texture_opcode op)
|
ir_texture(enum ir_texture_opcode op)
|
||||||
: op(op), projector(NULL), shadow_comparitor(NULL)
|
: op(op), projector(NULL), shadow_comparitor(NULL)
|
||||||
{
|
{
|
||||||
/* empty */
|
this->ir_type = ir_type_texture;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ir_texture *clone(struct hash_table *) const;
|
virtual ir_texture *clone(struct hash_table *) const;
|
||||||
|
@@ -172,10 +172,25 @@ ir_validate::validate_ir(ir_instruction *ir, void *data)
|
|||||||
hash_table_insert(ht, ir, ir);
|
hash_table_insert(ht, ir, ir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
check_node_type(ir_instruction *ir, void *data)
|
||||||
|
{
|
||||||
|
if (ir->ir_type <= ir_type_unset || ir->ir_type >= ir_type_max) {
|
||||||
|
printf("Instruction node with unset type\n");
|
||||||
|
ir->print(); printf("\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
validate_ir_tree(exec_list *instructions)
|
validate_ir_tree(exec_list *instructions)
|
||||||
{
|
{
|
||||||
ir_validate v;
|
ir_validate v;
|
||||||
|
|
||||||
v.run(instructions);
|
v.run(instructions);
|
||||||
|
|
||||||
|
foreach_iter(exec_list_iterator, iter, *instructions) {
|
||||||
|
ir_instruction *ir = (ir_instruction *)iter.get();
|
||||||
|
|
||||||
|
visit_tree(ir, check_node_type, NULL);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user