]>
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:: per-function data, data structures | |
7 | ||
8 | .. _per-function-data: | |
9 | ||
10 | Defining data structures for per-function information. | |
11 | ****************************************************** | |
12 | ||
13 | If the target needs to store information on a per-function basis, GCC | |
14 | provides a macro and a couple of variables to allow this. Note, just | |
15 | using statics to store the information is a bad idea, since GCC supports | |
16 | nested functions, so you can be halfway through encoding one function | |
17 | when another one comes along. | |
18 | ||
19 | GCC defines a data structure called ``struct function`` which | |
20 | contains all of the data specific to an individual function. This | |
21 | structure contains a field called ``machine`` whose type is | |
22 | ``struct machine_function *``, which can be used by targets to point | |
23 | to their own specific data. | |
24 | ||
25 | If a target needs per-function specific data it should define the type | |
26 | ``struct machine_function`` and also the macro ``INIT_EXPANDERS``. | |
27 | This macro should be used to initialize the function pointer | |
28 | ``init_machine_status``. This pointer is explained below. | |
29 | ||
30 | One typical use of per-function, target specific data is to create an | |
31 | RTX to hold the register containing the function's return address. This | |
32 | RTX can then be used to implement the ``__builtin_return_address`` | |
33 | function, for level 0. | |
34 | ||
35 | Note---earlier implementations of GCC used a single data area to hold | |
36 | all of the per-function information. Thus when processing of a nested | |
37 | function began the old per-function data had to be pushed onto a | |
38 | stack, and when the processing was finished, it had to be popped off the | |
39 | stack. GCC used to provide function pointers called | |
40 | ``save_machine_status`` and ``restore_machine_status`` to handle | |
41 | the saving and restoring of the target specific information. Since the | |
42 | single data area approach is no longer used, these pointers are no | |
43 | longer supported. | |
44 | ||
45 | .. c:macro:: INIT_EXPANDERS | |
46 | ||
47 | Macro called to initialize any target specific information. This macro | |
48 | is called once per function, before generation of any RTL has begun. | |
49 | The intention of this macro is to allow the initialization of the | |
50 | function pointer ``init_machine_status``. | |
51 | ||
52 | .. index:: init_machine_status | |
53 | ||
54 | Variable void (\*)(struct function \*) init_machine_statusIf this function pointer is non- ``NULL`` it will be called once per | |
55 | function, before function compilation starts, in order to allow the | |
56 | target to perform any target specific initialization of the | |
57 | ``struct function`` structure. It is intended that this would be | |
58 | used to initialize the ``machine`` of that structure. | |
59 | ||
60 | ``struct machine_function`` structures are expected to be freed by GC. | |
61 | Generally, any memory that they reference must be allocated by using | |
62 | GC allocation, including the structure itself. |