1/* Internal functions.
2 Copyright (C) 2011-2017 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/* INTEGER_CST values for IFN_UNIQUE function arg-0.
24
25 UNSPEC: Undifferentiated UNIQUE.
26
27 FORK and JOIN mark the points at which OpenACC partitioned
28 execution is entered or exited.
29 DEP_VAR = UNIQUE ({FORK,JOIN}, DEP_VAR, AXIS)
30
31 HEAD_MARK and TAIL_MARK are used to demark the sequence entering
32 or leaving partitioned execution.
33 DEP_VAR = UNIQUE ({HEAD,TAIL}_MARK, REMAINING_MARKS, ...PRIMARY_FLAGS)
34
35 The PRIMARY_FLAGS only occur on the first HEAD_MARK of a sequence. */
36#define IFN_UNIQUE_CODES \
37 DEF(UNSPEC), \
38 DEF(OACC_FORK), DEF(OACC_JOIN), \
39 DEF(OACC_HEAD_MARK), DEF(OACC_TAIL_MARK)
40
41enum ifn_unique_kind {
42#define DEF(X) IFN_UNIQUE_##X
43 IFN_UNIQUE_CODES
44#undef DEF
45};
46
47/* INTEGER_CST values for IFN_GOACC_LOOP arg-0. Allows the precise
48 stepping of the compute geometry over the loop iterations to be
49 deferred until it is known which compiler is generating the code.
50 The action is encoded in a constant first argument.
51
52 CHUNK_MAX = LOOP (CODE_CHUNKS, DIR, RANGE, STEP, CHUNK_SIZE, MASK)
53 STEP = LOOP (CODE_STEP, DIR, RANGE, STEP, CHUNK_SIZE, MASK)
54 OFFSET = LOOP (CODE_OFFSET, DIR, RANGE, STEP, CHUNK_SIZE, MASK, CHUNK_NO)
55 BOUND = LOOP (CODE_BOUND, DIR, RANGE, STEP, CHUNK_SIZE, MASK, OFFSET)
56
57 DIR - +1 for up loop, -1 for down loop
58 RANGE - Range of loop (END - BASE)
59 STEP - iteration step size
60 CHUNKING - size of chunking, (constant zero for no chunking)
61 CHUNK_NO - chunk number
62 MASK - partitioning mask. */
63
64#define IFN_GOACC_LOOP_CODES \
65 DEF(CHUNKS), DEF(STEP), DEF(OFFSET), DEF(BOUND)
66enum ifn_goacc_loop_kind {
67#define DEF(X) IFN_GOACC_LOOP_##X
68 IFN_GOACC_LOOP_CODES
69#undef DEF
70};
71
72/* The GOACC_REDUCTION function defines a generic interface to support
73 gang, worker and vector reductions. All calls are of the following
74 form:
75
76 V = REDUCTION (CODE, REF_TO_RES, LOCAL_VAR, LEVEL, OP, OFFSET)
77
78 REF_TO_RES - is a reference to the original reduction varl, may be NULL
79 LOCAL_VAR is the intermediate reduction variable
80 LEVEL corresponds to the GOMP_DIM of the reduction
81 OP is the tree code of the reduction operation
82 OFFSET may be used as an offset into a reduction array for the
83 reductions occuring at this level.
84 In general the return value is LOCAL_VAR, which creates a data
85 dependency between calls operating on the same reduction. */
86
87#define IFN_GOACC_REDUCTION_CODES \
88 DEF(SETUP), DEF(INIT), DEF(FINI), DEF(TEARDOWN)
89enum ifn_goacc_reduction_kind {
90#define DEF(X) IFN_GOACC_REDUCTION_##X
91 IFN_GOACC_REDUCTION_CODES
92#undef DEF
93};
94
95/* Initialize internal function tables. */
96
97extern void init_internal_fns ();
98
99/* Return the name of internal function FN. The name is only meaningful
100 for dumps; it has no linkage. */
101
102extern const char *const internal_fn_name_array[];
103
104static inline const char *
105internal_fn_name (enum internal_fn fn)
106{
107 return internal_fn_name_array[(int) fn];
108}
109
110/* Return the ECF_* flags for function FN. */
111
112extern const int internal_fn_flags_array[];
113
114static inline int
115internal_fn_flags (enum internal_fn fn)
116{
117 return internal_fn_flags_array[(int) fn];
118}
119
120/* Return fnspec for function FN. */
121
122extern GTY(()) const_tree internal_fn_fnspec_array[IFN_LAST + 1];
123
124static inline const_tree
125internal_fn_fnspec (enum internal_fn fn)
126{
127 return internal_fn_fnspec_array[(int) fn];
128}
129
130/* Describes an internal function that maps directly to an optab. */
131struct direct_internal_fn_info
132{
133 /* optabs can be parameterized by one or two modes. These fields describe
134 how to select those modes from the types of the return value and
135 arguments. A value of -1 says that the mode is determined by the
136 return type while a value N >= 0 says that the mode is determined by
137 the type of argument N. A value of -2 says that this internal
138 function isn't directly mapped to an optab. */
139 signed int type0 : 8;
140 signed int type1 : 8;
141 /* True if the function is pointwise, so that it can be vectorized by
142 converting the return type and all argument types to vectors of the
143 same number of elements. E.g. we can vectorize an IFN_SQRT on
144 floats as an IFN_SQRT on vectors of N floats.
145
146 This only needs 1 bit, but occupies the full 16 to ensure a nice
147 layout. */
148 unsigned int vectorizable : 16;
149};
150
151extern const direct_internal_fn_info direct_internal_fn_array[IFN_LAST + 1];
152
153/* Return true if FN is mapped directly to an optab. */
154
155inline bool
156direct_internal_fn_p (internal_fn fn)
157{
158 return direct_internal_fn_array[fn].type0 >= -1;
159}
160
161/* Return optab information about internal function FN. Only meaningful
162 if direct_internal_fn_p (FN). */
163
164inline const direct_internal_fn_info &
165direct_internal_fn (internal_fn fn)
166{
167 gcc_checking_assert (direct_internal_fn_p (fn));
168 return direct_internal_fn_array[fn];
169}
170
171extern tree_pair direct_internal_fn_types (internal_fn, tree, tree *);
172extern tree_pair direct_internal_fn_types (internal_fn, gcall *);
173extern bool direct_internal_fn_supported_p (internal_fn, tree_pair,
174 optimization_type);
175extern bool direct_internal_fn_supported_p (internal_fn, tree,
176 optimization_type);
177extern bool set_edom_supported_p (void);
178
179extern void expand_internal_call (gcall *);
180extern void expand_internal_call (internal_fn, gcall *);
181extern void expand_PHI (internal_fn, gcall *);
182
183#endif
184