]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/doc/gccint/gimple.rst
sphinx: add missing trailing newline
[thirdparty/gcc.git] / gcc / doc / gccint / gimple.rst
CommitLineData
c63539ff
ML
1..
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.
5
6.. index:: GIMPLE
7
8.. _gimple:
9
10GIMPLE
11------
12
13GIMPLE is a three-address representation derived from GENERIC by
14breaking down GENERIC expressions into tuples of no more than 3
15operands (with some exceptions like function calls). GIMPLE was
16heavily influenced by the SIMPLE IL used by the McCAT compiler
17project at McGill University, though we have made some different
18choices. For one thing, SIMPLE doesn't support ``goto``.
19
20Temporaries are introduced to hold intermediate values needed to
21compute complex expressions. Additionally, all the control
22structures used in GENERIC are lowered into conditional jumps,
23lexical scopes are removed and exception regions are converted
24into an on the side exception region tree.
25
26The compiler pass which converts GENERIC into GIMPLE is referred to as
27the :samp:`gimplifier`. The gimplifier works recursively, generating
28GIMPLE tuples out of the original GENERIC expressions.
29
30One of the early implementation strategies used for the GIMPLE
31representation was to use the same internal data structures used
32by front ends to represent parse trees. This simplified
33implementation because we could leverage existing functionality
34and interfaces. However, GIMPLE is a much more restrictive
35representation than abstract syntax trees (AST), therefore it
36does not require the full structural complexity provided by the
37main tree data structure.
38
39The GENERIC representation of a function is stored in the
40``DECL_SAVED_TREE`` field of the associated ``FUNCTION_DECL``
41tree node. It is converted to GIMPLE by a call to
42``gimplify_function_tree``.
43
44If a front end wants to include language-specific tree codes in the tree
45representation which it provides to the back end, it must provide a
46definition of ``LANG_HOOKS_GIMPLIFY_EXPR`` which knows how to
47convert the front end trees to GIMPLE. Usually such a hook will involve
48much of the same code for expanding front end trees to RTL. This function
49can return fully lowered GIMPLE, or it can return GENERIC trees and let the
50main gimplifier lower them the rest of the way; this is often simpler.
51GIMPLE that is not fully lowered is known as 'High GIMPLE' and
52consists of the IL before the pass ``pass_lower_cf``. High GIMPLE
53contains some container statements like lexical scopes
54(represented by ``GIMPLE_BIND``) and nested expressions (e.g.,
55``GIMPLE_TRY``), while 'Low GIMPLE' exposes all of the
56implicit jumps for control and exception expressions directly in
57the IL and EH region trees.
58
59The C and C++ front ends currently convert directly from front end
60trees to GIMPLE, and hand that off to the back end rather than first
61converting to GENERIC. Their gimplifier hooks know about all the
62``_STMT`` nodes and how to convert them to GENERIC forms. There
63was some work done on a genericization pass which would run first, but
64the existence of ``STMT_EXPR`` meant that in order to convert all
65of the C statements into GENERIC equivalents would involve walking the
66entire tree anyway, so it was simpler to lower all the way. This
67might change in the future if someone writes an optimization pass
68which would work better with higher-level trees, but currently the
69optimizers all expect GIMPLE.
70
71You can request to dump a C-like representation of the GIMPLE form
72with the flag :option:`-fdump-tree-gimple`.
73
74.. toctree::
75 :maxdepth: 2
76
77 gimple/tuple-representation
78 gimple/class-hierarchy-of-gimple-statements
79 gimple/gimple-instruction-set
80 gimple/temporaries
81 gimple/operands
82 gimple/manipulating-gimple-statements
83 gimple/tuple-specific-accessors
84 gimple/gimple-sequences
85 gimple/sequence-iterators
86 gimple/adding-a-new-gimple-statement-code
87 gimple/statement-and-operand-traversals
3ed1b4ce 88 gimple/exception-handling