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