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