Logical-Operators.html 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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: Logical Operators</title>
  20. <meta name="description" content="GNU Compiler Collection (GCC) Internals: Logical Operators">
  21. <meta name="keywords" content="GNU Compiler Collection (GCC) Internals: Logical Operators">
  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="Operands.html#Operands" rel="up" title="Operands">
  30. <link href="Manipulating-GIMPLE-statements.html#Manipulating-GIMPLE-statements" rel="next" title="Manipulating GIMPLE statements">
  31. <link href="Conditional-Expressions.html#Conditional-Expressions" rel="prev" title="Conditional Expressions">
  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="Logical-Operators"></a>
  63. <div class="header">
  64. <p>
  65. Previous: <a href="Conditional-Expressions.html#Conditional-Expressions" accesskey="p" rel="prev">Conditional Expressions</a>, Up: <a href="Operands.html#Operands" accesskey="u" rel="up">Operands</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="Logical-Operators-1"></a>
  69. <h4 class="subsection">11.6.4 Logical Operators</h4>
  70. <a name="index-Logical-Operators"></a>
  71. <p>Except when they appear in the condition operand of a
  72. <code>GIMPLE_COND</code>, logical &lsquo;and&rsquo; and &lsquo;or&rsquo; operators are simplified
  73. as follows: <code>a = b &amp;&amp; c</code> becomes
  74. </p>
  75. <div class="smallexample">
  76. <pre class="smallexample">T1 = (bool)b;
  77. if (T1 == true)
  78. T1 = (bool)c;
  79. a = T1;
  80. </pre></div>
  81. <p>Note that <code>T1</code> in this example cannot be an expression temporary,
  82. because it has two different assignments.
  83. </p>
  84. <a name="Manipulating-operands"></a>
  85. <h4 class="subsection">11.6.5 Manipulating operands</h4>
  86. <p>All gimple operands are of type <code>tree</code>. But only certain
  87. types of trees are allowed to be used as operand tuples. Basic
  88. validation is controlled by the function
  89. <code>get_gimple_rhs_class</code>, which given a tree code, returns an
  90. <code>enum</code> with the following values of type <code>enum
  91. gimple_rhs_class</code>
  92. </p>
  93. <ul>
  94. <li> <code>GIMPLE_INVALID_RHS</code>
  95. The tree cannot be used as a GIMPLE operand.
  96. </li><li> <code>GIMPLE_TERNARY_RHS</code>
  97. The tree is a valid GIMPLE ternary operation.
  98. </li><li> <code>GIMPLE_BINARY_RHS</code>
  99. The tree is a valid GIMPLE binary operation.
  100. </li><li> <code>GIMPLE_UNARY_RHS</code>
  101. The tree is a valid GIMPLE unary operation.
  102. </li><li> <code>GIMPLE_SINGLE_RHS</code>
  103. The tree is a single object, that cannot be split into simpler
  104. operands (for instance, <code>SSA_NAME</code>, <code>VAR_DECL</code>, <code>COMPONENT_REF</code>, etc).
  105. <p>This operand class also acts as an escape hatch for tree nodes
  106. that may be flattened out into the operand vector, but would need
  107. more than two slots on the RHS. For instance, a <code>COND_EXPR</code>
  108. expression of the form <code>(a op b) ? x : y</code> could be flattened
  109. out on the operand vector using 4 slots, but it would also
  110. require additional processing to distinguish <code>c = a op b</code>
  111. from <code>c = a op b ? x : y</code>. Something similar occurs with
  112. <code>ASSERT_EXPR</code>. In time, these special case tree
  113. expressions should be flattened into the operand vector.
  114. </p></li></ul>
  115. <p>For tree nodes in the categories <code>GIMPLE_TERNARY_RHS</code>,
  116. <code>GIMPLE_BINARY_RHS</code> and <code>GIMPLE_UNARY_RHS</code>, they cannot be
  117. stored inside tuples directly. They first need to be flattened and
  118. separated into individual components. For instance, given the GENERIC
  119. expression
  120. </p>
  121. <div class="smallexample">
  122. <pre class="smallexample">a = b + c
  123. </pre></div>
  124. <p>its tree representation is:
  125. </p>
  126. <div class="smallexample">
  127. <pre class="smallexample">MODIFY_EXPR &lt;VAR_DECL &lt;a&gt;, PLUS_EXPR &lt;VAR_DECL &lt;b&gt;, VAR_DECL &lt;c&gt;&gt;&gt;
  128. </pre></div>
  129. <p>In this case, the GIMPLE form for this statement is logically
  130. identical to its GENERIC form but in GIMPLE, the <code>PLUS_EXPR</code>
  131. on the RHS of the assignment is not represented as a tree,
  132. instead the two operands are taken out of the <code>PLUS_EXPR</code> sub-tree
  133. and flattened into the GIMPLE tuple as follows:
  134. </p>
  135. <div class="smallexample">
  136. <pre class="smallexample">GIMPLE_ASSIGN &lt;PLUS_EXPR, VAR_DECL &lt;a&gt;, VAR_DECL &lt;b&gt;, VAR_DECL &lt;c&gt;&gt;
  137. </pre></div>
  138. <a name="Operand-vector-allocation"></a>
  139. <h4 class="subsection">11.6.6 Operand vector allocation</h4>
  140. <p>The operand vector is stored at the bottom of the three tuple
  141. structures that accept operands. This means, that depending on
  142. the code of a given statement, its operand vector will be at
  143. different offsets from the base of the structure. To access
  144. tuple operands use the following accessors
  145. </p>
  146. <dl>
  147. <dt><a name="index-gimple_005fnum_005fops"></a>GIMPLE function: <em>unsigned</em> <strong>gimple_num_ops</strong> <em>(gimple g)</em></dt>
  148. <dd><p>Returns the number of operands in statement G.
  149. </p></dd></dl>
  150. <dl>
  151. <dt><a name="index-gimple_005fop"></a>GIMPLE function: <em>tree</em> <strong>gimple_op</strong> <em>(gimple g, unsigned i)</em></dt>
  152. <dd><p>Returns operand <code>I</code> from statement <code>G</code>.
  153. </p></dd></dl>
  154. <dl>
  155. <dt><a name="index-gimple_005fops"></a>GIMPLE function: <em>tree *</em> <strong>gimple_ops</strong> <em>(gimple g)</em></dt>
  156. <dd><p>Returns a pointer into the operand vector for statement <code>G</code>. This
  157. is computed using an internal table called <code>gimple_ops_offset_</code>[].
  158. This table is indexed by the gimple code of <code>G</code>.
  159. </p>
  160. <p>When the compiler is built, this table is filled-in using the
  161. sizes of the structures used by each statement code defined in
  162. gimple.def. Since the operand vector is at the bottom of the
  163. structure, for a gimple code <code>C</code> the offset is computed as sizeof
  164. (struct-of <code>C</code>) - sizeof (tree).
  165. </p>
  166. <p>This mechanism adds one memory indirection to every access when
  167. using <code>gimple_op</code>(), if this becomes a bottleneck, a pass can
  168. choose to memoize the result from <code>gimple_ops</code>() and use that to
  169. access the operands.
  170. </p></dd></dl>
  171. <a name="Operand-validation"></a>
  172. <h4 class="subsection">11.6.7 Operand validation</h4>
  173. <p>When adding a new operand to a gimple statement, the operand will
  174. be validated according to what each tuple accepts in its operand
  175. vector. These predicates are called by the
  176. <code>gimple_<var>name</var>_set_...()</code>. Each tuple will use one of the
  177. following predicates (Note, this list is not exhaustive):
  178. </p>
  179. <dl>
  180. <dt><a name="index-is_005fgimple_005fval"></a>GIMPLE function: <em>bool</em> <strong>is_gimple_val</strong> <em>(tree t)</em></dt>
  181. <dd><p>Returns true if t is a &quot;GIMPLE value&quot;, which are all the
  182. non-addressable stack variables (variables for which
  183. <code>is_gimple_reg</code> returns true) and constants (expressions for which
  184. <code>is_gimple_min_invariant</code> returns true).
  185. </p></dd></dl>
  186. <dl>
  187. <dt><a name="index-is_005fgimple_005faddressable"></a>GIMPLE function: <em>bool</em> <strong>is_gimple_addressable</strong> <em>(tree t)</em></dt>
  188. <dd><p>Returns true if t is a symbol or memory reference whose address
  189. can be taken.
  190. </p></dd></dl>
  191. <dl>
  192. <dt><a name="index-is_005fgimple_005fasm_005fval"></a>GIMPLE function: <em>bool</em> <strong>is_gimple_asm_val</strong> <em>(tree t)</em></dt>
  193. <dd><p>Similar to <code>is_gimple_val</code> but it also accepts hard registers.
  194. </p></dd></dl>
  195. <dl>
  196. <dt><a name="index-is_005fgimple_005fcall_005faddr"></a>GIMPLE function: <em>bool</em> <strong>is_gimple_call_addr</strong> <em>(tree t)</em></dt>
  197. <dd><p>Return true if t is a valid expression to use as the function
  198. called by a <code>GIMPLE_CALL</code>.
  199. </p></dd></dl>
  200. <dl>
  201. <dt><a name="index-is_005fgimple_005fmem_005fref_005faddr"></a>GIMPLE function: <em>bool</em> <strong>is_gimple_mem_ref_addr</strong> <em>(tree t)</em></dt>
  202. <dd><p>Return true if t is a valid expression to use as first operand
  203. of a <code>MEM_REF</code> expression.
  204. </p></dd></dl>
  205. <dl>
  206. <dt><a name="index-is_005fgimple_005fconstant"></a>GIMPLE function: <em>bool</em> <strong>is_gimple_constant</strong> <em>(tree t)</em></dt>
  207. <dd><p>Return true if t is a valid gimple constant.
  208. </p></dd></dl>
  209. <dl>
  210. <dt><a name="index-is_005fgimple_005fmin_005finvariant"></a>GIMPLE function: <em>bool</em> <strong>is_gimple_min_invariant</strong> <em>(tree t)</em></dt>
  211. <dd><p>Return true if t is a valid minimal invariant. This is different
  212. from constants, in that the specific value of t may not be known
  213. at compile time, but it is known that it doesn&rsquo;t change (e.g.,
  214. the address of a function local variable).
  215. </p></dd></dl>
  216. <dl>
  217. <dt><a name="index-is_005fgimple_005fip_005finvariant"></a>GIMPLE function: <em>bool</em> <strong>is_gimple_ip_invariant</strong> <em>(tree t)</em></dt>
  218. <dd><p>Return true if t is an interprocedural invariant. This means that t
  219. is a valid invariant in all functions (e.g. it can be an address of a
  220. global variable but not of a local one).
  221. </p></dd></dl>
  222. <dl>
  223. <dt><a name="index-is_005fgimple_005fip_005finvariant_005faddress"></a>GIMPLE function: <em>bool</em> <strong>is_gimple_ip_invariant_address</strong> <em>(tree t)</em></dt>
  224. <dd><p>Return true if t is an <code>ADDR_EXPR</code> that does not change once the
  225. program is running (and which is valid in all functions).
  226. </p></dd></dl>
  227. <a name="Statement-validation"></a>
  228. <h4 class="subsection">11.6.8 Statement validation</h4>
  229. <dl>
  230. <dt><a name="index-is_005fgimple_005fassign"></a>GIMPLE function: <em>bool</em> <strong>is_gimple_assign</strong> <em>(gimple g)</em></dt>
  231. <dd><p>Return true if the code of g is <code>GIMPLE_ASSIGN</code>.
  232. </p></dd></dl>
  233. <dl>
  234. <dt><a name="index-is_005fgimple_005fcall"></a>GIMPLE function: <em>bool</em> <strong>is_gimple_call</strong> <em>(gimple g)</em></dt>
  235. <dd><p>Return true if the code of g is <code>GIMPLE_CALL</code>.
  236. </p></dd></dl>
  237. <dl>
  238. <dt><a name="index-is_005fgimple_005fdebug"></a>GIMPLE function: <em>bool</em> <strong>is_gimple_debug</strong> <em>(gimple g)</em></dt>
  239. <dd><p>Return true if the code of g is <code>GIMPLE_DEBUG</code>.
  240. </p></dd></dl>
  241. <dl>
  242. <dt><a name="index-gimple_005fassign_005fcast_005fp"></a>GIMPLE function: <em>bool</em> <strong>gimple_assign_cast_p</strong> <em>(const_gimple g)</em></dt>
  243. <dd><p>Return true if g is a <code>GIMPLE_ASSIGN</code> that performs a type cast
  244. operation.
  245. </p></dd></dl>
  246. <dl>
  247. <dt><a name="index-gimple_005fdebug_005fbind_005fp"></a>GIMPLE function: <em>bool</em> <strong>gimple_debug_bind_p</strong> <em>(gimple g)</em></dt>
  248. <dd><p>Return true if g is a <code>GIMPLE_DEBUG</code> that binds the value of an
  249. expression to a variable.
  250. </p></dd></dl>
  251. <dl>
  252. <dt><a name="index-is_005fgimple_005fomp"></a>GIMPLE function: <em>bool</em> <strong>is_gimple_omp</strong> <em>(gimple g)</em></dt>
  253. <dd><p>Return true if g is any of the OpenMP codes.
  254. </p></dd></dl>
  255. <hr>
  256. <div class="header">
  257. <p>
  258. Previous: <a href="Conditional-Expressions.html#Conditional-Expressions" accesskey="p" rel="prev">Conditional Expressions</a>, Up: <a href="Operands.html#Operands" accesskey="u" rel="up">Operands</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>
  259. </div>
  260. </body>
  261. </html>