Sequence-iterators.html 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <!-- Copyright (C) 1988-2017 Free Software Foundation, Inc.
  4. Permission is granted to copy, distribute and/or modify this document
  5. under the terms of the GNU Free Documentation License, Version 1.3 or
  6. any later version published by the Free Software Foundation; with the
  7. Invariant Sections being "Funding Free Software", the Front-Cover
  8. Texts being (a) (see below), and with the Back-Cover Texts being (b)
  9. (see below). A copy of the license is included in the section entitled
  10. "GNU Free Documentation License".
  11. (a) The FSF's Front-Cover Text is:
  12. A GNU Manual
  13. (b) The FSF's Back-Cover Text is:
  14. You have freedom to copy and modify this GNU Manual, like GNU
  15. software. Copies published by the Free Software Foundation raise
  16. funds for GNU development. -->
  17. <!-- Created by GNU Texinfo 5.2, http://www.gnu.org/software/texinfo/ -->
  18. <head>
  19. <title>GNU Compiler Collection (GCC) Internals: Sequence iterators</title>
  20. <meta name="description" content="GNU Compiler Collection (GCC) Internals: Sequence iterators">
  21. <meta name="keywords" content="GNU Compiler Collection (GCC) Internals: Sequence iterators">
  22. <meta name="resource-type" content="document">
  23. <meta name="distribution" content="global">
  24. <meta name="Generator" content="makeinfo">
  25. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  26. <link href="index.html#Top" rel="start" title="Top">
  27. <link href="Option-Index.html#Option-Index" rel="index" title="Option Index">
  28. <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
  29. <link href="GIMPLE.html#GIMPLE" rel="up" title="GIMPLE">
  30. <link href="Adding-a-new-GIMPLE-statement-code.html#Adding-a-new-GIMPLE-statement-code" rel="next" title="Adding a new GIMPLE statement code">
  31. <link href="GIMPLE-sequences.html#GIMPLE-sequences" rel="prev" title="GIMPLE sequences">
  32. <style type="text/css">
  33. <!--
  34. a.summary-letter {text-decoration: none}
  35. blockquote.smallquotation {font-size: smaller}
  36. div.display {margin-left: 3.2em}
  37. div.example {margin-left: 3.2em}
  38. div.indentedblock {margin-left: 3.2em}
  39. div.lisp {margin-left: 3.2em}
  40. div.smalldisplay {margin-left: 3.2em}
  41. div.smallexample {margin-left: 3.2em}
  42. div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
  43. div.smalllisp {margin-left: 3.2em}
  44. kbd {font-style:oblique}
  45. pre.display {font-family: inherit}
  46. pre.format {font-family: inherit}
  47. pre.menu-comment {font-family: serif}
  48. pre.menu-preformatted {font-family: serif}
  49. pre.smalldisplay {font-family: inherit; font-size: smaller}
  50. pre.smallexample {font-size: smaller}
  51. pre.smallformat {font-family: inherit; font-size: smaller}
  52. pre.smalllisp {font-size: smaller}
  53. span.nocodebreak {white-space:nowrap}
  54. span.nolinebreak {white-space:nowrap}
  55. span.roman {font-family:serif; font-weight:normal}
  56. span.sansserif {font-family:sans-serif; font-weight:normal}
  57. ul.no-bullet {list-style: none}
  58. -->
  59. </style>
  60. </head>
  61. <body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
  62. <a name="Sequence-iterators"></a>
  63. <div class="header">
  64. <p>
  65. Next: <a href="Adding-a-new-GIMPLE-statement-code.html#Adding-a-new-GIMPLE-statement-code" accesskey="n" rel="next">Adding a new GIMPLE statement code</a>, Previous: <a href="GIMPLE-sequences.html#GIMPLE-sequences" accesskey="p" rel="prev">GIMPLE sequences</a>, Up: <a href="GIMPLE.html#GIMPLE" accesskey="u" rel="up">GIMPLE</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html#Option-Index" title="Index" rel="index">Index</a>]</p>
  66. </div>
  67. <hr>
  68. <a name="Sequence-iterators-1"></a>
  69. <h3 class="section">11.10 Sequence iterators</h3>
  70. <a name="index-Sequence-iterators"></a>
  71. <p>Sequence iterators are convenience constructs for iterating
  72. through statements in a sequence. Given a sequence <code>SEQ</code>, here is
  73. a typical use of gimple sequence iterators:
  74. </p>
  75. <div class="smallexample">
  76. <pre class="smallexample">gimple_stmt_iterator gsi;
  77. for (gsi = gsi_start (seq); !gsi_end_p (gsi); gsi_next (&amp;gsi))
  78. {
  79. gimple g = gsi_stmt (gsi);
  80. /* Do something with gimple statement <code>G</code>. */
  81. }
  82. </pre></div>
  83. <p>Backward iterations are possible:
  84. </p>
  85. <div class="smallexample">
  86. <pre class="smallexample"> for (gsi = gsi_last (seq); !gsi_end_p (gsi); gsi_prev (&amp;gsi))
  87. </pre></div>
  88. <p>Forward and backward iterations on basic blocks are possible with
  89. <code>gsi_start_bb</code> and <code>gsi_last_bb</code>.
  90. </p>
  91. <p>In the documentation below we sometimes refer to enum
  92. <code>gsi_iterator_update</code>. The valid options for this enumeration are:
  93. </p>
  94. <ul>
  95. <li> <code>GSI_NEW_STMT</code>
  96. Only valid when a single statement is added. Move the iterator to it.
  97. </li><li> <code>GSI_SAME_STMT</code>
  98. Leave the iterator at the same statement.
  99. </li><li> <code>GSI_CONTINUE_LINKING</code>
  100. Move iterator to whatever position is suitable for linking other
  101. statements in the same direction.
  102. </li></ul>
  103. <p>Below is a list of the functions used to manipulate and use
  104. statement iterators.
  105. </p>
  106. <dl>
  107. <dt><a name="index-gsi_005fstart"></a>GIMPLE function: <em>gimple_stmt_iterator</em> <strong>gsi_start</strong> <em>(gimple_seq seq)</em></dt>
  108. <dd><p>Return a new iterator pointing to the sequence <code>SEQ</code>&rsquo;s first
  109. statement. If <code>SEQ</code> is empty, the iterator&rsquo;s basic block is <code>NULL</code>.
  110. Use <code>gsi_start_bb</code> instead when the iterator needs to always have
  111. the correct basic block set.
  112. </p></dd></dl>
  113. <dl>
  114. <dt><a name="index-gsi_005fstart_005fbb"></a>GIMPLE function: <em>gimple_stmt_iterator</em> <strong>gsi_start_bb</strong> <em>(basic_block bb)</em></dt>
  115. <dd><p>Return a new iterator pointing to the first statement in basic
  116. block <code>BB</code>.
  117. </p></dd></dl>
  118. <dl>
  119. <dt><a name="index-gsi_005flast"></a>GIMPLE function: <em>gimple_stmt_iterator</em> <strong>gsi_last</strong> <em>(gimple_seq seq)</em></dt>
  120. <dd><p>Return a new iterator initially pointing to the last statement of
  121. sequence <code>SEQ</code>. If <code>SEQ</code> is empty, the iterator&rsquo;s basic block is
  122. <code>NULL</code>. Use <code>gsi_last_bb</code> instead when the iterator needs to always
  123. have the correct basic block set.
  124. </p></dd></dl>
  125. <dl>
  126. <dt><a name="index-gsi_005flast_005fbb"></a>GIMPLE function: <em>gimple_stmt_iterator</em> <strong>gsi_last_bb</strong> <em>(basic_block bb)</em></dt>
  127. <dd><p>Return a new iterator pointing to the last statement in basic
  128. block <code>BB</code>.
  129. </p></dd></dl>
  130. <dl>
  131. <dt><a name="index-gsi_005fend_005fp"></a>GIMPLE function: <em>bool</em> <strong>gsi_end_p</strong> <em>(gimple_stmt_iterator i)</em></dt>
  132. <dd><p>Return <code>TRUE</code> if at the end of <code>I</code>.
  133. </p></dd></dl>
  134. <dl>
  135. <dt><a name="index-gsi_005fone_005fbefore_005fend_005fp"></a>GIMPLE function: <em>bool</em> <strong>gsi_one_before_end_p</strong> <em>(gimple_stmt_iterator i)</em></dt>
  136. <dd><p>Return <code>TRUE</code> if we&rsquo;re one statement before the end of <code>I</code>.
  137. </p></dd></dl>
  138. <dl>
  139. <dt><a name="index-gsi_005fnext"></a>GIMPLE function: <em>void</em> <strong>gsi_next</strong> <em>(gimple_stmt_iterator *i)</em></dt>
  140. <dd><p>Advance the iterator to the next gimple statement.
  141. </p></dd></dl>
  142. <dl>
  143. <dt><a name="index-gsi_005fprev"></a>GIMPLE function: <em>void</em> <strong>gsi_prev</strong> <em>(gimple_stmt_iterator *i)</em></dt>
  144. <dd><p>Advance the iterator to the previous gimple statement.
  145. </p></dd></dl>
  146. <dl>
  147. <dt><a name="index-gsi_005fstmt"></a>GIMPLE function: <em>gimple</em> <strong>gsi_stmt</strong> <em>(gimple_stmt_iterator i)</em></dt>
  148. <dd><p>Return the current stmt.
  149. </p></dd></dl>
  150. <dl>
  151. <dt><a name="index-gsi_005fafter_005flabels"></a>GIMPLE function: <em>gimple_stmt_iterator</em> <strong>gsi_after_labels</strong> <em>(basic_block bb)</em></dt>
  152. <dd><p>Return a block statement iterator that points to the first
  153. non-label statement in block <code>BB</code>.
  154. </p></dd></dl>
  155. <dl>
  156. <dt><a name="index-gsi_005fstmt_005fptr"></a>GIMPLE function: <em>gimple *</em> <strong>gsi_stmt_ptr</strong> <em>(gimple_stmt_iterator *i)</em></dt>
  157. <dd><p>Return a pointer to the current stmt.
  158. </p></dd></dl>
  159. <dl>
  160. <dt><a name="index-gsi_005fbb"></a>GIMPLE function: <em>basic_block</em> <strong>gsi_bb</strong> <em>(gimple_stmt_iterator i)</em></dt>
  161. <dd><p>Return the basic block associated with this iterator.
  162. </p></dd></dl>
  163. <dl>
  164. <dt><a name="index-gsi_005fseq"></a>GIMPLE function: <em>gimple_seq</em> <strong>gsi_seq</strong> <em>(gimple_stmt_iterator i)</em></dt>
  165. <dd><p>Return the sequence associated with this iterator.
  166. </p></dd></dl>
  167. <dl>
  168. <dt><a name="index-gsi_005fremove"></a>GIMPLE function: <em>void</em> <strong>gsi_remove</strong> <em>(gimple_stmt_iterator *i, bool remove_eh_info)</em></dt>
  169. <dd><p>Remove the current stmt from the sequence. The iterator is
  170. updated to point to the next statement. When <code>REMOVE_EH_INFO</code> is
  171. true we remove the statement pointed to by iterator <code>I</code> from the <code>EH</code>
  172. tables. Otherwise we do not modify the <code>EH</code> tables. Generally,
  173. <code>REMOVE_EH_INFO</code> should be true when the statement is going to be
  174. removed from the <code>IL</code> and not reinserted elsewhere.
  175. </p></dd></dl>
  176. <dl>
  177. <dt><a name="index-gsi_005flink_005fseq_005fbefore"></a>GIMPLE function: <em>void</em> <strong>gsi_link_seq_before</strong> <em>(gimple_stmt_iterator *i, gimple_seq seq, enum gsi_iterator_update mode)</em></dt>
  178. <dd><p>Links the sequence of statements <code>SEQ</code> before the statement pointed
  179. by iterator <code>I</code>. <code>MODE</code> indicates what to do with the iterator
  180. after insertion (see <code>enum gsi_iterator_update</code> above).
  181. </p></dd></dl>
  182. <dl>
  183. <dt><a name="index-gsi_005flink_005fbefore"></a>GIMPLE function: <em>void</em> <strong>gsi_link_before</strong> <em>(gimple_stmt_iterator *i, gimple g, enum gsi_iterator_update mode)</em></dt>
  184. <dd><p>Links statement <code>G</code> before the statement pointed-to by iterator <code>I</code>.
  185. Updates iterator <code>I</code> according to <code>MODE</code>.
  186. </p></dd></dl>
  187. <dl>
  188. <dt><a name="index-gsi_005flink_005fseq_005fafter"></a>GIMPLE function: <em>void</em> <strong>gsi_link_seq_after</strong> <em>(gimple_stmt_iterator *i, gimple_seq seq, enum gsi_iterator_update mode)</em></dt>
  189. <dd><p>Links sequence <code>SEQ</code> after the statement pointed-to by iterator <code>I</code>.
  190. <code>MODE</code> is as in <code>gsi_insert_after</code>.
  191. </p></dd></dl>
  192. <dl>
  193. <dt><a name="index-gsi_005flink_005fafter"></a>GIMPLE function: <em>void</em> <strong>gsi_link_after</strong> <em>(gimple_stmt_iterator *i, gimple g, enum gsi_iterator_update mode)</em></dt>
  194. <dd><p>Links statement <code>G</code> after the statement pointed-to by iterator <code>I</code>.
  195. <code>MODE</code> is as in <code>gsi_insert_after</code>.
  196. </p></dd></dl>
  197. <dl>
  198. <dt><a name="index-gsi_005fsplit_005fseq_005fafter"></a>GIMPLE function: <em>gimple_seq</em> <strong>gsi_split_seq_after</strong> <em>(gimple_stmt_iterator i)</em></dt>
  199. <dd><p>Move all statements in the sequence after <code>I</code> to a new sequence.
  200. Return this new sequence.
  201. </p></dd></dl>
  202. <dl>
  203. <dt><a name="index-gsi_005fsplit_005fseq_005fbefore"></a>GIMPLE function: <em>gimple_seq</em> <strong>gsi_split_seq_before</strong> <em>(gimple_stmt_iterator *i)</em></dt>
  204. <dd><p>Move all statements in the sequence before <code>I</code> to a new sequence.
  205. Return this new sequence.
  206. </p></dd></dl>
  207. <dl>
  208. <dt><a name="index-gsi_005freplace"></a>GIMPLE function: <em>void</em> <strong>gsi_replace</strong> <em>(gimple_stmt_iterator *i, gimple stmt, bool update_eh_info)</em></dt>
  209. <dd><p>Replace the statement pointed-to by <code>I</code> to <code>STMT</code>. If <code>UPDATE_EH_INFO</code>
  210. is true, the exception handling information of the original
  211. statement is moved to the new statement.
  212. </p></dd></dl>
  213. <dl>
  214. <dt><a name="index-gsi_005finsert_005fbefore"></a>GIMPLE function: <em>void</em> <strong>gsi_insert_before</strong> <em>(gimple_stmt_iterator *i, gimple stmt, enum gsi_iterator_update mode)</em></dt>
  215. <dd><p>Insert statement <code>STMT</code> before the statement pointed-to by iterator
  216. <code>I</code>, update <code>STMT</code>&rsquo;s basic block and scan it for new operands. <code>MODE</code>
  217. specifies how to update iterator <code>I</code> after insertion (see enum
  218. <code>gsi_iterator_update</code>).
  219. </p></dd></dl>
  220. <dl>
  221. <dt><a name="index-gsi_005finsert_005fseq_005fbefore"></a>GIMPLE function: <em>void</em> <strong>gsi_insert_seq_before</strong> <em>(gimple_stmt_iterator *i, gimple_seq seq, enum gsi_iterator_update mode)</em></dt>
  222. <dd><p>Like <code>gsi_insert_before</code>, but for all the statements in <code>SEQ</code>.
  223. </p></dd></dl>
  224. <dl>
  225. <dt><a name="index-gsi_005finsert_005fafter"></a>GIMPLE function: <em>void</em> <strong>gsi_insert_after</strong> <em>(gimple_stmt_iterator *i, gimple stmt, enum gsi_iterator_update mode)</em></dt>
  226. <dd><p>Insert statement <code>STMT</code> after the statement pointed-to by iterator
  227. <code>I</code>, update <code>STMT</code>&rsquo;s basic block and scan it for new operands. <code>MODE</code>
  228. specifies how to update iterator <code>I</code> after insertion (see enum
  229. <code>gsi_iterator_update</code>).
  230. </p></dd></dl>
  231. <dl>
  232. <dt><a name="index-gsi_005finsert_005fseq_005fafter"></a>GIMPLE function: <em>void</em> <strong>gsi_insert_seq_after</strong> <em>(gimple_stmt_iterator *i, gimple_seq seq, enum gsi_iterator_update mode)</em></dt>
  233. <dd><p>Like <code>gsi_insert_after</code>, but for all the statements in <code>SEQ</code>.
  234. </p></dd></dl>
  235. <dl>
  236. <dt><a name="index-gsi_005ffor_005fstmt"></a>GIMPLE function: <em>gimple_stmt_iterator</em> <strong>gsi_for_stmt</strong> <em>(gimple stmt)</em></dt>
  237. <dd><p>Finds iterator for <code>STMT</code>.
  238. </p></dd></dl>
  239. <dl>
  240. <dt><a name="index-gsi_005fmove_005fafter"></a>GIMPLE function: <em>void</em> <strong>gsi_move_after</strong> <em>(gimple_stmt_iterator *from, gimple_stmt_iterator *to)</em></dt>
  241. <dd><p>Move the statement at <code>FROM</code> so it comes right after the statement
  242. at <code>TO</code>.
  243. </p></dd></dl>
  244. <dl>
  245. <dt><a name="index-gsi_005fmove_005fbefore"></a>GIMPLE function: <em>void</em> <strong>gsi_move_before</strong> <em>(gimple_stmt_iterator *from, gimple_stmt_iterator *to)</em></dt>
  246. <dd><p>Move the statement at <code>FROM</code> so it comes right before the statement
  247. at <code>TO</code>.
  248. </p></dd></dl>
  249. <dl>
  250. <dt><a name="index-gsi_005fmove_005fto_005fbb_005fend"></a>GIMPLE function: <em>void</em> <strong>gsi_move_to_bb_end</strong> <em>(gimple_stmt_iterator *from, basic_block bb)</em></dt>
  251. <dd><p>Move the statement at <code>FROM</code> to the end of basic block <code>BB</code>.
  252. </p></dd></dl>
  253. <dl>
  254. <dt><a name="index-gsi_005finsert_005fon_005fedge"></a>GIMPLE function: <em>void</em> <strong>gsi_insert_on_edge</strong> <em>(edge e, gimple stmt)</em></dt>
  255. <dd><p>Add <code>STMT</code> to the pending list of edge <code>E</code>. No actual insertion is
  256. made until a call to <code>gsi_commit_edge_inserts</code>() is made.
  257. </p></dd></dl>
  258. <dl>
  259. <dt><a name="index-gsi_005finsert_005fseq_005fon_005fedge"></a>GIMPLE function: <em>void</em> <strong>gsi_insert_seq_on_edge</strong> <em>(edge e, gimple_seq seq)</em></dt>
  260. <dd><p>Add the sequence of statements in <code>SEQ</code> to the pending list of edge
  261. <code>E</code>. No actual insertion is made until a call to
  262. <code>gsi_commit_edge_inserts</code>() is made.
  263. </p></dd></dl>
  264. <dl>
  265. <dt><a name="index-gsi_005finsert_005fon_005fedge_005fimmediate"></a>GIMPLE function: <em>basic_block</em> <strong>gsi_insert_on_edge_immediate</strong> <em>(edge e, gimple stmt)</em></dt>
  266. <dd><p>Similar to <code>gsi_insert_on_edge</code>+<code>gsi_commit_edge_inserts</code>. If a new
  267. block has to be created, it is returned.
  268. </p></dd></dl>
  269. <dl>
  270. <dt><a name="index-gsi_005fcommit_005fone_005fedge_005finsert"></a>GIMPLE function: <em>void</em> <strong>gsi_commit_one_edge_insert</strong> <em>(edge e, basic_block *new_bb)</em></dt>
  271. <dd><p>Commit insertions pending at edge <code>E</code>. If a new block is created,
  272. set <code>NEW_BB</code> to this block, otherwise set it to <code>NULL</code>.
  273. </p></dd></dl>
  274. <dl>
  275. <dt><a name="index-gsi_005fcommit_005fedge_005finserts"></a>GIMPLE function: <em>void</em> <strong>gsi_commit_edge_inserts</strong> <em>(void)</em></dt>
  276. <dd><p>This routine will commit all pending edge insertions, creating
  277. any new basic blocks which are necessary.
  278. </p></dd></dl>
  279. <hr>
  280. <div class="header">
  281. <p>
  282. Next: <a href="Adding-a-new-GIMPLE-statement-code.html#Adding-a-new-GIMPLE-statement-code" accesskey="n" rel="next">Adding a new GIMPLE statement code</a>, Previous: <a href="GIMPLE-sequences.html#GIMPLE-sequences" accesskey="p" rel="prev">GIMPLE sequences</a>, Up: <a href="GIMPLE.html#GIMPLE" accesskey="u" rel="up">GIMPLE</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html#Option-Index" title="Index" rel="index">Index</a>]</p>
  283. </div>
  284. </body>
  285. </html>