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_hv_accept.cpp 8.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  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 "ir.h"
  24. /**
  25. * \file ir_hv_accept.cpp
  26. * Implementations of all hierarchical visitor accept methods for IR
  27. * instructions.
  28. */
  29. /**
  30. * Process a list of nodes using a hierarchical vistor
  31. *
  32. * \warning
  33. * This function will operate correctly if a node being processed is removed
  34. * from list. However, if nodes are added to the list after the node being
  35. * processed, some of the added noded may not be processed.
  36. */
  37. static ir_visitor_status
  38. visit_list_elements(ir_hierarchical_visitor *v, exec_list *l)
  39. {
  40. exec_node *next;
  41. for (exec_node *n = l->head; n->next != NULL; n = next) {
  42. next = n->next;
  43. ir_instruction *const ir = (ir_instruction *) n;
  44. ir_visitor_status s = ir->accept(v);
  45. if (s != visit_continue)
  46. return s;
  47. }
  48. return visit_continue;
  49. }
  50. ir_visitor_status
  51. ir_variable::accept(ir_hierarchical_visitor *v)
  52. {
  53. return v->visit(this);
  54. }
  55. ir_visitor_status
  56. ir_loop::accept(ir_hierarchical_visitor *v)
  57. {
  58. ir_visitor_status s = v->visit_enter(this);
  59. if (s != visit_continue)
  60. return (s == visit_continue_with_parent) ? visit_continue : s;
  61. s = visit_list_elements(v, &this->body_instructions);
  62. if (s == visit_stop)
  63. return s;
  64. if (s != visit_continue_with_parent) {
  65. if (this->from) {
  66. s = this->from->accept(v);
  67. if (s != visit_continue)
  68. return (s == visit_continue_with_parent) ? visit_continue : s;
  69. }
  70. if (this->to) {
  71. s = this->to->accept(v);
  72. if (s != visit_continue)
  73. return (s == visit_continue_with_parent) ? visit_continue : s;
  74. }
  75. if (this->increment) {
  76. s = this->increment->accept(v);
  77. if (s != visit_continue)
  78. return (s == visit_continue_with_parent) ? visit_continue : s;
  79. }
  80. }
  81. return v->visit_leave(this);
  82. }
  83. ir_visitor_status
  84. ir_loop_jump::accept(ir_hierarchical_visitor *v)
  85. {
  86. return v->visit(this);
  87. }
  88. ir_visitor_status
  89. ir_function_signature::accept(ir_hierarchical_visitor *v)
  90. {
  91. ir_visitor_status s = v->visit_enter(this);
  92. if (s != visit_continue)
  93. return (s == visit_continue_with_parent) ? visit_continue : s;
  94. s = visit_list_elements(v, &this->body);
  95. return (s == visit_stop) ? s : v->visit_leave(this);
  96. }
  97. ir_visitor_status
  98. ir_function::accept(ir_hierarchical_visitor *v)
  99. {
  100. ir_visitor_status s = v->visit_enter(this);
  101. if (s != visit_continue)
  102. return (s == visit_continue_with_parent) ? visit_continue : s;
  103. s = visit_list_elements(v, &this->signatures);
  104. return (s == visit_stop) ? s : v->visit_leave(this);
  105. }
  106. ir_visitor_status
  107. ir_expression::accept(ir_hierarchical_visitor *v)
  108. {
  109. ir_visitor_status s = v->visit_enter(this);
  110. if (s != visit_continue)
  111. return (s == visit_continue_with_parent) ? visit_continue : s;
  112. for (unsigned i = 0; i < this->get_num_operands(); i++) {
  113. switch (this->operands[i]->accept(v)) {
  114. case visit_continue:
  115. break;
  116. case visit_continue_with_parent:
  117. // I wish for Java's labeled break-statement here.
  118. goto done;
  119. case visit_stop:
  120. return s;
  121. }
  122. }
  123. done:
  124. return v->visit_leave(this);
  125. }
  126. ir_visitor_status
  127. ir_texture::accept(ir_hierarchical_visitor *v)
  128. {
  129. ir_visitor_status s = v->visit_enter(this);
  130. if (s != visit_continue)
  131. return (s == visit_continue_with_parent) ? visit_continue : s;
  132. s = this->sampler->accept(v);
  133. if (s != visit_continue)
  134. return (s == visit_continue_with_parent) ? visit_continue : s;
  135. s = this->coordinate->accept(v);
  136. if (s != visit_continue)
  137. return (s == visit_continue_with_parent) ? visit_continue : s;
  138. if (this->projector) {
  139. s = this->projector->accept(v);
  140. if (s != visit_continue)
  141. return (s == visit_continue_with_parent) ? visit_continue : s;
  142. }
  143. if (this->shadow_comparitor) {
  144. s = this->shadow_comparitor->accept(v);
  145. if (s != visit_continue)
  146. return (s == visit_continue_with_parent) ? visit_continue : s;
  147. }
  148. switch (this->op) {
  149. case ir_tex:
  150. break;
  151. case ir_txb:
  152. s = this->lod_info.bias->accept(v);
  153. if (s != visit_continue)
  154. return (s == visit_continue_with_parent) ? visit_continue : s;
  155. break;
  156. case ir_txl:
  157. case ir_txf:
  158. s = this->lod_info.lod->accept(v);
  159. if (s != visit_continue)
  160. return (s == visit_continue_with_parent) ? visit_continue : s;
  161. break;
  162. case ir_txd:
  163. s = this->lod_info.grad.dPdx->accept(v);
  164. if (s != visit_continue)
  165. return (s == visit_continue_with_parent) ? visit_continue : s;
  166. s = this->lod_info.grad.dPdy->accept(v);
  167. if (s != visit_continue)
  168. return (s == visit_continue_with_parent) ? visit_continue : s;
  169. break;
  170. }
  171. return visit_continue_with_parent;
  172. }
  173. ir_visitor_status
  174. ir_swizzle::accept(ir_hierarchical_visitor *v)
  175. {
  176. ir_visitor_status s = v->visit_enter(this);
  177. if (s != visit_continue)
  178. return (s == visit_continue_with_parent) ? visit_continue : s;
  179. s = this->val->accept(v);
  180. return (s == visit_stop) ? s : v->visit_leave(this);
  181. }
  182. ir_visitor_status
  183. ir_dereference_variable::accept(ir_hierarchical_visitor *v)
  184. {
  185. return v->visit(this);
  186. }
  187. ir_visitor_status
  188. ir_dereference_array::accept(ir_hierarchical_visitor *v)
  189. {
  190. ir_visitor_status s = v->visit_enter(this);
  191. if (s != visit_continue)
  192. return (s == visit_continue_with_parent) ? visit_continue : s;
  193. s = this->array_index->accept(v);
  194. if (s != visit_continue)
  195. return (s == visit_continue_with_parent) ? visit_continue : s;
  196. s = this->array->accept(v);
  197. return (s == visit_stop) ? s : v->visit_leave(this);
  198. }
  199. ir_visitor_status
  200. ir_dereference_record::accept(ir_hierarchical_visitor *v)
  201. {
  202. ir_visitor_status s = v->visit_enter(this);
  203. if (s != visit_continue)
  204. return (s == visit_continue_with_parent) ? visit_continue : s;
  205. s = this->record->accept(v);
  206. return (s == visit_stop) ? s : v->visit_leave(this);
  207. }
  208. ir_visitor_status
  209. ir_assignment::accept(ir_hierarchical_visitor *v)
  210. {
  211. ir_visitor_status s = v->visit_enter(this);
  212. if (s != visit_continue)
  213. return (s == visit_continue_with_parent) ? visit_continue : s;
  214. s = this->lhs->accept(v);
  215. if (s != visit_continue)
  216. return (s == visit_continue_with_parent) ? visit_continue : s;
  217. s = this->rhs->accept(v);
  218. if (s != visit_continue)
  219. return (s == visit_continue_with_parent) ? visit_continue : s;
  220. if (this->condition)
  221. s = this->condition->accept(v);
  222. return (s == visit_stop) ? s : v->visit_leave(this);
  223. }
  224. ir_visitor_status
  225. ir_constant::accept(ir_hierarchical_visitor *v)
  226. {
  227. return v->visit(this);
  228. }
  229. ir_visitor_status
  230. ir_call::accept(ir_hierarchical_visitor *v)
  231. {
  232. ir_visitor_status s = v->visit_enter(this);
  233. if (s != visit_continue)
  234. return (s == visit_continue_with_parent) ? visit_continue : s;
  235. s = visit_list_elements(v, &this->actual_parameters);
  236. if (s == visit_stop)
  237. return s;
  238. return v->visit_leave(this);
  239. }
  240. ir_visitor_status
  241. ir_return::accept(ir_hierarchical_visitor *v)
  242. {
  243. ir_visitor_status s = v->visit_enter(this);
  244. if (s != visit_continue)
  245. return (s == visit_continue_with_parent) ? visit_continue : s;
  246. ir_rvalue *val = this->get_value();
  247. if (val) {
  248. s = val->accept(v);
  249. if (s != visit_continue)
  250. return (s == visit_continue_with_parent) ? visit_continue : s;
  251. }
  252. return v->visit_leave(this);
  253. }
  254. ir_visitor_status
  255. ir_if::accept(ir_hierarchical_visitor *v)
  256. {
  257. ir_visitor_status s = v->visit_enter(this);
  258. if (s != visit_continue)
  259. return (s == visit_continue_with_parent) ? visit_continue : s;
  260. s = this->condition->accept(v);
  261. if (s != visit_continue)
  262. return (s == visit_continue_with_parent) ? visit_continue : s;
  263. if (s != visit_continue_with_parent) {
  264. s = visit_list_elements(v, &this->then_instructions);
  265. if (s == visit_stop)
  266. return s;
  267. }
  268. if (s != visit_continue_with_parent) {
  269. s = visit_list_elements(v, &this->else_instructions);
  270. if (s == visit_stop)
  271. return s;
  272. }
  273. return v->visit_leave(this);
  274. }