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 | 1cf43a4 | 2010-03-30 16:56:50 -0700 | [diff] [blame] | 43 | class ir_constant *constant_expression_value(); |
Ian Romanick | 78b51b0 | 2010-03-09 16:23:37 -0800 | [diff] [blame] | 44 | virtual void accept(ir_visitor *) = 0; |
| 45 | |
Kenneth Graunke | 44e1dfa | 2010-03-25 23:30:28 -0700 | [diff] [blame] | 46 | /** |
| 47 | * \name IR instruction downcast functions |
| 48 | * |
| 49 | * These functions either cast the object to a derived class or return |
| 50 | * \c NULL if the object's type does not match the specified derived class. |
| 51 | * Additional downcast functions will be added as needed. |
| 52 | */ |
| 53 | /*@{*/ |
| 54 | virtual class ir_variable * as_variable() { return NULL; } |
Kenneth Graunke | 6202cbf | 2010-04-21 16:02:15 -0700 | [diff] [blame] | 55 | virtual class ir_function * as_function() { return NULL; } |
Kenneth Graunke | 44e1dfa | 2010-03-25 23:30:28 -0700 | [diff] [blame] | 56 | virtual class ir_dereference * as_dereference() { return NULL; } |
Kenneth Graunke | fb9fb5f | 2010-03-26 00:25:36 -0700 | [diff] [blame] | 57 | virtual class ir_rvalue * as_rvalue() { return NULL; } |
Eric Anholt | 7d21104 | 2010-04-16 16:43:47 -0700 | [diff] [blame] | 58 | virtual class ir_label * as_label() { return NULL; } |
Ian Romanick | 01f8de4 | 2010-04-05 17:13:14 -0700 | [diff] [blame] | 59 | virtual class ir_loop * as_loop() { return NULL; } |
Eric Anholt | cad9766 | 2010-04-07 11:46:26 -0700 | [diff] [blame] | 60 | virtual class ir_assignment * as_assignment() { return NULL; } |
| 61 | virtual class ir_call * as_call() { return NULL; } |
| 62 | virtual class ir_return * as_return() { return NULL; } |
Eric Anholt | 5ba9420 | 2010-04-14 17:03:03 -0700 | [diff] [blame] | 63 | virtual class ir_if * as_if() { return NULL; } |
Eric Anholt | 7d21104 | 2010-04-16 16:43:47 -0700 | [diff] [blame] | 64 | virtual class ir_swizzle * as_swizzle() { return NULL; } |
Eric Anholt | 5c89f0e | 2010-05-04 13:04:40 -0700 | [diff] [blame^] | 65 | virtual class ir_constant * as_constant() { return NULL; } |
Kenneth Graunke | 44e1dfa | 2010-03-25 23:30:28 -0700 | [diff] [blame] | 66 | /*@}*/ |
| 67 | |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 68 | protected: |
Kenneth Graunke | 44e1dfa | 2010-03-25 23:30:28 -0700 | [diff] [blame] | 69 | ir_instruction() |
Ian Romanick | d27ec24 | 2010-03-11 14:23:41 -0800 | [diff] [blame] | 70 | { |
| 71 | /* empty */ |
| 72 | } |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 73 | }; |
| 74 | |
| 75 | |
Kenneth Graunke | fb9fb5f | 2010-03-26 00:25:36 -0700 | [diff] [blame] | 76 | class ir_rvalue : public ir_instruction { |
| 77 | public: |
| 78 | virtual ir_rvalue * as_rvalue() |
| 79 | { |
| 80 | return this; |
| 81 | } |
| 82 | |
| 83 | virtual bool is_lvalue() |
| 84 | { |
| 85 | return false; |
| 86 | } |
| 87 | |
| 88 | protected: |
Ian Romanick | b427c91 | 2010-04-07 18:03:50 -0700 | [diff] [blame] | 89 | ir_rvalue() |
| 90 | { |
| 91 | /* empty */ |
| 92 | } |
Kenneth Graunke | fb9fb5f | 2010-03-26 00:25:36 -0700 | [diff] [blame] | 93 | }; |
| 94 | |
| 95 | |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 96 | enum ir_variable_mode { |
| 97 | ir_var_auto = 0, |
| 98 | ir_var_uniform, |
| 99 | ir_var_in, |
| 100 | ir_var_out, |
| 101 | ir_var_inout |
| 102 | }; |
| 103 | |
| 104 | enum ir_varaible_interpolation { |
| 105 | ir_var_smooth = 0, |
| 106 | ir_var_flat, |
| 107 | ir_var_noperspective |
| 108 | }; |
| 109 | |
Kenneth Graunke | fb9fb5f | 2010-03-26 00:25:36 -0700 | [diff] [blame] | 110 | |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 111 | class ir_variable : public ir_instruction { |
| 112 | public: |
| 113 | ir_variable(const struct glsl_type *, const char *); |
| 114 | |
Kenneth Graunke | 44e1dfa | 2010-03-25 23:30:28 -0700 | [diff] [blame] | 115 | virtual ir_variable *as_variable() |
| 116 | { |
| 117 | return this; |
| 118 | } |
| 119 | |
Ian Romanick | 78b51b0 | 2010-03-09 16:23:37 -0800 | [diff] [blame] | 120 | virtual void accept(ir_visitor *v) |
| 121 | { |
| 122 | v->visit(this); |
| 123 | } |
| 124 | |
Ian Romanick | 2d394d4 | 2010-03-31 17:52:44 -0700 | [diff] [blame] | 125 | /** |
| 126 | * Duplicate an IR variable |
| 127 | * |
| 128 | * \note |
| 129 | * This will probably be made \c virtual and moved to the base class |
| 130 | * eventually. |
| 131 | */ |
| 132 | ir_variable *clone() const |
| 133 | { |
| 134 | ir_variable *var = new ir_variable(type, name); |
| 135 | |
Ian Romanick | b8a21cc | 2010-04-01 18:31:11 -0700 | [diff] [blame] | 136 | var->max_array_access = this->max_array_access; |
Ian Romanick | 2d394d4 | 2010-03-31 17:52:44 -0700 | [diff] [blame] | 137 | var->read_only = this->read_only; |
| 138 | var->centroid = this->centroid; |
| 139 | var->invariant = this->invariant; |
| 140 | var->mode = this->mode; |
| 141 | var->interpolation = this->interpolation; |
| 142 | |
| 143 | return var; |
| 144 | } |
| 145 | |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 146 | const char *name; |
| 147 | |
Ian Romanick | b8a21cc | 2010-04-01 18:31:11 -0700 | [diff] [blame] | 148 | /** |
| 149 | * Highest element accessed with a constant expression array index |
| 150 | * |
| 151 | * Not used for non-array variables. |
| 152 | */ |
| 153 | unsigned max_array_access; |
| 154 | |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 155 | unsigned read_only:1; |
| 156 | unsigned centroid:1; |
| 157 | unsigned invariant:1; |
Eric Anholt | 71df19f | 2010-04-19 11:10:37 -0700 | [diff] [blame] | 158 | /** If the variable is initialized outside of the scope of the shader */ |
| 159 | unsigned shader_in:1; |
| 160 | /** |
| 161 | * If the variable value is later used outside of the scope of the shader. |
| 162 | */ |
| 163 | unsigned shader_out:1; |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 164 | |
| 165 | unsigned mode:3; |
| 166 | unsigned interpolation:2; |
Ian Romanick | 9d97537 | 2010-04-02 17:17:47 -0700 | [diff] [blame] | 167 | |
| 168 | /** |
| 169 | * Flag that the whole array is assignable |
| 170 | * |
| 171 | * In GLSL 1.20 and later whole arrays are assignable (and comparable for |
| 172 | * equality). This flag enables this behavior. |
| 173 | */ |
| 174 | unsigned array_lvalue:1; |
Eric Anholt | 326c676 | 2010-04-06 10:30:54 -0700 | [diff] [blame] | 175 | |
| 176 | /** |
Ian Romanick | c178c74 | 2010-04-07 16:53:54 -0700 | [diff] [blame] | 177 | * Emit a warning if this variable is accessed. |
| 178 | */ |
| 179 | const char *warn_extension; |
| 180 | |
| 181 | /** |
Eric Anholt | 326c676 | 2010-04-06 10:30:54 -0700 | [diff] [blame] | 182 | * Value assigned in the initializer of a variable declared "const" |
| 183 | */ |
| 184 | ir_constant *constant_value; |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 185 | }; |
| 186 | |
| 187 | |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 188 | /*@{*/ |
Kenneth Graunke | 9fa99f3 | 2010-04-21 12:30:22 -0700 | [diff] [blame] | 189 | /** |
| 190 | * The representation of a function instance; may be the full definition or |
| 191 | * simply a prototype. |
| 192 | */ |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 193 | class ir_function_signature : public ir_instruction { |
Eric Anholt | 894ea97 | 2010-04-07 13:19:11 -0700 | [diff] [blame] | 194 | /* An ir_function_signature will be part of the list of signatures in |
| 195 | * an ir_function. |
| 196 | */ |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 197 | public: |
Ian Romanick | e39cc69 | 2010-03-23 12:19:13 -0700 | [diff] [blame] | 198 | ir_function_signature(const glsl_type *return_type); |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 199 | |
Ian Romanick | 78b51b0 | 2010-03-09 16:23:37 -0800 | [diff] [blame] | 200 | virtual void accept(ir_visitor *v) |
| 201 | { |
| 202 | v->visit(this); |
| 203 | } |
| 204 | |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 205 | /** |
Ian Romanick | 0f0ea58 | 2010-03-31 16:44:12 -0700 | [diff] [blame] | 206 | * Get the name of the function for which this is a signature |
| 207 | */ |
| 208 | const char *function_name() const; |
| 209 | |
| 210 | /** |
Kenneth Graunke | abd40b1 | 2010-04-28 11:49:12 -0700 | [diff] [blame] | 211 | * Check whether the qualifiers match between this signature's parameters |
| 212 | * and the supplied parameter list. If not, returns the name of the first |
| 213 | * parameter with mismatched qualifiers (for use in error messages). |
| 214 | */ |
| 215 | const char *qualifiers_match(exec_list *params); |
| 216 | |
| 217 | /** |
Kenneth Graunke | bff6013 | 2010-04-28 12:44:24 -0700 | [diff] [blame] | 218 | * Replace the current parameter list with the given one. This is useful |
| 219 | * if the current information came from a prototype, and either has invalid |
| 220 | * or missing parameter names. |
| 221 | */ |
| 222 | void replace_parameters(exec_list *new_params); |
| 223 | |
| 224 | /** |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 225 | * Function return type. |
| 226 | * |
| 227 | * \note This discards the optional precision qualifier. |
| 228 | */ |
| 229 | const struct glsl_type *return_type; |
| 230 | |
| 231 | /** |
Eric Anholt | f1ddca9 | 2010-04-07 12:35:34 -0700 | [diff] [blame] | 232 | * List of ir_variable of function parameters. |
| 233 | * |
| 234 | * This represents the storage. The paramaters passed in a particular |
| 235 | * call will be in ir_call::actual_paramaters. |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 236 | */ |
Ian Romanick | 0044e7e | 2010-03-08 23:44:00 -0800 | [diff] [blame] | 237 | struct exec_list parameters; |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 238 | |
Kenneth Graunke | 9fa99f3 | 2010-04-21 12:30:22 -0700 | [diff] [blame] | 239 | /** Whether or not this function has a body (which may be empty). */ |
| 240 | unsigned is_defined:1; |
Ian Romanick | 6a15d5b | 2010-03-31 16:37:10 -0700 | [diff] [blame] | 241 | |
Eric Anholt | 894ea97 | 2010-04-07 13:19:11 -0700 | [diff] [blame] | 242 | /** Body of instructions in the function. */ |
| 243 | struct exec_list body; |
| 244 | |
Ian Romanick | 6a15d5b | 2010-03-31 16:37:10 -0700 | [diff] [blame] | 245 | private: |
| 246 | /** Function of which this signature is one overload. */ |
| 247 | class ir_function *function; |
| 248 | |
| 249 | friend class ir_function; |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 250 | }; |
| 251 | |
| 252 | |
| 253 | /** |
Kenneth Graunke | 9fa99f3 | 2010-04-21 12:30:22 -0700 | [diff] [blame] | 254 | * Header for tracking multiple overloaded functions with the same name. |
| 255 | * Contains a list of ir_function_signatures representing each of the |
| 256 | * actual functions. |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 257 | */ |
| 258 | class ir_function : public ir_instruction { |
| 259 | public: |
Ian Romanick | 882dad7 | 2010-03-23 17:42:04 -0700 | [diff] [blame] | 260 | ir_function(const char *name); |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 261 | |
Kenneth Graunke | 6202cbf | 2010-04-21 16:02:15 -0700 | [diff] [blame] | 262 | virtual ir_function *as_function() |
| 263 | { |
| 264 | return this; |
| 265 | } |
| 266 | |
Ian Romanick | 78b51b0 | 2010-03-09 16:23:37 -0800 | [diff] [blame] | 267 | virtual void accept(ir_visitor *v) |
| 268 | { |
| 269 | v->visit(this); |
| 270 | } |
| 271 | |
Ian Romanick | 6a15d5b | 2010-03-31 16:37:10 -0700 | [diff] [blame] | 272 | void add_signature(ir_function_signature *sig) |
| 273 | { |
| 274 | sig->function = this; |
| 275 | signatures.push_tail(sig); |
| 276 | } |
| 277 | |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 278 | /** |
Ian Romanick | 95cd6cc | 2010-03-31 16:40:26 -0700 | [diff] [blame] | 279 | * Get an iterator for the set of function signatures |
| 280 | */ |
| 281 | exec_list_iterator iterator() |
| 282 | { |
| 283 | return signatures.iterator(); |
| 284 | } |
| 285 | |
| 286 | /** |
Kenneth Graunke | 0d605cb | 2010-04-28 12:04:23 -0700 | [diff] [blame] | 287 | * Find a signature that matches a set of actual parameters, taking implicit |
| 288 | * conversions into account. |
Ian Romanick | 471471f | 2010-03-11 14:50:30 -0800 | [diff] [blame] | 289 | */ |
| 290 | const ir_function_signature *matching_signature(exec_list *actual_param); |
| 291 | |
| 292 | /** |
Kenneth Graunke | 0d605cb | 2010-04-28 12:04:23 -0700 | [diff] [blame] | 293 | * Find a signature that exactly matches a set of actual parameters without |
| 294 | * any implicit type conversions. |
| 295 | */ |
| 296 | ir_function_signature *exact_matching_signature(exec_list *actual_ps); |
| 297 | |
| 298 | /** |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 299 | * Name of the function. |
| 300 | */ |
| 301 | const char *name; |
| 302 | |
Ian Romanick | a477582 | 2010-03-31 16:40:58 -0700 | [diff] [blame] | 303 | private: |
Ian Romanick | 471471f | 2010-03-11 14:50:30 -0800 | [diff] [blame] | 304 | /** |
Eric Anholt | f1ddca9 | 2010-04-07 12:35:34 -0700 | [diff] [blame] | 305 | * List of ir_function_signature for each overloaded function with this name. |
Ian Romanick | 471471f | 2010-03-11 14:50:30 -0800 | [diff] [blame] | 306 | */ |
Ian Romanick | 0044e7e | 2010-03-08 23:44:00 -0800 | [diff] [blame] | 307 | struct exec_list signatures; |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 308 | }; |
Ian Romanick | 0f0ea58 | 2010-03-31 16:44:12 -0700 | [diff] [blame] | 309 | |
| 310 | inline const char *ir_function_signature::function_name() const |
| 311 | { |
| 312 | return function->name; |
| 313 | } |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 314 | /*@}*/ |
| 315 | |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 316 | |
Ian Romanick | 3c6fea3 | 2010-03-29 14:11:25 -0700 | [diff] [blame] | 317 | /** |
| 318 | * IR instruction representing high-level if-statements |
| 319 | */ |
| 320 | class ir_if : public ir_instruction { |
| 321 | public: |
| 322 | ir_if(ir_rvalue *condition) |
| 323 | : condition(condition) |
| 324 | { |
| 325 | /* empty */ |
| 326 | } |
| 327 | |
Eric Anholt | 5ba9420 | 2010-04-14 17:03:03 -0700 | [diff] [blame] | 328 | virtual ir_if *as_if() |
| 329 | { |
| 330 | return this; |
| 331 | } |
| 332 | |
Ian Romanick | 3c6fea3 | 2010-03-29 14:11:25 -0700 | [diff] [blame] | 333 | virtual void accept(ir_visitor *v) |
| 334 | { |
| 335 | v->visit(this); |
| 336 | } |
| 337 | |
| 338 | ir_rvalue *condition; |
Eric Anholt | f1ddca9 | 2010-04-07 12:35:34 -0700 | [diff] [blame] | 339 | /** List of ir_instruction for the body of the then branch */ |
Ian Romanick | 3c6fea3 | 2010-03-29 14:11:25 -0700 | [diff] [blame] | 340 | exec_list then_instructions; |
Eric Anholt | f1ddca9 | 2010-04-07 12:35:34 -0700 | [diff] [blame] | 341 | /** List of ir_instruction for the body of the else branch */ |
Ian Romanick | 3c6fea3 | 2010-03-29 14:11:25 -0700 | [diff] [blame] | 342 | exec_list else_instructions; |
| 343 | }; |
| 344 | |
| 345 | |
Ian Romanick | fad607a | 2010-04-05 16:16:07 -0700 | [diff] [blame] | 346 | /** |
| 347 | * IR instruction representing a high-level loop structure. |
| 348 | */ |
| 349 | class ir_loop : public ir_instruction { |
| 350 | public: |
| 351 | ir_loop() : from(NULL), to(NULL), increment(NULL), counter(NULL) |
| 352 | { |
| 353 | /* empty */ |
| 354 | } |
| 355 | |
| 356 | virtual void accept(ir_visitor *v) |
| 357 | { |
| 358 | v->visit(this); |
| 359 | } |
| 360 | |
Ian Romanick | 01f8de4 | 2010-04-05 17:13:14 -0700 | [diff] [blame] | 361 | virtual ir_loop *as_loop() |
| 362 | { |
| 363 | return this; |
| 364 | } |
| 365 | |
Ian Romanick | fad607a | 2010-04-05 16:16:07 -0700 | [diff] [blame] | 366 | /** |
| 367 | * Get an iterator for the instructions of the loop body |
| 368 | */ |
| 369 | exec_list_iterator iterator() |
| 370 | { |
| 371 | return body_instructions.iterator(); |
| 372 | } |
| 373 | |
Eric Anholt | f1ddca9 | 2010-04-07 12:35:34 -0700 | [diff] [blame] | 374 | /** List of ir_instruction that make up the body of the loop. */ |
Ian Romanick | fad607a | 2010-04-05 16:16:07 -0700 | [diff] [blame] | 375 | exec_list body_instructions; |
| 376 | |
| 377 | /** |
| 378 | * \name Loop counter and controls |
| 379 | */ |
| 380 | /*@{*/ |
| 381 | ir_rvalue *from; |
| 382 | ir_rvalue *to; |
| 383 | ir_rvalue *increment; |
| 384 | ir_variable *counter; |
| 385 | /*@}*/ |
| 386 | }; |
| 387 | |
| 388 | |
Kenneth Graunke | fb9fb5f | 2010-03-26 00:25:36 -0700 | [diff] [blame] | 389 | class ir_assignment : public ir_rvalue { |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 390 | public: |
Kenneth Graunke | fb9fb5f | 2010-03-26 00:25:36 -0700 | [diff] [blame] | 391 | ir_assignment(ir_rvalue *lhs, ir_rvalue *rhs, ir_rvalue *condition); |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 392 | |
Ian Romanick | 78b51b0 | 2010-03-09 16:23:37 -0800 | [diff] [blame] | 393 | virtual void accept(ir_visitor *v) |
| 394 | { |
| 395 | v->visit(this); |
| 396 | } |
| 397 | |
Eric Anholt | cad9766 | 2010-04-07 11:46:26 -0700 | [diff] [blame] | 398 | virtual ir_assignment * as_assignment() |
| 399 | { |
| 400 | return this; |
| 401 | } |
| 402 | |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 403 | /** |
| 404 | * Left-hand side of the assignment. |
| 405 | */ |
Kenneth Graunke | fb9fb5f | 2010-03-26 00:25:36 -0700 | [diff] [blame] | 406 | ir_rvalue *lhs; |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 407 | |
| 408 | /** |
| 409 | * Value being assigned |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 410 | */ |
Kenneth Graunke | fb9fb5f | 2010-03-26 00:25:36 -0700 | [diff] [blame] | 411 | ir_rvalue *rhs; |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 412 | |
| 413 | /** |
| 414 | * Optional condition for the assignment. |
| 415 | */ |
Kenneth Graunke | fb9fb5f | 2010-03-26 00:25:36 -0700 | [diff] [blame] | 416 | ir_rvalue *condition; |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 417 | }; |
| 418 | |
Kenneth Graunke | 3b96996 | 2010-04-07 17:18:29 -0700 | [diff] [blame] | 419 | /* Update ir_expression::num_operands() and operator_strs when |
Eric Anholt | 160d092 | 2010-04-01 18:07:08 -1000 | [diff] [blame] | 420 | * updating this list. |
Kenneth Graunke | 3b96996 | 2010-04-07 17:18:29 -0700 | [diff] [blame] | 421 | */ |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 422 | enum ir_expression_operation { |
| 423 | ir_unop_bit_not, |
| 424 | ir_unop_logic_not, |
| 425 | ir_unop_neg, |
| 426 | ir_unop_abs, |
| 427 | ir_unop_rcp, |
| 428 | ir_unop_rsq, |
Eric Anholt | 44d68fd | 2010-03-27 13:01:51 -0700 | [diff] [blame] | 429 | ir_unop_sqrt, |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 430 | ir_unop_exp, |
| 431 | ir_unop_log, |
Eric Anholt | 0166526 | 2010-03-27 13:56:35 -0700 | [diff] [blame] | 432 | ir_unop_exp2, |
| 433 | ir_unop_log2, |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 434 | ir_unop_f2i, /**< Float-to-integer conversion. */ |
| 435 | ir_unop_i2f, /**< Integer-to-float conversion. */ |
Eric Anholt | dc58b3f | 2010-04-02 02:13:43 -1000 | [diff] [blame] | 436 | ir_unop_f2b, /**< Float-to-boolean conversion */ |
| 437 | ir_unop_b2f, /**< Boolean-to-float conversion */ |
Eric Anholt | c2cb84e | 2010-04-02 02:17:08 -1000 | [diff] [blame] | 438 | ir_unop_i2b, /**< int-to-boolean conversion */ |
| 439 | ir_unop_b2i, /**< Boolean-to-int conversion */ |
Ian Romanick | 6c86ea8 | 2010-03-26 16:11:48 -0700 | [diff] [blame] | 440 | ir_unop_u2f, /**< Unsigned-to-float conversion. */ |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 441 | |
| 442 | /** |
| 443 | * \name Unary floating-point rounding operations. |
| 444 | */ |
| 445 | /*@{*/ |
| 446 | ir_unop_trunc, |
| 447 | ir_unop_ceil, |
| 448 | ir_unop_floor, |
| 449 | /*@}*/ |
| 450 | |
| 451 | ir_binop_add, |
| 452 | ir_binop_sub, |
| 453 | ir_binop_mul, |
| 454 | ir_binop_div, |
| 455 | ir_binop_mod, |
| 456 | |
| 457 | /** |
| 458 | * \name Binary comparison operators |
| 459 | */ |
| 460 | /*@{*/ |
| 461 | ir_binop_less, |
| 462 | ir_binop_greater, |
| 463 | ir_binop_lequal, |
| 464 | ir_binop_gequal, |
| 465 | ir_binop_equal, |
| 466 | ir_binop_nequal, |
| 467 | /*@}*/ |
| 468 | |
| 469 | /** |
| 470 | * \name Bit-wise binary operations. |
| 471 | */ |
| 472 | /*@{*/ |
| 473 | ir_binop_lshift, |
| 474 | ir_binop_rshift, |
| 475 | ir_binop_bit_and, |
| 476 | ir_binop_bit_xor, |
| 477 | ir_binop_bit_or, |
| 478 | /*@}*/ |
| 479 | |
| 480 | ir_binop_logic_and, |
| 481 | ir_binop_logic_xor, |
| 482 | ir_binop_logic_or, |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 483 | |
| 484 | ir_binop_dot, |
| 485 | ir_binop_min, |
| 486 | ir_binop_max, |
| 487 | |
| 488 | ir_binop_pow |
| 489 | }; |
| 490 | |
Kenneth Graunke | fb9fb5f | 2010-03-26 00:25:36 -0700 | [diff] [blame] | 491 | class ir_expression : public ir_rvalue { |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 492 | public: |
| 493 | ir_expression(int op, const struct glsl_type *type, |
Kenneth Graunke | fb9fb5f | 2010-03-26 00:25:36 -0700 | [diff] [blame] | 494 | ir_rvalue *, ir_rvalue *); |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 495 | |
Kenneth Graunke | 7dd6adb | 2010-04-07 16:56:57 -0700 | [diff] [blame] | 496 | static unsigned int get_num_operands(ir_expression_operation); |
| 497 | unsigned int get_num_operands() |
| 498 | { |
| 499 | return get_num_operands(operation); |
| 500 | } |
Eric Anholt | 160d092 | 2010-04-01 18:07:08 -1000 | [diff] [blame] | 501 | |
Kenneth Graunke | 3b96996 | 2010-04-07 17:18:29 -0700 | [diff] [blame] | 502 | /** |
| 503 | * Return a string representing this expression's operator. |
| 504 | */ |
| 505 | const char *operator_string(); |
| 506 | |
| 507 | /** |
| 508 | * Do a reverse-lookup to translate the given string into an operator. |
| 509 | */ |
| 510 | static ir_expression_operation get_operator(const char *); |
| 511 | |
Ian Romanick | 78b51b0 | 2010-03-09 16:23:37 -0800 | [diff] [blame] | 512 | virtual void accept(ir_visitor *v) |
| 513 | { |
| 514 | v->visit(this); |
| 515 | } |
| 516 | |
Eric Anholt | cad9766 | 2010-04-07 11:46:26 -0700 | [diff] [blame] | 517 | ir_expression *clone(); |
| 518 | |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 519 | ir_expression_operation operation; |
Kenneth Graunke | fb9fb5f | 2010-03-26 00:25:36 -0700 | [diff] [blame] | 520 | ir_rvalue *operands[2]; |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 521 | }; |
| 522 | |
| 523 | |
Ian Romanick | ed45ec6 | 2010-03-11 14:34:27 -0800 | [diff] [blame] | 524 | /** |
| 525 | * IR instruction representing a function call |
| 526 | */ |
Kenneth Graunke | fb9fb5f | 2010-03-26 00:25:36 -0700 | [diff] [blame] | 527 | class ir_call : public ir_rvalue { |
Ian Romanick | ed45ec6 | 2010-03-11 14:34:27 -0800 | [diff] [blame] | 528 | public: |
Ian Romanick | 471471f | 2010-03-11 14:50:30 -0800 | [diff] [blame] | 529 | ir_call(const ir_function_signature *callee, exec_list *actual_parameters) |
Ian Romanick | b427c91 | 2010-04-07 18:03:50 -0700 | [diff] [blame] | 530 | : callee(callee) |
Ian Romanick | ed45ec6 | 2010-03-11 14:34:27 -0800 | [diff] [blame] | 531 | { |
Ian Romanick | 9e7c34b | 2010-03-23 12:21:18 -0700 | [diff] [blame] | 532 | assert(callee->return_type != NULL); |
| 533 | type = callee->return_type; |
Ian Romanick | 471471f | 2010-03-11 14:50:30 -0800 | [diff] [blame] | 534 | actual_parameters->move_nodes_to(& this->actual_parameters); |
Ian Romanick | ed45ec6 | 2010-03-11 14:34:27 -0800 | [diff] [blame] | 535 | } |
| 536 | |
Eric Anholt | cad9766 | 2010-04-07 11:46:26 -0700 | [diff] [blame] | 537 | virtual ir_call *as_call() |
| 538 | { |
| 539 | return this; |
| 540 | } |
| 541 | |
Ian Romanick | ed45ec6 | 2010-03-11 14:34:27 -0800 | [diff] [blame] | 542 | virtual void accept(ir_visitor *v) |
| 543 | { |
| 544 | v->visit(this); |
| 545 | } |
| 546 | |
| 547 | /** |
| 548 | * Get a generic ir_call object when an error occurs |
| 549 | */ |
| 550 | static ir_call *get_error_instruction(); |
| 551 | |
Ian Romanick | 9878c65 | 2010-03-26 17:19:47 -0700 | [diff] [blame] | 552 | /** |
| 553 | * Get an iterator for the set of acutal parameters |
| 554 | */ |
| 555 | exec_list_iterator iterator() |
| 556 | { |
| 557 | return actual_parameters.iterator(); |
| 558 | } |
| 559 | |
Ian Romanick | 93614bc | 2010-03-26 17:29:29 -0700 | [diff] [blame] | 560 | /** |
| 561 | * Get the name of the function being called. |
| 562 | */ |
| 563 | const char *callee_name() const |
| 564 | { |
Ian Romanick | 0f0ea58 | 2010-03-31 16:44:12 -0700 | [diff] [blame] | 565 | return callee->function_name(); |
Ian Romanick | 93614bc | 2010-03-26 17:29:29 -0700 | [diff] [blame] | 566 | } |
| 567 | |
Eric Anholt | cad9766 | 2010-04-07 11:46:26 -0700 | [diff] [blame] | 568 | const ir_function_signature *get_callee() |
| 569 | { |
| 570 | return callee; |
| 571 | } |
| 572 | |
| 573 | /** |
| 574 | * Generates an inline version of the function before @ir, |
| 575 | * returning the return value of the function. |
| 576 | */ |
| 577 | ir_rvalue *generate_inline(ir_instruction *ir); |
| 578 | |
Ian Romanick | ed45ec6 | 2010-03-11 14:34:27 -0800 | [diff] [blame] | 579 | private: |
Ian Romanick | 471471f | 2010-03-11 14:50:30 -0800 | [diff] [blame] | 580 | ir_call() |
Ian Romanick | b427c91 | 2010-04-07 18:03:50 -0700 | [diff] [blame] | 581 | : callee(NULL) |
Ian Romanick | 471471f | 2010-03-11 14:50:30 -0800 | [diff] [blame] | 582 | { |
| 583 | /* empty */ |
| 584 | } |
| 585 | |
| 586 | const ir_function_signature *callee; |
Eric Anholt | f1ddca9 | 2010-04-07 12:35:34 -0700 | [diff] [blame] | 587 | |
| 588 | /* List of ir_rvalue of paramaters passed in this call. */ |
Ian Romanick | ed45ec6 | 2010-03-11 14:34:27 -0800 | [diff] [blame] | 589 | exec_list actual_parameters; |
| 590 | }; |
| 591 | |
| 592 | |
Ian Romanick | 9578c87 | 2010-03-19 16:44:52 -0700 | [diff] [blame] | 593 | /** |
| 594 | * \name Jump-like IR instructions. |
| 595 | * |
| 596 | * These include \c break, \c continue, \c return, and \c discard. |
| 597 | */ |
| 598 | /*@{*/ |
| 599 | class ir_jump : public ir_instruction { |
| 600 | protected: |
| 601 | ir_jump() |
Ian Romanick | 9578c87 | 2010-03-19 16:44:52 -0700 | [diff] [blame] | 602 | { |
| 603 | /* empty */ |
| 604 | } |
| 605 | }; |
| 606 | |
| 607 | class ir_return : public ir_jump { |
| 608 | public: |
| 609 | ir_return() |
| 610 | : value(NULL) |
| 611 | { |
| 612 | /* empty */ |
| 613 | } |
| 614 | |
Kenneth Graunke | fb9fb5f | 2010-03-26 00:25:36 -0700 | [diff] [blame] | 615 | ir_return(ir_rvalue *value) |
Ian Romanick | 9578c87 | 2010-03-19 16:44:52 -0700 | [diff] [blame] | 616 | : value(value) |
| 617 | { |
| 618 | /* empty */ |
| 619 | } |
| 620 | |
Eric Anholt | cad9766 | 2010-04-07 11:46:26 -0700 | [diff] [blame] | 621 | virtual ir_return *as_return() |
| 622 | { |
| 623 | return this; |
| 624 | } |
| 625 | |
Kenneth Graunke | fb9fb5f | 2010-03-26 00:25:36 -0700 | [diff] [blame] | 626 | ir_rvalue *get_value() const |
Ian Romanick | 9578c87 | 2010-03-19 16:44:52 -0700 | [diff] [blame] | 627 | { |
| 628 | return value; |
| 629 | } |
| 630 | |
| 631 | virtual void accept(ir_visitor *v) |
| 632 | { |
| 633 | v->visit(this); |
| 634 | } |
| 635 | |
| 636 | private: |
Kenneth Graunke | fb9fb5f | 2010-03-26 00:25:36 -0700 | [diff] [blame] | 637 | ir_rvalue *value; |
Ian Romanick | 9578c87 | 2010-03-19 16:44:52 -0700 | [diff] [blame] | 638 | }; |
Ian Romanick | f8e31e0 | 2010-04-05 16:28:15 -0700 | [diff] [blame] | 639 | |
| 640 | |
| 641 | /** |
| 642 | * Jump instructions used inside loops |
| 643 | * |
| 644 | * These include \c break and \c continue. The \c break within a loop is |
| 645 | * different from the \c break within a switch-statement. |
| 646 | * |
| 647 | * \sa ir_switch_jump |
| 648 | */ |
| 649 | class ir_loop_jump : public ir_jump { |
| 650 | public: |
| 651 | enum jump_mode { |
| 652 | jump_break, |
| 653 | jump_continue |
| 654 | }; |
| 655 | |
| 656 | ir_loop_jump(ir_loop *loop, jump_mode mode) |
| 657 | : loop(loop), mode(mode) |
| 658 | { |
| 659 | /* empty */ |
| 660 | } |
| 661 | |
| 662 | virtual void accept(ir_visitor *v) |
| 663 | { |
| 664 | v->visit(this); |
| 665 | } |
| 666 | |
| 667 | bool is_break() const |
| 668 | { |
| 669 | return mode == jump_break; |
| 670 | } |
| 671 | |
| 672 | bool is_continue() const |
| 673 | { |
| 674 | return mode == jump_continue; |
| 675 | } |
| 676 | |
| 677 | private: |
| 678 | /** Loop containing this break instruction. */ |
| 679 | ir_loop *loop; |
| 680 | |
| 681 | /** Mode selector for the jump instruction. */ |
| 682 | enum jump_mode mode; |
| 683 | }; |
Ian Romanick | 9578c87 | 2010-03-19 16:44:52 -0700 | [diff] [blame] | 684 | /*@}*/ |
| 685 | |
| 686 | |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 687 | struct ir_swizzle_mask { |
| 688 | unsigned x:2; |
| 689 | unsigned y:2; |
| 690 | unsigned z:2; |
| 691 | unsigned w:2; |
| 692 | |
| 693 | /** |
| 694 | * Number of components in the swizzle. |
| 695 | */ |
Kenneth Graunke | f25a5ad | 2010-03-25 11:22:42 -0700 | [diff] [blame] | 696 | unsigned num_components:3; |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 697 | |
| 698 | /** |
| 699 | * Does the swizzle contain duplicate components? |
| 700 | * |
| 701 | * L-value swizzles cannot contain duplicate components. |
| 702 | */ |
| 703 | unsigned has_duplicates:1; |
| 704 | }; |
| 705 | |
Kenneth Graunke | affc141 | 2010-03-26 01:20:08 -0700 | [diff] [blame] | 706 | |
| 707 | class ir_swizzle : public ir_rvalue { |
| 708 | public: |
| 709 | ir_swizzle(ir_rvalue *, unsigned x, unsigned y, unsigned z, unsigned w, |
| 710 | unsigned count); |
Eric Anholt | 05a4e59 | 2010-05-03 17:08:01 -0700 | [diff] [blame] | 711 | ir_swizzle(ir_rvalue *val, ir_swizzle_mask mask); |
Eric Anholt | cad9766 | 2010-04-07 11:46:26 -0700 | [diff] [blame] | 712 | |
Eric Anholt | 7d21104 | 2010-04-16 16:43:47 -0700 | [diff] [blame] | 713 | virtual ir_swizzle *as_swizzle() |
| 714 | { |
| 715 | return this; |
| 716 | } |
| 717 | |
Eric Anholt | cad9766 | 2010-04-07 11:46:26 -0700 | [diff] [blame] | 718 | ir_swizzle *clone() |
| 719 | { |
| 720 | return new ir_swizzle(this->val, this->mask); |
| 721 | } |
| 722 | |
Kenneth Graunke | affc141 | 2010-03-26 01:20:08 -0700 | [diff] [blame] | 723 | /** |
| 724 | * Construct an ir_swizzle from the textual representation. Can fail. |
| 725 | */ |
| 726 | static ir_swizzle *create(ir_rvalue *, const char *, unsigned vector_length); |
| 727 | |
| 728 | virtual void accept(ir_visitor *v) |
| 729 | { |
| 730 | v->visit(this); |
| 731 | } |
| 732 | |
| 733 | bool is_lvalue() |
| 734 | { |
Eric Anholt | a9fafc6 | 2010-03-28 01:29:18 -0700 | [diff] [blame] | 735 | return val->is_lvalue() && !mask.has_duplicates; |
Kenneth Graunke | affc141 | 2010-03-26 01:20:08 -0700 | [diff] [blame] | 736 | } |
| 737 | |
| 738 | ir_rvalue *val; |
| 739 | ir_swizzle_mask mask; |
| 740 | }; |
| 741 | |
| 742 | |
Kenneth Graunke | fb9fb5f | 2010-03-26 00:25:36 -0700 | [diff] [blame] | 743 | class ir_dereference : public ir_rvalue { |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 744 | public: |
| 745 | ir_dereference(struct ir_instruction *); |
| 746 | |
Kenneth Graunke | fb9fb5f | 2010-03-26 00:25:36 -0700 | [diff] [blame] | 747 | ir_dereference(ir_instruction *variable, ir_rvalue *array_index); |
Ian Romanick | 9546997 | 2010-03-25 17:01:15 -0700 | [diff] [blame] | 748 | |
Ian Romanick | 7ee79fb | 2010-04-19 15:40:49 -0700 | [diff] [blame] | 749 | ir_dereference(ir_instruction *variable, const char *field); |
| 750 | |
Kenneth Graunke | 44e1dfa | 2010-03-25 23:30:28 -0700 | [diff] [blame] | 751 | virtual ir_dereference *as_dereference() |
| 752 | { |
| 753 | return this; |
| 754 | } |
| 755 | |
Ian Romanick | 78b51b0 | 2010-03-09 16:23:37 -0800 | [diff] [blame] | 756 | virtual void accept(ir_visitor *v) |
| 757 | { |
| 758 | v->visit(this); |
| 759 | } |
| 760 | |
Eric Anholt | c7da28b | 2010-04-01 20:27:35 -1000 | [diff] [blame] | 761 | bool is_lvalue(); |
Kenneth Graunke | fb9fb5f | 2010-03-26 00:25:36 -0700 | [diff] [blame] | 762 | |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 763 | enum { |
| 764 | ir_reference_variable, |
| 765 | ir_reference_array, |
| 766 | ir_reference_record |
| 767 | } mode; |
| 768 | |
| 769 | /** |
| 770 | * Object being dereferenced. |
| 771 | * |
Kenneth Graunke | fb9fb5f | 2010-03-26 00:25:36 -0700 | [diff] [blame] | 772 | * Must be either an \c ir_variable or an \c ir_rvalue. |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 773 | */ |
| 774 | ir_instruction *var; |
| 775 | |
| 776 | union { |
Kenneth Graunke | fb9fb5f | 2010-03-26 00:25:36 -0700 | [diff] [blame] | 777 | ir_rvalue *array_index; |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 778 | const char *field; |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 779 | } selector; |
| 780 | }; |
| 781 | |
| 782 | |
Kenneth Graunke | fb9fb5f | 2010-03-26 00:25:36 -0700 | [diff] [blame] | 783 | class ir_constant : public ir_rvalue { |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 784 | public: |
| 785 | ir_constant(const struct glsl_type *type, const void *data); |
Eric Anholt | 3c36b2d | 2010-03-26 12:07:44 -0700 | [diff] [blame] | 786 | ir_constant(bool b); |
| 787 | ir_constant(unsigned int u); |
| 788 | ir_constant(int i); |
| 789 | ir_constant(float f); |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 790 | |
Eric Anholt | 5c89f0e | 2010-05-04 13:04:40 -0700 | [diff] [blame^] | 791 | virtual ir_constant *as_constant() |
| 792 | { |
| 793 | return this; |
| 794 | } |
| 795 | |
Ian Romanick | 78b51b0 | 2010-03-09 16:23:37 -0800 | [diff] [blame] | 796 | virtual void accept(ir_visitor *v) |
| 797 | { |
| 798 | v->visit(this); |
| 799 | } |
| 800 | |
Eric Anholt | cad9766 | 2010-04-07 11:46:26 -0700 | [diff] [blame] | 801 | ir_constant *clone() |
| 802 | { |
| 803 | return new ir_constant(this->type, &this->value); |
| 804 | } |
| 805 | |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 806 | /** |
| 807 | * Value of the constant. |
| 808 | * |
| 809 | * The field used to back the values supplied by the constant is determined |
| 810 | * by the type associated with the \c ir_instruction. Constants may be |
| 811 | * scalars, vectors, or matrices. |
| 812 | */ |
| 813 | union { |
| 814 | unsigned u[16]; |
| 815 | int i[16]; |
| 816 | float f[16]; |
| 817 | bool b[16]; |
| 818 | } value; |
| 819 | }; |
| 820 | |
Eric Anholt | 70b7492 | 2010-04-06 11:52:09 -0700 | [diff] [blame] | 821 | void |
| 822 | visit_exec_list(exec_list *list, ir_visitor *visitor); |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 823 | |
| 824 | extern void |
| 825 | _mesa_glsl_initialize_variables(exec_list *instructions, |
| 826 | struct _mesa_glsl_parse_state *state); |
Ian Romanick | e309a60 | 2010-03-15 15:20:15 -0700 | [diff] [blame] | 827 | |
Eric Anholt | c22c400 | 2010-03-26 18:20:30 -0700 | [diff] [blame] | 828 | extern void |
| 829 | _mesa_glsl_initialize_functions(exec_list *instructions, |
| 830 | struct _mesa_glsl_parse_state *state); |
| 831 | |
Ian Romanick | e309a60 | 2010-03-15 15:20:15 -0700 | [diff] [blame] | 832 | #endif /* IR_H */ |