vect: Ensure both NITERSM1 and NITERS are INTEGER_CSTs or neither of them [PR113210]
[official-gcc.git] / gcc / function-abi.h
blobcbc4d3e02c15e5109ea07fd71a0fb32b48658772
1 /* Information about function binary interfaces.
2 Copyright (C) 2019-2024 Free Software Foundation, Inc.
4 This file is part of GCC
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
9 version.
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 for more details.
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
20 #ifndef GCC_FUNCTION_ABI_H
21 #define GCC_FUNCTION_ABI_H
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.
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. */
31 const size_t NUM_ABI_IDS = 8;
33 /* Information about one of the target's predefined ABIs. */
34 class predefined_function_abi
36 public:
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; }
41 /* True if this ABI has been initialized. */
42 bool initialized_p () const { return m_initialized; }
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
51 return TEST_HARD_REG_BIT (m_full_reg_clobbers, regno);
54 /* Return true if a function call is allowed to alter some or all bits
55 of register REGNO.
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
66 return TEST_HARD_REG_BIT (m_full_and_partial_reg_clobbers, regno);
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
75 return overlaps_hard_reg_set_p (m_mode_clobbers[mode], mode, regno);
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).
83 These registers cannot hold any part of a value that is live across
84 a call. */
85 HARD_REG_SET full_reg_clobbers () const { return m_full_reg_clobbers; }
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 ().
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. */
96 HARD_REG_SET
97 full_and_partial_reg_clobbers () const
99 return m_full_and_partial_reg_clobbers;
102 /* Return the set of registers that cannot be used to hold a value of
103 mode MODE across a function call. That is:
105 (reg:REGNO MODE)
107 might be clobbered by a call whenever:
109 overlaps_hard_reg_set (mode_clobbers (MODE), MODE, REGNO)
111 In allocation terms, the registers in the returned set conflict
112 with any value of mode MODE that is live across a call. */
113 HARD_REG_SET
114 mode_clobbers (machine_mode mode) const
116 return m_mode_clobbers[mode];
119 void initialize (unsigned int, const_hard_reg_set);
120 void add_full_reg_clobber (unsigned int);
122 private:
123 unsigned int m_id : NUM_ABI_IDS;
124 unsigned int m_initialized : 1;
125 HARD_REG_SET m_full_reg_clobbers;
126 HARD_REG_SET m_full_and_partial_reg_clobbers;
127 HARD_REG_SET m_mode_clobbers[NUM_MACHINE_MODES];
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. */
133 class function_abi
135 public:
136 /* Initialize the structure for a general function with the given ABI. */
137 function_abi (const predefined_function_abi &base_abi)
138 : m_base_abi (&base_abi),
139 m_mask (base_abi.full_and_partial_reg_clobbers ()) {}
141 /* Initialize the structure for a function that has the given ABI and
142 that is known not to clobber registers outside MASK. */
143 function_abi (const predefined_function_abi &base_abi,
144 const_hard_reg_set mask)
145 : m_base_abi (&base_abi), m_mask (mask) {}
147 /* The predefined ABI from which this ABI is derived. */
148 const predefined_function_abi &base_abi () const { return *m_base_abi; }
150 /* The target-specific identifier of the predefined ABI. */
151 unsigned int id () const { return m_base_abi->id (); }
153 /* See the corresponding predefined_function_abi functions for
154 details about the following functions. */
156 HARD_REG_SET
157 full_reg_clobbers () const
159 return m_mask & m_base_abi->full_reg_clobbers ();
162 HARD_REG_SET
163 full_and_partial_reg_clobbers () const
165 return m_mask & m_base_abi->full_and_partial_reg_clobbers ();
168 HARD_REG_SET
169 mode_clobbers (machine_mode mode) const
171 return m_mask & m_base_abi->mode_clobbers (mode);
174 bool
175 clobbers_full_reg_p (unsigned int regno) const
177 return (TEST_HARD_REG_BIT (m_mask, regno)
178 & m_base_abi->clobbers_full_reg_p (regno));
181 bool
182 clobbers_at_least_part_of_reg_p (unsigned int regno) const
184 return (TEST_HARD_REG_BIT (m_mask, regno)
185 & m_base_abi->clobbers_at_least_part_of_reg_p (regno));
188 bool
189 clobbers_reg_p (machine_mode mode, unsigned int regno) const
191 return overlaps_hard_reg_set_p (mode_clobbers (mode), mode, regno);
194 bool
195 operator== (const function_abi &other) const
197 return m_base_abi == other.m_base_abi && m_mask == other.m_mask;
200 bool
201 operator!= (const function_abi &other) const
203 return !operator== (other);
206 protected:
207 const predefined_function_abi *m_base_abi;
208 HARD_REG_SET m_mask;
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. */
214 class function_abi_aggregator
216 public:
217 function_abi_aggregator () : m_abi_clobbers () {}
219 /* Record that the code region calls a function with the given ABI. */
220 void
221 note_callee_abi (const function_abi &abi)
223 m_abi_clobbers[abi.id ()] |= abi.full_and_partial_reg_clobbers ();
226 HARD_REG_SET caller_save_regs (const function_abi &) const;
228 private:
229 HARD_REG_SET m_abi_clobbers[NUM_ABI_IDS];
232 struct target_function_abi_info
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.
239 There are various ways of getting an ABI descriptor:
241 * fndecl_abi (FNDECL) is the ABI of function FNDECL.
243 * fntype_abi (FNTYPE) is the ABI of a function with type FNTYPE.
245 * crtl->abi is the ABI of the function that we are currently
246 compiling to rtl.
248 * insn_callee_abi (INSN) is the ABI used by the target of call insn INSN.
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.
258 At present, no target needs to support more than one EH ABI.
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.
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. */
270 predefined_function_abi x_function_abis[NUM_ABI_IDS];
273 extern target_function_abi_info default_target_function_abi_info;
274 #if SWITCHABLE_TARGET
275 extern target_function_abi_info *this_target_function_abi_info;
276 #else
277 #define this_target_function_abi_info (&default_target_function_abi_info)
278 #endif
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
289 extern HARD_REG_SET call_clobbers_in_region (unsigned int, const_hard_reg_set,
290 machine_mode mode);
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:
295 * Bit ID of ABIS is set if the region contains a call with
296 function_abi identifier ID.
298 * MASK contains all the registers that are fully or partially
299 clobbered by calls in the region.
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:
305 overlaps_hard_reg_set_p (MASK, MODE, REGNO). */
307 inline bool
308 call_clobbered_in_region_p (unsigned int abis, const_hard_reg_set mask,
309 machine_mode mode, unsigned int regno)
311 HARD_REG_SET clobbers = call_clobbers_in_region (abis, mask, mode);
312 return overlaps_hard_reg_set_p (clobbers, mode, regno);
315 extern const predefined_function_abi &fntype_abi (const_tree);
316 extern function_abi fndecl_abi (const_tree);
317 extern function_abi insn_callee_abi (const rtx_insn *);
318 extern function_abi expr_callee_abi (const_tree);
320 #endif