Clone of mesa.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ir_constant_folding.cpp 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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_folding.cpp
  25. * Replace constant-valued expressions with references to constant values.
  26. */
  27. #define NULL 0
  28. #include "ir.h"
  29. #include "ir_visitor.h"
  30. #include "ir_constant_folding.h"
  31. #include "glsl_types.h"
  32. /**
  33. * Visitor class for replacing expressions with ir_constant values.
  34. */
  35. void
  36. ir_constant_folding_visitor::visit(ir_variable *ir)
  37. {
  38. (void) ir;
  39. }
  40. void
  41. ir_constant_folding_visitor::visit(ir_label *ir)
  42. {
  43. (void) ir;
  44. }
  45. void
  46. ir_constant_folding_visitor::visit(ir_function_signature *ir)
  47. {
  48. (void) ir;
  49. }
  50. void
  51. ir_constant_folding_visitor::visit(ir_function *ir)
  52. {
  53. (void) ir;
  54. }
  55. void
  56. ir_constant_folding_visitor::visit(ir_expression *ir)
  57. {
  58. ir_constant *op[2];
  59. unsigned int operand;
  60. for (operand = 0; operand < ir->get_num_operands(); operand++) {
  61. op[operand] = ir->operands[operand]->constant_expression_value();
  62. if (op[operand]) {
  63. ir->operands[operand] = op[operand];
  64. }
  65. }
  66. }
  67. void
  68. ir_constant_folding_visitor::visit(ir_swizzle *ir)
  69. {
  70. (void) ir;
  71. }
  72. void
  73. ir_constant_folding_visitor::visit(ir_dereference *ir)
  74. {
  75. (void) ir;
  76. }
  77. void
  78. ir_constant_folding_visitor::visit(ir_assignment *ir)
  79. {
  80. ir_constant *const_val = ir->rhs->constant_expression_value();
  81. if (const_val)
  82. ir->rhs = const_val;
  83. else
  84. ir->rhs->accept(this);
  85. }
  86. void
  87. ir_constant_folding_visitor::visit(ir_constant *ir)
  88. {
  89. (void) ir;
  90. }
  91. void
  92. ir_constant_folding_visitor::visit(ir_call *ir)
  93. {
  94. (void) ir;
  95. }
  96. void
  97. ir_constant_folding_visitor::visit(ir_return *ir)
  98. {
  99. (void) ir;
  100. }
  101. void
  102. ir_constant_folding_visitor::visit(ir_if *ir)
  103. {
  104. ir_constant *const_val = ir->condition->constant_expression_value();
  105. if (const_val)
  106. ir->condition = const_val;
  107. else
  108. ir->condition->accept(this);
  109. }