Ian Romanick | 1cf43a4 | 2010-03-30 16:56:50 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2010 Intel Corporation |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 5 | * copy of this software and associated documentation files (the "Software"), |
| 6 | * to deal in the Software without restriction, including without limitation |
| 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 | * and/or sell copies of the Software, and to permit persons to whom the |
| 9 | * Software is furnished to do so, subject to the following conditions: |
| 10 | * |
| 11 | * The above copyright notice and this permission notice (including the next |
| 12 | * paragraph) shall be included in all copies or substantial portions of the |
| 13 | * Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 21 | * DEALINGS IN THE SOFTWARE. |
| 22 | */ |
| 23 | |
| 24 | /** |
| 25 | * \file ir_constant_expression.cpp |
| 26 | * Evaluate and process constant valued expressions |
| 27 | * |
| 28 | * In GLSL, constant valued expressions are used in several places. These |
| 29 | * must be processed and evaluated very early in the compilation process. |
| 30 | * |
| 31 | * * Sizes of arrays |
| 32 | * * Initializers for uniforms |
| 33 | * * Initializers for \c const variables |
| 34 | */ |
| 35 | |
Eric Anholt | 43ad37a | 2010-05-12 14:42:21 -0700 | [diff] [blame] | 36 | #include <math.h> |
Ian Romanick | 1cf43a4 | 2010-03-30 16:56:50 -0700 | [diff] [blame] | 37 | #include "ir.h" |
| 38 | #include "ir_visitor.h" |
Eric Anholt | a576f9d | 2010-03-31 16:25:12 -1000 | [diff] [blame] | 39 | #include "glsl_types.h" |
Ian Romanick | 1cf43a4 | 2010-03-30 16:56:50 -0700 | [diff] [blame] | 40 | |
| 41 | /** |
| 42 | * Visitor class for evaluating constant expressions |
| 43 | */ |
| 44 | class ir_constant_visitor : public ir_visitor { |
| 45 | public: |
| 46 | ir_constant_visitor() |
| 47 | : value(NULL) |
| 48 | { |
| 49 | /* empty */ |
| 50 | } |
| 51 | |
| 52 | virtual ~ir_constant_visitor() |
| 53 | { |
| 54 | /* empty */ |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * \name Visit methods |
| 59 | * |
| 60 | * As typical for the visitor pattern, there must be one \c visit method for |
| 61 | * each concrete subclass of \c ir_instruction. Virtual base classes within |
| 62 | * the hierarchy should not have \c visit methods. |
| 63 | */ |
| 64 | /*@{*/ |
| 65 | virtual void visit(ir_variable *); |
Ian Romanick | 1cf43a4 | 2010-03-30 16:56:50 -0700 | [diff] [blame] | 66 | virtual void visit(ir_function_signature *); |
| 67 | virtual void visit(ir_function *); |
| 68 | virtual void visit(ir_expression *); |
Kenneth Graunke | 26d74cd | 2010-05-26 17:42:03 -0700 | [diff] [blame] | 69 | virtual void visit(ir_texture *); |
Ian Romanick | 1cf43a4 | 2010-03-30 16:56:50 -0700 | [diff] [blame] | 70 | virtual void visit(ir_swizzle *); |
Ian Romanick | c7b1046 | 2010-05-19 13:20:12 +0200 | [diff] [blame] | 71 | virtual void visit(ir_dereference_variable *); |
| 72 | virtual void visit(ir_dereference_array *); |
| 73 | virtual void visit(ir_dereference_record *); |
Ian Romanick | 1cf43a4 | 2010-03-30 16:56:50 -0700 | [diff] [blame] | 74 | virtual void visit(ir_assignment *); |
| 75 | virtual void visit(ir_constant *); |
| 76 | virtual void visit(ir_call *); |
| 77 | virtual void visit(ir_return *); |
Kenneth Graunke | 16efab1 | 2010-06-30 10:47:34 -0700 | [diff] [blame^] | 78 | virtual void visit(ir_discard *); |
Ian Romanick | 1cf43a4 | 2010-03-30 16:56:50 -0700 | [diff] [blame] | 79 | virtual void visit(ir_if *); |
Ian Romanick | fad607a | 2010-04-05 16:16:07 -0700 | [diff] [blame] | 80 | virtual void visit(ir_loop *); |
Ian Romanick | f8e31e0 | 2010-04-05 16:28:15 -0700 | [diff] [blame] | 81 | virtual void visit(ir_loop_jump *); |
Ian Romanick | 1cf43a4 | 2010-03-30 16:56:50 -0700 | [diff] [blame] | 82 | /*@}*/ |
| 83 | |
| 84 | /** |
| 85 | * Value of the constant expression. |
| 86 | * |
| 87 | * \note |
| 88 | * This field will be \c NULL if the expression is not constant valued. |
| 89 | */ |
| 90 | /* FINIHSME: This cannot hold values for constant arrays or structures. */ |
| 91 | ir_constant *value; |
| 92 | }; |
| 93 | |
| 94 | |
| 95 | ir_constant * |
| 96 | ir_instruction::constant_expression_value() |
| 97 | { |
| 98 | ir_constant_visitor visitor; |
| 99 | |
| 100 | this->accept(& visitor); |
| 101 | return visitor.value; |
| 102 | } |
| 103 | |
| 104 | |
| 105 | void |
| 106 | ir_constant_visitor::visit(ir_variable *ir) |
| 107 | { |
| 108 | (void) ir; |
| 109 | value = NULL; |
| 110 | } |
| 111 | |
| 112 | |
| 113 | void |
Ian Romanick | 1cf43a4 | 2010-03-30 16:56:50 -0700 | [diff] [blame] | 114 | ir_constant_visitor::visit(ir_function_signature *ir) |
| 115 | { |
| 116 | (void) ir; |
| 117 | value = NULL; |
| 118 | } |
| 119 | |
| 120 | |
| 121 | void |
| 122 | ir_constant_visitor::visit(ir_function *ir) |
| 123 | { |
| 124 | (void) ir; |
| 125 | value = NULL; |
| 126 | } |
| 127 | |
Ian Romanick | 1cf43a4 | 2010-03-30 16:56:50 -0700 | [diff] [blame] | 128 | void |
| 129 | ir_constant_visitor::visit(ir_expression *ir) |
| 130 | { |
Ian Romanick | 1cf43a4 | 2010-03-30 16:56:50 -0700 | [diff] [blame] | 131 | value = NULL; |
Eric Anholt | a576f9d | 2010-03-31 16:25:12 -1000 | [diff] [blame] | 132 | ir_constant *op[2]; |
Eric Anholt | d98da97 | 2010-04-01 18:25:11 -1000 | [diff] [blame] | 133 | unsigned int operand, c; |
Ian Romanick | 4daaab6 | 2010-06-11 16:08:47 -0700 | [diff] [blame] | 134 | ir_constant_data data; |
Eric Anholt | 160d092 | 2010-04-01 18:07:08 -1000 | [diff] [blame] | 135 | |
Eric Anholt | d98da97 | 2010-04-01 18:25:11 -1000 | [diff] [blame] | 136 | for (operand = 0; operand < ir->get_num_operands(); operand++) { |
| 137 | op[operand] = ir->operands[operand]->constant_expression_value(); |
| 138 | if (!op[operand]) |
Eric Anholt | 160d092 | 2010-04-01 18:07:08 -1000 | [diff] [blame] | 139 | return; |
| 140 | } |
Eric Anholt | a576f9d | 2010-03-31 16:25:12 -1000 | [diff] [blame] | 141 | |
| 142 | switch (ir->operation) { |
Eric Anholt | 528bb85 | 2010-03-31 21:09:02 -1000 | [diff] [blame] | 143 | case ir_unop_logic_not: |
Ian Romanick | f8b88be | 2010-06-11 16:23:52 -0700 | [diff] [blame] | 144 | assert(op[0]->type->base_type == GLSL_TYPE_BOOL); |
Eric Anholt | d98da97 | 2010-04-01 18:25:11 -1000 | [diff] [blame] | 145 | for (c = 0; c < ir->operands[0]->type->components(); c++) |
Ian Romanick | 4daaab6 | 2010-06-11 16:08:47 -0700 | [diff] [blame] | 146 | data.b[c] = !op[0]->value.b[c]; |
Eric Anholt | 528bb85 | 2010-03-31 21:09:02 -1000 | [diff] [blame] | 147 | break; |
Eric Anholt | af18641 | 2010-04-06 10:53:57 -0700 | [diff] [blame] | 148 | |
| 149 | case ir_unop_f2i: |
| 150 | assert(op[0]->type->base_type == GLSL_TYPE_FLOAT); |
Eric Anholt | af18641 | 2010-04-06 10:53:57 -0700 | [diff] [blame] | 151 | for (c = 0; c < ir->operands[0]->type->components(); c++) { |
Ian Romanick | 4daaab6 | 2010-06-11 16:08:47 -0700 | [diff] [blame] | 152 | data.i[c] = op[0]->value.f[c]; |
Eric Anholt | af18641 | 2010-04-06 10:53:57 -0700 | [diff] [blame] | 153 | } |
| 154 | break; |
| 155 | case ir_unop_i2f: |
| 156 | assert(op[0]->type->base_type == GLSL_TYPE_UINT || |
| 157 | op[0]->type->base_type == GLSL_TYPE_INT); |
Eric Anholt | af18641 | 2010-04-06 10:53:57 -0700 | [diff] [blame] | 158 | for (c = 0; c < ir->operands[0]->type->components(); c++) { |
| 159 | if (op[0]->type->base_type == GLSL_TYPE_INT) |
Ian Romanick | 4daaab6 | 2010-06-11 16:08:47 -0700 | [diff] [blame] | 160 | data.f[c] = op[0]->value.i[c]; |
Eric Anholt | af18641 | 2010-04-06 10:53:57 -0700 | [diff] [blame] | 161 | else |
Ian Romanick | 4daaab6 | 2010-06-11 16:08:47 -0700 | [diff] [blame] | 162 | data.f[c] = op[0]->value.u[c]; |
Eric Anholt | af18641 | 2010-04-06 10:53:57 -0700 | [diff] [blame] | 163 | } |
| 164 | break; |
Ian Romanick | 7dc2b71 | 2010-06-07 15:10:14 -0700 | [diff] [blame] | 165 | case ir_unop_b2f: |
| 166 | assert(op[0]->type->base_type == GLSL_TYPE_BOOL); |
Ian Romanick | 7dc2b71 | 2010-06-07 15:10:14 -0700 | [diff] [blame] | 167 | for (c = 0; c < ir->operands[0]->type->components(); c++) { |
Ian Romanick | 4daaab6 | 2010-06-11 16:08:47 -0700 | [diff] [blame] | 168 | data.f[c] = op[0]->value.b[c] ? 1.0 : 0.0; |
Ian Romanick | 7dc2b71 | 2010-06-07 15:10:14 -0700 | [diff] [blame] | 169 | } |
| 170 | break; |
| 171 | case ir_unop_f2b: |
| 172 | assert(op[0]->type->base_type == GLSL_TYPE_FLOAT); |
Ian Romanick | 7dc2b71 | 2010-06-07 15:10:14 -0700 | [diff] [blame] | 173 | for (c = 0; c < ir->operands[0]->type->components(); c++) { |
Ian Romanick | 4daaab6 | 2010-06-11 16:08:47 -0700 | [diff] [blame] | 174 | data.b[c] = bool(op[0]->value.f[c]); |
Ian Romanick | 7dc2b71 | 2010-06-07 15:10:14 -0700 | [diff] [blame] | 175 | } |
| 176 | break; |
Ian Romanick | 39d6dd3 | 2010-06-11 13:46:30 -0700 | [diff] [blame] | 177 | case ir_unop_b2i: |
| 178 | assert(op[0]->type->base_type == GLSL_TYPE_BOOL); |
Ian Romanick | 39d6dd3 | 2010-06-11 13:46:30 -0700 | [diff] [blame] | 179 | for (c = 0; c < ir->operands[0]->type->components(); c++) { |
Ian Romanick | 4daaab6 | 2010-06-11 16:08:47 -0700 | [diff] [blame] | 180 | data.u[c] = op[0]->value.b[c] ? 1 : 0; |
Ian Romanick | 39d6dd3 | 2010-06-11 13:46:30 -0700 | [diff] [blame] | 181 | } |
| 182 | break; |
| 183 | case ir_unop_i2b: |
| 184 | assert(op[0]->type->is_integer()); |
Ian Romanick | 39d6dd3 | 2010-06-11 13:46:30 -0700 | [diff] [blame] | 185 | for (c = 0; c < ir->operands[0]->type->components(); c++) { |
Ian Romanick | 4daaab6 | 2010-06-11 16:08:47 -0700 | [diff] [blame] | 186 | data.b[c] = bool(op[0]->value.u[c]); |
Ian Romanick | 39d6dd3 | 2010-06-11 13:46:30 -0700 | [diff] [blame] | 187 | } |
| 188 | break; |
Eric Anholt | af18641 | 2010-04-06 10:53:57 -0700 | [diff] [blame] | 189 | |
Eric Anholt | 43ad37a | 2010-05-12 14:42:21 -0700 | [diff] [blame] | 190 | case ir_unop_neg: |
Eric Anholt | 43ad37a | 2010-05-12 14:42:21 -0700 | [diff] [blame] | 191 | for (c = 0; c < ir->operands[0]->type->components(); c++) { |
Ian Romanick | f8b88be | 2010-06-11 16:23:52 -0700 | [diff] [blame] | 192 | switch (ir->type->base_type) { |
Eric Anholt | 43ad37a | 2010-05-12 14:42:21 -0700 | [diff] [blame] | 193 | case GLSL_TYPE_UINT: |
Ian Romanick | 4daaab6 | 2010-06-11 16:08:47 -0700 | [diff] [blame] | 194 | data.u[c] = -op[0]->value.u[c]; |
Eric Anholt | 43ad37a | 2010-05-12 14:42:21 -0700 | [diff] [blame] | 195 | break; |
| 196 | case GLSL_TYPE_INT: |
Ian Romanick | 4daaab6 | 2010-06-11 16:08:47 -0700 | [diff] [blame] | 197 | data.i[c] = -op[0]->value.i[c]; |
Eric Anholt | 43ad37a | 2010-05-12 14:42:21 -0700 | [diff] [blame] | 198 | break; |
| 199 | case GLSL_TYPE_FLOAT: |
Ian Romanick | 4daaab6 | 2010-06-11 16:08:47 -0700 | [diff] [blame] | 200 | data.f[c] = -op[0]->value.f[c]; |
Eric Anholt | 43ad37a | 2010-05-12 14:42:21 -0700 | [diff] [blame] | 201 | break; |
| 202 | default: |
| 203 | assert(0); |
| 204 | } |
| 205 | } |
| 206 | break; |
| 207 | |
| 208 | case ir_unop_abs: |
| 209 | assert(op[0]->type->base_type == GLSL_TYPE_FLOAT); |
Eric Anholt | 43ad37a | 2010-05-12 14:42:21 -0700 | [diff] [blame] | 210 | for (c = 0; c < ir->operands[0]->type->components(); c++) { |
Ian Romanick | f8b88be | 2010-06-11 16:23:52 -0700 | [diff] [blame] | 211 | switch (ir->type->base_type) { |
Eric Anholt | 43ad37a | 2010-05-12 14:42:21 -0700 | [diff] [blame] | 212 | case GLSL_TYPE_UINT: |
Ian Romanick | 4daaab6 | 2010-06-11 16:08:47 -0700 | [diff] [blame] | 213 | data.u[c] = op[0]->value.u[c]; |
Eric Anholt | 43ad37a | 2010-05-12 14:42:21 -0700 | [diff] [blame] | 214 | break; |
| 215 | case GLSL_TYPE_INT: |
Ian Romanick | 4daaab6 | 2010-06-11 16:08:47 -0700 | [diff] [blame] | 216 | data.i[c] = op[0]->value.i[c]; |
| 217 | if (data.i[c] < 0) |
| 218 | data.i[c] = -data.i[c]; |
Eric Anholt | 43ad37a | 2010-05-12 14:42:21 -0700 | [diff] [blame] | 219 | break; |
| 220 | case GLSL_TYPE_FLOAT: |
Ian Romanick | 4daaab6 | 2010-06-11 16:08:47 -0700 | [diff] [blame] | 221 | data.f[c] = fabs(op[0]->value.f[c]); |
Eric Anholt | 43ad37a | 2010-05-12 14:42:21 -0700 | [diff] [blame] | 222 | break; |
| 223 | default: |
| 224 | assert(0); |
| 225 | } |
| 226 | } |
| 227 | break; |
| 228 | |
| 229 | case ir_unop_rcp: |
| 230 | assert(op[0]->type->base_type == GLSL_TYPE_FLOAT); |
Eric Anholt | 43ad37a | 2010-05-12 14:42:21 -0700 | [diff] [blame] | 231 | for (c = 0; c < ir->operands[0]->type->components(); c++) { |
Ian Romanick | f8b88be | 2010-06-11 16:23:52 -0700 | [diff] [blame] | 232 | switch (ir->type->base_type) { |
Eric Anholt | 43ad37a | 2010-05-12 14:42:21 -0700 | [diff] [blame] | 233 | case GLSL_TYPE_UINT: |
| 234 | if (op[0]->value.u[c] != 0.0) |
Ian Romanick | 4daaab6 | 2010-06-11 16:08:47 -0700 | [diff] [blame] | 235 | data.u[c] = 1 / op[0]->value.u[c]; |
Eric Anholt | 43ad37a | 2010-05-12 14:42:21 -0700 | [diff] [blame] | 236 | break; |
| 237 | case GLSL_TYPE_INT: |
| 238 | if (op[0]->value.i[c] != 0.0) |
Ian Romanick | 4daaab6 | 2010-06-11 16:08:47 -0700 | [diff] [blame] | 239 | data.i[c] = 1 / op[0]->value.i[c]; |
Eric Anholt | 43ad37a | 2010-05-12 14:42:21 -0700 | [diff] [blame] | 240 | break; |
| 241 | case GLSL_TYPE_FLOAT: |
| 242 | if (op[0]->value.f[c] != 0.0) |
Ian Romanick | 4daaab6 | 2010-06-11 16:08:47 -0700 | [diff] [blame] | 243 | data.f[c] = 1.0 / op[0]->value.f[c]; |
Eric Anholt | 43ad37a | 2010-05-12 14:42:21 -0700 | [diff] [blame] | 244 | break; |
| 245 | default: |
| 246 | assert(0); |
| 247 | } |
| 248 | } |
| 249 | break; |
| 250 | |
| 251 | case ir_unop_rsq: |
| 252 | assert(op[0]->type->base_type == GLSL_TYPE_FLOAT); |
Eric Anholt | 43ad37a | 2010-05-12 14:42:21 -0700 | [diff] [blame] | 253 | for (c = 0; c < ir->operands[0]->type->components(); c++) { |
Ian Romanick | 4daaab6 | 2010-06-11 16:08:47 -0700 | [diff] [blame] | 254 | data.f[c] = 1.0 / sqrtf(op[0]->value.f[c]); |
Eric Anholt | 43ad37a | 2010-05-12 14:42:21 -0700 | [diff] [blame] | 255 | } |
| 256 | break; |
| 257 | |
| 258 | case ir_unop_sqrt: |
| 259 | assert(op[0]->type->base_type == GLSL_TYPE_FLOAT); |
Eric Anholt | 43ad37a | 2010-05-12 14:42:21 -0700 | [diff] [blame] | 260 | for (c = 0; c < ir->operands[0]->type->components(); c++) { |
Ian Romanick | 4daaab6 | 2010-06-11 16:08:47 -0700 | [diff] [blame] | 261 | data.f[c] = sqrtf(op[0]->value.f[c]); |
Eric Anholt | 43ad37a | 2010-05-12 14:42:21 -0700 | [diff] [blame] | 262 | } |
| 263 | break; |
| 264 | |
| 265 | case ir_unop_exp: |
| 266 | assert(op[0]->type->base_type == GLSL_TYPE_FLOAT); |
Eric Anholt | 43ad37a | 2010-05-12 14:42:21 -0700 | [diff] [blame] | 267 | for (c = 0; c < ir->operands[0]->type->components(); c++) { |
Ian Romanick | 4daaab6 | 2010-06-11 16:08:47 -0700 | [diff] [blame] | 268 | data.f[c] = expf(op[0]->value.f[c]); |
Eric Anholt | 43ad37a | 2010-05-12 14:42:21 -0700 | [diff] [blame] | 269 | } |
| 270 | break; |
| 271 | |
| 272 | case ir_unop_log: |
| 273 | assert(op[0]->type->base_type == GLSL_TYPE_FLOAT); |
Eric Anholt | 43ad37a | 2010-05-12 14:42:21 -0700 | [diff] [blame] | 274 | for (c = 0; c < ir->operands[0]->type->components(); c++) { |
Ian Romanick | 4daaab6 | 2010-06-11 16:08:47 -0700 | [diff] [blame] | 275 | data.f[c] = logf(op[0]->value.f[c]); |
Eric Anholt | 43ad37a | 2010-05-12 14:42:21 -0700 | [diff] [blame] | 276 | } |
| 277 | break; |
| 278 | |
Kenneth Graunke | d6a32d4 | 2010-06-09 15:22:35 -0700 | [diff] [blame] | 279 | case ir_unop_dFdx: |
| 280 | case ir_unop_dFdy: |
| 281 | assert(op[0]->type->base_type == GLSL_TYPE_FLOAT); |
Kenneth Graunke | d6a32d4 | 2010-06-09 15:22:35 -0700 | [diff] [blame] | 282 | for (c = 0; c < ir->operands[0]->type->components(); c++) { |
Ian Romanick | 4daaab6 | 2010-06-11 16:08:47 -0700 | [diff] [blame] | 283 | data.f[c] = 0.0; |
Kenneth Graunke | d6a32d4 | 2010-06-09 15:22:35 -0700 | [diff] [blame] | 284 | } |
| 285 | break; |
| 286 | |
Eric Anholt | d251b92 | 2010-04-01 18:35:42 -1000 | [diff] [blame] | 287 | case ir_binop_add: |
| 288 | if (ir->operands[0]->type == ir->operands[1]->type) { |
Eric Anholt | d251b92 | 2010-04-01 18:35:42 -1000 | [diff] [blame] | 289 | for (c = 0; c < ir->operands[0]->type->components(); c++) { |
| 290 | switch (ir->operands[0]->type->base_type) { |
| 291 | case GLSL_TYPE_UINT: |
Ian Romanick | 4daaab6 | 2010-06-11 16:08:47 -0700 | [diff] [blame] | 292 | data.u[c] = op[0]->value.u[c] + op[1]->value.u[c]; |
Eric Anholt | d251b92 | 2010-04-01 18:35:42 -1000 | [diff] [blame] | 293 | break; |
| 294 | case GLSL_TYPE_INT: |
Ian Romanick | 4daaab6 | 2010-06-11 16:08:47 -0700 | [diff] [blame] | 295 | data.i[c] = op[0]->value.i[c] + op[1]->value.i[c]; |
Eric Anholt | d251b92 | 2010-04-01 18:35:42 -1000 | [diff] [blame] | 296 | break; |
| 297 | case GLSL_TYPE_FLOAT: |
Ian Romanick | 4daaab6 | 2010-06-11 16:08:47 -0700 | [diff] [blame] | 298 | data.f[c] = op[0]->value.f[c] + op[1]->value.f[c]; |
Eric Anholt | d251b92 | 2010-04-01 18:35:42 -1000 | [diff] [blame] | 299 | break; |
| 300 | default: |
| 301 | assert(0); |
| 302 | } |
| 303 | } |
Ian Romanick | f8b88be | 2010-06-11 16:23:52 -0700 | [diff] [blame] | 304 | } else |
| 305 | /* FINISHME: Support operations with non-equal types. */ |
| 306 | return; |
| 307 | |
Eric Anholt | d251b92 | 2010-04-01 18:35:42 -1000 | [diff] [blame] | 308 | break; |
| 309 | case ir_binop_sub: |
| 310 | if (ir->operands[0]->type == ir->operands[1]->type) { |
Eric Anholt | d251b92 | 2010-04-01 18:35:42 -1000 | [diff] [blame] | 311 | for (c = 0; c < ir->operands[0]->type->components(); c++) { |
| 312 | switch (ir->operands[0]->type->base_type) { |
| 313 | case GLSL_TYPE_UINT: |
Ian Romanick | 4daaab6 | 2010-06-11 16:08:47 -0700 | [diff] [blame] | 314 | data.u[c] = op[0]->value.u[c] - op[1]->value.u[c]; |
Eric Anholt | d251b92 | 2010-04-01 18:35:42 -1000 | [diff] [blame] | 315 | break; |
| 316 | case GLSL_TYPE_INT: |
Ian Romanick | 4daaab6 | 2010-06-11 16:08:47 -0700 | [diff] [blame] | 317 | data.i[c] = op[0]->value.i[c] - op[1]->value.i[c]; |
Eric Anholt | d251b92 | 2010-04-01 18:35:42 -1000 | [diff] [blame] | 318 | break; |
| 319 | case GLSL_TYPE_FLOAT: |
Ian Romanick | 4daaab6 | 2010-06-11 16:08:47 -0700 | [diff] [blame] | 320 | data.f[c] = op[0]->value.f[c] - op[1]->value.f[c]; |
Eric Anholt | d251b92 | 2010-04-01 18:35:42 -1000 | [diff] [blame] | 321 | break; |
| 322 | default: |
| 323 | assert(0); |
| 324 | } |
| 325 | } |
Ian Romanick | f8b88be | 2010-06-11 16:23:52 -0700 | [diff] [blame] | 326 | } else |
| 327 | /* FINISHME: Support operations with non-equal types. */ |
| 328 | return; |
| 329 | |
Eric Anholt | d251b92 | 2010-04-01 18:35:42 -1000 | [diff] [blame] | 330 | break; |
Eric Anholt | a576f9d | 2010-03-31 16:25:12 -1000 | [diff] [blame] | 331 | case ir_binop_mul: |
Eric Anholt | d98da97 | 2010-04-01 18:25:11 -1000 | [diff] [blame] | 332 | if (ir->operands[0]->type == ir->operands[1]->type && |
| 333 | !ir->operands[0]->type->is_matrix()) { |
Eric Anholt | d98da97 | 2010-04-01 18:25:11 -1000 | [diff] [blame] | 334 | for (c = 0; c < ir->operands[0]->type->components(); c++) { |
| 335 | switch (ir->operands[0]->type->base_type) { |
| 336 | case GLSL_TYPE_UINT: |
Ian Romanick | 4daaab6 | 2010-06-11 16:08:47 -0700 | [diff] [blame] | 337 | data.u[c] = op[0]->value.u[c] * op[1]->value.u[c]; |
Eric Anholt | d98da97 | 2010-04-01 18:25:11 -1000 | [diff] [blame] | 338 | break; |
| 339 | case GLSL_TYPE_INT: |
Ian Romanick | 4daaab6 | 2010-06-11 16:08:47 -0700 | [diff] [blame] | 340 | data.i[c] = op[0]->value.i[c] * op[1]->value.i[c]; |
Eric Anholt | d98da97 | 2010-04-01 18:25:11 -1000 | [diff] [blame] | 341 | break; |
| 342 | case GLSL_TYPE_FLOAT: |
Ian Romanick | 4daaab6 | 2010-06-11 16:08:47 -0700 | [diff] [blame] | 343 | data.f[c] = op[0]->value.f[c] * op[1]->value.f[c]; |
Eric Anholt | d98da97 | 2010-04-01 18:25:11 -1000 | [diff] [blame] | 344 | break; |
| 345 | default: |
| 346 | assert(0); |
| 347 | } |
Eric Anholt | a576f9d | 2010-03-31 16:25:12 -1000 | [diff] [blame] | 348 | } |
Ian Romanick | f8b88be | 2010-06-11 16:23:52 -0700 | [diff] [blame] | 349 | } else |
| 350 | /* FINISHME: Support operations with non-equal types. */ |
| 351 | return; |
| 352 | |
Eric Anholt | a576f9d | 2010-03-31 16:25:12 -1000 | [diff] [blame] | 353 | break; |
Eric Anholt | d251b92 | 2010-04-01 18:35:42 -1000 | [diff] [blame] | 354 | case ir_binop_div: |
| 355 | if (ir->operands[0]->type == ir->operands[1]->type) { |
Eric Anholt | d251b92 | 2010-04-01 18:35:42 -1000 | [diff] [blame] | 356 | for (c = 0; c < ir->operands[0]->type->components(); c++) { |
| 357 | switch (ir->operands[0]->type->base_type) { |
| 358 | case GLSL_TYPE_UINT: |
Ian Romanick | 4daaab6 | 2010-06-11 16:08:47 -0700 | [diff] [blame] | 359 | data.u[c] = op[0]->value.u[c] / op[1]->value.u[c]; |
Eric Anholt | d251b92 | 2010-04-01 18:35:42 -1000 | [diff] [blame] | 360 | break; |
| 361 | case GLSL_TYPE_INT: |
Ian Romanick | 4daaab6 | 2010-06-11 16:08:47 -0700 | [diff] [blame] | 362 | data.i[c] = op[0]->value.i[c] / op[1]->value.i[c]; |
Eric Anholt | d251b92 | 2010-04-01 18:35:42 -1000 | [diff] [blame] | 363 | break; |
| 364 | case GLSL_TYPE_FLOAT: |
Ian Romanick | 4daaab6 | 2010-06-11 16:08:47 -0700 | [diff] [blame] | 365 | data.f[c] = op[0]->value.f[c] / op[1]->value.f[c]; |
Eric Anholt | d251b92 | 2010-04-01 18:35:42 -1000 | [diff] [blame] | 366 | break; |
| 367 | default: |
| 368 | assert(0); |
| 369 | } |
| 370 | } |
Ian Romanick | f8b88be | 2010-06-11 16:23:52 -0700 | [diff] [blame] | 371 | } else |
| 372 | /* FINISHME: Support operations with non-equal types. */ |
| 373 | return; |
| 374 | |
Eric Anholt | d251b92 | 2010-04-01 18:35:42 -1000 | [diff] [blame] | 375 | break; |
Eric Anholt | a576f9d | 2010-03-31 16:25:12 -1000 | [diff] [blame] | 376 | case ir_binop_logic_and: |
Ian Romanick | f8b88be | 2010-06-11 16:23:52 -0700 | [diff] [blame] | 377 | assert(op[0]->type->base_type == GLSL_TYPE_BOOL); |
Eric Anholt | d98da97 | 2010-04-01 18:25:11 -1000 | [diff] [blame] | 378 | for (c = 0; c < ir->operands[0]->type->components(); c++) |
Ian Romanick | 4daaab6 | 2010-06-11 16:08:47 -0700 | [diff] [blame] | 379 | data.b[c] = op[0]->value.b[c] && op[1]->value.b[c]; |
Eric Anholt | a576f9d | 2010-03-31 16:25:12 -1000 | [diff] [blame] | 380 | break; |
Eric Anholt | d251b92 | 2010-04-01 18:35:42 -1000 | [diff] [blame] | 381 | case ir_binop_logic_xor: |
Ian Romanick | f8b88be | 2010-06-11 16:23:52 -0700 | [diff] [blame] | 382 | assert(op[0]->type->base_type == GLSL_TYPE_BOOL); |
Eric Anholt | d251b92 | 2010-04-01 18:35:42 -1000 | [diff] [blame] | 383 | for (c = 0; c < ir->operands[0]->type->components(); c++) |
Ian Romanick | 4daaab6 | 2010-06-11 16:08:47 -0700 | [diff] [blame] | 384 | data.b[c] = op[0]->value.b[c] ^ op[1]->value.b[c]; |
Eric Anholt | d251b92 | 2010-04-01 18:35:42 -1000 | [diff] [blame] | 385 | break; |
Eric Anholt | a576f9d | 2010-03-31 16:25:12 -1000 | [diff] [blame] | 386 | case ir_binop_logic_or: |
Ian Romanick | f8b88be | 2010-06-11 16:23:52 -0700 | [diff] [blame] | 387 | assert(op[0]->type->base_type == GLSL_TYPE_BOOL); |
Eric Anholt | d98da97 | 2010-04-01 18:25:11 -1000 | [diff] [blame] | 388 | for (c = 0; c < ir->operands[0]->type->components(); c++) |
Ian Romanick | 4daaab6 | 2010-06-11 16:08:47 -0700 | [diff] [blame] | 389 | data.b[c] = op[0]->value.b[c] || op[1]->value.b[c]; |
Eric Anholt | a576f9d | 2010-03-31 16:25:12 -1000 | [diff] [blame] | 390 | break; |
Eric Anholt | 85171c2 | 2010-04-06 09:55:45 -0700 | [diff] [blame] | 391 | |
| 392 | case ir_binop_less: |
Eric Anholt | 85171c2 | 2010-04-06 09:55:45 -0700 | [diff] [blame] | 393 | switch (ir->operands[0]->type->base_type) { |
| 394 | case GLSL_TYPE_UINT: |
Ian Romanick | 4daaab6 | 2010-06-11 16:08:47 -0700 | [diff] [blame] | 395 | data.b[0] = op[0]->value.u[0] < op[1]->value.u[0]; |
Eric Anholt | 85171c2 | 2010-04-06 09:55:45 -0700 | [diff] [blame] | 396 | break; |
| 397 | case GLSL_TYPE_INT: |
Ian Romanick | 4daaab6 | 2010-06-11 16:08:47 -0700 | [diff] [blame] | 398 | data.b[0] = op[0]->value.i[0] < op[1]->value.i[0]; |
Eric Anholt | 85171c2 | 2010-04-06 09:55:45 -0700 | [diff] [blame] | 399 | break; |
| 400 | case GLSL_TYPE_FLOAT: |
Ian Romanick | 4daaab6 | 2010-06-11 16:08:47 -0700 | [diff] [blame] | 401 | data.b[0] = op[0]->value.f[0] < op[1]->value.f[0]; |
Eric Anholt | 85171c2 | 2010-04-06 09:55:45 -0700 | [diff] [blame] | 402 | break; |
| 403 | default: |
| 404 | assert(0); |
| 405 | } |
| 406 | break; |
| 407 | case ir_binop_greater: |
Eric Anholt | 85171c2 | 2010-04-06 09:55:45 -0700 | [diff] [blame] | 408 | switch (ir->operands[0]->type->base_type) { |
| 409 | case GLSL_TYPE_UINT: |
Ian Romanick | 4daaab6 | 2010-06-11 16:08:47 -0700 | [diff] [blame] | 410 | data.b[0] = op[0]->value.u[0] > op[1]->value.u[0]; |
Eric Anholt | 85171c2 | 2010-04-06 09:55:45 -0700 | [diff] [blame] | 411 | break; |
| 412 | case GLSL_TYPE_INT: |
Ian Romanick | 4daaab6 | 2010-06-11 16:08:47 -0700 | [diff] [blame] | 413 | data.b[0] = op[0]->value.i[0] > op[1]->value.i[0]; |
Eric Anholt | 85171c2 | 2010-04-06 09:55:45 -0700 | [diff] [blame] | 414 | break; |
| 415 | case GLSL_TYPE_FLOAT: |
Ian Romanick | 4daaab6 | 2010-06-11 16:08:47 -0700 | [diff] [blame] | 416 | data.b[0] = op[0]->value.f[0] > op[1]->value.f[0]; |
Eric Anholt | 85171c2 | 2010-04-06 09:55:45 -0700 | [diff] [blame] | 417 | break; |
| 418 | default: |
| 419 | assert(0); |
| 420 | } |
| 421 | break; |
| 422 | case ir_binop_lequal: |
Eric Anholt | 85171c2 | 2010-04-06 09:55:45 -0700 | [diff] [blame] | 423 | switch (ir->operands[0]->type->base_type) { |
| 424 | case GLSL_TYPE_UINT: |
Ian Romanick | 4daaab6 | 2010-06-11 16:08:47 -0700 | [diff] [blame] | 425 | data.b[0] = op[0]->value.u[0] <= op[1]->value.u[0]; |
Eric Anholt | 85171c2 | 2010-04-06 09:55:45 -0700 | [diff] [blame] | 426 | break; |
| 427 | case GLSL_TYPE_INT: |
Ian Romanick | 4daaab6 | 2010-06-11 16:08:47 -0700 | [diff] [blame] | 428 | data.b[0] = op[0]->value.i[0] <= op[1]->value.i[0]; |
Eric Anholt | 85171c2 | 2010-04-06 09:55:45 -0700 | [diff] [blame] | 429 | break; |
| 430 | case GLSL_TYPE_FLOAT: |
Ian Romanick | 4daaab6 | 2010-06-11 16:08:47 -0700 | [diff] [blame] | 431 | data.b[0] = op[0]->value.f[0] <= op[1]->value.f[0]; |
Eric Anholt | 85171c2 | 2010-04-06 09:55:45 -0700 | [diff] [blame] | 432 | break; |
| 433 | default: |
| 434 | assert(0); |
| 435 | } |
| 436 | break; |
| 437 | case ir_binop_gequal: |
Eric Anholt | 85171c2 | 2010-04-06 09:55:45 -0700 | [diff] [blame] | 438 | switch (ir->operands[0]->type->base_type) { |
| 439 | case GLSL_TYPE_UINT: |
Ian Romanick | 4daaab6 | 2010-06-11 16:08:47 -0700 | [diff] [blame] | 440 | data.b[0] = op[0]->value.u[0] >= op[1]->value.u[0]; |
Eric Anholt | 85171c2 | 2010-04-06 09:55:45 -0700 | [diff] [blame] | 441 | break; |
| 442 | case GLSL_TYPE_INT: |
Ian Romanick | 4daaab6 | 2010-06-11 16:08:47 -0700 | [diff] [blame] | 443 | data.b[0] = op[0]->value.i[0] >= op[1]->value.i[0]; |
Eric Anholt | 85171c2 | 2010-04-06 09:55:45 -0700 | [diff] [blame] | 444 | break; |
| 445 | case GLSL_TYPE_FLOAT: |
Ian Romanick | 4daaab6 | 2010-06-11 16:08:47 -0700 | [diff] [blame] | 446 | data.b[0] = op[0]->value.f[0] >= op[1]->value.f[0]; |
Eric Anholt | 85171c2 | 2010-04-06 09:55:45 -0700 | [diff] [blame] | 447 | break; |
| 448 | default: |
| 449 | assert(0); |
| 450 | } |
| 451 | break; |
| 452 | |
Eric Anholt | ec1949e | 2010-04-06 10:02:27 -0700 | [diff] [blame] | 453 | case ir_binop_equal: |
Ian Romanick | 083d75a | 2010-06-11 16:20:43 -0700 | [diff] [blame] | 454 | data.b[0] = true; |
| 455 | for (c = 0; c < ir->operands[0]->type->components(); c++) { |
| 456 | switch (ir->operands[0]->type->base_type) { |
| 457 | case GLSL_TYPE_UINT: |
| 458 | data.b[0] = data.b[0] && op[0]->value.u[c] == op[1]->value.u[c]; |
| 459 | break; |
| 460 | case GLSL_TYPE_INT: |
| 461 | data.b[0] = data.b[0] && op[0]->value.i[c] == op[1]->value.i[c]; |
| 462 | break; |
| 463 | case GLSL_TYPE_FLOAT: |
| 464 | data.b[0] = data.b[0] && op[0]->value.f[c] == op[1]->value.f[c]; |
| 465 | break; |
| 466 | case GLSL_TYPE_BOOL: |
| 467 | data.b[0] = data.b[0] && op[0]->value.b[c] == op[1]->value.b[c]; |
| 468 | break; |
| 469 | default: |
| 470 | assert(0); |
Eric Anholt | ec1949e | 2010-04-06 10:02:27 -0700 | [diff] [blame] | 471 | } |
| 472 | } |
| 473 | break; |
| 474 | case ir_binop_nequal: |
Ian Romanick | 083d75a | 2010-06-11 16:20:43 -0700 | [diff] [blame] | 475 | data.b[0] = false; |
| 476 | for (c = 0; c < ir->operands[0]->type->components(); c++) { |
| 477 | switch (ir->operands[0]->type->base_type) { |
| 478 | case GLSL_TYPE_UINT: |
| 479 | data.b[0] = data.b[0] || op[0]->value.u[c] != op[1]->value.u[c]; |
| 480 | break; |
| 481 | case GLSL_TYPE_INT: |
| 482 | data.b[0] = data.b[0] || op[0]->value.i[c] != op[1]->value.i[c]; |
| 483 | break; |
| 484 | case GLSL_TYPE_FLOAT: |
| 485 | data.b[0] = data.b[0] || op[0]->value.f[c] != op[1]->value.f[c]; |
| 486 | break; |
| 487 | case GLSL_TYPE_BOOL: |
| 488 | data.b[0] = data.b[0] || op[0]->value.b[c] != op[1]->value.b[c]; |
| 489 | break; |
| 490 | default: |
| 491 | assert(0); |
Eric Anholt | ec1949e | 2010-04-06 10:02:27 -0700 | [diff] [blame] | 492 | } |
| 493 | } |
| 494 | break; |
| 495 | |
Eric Anholt | a576f9d | 2010-03-31 16:25:12 -1000 | [diff] [blame] | 496 | default: |
Ian Romanick | f8b88be | 2010-06-11 16:23:52 -0700 | [diff] [blame] | 497 | /* FINISHME: Should handle all expression types. */ |
| 498 | return; |
Eric Anholt | a576f9d | 2010-03-31 16:25:12 -1000 | [diff] [blame] | 499 | } |
Eric Anholt | d98da97 | 2010-04-01 18:25:11 -1000 | [diff] [blame] | 500 | |
Eric Anholt | 6b01b50 | 2010-06-24 15:18:39 -0700 | [diff] [blame] | 501 | void *ctx = talloc_parent(ir); |
Carl Worth | 1660a29 | 2010-06-23 18:11:51 -0700 | [diff] [blame] | 502 | this->value = new(ctx) ir_constant(ir->type, &data); |
Ian Romanick | 1cf43a4 | 2010-03-30 16:56:50 -0700 | [diff] [blame] | 503 | } |
| 504 | |
| 505 | |
| 506 | void |
Kenneth Graunke | 26d74cd | 2010-05-26 17:42:03 -0700 | [diff] [blame] | 507 | ir_constant_visitor::visit(ir_texture *ir) |
| 508 | { |
| 509 | // FINISHME: Do stuff with texture lookups |
| 510 | (void) ir; |
| 511 | value = NULL; |
| 512 | } |
| 513 | |
| 514 | |
| 515 | void |
Ian Romanick | 1cf43a4 | 2010-03-30 16:56:50 -0700 | [diff] [blame] | 516 | ir_constant_visitor::visit(ir_swizzle *ir) |
| 517 | { |
Ian Romanick | c2ba619 | 2010-06-11 12:30:28 -0700 | [diff] [blame] | 518 | ir_constant *v = ir->val->constant_expression_value(); |
| 519 | |
| 520 | this->value = NULL; |
| 521 | |
| 522 | if (v != NULL) { |
Ian Romanick | 0bb70a3 | 2010-06-11 15:49:49 -0700 | [diff] [blame] | 523 | ir_constant_data data; |
Ian Romanick | c2ba619 | 2010-06-11 12:30:28 -0700 | [diff] [blame] | 524 | |
| 525 | const unsigned swiz_idx[4] = { |
| 526 | ir->mask.x, ir->mask.y, ir->mask.z, ir->mask.w |
| 527 | }; |
| 528 | |
| 529 | for (unsigned i = 0; i < ir->mask.num_components; i++) { |
| 530 | switch (v->type->base_type) { |
| 531 | case GLSL_TYPE_UINT: |
| 532 | case GLSL_TYPE_INT: data.u[i] = v->value.u[swiz_idx[i]]; break; |
| 533 | case GLSL_TYPE_FLOAT: data.f[i] = v->value.f[swiz_idx[i]]; break; |
| 534 | case GLSL_TYPE_BOOL: data.b[i] = v->value.b[swiz_idx[i]]; break; |
| 535 | default: assert(!"Should not get here."); break; |
| 536 | } |
| 537 | } |
| 538 | |
Eric Anholt | 6b01b50 | 2010-06-24 15:18:39 -0700 | [diff] [blame] | 539 | void *ctx = talloc_parent(ir); |
Carl Worth | 1660a29 | 2010-06-23 18:11:51 -0700 | [diff] [blame] | 540 | this->value = new(ctx) ir_constant(ir->type, &data); |
Ian Romanick | c2ba619 | 2010-06-11 12:30:28 -0700 | [diff] [blame] | 541 | } |
Ian Romanick | 1cf43a4 | 2010-03-30 16:56:50 -0700 | [diff] [blame] | 542 | } |
| 543 | |
| 544 | |
| 545 | void |
Ian Romanick | c7b1046 | 2010-05-19 13:20:12 +0200 | [diff] [blame] | 546 | ir_constant_visitor::visit(ir_dereference_variable *ir) |
Ian Romanick | 1cf43a4 | 2010-03-30 16:56:50 -0700 | [diff] [blame] | 547 | { |
Ian Romanick | 1cf43a4 | 2010-03-30 16:56:50 -0700 | [diff] [blame] | 548 | value = NULL; |
Eric Anholt | 326c676 | 2010-04-06 10:30:54 -0700 | [diff] [blame] | 549 | |
Ian Romanick | c7b1046 | 2010-05-19 13:20:12 +0200 | [diff] [blame] | 550 | ir_variable *var = ir->variable_referenced(); |
| 551 | if (var && var->constant_value) |
Eric Anholt | 4b6fd39 | 2010-06-23 11:37:12 -0700 | [diff] [blame] | 552 | value = (ir_constant *)var->constant_value->clone(NULL); |
Ian Romanick | c7b1046 | 2010-05-19 13:20:12 +0200 | [diff] [blame] | 553 | } |
| 554 | |
| 555 | |
| 556 | void |
| 557 | ir_constant_visitor::visit(ir_dereference_array *ir) |
| 558 | { |
Carl Worth | 1660a29 | 2010-06-23 18:11:51 -0700 | [diff] [blame] | 559 | void *ctx = talloc_parent(ir); |
Ian Romanick | 9b92af9 | 2010-06-11 12:20:12 -0700 | [diff] [blame] | 560 | ir_constant *array = ir->array->constant_expression_value(); |
| 561 | ir_constant *idx = ir->array_index->constant_expression_value(); |
| 562 | |
| 563 | this->value = NULL; |
| 564 | |
| 565 | if ((array != NULL) && (idx != NULL)) { |
| 566 | if (array->type->is_matrix()) { |
| 567 | /* Array access of a matrix results in a vector. |
| 568 | */ |
| 569 | const unsigned column = idx->value.u[0]; |
| 570 | |
| 571 | const glsl_type *const column_type = array->type->column_type(); |
| 572 | |
| 573 | /* Offset in the constant matrix to the first element of the column |
| 574 | * to be extracted. |
| 575 | */ |
| 576 | const unsigned mat_idx = column * column_type->vector_elements; |
| 577 | |
Ian Romanick | 0bb70a3 | 2010-06-11 15:49:49 -0700 | [diff] [blame] | 578 | ir_constant_data data; |
Ian Romanick | 9b92af9 | 2010-06-11 12:20:12 -0700 | [diff] [blame] | 579 | |
| 580 | switch (column_type->base_type) { |
| 581 | case GLSL_TYPE_UINT: |
| 582 | case GLSL_TYPE_INT: |
| 583 | for (unsigned i = 0; i < column_type->vector_elements; i++) |
| 584 | data.u[i] = array->value.u[mat_idx + i]; |
| 585 | |
| 586 | break; |
| 587 | |
| 588 | case GLSL_TYPE_FLOAT: |
| 589 | for (unsigned i = 0; i < column_type->vector_elements; i++) |
| 590 | data.f[i] = array->value.f[mat_idx + i]; |
| 591 | |
| 592 | break; |
| 593 | |
| 594 | default: |
| 595 | assert(!"Should not get here."); |
| 596 | break; |
| 597 | } |
| 598 | |
Carl Worth | 1660a29 | 2010-06-23 18:11:51 -0700 | [diff] [blame] | 599 | this->value = new(ctx) ir_constant(column_type, &data); |
Ian Romanick | 9b92af9 | 2010-06-11 12:20:12 -0700 | [diff] [blame] | 600 | } else if (array->type->is_vector()) { |
| 601 | const unsigned component = idx->value.u[0]; |
| 602 | |
Carl Worth | 1660a29 | 2010-06-23 18:11:51 -0700 | [diff] [blame] | 603 | this->value = new(ctx) ir_constant(array, component); |
Ian Romanick | 9b92af9 | 2010-06-11 12:20:12 -0700 | [diff] [blame] | 604 | } else { |
| 605 | /* FINISHME: Handle access of constant arrays. */ |
| 606 | } |
| 607 | } |
Ian Romanick | c7b1046 | 2010-05-19 13:20:12 +0200 | [diff] [blame] | 608 | } |
| 609 | |
| 610 | |
| 611 | void |
| 612 | ir_constant_visitor::visit(ir_dereference_record *ir) |
| 613 | { |
Ian Romanick | 253dede | 2010-06-09 17:30:19 -0700 | [diff] [blame] | 614 | ir_constant *v = ir->record->constant_expression_value(); |
| 615 | |
| 616 | this->value = (v != NULL) ? v->get_record_field(ir->field) : NULL; |
Ian Romanick | 1cf43a4 | 2010-03-30 16:56:50 -0700 | [diff] [blame] | 617 | } |
| 618 | |
| 619 | |
| 620 | void |
| 621 | ir_constant_visitor::visit(ir_assignment *ir) |
| 622 | { |
| 623 | (void) ir; |
| 624 | value = NULL; |
| 625 | } |
| 626 | |
| 627 | |
| 628 | void |
| 629 | ir_constant_visitor::visit(ir_constant *ir) |
| 630 | { |
| 631 | value = ir; |
| 632 | } |
| 633 | |
| 634 | |
| 635 | void |
| 636 | ir_constant_visitor::visit(ir_call *ir) |
| 637 | { |
| 638 | (void) ir; |
| 639 | value = NULL; |
| 640 | } |
| 641 | |
| 642 | |
| 643 | void |
| 644 | ir_constant_visitor::visit(ir_return *ir) |
| 645 | { |
| 646 | (void) ir; |
| 647 | value = NULL; |
| 648 | } |
| 649 | |
| 650 | |
| 651 | void |
Kenneth Graunke | 16efab1 | 2010-06-30 10:47:34 -0700 | [diff] [blame^] | 652 | ir_constant_visitor::visit(ir_discard *ir) |
| 653 | { |
| 654 | (void) ir; |
| 655 | value = NULL; |
| 656 | } |
| 657 | |
| 658 | |
| 659 | void |
Ian Romanick | 1cf43a4 | 2010-03-30 16:56:50 -0700 | [diff] [blame] | 660 | ir_constant_visitor::visit(ir_if *ir) |
| 661 | { |
| 662 | (void) ir; |
| 663 | value = NULL; |
| 664 | } |
Ian Romanick | fad607a | 2010-04-05 16:16:07 -0700 | [diff] [blame] | 665 | |
| 666 | |
| 667 | void |
| 668 | ir_constant_visitor::visit(ir_loop *ir) |
| 669 | { |
| 670 | (void) ir; |
| 671 | value = NULL; |
| 672 | } |
Ian Romanick | f8e31e0 | 2010-04-05 16:28:15 -0700 | [diff] [blame] | 673 | |
| 674 | |
| 675 | void |
| 676 | ir_constant_visitor::visit(ir_loop_jump *ir) |
| 677 | { |
| 678 | (void) ir; |
| 679 | value = NULL; |
| 680 | } |