Clone of mesa.
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

ir_clone.cpp 6.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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. #include <string.h>
  24. #include "ir.h"
  25. #include "glsl_types.h"
  26. #include "hash_table.h"
  27. /**
  28. * Duplicate an IR variable
  29. *
  30. * \note
  31. * This will probably be made \c virtual and moved to the base class
  32. * eventually.
  33. */
  34. ir_instruction *
  35. ir_variable::clone(struct hash_table *ht) const
  36. {
  37. ir_variable *var = new ir_variable(type, name);
  38. var->max_array_access = this->max_array_access;
  39. var->read_only = this->read_only;
  40. var->centroid = this->centroid;
  41. var->invariant = this->invariant;
  42. var->mode = this->mode;
  43. var->interpolation = this->interpolation;
  44. if (ht) {
  45. hash_table_insert(ht, var, (void *)const_cast<ir_variable *>(this));
  46. }
  47. return var;
  48. }
  49. ir_instruction *
  50. ir_swizzle::clone(struct hash_table *ht) const
  51. {
  52. return new ir_swizzle((ir_rvalue *)this->val->clone(ht), this->mask);
  53. }
  54. ir_instruction *
  55. ir_return::clone(struct hash_table *ht) const
  56. {
  57. ir_rvalue *new_value = NULL;
  58. if (this->value)
  59. new_value = (ir_rvalue *)this->value->clone(ht);
  60. return new ir_return(new_value);
  61. }
  62. ir_instruction *
  63. ir_loop_jump::clone(struct hash_table *ht) const
  64. {
  65. (void)ht;
  66. return new ir_loop_jump(this->mode);
  67. }
  68. ir_instruction *
  69. ir_if::clone(struct hash_table *ht) const
  70. {
  71. ir_if *new_if = new ir_if((ir_rvalue *)this->condition->clone(ht));
  72. foreach_iter(exec_list_iterator, iter, this->then_instructions) {
  73. ir_instruction *ir = (ir_instruction *)iter.get();
  74. new_if->then_instructions.push_tail(ir->clone(ht));
  75. }
  76. foreach_iter(exec_list_iterator, iter, this->else_instructions) {
  77. ir_instruction *ir = (ir_instruction *)iter.get();
  78. new_if->else_instructions.push_tail(ir->clone(ht));
  79. }
  80. return new_if;
  81. }
  82. ir_instruction *
  83. ir_loop::clone(struct hash_table *ht) const
  84. {
  85. ir_loop *new_loop = new ir_loop();
  86. if (this->from)
  87. new_loop->from = (ir_rvalue *)this->from->clone(ht);
  88. if (this->to)
  89. new_loop->to = (ir_rvalue *)this->to->clone(ht);
  90. if (this->increment)
  91. new_loop->increment = (ir_rvalue *)this->increment->clone(ht);
  92. new_loop->counter = counter;
  93. foreach_iter(exec_list_iterator, iter, this->body_instructions) {
  94. ir_instruction *ir = (ir_instruction *)iter.get();
  95. new_loop->body_instructions.push_tail(ir->clone(ht));
  96. }
  97. return new_loop;
  98. }
  99. ir_instruction *
  100. ir_call::clone(struct hash_table *ht) const
  101. {
  102. exec_list new_parameters;
  103. foreach_iter(exec_list_iterator, iter, this->actual_parameters) {
  104. ir_instruction *ir = (ir_instruction *)iter.get();
  105. new_parameters.push_tail(ir->clone(ht));
  106. }
  107. return new ir_call(this->callee, &new_parameters);
  108. }
  109. ir_instruction *
  110. ir_expression::clone(struct hash_table *ht) const
  111. {
  112. ir_rvalue *op[2] = {NULL, NULL};
  113. unsigned int i;
  114. for (i = 0; i < get_num_operands(); i++) {
  115. op[i] = (ir_rvalue *)this->operands[i]->clone(ht);
  116. }
  117. return new ir_expression(this->operation, this->type, op[0], op[1]);
  118. }
  119. ir_instruction *
  120. ir_dereference_variable::clone(struct hash_table *ht) const
  121. {
  122. ir_variable *new_var;
  123. if (ht) {
  124. new_var = (ir_variable *)hash_table_find(ht, this->var);
  125. if (!new_var)
  126. new_var = this->var;
  127. } else {
  128. new_var = this->var;
  129. }
  130. return new ir_dereference_variable(new_var);
  131. }
  132. ir_instruction *
  133. ir_dereference_array::clone(struct hash_table *ht) const
  134. {
  135. return new ir_dereference_array((ir_rvalue *)this->array->clone(ht),
  136. (ir_rvalue *)this->array_index->clone(ht));
  137. }
  138. ir_instruction *
  139. ir_dereference_record::clone(struct hash_table *ht) const
  140. {
  141. return new ir_dereference_record((ir_rvalue *)this->record->clone(ht),
  142. this->field);
  143. }
  144. ir_instruction *
  145. ir_texture::clone(struct hash_table *ht) const
  146. {
  147. ir_texture *new_tex = new ir_texture(this->op);
  148. new_tex->sampler = (ir_dereference *)this->sampler->clone(ht);
  149. new_tex->coordinate = (ir_rvalue *)this->coordinate->clone(ht);
  150. if (this->projector)
  151. new_tex->projector = (ir_rvalue *)this->projector->clone(ht);
  152. if (this->shadow_comparitor) {
  153. new_tex->shadow_comparitor =
  154. (ir_rvalue *)this->shadow_comparitor->clone(ht);
  155. }
  156. for (int i = 0; i < 3; i++)
  157. new_tex->offsets[i] = this->offsets[i];
  158. switch (this->op) {
  159. case ir_tex:
  160. break;
  161. case ir_txb:
  162. new_tex->lod_info.bias = (ir_rvalue *)this->lod_info.bias->clone(ht);
  163. break;
  164. case ir_txl:
  165. case ir_txf:
  166. new_tex->lod_info.lod = (ir_rvalue *)this->lod_info.lod->clone(ht);
  167. break;
  168. case ir_txd:
  169. new_tex->lod_info.grad.dPdx =
  170. (ir_rvalue *)this->lod_info.grad.dPdx->clone(ht);
  171. new_tex->lod_info.grad.dPdy =
  172. (ir_rvalue *)this->lod_info.grad.dPdy->clone(ht);
  173. break;
  174. }
  175. return new_tex;
  176. }
  177. ir_instruction *
  178. ir_assignment::clone(struct hash_table *ht) const
  179. {
  180. ir_rvalue *new_condition = NULL;
  181. if (this->condition)
  182. new_condition = (ir_rvalue *)this->condition->clone(ht);
  183. return new ir_assignment((ir_rvalue *)this->lhs->clone(ht),
  184. (ir_rvalue *)this->rhs->clone(ht),
  185. new_condition);
  186. }
  187. ir_instruction *
  188. ir_function::clone(struct hash_table *ht) const
  189. {
  190. (void)ht;
  191. /* FINISHME */
  192. abort();
  193. }
  194. ir_instruction *
  195. ir_function_signature::clone(struct hash_table *ht) const
  196. {
  197. (void)ht;
  198. /* FINISHME */
  199. abort();
  200. }
  201. ir_instruction *
  202. ir_constant::clone(struct hash_table *ht) const
  203. {
  204. (void)ht;
  205. switch (this->type->base_type) {
  206. case GLSL_TYPE_UINT:
  207. case GLSL_TYPE_INT:
  208. case GLSL_TYPE_FLOAT:
  209. case GLSL_TYPE_BOOL:
  210. return new ir_constant(this->type, &this->value);
  211. case GLSL_TYPE_STRUCT: {
  212. ir_constant *c = new ir_constant;
  213. c->type = this->type;
  214. for (exec_node *node = this->components.head
  215. ; !node->is_tail_sentinal()
  216. ; node = node->next) {
  217. ir_constant *const orig = (ir_constant *) node;
  218. c->components.push_tail(orig->clone(NULL));
  219. }
  220. return c;
  221. }
  222. default:
  223. assert(!"Should not get here."); break;
  224. return NULL;
  225. }
  226. }