Fix typos in comments: s/wether/whether/ and related corrections.
[libfirm] / ir / be / ia32 / ia32_nodes_attr.h
1 /*
2  * Copyright (C) 1995-2008 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       Type definitions for ia32 node attributes.
23  * @author      Christian Wuerdig
24  * @version     $Id$
25  */
26 #ifndef FIRM_BE_IA32_IA32_NODES_ATTR_H
27 #define FIRM_BE_IA32_IA32_NODES_ATTR_H
28
29 #include "firm_types.h"
30 #include "../bearch.h"
31 #include "../bemachine.h"
32 #include "irnode_t.h"
33
34 /** ia32 condition codes (the numbers correspond to the real encoding order) */
35 typedef enum ia32_condition_code_t {
36         ia32_cc_negated       = 0x01, /**< negates condition */
37
38         ia32_cc_overflow      = 0x00,                                /**< OF=1 */
39         ia32_cc_below         = 0x02,                                /**< CF=1 */
40         ia32_cc_equal         = 0x04,                                /**< ZF=1 */
41         ia32_cc_below_equal   = 0x06,                                /**< ZF=1 or CF=1 */
42         ia32_cc_sign          = 0x08,                                /**< SF=1 */
43         ia32_cc_parity        = 0x0A,                                /**< PF=1 */
44         ia32_cc_less          = 0x0C,                                /**< SF!=OF */
45         ia32_cc_less_equal    = 0x0E,                                /**< ZF=1 or SF!=OF */
46         ia32_cc_not_overflow  = ia32_cc_negated|ia32_cc_overflow,    /**< OF=0 */
47         ia32_cc_above_equal   = ia32_cc_negated|ia32_cc_below,       /**< CF=0 */
48         ia32_cc_not_equal     = ia32_cc_negated|ia32_cc_equal,       /**< ZF=0 */
49         ia32_cc_above         = ia32_cc_negated|ia32_cc_below_equal, /**< ZF=0 and CF=0 */
50         ia32_cc_not_sign      = ia32_cc_negated|ia32_cc_sign,        /**< SF=0 */
51         ia32_cc_not_parity    = ia32_cc_negated|ia32_cc_parity,      /**< PF=0 */
52         ia32_cc_greater_equal = ia32_cc_negated|ia32_cc_less,        /**< SF=OF */
53         ia32_cc_greater       = ia32_cc_negated|ia32_cc_less_equal,  /**< ZF=0 and SF=OF */
54
55         /* the following codes are (unfortunately) NOT real hardware codes but
56          * simplify our backend as you need these combinations for some
57          * floatingpoint compares (the emitter will split them into multiple
58          * instructions) */
59         ia32_cc_float_parity_cases = 0x20,
60         /* we need even more cases as inversing the cc is different for float
61          * comparisons (though for the following we need no special
62          * parity+x combinations) */
63         ia32_cc_additional_float_cases = 0x10,
64
65         /* make sure that the lower 4 bit correspond to the real encoding
66          * (of the comparison not involving the parity special) */
67         ia32_cc_float_equal        = 0x34,                                /**< PF=0 and ZF=1 */
68         ia32_cc_float_below        = 0x32,                                /**< PF=0 and CF=1 */
69         ia32_cc_float_below_equal  = 0x36,                                /**< PF=0 and (ZF=1 or CF=1) */
70         ia32_cc_float_not_equal    = ia32_cc_negated|ia32_cc_float_equal, /**< PF=1 or ZF=0 */
71         ia32_cc_float_unordered_above_equal
72                 = ia32_cc_negated|ia32_cc_float_below,                        /**< PF=1 or CF=0 */
73         ia32_cc_float_unordered_above
74                 = ia32_cc_negated|ia32_cc_float_below_equal,                  /**< PF=1 or (ZF=0 and CF=0) */
75
76         ia32_cc_float_unordered_below_equal = 0x16,                       /**< ZF=1 or CF=1 */
77         ia32_cc_float_unordered_below       = 0x12,                       /**< CF=1 */
78         ia32_cc_float_above        =
79                 ia32_cc_negated|ia32_cc_float_unordered_below_equal,          /**< ZF=0 and CF=0 */
80         ia32_cc_float_above_equal
81                 = ia32_cc_negated|ia32_cc_float_unordered_below,              /**< CF=0 */
82 } ia32_condition_code_t;
83 ENUM_BITSET(ia32_condition_code_t)
84
85 static inline ia32_condition_code_t ia32_negate_condition_code(
86                 ia32_condition_code_t code)
87 {
88         return code ^ ia32_cc_negated;
89 }
90
91 static inline ia32_condition_code_t ia32_invert_condition_code(
92                 ia32_condition_code_t code)
93 {
94         /* doesn't appear to have any systematic, so use a table */
95         switch (code) {
96         case ia32_cc_below:              return ia32_cc_above;
97         case ia32_cc_below_equal:        return ia32_cc_above_equal;
98         case ia32_cc_above:              return ia32_cc_below;
99         case ia32_cc_above_equal:        return ia32_cc_below_equal;
100         case ia32_cc_less:               return ia32_cc_greater;
101         case ia32_cc_less_equal:         return ia32_cc_greater_equal;
102         case ia32_cc_greater:            return ia32_cc_less;
103         case ia32_cc_greater_equal:      return ia32_cc_less_equal;
104         case ia32_cc_float_below:        return ia32_cc_float_above;
105         case ia32_cc_float_below_equal:  return ia32_cc_float_above_equal;
106         case ia32_cc_float_above:        return ia32_cc_float_below;
107         case ia32_cc_float_above_equal:  return ia32_cc_float_below_equal;
108         case ia32_cc_float_unordered_below:       return ia32_cc_float_unordered_above;
109         case ia32_cc_float_unordered_below_equal: return ia32_cc_float_unordered_above_equal;
110         case ia32_cc_float_unordered_above:       return ia32_cc_float_unordered_below;
111         case ia32_cc_float_unordered_above_equal: return ia32_cc_float_unordered_below_equal;
112         default:                         return code;
113         }
114 }
115
116 typedef enum {
117         ia32_Normal,
118         ia32_AddrModeD,
119         ia32_AddrModeS
120 } ia32_op_type_t;
121
122 typedef enum {
123         ia32_am_none   = 0,
124         ia32_am_unary  = 1,
125         ia32_am_binary = 2
126 } ia32_am_type_t;
127
128 typedef enum {
129         match_commutative       = 1 << 0, /**< inputs are commutative */
130         match_am_and_immediates = 1 << 1, /**< node supports AM and immediate at
131                                                the same time */
132         match_am                = 1 << 2, /**< node supports (32bit) source AM */
133         match_8bit_am           = 1 << 3, /**< node supports 8bit source AM */
134         match_16bit_am          = 1 << 4, /**< node supports 16bit source AM */
135         match_immediate         = 1 << 5, /**< node supports immediates */
136         match_mode_neutral      = 1 << 6, /**< 16 and 8 bit modes can be emulated
137                                                by 32 bit operations */
138         match_try_am            = 1 << 7, /**< only try to produce AM node, don't
139                                                do anything if AM isn't possible */
140         match_two_users         = 1 << 8, /**< the instruction uses a load two times ... */
141         match_upconv_32         = 1 << 9  /**< 8/16 bit insn are processed by doing
142                                                an upconv to 32bit */
143 } match_flags_t;
144 ENUM_BITSET(match_flags_t)
145
146 typedef struct ia32_op_attr_t ia32_op_attr_t;
147 struct ia32_op_attr_t {
148         match_flags_t  flags;
149         unsigned       latency;
150 };
151
152 #ifndef NDEBUG
153 typedef enum {
154         IA32_ATTR_INVALID                = 0,
155         IA32_ATTR_ia32_attr_t            = 1 << 0,
156         IA32_ATTR_ia32_x87_attr_t        = 1 << 1,
157         IA32_ATTR_ia32_asm_attr_t        = 1 << 2,
158         IA32_ATTR_ia32_immediate_attr_t  = 1 << 3,
159         IA32_ATTR_ia32_condcode_attr_t   = 1 << 4,
160         IA32_ATTR_ia32_copyb_attr_t      = 1 << 5,
161         IA32_ATTR_ia32_call_attr_t       = 1 << 6,
162         IA32_ATTR_ia32_climbframe_attr_t = 1 << 7,
163         IA32_ATTR_ia32_switch_attr_t     = 1 << 8,
164 } ia32_attr_type_t;
165 #endif
166
167 /**
168  * The generic ia32 attributes. Every node has them.
169  */
170 typedef struct ia32_attr_t ia32_attr_t;
171 struct ia32_attr_t {
172         except_attr  exc;               /**< the exception attribute. MUST be the first one. */
173         struct ia32_attr_data_bitfield {
174                 unsigned tp:3;                  /**< ia32 node type. */
175                 unsigned am_arity:2;            /**< Indicates the address mode type supported by this node. */
176                 unsigned am_scale:2;            /**< The address mode scale for index register. */
177                 unsigned am_sc_sign:1;          /**< The sign bit of the address mode symconst. */
178
179                 unsigned am_sc_no_pic_adjust : 1;/**< AM symconst can be relative to EIP */
180                 unsigned use_frame:1;           /**< Indicates whether the operation uses the frame pointer or not. */
181                 unsigned has_except_label:1;        /**< Set if this node needs a label because of possible exception. */
182
183                 unsigned is_commutative:1;      /**< Indicates whether op is commutative or not. */
184
185                 unsigned need_stackent:1;       /**< Set to 1 if node need space on stack. */
186                 unsigned need_64bit_stackent:1; /**< needs a 64bit stack entity (see double->unsigned int conv) */
187                 unsigned need_32bit_stackent:1; /**< needs a 32bit stack entity */
188                 unsigned ins_permuted : 1;      /**< inputs of node have been permuted
189                                                      (for commutative nodes) */
190                 unsigned is_reload : 1;         /**< node performs a reload */
191                 unsigned is_spill : 1;
192                 unsigned is_remat : 1;
193         } data;
194
195         int        am_offs;       /**< offsets for AddrMode */
196         ir_entity *am_sc;         /**< SymConst for AddrMode */
197
198         ir_mode   *ls_mode;       /**< Load/Store mode: This is the mode of the
199                                        value that is manipulated by this node. */
200
201         ir_entity *frame_ent; /**< the frame entity attached to this node */
202
203         const be_execution_unit_t ***exec_units; /**< list of units this operation can be executed on */
204
205         ir_label_t        exc_label;       /**< the exception label iff this instruction can throw an exception */
206
207 #ifndef NDEBUG
208         const char       *orig_node;      /**< holds the name of the original ir node */
209         unsigned          attr_type;      /**< bitfield indicating the attribute type */
210 #endif
211 };
212
213 /**
214  * The attributes for a Call node.
215  */
216 typedef struct ia32_call_attr_t ia32_call_attr_t;
217 struct ia32_call_attr_t {
218         ia32_attr_t  attr;    /**< generic attribute */
219         unsigned     pop;     /**< number of bytes that get popped by the callee */
220         ir_type     *call_tp; /**< The call type, copied from the original Call node. */
221 };
222
223 /**
224  * The attributes for nodes with condition code.
225  */
226 typedef struct ia32_condcode_attr_t ia32_condcode_attr_t;
227 struct ia32_condcode_attr_t {
228         ia32_attr_t           attr;           /**< generic attribute */
229         ia32_condition_code_t condition_code; /**< condition code*/
230 };
231
232 /**
233  * The attributes for Switches
234  */
235 typedef struct ia32_switch_attr_t ia32_switch_attr_t;
236 struct ia32_switch_attr_t {
237         ia32_attr_t  attr;        /**< generic attribute */
238         long         default_pn;
239 };
240
241 /**
242  * The attributes for CopyB code.
243  */
244 typedef struct ia32_copyb_attr_t ia32_copyb_attr_t;
245 struct ia32_copyb_attr_t {
246         ia32_attr_t  attr;      /**< generic attribute */
247         unsigned     size;      /**< size of copied block */
248 };
249
250 /**
251  * The attributes for immediates.
252  */
253 typedef struct ia32_immediate_attr_t ia32_immediate_attr_t;
254 struct ia32_immediate_attr_t {
255         ia32_attr_t  attr;              /**< generic attribute */
256         ir_entity   *symconst;          /**< An entity if any. */
257         long         offset;            /**< An offset if any. */
258         unsigned     sc_sign : 1;       /**< The sign bit of the symconst. */
259         unsigned     no_pic_adjust : 1; /**< constant can be relative to EIP */
260 };
261
262 /**
263  * The attributes for x87 nodes.
264  */
265 typedef struct ia32_x87_attr_t ia32_x87_attr_t;
266 struct ia32_x87_attr_t {
267         ia32_attr_t            attr;      /**< the generic attribute */
268         const arch_register_t *x87[3];    /**< register slots for x87 register */
269 };
270
271 typedef struct ia32_asm_reg_t ia32_asm_reg_t;
272 struct ia32_asm_reg_t {
273         unsigned                   use_input  : 1; /* use input or output pos */
274         unsigned                   valid      : 1;
275         unsigned                   memory     : 1;
276         unsigned                   dummy_fill : 13;
277         unsigned                   inout_pos  : 16; /* in/out pos where the
278                                                        register is assigned */
279         const ir_mode             *mode;
280 };
281
282 /**
283  * The attributes for ASM nodes.
284  */
285 typedef struct ia32_asm_attr_t ia32_asm_attr_t;
286 struct ia32_asm_attr_t {
287         ia32_x87_attr_t       x87_attr;
288         ident                *asm_text;
289         const ia32_asm_reg_t *register_map;
290 };
291
292 /**
293  * The attributes for the ClimbFrame node.
294  */
295 typedef struct ia32_climbframe_attr_t ia32_climbframe_attr_t;
296 struct ia32_climbframe_attr_t {
297         ia32_attr_t attr;      /**< generic attribute */
298         unsigned    count;     /**< number of frames to climb up */
299 };
300
301 /* the following union is necessary to indicate to the compiler that we might want to cast
302  * the structs (we use them to simulate OO-inheritance) */
303 union allow_casts_attr_t_ {
304         ia32_attr_t            attr;
305         ia32_call_attr_t       call_attr;
306         ia32_condcode_attr_t   cc_attr;
307         ia32_copyb_attr_t      cpy_attr;
308         ia32_x87_attr_t        x87_attr;
309         ia32_asm_attr_t        asm_attr;
310         ia32_immediate_attr_t  immediate_attr;
311         ia32_climbframe_attr_t climbframe_attr;
312         ia32_switch_attr_t     switch_attr;
313 };
314
315 #ifndef NDEBUG
316 #define CAST_IA32_ATTR(type,ptr)        (assert( ((const ia32_attr_t*)(ptr))->attr_type & IA32_ATTR_ ## type ), (type*) (ptr))
317 #define CONST_CAST_IA32_ATTR(type,ptr)  (assert( ((const ia32_attr_t*)(ptr))->attr_type & IA32_ATTR_ ## type ), (const type*) (ptr))
318 #else
319 #define CAST_IA32_ATTR(type,ptr)        ((type*) (ptr))
320 #define CONST_CAST_IA32_ATTR(type,ptr)  ((const type*) (ptr))
321 #endif
322
323 #endif