* ipa-devirt.c (type_pair, default_hashset_traits): New types.
[official-gcc.git] / gcc / machmode.h
blob8d6ea187b4dc535a355d23e2aaf87ec0e9f039a3
1 /* Machine mode definitions for GCC; included by rtl.h and tree.h.
2 Copyright (C) 1991-2014 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 HAVE_MACHINE_MODES
21 #define HAVE_MACHINE_MODES
23 /* Make an enum class that gives all the machine modes. */
24 #include "insn-modes.h"
26 /* Get the name of mode MODE as a string. */
28 extern const char * const mode_name[NUM_MACHINE_MODES];
29 #define GET_MODE_NAME(MODE) mode_name[MODE]
31 /* Mode classes. */
33 #include "mode-classes.def"
34 #define DEF_MODE_CLASS(M) M
35 enum mode_class { MODE_CLASSES, MAX_MODE_CLASS };
36 #undef DEF_MODE_CLASS
37 #undef MODE_CLASSES
39 /* Get the general kind of object that mode MODE represents
40 (integer, floating, complex, etc.) */
42 extern const unsigned char mode_class[NUM_MACHINE_MODES];
43 #define GET_MODE_CLASS(MODE) ((enum mode_class) mode_class[MODE])
45 /* Nonzero if MODE is an integral mode. */
46 #define INTEGRAL_MODE_P(MODE) \
47 (GET_MODE_CLASS (MODE) == MODE_INT \
48 || GET_MODE_CLASS (MODE) == MODE_PARTIAL_INT \
49 || GET_MODE_CLASS (MODE) == MODE_COMPLEX_INT \
50 || GET_MODE_CLASS (MODE) == MODE_VECTOR_INT)
52 /* Nonzero if MODE is a floating-point mode. */
53 #define FLOAT_MODE_P(MODE) \
54 (GET_MODE_CLASS (MODE) == MODE_FLOAT \
55 || GET_MODE_CLASS (MODE) == MODE_DECIMAL_FLOAT \
56 || GET_MODE_CLASS (MODE) == MODE_COMPLEX_FLOAT \
57 || GET_MODE_CLASS (MODE) == MODE_VECTOR_FLOAT)
59 /* Nonzero if MODE is a complex mode. */
60 #define COMPLEX_MODE_P(MODE) \
61 (GET_MODE_CLASS (MODE) == MODE_COMPLEX_INT \
62 || GET_MODE_CLASS (MODE) == MODE_COMPLEX_FLOAT)
64 /* Nonzero if MODE is a vector mode. */
65 #define VECTOR_MODE_P(MODE) \
66 (GET_MODE_CLASS (MODE) == MODE_VECTOR_INT \
67 || GET_MODE_CLASS (MODE) == MODE_VECTOR_FLOAT \
68 || GET_MODE_CLASS (MODE) == MODE_VECTOR_FRACT \
69 || GET_MODE_CLASS (MODE) == MODE_VECTOR_UFRACT \
70 || GET_MODE_CLASS (MODE) == MODE_VECTOR_ACCUM \
71 || GET_MODE_CLASS (MODE) == MODE_VECTOR_UACCUM)
73 /* Nonzero if MODE is a scalar integral mode. */
74 #define SCALAR_INT_MODE_P(MODE) \
75 (GET_MODE_CLASS (MODE) == MODE_INT \
76 || GET_MODE_CLASS (MODE) == MODE_PARTIAL_INT)
78 /* Nonzero if MODE is a scalar floating point mode. */
79 #define SCALAR_FLOAT_MODE_P(MODE) \
80 (GET_MODE_CLASS (MODE) == MODE_FLOAT \
81 || GET_MODE_CLASS (MODE) == MODE_DECIMAL_FLOAT)
83 /* Nonzero if MODE is a decimal floating point mode. */
84 #define DECIMAL_FLOAT_MODE_P(MODE) \
85 (GET_MODE_CLASS (MODE) == MODE_DECIMAL_FLOAT)
87 /* Nonzero if MODE is a scalar fract mode. */
88 #define SCALAR_FRACT_MODE_P(MODE) \
89 (GET_MODE_CLASS (MODE) == MODE_FRACT)
91 /* Nonzero if MODE is a scalar ufract mode. */
92 #define SCALAR_UFRACT_MODE_P(MODE) \
93 (GET_MODE_CLASS (MODE) == MODE_UFRACT)
95 /* Nonzero if MODE is a scalar fract or ufract mode. */
96 #define ALL_SCALAR_FRACT_MODE_P(MODE) \
97 (SCALAR_FRACT_MODE_P (MODE) || SCALAR_UFRACT_MODE_P (MODE))
99 /* Nonzero if MODE is a scalar accum mode. */
100 #define SCALAR_ACCUM_MODE_P(MODE) \
101 (GET_MODE_CLASS (MODE) == MODE_ACCUM)
103 /* Nonzero if MODE is a scalar uaccum mode. */
104 #define SCALAR_UACCUM_MODE_P(MODE) \
105 (GET_MODE_CLASS (MODE) == MODE_UACCUM)
107 /* Nonzero if MODE is a scalar accum or uaccum mode. */
108 #define ALL_SCALAR_ACCUM_MODE_P(MODE) \
109 (SCALAR_ACCUM_MODE_P (MODE) || SCALAR_UACCUM_MODE_P (MODE))
111 /* Nonzero if MODE is a scalar fract or accum mode. */
112 #define SIGNED_SCALAR_FIXED_POINT_MODE_P(MODE) \
113 (SCALAR_FRACT_MODE_P (MODE) || SCALAR_ACCUM_MODE_P (MODE))
115 /* Nonzero if MODE is a scalar ufract or uaccum mode. */
116 #define UNSIGNED_SCALAR_FIXED_POINT_MODE_P(MODE) \
117 (SCALAR_UFRACT_MODE_P (MODE) || SCALAR_UACCUM_MODE_P (MODE))
119 /* Nonzero if MODE is a scalar fract, ufract, accum or uaccum mode. */
120 #define ALL_SCALAR_FIXED_POINT_MODE_P(MODE) \
121 (SIGNED_SCALAR_FIXED_POINT_MODE_P (MODE) \
122 || UNSIGNED_SCALAR_FIXED_POINT_MODE_P (MODE))
124 /* Nonzero if MODE is a scalar/vector fract mode. */
125 #define FRACT_MODE_P(MODE) \
126 (GET_MODE_CLASS (MODE) == MODE_FRACT \
127 || GET_MODE_CLASS (MODE) == MODE_VECTOR_FRACT)
129 /* Nonzero if MODE is a scalar/vector ufract mode. */
130 #define UFRACT_MODE_P(MODE) \
131 (GET_MODE_CLASS (MODE) == MODE_UFRACT \
132 || GET_MODE_CLASS (MODE) == MODE_VECTOR_UFRACT)
134 /* Nonzero if MODE is a scalar/vector fract or ufract mode. */
135 #define ALL_FRACT_MODE_P(MODE) \
136 (FRACT_MODE_P (MODE) || UFRACT_MODE_P (MODE))
138 /* Nonzero if MODE is a scalar/vector accum mode. */
139 #define ACCUM_MODE_P(MODE) \
140 (GET_MODE_CLASS (MODE) == MODE_ACCUM \
141 || GET_MODE_CLASS (MODE) == MODE_VECTOR_ACCUM)
143 /* Nonzero if MODE is a scalar/vector uaccum mode. */
144 #define UACCUM_MODE_P(MODE) \
145 (GET_MODE_CLASS (MODE) == MODE_UACCUM \
146 || GET_MODE_CLASS (MODE) == MODE_VECTOR_UACCUM)
148 /* Nonzero if MODE is a scalar/vector accum or uaccum mode. */
149 #define ALL_ACCUM_MODE_P(MODE) \
150 (ACCUM_MODE_P (MODE) || UACCUM_MODE_P (MODE))
152 /* Nonzero if MODE is a scalar/vector fract or accum mode. */
153 #define SIGNED_FIXED_POINT_MODE_P(MODE) \
154 (FRACT_MODE_P (MODE) || ACCUM_MODE_P (MODE))
156 /* Nonzero if MODE is a scalar/vector ufract or uaccum mode. */
157 #define UNSIGNED_FIXED_POINT_MODE_P(MODE) \
158 (UFRACT_MODE_P (MODE) || UACCUM_MODE_P (MODE))
160 /* Nonzero if MODE is a scalar/vector fract, ufract, accum or uaccum mode. */
161 #define ALL_FIXED_POINT_MODE_P(MODE) \
162 (SIGNED_FIXED_POINT_MODE_P (MODE) \
163 || UNSIGNED_FIXED_POINT_MODE_P (MODE))
165 /* Nonzero if CLASS modes can be widened. */
166 #define CLASS_HAS_WIDER_MODES_P(CLASS) \
167 (CLASS == MODE_INT \
168 || CLASS == MODE_PARTIAL_INT \
169 || CLASS == MODE_FLOAT \
170 || CLASS == MODE_DECIMAL_FLOAT \
171 || CLASS == MODE_COMPLEX_FLOAT \
172 || CLASS == MODE_FRACT \
173 || CLASS == MODE_UFRACT \
174 || CLASS == MODE_ACCUM \
175 || CLASS == MODE_UACCUM)
177 /* Get the size in bytes and bits of an object of mode MODE. */
179 extern CONST_MODE_SIZE unsigned char mode_size[NUM_MACHINE_MODES];
180 #if GCC_VERSION >= 4001
181 #define GET_MODE_SIZE(MODE) \
182 ((unsigned short) (__builtin_constant_p (MODE) \
183 ? mode_size_inline (MODE) : mode_size[MODE]))
184 #else
185 #define GET_MODE_SIZE(MODE) ((unsigned short) mode_size[MODE])
186 #endif
187 #define GET_MODE_BITSIZE(MODE) \
188 ((unsigned short) (GET_MODE_SIZE (MODE) * BITS_PER_UNIT))
190 /* Get the number of value bits of an object of mode MODE. */
191 extern const unsigned short mode_precision[NUM_MACHINE_MODES];
192 #define GET_MODE_PRECISION(MODE) mode_precision[MODE]
194 /* Get the number of integral bits of an object of mode MODE. */
195 extern CONST_MODE_IBIT unsigned char mode_ibit[NUM_MACHINE_MODES];
196 #define GET_MODE_IBIT(MODE) mode_ibit[MODE]
198 /* Get the number of fractional bits of an object of mode MODE. */
199 extern CONST_MODE_FBIT unsigned char mode_fbit[NUM_MACHINE_MODES];
200 #define GET_MODE_FBIT(MODE) mode_fbit[MODE]
202 /* Get a bitmask containing 1 for all bits in a word
203 that fit within mode MODE. */
205 extern const unsigned HOST_WIDE_INT mode_mask_array[NUM_MACHINE_MODES];
207 #define GET_MODE_MASK(MODE) mode_mask_array[MODE]
209 /* Return the mode of the inner elements in a vector. */
211 extern const unsigned char mode_inner[NUM_MACHINE_MODES];
212 #if GCC_VERSION >= 4001
213 #define GET_MODE_INNER(MODE) \
214 ((enum machine_mode) (__builtin_constant_p (MODE) \
215 ? mode_inner_inline (MODE) : mode_inner[MODE]))
216 #else
217 #define GET_MODE_INNER(MODE) ((enum machine_mode) mode_inner[MODE])
218 #endif
220 /* Get the size in bytes or bites of the basic parts of an
221 object of mode MODE. */
223 #define GET_MODE_UNIT_SIZE(MODE) \
224 (GET_MODE_INNER (MODE) == VOIDmode \
225 ? GET_MODE_SIZE (MODE) \
226 : GET_MODE_SIZE (GET_MODE_INNER (MODE)))
228 #define GET_MODE_UNIT_BITSIZE(MODE) \
229 ((unsigned short) (GET_MODE_UNIT_SIZE (MODE) * BITS_PER_UNIT))
231 #define GET_MODE_UNIT_PRECISION(MODE) \
232 (GET_MODE_INNER (MODE) == VOIDmode \
233 ? GET_MODE_PRECISION (MODE) \
234 : GET_MODE_PRECISION (GET_MODE_INNER (MODE)))
236 /* Get the number of units in the object. */
238 extern const unsigned char mode_nunits[NUM_MACHINE_MODES];
239 #if GCC_VERSION >= 4001
240 #define GET_MODE_NUNITS(MODE) \
241 ((unsigned char) (__builtin_constant_p (MODE) \
242 ? mode_nunits_inline (MODE) : mode_nunits[MODE]))
243 #else
244 #define GET_MODE_NUNITS(MODE) mode_nunits[MODE]
245 #endif
247 /* Get the next wider natural mode (eg, QI -> HI -> SI -> DI -> TI). */
249 extern const unsigned char mode_wider[NUM_MACHINE_MODES];
250 #define GET_MODE_WIDER_MODE(MODE) ((enum machine_mode) mode_wider[MODE])
252 /* For scalars, this is a mode with twice the precision. For vectors,
253 this is a mode with the same inner mode but with twice the elements. */
254 extern const unsigned char mode_2xwider[NUM_MACHINE_MODES];
255 #define GET_MODE_2XWIDER_MODE(MODE) ((enum machine_mode) mode_2xwider[MODE])
257 /* Return the mode for data of a given size SIZE and mode class CLASS.
258 If LIMIT is nonzero, then don't use modes bigger than MAX_FIXED_MODE_SIZE.
259 The value is BLKmode if no other mode is found. */
261 extern enum machine_mode mode_for_size (unsigned int, enum mode_class, int);
263 /* Similar, but find the smallest mode for a given width. */
265 extern enum machine_mode smallest_mode_for_size (unsigned int,
266 enum mode_class);
269 /* Return an integer mode of the exact same size as the input mode,
270 or BLKmode on failure. */
272 extern enum machine_mode int_mode_for_mode (enum machine_mode);
274 extern enum machine_mode bitwise_mode_for_mode (enum machine_mode);
276 /* Return a mode that is suitable for representing a vector,
277 or BLKmode on failure. */
279 extern enum machine_mode mode_for_vector (enum machine_mode, unsigned);
281 /* A class for iterating through possible bitfield modes. */
282 class bit_field_mode_iterator
284 public:
285 bit_field_mode_iterator (HOST_WIDE_INT, HOST_WIDE_INT,
286 HOST_WIDE_INT, HOST_WIDE_INT,
287 unsigned int, bool);
288 bool next_mode (enum machine_mode *);
289 bool prefer_smaller_modes ();
291 private:
292 enum machine_mode m_mode;
293 /* We use signed values here because the bit position can be negative
294 for invalid input such as gcc.dg/pr48335-8.c. */
295 HOST_WIDE_INT m_bitsize;
296 HOST_WIDE_INT m_bitpos;
297 HOST_WIDE_INT m_bitregion_start;
298 HOST_WIDE_INT m_bitregion_end;
299 unsigned int m_align;
300 bool m_volatilep;
301 int m_count;
304 /* Find the best mode to use to access a bit field. */
306 extern enum machine_mode get_best_mode (int, int,
307 unsigned HOST_WIDE_INT,
308 unsigned HOST_WIDE_INT,
309 unsigned int,
310 enum machine_mode, bool);
312 /* Determine alignment, 1<=result<=BIGGEST_ALIGNMENT. */
314 extern CONST_MODE_BASE_ALIGN unsigned char mode_base_align[NUM_MACHINE_MODES];
316 extern unsigned get_mode_alignment (enum machine_mode);
318 #define GET_MODE_ALIGNMENT(MODE) get_mode_alignment (MODE)
320 /* Get the precision of the mode or its inner mode if it has one. */
322 extern unsigned int element_precision (enum machine_mode);
324 /* For each class, get the narrowest mode in that class. */
326 extern const unsigned char class_narrowest_mode[MAX_MODE_CLASS];
327 #define GET_CLASS_NARROWEST_MODE(CLASS) \
328 ((enum machine_mode) class_narrowest_mode[CLASS])
330 /* Define the integer modes whose sizes are BITS_PER_UNIT and BITS_PER_WORD
331 and the mode whose class is Pmode and whose size is POINTER_SIZE. */
333 extern enum machine_mode byte_mode;
334 extern enum machine_mode word_mode;
335 extern enum machine_mode ptr_mode;
337 /* Target-dependent machine mode initialization - in insn-modes.c. */
338 extern void init_adjust_machine_modes (void);
340 #define TRULY_NOOP_TRUNCATION_MODES_P(MODE1, MODE2) \
341 TRULY_NOOP_TRUNCATION (GET_MODE_PRECISION (MODE1), \
342 GET_MODE_PRECISION (MODE2))
344 #define HWI_COMPUTABLE_MODE_P(MODE) \
345 (SCALAR_INT_MODE_P (MODE) \
346 && GET_MODE_PRECISION (MODE) <= HOST_BITS_PER_WIDE_INT)
348 #endif /* not HAVE_MACHINE_MODES */