]> git.ipfire.org Git - thirdparty/gcc.git/blob
79118da6452eaab72c529e904564cf9f6fa479bc
[thirdparty/gcc.git] /
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 .. _elimination:
7
8 Eliminating Frame Pointer and Arg Pointer
9 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10
11 .. prevent bad page break with this line
12
13 This is about eliminating the frame pointer and arg pointer.
14
15 .. function:: bool TARGET_FRAME_POINTER_REQUIRED (void)
16
17 .. hook-start:TARGET_FRAME_POINTER_REQUIRED
18
19 This target hook should return ``true`` if a function must have and use
20 a frame pointer. This target hook is called in the reload pass. If its return
21 value is ``true`` the function will have a frame pointer.
22
23 This target hook can in principle examine the current function and decide
24 according to the facts, but on most machines the constant ``false`` or the
25 constant ``true`` suffices. Use ``false`` when the machine allows code
26 to be generated with no frame pointer, and doing so saves some time or space.
27 Use ``true`` when there is no possible advantage to avoiding a frame
28 pointer.
29
30 In certain cases, the compiler does not know how to produce valid code
31 without a frame pointer. The compiler recognizes those cases and
32 automatically gives the function a frame pointer regardless of what
33 ``targetm.frame_pointer_required`` returns. You don't need to worry about
34 them.
35
36 In a function that does not require a frame pointer, the frame pointer
37 register can be allocated for ordinary usage, unless you mark it as a
38 fixed register. See ``FIXED_REGISTERS`` for more information.
39
40 Default return value is ``false``.
41
42 .. hook-end
43
44 .. c:macro:: ELIMINABLE_REGS
45
46 This macro specifies a table of register pairs used to eliminate
47 unneeded registers that point into the stack frame.
48
49 The definition of this macro is a list of structure initializations, each
50 of which specifies an original and replacement register.
51
52 On some machines, the position of the argument pointer is not known until
53 the compilation is completed. In such a case, a separate hard register
54 must be used for the argument pointer. This register can be eliminated by
55 replacing it with either the frame pointer or the argument pointer,
56 depending on whether or not the frame pointer has been eliminated.
57
58 In this case, you might specify:
59
60 .. code-block:: c++
61
62 #define ELIMINABLE_REGS \
63 {{ARG_POINTER_REGNUM, STACK_POINTER_REGNUM}, \
64 {ARG_POINTER_REGNUM, FRAME_POINTER_REGNUM}, \
65 {FRAME_POINTER_REGNUM, STACK_POINTER_REGNUM}}
66
67 Note that the elimination of the argument pointer with the stack pointer is
68 specified first since that is the preferred elimination.
69
70 .. function:: bool TARGET_CAN_ELIMINATE (const int from_reg, const int to_reg)
71
72 .. hook-start:TARGET_CAN_ELIMINATE
73
74 This target hook should return ``true`` if the compiler is allowed to
75 try to replace register number :samp:`{from_reg}` with register number
76 :samp:`{to_reg}`. This target hook will usually be ``true``, since most of the
77 cases preventing register elimination are things that the compiler already
78 knows about.
79
80 Default return value is ``true``.
81
82 .. hook-end
83
84 .. c:macro:: INITIAL_ELIMINATION_OFFSET (from_reg, to_reg, offset_var)
85
86 This macro returns the initial difference between the specified pair
87 of registers. The value would be computed from information
88 such as the result of ``get_frame_size ()`` and the tables of
89 registers ``df_regs_ever_live_p`` and ``call_used_regs``.
90
91 .. function:: void TARGET_COMPUTE_FRAME_LAYOUT (void)
92
93 .. hook-start:TARGET_COMPUTE_FRAME_LAYOUT
94
95 This target hook is called once each time the frame layout needs to be
96 recalculated. The calculations can be cached by the target and can then
97 be used by ``INITIAL_ELIMINATION_OFFSET`` instead of re-computing the
98 layout on every invocation of that hook. This is particularly useful
99 for targets that have an expensive frame layout function. Implementing
100 this callback is optional.
101
102 .. hook-end