3 * Copyright © 2010 Intel Corporation
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
30 #include "ir_visitor.h"
51 * Base class of all IR instructions
53 class ir_instruction
: public exec_node
{
56 const struct glsl_type
*type
;
58 virtual void accept(ir_visitor
*) = 0;
61 ir_instruction(int mode
)
69 * Dummy constructor to catch bad constructors in derived classes.
71 * Every derived must use the constructor that sets the instructions
72 * mode. Having the \c void constructor private prevents derived classes
73 * from accidentally doing the wrong thing.
79 enum ir_variable_mode
{
87 enum ir_varaible_interpolation
{
93 class ir_variable
: public ir_instruction
{
95 ir_variable(const struct glsl_type
*, const char *);
97 virtual void accept(ir_visitor
*v
)
104 unsigned read_only
:1;
106 unsigned invariant
:1;
109 unsigned interpolation
:2;
113 class ir_label
: public ir_instruction
{
115 ir_label(const char *label
);
117 virtual void accept(ir_visitor
*v
)
127 class ir_function_signature
: public ir_instruction
{
129 ir_function_signature(const glsl_type
*return_type
);
131 virtual void accept(ir_visitor
*v
)
137 * Function return type.
139 * \note This discards the optional precision qualifier.
141 const struct glsl_type
*return_type
;
144 * List of function parameters stored as ir_variable objects.
146 struct exec_list parameters
;
149 * Pointer to the label that begins the function definition.
151 ir_label
*definition
;
156 * Header for tracking functions in the symbol table
158 class ir_function
: public ir_instruction
{
160 ir_function(const char *name
);
162 virtual void accept(ir_visitor
*v
)
168 * Find a signature that matches a set of actual parameters.
170 const ir_function_signature
*matching_signature(exec_list
*actual_param
);
173 * Name of the function.
178 * Set of overloaded functions with this name.
180 struct exec_list signatures
;
185 class ir_dereference
;
187 class ir_assignment
: public ir_instruction
{
189 ir_assignment(ir_instruction
*lhs
, ir_instruction
*rhs
,
190 ir_expression
*condition
);
192 virtual void accept(ir_visitor
*v
)
198 * Left-hand side of the assignment.
203 * Value being assigned
205 * This should be either \c ir_op_expression or \c ir_op_dereference.
210 * Optional condition for the assignment.
212 ir_expression
*condition
;
216 enum ir_expression_operation
{
225 ir_unop_f2i
, /**< Float-to-integer conversion. */
226 ir_unop_i2f
, /**< Integer-to-float conversion. */
229 * \name Unary floating-point rounding operations.
244 * \name Binary comparison operators
256 * \name Bit-wise binary operations.
278 class ir_expression
: public ir_instruction
{
280 ir_expression(int op
, const struct glsl_type
*type
,
281 ir_instruction
*, ir_instruction
*);
283 virtual void accept(ir_visitor
*v
)
288 ir_expression_operation operation
;
289 ir_instruction
*operands
[2];
294 * IR instruction representing a function call
296 class ir_call
: public ir_instruction
{
298 ir_call(const ir_function_signature
*callee
, exec_list
*actual_parameters
)
299 : ir_instruction(ir_op_call
), callee(callee
)
301 assert(callee
->return_type
!= NULL
);
302 type
= callee
->return_type
;
303 actual_parameters
->move_nodes_to(& this->actual_parameters
);
306 virtual void accept(ir_visitor
*v
)
312 * Get a generic ir_call object when an error occurs
314 static ir_call
*get_error_instruction();
318 : ir_instruction(ir_op_call
), callee(NULL
)
323 const ir_function_signature
*callee
;
324 exec_list actual_parameters
;
329 * \name Jump-like IR instructions.
331 * These include \c break, \c continue, \c return, and \c discard.
334 class ir_jump
: public ir_instruction
{
337 : ir_instruction(ir_op_jump
)
343 class ir_return
: public ir_jump
{
351 ir_return(ir_expression
*value
)
357 ir_expression
*get_value() const
362 virtual void accept(ir_visitor
*v
)
368 ir_expression
*value
;
373 struct ir_swizzle_mask
{
380 * Number of components in the swizzle.
382 unsigned num_components
:3;
385 * Does the swizzle contain duplicate components?
387 * L-value swizzles cannot contain duplicate components.
389 unsigned has_duplicates
:1;
392 class ir_dereference
: public ir_instruction
{
394 ir_dereference(struct ir_instruction
*);
396 virtual void accept(ir_visitor
*v
)
402 * Setting the swizzle of a derefernce
404 void set_swizzle(unsigned x
, unsigned y
, unsigned z
, unsigned w
,
409 ir_reference_variable
,
415 * Object being dereferenced.
417 * Must be either an \c ir_variable or an \c ir_dereference.
422 ir_expression
*array_index
;
424 struct ir_swizzle_mask swizzle
;
429 class ir_constant
: public ir_instruction
{
431 ir_constant(const struct glsl_type
*type
, const void *data
);
433 virtual void accept(ir_visitor
*v
)
439 * Value of the constant.
441 * The field used to back the values supplied by the constant is determined
442 * by the type associated with the \c ir_instruction. Constants may be
443 * scalars, vectors, or matrices.
455 _mesa_glsl_initialize_variables(exec_list
*instructions
,
456 struct _mesa_glsl_parse_state
*state
);