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       Handling of ia32 specific firm opcodes.
23  * @author      Christian Wuerdig
24  *
25  * This file implements the creation of the achitecture specific firm opcodes
26  * and the coresponding node constructors for the ia32 assembler irg.
27  */
28 #ifndef FIRM_BE_IA32_IA32_NEW_NODES_H
29 #define FIRM_BE_IA32_IA32_NEW_NODES_H
30 
31 #include "ia32_nodes_attr.h"
32 
33 /** indices for AM inputs */
34 enum {
35 	n_ia32_base         = 0,
36 	n_ia32_index        = 1,
37 	n_ia32_mem          = 2,
38 	n_ia32_unary_op     = 3,
39 	n_ia32_binary_left  = 3,
40 	n_ia32_binary_right = 4
41 };
42 
43 /** proj numbers for "normal" one-result nodes (for the complicated cases where we not only
44  * need the result) */
45 enum {
46 	pn_ia32_res   = 0,
47 	pn_ia32_flags = 1,
48 	pn_ia32_mem   = 2
49 };
50 
51 extern struct obstack opcodes_obst;
52 
53 /**
54  * returns true if a node has x87 registers
55  */
56 int ia32_has_x87_register(const ir_node *n);
57 
58 /**
59  * Returns the attributes of an ia32 node.
60  */
61 ia32_attr_t *get_ia32_attr(ir_node *node);
62 const ia32_attr_t *get_ia32_attr_const(const ir_node *node);
63 
64 ia32_x87_attr_t *get_ia32_x87_attr(ir_node *node);
65 const ia32_x87_attr_t *get_ia32_x87_attr_const(const ir_node *node);
66 
67 ia32_immediate_attr_t *get_ia32_immediate_attr(ir_node *node);
68 const ia32_immediate_attr_t *get_ia32_immediate_attr_const(const ir_node *node);
69 
70 const ia32_asm_attr_t *get_ia32_asm_attr_const(const ir_node *node);
71 
72 /**
73  * Gets the condcode attributes of a node.
74  */
75 ia32_condcode_attr_t *get_ia32_condcode_attr(ir_node *node);
76 const ia32_condcode_attr_t *get_ia32_condcode_attr_const(const ir_node *node);
77 
78 /**
79  * Gets the Call node attributes.
80  */
81 ia32_call_attr_t *get_ia32_call_attr(ir_node *node);
82 const ia32_call_attr_t *get_ia32_call_attr_const(const ir_node *node);
83 
84 /**
85  * Gets the CopyB node attributes.
86  */
87 ia32_copyb_attr_t *get_ia32_copyb_attr(ir_node *node);
88 const ia32_copyb_attr_t *get_ia32_copyb_attr_const(const ir_node *node);
89 
90 /**
91  * Gets the ClimbFrame node attributes.
92  */
93 ia32_climbframe_attr_t *get_ia32_climbframe_attr(ir_node *node);
94 const ia32_climbframe_attr_t *get_ia32_climbframe_attr_const(const ir_node *node);
95 
96 ia32_switch_attr_t *get_ia32_switch_attr(ir_node *node);
97 const ia32_switch_attr_t *get_ia32_switch_attr_const(const ir_node *node);
98 
99 /**
100  * Gets the type of an ia32 node.
101  */
102 ia32_op_type_t get_ia32_op_type(const ir_node *node);
103 
104 /**
105  * Sets the type of an ia32 node.
106  */
107 void set_ia32_op_type(ir_node *node, ia32_op_type_t tp);
108 
109 /**
110  * Gets the supported address mode of an ia32 node
111  */
112 ia32_am_type_t get_ia32_am_support(const ir_node *node);
113 
114 /**
115  * Sets the supported addrmode of an ia32 node
116  */
117 void set_ia32_am_support(ir_node *node, ia32_am_type_t am_arity);
118 
119 /**
120  * Gets the addressmode offset as long.
121  */
122 int get_ia32_am_offs_int(const ir_node *node);
123 
124 /**
125  * Sets the addressmode offset
126  */
127 void set_ia32_am_offs_int(ir_node *node, int offset);
128 
129 void add_ia32_am_offs_int(ir_node *node, int offset);
130 
131 /**
132  * Returns the symconst entity associated to addrmode.
133  */
134 ir_entity *get_ia32_am_sc(const ir_node *node);
135 
136 /**
137  * Sets the symconst entity associated to addrmode.
138  */
139 void set_ia32_am_sc(ir_node *node, ir_entity *sc);
140 
141 /**
142  * Sets the sign bit for address mode symconst.
143  */
144 void set_ia32_am_sc_sign(ir_node *node);
145 
146 /**
147  * Clears the sign bit for address mode symconst.
148  */
149 void clear_ia32_am_sc_sign(ir_node *node);
150 
151 /**
152  * Returns the sign bit for address mode symconst.
153  */
154 int is_ia32_am_sc_sign(const ir_node *node);
155 
156 void set_ia32_am_tls_segment(ir_node *node, bool value);
157 
158 bool get_ia32_am_tls_segment(const ir_node *node);
159 
160 /**
161  * Gets the addr mode const.
162  */
163 unsigned get_ia32_am_scale(const ir_node *node);
164 
165 /**
166  * Sets the const for addr mode.
167  */
168 void set_ia32_am_scale(ir_node *node, unsigned scale);
169 
170 /**
171  * Sets the uses_frame flag.
172  */
173 void set_ia32_use_frame(ir_node *node);
174 
175 /**
176  * Clears the uses_frame flag.
177  */
178 void clear_ia32_use_frame(ir_node *node);
179 
180 /**
181  * Gets the uses_frame flag.
182  */
183 int is_ia32_use_frame(const ir_node *node);
184 
185 /**
186  * copies all address-mode attributes from one node to the other
187  */
188 void ia32_copy_am_attrs(ir_node *to, const ir_node *from);
189 
190 /**
191  * Sets node to commutative.
192  */
193 void set_ia32_commutative(ir_node *node);
194 
195 /**
196  * Sets node to non-commutative.
197  */
198 void clear_ia32_commutative(ir_node *node);
199 
200 /**
201  * Checks if node is commutative.
202  */
203 int is_ia32_commutative(const ir_node *node);
204 
205 /**
206  * Sets node needs_stackent
207  */
208 void set_ia32_need_stackent(ir_node *node);
209 
210 /**
211  * Clears node needs_stackent
212  */
213 void clear_ia32_need_stackent(ir_node *node);
214 
215 /**
216  * Checks if node needs a stack entity assigned
217  */
218 int is_ia32_need_stackent(const ir_node *node);
219 
220 void set_ia32_is_reload(ir_node *node);
221 int is_ia32_is_reload(const ir_node *node);
222 
223 void set_ia32_is_spill(ir_node *node);
224 int is_ia32_is_spill(const ir_node *node);
225 
226 void set_ia32_is_remat(ir_node *node);
227 int is_ia32_is_remat(const ir_node *node);
228 
229 /**
230  * Gets the mode of the stored/loaded value (only set for Store/Load)
231  */
232 ir_mode *get_ia32_ls_mode(const ir_node *node);
233 
234 /**
235  * Sets the mode of the stored/loaded value (only set for Store/Load)
236  */
237 void set_ia32_ls_mode(ir_node *node, ir_mode *mode);
238 
239 /**
240  * Gets the frame entity assigned to this node;
241  */
242 ir_entity *get_ia32_frame_ent(const ir_node *node);
243 
244 /**
245  * Sets the frame entity for this node;
246  */
247 void set_ia32_frame_ent(ir_node *node, ir_entity *ent);
248 
249 /**
250  * Returns the condition code of a node.
251  */
252 ia32_condition_code_t get_ia32_condcode(const ir_node *node);
253 
254 /**
255  * Sets the condition code of a node
256  */
257 void set_ia32_condcode(ir_node *node, ia32_condition_code_t code);
258 
259 const ir_switch_table *get_ia32_switch_table(const ir_node *node);
260 
261 unsigned get_ia32_copyb_size(const ir_node *node);
262 
263 /**
264  * Gets the instruction latency.
265  */
266 unsigned get_ia32_latency(const ir_node *node);
267 
268 /**
269  * Get the exception label attribute.
270  */
271 unsigned get_ia32_exc_label(const ir_node *node);
272 
273 /**
274  * Set the exception label attribute.
275  */
276 void set_ia32_exc_label(ir_node *node, unsigned flag);
277 
278 /**
279  * Return the exception label id.
280  */
281 ir_label_t get_ia32_exc_label_id(const ir_node *node);
282 
283 /**
284  * Assign the exception label id.
285  */
286 void set_ia32_exc_label_id(ir_node *node, ir_label_t id);
287 
288 #ifndef NDEBUG
289 
290 /**
291  * Returns the name of the original ir node.
292  */
293 const char *get_ia32_orig_node(const ir_node *node);
294 
295 /**
296  * Sets the name of the original ir node.
297  */
298 void set_ia32_orig_node(ir_node *node, const ir_node *old);
299 
300 #endif /* NDEBUG */
301 
302 
303 /**
304  * Returns the ident of an entity
305  * @param ent The entity
306  * @return The ident of the entity
307  */
308 ident *ia32_get_ent_ident(ir_entity *ent);
309 
310 /**
311  * Copy the attributes from a Const to an ia32_Const
312  */
313 void set_ia32_Const_attr(ir_node *ia32_cnst, ir_node *cnst);
314 
315 void set_ia32_Const_tarval(ir_node *node, ir_tarval *tv);
316 
317 /**
318  * Returns whether or not the node is an AddrModeS node.
319  */
320 int is_ia32_AddrModeS(const ir_node *node);
321 
322 /**
323  * Returns whether or not the node is an AddrModeD node.
324  */
325 int is_ia32_AddrModeD(const ir_node *node);
326 
327 /**
328  * Swaps left/right input of a node (and sets ins_permuted accordingly)
329  */
330 void ia32_swap_left_right(ir_node *node);
331 
332 /* Include the generated headers */
333 #include "gen_ia32_new_nodes.h"
334 
335 #endif
336