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