]>
Commit | Line | Data |
---|---|---|
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 | ||
10 | GIMPLE | |
11 | ------ | |
12 | ||
13 | GIMPLE is a three-address representation derived from GENERIC by | |
14 | breaking down GENERIC expressions into tuples of no more than 3 | |
15 | operands (with some exceptions like function calls). GIMPLE was | |
16 | heavily influenced by the SIMPLE IL used by the McCAT compiler | |
17 | project at McGill University, though we have made some different | |
18 | choices. For one thing, SIMPLE doesn't support ``goto``. | |
19 | ||
20 | Temporaries are introduced to hold intermediate values needed to | |
21 | compute complex expressions. Additionally, all the control | |
22 | structures used in GENERIC are lowered into conditional jumps, | |
23 | lexical scopes are removed and exception regions are converted | |
24 | into an on the side exception region tree. | |
25 | ||
26 | The compiler pass which converts GENERIC into GIMPLE is referred to as | |
27 | the :samp:`gimplifier`. The gimplifier works recursively, generating | |
28 | GIMPLE tuples out of the original GENERIC expressions. | |
29 | ||
30 | One of the early implementation strategies used for the GIMPLE | |
31 | representation was to use the same internal data structures used | |
32 | by front ends to represent parse trees. This simplified | |
33 | implementation because we could leverage existing functionality | |
34 | and interfaces. However, GIMPLE is a much more restrictive | |
35 | representation than abstract syntax trees (AST), therefore it | |
36 | does not require the full structural complexity provided by the | |
37 | main tree data structure. | |
38 | ||
39 | The GENERIC representation of a function is stored in the | |
40 | ``DECL_SAVED_TREE`` field of the associated ``FUNCTION_DECL`` | |
41 | tree node. It is converted to GIMPLE by a call to | |
42 | ``gimplify_function_tree``. | |
43 | ||
44 | If a front end wants to include language-specific tree codes in the tree | |
45 | representation which it provides to the back end, it must provide a | |
46 | definition of ``LANG_HOOKS_GIMPLIFY_EXPR`` which knows how to | |
47 | convert the front end trees to GIMPLE. Usually such a hook will involve | |
48 | much of the same code for expanding front end trees to RTL. This function | |
49 | can return fully lowered GIMPLE, or it can return GENERIC trees and let the | |
50 | main gimplifier lower them the rest of the way; this is often simpler. | |
51 | GIMPLE that is not fully lowered is known as 'High GIMPLE' and | |
52 | consists of the IL before the pass ``pass_lower_cf``. High GIMPLE | |
53 | contains 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 | |
56 | implicit jumps for control and exception expressions directly in | |
57 | the IL and EH region trees. | |
58 | ||
59 | The C and C++ front ends currently convert directly from front end | |
60 | trees to GIMPLE, and hand that off to the back end rather than first | |
61 | converting to GENERIC. Their gimplifier hooks know about all the | |
62 | ``_STMT`` nodes and how to convert them to GENERIC forms. There | |
63 | was some work done on a genericization pass which would run first, but | |
64 | the existence of ``STMT_EXPR`` meant that in order to convert all | |
65 | of the C statements into GENERIC equivalents would involve walking the | |
66 | entire tree anyway, so it was simpler to lower all the way. This | |
67 | might change in the future if someone writes an optimization pass | |
68 | which would work better with higher-level trees, but currently the | |
69 | optimizers all expect GIMPLE. | |
70 | ||
71 | You can request to dump a C-like representation of the GIMPLE form | |
72 | with 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 |