Ian Romanick | 986b8f7 | 2010-03-10 13:58:12 -0800 | [diff] [blame] | 1 | /* -*- c++ -*- */ |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 2 | /* |
| 3 | * Copyright © 2010 Intel Corporation |
| 4 | * |
| 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: |
| 11 | * |
| 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 |
| 14 | * Software. |
| 15 | * |
| 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. |
| 23 | */ |
| 24 | |
Ian Romanick | e309a60 | 2010-03-15 15:20:15 -0700 | [diff] [blame] | 25 | #pragma once |
| 26 | #ifndef IR_H |
| 27 | #define IR_H |
| 28 | |
Ian Romanick | 0044e7e | 2010-03-08 23:44:00 -0800 | [diff] [blame] | 29 | #include "list.h" |
Ian Romanick | 78b51b0 | 2010-03-09 16:23:37 -0800 | [diff] [blame] | 30 | #include "ir_visitor.h" |
Ian Romanick | 0044e7e | 2010-03-08 23:44:00 -0800 | [diff] [blame] | 31 | |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 32 | struct ir_program { |
| 33 | void *bong_hits; |
| 34 | }; |
| 35 | |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 36 | /** |
| 37 | * Base class of all IR instructions |
| 38 | */ |
Ian Romanick | 0044e7e | 2010-03-08 23:44:00 -0800 | [diff] [blame] | 39 | class ir_instruction : public exec_node { |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 40 | public: |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 41 | const struct glsl_type *type; |
| 42 | |
Ian Romanick | 78b51b0 | 2010-03-09 16:23:37 -0800 | [diff] [blame] | 43 | virtual void accept(ir_visitor *) = 0; |
| 44 | |
Kenneth Graunke | 44e1dfa | 2010-03-25 23:30:28 -0700 | [diff] [blame] | 45 | /** |
| 46 | * \name IR instruction downcast functions |
| 47 | * |
| 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. |
| 51 | */ |
| 52 | /*@{*/ |
| 53 | virtual class ir_variable * as_variable() { return NULL; } |
| 54 | virtual class ir_dereference * as_dereference() { return NULL; } |
Kenneth Graunke | fb9fb5f | 2010-03-26 00:25:36 -0700 | [diff] [blame] | 55 | virtual class ir_rvalue * as_rvalue() { return NULL; } |
Kenneth Graunke | 44e1dfa | 2010-03-25 23:30:28 -0700 | [diff] [blame] | 56 | /*@}*/ |
| 57 | |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 58 | protected: |
Kenneth Graunke | 44e1dfa | 2010-03-25 23:30:28 -0700 | [diff] [blame] | 59 | ir_instruction() |
Ian Romanick | d27ec24 | 2010-03-11 14:23:41 -0800 | [diff] [blame] | 60 | { |
| 61 | /* empty */ |
| 62 | } |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 63 | }; |
| 64 | |
| 65 | |
Kenneth Graunke | fb9fb5f | 2010-03-26 00:25:36 -0700 | [diff] [blame] | 66 | class ir_rvalue : public ir_instruction { |
| 67 | public: |
| 68 | virtual ir_rvalue * as_rvalue() |
| 69 | { |
| 70 | return this; |
| 71 | } |
| 72 | |
| 73 | virtual bool is_lvalue() |
| 74 | { |
| 75 | return false; |
| 76 | } |
| 77 | |
| 78 | protected: |
| 79 | ir_rvalue() : ir_instruction() { } |
| 80 | }; |
| 81 | |
| 82 | |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 83 | enum ir_variable_mode { |
| 84 | ir_var_auto = 0, |
| 85 | ir_var_uniform, |
| 86 | ir_var_in, |
| 87 | ir_var_out, |
| 88 | ir_var_inout |
| 89 | }; |
| 90 | |
| 91 | enum ir_varaible_interpolation { |
| 92 | ir_var_smooth = 0, |
| 93 | ir_var_flat, |
| 94 | ir_var_noperspective |
| 95 | }; |
| 96 | |
Kenneth Graunke | fb9fb5f | 2010-03-26 00:25:36 -0700 | [diff] [blame] | 97 | |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 98 | class ir_variable : public ir_instruction { |
| 99 | public: |
| 100 | ir_variable(const struct glsl_type *, const char *); |
| 101 | |
Kenneth Graunke | 44e1dfa | 2010-03-25 23:30:28 -0700 | [diff] [blame] | 102 | virtual ir_variable *as_variable() |
| 103 | { |
| 104 | return this; |
| 105 | } |
| 106 | |
Ian Romanick | 78b51b0 | 2010-03-09 16:23:37 -0800 | [diff] [blame] | 107 | virtual void accept(ir_visitor *v) |
| 108 | { |
| 109 | v->visit(this); |
| 110 | } |
| 111 | |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 112 | const char *name; |
| 113 | |
| 114 | unsigned read_only:1; |
| 115 | unsigned centroid:1; |
| 116 | unsigned invariant:1; |
| 117 | |
| 118 | unsigned mode:3; |
| 119 | unsigned interpolation:2; |
| 120 | }; |
| 121 | |
| 122 | |
| 123 | class ir_label : public ir_instruction { |
| 124 | public: |
| 125 | ir_label(const char *label); |
| 126 | |
Ian Romanick | 78b51b0 | 2010-03-09 16:23:37 -0800 | [diff] [blame] | 127 | virtual void accept(ir_visitor *v) |
| 128 | { |
| 129 | v->visit(this); |
| 130 | } |
| 131 | |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 132 | const char *label; |
| 133 | }; |
| 134 | |
| 135 | |
| 136 | /*@{*/ |
| 137 | class ir_function_signature : public ir_instruction { |
| 138 | public: |
Ian Romanick | e39cc69 | 2010-03-23 12:19:13 -0700 | [diff] [blame] | 139 | ir_function_signature(const glsl_type *return_type); |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 140 | |
Ian Romanick | 78b51b0 | 2010-03-09 16:23:37 -0800 | [diff] [blame] | 141 | virtual void accept(ir_visitor *v) |
| 142 | { |
| 143 | v->visit(this); |
| 144 | } |
| 145 | |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 146 | /** |
| 147 | * Function return type. |
| 148 | * |
| 149 | * \note This discards the optional precision qualifier. |
| 150 | */ |
| 151 | const struct glsl_type *return_type; |
| 152 | |
| 153 | /** |
| 154 | * List of function parameters stored as ir_variable objects. |
| 155 | */ |
Ian Romanick | 0044e7e | 2010-03-08 23:44:00 -0800 | [diff] [blame] | 156 | struct exec_list parameters; |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 157 | |
| 158 | /** |
| 159 | * Pointer to the label that begins the function definition. |
| 160 | */ |
| 161 | ir_label *definition; |
| 162 | }; |
| 163 | |
| 164 | |
| 165 | /** |
| 166 | * Header for tracking functions in the symbol table |
| 167 | */ |
| 168 | class ir_function : public ir_instruction { |
| 169 | public: |
Ian Romanick | 882dad7 | 2010-03-23 17:42:04 -0700 | [diff] [blame] | 170 | ir_function(const char *name); |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 171 | |
Ian Romanick | 78b51b0 | 2010-03-09 16:23:37 -0800 | [diff] [blame] | 172 | virtual void accept(ir_visitor *v) |
| 173 | { |
| 174 | v->visit(this); |
| 175 | } |
| 176 | |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 177 | /** |
Ian Romanick | 471471f | 2010-03-11 14:50:30 -0800 | [diff] [blame] | 178 | * Find a signature that matches a set of actual parameters. |
| 179 | */ |
| 180 | const ir_function_signature *matching_signature(exec_list *actual_param); |
| 181 | |
| 182 | /** |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 183 | * Name of the function. |
| 184 | */ |
| 185 | const char *name; |
| 186 | |
Ian Romanick | 471471f | 2010-03-11 14:50:30 -0800 | [diff] [blame] | 187 | /** |
| 188 | * Set of overloaded functions with this name. |
| 189 | */ |
Ian Romanick | 0044e7e | 2010-03-08 23:44:00 -0800 | [diff] [blame] | 190 | struct exec_list signatures; |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 191 | }; |
| 192 | /*@}*/ |
| 193 | |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 194 | |
Kenneth Graunke | fb9fb5f | 2010-03-26 00:25:36 -0700 | [diff] [blame] | 195 | class ir_assignment : public ir_rvalue { |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 196 | public: |
Kenneth Graunke | fb9fb5f | 2010-03-26 00:25:36 -0700 | [diff] [blame] | 197 | ir_assignment(ir_rvalue *lhs, ir_rvalue *rhs, ir_rvalue *condition); |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 198 | |
Ian Romanick | 78b51b0 | 2010-03-09 16:23:37 -0800 | [diff] [blame] | 199 | virtual void accept(ir_visitor *v) |
| 200 | { |
| 201 | v->visit(this); |
| 202 | } |
| 203 | |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 204 | /** |
| 205 | * Left-hand side of the assignment. |
| 206 | */ |
Kenneth Graunke | fb9fb5f | 2010-03-26 00:25:36 -0700 | [diff] [blame] | 207 | ir_rvalue *lhs; |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 208 | |
| 209 | /** |
| 210 | * Value being assigned |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 211 | */ |
Kenneth Graunke | fb9fb5f | 2010-03-26 00:25:36 -0700 | [diff] [blame] | 212 | ir_rvalue *rhs; |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 213 | |
| 214 | /** |
| 215 | * Optional condition for the assignment. |
| 216 | */ |
Kenneth Graunke | fb9fb5f | 2010-03-26 00:25:36 -0700 | [diff] [blame] | 217 | ir_rvalue *condition; |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 218 | }; |
| 219 | |
Eric Anholt | e65e12f | 2010-03-26 11:00:07 -0700 | [diff] [blame] | 220 | /* Update ir_print_visitor.cpp when updating this list. */ |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 221 | enum ir_expression_operation { |
| 222 | ir_unop_bit_not, |
| 223 | ir_unop_logic_not, |
| 224 | ir_unop_neg, |
| 225 | ir_unop_abs, |
| 226 | ir_unop_rcp, |
| 227 | ir_unop_rsq, |
Eric Anholt | 44d68fd | 2010-03-27 13:01:51 -0700 | [diff] [blame] | 228 | ir_unop_sqrt, |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 229 | ir_unop_exp, |
| 230 | ir_unop_log, |
Eric Anholt | 0166526 | 2010-03-27 13:56:35 -0700 | [diff] [blame^] | 231 | ir_unop_exp2, |
| 232 | ir_unop_log2, |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 233 | ir_unop_f2i, /**< Float-to-integer conversion. */ |
| 234 | ir_unop_i2f, /**< Integer-to-float conversion. */ |
Ian Romanick | 6c86ea8 | 2010-03-26 16:11:48 -0700 | [diff] [blame] | 235 | ir_unop_u2f, /**< Unsigned-to-float conversion. */ |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 236 | |
| 237 | /** |
| 238 | * \name Unary floating-point rounding operations. |
| 239 | */ |
| 240 | /*@{*/ |
| 241 | ir_unop_trunc, |
| 242 | ir_unop_ceil, |
| 243 | ir_unop_floor, |
| 244 | /*@}*/ |
| 245 | |
| 246 | ir_binop_add, |
| 247 | ir_binop_sub, |
| 248 | ir_binop_mul, |
| 249 | ir_binop_div, |
| 250 | ir_binop_mod, |
| 251 | |
| 252 | /** |
| 253 | * \name Binary comparison operators |
| 254 | */ |
| 255 | /*@{*/ |
| 256 | ir_binop_less, |
| 257 | ir_binop_greater, |
| 258 | ir_binop_lequal, |
| 259 | ir_binop_gequal, |
| 260 | ir_binop_equal, |
| 261 | ir_binop_nequal, |
| 262 | /*@}*/ |
| 263 | |
| 264 | /** |
| 265 | * \name Bit-wise binary operations. |
| 266 | */ |
| 267 | /*@{*/ |
| 268 | ir_binop_lshift, |
| 269 | ir_binop_rshift, |
| 270 | ir_binop_bit_and, |
| 271 | ir_binop_bit_xor, |
| 272 | ir_binop_bit_or, |
| 273 | /*@}*/ |
| 274 | |
| 275 | ir_binop_logic_and, |
| 276 | ir_binop_logic_xor, |
| 277 | ir_binop_logic_or, |
| 278 | ir_binop_logic_not, |
| 279 | |
| 280 | ir_binop_dot, |
| 281 | ir_binop_min, |
| 282 | ir_binop_max, |
| 283 | |
| 284 | ir_binop_pow |
| 285 | }; |
| 286 | |
Kenneth Graunke | fb9fb5f | 2010-03-26 00:25:36 -0700 | [diff] [blame] | 287 | class ir_expression : public ir_rvalue { |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 288 | public: |
| 289 | ir_expression(int op, const struct glsl_type *type, |
Kenneth Graunke | fb9fb5f | 2010-03-26 00:25:36 -0700 | [diff] [blame] | 290 | ir_rvalue *, ir_rvalue *); |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 291 | |
Ian Romanick | 78b51b0 | 2010-03-09 16:23:37 -0800 | [diff] [blame] | 292 | virtual void accept(ir_visitor *v) |
| 293 | { |
| 294 | v->visit(this); |
| 295 | } |
| 296 | |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 297 | ir_expression_operation operation; |
Kenneth Graunke | fb9fb5f | 2010-03-26 00:25:36 -0700 | [diff] [blame] | 298 | ir_rvalue *operands[2]; |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 299 | }; |
| 300 | |
| 301 | |
Ian Romanick | ed45ec6 | 2010-03-11 14:34:27 -0800 | [diff] [blame] | 302 | /** |
| 303 | * IR instruction representing a function call |
| 304 | */ |
Kenneth Graunke | fb9fb5f | 2010-03-26 00:25:36 -0700 | [diff] [blame] | 305 | class ir_call : public ir_rvalue { |
Ian Romanick | ed45ec6 | 2010-03-11 14:34:27 -0800 | [diff] [blame] | 306 | public: |
Ian Romanick | 471471f | 2010-03-11 14:50:30 -0800 | [diff] [blame] | 307 | ir_call(const ir_function_signature *callee, exec_list *actual_parameters) |
Kenneth Graunke | fb9fb5f | 2010-03-26 00:25:36 -0700 | [diff] [blame] | 308 | : ir_rvalue(), callee(callee) |
Ian Romanick | ed45ec6 | 2010-03-11 14:34:27 -0800 | [diff] [blame] | 309 | { |
Ian Romanick | 9e7c34b | 2010-03-23 12:21:18 -0700 | [diff] [blame] | 310 | assert(callee->return_type != NULL); |
| 311 | type = callee->return_type; |
Ian Romanick | 471471f | 2010-03-11 14:50:30 -0800 | [diff] [blame] | 312 | actual_parameters->move_nodes_to(& this->actual_parameters); |
Ian Romanick | ed45ec6 | 2010-03-11 14:34:27 -0800 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | virtual void accept(ir_visitor *v) |
| 316 | { |
| 317 | v->visit(this); |
| 318 | } |
| 319 | |
| 320 | /** |
| 321 | * Get a generic ir_call object when an error occurs |
| 322 | */ |
| 323 | static ir_call *get_error_instruction(); |
| 324 | |
Ian Romanick | 9878c65 | 2010-03-26 17:19:47 -0700 | [diff] [blame] | 325 | /** |
| 326 | * Get an iterator for the set of acutal parameters |
| 327 | */ |
| 328 | exec_list_iterator iterator() |
| 329 | { |
| 330 | return actual_parameters.iterator(); |
| 331 | } |
| 332 | |
Ian Romanick | 93614bc | 2010-03-26 17:29:29 -0700 | [diff] [blame] | 333 | /** |
| 334 | * Get the name of the function being called. |
| 335 | */ |
| 336 | const char *callee_name() const |
| 337 | { |
| 338 | /* FINISHME: This only works for functions that have definitions. */ |
| 339 | return callee->definition->label; |
| 340 | } |
| 341 | |
Ian Romanick | ed45ec6 | 2010-03-11 14:34:27 -0800 | [diff] [blame] | 342 | private: |
Ian Romanick | 471471f | 2010-03-11 14:50:30 -0800 | [diff] [blame] | 343 | ir_call() |
Kenneth Graunke | fb9fb5f | 2010-03-26 00:25:36 -0700 | [diff] [blame] | 344 | : ir_rvalue(), callee(NULL) |
Ian Romanick | 471471f | 2010-03-11 14:50:30 -0800 | [diff] [blame] | 345 | { |
| 346 | /* empty */ |
| 347 | } |
| 348 | |
| 349 | const ir_function_signature *callee; |
Ian Romanick | ed45ec6 | 2010-03-11 14:34:27 -0800 | [diff] [blame] | 350 | exec_list actual_parameters; |
| 351 | }; |
| 352 | |
| 353 | |
Ian Romanick | 9578c87 | 2010-03-19 16:44:52 -0700 | [diff] [blame] | 354 | /** |
| 355 | * \name Jump-like IR instructions. |
| 356 | * |
| 357 | * These include \c break, \c continue, \c return, and \c discard. |
| 358 | */ |
| 359 | /*@{*/ |
| 360 | class ir_jump : public ir_instruction { |
| 361 | protected: |
| 362 | ir_jump() |
Kenneth Graunke | 44e1dfa | 2010-03-25 23:30:28 -0700 | [diff] [blame] | 363 | : ir_instruction() |
Ian Romanick | 9578c87 | 2010-03-19 16:44:52 -0700 | [diff] [blame] | 364 | { |
| 365 | /* empty */ |
| 366 | } |
| 367 | }; |
| 368 | |
| 369 | class ir_return : public ir_jump { |
| 370 | public: |
| 371 | ir_return() |
| 372 | : value(NULL) |
| 373 | { |
| 374 | /* empty */ |
| 375 | } |
| 376 | |
Kenneth Graunke | fb9fb5f | 2010-03-26 00:25:36 -0700 | [diff] [blame] | 377 | ir_return(ir_rvalue *value) |
Ian Romanick | 9578c87 | 2010-03-19 16:44:52 -0700 | [diff] [blame] | 378 | : value(value) |
| 379 | { |
| 380 | /* empty */ |
| 381 | } |
| 382 | |
Kenneth Graunke | fb9fb5f | 2010-03-26 00:25:36 -0700 | [diff] [blame] | 383 | ir_rvalue *get_value() const |
Ian Romanick | 9578c87 | 2010-03-19 16:44:52 -0700 | [diff] [blame] | 384 | { |
| 385 | return value; |
| 386 | } |
| 387 | |
| 388 | virtual void accept(ir_visitor *v) |
| 389 | { |
| 390 | v->visit(this); |
| 391 | } |
| 392 | |
| 393 | private: |
Kenneth Graunke | fb9fb5f | 2010-03-26 00:25:36 -0700 | [diff] [blame] | 394 | ir_rvalue *value; |
Ian Romanick | 9578c87 | 2010-03-19 16:44:52 -0700 | [diff] [blame] | 395 | }; |
| 396 | /*@}*/ |
| 397 | |
| 398 | |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 399 | struct ir_swizzle_mask { |
| 400 | unsigned x:2; |
| 401 | unsigned y:2; |
| 402 | unsigned z:2; |
| 403 | unsigned w:2; |
| 404 | |
| 405 | /** |
| 406 | * Number of components in the swizzle. |
| 407 | */ |
Kenneth Graunke | f25a5ad | 2010-03-25 11:22:42 -0700 | [diff] [blame] | 408 | unsigned num_components:3; |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 409 | |
| 410 | /** |
| 411 | * Does the swizzle contain duplicate components? |
| 412 | * |
| 413 | * L-value swizzles cannot contain duplicate components. |
| 414 | */ |
| 415 | unsigned has_duplicates:1; |
| 416 | }; |
| 417 | |
Kenneth Graunke | affc141 | 2010-03-26 01:20:08 -0700 | [diff] [blame] | 418 | |
| 419 | class ir_swizzle : public ir_rvalue { |
| 420 | public: |
| 421 | ir_swizzle(ir_rvalue *, unsigned x, unsigned y, unsigned z, unsigned w, |
| 422 | unsigned count); |
| 423 | /** |
| 424 | * Construct an ir_swizzle from the textual representation. Can fail. |
| 425 | */ |
| 426 | static ir_swizzle *create(ir_rvalue *, const char *, unsigned vector_length); |
| 427 | |
| 428 | virtual void accept(ir_visitor *v) |
| 429 | { |
| 430 | v->visit(this); |
| 431 | } |
| 432 | |
| 433 | bool is_lvalue() |
| 434 | { |
| 435 | return val->is_lvalue(); |
| 436 | } |
| 437 | |
| 438 | ir_rvalue *val; |
| 439 | ir_swizzle_mask mask; |
| 440 | }; |
| 441 | |
| 442 | |
Kenneth Graunke | fb9fb5f | 2010-03-26 00:25:36 -0700 | [diff] [blame] | 443 | class ir_dereference : public ir_rvalue { |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 444 | public: |
| 445 | ir_dereference(struct ir_instruction *); |
| 446 | |
Kenneth Graunke | fb9fb5f | 2010-03-26 00:25:36 -0700 | [diff] [blame] | 447 | ir_dereference(ir_instruction *variable, ir_rvalue *array_index); |
Ian Romanick | 9546997 | 2010-03-25 17:01:15 -0700 | [diff] [blame] | 448 | |
Kenneth Graunke | 44e1dfa | 2010-03-25 23:30:28 -0700 | [diff] [blame] | 449 | virtual ir_dereference *as_dereference() |
| 450 | { |
| 451 | return this; |
| 452 | } |
| 453 | |
Ian Romanick | 78b51b0 | 2010-03-09 16:23:37 -0800 | [diff] [blame] | 454 | virtual void accept(ir_visitor *v) |
| 455 | { |
| 456 | v->visit(this); |
| 457 | } |
| 458 | |
Kenneth Graunke | fb9fb5f | 2010-03-26 00:25:36 -0700 | [diff] [blame] | 459 | bool is_lvalue() |
| 460 | { |
Eric Anholt | c4f86d3 | 2010-03-26 15:51:45 -0700 | [diff] [blame] | 461 | ir_variable *as_var; |
| 462 | |
| 463 | if (var == NULL) |
| 464 | return NULL; |
| 465 | |
| 466 | as_var = var->as_variable(); |
| 467 | |
| 468 | if (as_var == NULL) |
| 469 | return NULL; |
| 470 | |
| 471 | return !as_var->read_only; |
Kenneth Graunke | fb9fb5f | 2010-03-26 00:25:36 -0700 | [diff] [blame] | 472 | } |
| 473 | |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 474 | enum { |
| 475 | ir_reference_variable, |
| 476 | ir_reference_array, |
| 477 | ir_reference_record |
| 478 | } mode; |
| 479 | |
| 480 | /** |
| 481 | * Object being dereferenced. |
| 482 | * |
Kenneth Graunke | fb9fb5f | 2010-03-26 00:25:36 -0700 | [diff] [blame] | 483 | * Must be either an \c ir_variable or an \c ir_rvalue. |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 484 | */ |
| 485 | ir_instruction *var; |
| 486 | |
| 487 | union { |
Kenneth Graunke | fb9fb5f | 2010-03-26 00:25:36 -0700 | [diff] [blame] | 488 | ir_rvalue *array_index; |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 489 | const char *field; |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 490 | } selector; |
| 491 | }; |
| 492 | |
| 493 | |
Kenneth Graunke | fb9fb5f | 2010-03-26 00:25:36 -0700 | [diff] [blame] | 494 | class ir_constant : public ir_rvalue { |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 495 | public: |
| 496 | ir_constant(const struct glsl_type *type, const void *data); |
Eric Anholt | 3c36b2d | 2010-03-26 12:07:44 -0700 | [diff] [blame] | 497 | ir_constant(bool b); |
| 498 | ir_constant(unsigned int u); |
| 499 | ir_constant(int i); |
| 500 | ir_constant(float f); |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 501 | |
Ian Romanick | 78b51b0 | 2010-03-09 16:23:37 -0800 | [diff] [blame] | 502 | virtual void accept(ir_visitor *v) |
| 503 | { |
| 504 | v->visit(this); |
| 505 | } |
| 506 | |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 507 | /** |
| 508 | * Value of the constant. |
| 509 | * |
| 510 | * The field used to back the values supplied by the constant is determined |
| 511 | * by the type associated with the \c ir_instruction. Constants may be |
| 512 | * scalars, vectors, or matrices. |
| 513 | */ |
| 514 | union { |
| 515 | unsigned u[16]; |
| 516 | int i[16]; |
| 517 | float f[16]; |
| 518 | bool b[16]; |
| 519 | } value; |
| 520 | }; |
| 521 | |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 522 | |
| 523 | extern void |
| 524 | _mesa_glsl_initialize_variables(exec_list *instructions, |
| 525 | struct _mesa_glsl_parse_state *state); |
Ian Romanick | e309a60 | 2010-03-15 15:20:15 -0700 | [diff] [blame] | 526 | |
Eric Anholt | c22c400 | 2010-03-26 18:20:30 -0700 | [diff] [blame] | 527 | extern void |
| 528 | _mesa_glsl_initialize_functions(exec_list *instructions, |
| 529 | struct _mesa_glsl_parse_state *state); |
| 530 | |
Ian Romanick | e309a60 | 2010-03-15 15:20:15 -0700 | [diff] [blame] | 531 | #endif /* IR_H */ |