2 Copyright 1988-2022 Free Software Foundation, Inc.
3 This is part of the GCC manual.
4 For copying conditions, see the copyright.rst file.
13 Most statements in GIMPLE are assignment statements, represented by
14 ``GIMPLE_ASSIGN``. No other C expressions can appear at statement level;
15 a reference to a volatile object is converted into a
18 There are also several varieties of complex statements.
24 .. index:: Basic Statements
33 Used to represent an inline assembly statement. For an inline assembly
40 The ``ASM_STRING`` macro will return a ``STRING_CST`` node for
41 ``"mov x, y"``. If the original statement made use of the
42 extended-assembly syntax, then ``ASM_OUTPUTS``,
43 ``ASM_INPUTS``, and ``ASM_CLOBBERS`` will be the outputs, inputs,
44 and clobbers for the statement, represented as ``STRING_CST`` nodes.
45 The extended-assembly syntax looks like:
49 asm ("fsinx %1,%0" : "=f" (result) : "f" (angle));
51 The first string is the ``ASM_STRING``, containing the instruction
52 template. The next two strings are the output and inputs, respectively;
53 this statement has no clobbers. As this example indicates, 'plain'
54 assembly statements are merely a special case of extended assembly
55 statements; they have no cv-qualifiers, outputs, inputs, or clobbers.
56 All of the strings will be ``NUL`` -terminated, and will contain no
57 embedded ``NUL`` -characters.
59 If the assembly statement is declared ``volatile``, or if the
60 statement was not an extended assembly statement, and is therefore
61 implicitly volatile, then the predicate ``ASM_VOLATILE_P`` will hold
66 Used to represent a local declaration. The ``DECL_EXPR_DECL`` macro
67 can be used to obtain the entity declared. This declaration may be a
68 ``LABEL_DECL``, indicating that the label declared is a local label.
69 (As an extension, GCC allows the declaration of labels with scope.) In
70 C, this declaration may be a ``FUNCTION_DECL``, indicating the
71 use of the GCC nested function extension. For more information,
74 .. envvar:: LABEL_EXPR
76 Used to represent a label. The ``LABEL_DECL`` declared by this
77 statement can be obtained with the ``LABEL_EXPR_LABEL`` macro. The
78 ``IDENTIFIER_NODE`` giving the name of the label can be obtained from
79 the ``LABEL_DECL`` with ``DECL_NAME``.
83 Used to represent a ``goto`` statement. The ``GOTO_DESTINATION`` will
84 usually be a ``LABEL_DECL``. However, if the 'computed goto' extension
85 has been used, the ``GOTO_DESTINATION`` will be an arbitrary expression
86 indicating the destination. This expression will always have pointer type.
88 .. envvar:: RETURN_EXPR
90 Used to represent a ``return`` statement. Operand 0 represents the
91 value to return. It should either be the ``RESULT_DECL`` for the
92 containing function, or a ``MODIFY_EXPR`` or ``INIT_EXPR``
93 setting the function's ``RESULT_DECL``. It will be
94 ``NULL_TREE`` if the statement was just
100 .. envvar:: LOOP_EXPR
102 These nodes represent 'infinite' loops. The ``LOOP_EXPR_BODY``
103 represents the body of the loop. It should be executed forever, unless
104 an ``EXIT_EXPR`` is encountered.
106 .. envvar:: EXIT_EXPR
108 These nodes represent conditional exits from the nearest enclosing
109 ``LOOP_EXPR``. The single operand is the condition; if it is
110 nonzero, then the loop should be exited. An ``EXIT_EXPR`` will only
111 appear within a ``LOOP_EXPR``.
113 .. envvar:: SWITCH_EXPR
115 Used to represent a ``switch`` statement. The ``SWITCH_COND``
116 is the expression on which the switch is occurring. The
117 ``SWITCH_BODY`` is the body of the switch statement.
118 ``SWITCH_ALL_CASES_P`` is true if the switch includes a default
119 label or the case label ranges cover all possible values of the
120 condition expression.
122 Note that ``TREE_TYPE`` for a ``SWITCH_EXPR`` represents the
123 original type of switch expression as given in the source, before any
124 compiler conversions, instead of the type of the switch expression
125 itself (which is not meaningful).
127 .. envvar:: CASE_LABEL_EXPR
129 Use to represent a ``case`` label, range of ``case`` labels, or a
130 ``default`` label. If ``CASE_LOW`` is ``NULL_TREE``, then this is a
131 ``default`` label. Otherwise, if ``CASE_HIGH`` is ``NULL_TREE``, then
132 this is an ordinary ``case`` label. In this case, ``CASE_LOW`` is
133 an expression giving the value of the label. Both ``CASE_LOW`` and
134 ``CASE_HIGH`` are ``INTEGER_CST`` nodes. These values will have
135 the same type as the condition expression in the switch statement.
137 Otherwise, if both ``CASE_LOW`` and ``CASE_HIGH`` are defined, the
138 statement is a range of case labels. Such statements originate with the
139 extension that allows users to write things of the form:
145 The first value will be ``CASE_LOW``, while the second will be
148 .. envvar:: DEBUG_BEGIN_STMT
150 Marks the beginning of a source statement, for purposes of debug
151 information generation.
160 Block scopes and the variables they declare in GENERIC are
161 expressed using the ``BIND_EXPR`` code, which in previous
162 versions of GCC was primarily used for the C statement-expression
165 Variables in a block are collected into ``BIND_EXPR_VARS`` in
166 declaration order through their ``TREE_CHAIN`` field. Any runtime
167 initialization is moved out of ``DECL_INITIAL`` and into a
168 statement in the controlled block. When gimplifying from C or C++,
169 this initialization replaces the ``DECL_STMT``. These variables
170 will never require cleanups. The scope of these variables is just the
173 Variable-length arrays (VLAs) complicate this process, as their size
174 often refers to variables initialized earlier in the block and their
175 initialization involves an explicit stack allocation. To handle this,
176 we add an indirection and replace them with a pointer to stack space
177 allocated by means of ``alloca``. In most cases, we also arrange
178 for this space to be reclaimed when the enclosing ``BIND_EXPR`` is
179 exited, the exception to this being when there is an explicit call to
180 ``alloca`` in the source code, in which case the stack is left
181 depressed on exit of the ``BIND_EXPR``.
183 A C++ program will usually contain more ``BIND_EXPR`` s than
184 there are syntactic blocks in the source code, since several C++
185 constructs have implicit scopes associated with them. On the
186 other hand, although the C++ front end uses pseudo-scopes to
187 handle cleanups for objects with destructors, these don't
188 translate into the GIMPLE form; multiple declarations at the same
189 level use the same ``BIND_EXPR``.
191 .. index:: Statement Sequences
193 .. _statement-sequences:
198 Multiple statements at the same nesting level are collected into
199 a ``STATEMENT_LIST``. Statement lists are modified and
200 traversed using the interface in :samp:`tree-iterator.h`.
202 .. index:: Empty Statements
204 .. _empty-statements:
209 Whenever possible, statements with no effect are discarded. But
210 if they are nested within another construct which cannot be
211 discarded for some reason, they are instead replaced with an
212 empty statement, generated by ``build_empty_stmt``.
213 Initially, all empty statements were shared, after the pattern of
214 the Java front end, but this caused a lot of trouble in practice.
216 An empty statement is represented as ``(void)0``.
225 Other jumps are expressed by either ``GOTO_EXPR`` or
228 The operand of a ``GOTO_EXPR`` must be either a label or a
229 variable containing the address to jump to.
231 The operand of a ``RETURN_EXPR`` is either ``NULL_TREE``,
232 ``RESULT_DECL``, or a ``MODIFY_EXPR`` which sets the return
233 value. It would be nice to move the ``MODIFY_EXPR`` into a
234 separate statement, but the special return semantics in
235 ``expand_return`` make that difficult. It may still happen in
236 the future, perhaps by moving most of that logic into
237 ``expand_assignment``.
246 Destructors for local C++ objects and similar dynamic cleanups are
247 represented in GIMPLE by a ``TRY_FINALLY_EXPR``.
248 ``TRY_FINALLY_EXPR`` has two operands, both of which are a sequence
249 of statements to execute. The first sequence is executed. When it
250 completes the second sequence is executed.
252 The first sequence may complete in the following ways:
254 * Execute the last statement in the sequence and fall off the
257 * Execute a goto statement (``GOTO_EXPR``) to an ordinary
258 label outside the sequence.
260 * Execute a return statement (``RETURN_EXPR``).
262 * Throw an exception. This is currently not explicitly represented in
265 The second sequence is not executed if the first sequence completes by
266 calling ``setjmp`` or ``exit`` or any other function that does
267 not return. The second sequence is also not executed if the first
268 sequence completes via a non-local goto or a computed goto (in general
269 the compiler does not know whether such a goto statement exits the
270 first sequence or not, so we assume that it doesn't).
272 After the second sequence is executed, if it completes normally by
273 falling off the end, execution continues wherever the first sequence
274 would have continued, by falling off the end, or doing a goto, etc.
276 If the second sequence is an ``EH_ELSE_EXPR`` selector, then the
277 sequence in its first operand is used when the first sequence completes
278 normally, and that in its second operand is used for exceptional
279 cleanups, i.e., when an exception propagates out of the first sequence.
281 ``TRY_FINALLY_EXPR`` complicates the flow graph, since the cleanup
282 needs to appear on every edge out of the controlled block; this
283 reduces the freedom to move code across these edges. Therefore, the
284 EH lowering pass which runs before most of the optimization passes
285 eliminates these expressions by explicitly adding the cleanup to each
286 edge. Rethrowing the exception is represented using ``RESX_EXPR``.
293 .. index:: OMP_PARALLEL, OMP_FOR, OMP_SECTIONS, OMP_SINGLE, OMP_SECTION, OMP_MASTER, OMP_ORDERED, OMP_CRITICAL, OMP_RETURN, OMP_CONTINUE, OMP_ATOMIC, OMP_CLAUSE
295 All the statements starting with ``OMP_`` represent directives and
296 clauses used by the OpenMP API https://www.openmp.org.
298 .. envvar:: OMP_PARALLEL
300 Represents ``#pragma omp parallel [clause1 ... clauseN]``. It
303 Operand ``OMP_PARALLEL_BODY`` is valid while in GENERIC and
304 High GIMPLE forms. It contains the body of code to be executed
305 by all the threads. During GIMPLE lowering, this operand becomes
306 ``NULL`` and the body is emitted linearly after
309 Operand ``OMP_PARALLEL_CLAUSES`` is the list of clauses
310 associated with the directive.
312 Operand ``OMP_PARALLEL_FN`` is created by
313 ``pass_lower_omp``, it contains the ``FUNCTION_DECL``
314 for the function that will contain the body of the parallel
317 Operand ``OMP_PARALLEL_DATA_ARG`` is also created by
318 ``pass_lower_omp``. If there are shared variables to be
319 communicated to the children threads, this operand will contain
320 the ``VAR_DECL`` that contains all the shared values and
325 Represents ``#pragma omp for [clause1 ... clauseN]``. It has
328 Operand ``OMP_FOR_BODY`` contains the loop body.
330 Operand ``OMP_FOR_CLAUSES`` is the list of clauses
331 associated with the directive.
333 Operand ``OMP_FOR_INIT`` is the loop initialization code of
334 the form ``VAR = N1``.
336 Operand ``OMP_FOR_COND`` is the loop conditional expression
337 of the form ``VAR {<,>,<=,>=} N2``.
339 Operand ``OMP_FOR_INCR`` is the loop index increment of the
340 form ``VAR {+=,-=} INCR``.
342 Operand ``OMP_FOR_PRE_BODY`` contains side effect code from
343 operands ``OMP_FOR_INIT``, ``OMP_FOR_COND`` and
344 ``OMP_FOR_INC``. These side effects are part of the
345 ``OMP_FOR`` block but must be evaluated before the start of
348 The loop index variable ``VAR`` must be a signed integer variable,
349 which is implicitly private to each thread. Bounds
350 ``N1`` and ``N2`` and the increment expression
351 ``INCR`` are required to be loop invariant integer
352 expressions that are evaluated without any synchronization. The
353 evaluation order, frequency of evaluation and side effects are
354 unspecified by the standard.
356 .. envvar:: OMP_SECTIONS
358 Represents ``#pragma omp sections [clause1 ... clauseN]``.
360 Operand ``OMP_SECTIONS_BODY`` contains the sections body,
361 which in turn contains a set of ``OMP_SECTION`` nodes for
362 each of the concurrent sections delimited by ``#pragma omp
365 Operand ``OMP_SECTIONS_CLAUSES`` is the list of clauses
366 associated with the directive.
368 .. envvar:: OMP_SECTION
370 Section delimiter for ``OMP_SECTIONS``.
372 .. envvar:: OMP_SINGLE
374 Represents ``#pragma omp single``.
376 Operand ``OMP_SINGLE_BODY`` contains the body of code to be
377 executed by a single thread.
379 Operand ``OMP_SINGLE_CLAUSES`` is the list of clauses
380 associated with the directive.
382 .. envvar:: OMP_MASTER
384 Represents ``#pragma omp master``.
386 Operand ``OMP_MASTER_BODY`` contains the body of code to be
387 executed by the master thread.
389 .. envvar:: OMP_ORDERED
391 Represents ``#pragma omp ordered``.
393 Operand ``OMP_ORDERED_BODY`` contains the body of code to be
394 executed in the sequential order dictated by the loop index
397 .. envvar:: OMP_CRITICAL
399 Represents ``#pragma omp critical [name]``.
401 Operand ``OMP_CRITICAL_BODY`` is the critical section.
403 Operand ``OMP_CRITICAL_NAME`` is an optional identifier to
404 label the critical section.
406 .. envvar:: OMP_RETURN
408 This does not represent any OpenMP directive, it is an artificial
409 marker to indicate the end of the body of an OpenMP. It is used
410 by the flow graph (``tree-cfg.cc``) and OpenMP region
411 building code (``omp-low.cc``).
413 .. envvar:: OMP_CONTINUE
415 Similarly, this instruction does not represent an OpenMP
416 directive, it is used by ``OMP_FOR`` (and similar codes) as well as
417 ``OMP_SECTIONS`` to mark the place where the code needs to
418 loop to the next iteration, or the next section, respectively.
420 In some cases, ``OMP_CONTINUE`` is placed right before
421 ``OMP_RETURN``. But if there are cleanups that need to
422 occur right after the looping body, it will be emitted between
423 ``OMP_CONTINUE`` and ``OMP_RETURN``.
425 .. envvar:: OMP_ATOMIC
427 Represents ``#pragma omp atomic``.
429 Operand 0 is the address at which the atomic operation is to be
432 Operand 1 is the expression to evaluate. The gimplifier tries
433 three alternative code generation strategies. Whenever possible,
434 an atomic update built-in is used. If that fails, a
435 compare-and-swap loop is attempted. If that also fails, a
436 regular critical section around the expression is used.
438 .. envvar:: OMP_CLAUSE
440 Represents clauses associated with one of the ``OMP_`` directives.
441 Clauses are represented by separate subcodes defined in
442 :samp:`tree.h`. Clauses codes can be one of:
443 ``OMP_CLAUSE_PRIVATE``, ``OMP_CLAUSE_SHARED``,
444 ``OMP_CLAUSE_FIRSTPRIVATE``,
445 ``OMP_CLAUSE_LASTPRIVATE``, ``OMP_CLAUSE_COPYIN``,
446 ``OMP_CLAUSE_COPYPRIVATE``, ``OMP_CLAUSE_IF``,
447 ``OMP_CLAUSE_NUM_THREADS``, ``OMP_CLAUSE_SCHEDULE``,
448 ``OMP_CLAUSE_NOWAIT``, ``OMP_CLAUSE_ORDERED``,
449 ``OMP_CLAUSE_DEFAULT``, ``OMP_CLAUSE_REDUCTION``,
450 ``OMP_CLAUSE_COLLAPSE``, ``OMP_CLAUSE_UNTIED``,
451 ``OMP_CLAUSE_FINAL``, and ``OMP_CLAUSE_MERGEABLE``. Each code
452 represents the corresponding OpenMP clause.
454 Clauses associated with the same directive are chained together
455 via ``OMP_CLAUSE_CHAIN``. Those clauses that accept a list
456 of variables are restricted to exactly one, accessed with
457 ``OMP_CLAUSE_VAR``. Therefore, multiple variables under the
458 same clause ``C`` need to be represented as multiple ``C`` clauses
459 chained together. This facilitates adding new clauses during
467 .. index:: OACC_CACHE, OACC_DATA, OACC_DECLARE, OACC_ENTER_DATA, OACC_EXIT_DATA, OACC_HOST_DATA, OACC_KERNELS, OACC_LOOP, OACC_PARALLEL, OACC_SERIAL, OACC_UPDATE
469 All the statements starting with ``OACC_`` represent directives and
470 clauses used by the OpenACC API https://www.openacc.org.
472 .. envvar:: OACC_CACHE
474 Represents ``#pragma acc cache (var ...)``.
476 .. envvar:: OACC_DATA
478 Represents ``#pragma acc data [clause1 ... clauseN]``.
480 .. envvar:: OACC_DECLARE
482 Represents ``#pragma acc declare [clause1 ... clauseN]``.
484 .. envvar:: OACC_ENTER_DATA
486 Represents ``#pragma acc enter data [clause1 ... clauseN]``.
488 .. envvar:: OACC_EXIT_DATA
490 Represents ``#pragma acc exit data [clause1 ... clauseN]``.
492 .. envvar:: OACC_HOST_DATA
494 Represents ``#pragma acc host_data [clause1 ... clauseN]``.
496 .. envvar:: OACC_KERNELS
498 Represents ``#pragma acc kernels [clause1 ... clauseN]``.
500 .. envvar:: OACC_LOOP
502 Represents ``#pragma acc loop [clause1 ... clauseN]``.
504 See the description of the ``OMP_FOR`` code.
506 .. envvar:: OACC_PARALLEL
508 Represents ``#pragma acc parallel [clause1 ... clauseN]``.
510 .. envvar:: OACC_SERIAL
512 Represents ``#pragma acc serial [clause1 ... clauseN]``.
514 .. envvar:: OACC_UPDATE
516 Represents ``#pragma acc update [clause1 ... clauseN]``.