Add is_Conv().
[libfirm] / ir / ir / irmode_t.h
1 /*
2  * Copyright (C) 1995-2007 University of Karlsruhe.  All right reserved.
3  *
4  * This file is part of libFirm.
5  *
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.
10  *
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.
14  *
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
17  * PURPOSE.
18  */
19
20 /**
21  * @file
22  * @brief   Data modes of operations -- private header.
23  * @author  Martin Trapp, Christian Schaefer, Goetz Lindenmaier, Mathias Heil,
24  *          Michael Beck
25  * @version $Id$
26  */
27 #ifndef FIRM_IR_IRMODE_T_H
28 #define FIRM_IR_IRMODE_T_H
29
30 #include <assert.h>
31 #include "irmode.h"
32 #include "tv.h"
33
34 /** This struct is supposed to completely define a mode. **/
35 struct ir_mode {
36         firm_kind         kind;       /**< distinguishes this node from others */
37         modecode          code;       /**< unambiguous identifier of a mode */
38         ident             *name;      /**< Name ident of this mode */
39
40         /* ----------------------------------------------------------------------- */
41         /* On changing this struct you have to evaluate the mode_are_equal function!*/
42         mode_sort         sort;          /**< coarse classification of this mode:
43                                           int, float, reference ...
44                                           (see irmode.h) */
45         mode_arithmetic   arithmetic;    /**< different arithmetic operations possible with a mode */
46         int               size;          /**< size of the mode in Bits. */
47         unsigned          sign:1;        /**< signedness of this mode */
48         unsigned int      modulo_shift;  /**< number of bits a values of this mode will be shifted */
49         unsigned          vector_elem;   /**< if this is not equal 1, this is a vector mode with
50                                           vector_elem number of elements, size contains the size
51                                           of all bits and must be dividable by vector_elem */
52
53         /* ----------------------------------------------------------------------- */
54         tarval            *min;         /**< the minimum value that can be expressed */
55         tarval            *max;         /**< the maximum value that can be expressed */
56         tarval            *null;        /**< the value 0 */
57         tarval            *one;         /**< the value 1 */
58         tarval            *minus_one;   /**< the value -1 */
59         ir_mode           *eq_signed;   /**< For pointer modes, the equivalent signed integer one. */
60         ir_mode           *eq_unsigned; /**< For pointer modes, the equivalent unsigned integer one. */
61         void              *link;        /**< To store some intermediate information */
62         const void        *tv_priv;     /**< tarval module will save private data here */
63 };
64
65
66 /* ------------------------------- *
67  * inline functions                *
68  * ------------------------------- */
69 extern ir_mode *mode_P_code, *mode_P_data;
70
71 static INLINE ir_mode *
72 _get_modeP_code(void) { return mode_P_code; }
73
74 static INLINE ir_mode *
75 _get_modeP_data(void) { return mode_P_data; }
76
77 static INLINE modecode
78 _get_mode_modecode(const ir_mode *mode) { return mode->code; }
79
80 static INLINE ident *
81 _get_mode_ident(const ir_mode *mode) { return mode->name; }
82
83 static INLINE mode_sort
84 _get_mode_sort(const ir_mode* mode) { return mode->sort; }
85
86 static INLINE int
87 _get_mode_size_bits(const ir_mode *mode) { return mode->size; }
88
89 static INLINE int
90 _get_mode_size_bytes(const ir_mode *mode) {
91         int size = _get_mode_size_bits(mode);
92         if ((size & 7) != 0) return -1;
93         return size >> 3;
94 }
95
96 static INLINE int
97 _get_mode_sign(const ir_mode *mode) { return mode->sign; }
98
99 static INLINE int
100 _get_mode_arithmetic(const ir_mode *mode) { return mode->arithmetic; }
101
102 static INLINE unsigned int
103 _get_mode_modulo_shift(const ir_mode *mode) { return mode->modulo_shift; }
104
105 static INLINE unsigned int
106 _get_mode_vector_elems(const ir_mode *mode) { return mode->vector_elem; }
107
108 static INLINE void *
109 _get_mode_link(const ir_mode *mode) { return mode->link; }
110
111 static INLINE void
112 _set_mode_link(ir_mode *mode, void *l) { mode->link = l; }
113
114 /* Functions to check, whether a modecode is signed, float, int, num, data,
115    datab or dataM. For more exact definitions read the corresponding pages
116    in the firm documentation or the following enumeration
117
118    The set of "float" is defined as:
119    ---------------------------------
120    float = {irm_F, irm_D, irm_E}
121
122    The set of "int" is defined as:
123    -------------------------------
124    int   = {irm_Bs, irm_Bu, irm_Hs, irm_Hu, irm_Is, irm_Iu, irm_Ls, irm_Lu}
125
126    The set of "num" is defined as:
127    -------------------------------
128    num   = {irm_F, irm_D, irm_E, irm_Bs, irm_Bu, irm_Hs, irm_Hu,
129             irm_Is, irm_Iu, irm_Ls, irm_Lu}
130             = {float || int}
131
132    The set of "data" is defined as:
133    -------------------------------
134    data  = {irm_F, irm_D, irm_E irm_Bs, irm_Bu, irm_Hs, irm_Hu,
135             irm_Is, irm_Iu, irm_Ls, irm_Lu, irm_C, irm_U, irm_P}
136             = {num || irm_C || irm_U || irm_P}
137
138    The set of "datab" is defined as:
139    ---------------------------------
140    datab = {irm_F, irm_D, irm_E, irm_Bs, irm_Bu, irm_Hs, irm_Hu,
141             irm_Is, irm_Iu, irm_Ls, irm_Lu, irm_C, irm_U, irm_P, irm_b}
142             = {data || irm_b }
143
144    The set of "dataM" is defined as:
145    ---------------------------------
146    dataM = {irm_F, irm_D, irm_E, irm_Bs, irm_Bu, irm_Hs, irm_Hu,
147             irm_Is, irm_Iu, irm_Ls, irm_Lu, irm_C, irm_U, irm_P, irm_M}
148             = {data || irm_M}
149 */
150
151 static INLINE int
152 _mode_is_signed(const ir_mode *mode) {
153         assert(mode);
154         return mode->sign;
155 }
156
157 static INLINE int
158 _mode_is_float(const ir_mode *mode) {
159         assert(mode);
160         return (_get_mode_sort(mode) == irms_float_number);
161 }
162
163 static INLINE int
164 _mode_is_int(const ir_mode *mode) {
165         assert(mode);
166         return (_get_mode_sort(mode) == irms_int_number);
167 }
168
169 static INLINE int
170 _mode_is_character(const ir_mode *mode) {
171         assert(mode);
172         return (_get_mode_sort(mode) == irms_character);
173 }
174
175 static INLINE int
176 _mode_is_reference(const ir_mode *mode) {
177         assert(mode);
178         return (_get_mode_sort(mode) == irms_reference);
179 }
180
181 static INLINE int
182 _mode_is_num(const ir_mode *mode) {
183         assert(mode);
184         return (_mode_is_int(mode) || _mode_is_float(mode));
185 }
186
187 static INLINE int
188 _mode_is_numP(const ir_mode *mode) {
189         assert(mode);
190         return (_mode_is_int(mode) || _mode_is_float(mode) || _mode_is_reference(mode));
191 }
192
193 static INLINE int
194 _mode_is_data(const ir_mode *mode) {
195         assert(mode);
196         return (_mode_is_numP(mode) || _get_mode_sort(mode) == irms_character);
197 }
198
199 static INLINE int
200 _mode_is_datab(const ir_mode *mode) {
201         assert(mode);
202         return (_mode_is_data(mode) || _get_mode_sort(mode) == irms_internal_boolean);
203 }
204
205 static INLINE int
206 _mode_is_dataM(const ir_mode *mode) {
207         assert(mode);
208         return (_mode_is_data(mode) || _get_mode_modecode(mode) == irm_M);
209 }
210
211 static INLINE int
212 _mode_is_float_vector(const ir_mode *mode) {
213         assert(mode);
214         return (_get_mode_sort(mode) == irms_float_number) && (_get_mode_vector_elems(mode) > 1);
215 }
216
217 static INLINE int
218 _mode_is_int_vector(const ir_mode *mode) {
219         assert(mode);
220         return (_get_mode_sort(mode) == irms_int_number) && (_get_mode_vector_elems(mode) > 1);
221 }
222
223 /** mode module initialization, call once before use of any other function **/
224 void init_mode(void);
225
226 /** mode module finalization. frees all memory.  */
227 void finish_mode(void);
228
229 #define get_modeP_code()               _get_modeP_code()
230 #define get_modeP_data()               _get_modeP_data()
231 #define get_mode_modecode(mode)        _get_mode_modecode(mode)
232 #define get_mode_ident(mode)           _get_mode_ident(mode)
233 #define get_mode_sort(mode)            _get_mode_sort(mode)
234 #define get_mode_size_bits(mode)       _get_mode_size_bits(mode)
235 #define get_mode_size_bytes(mode)      _get_mode_size_bytes(mode)
236 #define get_mode_sign(mode)            _get_mode_sign(mode)
237 #define get_mode_arithmetic(mode)      _get_mode_arithmetic(mode)
238 #define get_mode_modulo_shift(mode)    _get_mode_modulo_shift(mode)
239 #define get_mode_n_vector_elems(mode)  _get_mode_vector_elems(mode)
240 #define get_mode_link(mode)            _get_mode_link(mode)
241 #define set_mode_link(mode, l)         _set_mode_link(mode, l)
242 #define mode_is_signed(mode)           _mode_is_signed(mode)
243 #define mode_is_float(mode)            _mode_is_float(mode)
244 #define mode_is_int(mode)              _mode_is_int(mode)
245 #define mode_is_character(mode)        _mode_is_character(mode)
246 #define mode_is_reference(mode)        _mode_is_reference(mode)
247 #define mode_is_num(mode)              _mode_is_num(mode)
248 #define mode_is_numP(mode)             _mode_is_numP(mode)
249 #define mode_is_data(mode)             _mode_is_data(mode)
250 #define mode_is_datab(mode)            _mode_is_datab(mode)
251 #define mode_is_dataM(mode)            _mode_is_dataM(mode)
252 #define mode_is_float_vector(mode)     _mode_is_float_vector(mode)
253 #define mode_is_int_vector(mode)       _mode_is_int_vector(mode)
254
255 #endif