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.

325 lines
14KB

  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-2020 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 6.5, http://www.gnu.org/software/texinfo/ -->
  18. <head>
  19. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  20. <title>Logical Operators (GNU Compiler Collection (GCC) Internals)</title>
  21. <meta name="description" content="Logical Operators (GNU Compiler Collection (GCC) Internals)">
  22. <meta name="keywords" content="Logical Operators (GNU Compiler Collection (GCC) Internals)">
  23. <meta name="resource-type" content="document">
  24. <meta name="distribution" content="global">
  25. <meta name="Generator" content="makeinfo">
  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.indentedblock {margin-right: 0em}
  36. blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
  37. blockquote.smallquotation {font-size: smaller}
  38. div.display {margin-left: 3.2em}
  39. div.example {margin-left: 3.2em}
  40. div.lisp {margin-left: 3.2em}
  41. div.smalldisplay {margin-left: 3.2em}
  42. div.smallexample {margin-left: 3.2em}
  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.nolinebreak {white-space: nowrap}
  54. span.roman {font-family: initial; font-weight: normal}
  55. span.sansserif {font-family: sans-serif; font-weight: normal}
  56. ul.no-bullet {list-style: none}
  57. -->
  58. </style>
  59. </head>
  60. <body lang="en">
  61. <a name="Logical-Operators"></a>
  62. <div class="header">
  63. <p>
  64. 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>
  65. </div>
  66. <hr>
  67. <a name="Logical-Operators-1"></a>
  68. <h4 class="subsection">12.6.4 Logical Operators</h4>
  69. <a name="index-Logical-Operators"></a>
  70. <p>Except when they appear in the condition operand of a
  71. <code>GIMPLE_COND</code>, logical &lsquo;and&rsquo; and &lsquo;or&rsquo; operators are simplified
  72. as follows: <code>a = b &amp;&amp; c</code> becomes
  73. </p>
  74. <div class="smallexample">
  75. <pre class="smallexample">T1 = (bool)b;
  76. if (T1 == true)
  77. T1 = (bool)c;
  78. a = T1;
  79. </pre></div>
  80. <p>Note that <code>T1</code> in this example cannot be an expression temporary,
  81. because it has two different assignments.
  82. </p>
  83. <a name="Manipulating-operands"></a>
  84. <h4 class="subsection">12.6.5 Manipulating operands</h4>
  85. <p>All gimple operands are of type <code>tree</code>. But only certain
  86. types of trees are allowed to be used as operand tuples. Basic
  87. validation is controlled by the function
  88. <code>get_gimple_rhs_class</code>, which given a tree code, returns an
  89. <code>enum</code> with the following values of type <code>enum
  90. gimple_rhs_class</code>
  91. </p>
  92. <ul>
  93. <li> <code>GIMPLE_INVALID_RHS</code>
  94. The tree cannot be used as a GIMPLE operand.
  95. </li><li> <code>GIMPLE_TERNARY_RHS</code>
  96. The tree is a valid GIMPLE ternary operation.
  97. </li><li> <code>GIMPLE_BINARY_RHS</code>
  98. The tree is a valid GIMPLE binary operation.
  99. </li><li> <code>GIMPLE_UNARY_RHS</code>
  100. The tree is a valid GIMPLE unary operation.
  101. </li><li> <code>GIMPLE_SINGLE_RHS</code>
  102. The tree is a single object, that cannot be split into simpler
  103. operands (for instance, <code>SSA_NAME</code>, <code>VAR_DECL</code>, <code>COMPONENT_REF</code>, etc).
  104. <p>This operand class also acts as an escape hatch for tree nodes
  105. that may be flattened out into the operand vector, but would need
  106. more than two slots on the RHS. For instance, a <code>COND_EXPR</code>
  107. expression of the form <code>(a op b) ? x : y</code> could be flattened
  108. out on the operand vector using 4 slots, but it would also
  109. require additional processing to distinguish <code>c = a op b</code>
  110. from <code>c = a op b ? x : y</code>. Something similar occurs with
  111. <code>ASSERT_EXPR</code>. In time, these special case tree
  112. expressions should be flattened into the operand vector.
  113. </p></li></ul>
  114. <p>For tree nodes in the categories <code>GIMPLE_TERNARY_RHS</code>,
  115. <code>GIMPLE_BINARY_RHS</code> and <code>GIMPLE_UNARY_RHS</code>, they cannot be
  116. stored inside tuples directly. They first need to be flattened and
  117. separated into individual components. For instance, given the GENERIC
  118. expression
  119. </p>
  120. <div class="smallexample">
  121. <pre class="smallexample">a = b + c
  122. </pre></div>
  123. <p>its tree representation is:
  124. </p>
  125. <div class="smallexample">
  126. <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;
  127. </pre></div>
  128. <p>In this case, the GIMPLE form for this statement is logically
  129. identical to its GENERIC form but in GIMPLE, the <code>PLUS_EXPR</code>
  130. on the RHS of the assignment is not represented as a tree,
  131. instead the two operands are taken out of the <code>PLUS_EXPR</code> sub-tree
  132. and flattened into the GIMPLE tuple as follows:
  133. </p>
  134. <div class="smallexample">
  135. <pre class="smallexample">GIMPLE_ASSIGN &lt;PLUS_EXPR, VAR_DECL &lt;a&gt;, VAR_DECL &lt;b&gt;, VAR_DECL &lt;c&gt;&gt;
  136. </pre></div>
  137. <a name="Operand-vector-allocation"></a>
  138. <h4 class="subsection">12.6.6 Operand vector allocation</h4>
  139. <p>The operand vector is stored at the bottom of the three tuple
  140. structures that accept operands. This means, that depending on
  141. the code of a given statement, its operand vector will be at
  142. different offsets from the base of the structure. To access
  143. tuple operands use the following accessors
  144. </p>
  145. <dl>
  146. <dt><a name="index-gimple_005fnum_005fops"></a>GIMPLE function: <em>unsigned</em> <strong>gimple_num_ops</strong> <em>(gimple g)</em></dt>
  147. <dd><p>Returns the number of operands in statement G.
  148. </p></dd></dl>
  149. <dl>
  150. <dt><a name="index-gimple_005fop"></a>GIMPLE function: <em>tree</em> <strong>gimple_op</strong> <em>(gimple g, unsigned i)</em></dt>
  151. <dd><p>Returns operand <code>I</code> from statement <code>G</code>.
  152. </p></dd></dl>
  153. <dl>
  154. <dt><a name="index-gimple_005fops"></a>GIMPLE function: <em>tree *</em> <strong>gimple_ops</strong> <em>(gimple g)</em></dt>
  155. <dd><p>Returns a pointer into the operand vector for statement <code>G</code>. This
  156. is computed using an internal table called <code>gimple_ops_offset_</code>[].
  157. This table is indexed by the gimple code of <code>G</code>.
  158. </p>
  159. <p>When the compiler is built, this table is filled-in using the
  160. sizes of the structures used by each statement code defined in
  161. gimple.def. Since the operand vector is at the bottom of the
  162. structure, for a gimple code <code>C</code> the offset is computed as sizeof
  163. (struct-of <code>C</code>) - sizeof (tree).
  164. </p>
  165. <p>This mechanism adds one memory indirection to every access when
  166. using <code>gimple_op</code>(), if this becomes a bottleneck, a pass can
  167. choose to memoize the result from <code>gimple_ops</code>() and use that to
  168. access the operands.
  169. </p></dd></dl>
  170. <a name="Operand-validation"></a>
  171. <h4 class="subsection">12.6.7 Operand validation</h4>
  172. <p>When adding a new operand to a gimple statement, the operand will
  173. be validated according to what each tuple accepts in its operand
  174. vector. These predicates are called by the
  175. <code>gimple_<var>name</var>_set_...()</code>. Each tuple will use one of the
  176. following predicates (Note, this list is not exhaustive):
  177. </p>
  178. <dl>
  179. <dt><a name="index-is_005fgimple_005fval"></a>GIMPLE function: <em>bool</em> <strong>is_gimple_val</strong> <em>(tree t)</em></dt>
  180. <dd><p>Returns true if t is a &quot;GIMPLE value&quot;, which are all the
  181. non-addressable stack variables (variables for which
  182. <code>is_gimple_reg</code> returns true) and constants (expressions for which
  183. <code>is_gimple_min_invariant</code> returns true).
  184. </p></dd></dl>
  185. <dl>
  186. <dt><a name="index-is_005fgimple_005faddressable"></a>GIMPLE function: <em>bool</em> <strong>is_gimple_addressable</strong> <em>(tree t)</em></dt>
  187. <dd><p>Returns true if t is a symbol or memory reference whose address
  188. can be taken.
  189. </p></dd></dl>
  190. <dl>
  191. <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>
  192. <dd><p>Similar to <code>is_gimple_val</code> but it also accepts hard registers.
  193. </p></dd></dl>
  194. <dl>
  195. <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>
  196. <dd><p>Return true if t is a valid expression to use as the function
  197. called by a <code>GIMPLE_CALL</code>.
  198. </p></dd></dl>
  199. <dl>
  200. <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>
  201. <dd><p>Return true if t is a valid expression to use as first operand
  202. of a <code>MEM_REF</code> expression.
  203. </p></dd></dl>
  204. <dl>
  205. <dt><a name="index-is_005fgimple_005fconstant"></a>GIMPLE function: <em>bool</em> <strong>is_gimple_constant</strong> <em>(tree t)</em></dt>
  206. <dd><p>Return true if t is a valid gimple constant.
  207. </p></dd></dl>
  208. <dl>
  209. <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>
  210. <dd><p>Return true if t is a valid minimal invariant. This is different
  211. from constants, in that the specific value of t may not be known
  212. at compile time, but it is known that it doesn&rsquo;t change (e.g.,
  213. the address of a function local variable).
  214. </p></dd></dl>
  215. <dl>
  216. <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>
  217. <dd><p>Return true if t is an interprocedural invariant. This means that t
  218. is a valid invariant in all functions (e.g. it can be an address of a
  219. global variable but not of a local one).
  220. </p></dd></dl>
  221. <dl>
  222. <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>
  223. <dd><p>Return true if t is an <code>ADDR_EXPR</code> that does not change once the
  224. program is running (and which is valid in all functions).
  225. </p></dd></dl>
  226. <a name="Statement-validation"></a>
  227. <h4 class="subsection">12.6.8 Statement validation</h4>
  228. <dl>
  229. <dt><a name="index-is_005fgimple_005fassign"></a>GIMPLE function: <em>bool</em> <strong>is_gimple_assign</strong> <em>(gimple g)</em></dt>
  230. <dd><p>Return true if the code of g is <code>GIMPLE_ASSIGN</code>.
  231. </p></dd></dl>
  232. <dl>
  233. <dt><a name="index-is_005fgimple_005fcall"></a>GIMPLE function: <em>bool</em> <strong>is_gimple_call</strong> <em>(gimple g)</em></dt>
  234. <dd><p>Return true if the code of g is <code>GIMPLE_CALL</code>.
  235. </p></dd></dl>
  236. <dl>
  237. <dt><a name="index-is_005fgimple_005fdebug"></a>GIMPLE function: <em>bool</em> <strong>is_gimple_debug</strong> <em>(gimple g)</em></dt>
  238. <dd><p>Return true if the code of g is <code>GIMPLE_DEBUG</code>.
  239. </p></dd></dl>
  240. <dl>
  241. <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>
  242. <dd><p>Return true if g is a <code>GIMPLE_ASSIGN</code> that performs a type cast
  243. operation.
  244. </p></dd></dl>
  245. <dl>
  246. <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>
  247. <dd><p>Return true if g is a <code>GIMPLE_DEBUG</code> that binds the value of an
  248. expression to a variable.
  249. </p></dd></dl>
  250. <dl>
  251. <dt><a name="index-is_005fgimple_005fomp"></a>GIMPLE function: <em>bool</em> <strong>is_gimple_omp</strong> <em>(gimple g)</em></dt>
  252. <dd><p>Return true if g is any of the OpenMP codes.
  253. </p></dd></dl>
  254. <dl>
  255. <dt><a name="index-_0028gimple"></a>GIMPLE function: <em>gimple_debug_begin_stmt_p</em> <strong>(gimple</strong> <em>g)</em></dt>
  256. <dd><p>Return true if g is a <code>GIMPLE_DEBUG</code> that marks the beginning of
  257. a source statement.
  258. </p></dd></dl>
  259. <dl>
  260. <dt><a name="index-_0028gimple-1"></a>GIMPLE function: <em>gimple_debug_inline_entry_p</em> <strong>(gimple</strong> <em>g)</em></dt>
  261. <dd><p>Return true if g is a <code>GIMPLE_DEBUG</code> that marks the entry
  262. point of an inlined function.
  263. </p></dd></dl>
  264. <dl>
  265. <dt><a name="index-_0028gimple-2"></a>GIMPLE function: <em>gimple_debug_nonbind_marker_p</em> <strong>(gimple</strong> <em>g)</em></dt>
  266. <dd><p>Return true if g is a <code>GIMPLE_DEBUG</code> that marks a program location,
  267. without any variable binding.
  268. </p></dd></dl>
  269. <hr>
  270. <div class="header">
  271. <p>
  272. 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>
  273. </div>
  274. </body>
  275. </html>