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