GIMPLE.html 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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: GIMPLE</title>
  20. <meta name="description" content="GNU Compiler Collection (GCC) Internals: GIMPLE">
  21. <meta name="keywords" content="GNU Compiler Collection (GCC) Internals: GIMPLE">
  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="index.html#Top" rel="up" title="Top">
  30. <link href="Tuple-representation.html#Tuple-representation" rel="next" title="Tuple representation">
  31. <link href="Java-Trees.html#Java-Trees" rel="prev" title="Java Trees">
  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="GIMPLE"></a>
  63. <div class="header">
  64. <p>
  65. Next: <a href="Tree-SSA.html#Tree-SSA" accesskey="n" rel="next">Tree SSA</a>, Previous: <a href="GENERIC.html#GENERIC" accesskey="p" rel="prev">GENERIC</a>, Up: <a href="index.html#Top" accesskey="u" rel="up">Top</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="GIMPLE-1"></a>
  69. <h2 class="chapter">11 GIMPLE</h2>
  70. <a name="index-GIMPLE-2"></a>
  71. <p>GIMPLE is a three-address representation derived from GENERIC by
  72. breaking down GENERIC expressions into tuples of no more than 3
  73. operands (with some exceptions like function calls). GIMPLE was
  74. heavily influenced by the SIMPLE IL used by the McCAT compiler
  75. project at McGill University, though we have made some different
  76. choices. For one thing, SIMPLE doesn&rsquo;t support <code>goto</code>.
  77. </p>
  78. <p>Temporaries are introduced to hold intermediate values needed to
  79. compute complex expressions. Additionally, all the control
  80. structures used in GENERIC are lowered into conditional jumps,
  81. lexical scopes are removed and exception regions are converted
  82. into an on the side exception region tree.
  83. </p>
  84. <p>The compiler pass which converts GENERIC into GIMPLE is referred to as
  85. the &lsquo;<samp>gimplifier</samp>&rsquo;. The gimplifier works recursively, generating
  86. GIMPLE tuples out of the original GENERIC expressions.
  87. </p>
  88. <p>One of the early implementation strategies used for the GIMPLE
  89. representation was to use the same internal data structures used
  90. by front ends to represent parse trees. This simplified
  91. implementation because we could leverage existing functionality
  92. and interfaces. However, GIMPLE is a much more restrictive
  93. representation than abstract syntax trees (AST), therefore it
  94. does not require the full structural complexity provided by the
  95. main tree data structure.
  96. </p>
  97. <p>The GENERIC representation of a function is stored in the
  98. <code>DECL_SAVED_TREE</code> field of the associated <code>FUNCTION_DECL</code>
  99. tree node. It is converted to GIMPLE by a call to
  100. <code>gimplify_function_tree</code>.
  101. </p>
  102. <p>If a front end wants to include language-specific tree codes in the tree
  103. representation which it provides to the back end, it must provide a
  104. definition of <code>LANG_HOOKS_GIMPLIFY_EXPR</code> which knows how to
  105. convert the front end trees to GIMPLE. Usually such a hook will involve
  106. much of the same code for expanding front end trees to RTL. This function
  107. can return fully lowered GIMPLE, or it can return GENERIC trees and let the
  108. main gimplifier lower them the rest of the way; this is often simpler.
  109. GIMPLE that is not fully lowered is known as &ldquo;High GIMPLE&rdquo; and
  110. consists of the IL before the pass <code>pass_lower_cf</code>. High GIMPLE
  111. contains some container statements like lexical scopes
  112. (represented by <code>GIMPLE_BIND</code>) and nested expressions (e.g.,
  113. <code>GIMPLE_TRY</code>), while &ldquo;Low GIMPLE&rdquo; exposes all of the
  114. implicit jumps for control and exception expressions directly in
  115. the IL and EH region trees.
  116. </p>
  117. <p>The C and C++ front ends currently convert directly from front end
  118. trees to GIMPLE, and hand that off to the back end rather than first
  119. converting to GENERIC. Their gimplifier hooks know about all the
  120. <code>_STMT</code> nodes and how to convert them to GENERIC forms. There
  121. was some work done on a genericization pass which would run first, but
  122. the existence of <code>STMT_EXPR</code> meant that in order to convert all
  123. of the C statements into GENERIC equivalents would involve walking the
  124. entire tree anyway, so it was simpler to lower all the way. This
  125. might change in the future if someone writes an optimization pass
  126. which would work better with higher-level trees, but currently the
  127. optimizers all expect GIMPLE.
  128. </p>
  129. <p>You can request to dump a C-like representation of the GIMPLE form
  130. with the flag <samp>-fdump-tree-gimple</samp>.
  131. </p>
  132. <table class="menu" border="0" cellspacing="0">
  133. <tr><td align="left" valign="top">&bull; <a href="Tuple-representation.html#Tuple-representation" accesskey="1">Tuple representation</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
  134. </td></tr>
  135. <tr><td align="left" valign="top">&bull; <a href="Class-hierarchy-of-GIMPLE-statements.html#Class-hierarchy-of-GIMPLE-statements" accesskey="2">Class hierarchy of GIMPLE statements</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
  136. </td></tr>
  137. <tr><td align="left" valign="top">&bull; <a href="GIMPLE-instruction-set.html#GIMPLE-instruction-set" accesskey="3">GIMPLE instruction set</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
  138. </td></tr>
  139. <tr><td align="left" valign="top">&bull; <a href="GIMPLE-Exception-Handling.html#GIMPLE-Exception-Handling" accesskey="4">GIMPLE Exception Handling</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
  140. </td></tr>
  141. <tr><td align="left" valign="top">&bull; <a href="Temporaries.html#Temporaries" accesskey="5">Temporaries</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
  142. </td></tr>
  143. <tr><td align="left" valign="top">&bull; <a href="Operands.html#Operands" accesskey="6">Operands</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
  144. </td></tr>
  145. <tr><td align="left" valign="top">&bull; <a href="Manipulating-GIMPLE-statements.html#Manipulating-GIMPLE-statements" accesskey="7">Manipulating GIMPLE statements</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
  146. </td></tr>
  147. <tr><td align="left" valign="top">&bull; <a href="Tuple-specific-accessors.html#Tuple-specific-accessors" accesskey="8">Tuple specific accessors</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
  148. </td></tr>
  149. <tr><td align="left" valign="top">&bull; <a href="GIMPLE-sequences.html#GIMPLE-sequences" accesskey="9">GIMPLE sequences</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
  150. </td></tr>
  151. <tr><td align="left" valign="top">&bull; <a href="Sequence-iterators.html#Sequence-iterators">Sequence iterators</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
  152. </td></tr>
  153. <tr><td align="left" valign="top">&bull; <a href="Adding-a-new-GIMPLE-statement-code.html#Adding-a-new-GIMPLE-statement-code">Adding a new GIMPLE statement code</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
  154. </td></tr>
  155. <tr><td align="left" valign="top">&bull; <a href="Statement-and-operand-traversals.html#Statement-and-operand-traversals">Statement and operand traversals</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
  156. </td></tr>
  157. </table>
  158. <hr>
  159. <div class="header">
  160. <p>
  161. Next: <a href="Tree-SSA.html#Tree-SSA" accesskey="n" rel="next">Tree SSA</a>, Previous: <a href="GENERIC.html#GENERIC" accesskey="p" rel="prev">GENERIC</a>, Up: <a href="index.html#Top" accesskey="u" rel="up">Top</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>
  162. </div>
  163. </body>
  164. </html>