GCC Middle and Back End API Reference
function-abi.h
Go to the documentation of this file.
1/* Information about function binary interfaces.
2 Copyright (C) 2019-2024 Free Software Foundation, Inc.
3
4This file is part of GCC
5
6GCC is free software; you can redistribute it and/or modify it under
7the terms of the GNU General Public License as published by the Free
8Software Foundation; either version 3, or (at your option) any later
9version.
10
11GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12WARRANTY; without even the implied warranty of MERCHANTABILITY or
13FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14for more details.
15
16You should have received a copy of the GNU General Public License
17along with GCC; see the file COPYING3. If not see
18<http://www.gnu.org/licenses/>. */
19
20#ifndef GCC_FUNCTION_ABI_H
21#define GCC_FUNCTION_ABI_H
22
23/* Most targets use the same ABI for all functions in a translation
24 unit, but some targets support interoperability between several ABIs.
25 Each such ABI has a unique 0-based identifier, with 0 always being
26 the default choice of ABI.
27
28 NUM_ABI_IDS is the maximum number of such ABIs that GCC can handle at once.
29 A bitfield with this number of bits can represent any combinaion of the
30 supported ABIs. */
31const size_t NUM_ABI_IDS = 8;
32
33/* Information about one of the target's predefined ABIs. */
35{
36public:
37 /* A target-specific identifier for this ABI. The value must be in
38 the range [0, NUM_ABI_IDS - 1]. */
39 unsigned int id () const { return m_id; }
40
41 /* True if this ABI has been initialized. */
42 bool initialized_p () const { return m_initialized; }
43
44 /* Return true if a function call is allowed to alter every bit of
45 register REGNO, so that the register contains an arbitrary value
46 on return. If so, the register cannot hold any part of a value
47 that is live across a call. */
48 bool
49 clobbers_full_reg_p (unsigned int regno) const
50 {
52 }
53
54 /* Return true if a function call is allowed to alter some or all bits
55 of register REGNO.
56
57 This is true whenever clobbers_full_reg_p (REGNO) is true. It is
58 also true if, for example, the ABI says that a call must preserve the
59 low 32 or 64 bits of REGNO, but can clobber the upper bits of REGNO.
60 In the latter case, it is possible for REGNO to hold values that
61 are live across a call, provided that the value occupies only the
62 call-preserved part of the register. */
63 bool
64 clobbers_at_least_part_of_reg_p (unsigned int regno) const
65 {
67 }
68
69 /* Return true if a function call is allowed to clobber at least part
70 of (reg:MODE REGNO). If so, it is not possible for the register
71 as a whole to be live across a call. */
72 bool
73 clobbers_reg_p (machine_mode mode, unsigned int regno) const
74 {
75 return overlaps_hard_reg_set_p (m_mode_clobbers[mode], mode, regno);
76 }
77
78 /* Return the set of registers that a function call is allowed to
79 alter completely, so that the registers contain arbitrary values
80 on return. This doesn't include registers that a call can only
81 partly clobber (as per TARGET_HARD_REGNO_CALL_PART_CLOBBERED).
82
83 These registers cannot hold any part of a value that is live across
84 a call. */
86
87 /* Return the set of registers that a function call is allowed to alter
88 to some degree. For example, if an ABI says that a call must preserve
89 the low 32 or 64 bits of a register R, but can clobber the upper bits
90 of R, R would be in this set but not in full_reg_clobbers ().
91
92 This set is a superset of full_reg_clobbers (). It is possible for a
93 register in full_and_partial_reg_clobbers () & ~full_reg_clobbers ()
94 to contain values that are live across a call, provided that the live
95 value only occupies the call-preserved part of the register. */
101
102 /* Return the set of registers that cannot be used to hold a value of
103 mode MODE across a function call. That is:
104
105 (reg:REGNO MODE)
106
107 might be clobbered by a call whenever:
108
109 overlaps_hard_reg_set (mode_clobbers (MODE), MODE, REGNO)
110
111 In allocation terms, the registers in the returned set conflict
112 with any value of mode MODE that is live across a call. */
114 mode_clobbers (machine_mode mode) const
115 {
116 return m_mode_clobbers[mode];
117 }
118
119 void initialize (unsigned int, const_hard_reg_set);
120 void add_full_reg_clobber (unsigned int);
121
122private:
123 unsigned int m_id : NUM_ABI_IDS;
124 unsigned int m_initialized : 1;
127 HARD_REG_SET m_mode_clobbers[NUM_MACHINE_MODES];
128};
129
130/* Describes either a predefined ABI or the ABI of a particular function.
131 In the latter case, the ABI might make use of extra function-specific
132 information, such as for -fipa-ra. */
134{
135public:
136 /* Initialize the structure for a general function with the given ABI. */
140
141 /* Initialize the structure for a function that has the given ABI and
142 that is known not to clobber registers outside MASK. */
146
147 /* The predefined ABI from which this ABI is derived. */
148 const predefined_function_abi &base_abi () const { return *m_base_abi; }
149
150 /* The target-specific identifier of the predefined ABI. */
151 unsigned int id () const { return m_base_abi->id (); }
152
153 /* See the corresponding predefined_function_abi functions for
154 details about the following functions. */
155
158 {
160 }
161
167
169 mode_clobbers (machine_mode mode) const
170 {
171 return m_mask & m_base_abi->mode_clobbers (mode);
172 }
173
174 bool
175 clobbers_full_reg_p (unsigned int regno) const
176 {
177 return (TEST_HARD_REG_BIT (m_mask, regno)
179 }
180
181 bool
182 clobbers_at_least_part_of_reg_p (unsigned int regno) const
183 {
184 return (TEST_HARD_REG_BIT (m_mask, regno)
186 }
187
188 bool
189 clobbers_reg_p (machine_mode mode, unsigned int regno) const
190 {
191 return overlaps_hard_reg_set_p (mode_clobbers (mode), mode, regno);
192 }
193
194 bool
195 operator== (const function_abi &other) const
196 {
197 return m_base_abi == other.m_base_abi && m_mask == other.m_mask;
198 }
199
200 bool
201 operator!= (const function_abi &other) const
202 {
203 return !operator== (other);
204 }
205
206protected:
209};
210
211/* This class collects information about the ABIs of functions that are
212 called in a particular region of code. It is mostly intended to be
213 used as a local variable during an IR walk. */
215{
216public:
218
219 /* Record that the code region calls a function with the given ABI. */
220 void
222 {
224 }
225
227
228private:
230};
231
233{
234 /* An array of all the target ABIs that are available in this
235 translation unit. Not all entries are used for all targets,
236 but the structures are relatively small, and using a fixed-size
237 array avoids extra indirection.
238
239 There are various ways of getting an ABI descriptor:
240
241 * fndecl_abi (FNDECL) is the ABI of function FNDECL.
242
243 * fntype_abi (FNTYPE) is the ABI of a function with type FNTYPE.
244
245 * crtl->abi is the ABI of the function that we are currently
246 compiling to rtl.
247
248 * insn_callee_abi (INSN) is the ABI used by the target of call insn INSN.
249
250 * eh_edge_abi is the "ABI" used when taking an EH edge from an
251 exception-throwing statement to an exception handler. Catching
252 exceptions from calls can be treated as an abnormal return from
253 those calls, and this ABI therefore describes the ABI of functions
254 on such an abnormal return. Statements that throw non-call
255 exceptions can be treated as being implicitly wrapped in a call
256 that has such an abnormal return.
257
258 At present, no target needs to support more than one EH ABI.
259
260 * function_abis[N] is the ABI with identifier N. This can be useful
261 when referring back to ABIs that have been collected by number in
262 a bitmask, such as after walking function calls in a particular
263 region of code.
264
265 * default_function_abi refers specifically to the target's default
266 choice of ABI, regardless of which (if any) functions actually
267 use it. This ABI and data derived from it do *not* provide
268 globally conservatively-correct information, so it is only
269 useful in very specific circumstances. */
271};
272
274#if SWITCHABLE_TARGET
276#else
277#define this_target_function_abi_info (&default_target_function_abi_info)
278#endif
279
280/* See the comment above x_function_abis for when these macros should be used.
281 At present, eh_edge_abi is always the default ABI, but that could change
282 in future if a target needs it to. */
283#define function_abis \
284 (this_target_function_abi_info->x_function_abis)
285#define default_function_abi \
286 (this_target_function_abi_info->x_function_abis[0])
287#define eh_edge_abi default_function_abi
288
290 machine_mode mode);
291
292/* Return true if (reg:MODE REGNO) might be clobbered by one of the
293 calls in a region described by ABIS and MASK, where:
294
295 * Bit ID of ABIS is set if the region contains a call with
296 function_abi identifier ID.
297
298 * MASK contains all the registers that are fully or partially
299 clobbered by calls in the region.
300
301 This is not quite as accurate as testing each individual call,
302 but it's a close and conservatively-correct approximation.
303 It's much better for some targets than:
304
305 overlaps_hard_reg_set_p (MASK, MODE, REGNO). */
306
307inline bool
309 machine_mode mode, unsigned int regno)
310{
311 HARD_REG_SET clobbers = call_clobbers_in_region (abis, mask, mode);
312 return overlaps_hard_reg_set_p (clobbers, mode, regno);
313}
314
317extern function_abi insn_callee_abi (const rtx_insn *);
319
320#endif
Definition function-abi.h:215
HARD_REG_SET m_abi_clobbers[NUM_ABI_IDS]
Definition function-abi.h:229
function_abi_aggregator()
Definition function-abi.h:217
void note_callee_abi(const function_abi &abi)
Definition function-abi.h:221
HARD_REG_SET caller_save_regs(const function_abi &) const
Definition function-abi.cc:134
Definition function-abi.h:134
bool operator==(const function_abi &other) const
Definition function-abi.h:195
HARD_REG_SET full_and_partial_reg_clobbers() const
Definition function-abi.h:163
unsigned int id() const
Definition function-abi.h:151
HARD_REG_SET mode_clobbers(machine_mode mode) const
Definition function-abi.h:169
function_abi(const predefined_function_abi &base_abi, const_hard_reg_set mask)
Definition function-abi.h:143
function_abi(const predefined_function_abi &base_abi)
Definition function-abi.h:137
HARD_REG_SET m_mask
Definition function-abi.h:208
bool clobbers_full_reg_p(unsigned int regno) const
Definition function-abi.h:175
HARD_REG_SET full_reg_clobbers() const
Definition function-abi.h:157
bool clobbers_at_least_part_of_reg_p(unsigned int regno) const
Definition function-abi.h:182
const predefined_function_abi & base_abi() const
Definition function-abi.h:148
bool operator!=(const function_abi &other) const
Definition function-abi.h:201
bool clobbers_reg_p(machine_mode mode, unsigned int regno) const
Definition function-abi.h:189
const predefined_function_abi * m_base_abi
Definition function-abi.h:207
Definition function-abi.h:35
unsigned int id() const
Definition function-abi.h:39
unsigned int m_initialized
Definition function-abi.h:124
void add_full_reg_clobber(unsigned int)
Definition function-abi.cc:118
unsigned int m_id
Definition function-abi.h:123
HARD_REG_SET m_mode_clobbers[NUM_MACHINE_MODES]
Definition function-abi.h:127
void initialize(unsigned int, const_hard_reg_set)
Definition function-abi.cc:42
HARD_REG_SET full_and_partial_reg_clobbers() const
Definition function-abi.h:97
HARD_REG_SET m_full_and_partial_reg_clobbers
Definition function-abi.h:126
bool clobbers_at_least_part_of_reg_p(unsigned int regno) const
Definition function-abi.h:64
HARD_REG_SET full_reg_clobbers() const
Definition function-abi.h:85
bool clobbers_reg_p(machine_mode mode, unsigned int regno) const
Definition function-abi.h:73
HARD_REG_SET mode_clobbers(machine_mode mode) const
Definition function-abi.h:114
HARD_REG_SET m_full_reg_clobbers
Definition function-abi.h:125
bool clobbers_full_reg_p(unsigned int regno) const
Definition function-abi.h:49
bool initialized_p() const
Definition function-abi.h:42
const union tree_node * const_tree
Definition coretypes.h:98
target_function_abi_info default_target_function_abi_info
Definition function-abi.cc:32
bool call_clobbered_in_region_p(unsigned int abis, const_hard_reg_set mask, machine_mode mode, unsigned int regno)
Definition function-abi.h:308
function_abi expr_callee_abi(const_tree)
Definition function-abi.cc:237
function_abi insn_callee_abi(const rtx_insn *)
Definition function-abi.cc:219
HARD_REG_SET call_clobbers_in_region(unsigned int, const_hard_reg_set, machine_mode mode)
Definition function-abi.cc:179
const size_t NUM_ABI_IDS
Definition function-abi.h:31
function_abi fndecl_abi(const_tree)
Definition function-abi.cc:204
const predefined_function_abi & fntype_abi(const_tree)
Definition function-abi.cc:193
#define this_target_function_abi_info
Definition function-abi.h:277
#define TEST_HARD_REG_BIT(SET, BIT)
Definition hard-reg-set.h:170
HARD_REG_ELT_TYPE HARD_REG_SET
Definition hard-reg-set.h:47
const HARD_REG_SET const_hard_reg_set
Definition hard-reg-set.h:48
bool overlaps_hard_reg_set_p(const_hard_reg_set regs, machine_mode mode, unsigned int regno)
Definition regs.h:332
Definition rtl.h:546
Definition function-abi.h:233
predefined_function_abi x_function_abis[NUM_ABI_IDS]
Definition function-abi.h:270