blob: 3d2c7ff5cf56be6ab0a52155ed840e65420c8551 [file] [log] [blame]
Ian Romanick986b8f72010-03-10 13:58:12 -08001/* -*- c++ -*- */
Ian Romanicka87ac252010-02-22 13:19:34 -08002/*
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 Romanicke309a602010-03-15 15:20:15 -070025#pragma once
26#ifndef IR_H
27#define IR_H
28
Eric Anholtac95f2f2010-06-22 10:38:52 -070029#include <cstdio>
30#include <cstdlib>
31
Carl Worthf961e442010-06-23 15:47:04 -070032extern "C" {
33#include <talloc.h>
34}
35
Ian Romanick0044e7e2010-03-08 23:44:00 -080036#include "list.h"
Ian Romanick78b51b02010-03-09 16:23:37 -080037#include "ir_visitor.h"
Ian Romanick8895bae2010-05-14 12:39:23 -070038#include "ir_hierarchical_visitor.h"
Ian Romanick0044e7e2010-03-08 23:44:00 -080039
Eric Anholt829e0a82010-05-06 13:09:54 -070040#ifndef ARRAY_SIZE
41#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
42#endif
43
Ian Romanicka87ac252010-02-22 13:19:34 -080044struct ir_program {
45 void *bong_hits;
46};
47
Ian Romanicka87ac252010-02-22 13:19:34 -080048/**
49 * Base class of all IR instructions
50 */
Ian Romanick0044e7e2010-03-08 23:44:00 -080051class ir_instruction : public exec_node {
Ian Romanicka87ac252010-02-22 13:19:34 -080052public:
Ian Romanicka87ac252010-02-22 13:19:34 -080053 const struct glsl_type *type;
54
Ian Romanick1cf43a42010-03-30 16:56:50 -070055 class ir_constant *constant_expression_value();
Eric Anholte46a4542010-06-22 12:09:21 -070056
57 /** ir_print_visitor helper for debugging. */
Eric Anholt4b6fd392010-06-23 11:37:12 -070058 void print(void) const;
Eric Anholte46a4542010-06-22 12:09:21 -070059
Ian Romanick78b51b02010-03-09 16:23:37 -080060 virtual void accept(ir_visitor *) = 0;
Ian Romanick8895bae2010-05-14 12:39:23 -070061 virtual ir_visitor_status accept(ir_hierarchical_visitor *) = 0;
Eric Anholt4b6fd392010-06-23 11:37:12 -070062 virtual ir_instruction *clone(struct hash_table *ht) const = 0;
Ian Romanick78b51b02010-03-09 16:23:37 -080063
Kenneth Graunke44e1dfa2010-03-25 23:30:28 -070064 /**
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 Graunke6202cbf2010-04-21 16:02:15 -070073 virtual class ir_function * as_function() { return NULL; }
Kenneth Graunke44e1dfa2010-03-25 23:30:28 -070074 virtual class ir_dereference * as_dereference() { return NULL; }
Eric Anholtb145e902010-05-11 11:31:09 -070075 virtual class ir_dereference_array * as_dereference_array() { return NULL; }
Kenneth Graunkefb9fb5f2010-03-26 00:25:36 -070076 virtual class ir_rvalue * as_rvalue() { return NULL; }
Ian Romanick01f8de42010-04-05 17:13:14 -070077 virtual class ir_loop * as_loop() { return NULL; }
Eric Anholtcad97662010-04-07 11:46:26 -070078 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 Anholt5ba94202010-04-14 17:03:03 -070081 virtual class ir_if * as_if() { return NULL; }
Eric Anholt7d211042010-04-16 16:43:47 -070082 virtual class ir_swizzle * as_swizzle() { return NULL; }
Eric Anholt5c89f0e2010-05-04 13:04:40 -070083 virtual class ir_constant * as_constant() { return NULL; }
Kenneth Graunke44e1dfa2010-03-25 23:30:28 -070084 /*@}*/
85
Ian Romanicka87ac252010-02-22 13:19:34 -080086protected:
Kenneth Graunke44e1dfa2010-03-25 23:30:28 -070087 ir_instruction()
Ian Romanickd27ec242010-03-11 14:23:41 -080088 {
89 /* empty */
90 }
Ian Romanicka87ac252010-02-22 13:19:34 -080091};
92
93
Kenneth Graunkefb9fb5f2010-03-26 00:25:36 -070094class ir_rvalue : public ir_instruction {
95public:
96 virtual ir_rvalue * as_rvalue()
97 {
98 return this;
99 }
100
101 virtual bool is_lvalue()
102 {
103 return false;
104 }
105
Ian Romanick2b3c4762010-05-14 17:35:42 -0700106 /**
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 Romanickb067db22010-05-26 11:32:52 -0700114
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 Graunkefb9fb5f2010-03-26 00:25:36 -0700129protected:
Ian Romanickb427c912010-04-07 18:03:50 -0700130 ir_rvalue()
131 {
132 /* empty */
133 }
Kenneth Graunkefb9fb5f2010-03-26 00:25:36 -0700134};
135
136
Ian Romanicka87ac252010-02-22 13:19:34 -0800137enum 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 Wortha22426d2010-06-17 00:37:39 -0700145enum ir_variable_interpolation {
Ian Romanicka87ac252010-02-22 13:19:34 -0800146 ir_var_smooth = 0,
147 ir_var_flat,
148 ir_var_noperspective
149};
150
Kenneth Graunkefb9fb5f2010-03-26 00:25:36 -0700151
Ian Romanicka87ac252010-02-22 13:19:34 -0800152class ir_variable : public ir_instruction {
153public:
154 ir_variable(const struct glsl_type *, const char *);
155
Eric Anholt4b6fd392010-06-23 11:37:12 -0700156 virtual ir_instruction *clone(struct hash_table *ht) const;
157
Kenneth Graunke44e1dfa2010-03-25 23:30:28 -0700158 virtual ir_variable *as_variable()
159 {
160 return this;
161 }
162
Ian Romanick78b51b02010-03-09 16:23:37 -0800163 virtual void accept(ir_visitor *v)
164 {
165 v->visit(this);
166 }
167
Ian Romanick8895bae2010-05-14 12:39:23 -0700168 virtual ir_visitor_status accept(ir_hierarchical_visitor *);
169
Ian Romanick2d394d42010-03-31 17:52:44 -0700170
Ian Romanick950ceb22010-06-18 19:00:28 -0700171 /**
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 Romanick8b80e9f2010-06-21 16:05:29 -0700181 /**
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 Romanicka87ac252010-02-22 13:19:34 -0800189 const char *name;
190
Ian Romanickb8a21cc2010-04-01 18:31:11 -0700191 /**
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 Romanicka87ac252010-02-22 13:19:34 -0800198 unsigned read_only:1;
199 unsigned centroid:1;
200 unsigned invariant:1;
Eric Anholt71df19f2010-04-19 11:10:37 -0700201 /** 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 Romanicka87ac252010-02-22 13:19:34 -0800207
208 unsigned mode:3;
209 unsigned interpolation:2;
Ian Romanick9d975372010-04-02 17:17:47 -0700210
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 Anholt326c6762010-04-06 10:30:54 -0700218
219 /**
Ian Romanick69a079a2010-06-21 11:42:02 -0700220 * 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 Romanickc178c742010-04-07 16:53:54 -0700237 * Emit a warning if this variable is accessed.
238 */
239 const char *warn_extension;
240
241 /**
Eric Anholt326c6762010-04-06 10:30:54 -0700242 * Value assigned in the initializer of a variable declared "const"
243 */
244 ir_constant *constant_value;
Ian Romanicka87ac252010-02-22 13:19:34 -0800245};
246
247
Ian Romanicka87ac252010-02-22 13:19:34 -0800248/*@{*/
Kenneth Graunke9fa99f32010-04-21 12:30:22 -0700249/**
250 * The representation of a function instance; may be the full definition or
251 * simply a prototype.
252 */
Ian Romanicka87ac252010-02-22 13:19:34 -0800253class ir_function_signature : public ir_instruction {
Eric Anholt894ea972010-04-07 13:19:11 -0700254 /* An ir_function_signature will be part of the list of signatures in
255 * an ir_function.
256 */
Ian Romanicka87ac252010-02-22 13:19:34 -0800257public:
Ian Romanicke39cc692010-03-23 12:19:13 -0700258 ir_function_signature(const glsl_type *return_type);
Ian Romanicka87ac252010-02-22 13:19:34 -0800259
Eric Anholt4b6fd392010-06-23 11:37:12 -0700260 virtual ir_instruction *clone(struct hash_table *ht) const;
261
Ian Romanick78b51b02010-03-09 16:23:37 -0800262 virtual void accept(ir_visitor *v)
263 {
264 v->visit(this);
265 }
266
Ian Romanick8895bae2010-05-14 12:39:23 -0700267 virtual ir_visitor_status accept(ir_hierarchical_visitor *);
268
Ian Romanicka87ac252010-02-22 13:19:34 -0800269 /**
Ian Romanick0f0ea582010-03-31 16:44:12 -0700270 * Get the name of the function for which this is a signature
271 */
272 const char *function_name() const;
273
274 /**
Kenneth Graunkeabd40b12010-04-28 11:49:12 -0700275 * 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 Graunkebff60132010-04-28 12:44:24 -0700282 * 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 Romanicka87ac252010-02-22 13:19:34 -0800289 * Function return type.
290 *
291 * \note This discards the optional precision qualifier.
292 */
293 const struct glsl_type *return_type;
294
295 /**
Eric Anholtf1ddca92010-04-07 12:35:34 -0700296 * 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 Romanicka87ac252010-02-22 13:19:34 -0800300 */
Ian Romanick0044e7e2010-03-08 23:44:00 -0800301 struct exec_list parameters;
Ian Romanicka87ac252010-02-22 13:19:34 -0800302
Kenneth Graunke9fa99f32010-04-21 12:30:22 -0700303 /** Whether or not this function has a body (which may be empty). */
304 unsigned is_defined:1;
Ian Romanick6a15d5b2010-03-31 16:37:10 -0700305
Eric Anholt894ea972010-04-07 13:19:11 -0700306 /** Body of instructions in the function. */
307 struct exec_list body;
308
Ian Romanick6a15d5b2010-03-31 16:37:10 -0700309private:
310 /** Function of which this signature is one overload. */
311 class ir_function *function;
312
313 friend class ir_function;
Ian Romanicka87ac252010-02-22 13:19:34 -0800314};
315
316
317/**
Kenneth Graunke9fa99f32010-04-21 12:30:22 -0700318 * 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 Romanicka87ac252010-02-22 13:19:34 -0800321 */
322class ir_function : public ir_instruction {
323public:
Ian Romanick882dad72010-03-23 17:42:04 -0700324 ir_function(const char *name);
Ian Romanicka87ac252010-02-22 13:19:34 -0800325
Eric Anholt4b6fd392010-06-23 11:37:12 -0700326 virtual ir_instruction *clone(struct hash_table *ht) const;
327
Kenneth Graunke6202cbf2010-04-21 16:02:15 -0700328 virtual ir_function *as_function()
329 {
330 return this;
331 }
332
Ian Romanick78b51b02010-03-09 16:23:37 -0800333 virtual void accept(ir_visitor *v)
334 {
335 v->visit(this);
336 }
337
Ian Romanick8895bae2010-05-14 12:39:23 -0700338 virtual ir_visitor_status accept(ir_hierarchical_visitor *);
339
Ian Romanick6a15d5b2010-03-31 16:37:10 -0700340 void add_signature(ir_function_signature *sig)
341 {
342 sig->function = this;
343 signatures.push_tail(sig);
344 }
345
Ian Romanicka87ac252010-02-22 13:19:34 -0800346 /**
Ian Romanick95cd6cc2010-03-31 16:40:26 -0700347 * Get an iterator for the set of function signatures
348 */
349 exec_list_iterator iterator()
350 {
351 return signatures.iterator();
352 }
353
354 /**
Kenneth Graunke0d605cb2010-04-28 12:04:23 -0700355 * Find a signature that matches a set of actual parameters, taking implicit
356 * conversions into account.
Ian Romanick471471f2010-03-11 14:50:30 -0800357 */
358 const ir_function_signature *matching_signature(exec_list *actual_param);
359
360 /**
Kenneth Graunke0d605cb2010-04-28 12:04:23 -0700361 * 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 Romanicka87ac252010-02-22 13:19:34 -0800367 * Name of the function.
368 */
369 const char *name;
370
Ian Romanicka4775822010-03-31 16:40:58 -0700371private:
Ian Romanick471471f2010-03-11 14:50:30 -0800372 /**
Eric Anholtf1ddca92010-04-07 12:35:34 -0700373 * List of ir_function_signature for each overloaded function with this name.
Ian Romanick471471f2010-03-11 14:50:30 -0800374 */
Ian Romanick0044e7e2010-03-08 23:44:00 -0800375 struct exec_list signatures;
Ian Romanicka87ac252010-02-22 13:19:34 -0800376};
Ian Romanick0f0ea582010-03-31 16:44:12 -0700377
378inline const char *ir_function_signature::function_name() const
379{
380 return function->name;
381}
Ian Romanicka87ac252010-02-22 13:19:34 -0800382/*@}*/
383
Ian Romanicka87ac252010-02-22 13:19:34 -0800384
Ian Romanick3c6fea32010-03-29 14:11:25 -0700385/**
386 * IR instruction representing high-level if-statements
387 */
388class ir_if : public ir_instruction {
389public:
390 ir_if(ir_rvalue *condition)
391 : condition(condition)
392 {
393 /* empty */
394 }
395
Eric Anholt4b6fd392010-06-23 11:37:12 -0700396 virtual ir_instruction *clone(struct hash_table *ht) const;
397
Eric Anholt5ba94202010-04-14 17:03:03 -0700398 virtual ir_if *as_if()
399 {
400 return this;
401 }
402
Ian Romanick3c6fea32010-03-29 14:11:25 -0700403 virtual void accept(ir_visitor *v)
404 {
405 v->visit(this);
406 }
407
Ian Romanick8895bae2010-05-14 12:39:23 -0700408 virtual ir_visitor_status accept(ir_hierarchical_visitor *);
409
Ian Romanick3c6fea32010-03-29 14:11:25 -0700410 ir_rvalue *condition;
Eric Anholtf1ddca92010-04-07 12:35:34 -0700411 /** List of ir_instruction for the body of the then branch */
Ian Romanick3c6fea32010-03-29 14:11:25 -0700412 exec_list then_instructions;
Eric Anholtf1ddca92010-04-07 12:35:34 -0700413 /** List of ir_instruction for the body of the else branch */
Ian Romanick3c6fea32010-03-29 14:11:25 -0700414 exec_list else_instructions;
415};
416
417
Ian Romanickfad607a2010-04-05 16:16:07 -0700418/**
419 * IR instruction representing a high-level loop structure.
420 */
421class ir_loop : public ir_instruction {
422public:
423 ir_loop() : from(NULL), to(NULL), increment(NULL), counter(NULL)
424 {
425 /* empty */
426 }
427
Eric Anholt4b6fd392010-06-23 11:37:12 -0700428 virtual ir_instruction *clone(struct hash_table *ht) const;
429
Ian Romanickfad607a2010-04-05 16:16:07 -0700430 virtual void accept(ir_visitor *v)
431 {
432 v->visit(this);
433 }
434
Ian Romanick8895bae2010-05-14 12:39:23 -0700435 virtual ir_visitor_status accept(ir_hierarchical_visitor *);
436
Ian Romanick01f8de42010-04-05 17:13:14 -0700437 virtual ir_loop *as_loop()
438 {
439 return this;
440 }
441
Ian Romanickfad607a2010-04-05 16:16:07 -0700442 /**
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 Anholtf1ddca92010-04-07 12:35:34 -0700450 /** List of ir_instruction that make up the body of the loop. */
Ian Romanickfad607a2010-04-05 16:16:07 -0700451 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 Graunkefb9fb5f2010-03-26 00:25:36 -0700465class ir_assignment : public ir_rvalue {
Ian Romanicka87ac252010-02-22 13:19:34 -0800466public:
Kenneth Graunkefb9fb5f2010-03-26 00:25:36 -0700467 ir_assignment(ir_rvalue *lhs, ir_rvalue *rhs, ir_rvalue *condition);
Ian Romanicka87ac252010-02-22 13:19:34 -0800468
Eric Anholt4b6fd392010-06-23 11:37:12 -0700469 virtual ir_instruction *clone(struct hash_table *ht) const;
470
Ian Romanick78b51b02010-03-09 16:23:37 -0800471 virtual void accept(ir_visitor *v)
472 {
473 v->visit(this);
474 }
475
Ian Romanick8895bae2010-05-14 12:39:23 -0700476 virtual ir_visitor_status accept(ir_hierarchical_visitor *);
477
Eric Anholtcad97662010-04-07 11:46:26 -0700478 virtual ir_assignment * as_assignment()
479 {
480 return this;
481 }
482
Ian Romanicka87ac252010-02-22 13:19:34 -0800483 /**
484 * Left-hand side of the assignment.
485 */
Kenneth Graunkefb9fb5f2010-03-26 00:25:36 -0700486 ir_rvalue *lhs;
Ian Romanicka87ac252010-02-22 13:19:34 -0800487
488 /**
489 * Value being assigned
Ian Romanicka87ac252010-02-22 13:19:34 -0800490 */
Kenneth Graunkefb9fb5f2010-03-26 00:25:36 -0700491 ir_rvalue *rhs;
Ian Romanicka87ac252010-02-22 13:19:34 -0800492
493 /**
494 * Optional condition for the assignment.
495 */
Kenneth Graunkefb9fb5f2010-03-26 00:25:36 -0700496 ir_rvalue *condition;
Ian Romanicka87ac252010-02-22 13:19:34 -0800497};
498
Kenneth Graunke3b969962010-04-07 17:18:29 -0700499/* Update ir_expression::num_operands() and operator_strs when
Eric Anholt160d0922010-04-01 18:07:08 -1000500 * updating this list.
Kenneth Graunke3b969962010-04-07 17:18:29 -0700501 */
Ian Romanicka87ac252010-02-22 13:19:34 -0800502enum ir_expression_operation {
503 ir_unop_bit_not,
504 ir_unop_logic_not,
505 ir_unop_neg,
506 ir_unop_abs,
Kenneth Graunkea4b7b5a2010-05-03 20:05:57 -0700507 ir_unop_sign,
Ian Romanicka87ac252010-02-22 13:19:34 -0800508 ir_unop_rcp,
509 ir_unop_rsq,
Eric Anholt44d68fd2010-03-27 13:01:51 -0700510 ir_unop_sqrt,
Ian Romanicka87ac252010-02-22 13:19:34 -0800511 ir_unop_exp,
512 ir_unop_log,
Eric Anholt01665262010-03-27 13:56:35 -0700513 ir_unop_exp2,
514 ir_unop_log2,
Ian Romanicka87ac252010-02-22 13:19:34 -0800515 ir_unop_f2i, /**< Float-to-integer conversion. */
516 ir_unop_i2f, /**< Integer-to-float conversion. */
Eric Anholtdc58b3f2010-04-02 02:13:43 -1000517 ir_unop_f2b, /**< Float-to-boolean conversion */
518 ir_unop_b2f, /**< Boolean-to-float conversion */
Eric Anholtc2cb84e2010-04-02 02:17:08 -1000519 ir_unop_i2b, /**< int-to-boolean conversion */
520 ir_unop_b2i, /**< Boolean-to-int conversion */
Ian Romanick6c86ea82010-03-26 16:11:48 -0700521 ir_unop_u2f, /**< Unsigned-to-float conversion. */
Ian Romanicka87ac252010-02-22 13:19:34 -0800522
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 Graunke57e7da12010-05-03 22:11:17 -0700532 /**
533 * \name Trigonometric operations.
534 */
535 /*@{*/
536 ir_unop_sin,
537 ir_unop_cos,
538 /*@}*/
539
Kenneth Graunkeb843c7a2010-06-09 14:42:41 -0700540 /**
541 * \name Partial derivatives.
542 */
543 /*@{*/
544 ir_unop_dFdx,
545 ir_unop_dFdy,
546 /*@}*/
547
Ian Romanicka87ac252010-02-22 13:19:34 -0800548 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 Romanicka87ac252010-02-22 13:19:34 -0800580
581 ir_binop_dot,
582 ir_binop_min,
583 ir_binop_max,
584
585 ir_binop_pow
586};
587
Kenneth Graunkefb9fb5f2010-03-26 00:25:36 -0700588class ir_expression : public ir_rvalue {
Ian Romanicka87ac252010-02-22 13:19:34 -0800589public:
590 ir_expression(int op, const struct glsl_type *type,
Kenneth Graunkefb9fb5f2010-03-26 00:25:36 -0700591 ir_rvalue *, ir_rvalue *);
Ian Romanicka87ac252010-02-22 13:19:34 -0800592
Eric Anholt4b6fd392010-06-23 11:37:12 -0700593 virtual ir_instruction *clone(struct hash_table *ht) const;
594
Kenneth Graunke7dd6adb2010-04-07 16:56:57 -0700595 static unsigned int get_num_operands(ir_expression_operation);
Eric Anholt4b6fd392010-06-23 11:37:12 -0700596 unsigned int get_num_operands() const
Kenneth Graunke7dd6adb2010-04-07 16:56:57 -0700597 {
598 return get_num_operands(operation);
599 }
Eric Anholt160d0922010-04-01 18:07:08 -1000600
Kenneth Graunke3b969962010-04-07 17:18:29 -0700601 /**
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 Romanick78b51b02010-03-09 16:23:37 -0800611 virtual void accept(ir_visitor *v)
612 {
613 v->visit(this);
614 }
615
Ian Romanick8895bae2010-05-14 12:39:23 -0700616 virtual ir_visitor_status accept(ir_hierarchical_visitor *);
617
Ian Romanicka87ac252010-02-22 13:19:34 -0800618 ir_expression_operation operation;
Kenneth Graunkefb9fb5f2010-03-26 00:25:36 -0700619 ir_rvalue *operands[2];
Ian Romanicka87ac252010-02-22 13:19:34 -0800620};
621
622
Ian Romanicked45ec62010-03-11 14:34:27 -0800623/**
624 * IR instruction representing a function call
625 */
Kenneth Graunkefb9fb5f2010-03-26 00:25:36 -0700626class ir_call : public ir_rvalue {
Ian Romanicked45ec62010-03-11 14:34:27 -0800627public:
Ian Romanick471471f2010-03-11 14:50:30 -0800628 ir_call(const ir_function_signature *callee, exec_list *actual_parameters)
Ian Romanickb427c912010-04-07 18:03:50 -0700629 : callee(callee)
Ian Romanicked45ec62010-03-11 14:34:27 -0800630 {
Ian Romanick9e7c34b2010-03-23 12:21:18 -0700631 assert(callee->return_type != NULL);
632 type = callee->return_type;
Ian Romanick471471f2010-03-11 14:50:30 -0800633 actual_parameters->move_nodes_to(& this->actual_parameters);
Ian Romanicked45ec62010-03-11 14:34:27 -0800634 }
635
Eric Anholt4b6fd392010-06-23 11:37:12 -0700636 virtual ir_instruction *clone(struct hash_table *ht) const;
637
Eric Anholtcad97662010-04-07 11:46:26 -0700638 virtual ir_call *as_call()
639 {
640 return this;
641 }
642
Ian Romanicked45ec62010-03-11 14:34:27 -0800643 virtual void accept(ir_visitor *v)
644 {
645 v->visit(this);
646 }
647
Ian Romanick8895bae2010-05-14 12:39:23 -0700648 virtual ir_visitor_status accept(ir_hierarchical_visitor *);
649
Ian Romanicked45ec62010-03-11 14:34:27 -0800650 /**
651 * Get a generic ir_call object when an error occurs
Carl Worthe01193a2010-06-23 18:25:04 -0700652 *
653 * Any allocation will be performed with 'ctx' as talloc owner.
Ian Romanicked45ec62010-03-11 14:34:27 -0800654 */
Carl Worthe01193a2010-06-23 18:25:04 -0700655 static ir_call *get_error_instruction(void *ctx);
Ian Romanicked45ec62010-03-11 14:34:27 -0800656
Ian Romanick9878c652010-03-26 17:19:47 -0700657 /**
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 Romanick93614bc2010-03-26 17:29:29 -0700665 /**
666 * Get the name of the function being called.
667 */
668 const char *callee_name() const
669 {
Ian Romanick0f0ea582010-03-31 16:44:12 -0700670 return callee->function_name();
Ian Romanick93614bc2010-03-26 17:29:29 -0700671 }
672
Eric Anholtcad97662010-04-07 11:46:26 -0700673 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 Romanicked45ec62010-03-11 14:34:27 -0800684private:
Ian Romanick471471f2010-03-11 14:50:30 -0800685 ir_call()
Ian Romanickb427c912010-04-07 18:03:50 -0700686 : callee(NULL)
Ian Romanick471471f2010-03-11 14:50:30 -0800687 {
688 /* empty */
689 }
690
691 const ir_function_signature *callee;
Eric Anholtf1ddca92010-04-07 12:35:34 -0700692
693 /* List of ir_rvalue of paramaters passed in this call. */
Ian Romanicked45ec62010-03-11 14:34:27 -0800694 exec_list actual_parameters;
695};
696
697
Ian Romanick9578c872010-03-19 16:44:52 -0700698/**
699 * \name Jump-like IR instructions.
700 *
701 * These include \c break, \c continue, \c return, and \c discard.
702 */
703/*@{*/
704class ir_jump : public ir_instruction {
705protected:
706 ir_jump()
Ian Romanick9578c872010-03-19 16:44:52 -0700707 {
708 /* empty */
709 }
710};
711
712class ir_return : public ir_jump {
713public:
714 ir_return()
715 : value(NULL)
716 {
717 /* empty */
718 }
719
Kenneth Graunkefb9fb5f2010-03-26 00:25:36 -0700720 ir_return(ir_rvalue *value)
Ian Romanick9578c872010-03-19 16:44:52 -0700721 : value(value)
722 {
723 /* empty */
724 }
725
Eric Anholt4b6fd392010-06-23 11:37:12 -0700726 virtual ir_instruction *clone(struct hash_table *) const;
727
Eric Anholtcad97662010-04-07 11:46:26 -0700728 virtual ir_return *as_return()
729 {
730 return this;
731 }
732
Kenneth Graunkefb9fb5f2010-03-26 00:25:36 -0700733 ir_rvalue *get_value() const
Ian Romanick9578c872010-03-19 16:44:52 -0700734 {
735 return value;
736 }
737
738 virtual void accept(ir_visitor *v)
739 {
740 v->visit(this);
741 }
742
Ian Romanick8895bae2010-05-14 12:39:23 -0700743 virtual ir_visitor_status accept(ir_hierarchical_visitor *);
744
Kenneth Graunkefb9fb5f2010-03-26 00:25:36 -0700745 ir_rvalue *value;
Ian Romanick9578c872010-03-19 16:44:52 -0700746};
Ian Romanickf8e31e02010-04-05 16:28:15 -0700747
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 */
757class ir_loop_jump : public ir_jump {
758public:
759 enum jump_mode {
760 jump_break,
761 jump_continue
762 };
763
Eric Anholt4b6fd392010-06-23 11:37:12 -0700764 ir_loop_jump(jump_mode mode)
Ian Romanickf8e31e02010-04-05 16:28:15 -0700765 {
Eric Anholt0c005bd2010-05-07 12:35:47 -0700766 this->mode = mode;
767 this->loop = loop;
Ian Romanickf8e31e02010-04-05 16:28:15 -0700768 }
769
Eric Anholt4b6fd392010-06-23 11:37:12 -0700770 virtual ir_instruction *clone(struct hash_table *) const;
771
Ian Romanickf8e31e02010-04-05 16:28:15 -0700772 virtual void accept(ir_visitor *v)
773 {
774 v->visit(this);
775 }
776
Ian Romanick8895bae2010-05-14 12:39:23 -0700777 virtual ir_visitor_status accept(ir_hierarchical_visitor *);
778
Ian Romanickf8e31e02010-04-05 16:28:15 -0700779 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 Romanickf8e31e02010-04-05 16:28:15 -0700789 /** Mode selector for the jump instruction. */
790 enum jump_mode mode;
Eric Anholt0c005bd2010-05-07 12:35:47 -0700791private:
792 /** Loop containing this break instruction. */
793 ir_loop *loop;
Ian Romanickf8e31e02010-04-05 16:28:15 -0700794};
Ian Romanick9578c872010-03-19 16:44:52 -0700795/*@}*/
796
797
Ian Romanick81377c02010-04-28 18:42:36 -0700798/**
799 * Texture sampling opcodes used in ir_texture
800 */
801enum 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 */
828class ir_texture : public ir_rvalue {
829public:
830 ir_texture(enum ir_texture_opcode op)
Kenneth Graunkeb97efa52010-06-09 11:07:53 -0700831 : op(op), projector(NULL), shadow_comparitor(NULL)
Ian Romanick81377c02010-04-28 18:42:36 -0700832 {
833 /* empty */
834 }
835
Eric Anholt4b6fd392010-06-23 11:37:12 -0700836 virtual ir_instruction *clone(struct hash_table *) const;
837
Kenneth Graunke26d74cd2010-05-26 17:42:03 -0700838 virtual void accept(ir_visitor *v)
839 {
840 v->visit(this);
841 }
842
843 virtual ir_visitor_status accept(ir_hierarchical_visitor *);
844
Kenneth Graunkec30f6e52010-05-26 16:41:47 -0700845 /**
846 * Return a string representing the ir_texture_opcode.
847 */
848 const char *opcode_string();
849
Kenneth Graunke56d3f6a2010-06-03 15:07:34 -0700850 /** Set the sampler and infer the type. */
851 void set_sampler(ir_dereference *sampler);
852
Kenneth Graunkec30f6e52010-05-26 16:41:47 -0700853 /**
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 Romanick81377c02010-04-28 18:42:36 -0700858 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 Romanicka87ac252010-02-22 13:19:34 -0800897struct 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 Graunkef25a5ad2010-03-25 11:22:42 -0700906 unsigned num_components:3;
Ian Romanicka87ac252010-02-22 13:19:34 -0800907
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 Graunkeaffc1412010-03-26 01:20:08 -0700916
917class ir_swizzle : public ir_rvalue {
918public:
919 ir_swizzle(ir_rvalue *, unsigned x, unsigned y, unsigned z, unsigned w,
920 unsigned count);
Eric Anholt05a4e592010-05-03 17:08:01 -0700921 ir_swizzle(ir_rvalue *val, ir_swizzle_mask mask);
Eric Anholtcad97662010-04-07 11:46:26 -0700922
Eric Anholt4b6fd392010-06-23 11:37:12 -0700923 virtual ir_instruction *clone(struct hash_table *) const;
924
Eric Anholt7d211042010-04-16 16:43:47 -0700925 virtual ir_swizzle *as_swizzle()
926 {
927 return this;
928 }
929
Kenneth Graunkeaffc1412010-03-26 01:20:08 -0700930 /**
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 Romanick8895bae2010-05-14 12:39:23 -0700940 virtual ir_visitor_status accept(ir_hierarchical_visitor *);
941
Kenneth Graunkeaffc1412010-03-26 01:20:08 -0700942 bool is_lvalue()
943 {
Eric Anholta9fafc62010-03-28 01:29:18 -0700944 return val->is_lvalue() && !mask.has_duplicates;
Kenneth Graunkeaffc1412010-03-26 01:20:08 -0700945 }
946
Ian Romanick2b3c4762010-05-14 17:35:42 -0700947 /**
948 * Get the variable that is ultimately referenced by an r-value
949 */
950 virtual ir_variable *variable_referenced();
951
Kenneth Graunkeaffc1412010-03-26 01:20:08 -0700952 ir_rvalue *val;
953 ir_swizzle_mask mask;
954};
955
956
Kenneth Graunkefb9fb5f2010-03-26 00:25:36 -0700957class ir_dereference : public ir_rvalue {
Ian Romanicka87ac252010-02-22 13:19:34 -0800958public:
Kenneth Graunke44e1dfa2010-03-25 23:30:28 -0700959 virtual ir_dereference *as_dereference()
960 {
961 return this;
962 }
963
Eric Anholtc7da28b2010-04-01 20:27:35 -1000964 bool is_lvalue();
Kenneth Graunkefb9fb5f2010-03-26 00:25:36 -0700965
Ian Romanick2b3c4762010-05-14 17:35:42 -0700966 /**
967 * Get the variable that is ultimately referenced by an r-value
968 */
Ian Romanick70fe8b62010-05-19 11:37:35 +0200969 virtual ir_variable *variable_referenced() = 0;
Ian Romanick70fe8b62010-05-19 11:37:35 +0200970};
971
972
973class ir_dereference_variable : public ir_dereference {
974public:
975 ir_dereference_variable(ir_variable *var);
976
Eric Anholt4b6fd392010-06-23 11:37:12 -0700977 virtual ir_instruction *clone(struct hash_table *) const;
978
Ian Romanick70fe8b62010-05-19 11:37:35 +0200979 /**
980 * Get the variable that is ultimately referenced by an r-value
981 */
982 virtual ir_variable *variable_referenced()
983 {
Ian Romanick36ea2862010-05-19 13:52:29 +0200984 return this->var;
Ian Romanick70fe8b62010-05-19 11:37:35 +0200985 }
Ian Romanickf3a002b2010-05-19 12:02:19 +0200986
Ian Romanickb067db22010-05-26 11:32:52 -0700987 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 Romanickc7b10462010-05-19 13:20:12 +0200998 virtual void accept(ir_visitor *v)
999 {
1000 v->visit(this);
1001 }
1002
Ian Romanickf3a002b2010-05-19 12:02:19 +02001003 virtual ir_visitor_status accept(ir_hierarchical_visitor *);
Ian Romanick36ea2862010-05-19 13:52:29 +02001004
1005 /**
1006 * Object being dereferenced.
1007 */
1008 ir_variable *var;
Ian Romanick70fe8b62010-05-19 11:37:35 +02001009};
1010
1011
1012class ir_dereference_array : public ir_dereference {
1013public:
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 Anholt4b6fd392010-06-23 11:37:12 -07001018 virtual ir_instruction *clone(struct hash_table *) const;
1019
Eric Anholtb145e902010-05-11 11:31:09 -07001020 virtual ir_dereference_array *as_dereference_array()
1021 {
1022 return this;
1023 }
1024
Ian Romanick70fe8b62010-05-19 11:37:35 +02001025 /**
1026 * Get the variable that is ultimately referenced by an r-value
1027 */
1028 virtual ir_variable *variable_referenced()
1029 {
Ian Romanick36ea2862010-05-19 13:52:29 +02001030 return this->array->variable_referenced();
Ian Romanick70fe8b62010-05-19 11:37:35 +02001031 }
1032
Ian Romanickc7b10462010-05-19 13:20:12 +02001033 virtual void accept(ir_visitor *v)
1034 {
1035 v->visit(this);
1036 }
1037
Ian Romanickf3a002b2010-05-19 12:02:19 +02001038 virtual ir_visitor_status accept(ir_hierarchical_visitor *);
Ian Romanick70fe8b62010-05-19 11:37:35 +02001039
Ian Romanick36ea2862010-05-19 13:52:29 +02001040 ir_rvalue *array;
1041 ir_rvalue *array_index;
1042
Ian Romanick70fe8b62010-05-19 11:37:35 +02001043private:
1044 void set_array(ir_rvalue *value);
1045};
1046
1047
1048class ir_dereference_record : public ir_dereference {
1049public:
1050 ir_dereference_record(ir_rvalue *value, const char *field);
1051
1052 ir_dereference_record(ir_variable *var, const char *field);
1053
Eric Anholt4b6fd392010-06-23 11:37:12 -07001054 virtual ir_instruction *clone(struct hash_table *) const;
1055
Ian Romanick70fe8b62010-05-19 11:37:35 +02001056 /**
1057 * Get the variable that is ultimately referenced by an r-value
1058 */
1059 virtual ir_variable *variable_referenced()
1060 {
Ian Romanick36ea2862010-05-19 13:52:29 +02001061 return this->record->variable_referenced();
Ian Romanick70fe8b62010-05-19 11:37:35 +02001062 }
Ian Romanickf3a002b2010-05-19 12:02:19 +02001063
Ian Romanickc7b10462010-05-19 13:20:12 +02001064 virtual void accept(ir_visitor *v)
1065 {
1066 v->visit(this);
1067 }
1068
Ian Romanickf3a002b2010-05-19 12:02:19 +02001069 virtual ir_visitor_status accept(ir_hierarchical_visitor *);
Ian Romanick36ea2862010-05-19 13:52:29 +02001070
1071 ir_rvalue *record;
1072 const char *field;
Ian Romanicka87ac252010-02-22 13:19:34 -08001073};
1074
1075
Ian Romanickbe1d2bf2010-06-11 14:01:44 -07001076/**
1077 * Data stored in an ir_constant
1078 */
1079union ir_constant_data {
1080 unsigned u[16];
1081 int i[16];
1082 float f[16];
1083 bool b[16];
1084};
1085
1086
Kenneth Graunkefb9fb5f2010-03-26 00:25:36 -07001087class ir_constant : public ir_rvalue {
Ian Romanicka87ac252010-02-22 13:19:34 -08001088public:
Ian Romanick824b6592010-06-11 16:57:47 -07001089 ir_constant(const struct glsl_type *type, const ir_constant_data *data);
Eric Anholt3c36b2d2010-03-26 12:07:44 -07001090 ir_constant(bool b);
1091 ir_constant(unsigned int u);
1092 ir_constant(int i);
1093 ir_constant(float f);
Ian Romanicka87ac252010-02-22 13:19:34 -08001094
Ian Romanick989cfc42010-06-04 16:13:35 -07001095 /**
Ian Romanick756a3fa2010-06-04 16:34:38 -07001096 * 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 Romanick989cfc42010-06-04 16:13:35 -07001101 * 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 Anholt4b6fd392010-06-23 11:37:12 -07001112 virtual ir_instruction *clone(struct hash_table *) const;
1113
Eric Anholt5c89f0e2010-05-04 13:04:40 -07001114 virtual ir_constant *as_constant()
1115 {
1116 return this;
1117 }
1118
Ian Romanick78b51b02010-03-09 16:23:37 -08001119 virtual void accept(ir_visitor *v)
1120 {
1121 v->visit(this);
1122 }
1123
Ian Romanick8895bae2010-05-14 12:39:23 -07001124 virtual ir_visitor_status accept(ir_hierarchical_visitor *);
1125
Ian Romanicka87ac252010-02-22 13:19:34 -08001126 /**
Ian Romanick31881902010-06-04 16:30:07 -07001127 * 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 Romanickb94c29a2010-06-09 17:28:54 -07001140 ir_constant *get_record_field(const char *name);
1141
Ian Romanick31881902010-06-04 16:30:07 -07001142 /**
Ian Romanick1e8b7a72010-06-17 19:50:36 -07001143 * Determine whether a constant has the same value as another constant
1144 */
1145 bool has_value(const ir_constant *) const;
1146
1147 /**
Ian Romanicka87ac252010-02-22 13:19:34 -08001148 * 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 Romanickbe1d2bf2010-06-11 14:01:44 -07001154 union ir_constant_data value;
Ian Romanick7f1ab832010-06-09 17:11:50 -07001155
1156 exec_list components;
Ian Romanick710919f2010-06-09 17:18:04 -07001157
1158private:
1159 /**
1160 * Parameterless constructor only used by the clone method
1161 */
1162 ir_constant(void);
Ian Romanicka87ac252010-02-22 13:19:34 -08001163};
1164
Eric Anholt70b74922010-04-06 11:52:09 -07001165void
1166visit_exec_list(exec_list *list, ir_visitor *visitor);
Ian Romanickadfb0cd2010-03-10 10:43:16 -08001167
Eric Anholt53cdb7e2010-06-22 12:07:21 -07001168void validate_ir_tree(exec_list *instructions);
1169
Ian Romanickadfb0cd2010-03-10 10:43:16 -08001170extern void
1171_mesa_glsl_initialize_variables(exec_list *instructions,
1172 struct _mesa_glsl_parse_state *state);
Ian Romanicke309a602010-03-15 15:20:15 -07001173
Eric Anholtc22c4002010-03-26 18:20:30 -07001174extern void
1175_mesa_glsl_initialize_functions(exec_list *instructions,
1176 struct _mesa_glsl_parse_state *state);
1177
Ian Romanicke309a602010-03-15 15:20:15 -07001178#endif /* IR_H */