Clone of mesa.
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

ir_constant_expression.cpp 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  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. * \file ir_constant_expression.cpp
  25. * Evaluate and process constant valued expressions
  26. *
  27. * In GLSL, constant valued expressions are used in several places. These
  28. * must be processed and evaluated very early in the compilation process.
  29. *
  30. * * Sizes of arrays
  31. * * Initializers for uniforms
  32. * * Initializers for \c const variables
  33. */
  34. #include <math.h>
  35. #include "ir.h"
  36. #include "ir_visitor.h"
  37. #include "glsl_types.h"
  38. /**
  39. * Visitor class for evaluating constant expressions
  40. */
  41. class ir_constant_visitor : public ir_visitor {
  42. public:
  43. ir_constant_visitor()
  44. : value(NULL)
  45. {
  46. /* empty */
  47. }
  48. virtual ~ir_constant_visitor()
  49. {
  50. /* empty */
  51. }
  52. /**
  53. * \name Visit methods
  54. *
  55. * As typical for the visitor pattern, there must be one \c visit method for
  56. * each concrete subclass of \c ir_instruction. Virtual base classes within
  57. * the hierarchy should not have \c visit methods.
  58. */
  59. /*@{*/
  60. virtual void visit(ir_variable *);
  61. virtual void visit(ir_function_signature *);
  62. virtual void visit(ir_function *);
  63. virtual void visit(ir_expression *);
  64. virtual void visit(ir_texture *);
  65. virtual void visit(ir_swizzle *);
  66. virtual void visit(ir_dereference_variable *);
  67. virtual void visit(ir_dereference_array *);
  68. virtual void visit(ir_dereference_record *);
  69. virtual void visit(ir_assignment *);
  70. virtual void visit(ir_constant *);
  71. virtual void visit(ir_call *);
  72. virtual void visit(ir_return *);
  73. virtual void visit(ir_discard *);
  74. virtual void visit(ir_if *);
  75. virtual void visit(ir_loop *);
  76. virtual void visit(ir_loop_jump *);
  77. /*@}*/
  78. /**
  79. * Value of the constant expression.
  80. *
  81. * \note
  82. * This field will be \c NULL if the expression is not constant valued.
  83. */
  84. /* FINIHSME: This cannot hold values for constant arrays or structures. */
  85. ir_constant *value;
  86. };
  87. ir_constant *
  88. ir_instruction::constant_expression_value()
  89. {
  90. ir_constant_visitor visitor;
  91. this->accept(& visitor);
  92. return visitor.value;
  93. }
  94. void
  95. ir_constant_visitor::visit(ir_variable *ir)
  96. {
  97. (void) ir;
  98. value = NULL;
  99. }
  100. void
  101. ir_constant_visitor::visit(ir_function_signature *ir)
  102. {
  103. (void) ir;
  104. value = NULL;
  105. }
  106. void
  107. ir_constant_visitor::visit(ir_function *ir)
  108. {
  109. (void) ir;
  110. value = NULL;
  111. }
  112. void
  113. ir_constant_visitor::visit(ir_expression *ir)
  114. {
  115. value = NULL;
  116. ir_constant *op[2];
  117. unsigned int operand, c;
  118. ir_constant_data data;
  119. for (operand = 0; operand < ir->get_num_operands(); operand++) {
  120. op[operand] = ir->operands[operand]->constant_expression_value();
  121. if (!op[operand])
  122. return;
  123. }
  124. switch (ir->operation) {
  125. case ir_unop_logic_not:
  126. assert(op[0]->type->base_type == GLSL_TYPE_BOOL);
  127. for (c = 0; c < ir->operands[0]->type->components(); c++)
  128. data.b[c] = !op[0]->value.b[c];
  129. break;
  130. case ir_unop_f2i:
  131. assert(op[0]->type->base_type == GLSL_TYPE_FLOAT);
  132. for (c = 0; c < ir->operands[0]->type->components(); c++) {
  133. data.i[c] = op[0]->value.f[c];
  134. }
  135. break;
  136. case ir_unop_i2f:
  137. assert(op[0]->type->base_type == GLSL_TYPE_UINT ||
  138. op[0]->type->base_type == GLSL_TYPE_INT);
  139. for (c = 0; c < ir->operands[0]->type->components(); c++) {
  140. if (op[0]->type->base_type == GLSL_TYPE_INT)
  141. data.f[c] = op[0]->value.i[c];
  142. else
  143. data.f[c] = op[0]->value.u[c];
  144. }
  145. break;
  146. case ir_unop_b2f:
  147. assert(op[0]->type->base_type == GLSL_TYPE_BOOL);
  148. for (c = 0; c < ir->operands[0]->type->components(); c++) {
  149. data.f[c] = op[0]->value.b[c] ? 1.0 : 0.0;
  150. }
  151. break;
  152. case ir_unop_f2b:
  153. assert(op[0]->type->base_type == GLSL_TYPE_FLOAT);
  154. for (c = 0; c < ir->operands[0]->type->components(); c++) {
  155. data.b[c] = bool(op[0]->value.f[c]);
  156. }
  157. break;
  158. case ir_unop_b2i:
  159. assert(op[0]->type->base_type == GLSL_TYPE_BOOL);
  160. for (c = 0; c < ir->operands[0]->type->components(); c++) {
  161. data.u[c] = op[0]->value.b[c] ? 1 : 0;
  162. }
  163. break;
  164. case ir_unop_i2b:
  165. assert(op[0]->type->is_integer());
  166. for (c = 0; c < ir->operands[0]->type->components(); c++) {
  167. data.b[c] = bool(op[0]->value.u[c]);
  168. }
  169. break;
  170. case ir_unop_fract:
  171. for (c = 0; c < ir->operands[0]->type->components(); c++) {
  172. switch (ir->type->base_type) {
  173. case GLSL_TYPE_UINT:
  174. data.u[c] = 0;
  175. break;
  176. case GLSL_TYPE_INT:
  177. data.i[c] = 0;
  178. break;
  179. case GLSL_TYPE_FLOAT:
  180. data.f[c] = op[0]->value.f[c] - floor(op[0]->value.f[c]);
  181. break;
  182. default:
  183. assert(0);
  184. }
  185. }
  186. break;
  187. case ir_unop_neg:
  188. for (c = 0; c < ir->operands[0]->type->components(); c++) {
  189. switch (ir->type->base_type) {
  190. case GLSL_TYPE_UINT:
  191. data.u[c] = -op[0]->value.u[c];
  192. break;
  193. case GLSL_TYPE_INT:
  194. data.i[c] = -op[0]->value.i[c];
  195. break;
  196. case GLSL_TYPE_FLOAT:
  197. data.f[c] = -op[0]->value.f[c];
  198. break;
  199. default:
  200. assert(0);
  201. }
  202. }
  203. break;
  204. case ir_unop_abs:
  205. assert(op[0]->type->base_type == GLSL_TYPE_FLOAT);
  206. for (c = 0; c < ir->operands[0]->type->components(); c++) {
  207. switch (ir->type->base_type) {
  208. case GLSL_TYPE_UINT:
  209. data.u[c] = op[0]->value.u[c];
  210. break;
  211. case GLSL_TYPE_INT:
  212. data.i[c] = op[0]->value.i[c];
  213. if (data.i[c] < 0)
  214. data.i[c] = -data.i[c];
  215. break;
  216. case GLSL_TYPE_FLOAT:
  217. data.f[c] = fabs(op[0]->value.f[c]);
  218. break;
  219. default:
  220. assert(0);
  221. }
  222. }
  223. break;
  224. case ir_unop_rcp:
  225. assert(op[0]->type->base_type == GLSL_TYPE_FLOAT);
  226. for (c = 0; c < ir->operands[0]->type->components(); c++) {
  227. switch (ir->type->base_type) {
  228. case GLSL_TYPE_UINT:
  229. if (op[0]->value.u[c] != 0.0)
  230. data.u[c] = 1 / op[0]->value.u[c];
  231. break;
  232. case GLSL_TYPE_INT:
  233. if (op[0]->value.i[c] != 0.0)
  234. data.i[c] = 1 / op[0]->value.i[c];
  235. break;
  236. case GLSL_TYPE_FLOAT:
  237. if (op[0]->value.f[c] != 0.0)
  238. data.f[c] = 1.0 / op[0]->value.f[c];
  239. break;
  240. default:
  241. assert(0);
  242. }
  243. }
  244. break;
  245. case ir_unop_rsq:
  246. assert(op[0]->type->base_type == GLSL_TYPE_FLOAT);
  247. for (c = 0; c < ir->operands[0]->type->components(); c++) {
  248. data.f[c] = 1.0 / sqrtf(op[0]->value.f[c]);
  249. }
  250. break;
  251. case ir_unop_sqrt:
  252. assert(op[0]->type->base_type == GLSL_TYPE_FLOAT);
  253. for (c = 0; c < ir->operands[0]->type->components(); c++) {
  254. data.f[c] = sqrtf(op[0]->value.f[c]);
  255. }
  256. break;
  257. case ir_unop_exp:
  258. assert(op[0]->type->base_type == GLSL_TYPE_FLOAT);
  259. for (c = 0; c < ir->operands[0]->type->components(); c++) {
  260. data.f[c] = expf(op[0]->value.f[c]);
  261. }
  262. break;
  263. case ir_unop_log:
  264. assert(op[0]->type->base_type == GLSL_TYPE_FLOAT);
  265. for (c = 0; c < ir->operands[0]->type->components(); c++) {
  266. data.f[c] = logf(op[0]->value.f[c]);
  267. }
  268. break;
  269. case ir_unop_dFdx:
  270. case ir_unop_dFdy:
  271. assert(op[0]->type->base_type == GLSL_TYPE_FLOAT);
  272. for (c = 0; c < ir->operands[0]->type->components(); c++) {
  273. data.f[c] = 0.0;
  274. }
  275. break;
  276. case ir_binop_add:
  277. if (ir->operands[0]->type == ir->operands[1]->type) {
  278. for (c = 0; c < ir->operands[0]->type->components(); c++) {
  279. switch (ir->operands[0]->type->base_type) {
  280. case GLSL_TYPE_UINT:
  281. data.u[c] = op[0]->value.u[c] + op[1]->value.u[c];
  282. break;
  283. case GLSL_TYPE_INT:
  284. data.i[c] = op[0]->value.i[c] + op[1]->value.i[c];
  285. break;
  286. case GLSL_TYPE_FLOAT:
  287. data.f[c] = op[0]->value.f[c] + op[1]->value.f[c];
  288. break;
  289. default:
  290. assert(0);
  291. }
  292. }
  293. } else
  294. /* FINISHME: Support operations with non-equal types. */
  295. return;
  296. break;
  297. case ir_binop_sub:
  298. if (ir->operands[0]->type == ir->operands[1]->type) {
  299. for (c = 0; c < ir->operands[0]->type->components(); c++) {
  300. switch (ir->operands[0]->type->base_type) {
  301. case GLSL_TYPE_UINT:
  302. data.u[c] = op[0]->value.u[c] - op[1]->value.u[c];
  303. break;
  304. case GLSL_TYPE_INT:
  305. data.i[c] = op[0]->value.i[c] - op[1]->value.i[c];
  306. break;
  307. case GLSL_TYPE_FLOAT:
  308. data.f[c] = op[0]->value.f[c] - op[1]->value.f[c];
  309. break;
  310. default:
  311. assert(0);
  312. }
  313. }
  314. } else
  315. /* FINISHME: Support operations with non-equal types. */
  316. return;
  317. break;
  318. case ir_binop_mul:
  319. if (ir->operands[0]->type == ir->operands[1]->type &&
  320. !ir->operands[0]->type->is_matrix()) {
  321. for (c = 0; c < ir->operands[0]->type->components(); c++) {
  322. switch (ir->operands[0]->type->base_type) {
  323. case GLSL_TYPE_UINT:
  324. data.u[c] = op[0]->value.u[c] * op[1]->value.u[c];
  325. break;
  326. case GLSL_TYPE_INT:
  327. data.i[c] = op[0]->value.i[c] * op[1]->value.i[c];
  328. break;
  329. case GLSL_TYPE_FLOAT:
  330. data.f[c] = op[0]->value.f[c] * op[1]->value.f[c];
  331. break;
  332. default:
  333. assert(0);
  334. }
  335. }
  336. } else
  337. /* FINISHME: Support operations with non-equal types. */
  338. return;
  339. break;
  340. case ir_binop_div:
  341. if (ir->operands[0]->type == ir->operands[1]->type) {
  342. for (c = 0; c < ir->operands[0]->type->components(); c++) {
  343. switch (ir->operands[0]->type->base_type) {
  344. case GLSL_TYPE_UINT:
  345. data.u[c] = op[0]->value.u[c] / op[1]->value.u[c];
  346. break;
  347. case GLSL_TYPE_INT:
  348. data.i[c] = op[0]->value.i[c] / op[1]->value.i[c];
  349. break;
  350. case GLSL_TYPE_FLOAT:
  351. data.f[c] = op[0]->value.f[c] / op[1]->value.f[c];
  352. break;
  353. default:
  354. assert(0);
  355. }
  356. }
  357. } else
  358. /* FINISHME: Support operations with non-equal types. */
  359. return;
  360. break;
  361. case ir_binop_logic_and:
  362. assert(op[0]->type->base_type == GLSL_TYPE_BOOL);
  363. for (c = 0; c < ir->operands[0]->type->components(); c++)
  364. data.b[c] = op[0]->value.b[c] && op[1]->value.b[c];
  365. break;
  366. case ir_binop_logic_xor:
  367. assert(op[0]->type->base_type == GLSL_TYPE_BOOL);
  368. for (c = 0; c < ir->operands[0]->type->components(); c++)
  369. data.b[c] = op[0]->value.b[c] ^ op[1]->value.b[c];
  370. break;
  371. case ir_binop_logic_or:
  372. assert(op[0]->type->base_type == GLSL_TYPE_BOOL);
  373. for (c = 0; c < ir->operands[0]->type->components(); c++)
  374. data.b[c] = op[0]->value.b[c] || op[1]->value.b[c];
  375. break;
  376. case ir_binop_less:
  377. switch (ir->operands[0]->type->base_type) {
  378. case GLSL_TYPE_UINT:
  379. data.b[0] = op[0]->value.u[0] < op[1]->value.u[0];
  380. break;
  381. case GLSL_TYPE_INT:
  382. data.b[0] = op[0]->value.i[0] < op[1]->value.i[0];
  383. break;
  384. case GLSL_TYPE_FLOAT:
  385. data.b[0] = op[0]->value.f[0] < op[1]->value.f[0];
  386. break;
  387. default:
  388. assert(0);
  389. }
  390. break;
  391. case ir_binop_greater:
  392. switch (ir->operands[0]->type->base_type) {
  393. case GLSL_TYPE_UINT:
  394. data.b[0] = op[0]->value.u[0] > op[1]->value.u[0];
  395. break;
  396. case GLSL_TYPE_INT:
  397. data.b[0] = op[0]->value.i[0] > op[1]->value.i[0];
  398. break;
  399. case GLSL_TYPE_FLOAT:
  400. data.b[0] = op[0]->value.f[0] > op[1]->value.f[0];
  401. break;
  402. default:
  403. assert(0);
  404. }
  405. break;
  406. case ir_binop_lequal:
  407. switch (ir->operands[0]->type->base_type) {
  408. case GLSL_TYPE_UINT:
  409. data.b[0] = op[0]->value.u[0] <= op[1]->value.u[0];
  410. break;
  411. case GLSL_TYPE_INT:
  412. data.b[0] = op[0]->value.i[0] <= op[1]->value.i[0];
  413. break;
  414. case GLSL_TYPE_FLOAT:
  415. data.b[0] = op[0]->value.f[0] <= op[1]->value.f[0];
  416. break;
  417. default:
  418. assert(0);
  419. }
  420. break;
  421. case ir_binop_gequal:
  422. switch (ir->operands[0]->type->base_type) {
  423. case GLSL_TYPE_UINT:
  424. data.b[0] = op[0]->value.u[0] >= op[1]->value.u[0];
  425. break;
  426. case GLSL_TYPE_INT:
  427. data.b[0] = op[0]->value.i[0] >= op[1]->value.i[0];
  428. break;
  429. case GLSL_TYPE_FLOAT:
  430. data.b[0] = op[0]->value.f[0] >= op[1]->value.f[0];
  431. break;
  432. default:
  433. assert(0);
  434. }
  435. break;
  436. case ir_binop_equal:
  437. data.b[0] = true;
  438. for (c = 0; c < ir->operands[0]->type->components(); c++) {
  439. switch (ir->operands[0]->type->base_type) {
  440. case GLSL_TYPE_UINT:
  441. data.b[0] = data.b[0] && op[0]->value.u[c] == op[1]->value.u[c];
  442. break;
  443. case GLSL_TYPE_INT:
  444. data.b[0] = data.b[0] && op[0]->value.i[c] == op[1]->value.i[c];
  445. break;
  446. case GLSL_TYPE_FLOAT:
  447. data.b[0] = data.b[0] && op[0]->value.f[c] == op[1]->value.f[c];
  448. break;
  449. case GLSL_TYPE_BOOL:
  450. data.b[0] = data.b[0] && op[0]->value.b[c] == op[1]->value.b[c];
  451. break;
  452. default:
  453. assert(0);
  454. }
  455. }
  456. break;
  457. case ir_binop_nequal:
  458. data.b[0] = false;
  459. for (c = 0; c < ir->operands[0]->type->components(); c++) {
  460. switch (ir->operands[0]->type->base_type) {
  461. case GLSL_TYPE_UINT:
  462. data.b[0] = data.b[0] || op[0]->value.u[c] != op[1]->value.u[c];
  463. break;
  464. case GLSL_TYPE_INT:
  465. data.b[0] = data.b[0] || op[0]->value.i[c] != op[1]->value.i[c];
  466. break;
  467. case GLSL_TYPE_FLOAT:
  468. data.b[0] = data.b[0] || op[0]->value.f[c] != op[1]->value.f[c];
  469. break;
  470. case GLSL_TYPE_BOOL:
  471. data.b[0] = data.b[0] || op[0]->value.b[c] != op[1]->value.b[c];
  472. break;
  473. default:
  474. assert(0);
  475. }
  476. }
  477. break;
  478. default:
  479. /* FINISHME: Should handle all expression types. */
  480. return;
  481. }
  482. void *ctx = talloc_parent(ir);
  483. this->value = new(ctx) ir_constant(ir->type, &data);
  484. }
  485. void
  486. ir_constant_visitor::visit(ir_texture *ir)
  487. {
  488. // FINISHME: Do stuff with texture lookups
  489. (void) ir;
  490. value = NULL;
  491. }
  492. void
  493. ir_constant_visitor::visit(ir_swizzle *ir)
  494. {
  495. ir_constant *v = ir->val->constant_expression_value();
  496. this->value = NULL;
  497. if (v != NULL) {
  498. ir_constant_data data;
  499. const unsigned swiz_idx[4] = {
  500. ir->mask.x, ir->mask.y, ir->mask.z, ir->mask.w
  501. };
  502. for (unsigned i = 0; i < ir->mask.num_components; i++) {
  503. switch (v->type->base_type) {
  504. case GLSL_TYPE_UINT:
  505. case GLSL_TYPE_INT: data.u[i] = v->value.u[swiz_idx[i]]; break;
  506. case GLSL_TYPE_FLOAT: data.f[i] = v->value.f[swiz_idx[i]]; break;
  507. case GLSL_TYPE_BOOL: data.b[i] = v->value.b[swiz_idx[i]]; break;
  508. default: assert(!"Should not get here."); break;
  509. }
  510. }
  511. void *ctx = talloc_parent(ir);
  512. this->value = new(ctx) ir_constant(ir->type, &data);
  513. }
  514. }
  515. void
  516. ir_constant_visitor::visit(ir_dereference_variable *ir)
  517. {
  518. value = NULL;
  519. ir_variable *var = ir->variable_referenced();
  520. if (var && var->constant_value)
  521. value = (ir_constant *)var->constant_value->clone(NULL);
  522. }
  523. void
  524. ir_constant_visitor::visit(ir_dereference_array *ir)
  525. {
  526. void *ctx = talloc_parent(ir);
  527. ir_constant *array = ir->array->constant_expression_value();
  528. ir_constant *idx = ir->array_index->constant_expression_value();
  529. this->value = NULL;
  530. if ((array != NULL) && (idx != NULL)) {
  531. if (array->type->is_matrix()) {
  532. /* Array access of a matrix results in a vector.
  533. */
  534. const unsigned column = idx->value.u[0];
  535. const glsl_type *const column_type = array->type->column_type();
  536. /* Offset in the constant matrix to the first element of the column
  537. * to be extracted.
  538. */
  539. const unsigned mat_idx = column * column_type->vector_elements;
  540. ir_constant_data data;
  541. switch (column_type->base_type) {
  542. case GLSL_TYPE_UINT:
  543. case GLSL_TYPE_INT:
  544. for (unsigned i = 0; i < column_type->vector_elements; i++)
  545. data.u[i] = array->value.u[mat_idx + i];
  546. break;
  547. case GLSL_TYPE_FLOAT:
  548. for (unsigned i = 0; i < column_type->vector_elements; i++)
  549. data.f[i] = array->value.f[mat_idx + i];
  550. break;
  551. default:
  552. assert(!"Should not get here.");
  553. break;
  554. }
  555. this->value = new(ctx) ir_constant(column_type, &data);
  556. } else if (array->type->is_vector()) {
  557. const unsigned component = idx->value.u[0];
  558. this->value = new(ctx) ir_constant(array, component);
  559. } else {
  560. /* FINISHME: Handle access of constant arrays. */
  561. }
  562. }
  563. }
  564. void
  565. ir_constant_visitor::visit(ir_dereference_record *ir)
  566. {
  567. ir_constant *v = ir->record->constant_expression_value();
  568. this->value = (v != NULL) ? v->get_record_field(ir->field) : NULL;
  569. }
  570. void
  571. ir_constant_visitor::visit(ir_assignment *ir)
  572. {
  573. (void) ir;
  574. value = NULL;
  575. }
  576. void
  577. ir_constant_visitor::visit(ir_constant *ir)
  578. {
  579. value = ir;
  580. }
  581. void
  582. ir_constant_visitor::visit(ir_call *ir)
  583. {
  584. (void) ir;
  585. value = NULL;
  586. }
  587. void
  588. ir_constant_visitor::visit(ir_return *ir)
  589. {
  590. (void) ir;
  591. value = NULL;
  592. }
  593. void
  594. ir_constant_visitor::visit(ir_discard *ir)
  595. {
  596. (void) ir;
  597. value = NULL;
  598. }
  599. void
  600. ir_constant_visitor::visit(ir_if *ir)
  601. {
  602. (void) ir;
  603. value = NULL;
  604. }
  605. void
  606. ir_constant_visitor::visit(ir_loop *ir)
  607. {
  608. (void) ir;
  609. value = NULL;
  610. }
  611. void
  612. ir_constant_visitor::visit(ir_loop_jump *ir)
  613. {
  614. (void) ir;
  615. value = NULL;
  616. }