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"
37 * Base class of all IR instructions
39 class ir_instruction
: public exec_node
{
41 const struct glsl_type
*type
;
43 virtual void accept(ir_visitor
*) = 0;
46 * \name IR instruction downcast functions
48 * These functions either cast the object to a derived class or return
49 * \c NULL if the object's type does not match the specified derived class.
50 * Additional downcast functions will be added as needed.
53 virtual class ir_variable
* as_variable() { return NULL
; }
54 virtual class ir_dereference
* as_dereference() { return NULL
; }
55 virtual class ir_rvalue
* as_rvalue() { return NULL
; }
66 class ir_rvalue
: public ir_instruction
{
68 virtual ir_rvalue
* as_rvalue()
73 virtual bool is_lvalue()
79 ir_rvalue() : ir_instruction() { }
83 enum ir_variable_mode
{
91 enum ir_varaible_interpolation
{
98 class ir_variable
: public ir_instruction
{
100 ir_variable(const struct glsl_type
*, const char *);
102 virtual ir_variable
*as_variable()
107 virtual void accept(ir_visitor
*v
)
114 unsigned read_only
:1;
116 unsigned invariant
:1;
119 unsigned interpolation
:2;
123 class ir_label
: public ir_instruction
{
125 ir_label(const char *label
);
127 virtual void accept(ir_visitor
*v
)
137 class ir_function_signature
: public ir_instruction
{
139 ir_function_signature(const glsl_type
*return_type
);
141 virtual void accept(ir_visitor
*v
)
147 * Function return type.
149 * \note This discards the optional precision qualifier.
151 const struct glsl_type
*return_type
;
154 * List of function parameters stored as ir_variable objects.
156 struct exec_list parameters
;
159 * Pointer to the label that begins the function definition.
161 ir_label
*definition
;
166 * Header for tracking functions in the symbol table
168 class ir_function
: public ir_instruction
{
170 ir_function(const char *name
);
172 virtual void accept(ir_visitor
*v
)
178 * Find a signature that matches a set of actual parameters.
180 const ir_function_signature
*matching_signature(exec_list
*actual_param
);
183 * Name of the function.
188 * Set of overloaded functions with this name.
190 struct exec_list signatures
;
195 class ir_assignment
: public ir_rvalue
{
197 ir_assignment(ir_rvalue
*lhs
, ir_rvalue
*rhs
, ir_rvalue
*condition
);
199 virtual void accept(ir_visitor
*v
)
205 * Left-hand side of the assignment.
210 * Value being assigned
215 * Optional condition for the assignment.
217 ir_rvalue
*condition
;
221 enum ir_expression_operation
{
230 ir_unop_f2i
, /**< Float-to-integer conversion. */
231 ir_unop_i2f
, /**< Integer-to-float conversion. */
234 * \name Unary floating-point rounding operations.
249 * \name Binary comparison operators
261 * \name Bit-wise binary operations.
283 class ir_expression
: public ir_rvalue
{
285 ir_expression(int op
, const struct glsl_type
*type
,
286 ir_rvalue
*, ir_rvalue
*);
288 virtual void accept(ir_visitor
*v
)
293 ir_expression_operation operation
;
294 ir_rvalue
*operands
[2];
299 * IR instruction representing a function call
301 class ir_call
: public ir_rvalue
{
303 ir_call(const ir_function_signature
*callee
, exec_list
*actual_parameters
)
304 : ir_rvalue(), callee(callee
)
306 assert(callee
->return_type
!= NULL
);
307 type
= callee
->return_type
;
308 actual_parameters
->move_nodes_to(& this->actual_parameters
);
311 virtual void accept(ir_visitor
*v
)
317 * Get a generic ir_call object when an error occurs
319 static ir_call
*get_error_instruction();
323 : ir_rvalue(), callee(NULL
)
328 const ir_function_signature
*callee
;
329 exec_list actual_parameters
;
334 * \name Jump-like IR instructions.
336 * These include \c break, \c continue, \c return, and \c discard.
339 class ir_jump
: public ir_instruction
{
348 class ir_return
: public ir_jump
{
356 ir_return(ir_rvalue
*value
)
362 ir_rvalue
*get_value() const
367 virtual void accept(ir_visitor
*v
)
378 struct ir_swizzle_mask
{
385 * Number of components in the swizzle.
387 unsigned num_components
:3;
390 * Does the swizzle contain duplicate components?
392 * L-value swizzles cannot contain duplicate components.
394 unsigned has_duplicates
:1;
397 class ir_dereference
: public ir_rvalue
{
399 ir_dereference(struct ir_instruction
*);
401 ir_dereference(ir_instruction
*variable
, ir_rvalue
*array_index
);
403 virtual ir_dereference
*as_dereference()
408 virtual void accept(ir_visitor
*v
)
419 * Setting the swizzle of a derefernce
421 void set_swizzle(unsigned x
, unsigned y
, unsigned z
, unsigned w
,
426 ir_reference_variable
,
432 * Object being dereferenced.
434 * Must be either an \c ir_variable or an \c ir_rvalue.
439 ir_rvalue
*array_index
;
441 struct ir_swizzle_mask swizzle
;
446 class ir_constant
: public ir_rvalue
{
448 ir_constant(const struct glsl_type
*type
, const void *data
);
450 virtual void accept(ir_visitor
*v
)
456 * Value of the constant.
458 * The field used to back the values supplied by the constant is determined
459 * by the type associated with the \c ir_instruction. Constants may be
460 * scalars, vectors, or matrices.
472 _mesa_glsl_initialize_variables(exec_list
*instructions
,
473 struct _mesa_glsl_parse_state
*state
);