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 | 8895bae | 2010-05-14 12:39:23 -0700 | [diff] [blame] | 31 | #include "ir_hierarchical_visitor.h" |
Ian Romanick | 0044e7e | 2010-03-08 23:44:00 -0800 | [diff] [blame] | 32 | |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 33 | struct ir_program { |
| 34 | void *bong_hits; |
| 35 | }; |
| 36 | |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 37 | /** |
| 38 | * Base class of all IR instructions |
| 39 | */ |
Ian Romanick | 0044e7e | 2010-03-08 23:44:00 -0800 | [diff] [blame] | 40 | class ir_instruction : public exec_node { |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 41 | public: |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 42 | const struct glsl_type *type; |
| 43 | |
Ian Romanick | 1cf43a4 | 2010-03-30 16:56:50 -0700 | [diff] [blame] | 44 | class ir_constant *constant_expression_value(); |
Ian Romanick | 78b51b0 | 2010-03-09 16:23:37 -0800 | [diff] [blame] | 45 | virtual void accept(ir_visitor *) = 0; |
Ian Romanick | 8895bae | 2010-05-14 12:39:23 -0700 | [diff] [blame] | 46 | virtual ir_visitor_status accept(ir_hierarchical_visitor *) = 0; |
Ian Romanick | 78b51b0 | 2010-03-09 16:23:37 -0800 | [diff] [blame] | 47 | |
Kenneth Graunke | 44e1dfa | 2010-03-25 23:30:28 -0700 | [diff] [blame] | 48 | /** |
| 49 | * \name IR instruction downcast functions |
| 50 | * |
| 51 | * These functions either cast the object to a derived class or return |
| 52 | * \c NULL if the object's type does not match the specified derived class. |
| 53 | * Additional downcast functions will be added as needed. |
| 54 | */ |
| 55 | /*@{*/ |
| 56 | virtual class ir_variable * as_variable() { return NULL; } |
Kenneth Graunke | 6202cbf | 2010-04-21 16:02:15 -0700 | [diff] [blame] | 57 | virtual class ir_function * as_function() { return NULL; } |
Kenneth Graunke | 44e1dfa | 2010-03-25 23:30:28 -0700 | [diff] [blame] | 58 | virtual class ir_dereference * as_dereference() { return NULL; } |
Eric Anholt | b145e90 | 2010-05-11 11:31:09 -0700 | [diff] [blame] | 59 | virtual class ir_dereference_array * as_dereference_array() { return NULL; } |
Kenneth Graunke | fb9fb5f | 2010-03-26 00:25:36 -0700 | [diff] [blame] | 60 | virtual class ir_rvalue * as_rvalue() { return NULL; } |
Ian Romanick | 01f8de4 | 2010-04-05 17:13:14 -0700 | [diff] [blame] | 61 | virtual class ir_loop * as_loop() { return NULL; } |
Eric Anholt | cad9766 | 2010-04-07 11:46:26 -0700 | [diff] [blame] | 62 | virtual class ir_assignment * as_assignment() { return NULL; } |
| 63 | virtual class ir_call * as_call() { return NULL; } |
| 64 | virtual class ir_return * as_return() { return NULL; } |
Eric Anholt | 5ba9420 | 2010-04-14 17:03:03 -0700 | [diff] [blame] | 65 | virtual class ir_if * as_if() { return NULL; } |
Eric Anholt | 7d21104 | 2010-04-16 16:43:47 -0700 | [diff] [blame] | 66 | virtual class ir_swizzle * as_swizzle() { return NULL; } |
Eric Anholt | 5c89f0e | 2010-05-04 13:04:40 -0700 | [diff] [blame] | 67 | virtual class ir_constant * as_constant() { return NULL; } |
Kenneth Graunke | 44e1dfa | 2010-03-25 23:30:28 -0700 | [diff] [blame] | 68 | /*@}*/ |
| 69 | |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 70 | protected: |
Kenneth Graunke | 44e1dfa | 2010-03-25 23:30:28 -0700 | [diff] [blame] | 71 | ir_instruction() |
Ian Romanick | d27ec24 | 2010-03-11 14:23:41 -0800 | [diff] [blame] | 72 | { |
| 73 | /* empty */ |
| 74 | } |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 75 | }; |
| 76 | |
| 77 | |
Kenneth Graunke | fb9fb5f | 2010-03-26 00:25:36 -0700 | [diff] [blame] | 78 | class ir_rvalue : public ir_instruction { |
| 79 | public: |
| 80 | virtual ir_rvalue * as_rvalue() |
| 81 | { |
| 82 | return this; |
| 83 | } |
| 84 | |
| 85 | virtual bool is_lvalue() |
| 86 | { |
| 87 | return false; |
| 88 | } |
| 89 | |
Ian Romanick | 2b3c476 | 2010-05-14 17:35:42 -0700 | [diff] [blame] | 90 | /** |
| 91 | * Get the variable that is ultimately referenced by an r-value |
| 92 | */ |
| 93 | virtual ir_variable *variable_referenced() |
| 94 | { |
| 95 | return NULL; |
| 96 | } |
| 97 | |
Ian Romanick | b067db2 | 2010-05-26 11:32:52 -0700 | [diff] [blame] | 98 | |
| 99 | /** |
| 100 | * If an r-value is a reference to a whole variable, get that variable |
| 101 | * |
| 102 | * \return |
| 103 | * Pointer to a variable that is completely dereferenced by the r-value. If |
| 104 | * the r-value is not a dereference or the dereference does not access the |
| 105 | * entire variable (i.e., it's just one array element, struct field), \c NULL |
| 106 | * is returned. |
| 107 | */ |
| 108 | virtual ir_variable *whole_variable_referenced() |
| 109 | { |
| 110 | return NULL; |
| 111 | } |
| 112 | |
Kenneth Graunke | fb9fb5f | 2010-03-26 00:25:36 -0700 | [diff] [blame] | 113 | protected: |
Ian Romanick | b427c91 | 2010-04-07 18:03:50 -0700 | [diff] [blame] | 114 | ir_rvalue() |
| 115 | { |
| 116 | /* empty */ |
| 117 | } |
Kenneth Graunke | fb9fb5f | 2010-03-26 00:25:36 -0700 | [diff] [blame] | 118 | }; |
| 119 | |
| 120 | |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 121 | enum ir_variable_mode { |
| 122 | ir_var_auto = 0, |
| 123 | ir_var_uniform, |
| 124 | ir_var_in, |
| 125 | ir_var_out, |
| 126 | ir_var_inout |
| 127 | }; |
| 128 | |
| 129 | enum ir_varaible_interpolation { |
| 130 | ir_var_smooth = 0, |
| 131 | ir_var_flat, |
| 132 | ir_var_noperspective |
| 133 | }; |
| 134 | |
Kenneth Graunke | fb9fb5f | 2010-03-26 00:25:36 -0700 | [diff] [blame] | 135 | |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 136 | class ir_variable : public ir_instruction { |
| 137 | public: |
| 138 | ir_variable(const struct glsl_type *, const char *); |
| 139 | |
Kenneth Graunke | 44e1dfa | 2010-03-25 23:30:28 -0700 | [diff] [blame] | 140 | virtual ir_variable *as_variable() |
| 141 | { |
| 142 | return this; |
| 143 | } |
| 144 | |
Ian Romanick | 78b51b0 | 2010-03-09 16:23:37 -0800 | [diff] [blame] | 145 | virtual void accept(ir_visitor *v) |
| 146 | { |
| 147 | v->visit(this); |
| 148 | } |
| 149 | |
Ian Romanick | 8895bae | 2010-05-14 12:39:23 -0700 | [diff] [blame] | 150 | virtual ir_visitor_status accept(ir_hierarchical_visitor *); |
| 151 | |
Ian Romanick | 2d394d4 | 2010-03-31 17:52:44 -0700 | [diff] [blame] | 152 | /** |
| 153 | * Duplicate an IR variable |
| 154 | * |
| 155 | * \note |
| 156 | * This will probably be made \c virtual and moved to the base class |
| 157 | * eventually. |
| 158 | */ |
| 159 | ir_variable *clone() const |
| 160 | { |
| 161 | ir_variable *var = new ir_variable(type, name); |
| 162 | |
Ian Romanick | b8a21cc | 2010-04-01 18:31:11 -0700 | [diff] [blame] | 163 | var->max_array_access = this->max_array_access; |
Ian Romanick | 2d394d4 | 2010-03-31 17:52:44 -0700 | [diff] [blame] | 164 | var->read_only = this->read_only; |
| 165 | var->centroid = this->centroid; |
| 166 | var->invariant = this->invariant; |
| 167 | var->mode = this->mode; |
| 168 | var->interpolation = this->interpolation; |
| 169 | |
| 170 | return var; |
| 171 | } |
| 172 | |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 173 | const char *name; |
| 174 | |
Ian Romanick | b8a21cc | 2010-04-01 18:31:11 -0700 | [diff] [blame] | 175 | /** |
| 176 | * Highest element accessed with a constant expression array index |
| 177 | * |
| 178 | * Not used for non-array variables. |
| 179 | */ |
| 180 | unsigned max_array_access; |
| 181 | |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 182 | unsigned read_only:1; |
| 183 | unsigned centroid:1; |
| 184 | unsigned invariant:1; |
Eric Anholt | 71df19f | 2010-04-19 11:10:37 -0700 | [diff] [blame] | 185 | /** If the variable is initialized outside of the scope of the shader */ |
| 186 | unsigned shader_in:1; |
| 187 | /** |
| 188 | * If the variable value is later used outside of the scope of the shader. |
| 189 | */ |
| 190 | unsigned shader_out:1; |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 191 | |
| 192 | unsigned mode:3; |
| 193 | unsigned interpolation:2; |
Ian Romanick | 9d97537 | 2010-04-02 17:17:47 -0700 | [diff] [blame] | 194 | |
| 195 | /** |
| 196 | * Flag that the whole array is assignable |
| 197 | * |
| 198 | * In GLSL 1.20 and later whole arrays are assignable (and comparable for |
| 199 | * equality). This flag enables this behavior. |
| 200 | */ |
| 201 | unsigned array_lvalue:1; |
Eric Anholt | 326c676 | 2010-04-06 10:30:54 -0700 | [diff] [blame] | 202 | |
| 203 | /** |
Ian Romanick | c178c74 | 2010-04-07 16:53:54 -0700 | [diff] [blame] | 204 | * Emit a warning if this variable is accessed. |
| 205 | */ |
| 206 | const char *warn_extension; |
| 207 | |
| 208 | /** |
Eric Anholt | 326c676 | 2010-04-06 10:30:54 -0700 | [diff] [blame] | 209 | * Value assigned in the initializer of a variable declared "const" |
| 210 | */ |
| 211 | ir_constant *constant_value; |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 212 | }; |
| 213 | |
| 214 | |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 215 | /*@{*/ |
Kenneth Graunke | 9fa99f3 | 2010-04-21 12:30:22 -0700 | [diff] [blame] | 216 | /** |
| 217 | * The representation of a function instance; may be the full definition or |
| 218 | * simply a prototype. |
| 219 | */ |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 220 | class ir_function_signature : public ir_instruction { |
Eric Anholt | 894ea97 | 2010-04-07 13:19:11 -0700 | [diff] [blame] | 221 | /* An ir_function_signature will be part of the list of signatures in |
| 222 | * an ir_function. |
| 223 | */ |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 224 | public: |
Ian Romanick | e39cc69 | 2010-03-23 12:19:13 -0700 | [diff] [blame] | 225 | ir_function_signature(const glsl_type *return_type); |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 226 | |
Ian Romanick | 78b51b0 | 2010-03-09 16:23:37 -0800 | [diff] [blame] | 227 | virtual void accept(ir_visitor *v) |
| 228 | { |
| 229 | v->visit(this); |
| 230 | } |
| 231 | |
Ian Romanick | 8895bae | 2010-05-14 12:39:23 -0700 | [diff] [blame] | 232 | virtual ir_visitor_status accept(ir_hierarchical_visitor *); |
| 233 | |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 234 | /** |
Ian Romanick | 0f0ea58 | 2010-03-31 16:44:12 -0700 | [diff] [blame] | 235 | * Get the name of the function for which this is a signature |
| 236 | */ |
| 237 | const char *function_name() const; |
| 238 | |
| 239 | /** |
Kenneth Graunke | abd40b1 | 2010-04-28 11:49:12 -0700 | [diff] [blame] | 240 | * Check whether the qualifiers match between this signature's parameters |
| 241 | * and the supplied parameter list. If not, returns the name of the first |
| 242 | * parameter with mismatched qualifiers (for use in error messages). |
| 243 | */ |
| 244 | const char *qualifiers_match(exec_list *params); |
| 245 | |
| 246 | /** |
Kenneth Graunke | bff6013 | 2010-04-28 12:44:24 -0700 | [diff] [blame] | 247 | * Replace the current parameter list with the given one. This is useful |
| 248 | * if the current information came from a prototype, and either has invalid |
| 249 | * or missing parameter names. |
| 250 | */ |
| 251 | void replace_parameters(exec_list *new_params); |
| 252 | |
| 253 | /** |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 254 | * Function return type. |
| 255 | * |
| 256 | * \note This discards the optional precision qualifier. |
| 257 | */ |
| 258 | const struct glsl_type *return_type; |
| 259 | |
| 260 | /** |
Eric Anholt | f1ddca9 | 2010-04-07 12:35:34 -0700 | [diff] [blame] | 261 | * List of ir_variable of function parameters. |
| 262 | * |
| 263 | * This represents the storage. The paramaters passed in a particular |
| 264 | * call will be in ir_call::actual_paramaters. |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 265 | */ |
Ian Romanick | 0044e7e | 2010-03-08 23:44:00 -0800 | [diff] [blame] | 266 | struct exec_list parameters; |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 267 | |
Kenneth Graunke | 9fa99f3 | 2010-04-21 12:30:22 -0700 | [diff] [blame] | 268 | /** Whether or not this function has a body (which may be empty). */ |
| 269 | unsigned is_defined:1; |
Ian Romanick | 6a15d5b | 2010-03-31 16:37:10 -0700 | [diff] [blame] | 270 | |
Eric Anholt | 894ea97 | 2010-04-07 13:19:11 -0700 | [diff] [blame] | 271 | /** Body of instructions in the function. */ |
| 272 | struct exec_list body; |
| 273 | |
Ian Romanick | 6a15d5b | 2010-03-31 16:37:10 -0700 | [diff] [blame] | 274 | private: |
| 275 | /** Function of which this signature is one overload. */ |
| 276 | class ir_function *function; |
| 277 | |
| 278 | friend class ir_function; |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 279 | }; |
| 280 | |
| 281 | |
| 282 | /** |
Kenneth Graunke | 9fa99f3 | 2010-04-21 12:30:22 -0700 | [diff] [blame] | 283 | * Header for tracking multiple overloaded functions with the same name. |
| 284 | * Contains a list of ir_function_signatures representing each of the |
| 285 | * actual functions. |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 286 | */ |
| 287 | class ir_function : public ir_instruction { |
| 288 | public: |
Ian Romanick | 882dad7 | 2010-03-23 17:42:04 -0700 | [diff] [blame] | 289 | ir_function(const char *name); |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 290 | |
Kenneth Graunke | 6202cbf | 2010-04-21 16:02:15 -0700 | [diff] [blame] | 291 | virtual ir_function *as_function() |
| 292 | { |
| 293 | return this; |
| 294 | } |
| 295 | |
Ian Romanick | 78b51b0 | 2010-03-09 16:23:37 -0800 | [diff] [blame] | 296 | virtual void accept(ir_visitor *v) |
| 297 | { |
| 298 | v->visit(this); |
| 299 | } |
| 300 | |
Ian Romanick | 8895bae | 2010-05-14 12:39:23 -0700 | [diff] [blame] | 301 | virtual ir_visitor_status accept(ir_hierarchical_visitor *); |
| 302 | |
Ian Romanick | 6a15d5b | 2010-03-31 16:37:10 -0700 | [diff] [blame] | 303 | void add_signature(ir_function_signature *sig) |
| 304 | { |
| 305 | sig->function = this; |
| 306 | signatures.push_tail(sig); |
| 307 | } |
| 308 | |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 309 | /** |
Ian Romanick | 95cd6cc | 2010-03-31 16:40:26 -0700 | [diff] [blame] | 310 | * Get an iterator for the set of function signatures |
| 311 | */ |
| 312 | exec_list_iterator iterator() |
| 313 | { |
| 314 | return signatures.iterator(); |
| 315 | } |
| 316 | |
| 317 | /** |
Kenneth Graunke | 0d605cb | 2010-04-28 12:04:23 -0700 | [diff] [blame] | 318 | * Find a signature that matches a set of actual parameters, taking implicit |
| 319 | * conversions into account. |
Ian Romanick | 471471f | 2010-03-11 14:50:30 -0800 | [diff] [blame] | 320 | */ |
| 321 | const ir_function_signature *matching_signature(exec_list *actual_param); |
| 322 | |
| 323 | /** |
Kenneth Graunke | 0d605cb | 2010-04-28 12:04:23 -0700 | [diff] [blame] | 324 | * Find a signature that exactly matches a set of actual parameters without |
| 325 | * any implicit type conversions. |
| 326 | */ |
| 327 | ir_function_signature *exact_matching_signature(exec_list *actual_ps); |
| 328 | |
| 329 | /** |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 330 | * Name of the function. |
| 331 | */ |
| 332 | const char *name; |
| 333 | |
Ian Romanick | a477582 | 2010-03-31 16:40:58 -0700 | [diff] [blame] | 334 | private: |
Ian Romanick | 471471f | 2010-03-11 14:50:30 -0800 | [diff] [blame] | 335 | /** |
Eric Anholt | f1ddca9 | 2010-04-07 12:35:34 -0700 | [diff] [blame] | 336 | * List of ir_function_signature for each overloaded function with this name. |
Ian Romanick | 471471f | 2010-03-11 14:50:30 -0800 | [diff] [blame] | 337 | */ |
Ian Romanick | 0044e7e | 2010-03-08 23:44:00 -0800 | [diff] [blame] | 338 | struct exec_list signatures; |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 339 | }; |
Ian Romanick | 0f0ea58 | 2010-03-31 16:44:12 -0700 | [diff] [blame] | 340 | |
| 341 | inline const char *ir_function_signature::function_name() const |
| 342 | { |
| 343 | return function->name; |
| 344 | } |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 345 | /*@}*/ |
| 346 | |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 347 | |
Ian Romanick | 3c6fea3 | 2010-03-29 14:11:25 -0700 | [diff] [blame] | 348 | /** |
| 349 | * IR instruction representing high-level if-statements |
| 350 | */ |
| 351 | class ir_if : public ir_instruction { |
| 352 | public: |
| 353 | ir_if(ir_rvalue *condition) |
| 354 | : condition(condition) |
| 355 | { |
| 356 | /* empty */ |
| 357 | } |
| 358 | |
Eric Anholt | 5ba9420 | 2010-04-14 17:03:03 -0700 | [diff] [blame] | 359 | virtual ir_if *as_if() |
| 360 | { |
| 361 | return this; |
| 362 | } |
| 363 | |
Ian Romanick | 3c6fea3 | 2010-03-29 14:11:25 -0700 | [diff] [blame] | 364 | virtual void accept(ir_visitor *v) |
| 365 | { |
| 366 | v->visit(this); |
| 367 | } |
| 368 | |
Ian Romanick | 8895bae | 2010-05-14 12:39:23 -0700 | [diff] [blame] | 369 | virtual ir_visitor_status accept(ir_hierarchical_visitor *); |
| 370 | |
Ian Romanick | 3c6fea3 | 2010-03-29 14:11:25 -0700 | [diff] [blame] | 371 | ir_rvalue *condition; |
Eric Anholt | f1ddca9 | 2010-04-07 12:35:34 -0700 | [diff] [blame] | 372 | /** List of ir_instruction for the body of the then branch */ |
Ian Romanick | 3c6fea3 | 2010-03-29 14:11:25 -0700 | [diff] [blame] | 373 | exec_list then_instructions; |
Eric Anholt | f1ddca9 | 2010-04-07 12:35:34 -0700 | [diff] [blame] | 374 | /** List of ir_instruction for the body of the else branch */ |
Ian Romanick | 3c6fea3 | 2010-03-29 14:11:25 -0700 | [diff] [blame] | 375 | exec_list else_instructions; |
| 376 | }; |
| 377 | |
| 378 | |
Ian Romanick | fad607a | 2010-04-05 16:16:07 -0700 | [diff] [blame] | 379 | /** |
| 380 | * IR instruction representing a high-level loop structure. |
| 381 | */ |
| 382 | class ir_loop : public ir_instruction { |
| 383 | public: |
| 384 | ir_loop() : from(NULL), to(NULL), increment(NULL), counter(NULL) |
| 385 | { |
| 386 | /* empty */ |
| 387 | } |
| 388 | |
| 389 | virtual void accept(ir_visitor *v) |
| 390 | { |
| 391 | v->visit(this); |
| 392 | } |
| 393 | |
Ian Romanick | 8895bae | 2010-05-14 12:39:23 -0700 | [diff] [blame] | 394 | virtual ir_visitor_status accept(ir_hierarchical_visitor *); |
| 395 | |
Ian Romanick | 01f8de4 | 2010-04-05 17:13:14 -0700 | [diff] [blame] | 396 | virtual ir_loop *as_loop() |
| 397 | { |
| 398 | return this; |
| 399 | } |
| 400 | |
Ian Romanick | fad607a | 2010-04-05 16:16:07 -0700 | [diff] [blame] | 401 | /** |
| 402 | * Get an iterator for the instructions of the loop body |
| 403 | */ |
| 404 | exec_list_iterator iterator() |
| 405 | { |
| 406 | return body_instructions.iterator(); |
| 407 | } |
| 408 | |
Eric Anholt | f1ddca9 | 2010-04-07 12:35:34 -0700 | [diff] [blame] | 409 | /** List of ir_instruction that make up the body of the loop. */ |
Ian Romanick | fad607a | 2010-04-05 16:16:07 -0700 | [diff] [blame] | 410 | exec_list body_instructions; |
| 411 | |
| 412 | /** |
| 413 | * \name Loop counter and controls |
| 414 | */ |
| 415 | /*@{*/ |
| 416 | ir_rvalue *from; |
| 417 | ir_rvalue *to; |
| 418 | ir_rvalue *increment; |
| 419 | ir_variable *counter; |
| 420 | /*@}*/ |
| 421 | }; |
| 422 | |
| 423 | |
Kenneth Graunke | fb9fb5f | 2010-03-26 00:25:36 -0700 | [diff] [blame] | 424 | class ir_assignment : public ir_rvalue { |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 425 | public: |
Kenneth Graunke | fb9fb5f | 2010-03-26 00:25:36 -0700 | [diff] [blame] | 426 | ir_assignment(ir_rvalue *lhs, ir_rvalue *rhs, ir_rvalue *condition); |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 427 | |
Ian Romanick | 78b51b0 | 2010-03-09 16:23:37 -0800 | [diff] [blame] | 428 | virtual void accept(ir_visitor *v) |
| 429 | { |
| 430 | v->visit(this); |
| 431 | } |
| 432 | |
Ian Romanick | 8895bae | 2010-05-14 12:39:23 -0700 | [diff] [blame] | 433 | virtual ir_visitor_status accept(ir_hierarchical_visitor *); |
| 434 | |
Eric Anholt | cad9766 | 2010-04-07 11:46:26 -0700 | [diff] [blame] | 435 | virtual ir_assignment * as_assignment() |
| 436 | { |
| 437 | return this; |
| 438 | } |
| 439 | |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 440 | /** |
| 441 | * Left-hand side of the assignment. |
| 442 | */ |
Kenneth Graunke | fb9fb5f | 2010-03-26 00:25:36 -0700 | [diff] [blame] | 443 | ir_rvalue *lhs; |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 444 | |
| 445 | /** |
| 446 | * Value being assigned |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 447 | */ |
Kenneth Graunke | fb9fb5f | 2010-03-26 00:25:36 -0700 | [diff] [blame] | 448 | ir_rvalue *rhs; |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 449 | |
| 450 | /** |
| 451 | * Optional condition for the assignment. |
| 452 | */ |
Kenneth Graunke | fb9fb5f | 2010-03-26 00:25:36 -0700 | [diff] [blame] | 453 | ir_rvalue *condition; |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 454 | }; |
| 455 | |
Kenneth Graunke | 3b96996 | 2010-04-07 17:18:29 -0700 | [diff] [blame] | 456 | /* Update ir_expression::num_operands() and operator_strs when |
Eric Anholt | 160d092 | 2010-04-01 18:07:08 -1000 | [diff] [blame] | 457 | * updating this list. |
Kenneth Graunke | 3b96996 | 2010-04-07 17:18:29 -0700 | [diff] [blame] | 458 | */ |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 459 | enum ir_expression_operation { |
| 460 | ir_unop_bit_not, |
| 461 | ir_unop_logic_not, |
| 462 | ir_unop_neg, |
| 463 | ir_unop_abs, |
Kenneth Graunke | a4b7b5a | 2010-05-03 20:05:57 -0700 | [diff] [blame] | 464 | ir_unop_sign, |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 465 | ir_unop_rcp, |
| 466 | ir_unop_rsq, |
Eric Anholt | 44d68fd | 2010-03-27 13:01:51 -0700 | [diff] [blame] | 467 | ir_unop_sqrt, |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 468 | ir_unop_exp, |
| 469 | ir_unop_log, |
Eric Anholt | 0166526 | 2010-03-27 13:56:35 -0700 | [diff] [blame] | 470 | ir_unop_exp2, |
| 471 | ir_unop_log2, |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 472 | ir_unop_f2i, /**< Float-to-integer conversion. */ |
| 473 | ir_unop_i2f, /**< Integer-to-float conversion. */ |
Eric Anholt | dc58b3f | 2010-04-02 02:13:43 -1000 | [diff] [blame] | 474 | ir_unop_f2b, /**< Float-to-boolean conversion */ |
| 475 | ir_unop_b2f, /**< Boolean-to-float conversion */ |
Eric Anholt | c2cb84e | 2010-04-02 02:17:08 -1000 | [diff] [blame] | 476 | ir_unop_i2b, /**< int-to-boolean conversion */ |
| 477 | ir_unop_b2i, /**< Boolean-to-int conversion */ |
Ian Romanick | 6c86ea8 | 2010-03-26 16:11:48 -0700 | [diff] [blame] | 478 | ir_unop_u2f, /**< Unsigned-to-float conversion. */ |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 479 | |
| 480 | /** |
| 481 | * \name Unary floating-point rounding operations. |
| 482 | */ |
| 483 | /*@{*/ |
| 484 | ir_unop_trunc, |
| 485 | ir_unop_ceil, |
| 486 | ir_unop_floor, |
| 487 | /*@}*/ |
| 488 | |
Kenneth Graunke | 57e7da1 | 2010-05-03 22:11:17 -0700 | [diff] [blame] | 489 | /** |
| 490 | * \name Trigonometric operations. |
| 491 | */ |
| 492 | /*@{*/ |
| 493 | ir_unop_sin, |
| 494 | ir_unop_cos, |
| 495 | /*@}*/ |
| 496 | |
Kenneth Graunke | b843c7a | 2010-06-09 14:42:41 -0700 | [diff] [blame] | 497 | /** |
| 498 | * \name Partial derivatives. |
| 499 | */ |
| 500 | /*@{*/ |
| 501 | ir_unop_dFdx, |
| 502 | ir_unop_dFdy, |
| 503 | /*@}*/ |
| 504 | |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 505 | ir_binop_add, |
| 506 | ir_binop_sub, |
| 507 | ir_binop_mul, |
| 508 | ir_binop_div, |
| 509 | ir_binop_mod, |
| 510 | |
| 511 | /** |
| 512 | * \name Binary comparison operators |
| 513 | */ |
| 514 | /*@{*/ |
| 515 | ir_binop_less, |
| 516 | ir_binop_greater, |
| 517 | ir_binop_lequal, |
| 518 | ir_binop_gequal, |
| 519 | ir_binop_equal, |
| 520 | ir_binop_nequal, |
| 521 | /*@}*/ |
| 522 | |
| 523 | /** |
| 524 | * \name Bit-wise binary operations. |
| 525 | */ |
| 526 | /*@{*/ |
| 527 | ir_binop_lshift, |
| 528 | ir_binop_rshift, |
| 529 | ir_binop_bit_and, |
| 530 | ir_binop_bit_xor, |
| 531 | ir_binop_bit_or, |
| 532 | /*@}*/ |
| 533 | |
| 534 | ir_binop_logic_and, |
| 535 | ir_binop_logic_xor, |
| 536 | ir_binop_logic_or, |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 537 | |
| 538 | ir_binop_dot, |
| 539 | ir_binop_min, |
| 540 | ir_binop_max, |
| 541 | |
| 542 | ir_binop_pow |
| 543 | }; |
| 544 | |
Kenneth Graunke | fb9fb5f | 2010-03-26 00:25:36 -0700 | [diff] [blame] | 545 | class ir_expression : public ir_rvalue { |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 546 | public: |
| 547 | ir_expression(int op, const struct glsl_type *type, |
Kenneth Graunke | fb9fb5f | 2010-03-26 00:25:36 -0700 | [diff] [blame] | 548 | ir_rvalue *, ir_rvalue *); |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 549 | |
Kenneth Graunke | 7dd6adb | 2010-04-07 16:56:57 -0700 | [diff] [blame] | 550 | static unsigned int get_num_operands(ir_expression_operation); |
| 551 | unsigned int get_num_operands() |
| 552 | { |
| 553 | return get_num_operands(operation); |
| 554 | } |
Eric Anholt | 160d092 | 2010-04-01 18:07:08 -1000 | [diff] [blame] | 555 | |
Kenneth Graunke | 3b96996 | 2010-04-07 17:18:29 -0700 | [diff] [blame] | 556 | /** |
| 557 | * Return a string representing this expression's operator. |
| 558 | */ |
| 559 | const char *operator_string(); |
| 560 | |
| 561 | /** |
| 562 | * Do a reverse-lookup to translate the given string into an operator. |
| 563 | */ |
| 564 | static ir_expression_operation get_operator(const char *); |
| 565 | |
Ian Romanick | 78b51b0 | 2010-03-09 16:23:37 -0800 | [diff] [blame] | 566 | virtual void accept(ir_visitor *v) |
| 567 | { |
| 568 | v->visit(this); |
| 569 | } |
| 570 | |
Ian Romanick | 8895bae | 2010-05-14 12:39:23 -0700 | [diff] [blame] | 571 | virtual ir_visitor_status accept(ir_hierarchical_visitor *); |
| 572 | |
Eric Anholt | cad9766 | 2010-04-07 11:46:26 -0700 | [diff] [blame] | 573 | ir_expression *clone(); |
| 574 | |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 575 | ir_expression_operation operation; |
Kenneth Graunke | fb9fb5f | 2010-03-26 00:25:36 -0700 | [diff] [blame] | 576 | ir_rvalue *operands[2]; |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 577 | }; |
| 578 | |
| 579 | |
Ian Romanick | ed45ec6 | 2010-03-11 14:34:27 -0800 | [diff] [blame] | 580 | /** |
| 581 | * IR instruction representing a function call |
| 582 | */ |
Kenneth Graunke | fb9fb5f | 2010-03-26 00:25:36 -0700 | [diff] [blame] | 583 | class ir_call : public ir_rvalue { |
Ian Romanick | ed45ec6 | 2010-03-11 14:34:27 -0800 | [diff] [blame] | 584 | public: |
Ian Romanick | 471471f | 2010-03-11 14:50:30 -0800 | [diff] [blame] | 585 | ir_call(const ir_function_signature *callee, exec_list *actual_parameters) |
Ian Romanick | b427c91 | 2010-04-07 18:03:50 -0700 | [diff] [blame] | 586 | : callee(callee) |
Ian Romanick | ed45ec6 | 2010-03-11 14:34:27 -0800 | [diff] [blame] | 587 | { |
Ian Romanick | 9e7c34b | 2010-03-23 12:21:18 -0700 | [diff] [blame] | 588 | assert(callee->return_type != NULL); |
| 589 | type = callee->return_type; |
Ian Romanick | 471471f | 2010-03-11 14:50:30 -0800 | [diff] [blame] | 590 | actual_parameters->move_nodes_to(& this->actual_parameters); |
Ian Romanick | ed45ec6 | 2010-03-11 14:34:27 -0800 | [diff] [blame] | 591 | } |
| 592 | |
Eric Anholt | cad9766 | 2010-04-07 11:46:26 -0700 | [diff] [blame] | 593 | virtual ir_call *as_call() |
| 594 | { |
| 595 | return this; |
| 596 | } |
| 597 | |
Ian Romanick | ed45ec6 | 2010-03-11 14:34:27 -0800 | [diff] [blame] | 598 | virtual void accept(ir_visitor *v) |
| 599 | { |
| 600 | v->visit(this); |
| 601 | } |
| 602 | |
Ian Romanick | 8895bae | 2010-05-14 12:39:23 -0700 | [diff] [blame] | 603 | virtual ir_visitor_status accept(ir_hierarchical_visitor *); |
| 604 | |
Ian Romanick | ed45ec6 | 2010-03-11 14:34:27 -0800 | [diff] [blame] | 605 | /** |
| 606 | * Get a generic ir_call object when an error occurs |
| 607 | */ |
| 608 | static ir_call *get_error_instruction(); |
| 609 | |
Ian Romanick | 9878c65 | 2010-03-26 17:19:47 -0700 | [diff] [blame] | 610 | /** |
| 611 | * Get an iterator for the set of acutal parameters |
| 612 | */ |
| 613 | exec_list_iterator iterator() |
| 614 | { |
| 615 | return actual_parameters.iterator(); |
| 616 | } |
| 617 | |
Ian Romanick | 93614bc | 2010-03-26 17:29:29 -0700 | [diff] [blame] | 618 | /** |
| 619 | * Get the name of the function being called. |
| 620 | */ |
| 621 | const char *callee_name() const |
| 622 | { |
Ian Romanick | 0f0ea58 | 2010-03-31 16:44:12 -0700 | [diff] [blame] | 623 | return callee->function_name(); |
Ian Romanick | 93614bc | 2010-03-26 17:29:29 -0700 | [diff] [blame] | 624 | } |
| 625 | |
Eric Anholt | cad9766 | 2010-04-07 11:46:26 -0700 | [diff] [blame] | 626 | const ir_function_signature *get_callee() |
| 627 | { |
| 628 | return callee; |
| 629 | } |
| 630 | |
| 631 | /** |
| 632 | * Generates an inline version of the function before @ir, |
| 633 | * returning the return value of the function. |
| 634 | */ |
| 635 | ir_rvalue *generate_inline(ir_instruction *ir); |
| 636 | |
Ian Romanick | ed45ec6 | 2010-03-11 14:34:27 -0800 | [diff] [blame] | 637 | private: |
Ian Romanick | 471471f | 2010-03-11 14:50:30 -0800 | [diff] [blame] | 638 | ir_call() |
Ian Romanick | b427c91 | 2010-04-07 18:03:50 -0700 | [diff] [blame] | 639 | : callee(NULL) |
Ian Romanick | 471471f | 2010-03-11 14:50:30 -0800 | [diff] [blame] | 640 | { |
| 641 | /* empty */ |
| 642 | } |
| 643 | |
| 644 | const ir_function_signature *callee; |
Eric Anholt | f1ddca9 | 2010-04-07 12:35:34 -0700 | [diff] [blame] | 645 | |
| 646 | /* List of ir_rvalue of paramaters passed in this call. */ |
Ian Romanick | ed45ec6 | 2010-03-11 14:34:27 -0800 | [diff] [blame] | 647 | exec_list actual_parameters; |
| 648 | }; |
| 649 | |
| 650 | |
Ian Romanick | 9578c87 | 2010-03-19 16:44:52 -0700 | [diff] [blame] | 651 | /** |
| 652 | * \name Jump-like IR instructions. |
| 653 | * |
| 654 | * These include \c break, \c continue, \c return, and \c discard. |
| 655 | */ |
| 656 | /*@{*/ |
| 657 | class ir_jump : public ir_instruction { |
| 658 | protected: |
| 659 | ir_jump() |
Ian Romanick | 9578c87 | 2010-03-19 16:44:52 -0700 | [diff] [blame] | 660 | { |
| 661 | /* empty */ |
| 662 | } |
| 663 | }; |
| 664 | |
| 665 | class ir_return : public ir_jump { |
| 666 | public: |
| 667 | ir_return() |
| 668 | : value(NULL) |
| 669 | { |
| 670 | /* empty */ |
| 671 | } |
| 672 | |
Kenneth Graunke | fb9fb5f | 2010-03-26 00:25:36 -0700 | [diff] [blame] | 673 | ir_return(ir_rvalue *value) |
Ian Romanick | 9578c87 | 2010-03-19 16:44:52 -0700 | [diff] [blame] | 674 | : value(value) |
| 675 | { |
| 676 | /* empty */ |
| 677 | } |
| 678 | |
Eric Anholt | cad9766 | 2010-04-07 11:46:26 -0700 | [diff] [blame] | 679 | virtual ir_return *as_return() |
| 680 | { |
| 681 | return this; |
| 682 | } |
| 683 | |
Kenneth Graunke | fb9fb5f | 2010-03-26 00:25:36 -0700 | [diff] [blame] | 684 | ir_rvalue *get_value() const |
Ian Romanick | 9578c87 | 2010-03-19 16:44:52 -0700 | [diff] [blame] | 685 | { |
| 686 | return value; |
| 687 | } |
| 688 | |
| 689 | virtual void accept(ir_visitor *v) |
| 690 | { |
| 691 | v->visit(this); |
| 692 | } |
| 693 | |
Ian Romanick | 8895bae | 2010-05-14 12:39:23 -0700 | [diff] [blame] | 694 | virtual ir_visitor_status accept(ir_hierarchical_visitor *); |
| 695 | |
Kenneth Graunke | fb9fb5f | 2010-03-26 00:25:36 -0700 | [diff] [blame] | 696 | ir_rvalue *value; |
Ian Romanick | 9578c87 | 2010-03-19 16:44:52 -0700 | [diff] [blame] | 697 | }; |
Ian Romanick | f8e31e0 | 2010-04-05 16:28:15 -0700 | [diff] [blame] | 698 | |
| 699 | |
| 700 | /** |
| 701 | * Jump instructions used inside loops |
| 702 | * |
| 703 | * These include \c break and \c continue. The \c break within a loop is |
| 704 | * different from the \c break within a switch-statement. |
| 705 | * |
| 706 | * \sa ir_switch_jump |
| 707 | */ |
| 708 | class ir_loop_jump : public ir_jump { |
| 709 | public: |
| 710 | enum jump_mode { |
| 711 | jump_break, |
| 712 | jump_continue |
| 713 | }; |
| 714 | |
| 715 | ir_loop_jump(ir_loop *loop, jump_mode mode) |
| 716 | : loop(loop), mode(mode) |
| 717 | { |
| 718 | /* empty */ |
| 719 | } |
| 720 | |
| 721 | virtual void accept(ir_visitor *v) |
| 722 | { |
| 723 | v->visit(this); |
| 724 | } |
| 725 | |
Ian Romanick | 8895bae | 2010-05-14 12:39:23 -0700 | [diff] [blame] | 726 | virtual ir_visitor_status accept(ir_hierarchical_visitor *); |
| 727 | |
Ian Romanick | f8e31e0 | 2010-04-05 16:28:15 -0700 | [diff] [blame] | 728 | bool is_break() const |
| 729 | { |
| 730 | return mode == jump_break; |
| 731 | } |
| 732 | |
| 733 | bool is_continue() const |
| 734 | { |
| 735 | return mode == jump_continue; |
| 736 | } |
| 737 | |
| 738 | private: |
| 739 | /** Loop containing this break instruction. */ |
| 740 | ir_loop *loop; |
| 741 | |
| 742 | /** Mode selector for the jump instruction. */ |
| 743 | enum jump_mode mode; |
| 744 | }; |
Ian Romanick | 9578c87 | 2010-03-19 16:44:52 -0700 | [diff] [blame] | 745 | /*@}*/ |
| 746 | |
| 747 | |
Ian Romanick | 81377c0 | 2010-04-28 18:42:36 -0700 | [diff] [blame] | 748 | /** |
| 749 | * Texture sampling opcodes used in ir_texture |
| 750 | */ |
| 751 | enum ir_texture_opcode { |
| 752 | ir_tex, /* Regular texture look-up */ |
| 753 | ir_txb, /* Texture look-up with LOD bias */ |
| 754 | ir_txl, /* Texture look-up with explicit LOD */ |
| 755 | ir_txd, /* Texture look-up with partial derivatvies */ |
| 756 | ir_txf /* Texel fetch with explicit LOD */ |
| 757 | }; |
| 758 | |
| 759 | |
| 760 | /** |
| 761 | * IR instruction to sample a texture |
| 762 | * |
| 763 | * The specific form of the IR instruction depends on the \c mode value |
| 764 | * selected from \c ir_texture_opcodes. In the printed IR, these will |
| 765 | * appear as: |
| 766 | * |
| 767 | * Texel offset |
| 768 | * | Projection divisor |
| 769 | * | | Shadow comparitor |
| 770 | * | | | |
| 771 | * v v v |
| 772 | * (tex (sampler) (coordinate) (0 0 0) (1) ( )) |
| 773 | * (txb (sampler) (coordinate) (0 0 0) (1) ( ) (bias)) |
| 774 | * (txl (sampler) (coordinate) (0 0 0) (1) ( ) (lod)) |
| 775 | * (txd (sampler) (coordinate) (0 0 0) (1) ( ) (dPdx dPdy)) |
| 776 | * (txf (sampler) (coordinate) (0 0 0) (lod)) |
| 777 | */ |
| 778 | class ir_texture : public ir_rvalue { |
| 779 | public: |
| 780 | ir_texture(enum ir_texture_opcode op) |
Kenneth Graunke | b97efa5 | 2010-06-09 11:07:53 -0700 | [diff] [blame] | 781 | : op(op), projector(NULL), shadow_comparitor(NULL) |
Ian Romanick | 81377c0 | 2010-04-28 18:42:36 -0700 | [diff] [blame] | 782 | { |
| 783 | /* empty */ |
| 784 | } |
| 785 | |
Kenneth Graunke | 26d74cd | 2010-05-26 17:42:03 -0700 | [diff] [blame] | 786 | virtual void accept(ir_visitor *v) |
| 787 | { |
| 788 | v->visit(this); |
| 789 | } |
| 790 | |
| 791 | virtual ir_visitor_status accept(ir_hierarchical_visitor *); |
| 792 | |
Kenneth Graunke | c30f6e5 | 2010-05-26 16:41:47 -0700 | [diff] [blame] | 793 | /** |
| 794 | * Return a string representing the ir_texture_opcode. |
| 795 | */ |
| 796 | const char *opcode_string(); |
| 797 | |
Kenneth Graunke | 56d3f6a | 2010-06-03 15:07:34 -0700 | [diff] [blame] | 798 | /** Set the sampler and infer the type. */ |
| 799 | void set_sampler(ir_dereference *sampler); |
| 800 | |
Kenneth Graunke | c30f6e5 | 2010-05-26 16:41:47 -0700 | [diff] [blame] | 801 | /** |
| 802 | * Do a reverse-lookup to translate a string into an ir_texture_opcode. |
| 803 | */ |
| 804 | static ir_texture_opcode get_opcode(const char *); |
| 805 | |
Ian Romanick | 81377c0 | 2010-04-28 18:42:36 -0700 | [diff] [blame] | 806 | enum ir_texture_opcode op; |
| 807 | |
| 808 | /** Sampler to use for the texture access. */ |
| 809 | ir_dereference *sampler; |
| 810 | |
| 811 | /** Texture coordinate to sample */ |
| 812 | ir_rvalue *coordinate; |
| 813 | |
| 814 | /** |
| 815 | * Value used for projective divide. |
| 816 | * |
| 817 | * If there is no projective divide (the common case), this will be |
| 818 | * \c NULL. Optimization passes should check for this to point to a constant |
| 819 | * of 1.0 and replace that with \c NULL. |
| 820 | */ |
| 821 | ir_rvalue *projector; |
| 822 | |
| 823 | /** |
| 824 | * Coordinate used for comparison on shadow look-ups. |
| 825 | * |
| 826 | * If there is no shadow comparison, this will be \c NULL. For the |
| 827 | * \c ir_txf opcode, this *must* be \c NULL. |
| 828 | */ |
| 829 | ir_rvalue *shadow_comparitor; |
| 830 | |
| 831 | /** Explicit texel offsets. */ |
| 832 | signed char offsets[3]; |
| 833 | |
| 834 | union { |
| 835 | ir_rvalue *lod; /**< Floating point LOD */ |
| 836 | ir_rvalue *bias; /**< Floating point LOD bias */ |
| 837 | struct { |
| 838 | ir_rvalue *dPdx; /**< Partial derivative of coordinate wrt X */ |
| 839 | ir_rvalue *dPdy; /**< Partial derivative of coordinate wrt Y */ |
| 840 | } grad; |
| 841 | } lod_info; |
| 842 | }; |
| 843 | |
| 844 | |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 845 | struct ir_swizzle_mask { |
| 846 | unsigned x:2; |
| 847 | unsigned y:2; |
| 848 | unsigned z:2; |
| 849 | unsigned w:2; |
| 850 | |
| 851 | /** |
| 852 | * Number of components in the swizzle. |
| 853 | */ |
Kenneth Graunke | f25a5ad | 2010-03-25 11:22:42 -0700 | [diff] [blame] | 854 | unsigned num_components:3; |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 855 | |
| 856 | /** |
| 857 | * Does the swizzle contain duplicate components? |
| 858 | * |
| 859 | * L-value swizzles cannot contain duplicate components. |
| 860 | */ |
| 861 | unsigned has_duplicates:1; |
| 862 | }; |
| 863 | |
Kenneth Graunke | affc141 | 2010-03-26 01:20:08 -0700 | [diff] [blame] | 864 | |
| 865 | class ir_swizzle : public ir_rvalue { |
| 866 | public: |
| 867 | ir_swizzle(ir_rvalue *, unsigned x, unsigned y, unsigned z, unsigned w, |
| 868 | unsigned count); |
Eric Anholt | 05a4e59 | 2010-05-03 17:08:01 -0700 | [diff] [blame] | 869 | ir_swizzle(ir_rvalue *val, ir_swizzle_mask mask); |
Eric Anholt | cad9766 | 2010-04-07 11:46:26 -0700 | [diff] [blame] | 870 | |
Eric Anholt | 7d21104 | 2010-04-16 16:43:47 -0700 | [diff] [blame] | 871 | virtual ir_swizzle *as_swizzle() |
| 872 | { |
| 873 | return this; |
| 874 | } |
| 875 | |
Eric Anholt | cad9766 | 2010-04-07 11:46:26 -0700 | [diff] [blame] | 876 | ir_swizzle *clone() |
| 877 | { |
| 878 | return new ir_swizzle(this->val, this->mask); |
| 879 | } |
| 880 | |
Kenneth Graunke | affc141 | 2010-03-26 01:20:08 -0700 | [diff] [blame] | 881 | /** |
| 882 | * Construct an ir_swizzle from the textual representation. Can fail. |
| 883 | */ |
| 884 | static ir_swizzle *create(ir_rvalue *, const char *, unsigned vector_length); |
| 885 | |
| 886 | virtual void accept(ir_visitor *v) |
| 887 | { |
| 888 | v->visit(this); |
| 889 | } |
| 890 | |
Ian Romanick | 8895bae | 2010-05-14 12:39:23 -0700 | [diff] [blame] | 891 | virtual ir_visitor_status accept(ir_hierarchical_visitor *); |
| 892 | |
Kenneth Graunke | affc141 | 2010-03-26 01:20:08 -0700 | [diff] [blame] | 893 | bool is_lvalue() |
| 894 | { |
Eric Anholt | a9fafc6 | 2010-03-28 01:29:18 -0700 | [diff] [blame] | 895 | return val->is_lvalue() && !mask.has_duplicates; |
Kenneth Graunke | affc141 | 2010-03-26 01:20:08 -0700 | [diff] [blame] | 896 | } |
| 897 | |
Ian Romanick | 2b3c476 | 2010-05-14 17:35:42 -0700 | [diff] [blame] | 898 | /** |
| 899 | * Get the variable that is ultimately referenced by an r-value |
| 900 | */ |
| 901 | virtual ir_variable *variable_referenced(); |
| 902 | |
Kenneth Graunke | affc141 | 2010-03-26 01:20:08 -0700 | [diff] [blame] | 903 | ir_rvalue *val; |
| 904 | ir_swizzle_mask mask; |
| 905 | }; |
| 906 | |
| 907 | |
Kenneth Graunke | fb9fb5f | 2010-03-26 00:25:36 -0700 | [diff] [blame] | 908 | class ir_dereference : public ir_rvalue { |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 909 | public: |
Kenneth Graunke | 44e1dfa | 2010-03-25 23:30:28 -0700 | [diff] [blame] | 910 | virtual ir_dereference *as_dereference() |
| 911 | { |
| 912 | return this; |
| 913 | } |
| 914 | |
Eric Anholt | c7da28b | 2010-04-01 20:27:35 -1000 | [diff] [blame] | 915 | bool is_lvalue(); |
Kenneth Graunke | fb9fb5f | 2010-03-26 00:25:36 -0700 | [diff] [blame] | 916 | |
Ian Romanick | 2b3c476 | 2010-05-14 17:35:42 -0700 | [diff] [blame] | 917 | /** |
| 918 | * Get the variable that is ultimately referenced by an r-value |
| 919 | */ |
Ian Romanick | 70fe8b6 | 2010-05-19 11:37:35 +0200 | [diff] [blame] | 920 | virtual ir_variable *variable_referenced() = 0; |
Ian Romanick | 70fe8b6 | 2010-05-19 11:37:35 +0200 | [diff] [blame] | 921 | }; |
| 922 | |
| 923 | |
| 924 | class ir_dereference_variable : public ir_dereference { |
| 925 | public: |
| 926 | ir_dereference_variable(ir_variable *var); |
| 927 | |
| 928 | /** |
| 929 | * Get the variable that is ultimately referenced by an r-value |
| 930 | */ |
| 931 | virtual ir_variable *variable_referenced() |
| 932 | { |
Ian Romanick | 36ea286 | 2010-05-19 13:52:29 +0200 | [diff] [blame] | 933 | return this->var; |
Ian Romanick | 70fe8b6 | 2010-05-19 11:37:35 +0200 | [diff] [blame] | 934 | } |
Ian Romanick | f3a002b | 2010-05-19 12:02:19 +0200 | [diff] [blame] | 935 | |
Ian Romanick | b067db2 | 2010-05-26 11:32:52 -0700 | [diff] [blame] | 936 | virtual ir_variable *whole_variable_referenced() |
| 937 | { |
| 938 | /* ir_dereference_variable objects always dereference the entire |
| 939 | * variable. However, if this dereference is dereferenced by anything |
| 940 | * else, the complete deferefernce chain is not a whole-variable |
| 941 | * dereference. This method should only be called on the top most |
| 942 | * ir_rvalue in a dereference chain. |
| 943 | */ |
| 944 | return this->var; |
| 945 | } |
| 946 | |
Ian Romanick | c7b1046 | 2010-05-19 13:20:12 +0200 | [diff] [blame] | 947 | virtual void accept(ir_visitor *v) |
| 948 | { |
| 949 | v->visit(this); |
| 950 | } |
| 951 | |
Ian Romanick | f3a002b | 2010-05-19 12:02:19 +0200 | [diff] [blame] | 952 | virtual ir_visitor_status accept(ir_hierarchical_visitor *); |
Ian Romanick | 36ea286 | 2010-05-19 13:52:29 +0200 | [diff] [blame] | 953 | |
| 954 | /** |
| 955 | * Object being dereferenced. |
| 956 | */ |
| 957 | ir_variable *var; |
Ian Romanick | 70fe8b6 | 2010-05-19 11:37:35 +0200 | [diff] [blame] | 958 | }; |
| 959 | |
| 960 | |
| 961 | class ir_dereference_array : public ir_dereference { |
| 962 | public: |
| 963 | ir_dereference_array(ir_rvalue *value, ir_rvalue *array_index); |
| 964 | |
| 965 | ir_dereference_array(ir_variable *var, ir_rvalue *array_index); |
| 966 | |
Eric Anholt | b145e90 | 2010-05-11 11:31:09 -0700 | [diff] [blame] | 967 | virtual ir_dereference_array *as_dereference_array() |
| 968 | { |
| 969 | return this; |
| 970 | } |
| 971 | |
Ian Romanick | 70fe8b6 | 2010-05-19 11:37:35 +0200 | [diff] [blame] | 972 | /** |
| 973 | * Get the variable that is ultimately referenced by an r-value |
| 974 | */ |
| 975 | virtual ir_variable *variable_referenced() |
| 976 | { |
Ian Romanick | 36ea286 | 2010-05-19 13:52:29 +0200 | [diff] [blame] | 977 | return this->array->variable_referenced(); |
Ian Romanick | 70fe8b6 | 2010-05-19 11:37:35 +0200 | [diff] [blame] | 978 | } |
| 979 | |
Ian Romanick | c7b1046 | 2010-05-19 13:20:12 +0200 | [diff] [blame] | 980 | virtual void accept(ir_visitor *v) |
| 981 | { |
| 982 | v->visit(this); |
| 983 | } |
| 984 | |
Ian Romanick | f3a002b | 2010-05-19 12:02:19 +0200 | [diff] [blame] | 985 | virtual ir_visitor_status accept(ir_hierarchical_visitor *); |
Ian Romanick | 70fe8b6 | 2010-05-19 11:37:35 +0200 | [diff] [blame] | 986 | |
Ian Romanick | 36ea286 | 2010-05-19 13:52:29 +0200 | [diff] [blame] | 987 | ir_rvalue *array; |
| 988 | ir_rvalue *array_index; |
| 989 | |
Ian Romanick | 70fe8b6 | 2010-05-19 11:37:35 +0200 | [diff] [blame] | 990 | private: |
| 991 | void set_array(ir_rvalue *value); |
| 992 | }; |
| 993 | |
| 994 | |
| 995 | class ir_dereference_record : public ir_dereference { |
| 996 | public: |
| 997 | ir_dereference_record(ir_rvalue *value, const char *field); |
| 998 | |
| 999 | ir_dereference_record(ir_variable *var, const char *field); |
| 1000 | |
| 1001 | /** |
| 1002 | * Get the variable that is ultimately referenced by an r-value |
| 1003 | */ |
| 1004 | virtual ir_variable *variable_referenced() |
| 1005 | { |
Ian Romanick | 36ea286 | 2010-05-19 13:52:29 +0200 | [diff] [blame] | 1006 | return this->record->variable_referenced(); |
Ian Romanick | 70fe8b6 | 2010-05-19 11:37:35 +0200 | [diff] [blame] | 1007 | } |
Ian Romanick | f3a002b | 2010-05-19 12:02:19 +0200 | [diff] [blame] | 1008 | |
Ian Romanick | c7b1046 | 2010-05-19 13:20:12 +0200 | [diff] [blame] | 1009 | virtual void accept(ir_visitor *v) |
| 1010 | { |
| 1011 | v->visit(this); |
| 1012 | } |
| 1013 | |
Ian Romanick | f3a002b | 2010-05-19 12:02:19 +0200 | [diff] [blame] | 1014 | virtual ir_visitor_status accept(ir_hierarchical_visitor *); |
Ian Romanick | 36ea286 | 2010-05-19 13:52:29 +0200 | [diff] [blame] | 1015 | |
| 1016 | ir_rvalue *record; |
| 1017 | const char *field; |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 1018 | }; |
| 1019 | |
| 1020 | |
Ian Romanick | be1d2bf | 2010-06-11 14:01:44 -0700 | [diff] [blame] | 1021 | /** |
| 1022 | * Data stored in an ir_constant |
| 1023 | */ |
| 1024 | union ir_constant_data { |
| 1025 | unsigned u[16]; |
| 1026 | int i[16]; |
| 1027 | float f[16]; |
| 1028 | bool b[16]; |
| 1029 | }; |
| 1030 | |
| 1031 | |
Kenneth Graunke | fb9fb5f | 2010-03-26 00:25:36 -0700 | [diff] [blame] | 1032 | class ir_constant : public ir_rvalue { |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 1033 | public: |
Ian Romanick | 824b659 | 2010-06-11 16:57:47 -0700 | [diff] [blame^] | 1034 | ir_constant(const struct glsl_type *type, const ir_constant_data *data); |
Eric Anholt | 3c36b2d | 2010-03-26 12:07:44 -0700 | [diff] [blame] | 1035 | ir_constant(bool b); |
| 1036 | ir_constant(unsigned int u); |
| 1037 | ir_constant(int i); |
| 1038 | ir_constant(float f); |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 1039 | |
Ian Romanick | 989cfc4 | 2010-06-04 16:13:35 -0700 | [diff] [blame] | 1040 | /** |
Ian Romanick | 756a3fa | 2010-06-04 16:34:38 -0700 | [diff] [blame] | 1041 | * Construct an ir_constant from a list of ir_constant values |
| 1042 | */ |
| 1043 | ir_constant(const struct glsl_type *type, exec_list *values); |
| 1044 | |
| 1045 | /** |
Ian Romanick | 989cfc4 | 2010-06-04 16:13:35 -0700 | [diff] [blame] | 1046 | * Construct an ir_constant from a scalar component of another ir_constant |
| 1047 | * |
| 1048 | * The new \c ir_constant inherits the type of the component from the |
| 1049 | * source constant. |
| 1050 | * |
| 1051 | * \note |
| 1052 | * In the case of a matrix constant, the new constant is a scalar, \b not |
| 1053 | * a vector. |
| 1054 | */ |
| 1055 | ir_constant(const ir_constant *c, unsigned i); |
| 1056 | |
Eric Anholt | 5c89f0e | 2010-05-04 13:04:40 -0700 | [diff] [blame] | 1057 | virtual ir_constant *as_constant() |
| 1058 | { |
| 1059 | return this; |
| 1060 | } |
| 1061 | |
Ian Romanick | 78b51b0 | 2010-03-09 16:23:37 -0800 | [diff] [blame] | 1062 | virtual void accept(ir_visitor *v) |
| 1063 | { |
| 1064 | v->visit(this); |
| 1065 | } |
| 1066 | |
Ian Romanick | 8895bae | 2010-05-14 12:39:23 -0700 | [diff] [blame] | 1067 | virtual ir_visitor_status accept(ir_hierarchical_visitor *); |
| 1068 | |
Ian Romanick | 710919f | 2010-06-09 17:18:04 -0700 | [diff] [blame] | 1069 | ir_constant *clone(); |
Eric Anholt | cad9766 | 2010-04-07 11:46:26 -0700 | [diff] [blame] | 1070 | |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 1071 | /** |
Ian Romanick | 3188190 | 2010-06-04 16:30:07 -0700 | [diff] [blame] | 1072 | * Get a particular component of a constant as a specific type |
| 1073 | * |
| 1074 | * This is useful, for example, to get a value from an integer constant |
| 1075 | * as a float or bool. This appears frequently when constructors are |
| 1076 | * called with all constant parameters. |
| 1077 | */ |
| 1078 | /*@{*/ |
| 1079 | bool get_bool_component(unsigned i) const; |
| 1080 | float get_float_component(unsigned i) const; |
| 1081 | int get_int_component(unsigned i) const; |
| 1082 | unsigned get_uint_component(unsigned i) const; |
| 1083 | /*@}*/ |
| 1084 | |
Ian Romanick | b94c29a | 2010-06-09 17:28:54 -0700 | [diff] [blame] | 1085 | ir_constant *get_record_field(const char *name); |
| 1086 | |
Ian Romanick | 3188190 | 2010-06-04 16:30:07 -0700 | [diff] [blame] | 1087 | /** |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 1088 | * Value of the constant. |
| 1089 | * |
| 1090 | * The field used to back the values supplied by the constant is determined |
| 1091 | * by the type associated with the \c ir_instruction. Constants may be |
| 1092 | * scalars, vectors, or matrices. |
| 1093 | */ |
Ian Romanick | be1d2bf | 2010-06-11 14:01:44 -0700 | [diff] [blame] | 1094 | union ir_constant_data value; |
Ian Romanick | 7f1ab83 | 2010-06-09 17:11:50 -0700 | [diff] [blame] | 1095 | |
| 1096 | exec_list components; |
Ian Romanick | 710919f | 2010-06-09 17:18:04 -0700 | [diff] [blame] | 1097 | |
| 1098 | private: |
| 1099 | /** |
| 1100 | * Parameterless constructor only used by the clone method |
| 1101 | */ |
| 1102 | ir_constant(void); |
Ian Romanick | a87ac25 | 2010-02-22 13:19:34 -0800 | [diff] [blame] | 1103 | }; |
| 1104 | |
Eric Anholt | 70b7492 | 2010-04-06 11:52:09 -0700 | [diff] [blame] | 1105 | void |
| 1106 | visit_exec_list(exec_list *list, ir_visitor *visitor); |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 1107 | |
| 1108 | extern void |
| 1109 | _mesa_glsl_initialize_variables(exec_list *instructions, |
| 1110 | struct _mesa_glsl_parse_state *state); |
Ian Romanick | e309a60 | 2010-03-15 15:20:15 -0700 | [diff] [blame] | 1111 | |
Eric Anholt | c22c400 | 2010-03-26 18:20:30 -0700 | [diff] [blame] | 1112 | extern void |
| 1113 | _mesa_glsl_initialize_functions(exec_list *instructions, |
| 1114 | struct _mesa_glsl_parse_state *state); |
| 1115 | |
Ian Romanick | e309a60 | 2010-03-15 15:20:15 -0700 | [diff] [blame] | 1116 | #endif /* IR_H */ |