GCC Middle and Back End API Reference
internal-fn.h
Go to the documentation of this file.
1/* Internal functions.
2 Copyright (C) 2011-2026 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_INTERNAL_FN_H
21#define GCC_INTERNAL_FN_H
22
23#include "insn-codes.h"
24#include "insn-opinit.h"
25
26
27/* INTEGER_CST values for IFN_UNIQUE function arg-0.
28
29 UNSPEC: Undifferentiated UNIQUE.
30
31 FORK and JOIN mark the points at which OpenACC partitioned
32 execution is entered or exited.
33 DEP_VAR = UNIQUE ({FORK,JOIN}, DEP_VAR, AXIS)
34
35 HEAD_MARK and TAIL_MARK are used to demark the sequence entering
36 or leaving partitioned execution.
37 DEP_VAR = UNIQUE ({HEAD,TAIL}_MARK, REMAINING_MARKS, ...PRIMARY_FLAGS)
38
39 The PRIMARY_FLAGS only occur on the first HEAD_MARK of a sequence.
40
41 PRIVATE captures variables to be made private at the surrounding parallelism
42 level. */
43#define IFN_UNIQUE_CODES \
44 DEF(UNSPEC), \
45 DEF(OACC_FORK), DEF(OACC_JOIN), \
46 DEF(OACC_HEAD_MARK), DEF(OACC_TAIL_MARK), \
47 DEF(OACC_PRIVATE)
48
50#define DEF(X) IFN_UNIQUE_##X
52#undef DEF
53};
54
55/* INTEGER_CST values for IFN_GOACC_LOOP arg-0. Allows the precise
56 stepping of the compute geometry over the loop iterations to be
57 deferred until it is known which compiler is generating the code.
58 The action is encoded in a constant first argument.
59
60 CHUNK_MAX = LOOP (CODE_CHUNKS, DIR, RANGE, STEP, CHUNK_SIZE, MASK)
61 STEP = LOOP (CODE_STEP, DIR, RANGE, STEP, CHUNK_SIZE, MASK)
62 OFFSET = LOOP (CODE_OFFSET, DIR, RANGE, STEP, CHUNK_SIZE, MASK, CHUNK_NO)
63 BOUND = LOOP (CODE_BOUND, DIR, RANGE, STEP, CHUNK_SIZE, MASK, OFFSET)
64
65 DIR - +1 for up loop, -1 for down loop
66 RANGE - Range of loop (END - BASE)
67 STEP - iteration step size
68 CHUNKING - size of chunking, (constant zero for no chunking)
69 CHUNK_NO - chunk number
70 MASK - partitioning mask. */
71
72#define IFN_GOACC_LOOP_CODES \
73 DEF(CHUNKS), DEF(STEP), DEF(OFFSET), DEF(BOUND)
75#define DEF(X) IFN_GOACC_LOOP_##X
77#undef DEF
78};
79
80/* The GOACC_REDUCTION function defines a generic interface to support
81 gang, worker and vector reductions. All calls are of the following
82 form:
83
84 V = REDUCTION (CODE, REF_TO_RES, LOCAL_VAR, LEVEL, OP, OFFSET)
85
86 REF_TO_RES - is a reference to the original reduction varl, may be NULL
87 LOCAL_VAR is the intermediate reduction variable
88 LEVEL corresponds to the GOMP_DIM of the reduction
89 OP is the tree code of the reduction operation
90 OFFSET may be used as an offset into a reduction array for the
91 reductions occurring at this level.
92 In general the return value is LOCAL_VAR, which creates a data
93 dependency between calls operating on the same reduction. */
94
95#define IFN_GOACC_REDUCTION_CODES \
96 DEF(SETUP), DEF(INIT), DEF(FINI), DEF(TEARDOWN)
98#define DEF(X) IFN_GOACC_REDUCTION_##X
100#undef DEF
101};
102
103/* Initialize internal function tables. */
104
105extern void init_internal_fns ();
106
107/* Return the name of internal function FN. The name is only meaningful
108 for dumps; it has no linkage. */
109
110extern const char *const internal_fn_name_array[];
111
112inline const char *
114{
115 return internal_fn_name_array[(int) fn];
116}
117
118extern internal_fn lookup_internal_fn (const char *);
121 internal_fn *);
123
124/* Return the ECF_* flags for function FN. */
125
126extern const int internal_fn_flags_array[];
127
128inline int
130{
131 return internal_fn_flags_array[(int) fn];
132}
133
134/* Return fnspec for function FN. */
135
136extern GTY(()) const_tree internal_fn_fnspec_array[IFN_LAST + 1];
137
138inline const_tree
140{
141 return internal_fn_fnspec_array[(int) fn];
142}
143
144/* Describes an internal function that maps directly to an optab. */
146{
147 /* optabs can be parameterized by one or two modes. These fields describe
148 how to select those modes from the types of the return value and
149 arguments. A value of -1 says that the mode is determined by the
150 return type while a value N >= 0 says that the mode is determined by
151 the type of argument N. A value of -2 says that this internal
152 function isn't directly mapped to an optab. */
153 signed int type0 : 8;
154 signed int type1 : 8;
155 /* True if the function is pointwise, so that it can be vectorized by
156 converting the return type and all argument types to vectors of the
157 same number of elements. E.g. we can vectorize an IFN_SQRT on
158 floats as an IFN_SQRT on vectors of N floats.
159
160 This only needs 1 bit, but occupies the full 8 to ensure a nice
161 layout. */
162 unsigned int vectorizable : 8;
163 /* The minimum and maximum number of arguments of a call to the
164 function. */
165 unsigned int nargs_min : 4;
166 unsigned int nargs_max : 4;
167};
168
169extern const direct_internal_fn_info direct_internal_fn_array[IFN_LAST + 1];
170
171/* Return true if FN is mapped directly to an optab. */
172
173inline bool
178
179/* Return true if FN is a direct internal function that can be vectorized by
180 converting the return type and all argument types to vectors of the same
181 number of elements. E.g. we can vectorize an IFN_SQRT on floats as an
182 IFN_SQRT on vectors of N floats. */
183
184inline bool
189
190/* Return optab information about internal function FN. Only meaningful
191 if direct_internal_fn_p (FN). */
192
193inline const direct_internal_fn_info &
199
200/* Return true if a call to FN can have NARGS arguments. FN must satisfy
201 direct_internal_fn_p. */
202
203inline bool
205{
207 return nargs >= info.nargs_min && nargs <= info.nargs_max;
208}
209
217
218/* Return true if FN is supported for types TYPE0 and TYPE1 when the
219 optimization type is OPT_TYPE. The types are those associated with
220 the "type0" and "type1" fields of FN's direct_internal_fn_info
221 structure. */
222
223inline bool
225 optimization_type opt_type)
226{
227 return direct_internal_fn_supported_p (fn, tree_pair (type0, type1),
228 opt_type);
229}
230
235extern bool widening_fn_p (code_helper);
237
238extern bool set_edom_supported_p (void);
239extern bool check_internal_fn_args (location_t, internal_fn, unsigned int,
240 const tree *);
241
249 tree_code *, tree (&)[3],
250 tree *, tree *, tree *);
251
252extern bool internal_load_fn_p (internal_fn);
253extern bool internal_store_fn_p (internal_fn);
263 tree, tree, int,
264 vec<int> * = nullptr);
266 vec<int> * = nullptr);
268 poly_uint64, unsigned int);
269
270/* Integer constants representing which else value is supported for masked load
271 functions. */
272#define MASK_LOAD_ELSE_ZERO -1
273#define MASK_LOAD_ELSE_M1 -2
274#define MASK_LOAD_ELSE_UNDEFINED -3
275
276extern void get_supported_else_vals (enum insn_code, unsigned, vec<int> &);
277extern bool supported_else_val_p (enum insn_code, unsigned, int);
278
279#define VECT_PARTIAL_BIAS_UNSUPPORTED 127
280
281extern signed char internal_len_load_store_bias (internal_fn ifn,
282 machine_mode);
283
284extern void expand_addsub_overflow (location_t, tree_code, tree, tree, tree,
285 bool, bool, bool, bool, tree *);
286extern void expand_internal_call (gcall *);
287extern void expand_internal_call (internal_fn, gcall *);
288extern void expand_PHI (internal_fn, gcall *);
289extern void expand_SHUFFLEVECTOR (internal_fn, gcall *);
290extern void expand_SPACESHIP (internal_fn, gcall *);
292extern void expand_ASSUME (internal_fn, gcall *);
293extern void expand_MASK_CALL (internal_fn, gcall *);
294extern void expand_VARYING (internal_fn, gcall *);
295extern void expand_MULBITINT (internal_fn, gcall *);
296extern void expand_DIVMODBITINT (internal_fn, gcall *);
297extern void expand_FLOATTOBITINT (internal_fn, gcall *);
298extern void expand_BITINTTOFLOAT (internal_fn, gcall *);
299extern void expand_CLRSB (internal_fn, gcall *);
300extern void expand_CLZ (internal_fn, gcall *);
301extern void expand_CTZ (internal_fn, gcall *);
302extern void expand_FFS (internal_fn, gcall *);
303extern void expand_PARITY (internal_fn, gcall *);
304extern void expand_POPCOUNT (internal_fn, gcall *);
305extern void expand_BSWAP (internal_fn, gcall *);
306extern void expand_BITREVERSE (internal_fn, gcall *);
307extern void expand_CLMUL (internal_fn, gcall *);
308extern void expand_CLMUL_WIDEN (internal_fn, gcall *);
309extern void expand_BITCOMPRESS (internal_fn, gcall *);
310extern void expand_BITEXPAND (internal_fn, gcall *);
311
313
314enum {
321};
322
323#endif
Definition tree.h:84
std::pair< tree, tree > tree_pair
Definition coretypes.h:388
const union tree_node * const_tree
Definition coretypes.h:98
#define GTY(x)
Definition coretypes.h:41
union tree_node * tree
Definition coretypes.h:97
optimization_type
Definition coretypes.h:289
internal_fn
Definition genmatch.cc:1024
tree_code
Definition genmatch.cc:1011
enum optab_tag optab
int first_commutative_argument(code_helper code, tree type)
Definition gimple-match-exports.cc:1335
internal_fn get_conditional_internal_fn(code_helper code, tree type)
Definition gimple-match-exports.cc:1409
bool set_edom_supported_p(void)
Definition internal-fn.cc:4894
bool commutative_binary_fn_p(internal_fn fn)
Definition internal-fn.cc:4671
bool supported_else_val_p(enum insn_code icode, unsigned else_index, int else_val)
Definition internal-fn.cc:5595
signed char internal_len_load_store_bias(internal_fn ifn, machine_mode mode)
Definition internal-fn.cc:5690
bool internal_check_ptrs_fn_supported_p(internal_fn ifn, tree type, poly_uint64 length, unsigned int align)
Definition internal-fn.cc:5670
void expand_DIVMODBITINT(internal_fn, gcall *stmt)
Definition internal-fn.cc:5850
internal_fn get_conditional_len_internal_fn(tree_code code)
Definition internal-fn.cc:5022
internal_fn get_unconditional_internal_fn(internal_fn ifn)
Definition internal-fn.cc:5112
bool vectorized_internal_fn_supported_p(internal_fn ifn, tree type)
Definition internal-fn.cc:5750
bool internal_load_fn_p(internal_fn fn)
Definition internal-fn.cc:5213
void expand_BITINTTOFLOAT(internal_fn, gcall *stmt)
Definition internal-fn.cc:5873
void expand_FLOATTOBITINT(internal_fn, gcall *stmt)
Definition internal-fn.cc:5861
bool widening_evenodd_fn_p(code_helper code)
Definition internal-fn.cc:4817
bool internal_gather_scatter_fn_supported_p(internal_fn ifn, tree vector_type, tree memory_element_type, tree offset_vector_type, int scale, vec< int > *elsvals)
Definition internal-fn.cc:5618
void expand_BITCOMPRESS(internal_fn, gcall *stmt)
Definition internal-fn.cc:6529
void expand_internal_call(internal_fn fn, gcall *stmt)
Definition internal-fn.cc:5731
internal_fn lookup_internal_fn(const char *name)
Definition internal-fn.cc:82
void expand_PARITY(internal_fn fn, gcall *stmt)
Definition internal-fn.cc:5998
void expand_MULBITINT(internal_fn, gcall *stmt)
Definition internal-fn.cc:5839
const direct_internal_fn_info direct_internal_fn_array[IFN_LAST+1]
Definition internal-fn.cc:207
void expand_CLMUL(internal_fn, gcall *stmt)
Definition internal-fn.cc:6354
bool commutative_ternary_fn_p(internal_fn fn)
Definition internal-fn.cc:4707
void init_internal_fns()
Definition internal-fn.cc:148
void get_supported_else_vals(enum insn_code icode, unsigned else_index, vec< int > &else_vals)
Definition internal-fn.cc:5566
const_tree internal_fn_fnspec_array[IFN_LAST+1]
Definition internal-fn.cc:145
void expand_POPCOUNT(internal_fn fn, gcall *stmt)
Definition internal-fn.cc:6005
void expand_CLZ(internal_fn fn, gcall *stmt)
Definition internal-fn.cc:5979
int internal_fn_len_index(internal_fn fn)
Definition internal-fn.cc:5280
int internal_fn_offset_index(internal_fn fn)
Definition internal-fn.cc:5517
tree_pair direct_internal_fn_types(internal_fn fn, tree return_type, tree *args)
Definition internal-fn.cc:4410
const char *const internal_fn_name_array[]
Definition internal-fn.cc:65
bool internal_store_fn_p(internal_fn fn)
Definition internal-fn.cc:5236
bool check_internal_fn_args(location_t loc, internal_fn fn, unsigned int nargs, const tree *args)
Definition internal-fn.cc:4844
void expand_SHUFFLEVECTOR(internal_fn, gcall *)
Definition internal-fn.cc:5782
void expand_CLRSB(internal_fn fn, gcall *stmt)
Definition internal-fn.cc:5913
const int internal_fn_flags_array[]
Definition internal-fn.cc:72
void expand_BITEXPAND(internal_fn, gcall *stmt)
Definition internal-fn.cc:6741
int internal_fn_mask_index(internal_fn fn)
Definition internal-fn.cc:5426
bool widening_fn_p(code_helper code)
Definition internal-fn.cc:4787
optab direct_internal_fn_optab(internal_fn fn, tree_pair types)
Definition internal-fn.cc:4527
int internal_fn_stored_value_index(internal_fn fn)
Definition internal-fn.cc:5464
void expand_BITREVERSE(internal_fn fn, gcall *stmt)
Definition internal-fn.cc:6105
void expand_PHI(internal_fn, gcall *)
Definition internal-fn.cc:5788
void lookup_hilo_internal_fn(internal_fn ifn, internal_fn *lo, internal_fn *hi)
Definition internal-fn.cc:102
bool associative_binary_fn_p(internal_fn fn)
Definition internal-fn.cc:4726
int internal_fn_scale_index(internal_fn fn)
Definition internal-fn.cc:5541
internal_fn get_len_internal_fn(internal_fn fn)
Definition internal-fn.cc:5080
void expand_MASK_CALL(internal_fn, gcall *)
Definition internal-fn.cc:5825
void expand_FFS(internal_fn fn, gcall *stmt)
Definition internal-fn.cc:5991
bool direct_internal_fn_supported_p(internal_fn fn, tree_pair types, optimization_type opt_type)
Definition internal-fn.cc:4612
bool can_interpret_as_conditional_op_p(gimple *stmt, tree *cond_out, tree_code *code_out, tree(&ops)[3], tree *else_out, tree *len, tree *bias)
Definition internal-fn.cc:5159
void expand_CLMUL_WIDEN(internal_fn, gcall *stmt)
Definition internal-fn.cc:6384
void expand_CTZ(internal_fn fn, gcall *stmt)
Definition internal-fn.cc:5985
bool internal_gather_scatter_fn_p(internal_fn fn)
Definition internal-fn.cc:5259
void expand_BSWAP(internal_fn fn, gcall *stmt)
Definition internal-fn.cc:6098
void lookup_evenodd_internal_fn(internal_fn ifn, internal_fn *even, internal_fn *odd)
Definition internal-fn.cc:124
void expand_VARYING(internal_fn, gcall *)
Definition internal-fn.cc:5832
void expand_addsub_overflow(location_t loc, tree_code code, tree lhs, tree arg0, tree arg1, bool unsr_p, bool uns0_p, bool uns1_p, bool is_ubsan, tree *datap)
Definition internal-fn.cc:1209
void expand_SPACESHIP(internal_fn, gcall *stmt)
Definition internal-fn.cc:5794
bool internal_strided_fn_supported_p(internal_fn ifn, tree vector_type, vec< int > *elsvals)
Definition internal-fn.cc:5650
int internal_fn_alias_ptr_index(internal_fn fn)
Definition internal-fn.cc:5494
void expand_ASSUME(internal_fn, gcall *)
Definition internal-fn.cc:5820
tree_code conditional_internal_fn_code(internal_fn ifn)
Definition internal-fn.cc:4985
int internal_fn_else_index(internal_fn fn)
Definition internal-fn.cc:5341
bool vectorizable_internal_fn_p(internal_fn fn)
Definition internal-fn.h:185
const direct_internal_fn_info & direct_internal_fn(internal_fn fn)
Definition internal-fn.h:194
bool direct_internal_fn_p(internal_fn fn)
Definition internal-fn.h:174
#define IFN_GOACC_REDUCTION_CODES
Definition internal-fn.h:95
@ ATOMIC_OP_FETCH_CMP_0_EQ
Definition internal-fn.h:315
@ ATOMIC_OP_FETCH_CMP_0_GT
Definition internal-fn.h:319
@ ATOMIC_OP_FETCH_CMP_0_LE
Definition internal-fn.h:318
@ ATOMIC_OP_FETCH_CMP_0_LT
Definition internal-fn.h:317
@ ATOMIC_OP_FETCH_CMP_0_GE
Definition internal-fn.h:320
@ ATOMIC_OP_FETCH_CMP_0_NE
Definition internal-fn.h:316
const_tree internal_fn_fnspec(enum internal_fn fn)
Definition internal-fn.h:139
int internal_fn_flags(enum internal_fn fn)
Definition internal-fn.h:129
const char * internal_fn_name(enum internal_fn fn)
Definition internal-fn.h:113
#define IFN_GOACC_LOOP_CODES
Definition internal-fn.h:72
ifn_unique_kind
Definition internal-fn.h:49
ifn_goacc_loop_kind
Definition internal-fn.h:74
void expand_TRAP(internal_fn, gcall *)
#define IFN_UNIQUE_CODES
Definition internal-fn.h:43
ifn_goacc_reduction_kind
Definition internal-fn.h:97
bool direct_internal_fn_nargs_ok_p(internal_fn fn, unsigned int nargs)
Definition internal-fn.h:204
poly_int< NUM_POLY_INT_COEFFS, unsigned HOST_WIDE_INT > poly_uint64
Definition poly-int-types.h:25
Definition internal-fn.h:146
unsigned int nargs_max
Definition internal-fn.h:166
signed int type1
Definition internal-fn.h:154
signed int type0
Definition internal-fn.h:153
unsigned int nargs_min
Definition internal-fn.h:165
unsigned int vectorizable
Definition internal-fn.h:162
Definition gimple.h:356
Definition gimple.h:225
Definition vec.h:450
#define gcc_checking_assert(EXPR)
Definition system.h:765