2 * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved.
4 * This file is part of libFirm.
6 * This file may be distributed and/or modified under the terms of the
7 * GNU General Public License version 2 as published by the Free Software
8 * Foundation and appearing in the file LICENSE.GPL included in the
9 * packaging of this file.
11 * Licensees holding valid libFirm Professional Edition licenses may use
12 * this file in accordance with the libFirm Commercial License.
13 * Agreement provided with the Software.
15 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * File name: ir/ir/irmode_t.h
23 * Purpose: Data modes of operations -- private header.
24 * Author: Martin Trapp, Christian Schaefer
25 * Modified by: Goetz Lindenmaier, Mathias Heil, Michael Beck
28 * Copyright: (c) 1998-2007 Universität Karlsruhe
42 /** This struct is supposed to completely define a mode. **/
44 firm_kind kind; /**< distinguishes this node from others */
45 modecode code; /**< unambiguous identifier of a mode */
46 ident *name; /**< Name ident of this mode */
48 /* ----------------------------------------------------------------------- */
49 /* On changing this struct you have to evaluate the mode_are_equal function!*/
50 mode_sort sort; /**< coarse classification of this mode:
51 int, float, reference ...
53 mode_arithmetic arithmetic; /**< different arithmetic operations possible with a mode */
54 int size; /**< size of the mode in Bits. */
55 unsigned sign:1; /**< signedness of this mode */
56 unsigned int modulo_shift; /**< number of bits a values of this mode will be shifted */
57 unsigned vector_elem; /**< if this is not equal 1, this is a vector mode with
58 vector_elem number of elements, size contains the size
59 of all bits and must be dividable by vector_elem */
61 /* ----------------------------------------------------------------------- */
62 tarval *min; /**< the minimum value that can be expressed */
63 tarval *max; /**< the maximum value that can be expressed */
64 tarval *null; /**< the value 0 */
65 tarval *one; /**< the value 1 */
66 tarval *minus_one; /**< the value -1 */
67 ir_mode *eq_signed; /**< For pointer modes, the equivalent signed integer one. */
68 ir_mode *eq_unsigned; /**< For pointer modes, the equivalent unsigned integer one. */
69 void *link; /**< To store some intermediate information */
70 const void *tv_priv; /**< tarval module will save private data here */
74 /* ------------------------------- *
76 * ------------------------------- */
77 extern ir_mode *mode_P_code, *mode_P_data;
79 static INLINE ir_mode *
80 _get_modeP_code(void) { return mode_P_code; }
82 static INLINE ir_mode *
83 _get_modeP_data(void) { return mode_P_data; }
85 static INLINE modecode
86 _get_mode_modecode(const ir_mode *mode) { return mode->code; }
89 _get_mode_ident(const ir_mode *mode) { return mode->name; }
91 static INLINE mode_sort
92 _get_mode_sort(const ir_mode* mode) { return mode->sort; }
95 _get_mode_size_bits(const ir_mode *mode) { return mode->size; }
98 _get_mode_size_bytes(const ir_mode *mode) {
99 int size = _get_mode_size_bits(mode);
100 if ((size & 7) != 0) return -1;
105 _get_mode_sign(const ir_mode *mode) { return mode->sign; }
108 _get_mode_arithmetic(const ir_mode *mode) { return mode->arithmetic; }
110 static INLINE unsigned int
111 _get_mode_modulo_shift(const ir_mode *mode) { return mode->modulo_shift; }
113 static INLINE unsigned int
114 _get_mode_vector_elems(const ir_mode *mode) { return mode->vector_elem; }
117 _get_mode_link(const ir_mode *mode) { return mode->link; }
120 _set_mode_link(ir_mode *mode, void *l) { mode->link = l; }
122 /* Functions to check, whether a modecode is signed, float, int, num, data,
123 datab or dataM. For more exact definitions read the corresponding pages
124 in the firm documentation or the following enumeration
126 The set of "float" is defined as:
127 ---------------------------------
128 float = {irm_F, irm_D, irm_E}
130 The set of "int" is defined as:
131 -------------------------------
132 int = {irm_Bs, irm_Bu, irm_Hs, irm_Hu, irm_Is, irm_Iu, irm_Ls, irm_Lu}
134 The set of "num" is defined as:
135 -------------------------------
136 num = {irm_F, irm_D, irm_E, irm_Bs, irm_Bu, irm_Hs, irm_Hu,
137 irm_Is, irm_Iu, irm_Ls, irm_Lu}
140 The set of "data" is defined as:
141 -------------------------------
142 data = {irm_F, irm_D, irm_E irm_Bs, irm_Bu, irm_Hs, irm_Hu,
143 irm_Is, irm_Iu, irm_Ls, irm_Lu, irm_C, irm_U, irm_P}
144 = {num || irm_C || irm_U || irm_P}
146 The set of "datab" is defined as:
147 ---------------------------------
148 datab = {irm_F, irm_D, irm_E, irm_Bs, irm_Bu, irm_Hs, irm_Hu,
149 irm_Is, irm_Iu, irm_Ls, irm_Lu, irm_C, irm_U, irm_P, irm_b}
152 The set of "dataM" is defined as:
153 ---------------------------------
154 dataM = {irm_F, irm_D, irm_E, irm_Bs, irm_Bu, irm_Hs, irm_Hu,
155 irm_Is, irm_Iu, irm_Ls, irm_Lu, irm_C, irm_U, irm_P, irm_M}
160 _mode_is_signed(const ir_mode *mode) {
166 _mode_is_float(const ir_mode *mode) {
168 return (_get_mode_sort(mode) == irms_float_number);
172 _mode_is_int(const ir_mode *mode) {
174 return (_get_mode_sort(mode) == irms_int_number);
178 _mode_is_character(const ir_mode *mode) {
180 return (_get_mode_sort(mode) == irms_character);
184 _mode_is_reference(const ir_mode *mode) {
186 return (_get_mode_sort(mode) == irms_reference);
190 _mode_is_num(const ir_mode *mode) {
192 return (_mode_is_int(mode) || _mode_is_float(mode));
196 _mode_is_numP(const ir_mode *mode) {
198 return (_mode_is_int(mode) || _mode_is_float(mode) || _mode_is_reference(mode));
202 _mode_is_data(const ir_mode *mode) {
204 return (_mode_is_numP(mode) || _get_mode_sort(mode) == irms_character);
208 _mode_is_datab(const ir_mode *mode) {
210 return (_mode_is_data(mode) || _get_mode_sort(mode) == irms_internal_boolean);
214 _mode_is_dataM(const ir_mode *mode) {
216 return (_mode_is_data(mode) || _get_mode_modecode(mode) == irm_M);
220 _mode_is_float_vector(const ir_mode *mode) {
222 return (_get_mode_sort(mode) == irms_float_number) && (_get_mode_vector_elems(mode) > 1);
226 _mode_is_int_vector(const ir_mode *mode) {
228 return (_get_mode_sort(mode) == irms_int_number) && (_get_mode_vector_elems(mode) > 1);
231 /** mode module initialization, call once before use of any other function **/
232 void init_mode(void);
234 /** mode module finalization. frees all memory. */
235 void finish_mode(void);
237 #define get_modeP_code() _get_modeP_code()
238 #define get_modeP_data() _get_modeP_data()
239 #define get_mode_modecode(mode) _get_mode_modecode(mode)
240 #define get_mode_ident(mode) _get_mode_ident(mode)
241 #define get_mode_sort(mode) _get_mode_sort(mode)
242 #define get_mode_size_bits(mode) _get_mode_size_bits(mode)
243 #define get_mode_size_bytes(mode) _get_mode_size_bytes(mode)
244 #define get_mode_sign(mode) _get_mode_sign(mode)
245 #define get_mode_arithmetic(mode) _get_mode_arithmetic(mode)
246 #define get_mode_modulo_shift(mode) _get_mode_modulo_shift(mode)
247 #define get_mode_n_vector_elems(mode) _get_mode_vector_elems(mode)
248 #define get_mode_link(mode) _get_mode_link(mode)
249 #define set_mode_link(mode, l) _set_mode_link(mode, l)
250 #define mode_is_signed(mode) _mode_is_signed(mode)
251 #define mode_is_float(mode) _mode_is_float(mode)
252 #define mode_is_int(mode) _mode_is_int(mode)
253 #define mode_is_character(mode) _mode_is_character(mode)
254 #define mode_is_reference(mode) _mode_is_reference(mode)
255 #define mode_is_num(mode) _mode_is_num(mode)
256 #define mode_is_numP(mode) _mode_is_numP(mode)
257 #define mode_is_data(mode) _mode_is_data(mode)
258 #define mode_is_datab(mode) _mode_is_datab(mode)
259 #define mode_is_dataM(mode) _mode_is_dataM(mode)
260 #define mode_is_float_vector(mode) _mode_is_float_vector(mode)
261 #define mode_is_int_vector(mode) _mode_is_int_vector(mode)
263 #endif /* _IRMODE_T_H_ */