C99 features femoved
[libfirm] / ir / be / ia32 / ia32_new_nodes.c
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       Handling of ia32 specific firm opcodes.
23  * @author      Christian Wuerdig
24  * @version     $Id$
25  *
26  * This file implements the creation of the achitecture specific firm opcodes
27  * and the coresponding node constructors for the ia32 assembler irg.
28  */
29 #ifdef HAVE_CONFIG_H
30 #include "config.h"
31 #endif
32
33 #include <stdlib.h>
34
35 #include "irprog_t.h"
36 #include "irgraph_t.h"
37 #include "irnode_t.h"
38 #include "irmode_t.h"
39 #include "ircons_t.h"
40 #include "iropt_t.h"
41 #include "irop.h"
42 #include "firm_common_t.h"
43 #include "irvrfy_t.h"
44 #include "irprintf.h"
45 #include "iredges.h"
46 #include "error.h"
47 #include "raw_bitset.h"
48 #include "xmalloc.h"
49
50 #include "../bearch_t.h"
51
52 #include "bearch_ia32_t.h"
53 #include "ia32_nodes_attr.h"
54 #include "ia32_new_nodes.h"
55 #include "gen_ia32_regalloc_if.h"
56 #include "gen_ia32_machine.h"
57
58 /***********************************************************************************
59  *      _                                   _       _             __
60  *     | |                                 (_)     | |           / _|
61  *   __| |_   _ _ __ ___  _ __   ___ _ __   _ _ __ | |_ ___ _ __| |_ __ _  ___ ___
62  *  / _` | | | | '_ ` _ \| '_ \ / _ \ '__| | | '_ \| __/ _ \ '__|  _/ _` |/ __/ _ \
63  * | (_| | |_| | | | | | | |_) |  __/ |    | | | | | ||  __/ |  | || (_| | (_|  __/
64  *  \__,_|\__,_|_| |_| |_| .__/ \___|_|    |_|_| |_|\__\___|_|  |_| \__,_|\___\___|
65  *                       | |
66  *                       |_|
67  ***********************************************************************************/
68
69 /**
70  * Dumps the register requirements for either in or out.
71  */
72 static void dump_reg_req(FILE *F, ir_node *n, const arch_register_req_t **reqs,
73                          int inout) {
74         char *dir = inout ? "out" : "in";
75         int   max = inout ? get_ia32_n_res(n) : get_irn_arity(n);
76         char  buf[1024];
77         int   i;
78
79         memset(buf, 0, sizeof(buf));
80
81         if (reqs) {
82                 for (i = 0; i < max; i++) {
83                         fprintf(F, "%sreq #%d =", dir, i);
84
85                         if (reqs[i]->type == arch_register_req_type_none) {
86                                 fprintf(F, " n/a");
87                         }
88
89                         if (reqs[i]->type & arch_register_req_type_normal) {
90                                 fprintf(F, " %s", reqs[i]->cls->name);
91                         }
92
93                         if (reqs[i]->type & arch_register_req_type_limited) {
94                                 fprintf(F, " %s",
95                                         arch_register_req_format(buf, sizeof(buf), reqs[i], n));
96                         }
97
98                         if (reqs[i]->type & arch_register_req_type_should_be_same) {
99                                 ir_fprintf(F, " same as %+F", get_irn_n(n, reqs[i]->other_same));
100                         }
101
102                         if (reqs[i]->type & arch_register_req_type_should_be_different) {
103                                 ir_fprintf(F, " different from %+F", get_irn_n(n, reqs[i]->other_different));
104                         }
105
106                         fprintf(F, "\n");
107                 }
108
109                 fprintf(F, "\n");
110         }
111         else {
112                 fprintf(F, "%sreq = N/A\n", dir);
113         }
114 }
115
116 /**
117  * Dumper interface for dumping ia32 nodes in vcg.
118  * @param n        the node to dump
119  * @param F        the output file
120  * @param reason   indicates which kind of information should be dumped
121  * @return 0 on success or != 0 on failure
122  */
123 static int ia32_dump_node(ir_node *n, FILE *F, dump_reason_t reason) {
124         ir_mode     *mode = NULL;
125         int          bad  = 0;
126         int          i, n_res, am_flav, flags;
127         const arch_register_req_t **reqs;
128         const arch_register_t     **slots;
129
130         switch (reason) {
131                 case dump_node_opcode_txt:
132                         fprintf(F, "%s", get_irn_opname(n));
133                         break;
134
135                 case dump_node_mode_txt:
136                         if (is_ia32_Ld(n) || is_ia32_St(n)) {
137                                 mode = get_ia32_ls_mode(n);
138                                 fprintf(F, "[%s]", mode ? get_mode_name(mode) : "?NOMODE?");
139                         }
140
141                         if(is_ia32_Immediate(n)) {
142                                 const ia32_immediate_attr_t *attr
143                                         = get_ia32_immediate_attr_const(n);
144
145                                 fputc(' ', F);
146                                 if(attr->symconst) {
147                                         if(attr->attr.data.am_sc_sign) {
148                                                 fputc('-', F);
149                                         }
150                                         fputs(get_entity_name(attr->symconst), F);
151                                 }
152                                 if(attr->offset != 0 || attr->symconst == NULL) {
153                                         if(attr->offset > 0 && attr->symconst != NULL) {
154                                                 fputc('+', F);
155                                         }
156                                         fprintf(F, "%ld", attr->offset);
157                                 }
158                         }
159
160                         break;
161
162                 case dump_node_nodeattr_txt:
163                         if (is_ia32_ImmConst(n) || is_ia32_ImmSymConst(n)) {
164                                 if(is_ia32_ImmSymConst(n)) {
165                                         ir_entity *ent = get_ia32_Immop_symconst(n);
166                                         ident *id = get_entity_ld_ident(ent);
167                                         fprintf(F, "[SymC %s]", get_id_str(id));
168                                 } else {
169                                         char buf[128];
170                                         tarval *tv = get_ia32_Immop_tarval(n);
171
172                                         tarval_snprintf(buf, sizeof(buf), tv);
173                                         fprintf(F, "[%s]", buf);
174                                 }
175                         }
176
177                         if (! is_ia32_Lea(n)) {
178                                 if (is_ia32_AddrModeS(n)) {
179                                         fprintf(F, "[AM S] ");
180                                 }
181                                 else if (is_ia32_AddrModeD(n)) {
182                                         fprintf(F, "[AM D] ");
183                                 }
184                         }
185
186                         break;
187
188                 case dump_node_info_txt:
189                         n_res = get_ia32_n_res(n);
190                         fprintf(F, "=== IA32 attr begin ===\n");
191
192                         /* dump IN requirements */
193                         if (get_irn_arity(n) > 0) {
194                                 reqs = get_ia32_in_req_all(n);
195                                 dump_reg_req(F, n, reqs, 0);
196                         }
197
198                         /* dump OUT requirements */
199                         if (n_res > 0) {
200                                 reqs = get_ia32_out_req_all(n);
201                                 dump_reg_req(F, n, reqs, 1);
202                         }
203
204                         /* dump assigned registers */
205                         slots = get_ia32_slots(n);
206                         if (slots && n_res > 0) {
207                                 for (i = 0; i < n_res; i++) {
208                                         const arch_register_t *reg;
209
210                                         reg = slots[i];
211
212                                         fprintf(F, "reg #%d = %s\n", i, reg ? arch_register_get_name(reg) : "n/a");
213                                 }
214                                 fprintf(F, "\n");
215                         }
216
217                         /* dump op type */
218                         fprintf(F, "op = ");
219                         switch (get_ia32_op_type(n)) {
220                                 case ia32_Normal:
221                                         fprintf(F, "Normal");
222                                         break;
223                                 case ia32_AddrModeD:
224                                         fprintf(F, "AM Dest (Load+Store)");
225                                         break;
226                                 case ia32_AddrModeS:
227                                         fprintf(F, "AM Source (Load)");
228                                         break;
229                                 default:
230                                         fprintf(F, "unknown (%d)", get_ia32_op_type(n));
231                                         break;
232                         }
233                         fprintf(F, "\n");
234
235                         /* dump immop type */
236                         fprintf(F, "immediate = ");
237                         switch (get_ia32_immop_type(n)) {
238                                 case ia32_ImmNone:
239                                         fprintf(F, "None");
240                                         break;
241                                 case ia32_ImmConst:
242                                         fprintf(F, "Const");
243                                         break;
244                                 case ia32_ImmSymConst:
245                                         fprintf(F, "SymConst");
246                                         break;
247                                 default:
248                                         fprintf(F, "unknown (%d)", get_ia32_immop_type(n));
249                                         break;
250                         }
251                         fprintf(F, "\n");
252
253                         /* dump supported am */
254                         fprintf(F, "AM support = ");
255                         switch (get_ia32_am_support(n)) {
256                                 case ia32_am_None:
257                                         fprintf(F, "none");
258                                         break;
259                                 case ia32_am_Source:
260                                         fprintf(F, "source only (Load)");
261                                         break;
262                                 case ia32_am_Dest:
263                                         fprintf(F, "dest only (Load+Store)");
264                                         break;
265                                 case ia32_am_Full:
266                                         fprintf(F, "full");
267                                         break;
268                                 default:
269                                         fprintf(F, "unknown (%d)", get_ia32_am_support(n));
270                                         break;
271                         }
272                         fprintf(F, "\n");
273
274                         /* dump am flavour */
275                         fprintf(F, "AM flavour =");
276                         am_flav = get_ia32_am_flavour(n);
277                         if (am_flav == ia32_am_N) {
278                                 fprintf(F, " none");
279                         }
280                         else {
281                                 if (am_flav & ia32_O) {
282                                         fprintf(F, " O");
283                                 }
284                                 if (am_flav & ia32_B) {
285                                         fprintf(F, " B");
286                                 }
287                                 if (am_flav & ia32_I) {
288                                         fprintf(F, " I");
289                                 }
290                                 if (am_flav & ia32_S) {
291                                         fprintf(F, " S");
292                                 }
293                         }
294                         fprintf(F, " (%d)\n", am_flav);
295
296                         /* dump AM offset */
297                         if(get_ia32_am_offs_int(n) != 0) {
298                                 fprintf(F, "AM offset = %d\n", get_ia32_am_offs_int(n));
299                         }
300
301                         /* dump AM symconst */
302                         if(get_ia32_am_sc(n) != NULL) {
303                                 ir_entity *ent = get_ia32_am_sc(n);
304                                 ident *id = get_entity_ld_ident(ent);
305                                 fprintf(F, "AM symconst = %s\n", get_id_str(id));
306                         }
307
308                         /* dump AM scale */
309                         fprintf(F, "AM scale = %d\n", get_ia32_am_scale(n));
310
311                         /* dump pn code */
312                         if(is_ia32_SwitchJmp(n)) {
313                                 fprintf(F, "pn_code = %ld\n", get_ia32_pncode(n));
314                         } else {
315                                 if(get_ia32_pncode(n) & ia32_pn_Cmp_Unsigned) {
316                                         long pnc = get_ia32_pncode(n);
317                                         fprintf(F, "pn_code = %ld (%s, unsigned)\n",
318                                                 pnc, get_pnc_string(pnc & ~ia32_pn_Cmp_Unsigned));
319                                 } else {
320                                         fprintf(F, "pn_code = %ld (%s)\n", get_ia32_pncode(n),
321                                                 get_pnc_string(get_ia32_pncode(n)));
322                                 }
323                         }
324
325                         /* dump n_res */
326                         fprintf(F, "n_res = %d\n", get_ia32_n_res(n));
327
328                         /* dump use_frame */
329                         fprintf(F, "use_frame = %d\n", is_ia32_use_frame(n));
330
331                         /* commutative */
332                         fprintf(F, "commutative = %d\n", is_ia32_commutative(n));
333
334                         /* emit cl */
335                         fprintf(F, "emit cl instead of ecx = %d\n", is_ia32_emit_cl(n));
336
337                         /* got lea */
338                         fprintf(F, "got loea = %d\n", is_ia32_got_lea(n));
339
340                         /* need stackent */
341                         fprintf(F, "need stackent = %d\n", is_ia32_need_stackent(n));
342
343                         /* dump latency */
344                         fprintf(F, "latency = %d\n", get_ia32_latency(n));
345
346                         /* dump flags */
347                         fprintf(F, "flags =");
348                         flags = get_ia32_flags(n);
349                         if (flags == arch_irn_flags_none) {
350                                 fprintf(F, " none");
351                         }
352                         else {
353                                 if (flags & arch_irn_flags_dont_spill) {
354                                         fprintf(F, " unspillable");
355                                 }
356                                 if (flags & arch_irn_flags_rematerializable) {
357                                         fprintf(F, " remat");
358                                 }
359                                 if (flags & arch_irn_flags_ignore) {
360                                         fprintf(F, " ignore");
361                                 }
362                                 if (flags & arch_irn_flags_modify_sp) {
363                                         fprintf(F, " modify_sp");
364                                 }
365                         }
366                         fprintf(F, " (%d)\n", flags);
367
368                         /* dump frame entity */
369                         fprintf(F, "frame entity = ");
370                         if (get_ia32_frame_ent(n)) {
371                                 ir_fprintf(F, "%+F", get_ia32_frame_ent(n));
372                         }
373                         else {
374                                 fprintf(F, "n/a");
375                         }
376                         fprintf(F, "\n");
377
378                         /* dump modes */
379                         fprintf(F, "ls_mode = ");
380                         if (get_ia32_ls_mode(n)) {
381                                 ir_fprintf(F, "%+F", get_ia32_ls_mode(n));
382                         }
383                         else {
384                                 fprintf(F, "n/a");
385                         }
386                         fprintf(F, "\n");
387
388 #ifndef NDEBUG
389                         /* dump original ir node name */
390                         fprintf(F, "orig node = ");
391                         if (get_ia32_orig_node(n)) {
392                                 fprintf(F, "%s", get_ia32_orig_node(n));
393                         }
394                         else {
395                                 fprintf(F, "n/a");
396                         }
397                         fprintf(F, "\n");
398 #endif /* NDEBUG */
399
400                         fprintf(F, "=== IA32 attr end ===\n");
401                         /* end of: case dump_node_info_txt */
402                         break;
403         }
404
405         return bad;
406 }
407
408
409
410 /***************************************************************************************************
411  *        _   _                   _       __        _                    _   _               _
412  *       | | | |                 | |     / /       | |                  | | | |             | |
413  *   __ _| |_| |_ _ __   ___  ___| |_   / /_ _  ___| |_   _ __ ___   ___| |_| |__   ___   __| |___
414  *  / _` | __| __| '__| / __|/ _ \ __| / / _` |/ _ \ __| | '_ ` _ \ / _ \ __| '_ \ / _ \ / _` / __|
415  * | (_| | |_| |_| |    \__ \  __/ |_ / / (_| |  __/ |_  | | | | | |  __/ |_| | | | (_) | (_| \__ \
416  *  \__,_|\__|\__|_|    |___/\___|\__/_/ \__, |\___|\__| |_| |_| |_|\___|\__|_| |_|\___/ \__,_|___/
417  *                                        __/ |
418  *                                       |___/
419  ***************************************************************************************************/
420
421 ia32_attr_t *get_ia32_attr(ir_node *node) {
422         assert(is_ia32_irn(node) && "need ia32 node to get ia32 attributes");
423         return (ia32_attr_t *)get_irn_generic_attr(node);
424 }
425
426 const ia32_attr_t *get_ia32_attr_const(const ir_node *node) {
427         assert(is_ia32_irn(node) && "need ia32 node to get ia32 attributes");
428         return (const ia32_attr_t*) get_irn_generic_attr_const(node);
429 }
430
431 ia32_x87_attr_t *get_ia32_x87_attr(ir_node *node) {
432         ia32_attr_t     *attr     = get_ia32_attr(node);
433         ia32_x87_attr_t *x87_attr = CAST_IA32_ATTR(ia32_x87_attr_t, attr);
434         return x87_attr;
435 }
436
437 const ia32_x87_attr_t *get_ia32_x87_attr_const(const ir_node *node) {
438         const ia32_attr_t     *attr     = get_ia32_attr_const(node);
439         const ia32_x87_attr_t *x87_attr = CONST_CAST_IA32_ATTR(ia32_x87_attr_t, attr);
440         return x87_attr;
441 }
442
443 const ia32_asm_attr_t *get_ia32_asm_attr_const(const ir_node *node) {
444         const ia32_attr_t     *attr     = get_ia32_attr_const(node);
445         const ia32_asm_attr_t *asm_attr = CONST_CAST_IA32_ATTR(ia32_asm_attr_t, attr);
446
447         return asm_attr;
448 }
449
450 const ia32_immediate_attr_t *get_ia32_immediate_attr_const(const ir_node *node)
451 {
452         const ia32_attr_t     *attr     = get_ia32_attr_const(node);
453         const ia32_immediate_attr_t *immediate_attr
454                 = CONST_CAST_IA32_ATTR(ia32_immediate_attr_t, attr);
455
456         return immediate_attr;
457 }
458
459 /**
460  * Gets the type of an ia32 node.
461  */
462 ia32_op_type_t get_ia32_op_type(const ir_node *node) {
463         const ia32_attr_t *attr = get_ia32_attr_const(node);
464         return attr->data.tp;
465 }
466
467 /**
468  * Sets the type of an ia32 node.
469  */
470 void set_ia32_op_type(ir_node *node, ia32_op_type_t tp) {
471         ia32_attr_t *attr = get_ia32_attr(node);
472         attr->data.tp     = tp;
473 }
474
475 /**
476  * Gets the immediate op type of an ia32 node.
477  */
478 ia32_immop_type_t get_ia32_immop_type(const ir_node *node) {
479         const ia32_attr_t *attr = get_ia32_attr_const(node);
480         return attr->data.imm_tp;
481 }
482
483 /**
484  * Gets the supported address mode of an ia32 node
485  */
486 ia32_am_type_t get_ia32_am_support(const ir_node *node) {
487         const ia32_attr_t *attr = get_ia32_attr_const(node);
488         return attr->data.am_support;
489 }
490
491 ia32_am_arity_t get_ia32_am_arity(const ir_node *node) {
492         const ia32_attr_t *attr = get_ia32_attr_const(node);
493         return attr->data.am_arity;
494 }
495
496 /**
497  * Sets the supported address mode of an ia32 node
498  */
499 void set_ia32_am_support(ir_node *node, ia32_am_type_t am_tp,
500                          ia32_am_arity_t arity) {
501         ia32_attr_t *attr     = get_ia32_attr(node);
502         attr->data.am_support = am_tp;
503         attr->data.am_arity   = arity;
504
505         assert((am_tp == ia32_am_None && arity == ia32_am_arity_none) ||
506                (am_tp != ia32_am_None &&
507                ((arity == ia32_am_unary) || (arity == ia32_am_binary))));
508 }
509
510 /**
511  * Gets the address mode flavour of an ia32 node
512  */
513 ia32_am_flavour_t get_ia32_am_flavour(const ir_node *node) {
514         const ia32_attr_t *attr = get_ia32_attr_const(node);
515         return attr->data.am_flavour;
516 }
517
518 /**
519  * Sets the address mode flavour of an ia32 node
520  */
521 void set_ia32_am_flavour(ir_node *node, ia32_am_flavour_t am_flavour) {
522         ia32_attr_t *attr     = get_ia32_attr(node);
523         attr->data.am_flavour = am_flavour;
524 }
525
526 /**
527  * Gets the address mode offset as int.
528  */
529 int get_ia32_am_offs_int(const ir_node *node) {
530         const ia32_attr_t *attr = get_ia32_attr_const(node);
531         return attr->am_offs;
532 }
533
534 /**
535  * Sets the address mode offset from an int.
536  */
537 void set_ia32_am_offs_int(ir_node *node, int offset) {
538         ia32_attr_t *attr = get_ia32_attr(node);
539         attr->am_offs = offset;
540 }
541
542 void add_ia32_am_offs_int(ir_node *node, int offset) {
543         ia32_attr_t *attr = get_ia32_attr(node);
544         attr->am_offs += offset;
545 }
546
547 /**
548  * Returns the symconst entity associated to address mode.
549  */
550 ir_entity *get_ia32_am_sc(const ir_node *node) {
551         const ia32_attr_t *attr = get_ia32_attr_const(node);
552         return attr->am_sc;
553 }
554
555 /**
556  * Sets the symconst entity associated to address mode.
557  */
558 void set_ia32_am_sc(ir_node *node, ir_entity *entity) {
559         ia32_attr_t *attr = get_ia32_attr(node);
560         attr->am_sc       = entity;
561 }
562
563 /**
564  * Sets the sign bit for address mode symconst.
565  */
566 void set_ia32_am_sc_sign(ir_node *node) {
567         ia32_attr_t *attr     = get_ia32_attr(node);
568         attr->data.am_sc_sign = 1;
569 }
570
571 /**
572  * Clears the sign bit for address mode symconst.
573  */
574 void clear_ia32_am_sc_sign(ir_node *node) {
575         ia32_attr_t *attr     = get_ia32_attr(node);
576         attr->data.am_sc_sign = 0;
577 }
578
579 /**
580  * Returns the sign bit for address mode symconst.
581  */
582 int is_ia32_am_sc_sign(const ir_node *node) {
583         const ia32_attr_t *attr = get_ia32_attr_const(node);
584         return attr->data.am_sc_sign;
585 }
586
587 /**
588  * Gets the addr mode const.
589  */
590 int get_ia32_am_scale(const ir_node *node) {
591         const ia32_attr_t *attr = get_ia32_attr_const(node);
592         return attr->data.am_scale;
593 }
594
595 /**
596  * Sets the index register scale for address mode.
597  */
598 void set_ia32_am_scale(ir_node *node, int scale) {
599         ia32_attr_t *attr   = get_ia32_attr(node);
600         attr->data.am_scale = scale;
601 }
602
603 /**
604  * Return the tarval of an immediate operation or NULL in case of SymConst
605  */
606 tarval *get_ia32_Immop_tarval(const ir_node *node) {
607         const ia32_attr_t *attr = get_ia32_attr_const(node);
608         assert(attr->data.imm_tp == ia32_ImmConst);
609     return attr->cnst_val.tv;
610 }
611
612 /**
613  * Sets the attributes of an immediate operation to the specified tarval
614  */
615 void set_ia32_Immop_tarval(ir_node *node, tarval *tv) {
616         ia32_attr_t *attr = get_ia32_attr(node);
617         attr->data.imm_tp = ia32_ImmConst;
618         attr->cnst_val.tv = tv;
619 }
620
621 void set_ia32_Immop_symconst(ir_node *node, ir_entity *entity) {
622         ia32_attr_t *attr = get_ia32_attr(node);
623         attr->data.imm_tp = ia32_ImmSymConst;
624         attr->cnst_val.sc = entity;
625 }
626
627 ir_entity *get_ia32_Immop_symconst(const ir_node *node) {
628         const ia32_attr_t *attr = get_ia32_attr_const(node);
629         assert(attr->data.imm_tp == ia32_ImmSymConst);
630         return attr->cnst_val.sc;
631 }
632
633 /**
634  * Sets the uses_frame flag.
635  */
636 void set_ia32_use_frame(ir_node *node) {
637         ia32_attr_t *attr    = get_ia32_attr(node);
638         attr->data.use_frame = 1;
639 }
640
641 /**
642  * Clears the uses_frame flag.
643  */
644 void clear_ia32_use_frame(ir_node *node) {
645         ia32_attr_t *attr    = get_ia32_attr(node);
646         attr->data.use_frame = 0;
647 }
648
649 /**
650  * Gets the uses_frame flag.
651  */
652 int is_ia32_use_frame(const ir_node *node) {
653         const ia32_attr_t *attr = get_ia32_attr_const(node);
654         return attr->data.use_frame;
655 }
656
657 /**
658  * Sets node to commutative.
659  */
660 void set_ia32_commutative(ir_node *node) {
661         ia32_attr_t *attr         = get_ia32_attr(node);
662         attr->data.is_commutative = 1;
663 }
664
665 /**
666  * Sets node to non-commutative.
667  */
668 void clear_ia32_commutative(ir_node *node) {
669         ia32_attr_t *attr         = get_ia32_attr(node);
670         attr->data.is_commutative = 0;
671 }
672
673 /**
674  * Checks if node is commutative.
675  */
676 int is_ia32_commutative(const ir_node *node) {
677         const ia32_attr_t *attr = get_ia32_attr_const(node);
678         return attr->data.is_commutative;
679 }
680
681 /**
682  * Sets node emit_cl.
683  */
684 void set_ia32_emit_cl(ir_node *node) {
685         ia32_attr_t *attr  = get_ia32_attr(node);
686         attr->data.emit_cl = 1;
687 }
688
689 /**
690  * Clears node emit_cl.
691  */
692 void clear_ia32_emit_cl(ir_node *node) {
693         ia32_attr_t *attr  = get_ia32_attr(node);
694         attr->data.emit_cl = 0;
695 }
696
697 /**
698  * Checks if node needs %cl.
699  */
700 int is_ia32_emit_cl(const ir_node *node) {
701         const ia32_attr_t *attr = get_ia32_attr_const(node);
702         return attr->data.emit_cl;
703 }
704
705 /**
706  * Sets node got_lea.
707  */
708 void set_ia32_got_lea(ir_node *node) {
709         ia32_attr_t *attr  = get_ia32_attr(node);
710         attr->data.got_lea = 1;
711 }
712
713 /**
714  * Clears node got_lea.
715  */
716 void clear_ia32_got_lea(ir_node *node) {
717         ia32_attr_t *attr  = get_ia32_attr(node);
718         attr->data.got_lea = 0;
719 }
720
721 /**
722  * Checks if node got lea.
723  */
724 int is_ia32_got_lea(const ir_node *node) {
725         const ia32_attr_t *attr = get_ia32_attr_const(node);
726         return attr->data.got_lea;
727 }
728
729 void set_ia32_need_stackent(ir_node *node) {
730         ia32_attr_t *attr     = get_ia32_attr(node);
731         attr->data.need_stackent = 1;
732 }
733
734 void clear_ia32_need_stackent(ir_node *node) {
735         ia32_attr_t *attr     = get_ia32_attr(node);
736         attr->data.need_stackent = 0;
737 }
738
739 int is_ia32_need_stackent(const ir_node *node) {
740         const ia32_attr_t *attr = get_ia32_attr_const(node);
741         return attr->data.need_stackent;
742 }
743
744 /**
745  * Gets the mode of the stored/loaded value (only set for Store/Load)
746  */
747 ir_mode *get_ia32_ls_mode(const ir_node *node) {
748         const ia32_attr_t *attr = get_ia32_attr_const(node);
749         return attr->ls_mode;
750 }
751
752 /**
753  * Sets the mode of the stored/loaded value (only set for Store/Load)
754  */
755 void set_ia32_ls_mode(ir_node *node, ir_mode *mode) {
756         ia32_attr_t *attr = get_ia32_attr(node);
757         attr->ls_mode     = mode;
758 }
759
760 /**
761  * Gets the frame entity assigned to this node.
762  */
763 ir_entity *get_ia32_frame_ent(const ir_node *node) {
764         const ia32_attr_t *attr = get_ia32_attr_const(node);
765         return attr->frame_ent;
766 }
767
768 /**
769  * Sets the frame entity for this node.
770  */
771 void set_ia32_frame_ent(ir_node *node, ir_entity *ent) {
772         ia32_attr_t *attr = get_ia32_attr(node);
773         attr->frame_ent   = ent;
774         if(ent != NULL)
775                 set_ia32_use_frame(node);
776         else
777                 clear_ia32_use_frame(node);
778 }
779
780
781 /**
782  * Gets the instruction latency.
783  */
784 unsigned get_ia32_latency(const ir_node *node) {
785         const ia32_attr_t *attr = get_ia32_attr_const(node);
786         return attr->latency;
787 }
788
789 /**
790 * Sets the instruction latency.
791 */
792 void set_ia32_latency(ir_node *node, unsigned latency) {
793         ia32_attr_t *attr = get_ia32_attr(node);
794         attr->latency     = latency;
795 }
796
797 /**
798  * Returns the argument register requirements of an ia32 node.
799  */
800 const arch_register_req_t **get_ia32_in_req_all(const ir_node *node) {
801         const ia32_attr_t *attr = get_ia32_attr_const(node);
802         return attr->in_req;
803 }
804
805 /**
806  * Sets the argument register requirements of an ia32 node.
807  */
808 void set_ia32_in_req_all(ir_node *node, const arch_register_req_t **reqs) {
809         ia32_attr_t *attr = get_ia32_attr(node);
810         attr->in_req      = reqs;
811 }
812
813 /**
814  * Returns the result register requirements of an ia32 node.
815  */
816 const arch_register_req_t **get_ia32_out_req_all(const ir_node *node) {
817         const ia32_attr_t *attr = get_ia32_attr_const(node);
818         return attr->out_req;
819 }
820
821 /**
822  * Sets the result register requirements of an ia32 node.
823  */
824 void set_ia32_out_req_all(ir_node *node, const arch_register_req_t **reqs) {
825         ia32_attr_t *attr = get_ia32_attr(node);
826         attr->out_req     = reqs;
827 }
828
829 /**
830  * Returns the argument register requirement at position pos of an ia32 node.
831  */
832 const arch_register_req_t *get_ia32_in_req(const ir_node *node, int pos) {
833         const ia32_attr_t *attr = get_ia32_attr_const(node);
834         if(attr->in_req == NULL)
835                 return arch_no_register_req;
836
837         return attr->in_req[pos];
838 }
839
840 /**
841  * Returns the result register requirement at position pos of an ia32 node.
842  */
843 const arch_register_req_t *get_ia32_out_req(const ir_node *node, int pos) {
844         const ia32_attr_t *attr = get_ia32_attr_const(node);
845         if(attr->out_req == NULL)
846                 return arch_no_register_req;
847
848         return attr->out_req[pos];
849 }
850
851 /**
852  * Sets the OUT register requirements at position pos.
853  */
854 void set_ia32_req_out(ir_node *node, const arch_register_req_t *req, int pos) {
855         ia32_attr_t *attr  = get_ia32_attr(node);
856         attr->out_req[pos] = req;
857 }
858
859 /**
860  * Sets the IN register requirements at position pos.
861  */
862 void set_ia32_req_in(ir_node *node, const arch_register_req_t *req, int pos) {
863         ia32_attr_t *attr = get_ia32_attr(node);
864         attr->in_req[pos] = req;
865 }
866
867 /**
868  * Returns the register flag of an ia32 node.
869  */
870 arch_irn_flags_t get_ia32_flags(const ir_node *node) {
871         const ia32_attr_t *attr = get_ia32_attr_const(node);
872         return attr->data.flags;
873 }
874
875 /**
876  * Sets the register flag of an ia32 node.
877  */
878 void set_ia32_flags(ir_node *node, arch_irn_flags_t flags) {
879         ia32_attr_t *attr = get_ia32_attr(node);
880         attr->data.flags  = flags;
881 }
882
883 /**
884  * Returns the result register slots of an ia32 node.
885  */
886 const arch_register_t **get_ia32_slots(const ir_node *node) {
887         const ia32_attr_t *attr = get_ia32_attr_const(node);
888         return attr->slots;
889 }
890
891 /**
892  * Returns the number of results.
893  */
894 int get_ia32_n_res(const ir_node *node) {
895         const ia32_attr_t *attr = get_ia32_attr_const(node);
896         return ARR_LEN(attr->slots);
897 }
898
899 /**
900  * Returns the flavour of an ia32 node,
901  */
902 ia32_op_flavour_t get_ia32_flavour(const ir_node *node) {
903         const ia32_attr_t *attr = get_ia32_attr_const(node);
904         return attr->data.op_flav;
905 }
906
907 /**
908  * Sets the flavour of an ia32 node to flavour_Div/Mod/DivMod/Mul/Mulh.
909  */
910 void set_ia32_flavour(ir_node *node, ia32_op_flavour_t op_flav) {
911         ia32_attr_t *attr  = get_ia32_attr(node);
912         attr->data.op_flav = op_flav;
913 }
914
915 /**
916  * Returns the projnum code.
917  */
918 long get_ia32_pncode(const ir_node *node)
919 {
920         const ia32_attr_t *attr = get_ia32_attr_const(node);
921         return attr->pn_code;
922 }
923
924 /**
925  * Sets the projnum code
926  */
927 void set_ia32_pncode(ir_node *node, long code)
928 {
929         ia32_attr_t *attr = get_ia32_attr(node);
930         attr->pn_code     = code;
931 }
932
933 /**
934  * Sets the flags for the n'th out.
935  */
936 void set_ia32_out_flags(ir_node *node, arch_irn_flags_t flags, int pos) {
937         ia32_attr_t *attr = get_ia32_attr(node);
938         assert(pos < ARR_LEN(attr->out_flags) && "Invalid OUT position.");
939         attr->out_flags[pos] = flags;
940 }
941
942 /**
943  * Gets the flags for the n'th out.
944  */
945 arch_irn_flags_t get_ia32_out_flags(const ir_node *node, int pos) {
946         const ia32_attr_t *attr = get_ia32_attr_const(node);
947         assert(pos < ARR_LEN(attr->out_flags) && "Invalid OUT position.");
948         return attr->out_flags[pos];
949 }
950
951 /**
952  * Get the list of available execution units.
953  */
954 const be_execution_unit_t ***get_ia32_exec_units(const ir_node *node) {
955         const ia32_attr_t *attr = get_ia32_attr_const(node);
956         return attr->exec_units;
957 }
958
959 /**
960  * Get the exception label attribute.
961  */
962 unsigned get_ia32_exc_label(const ir_node *node) {
963         const ia32_attr_t *attr = get_ia32_attr_const(node);
964         return attr->data.except_label;
965 }
966
967 /**
968  * Set the exception label attribute.
969  */
970 void set_ia32_exc_label(ir_node *node, unsigned flag) {
971         ia32_attr_t *attr = get_ia32_attr(node);
972         attr->data.except_label = flag;
973 }
974
975 #ifndef NDEBUG
976
977 /**
978  * Returns the name of the original ir node.
979  */
980 const char *get_ia32_orig_node(const ir_node *node) {
981         const ia32_attr_t *attr = get_ia32_attr_const(node);
982         return attr->orig_node;
983 }
984
985 /**
986  * Sets the name of the original ir node.
987  */
988 void set_ia32_orig_node(ir_node *node, const char *name) {
989         ia32_attr_t *attr = get_ia32_attr(node);
990         attr->orig_node   = name;
991 }
992
993 #endif /* NDEBUG */
994
995 /******************************************************************************************************
996  *                      _       _         _   _           __                  _   _
997  *                     (_)     | |       | | | |         / _|                | | (_)
998  *  ___ _ __   ___  ___ _  __ _| |   __ _| |_| |_ _ __  | |_ _   _ _ __   ___| |_ _  ___  _ __    ___
999  * / __| '_ \ / _ \/ __| |/ _` | |  / _` | __| __| '__| |  _| | | | '_ \ / __| __| |/ _ \| '_ \  / __|
1000  * \__ \ |_) |  __/ (__| | (_| | | | (_| | |_| |_| |    | | | |_| | | | | (__| |_| | (_) | | | | \__ \
1001  * |___/ .__/ \___|\___|_|\__,_|_|  \__,_|\__|\__|_|    |_|  \__,_|_| |_|\___|\__|_|\___/|_| |_| |___/
1002  *     | |
1003  *     |_|
1004  ******************************************************************************************************/
1005
1006 /**
1007  * Copy the attributes from an ia32_Const to an Immop (Add_i, Sub_i, ...) node
1008  */
1009 void copy_ia32_Immop_attr(ir_node *node, ir_node *from) {
1010         ia32_immop_type_t immop_type = get_ia32_immop_type(from);
1011
1012         if(immop_type == ia32_ImmConst) {
1013                 set_ia32_Immop_tarval(node, get_ia32_Immop_tarval(from));
1014         } else if(immop_type == ia32_ImmSymConst) {
1015                 set_ia32_Immop_symconst(node, get_ia32_Immop_symconst(from));
1016         } else {
1017                 ia32_attr_t *attr = get_ia32_attr(node);
1018                 assert(immop_type == ia32_ImmNone);
1019                 attr->data.imm_tp = ia32_ImmNone;
1020         }
1021 }
1022
1023 /**
1024  * Copy the attributes from a Firm Const/SymConst to an ia32_Const
1025  */
1026 void set_ia32_Const_attr(ir_node *ia32_cnst, ir_node *cnst) {
1027         assert(is_ia32_Cnst(ia32_cnst) && "Need ia32_Const to set Const attr");
1028
1029         switch (get_irn_opcode(cnst)) {
1030                 case iro_Const:
1031                         set_ia32_Const_tarval(ia32_cnst, get_Const_tarval(cnst));
1032                         break;
1033                 case iro_SymConst:
1034                         assert(get_SymConst_kind(cnst) == symconst_addr_ent);
1035                         set_ia32_Immop_symconst(ia32_cnst, get_SymConst_entity(cnst));
1036                         break;
1037                 case iro_Unknown:
1038                         assert(0 && "Unknown Const NYI");
1039                         break;
1040                 default:
1041                         assert(0 && "Cannot create ia32_Const for this opcode");
1042         }
1043 }
1044
1045 void set_ia32_Const_tarval(ir_node *ia32_cnst, tarval *tv) {
1046 #if 0
1047         if(mode_is_reference(get_tarval_mode(tv))) {
1048                 if(tarval_is_null(tv)) {
1049                         tv = get_tarval_null(mode_Iu);
1050                 } else {
1051                         long val;
1052                         /* workaround... */
1053                         if(!tarval_is_long(tv))
1054                                 panic("Can't convert reference tarval to mode_Iu at %+F", ia32_cnst);
1055                         val = get_tarval_long(tv);
1056                         tv = new_tarval_from_long(val, mode_Iu);
1057                 }
1058         } else {
1059                 tv = tarval_convert_to(tv, mode_Iu);
1060         }
1061 #else
1062         tv = tarval_convert_to(tv, mode_Iu);
1063 #endif
1064
1065         assert(tv != get_tarval_bad() && tv != get_tarval_undefined()
1066                         && tv != NULL);
1067         set_ia32_Immop_tarval(ia32_cnst, tv);
1068 }
1069
1070
1071 /**
1072  * Sets the AddrMode(S|D) attribute
1073  */
1074 void set_ia32_AddrMode(ir_node *node, char direction) {
1075         ia32_attr_t *attr = get_ia32_attr(node);
1076
1077         switch (direction) {
1078                 case 'D':
1079                         attr->data.tp = ia32_AddrModeD;
1080                         break;
1081                 case 'S':
1082                         attr->data.tp = ia32_AddrModeS;
1083                         break;
1084                 default:
1085                         assert(0 && "wrong AM type");
1086         }
1087 }
1088
1089 /**
1090  * Returns whether or not the node is an immediate operation with Const.
1091  */
1092 int is_ia32_ImmConst(const ir_node *node) {
1093         const ia32_attr_t *attr = get_ia32_attr_const(node);
1094         return (attr->data.imm_tp == ia32_ImmConst);
1095 }
1096
1097 /**
1098  * Returns whether or not the node is an immediate operation with SymConst.
1099  */
1100 int is_ia32_ImmSymConst(const ir_node *node) {
1101         const ia32_attr_t *attr = get_ia32_attr_const(node);
1102         return (attr->data.imm_tp == ia32_ImmSymConst);
1103 }
1104
1105 /**
1106  * Returns whether or not the node is an AddrModeS node.
1107  */
1108 int is_ia32_AddrModeS(const ir_node *node) {
1109         const ia32_attr_t *attr = get_ia32_attr_const(node);
1110         return (attr->data.tp == ia32_AddrModeS);
1111 }
1112
1113 /**
1114  * Returns whether or not the node is an AddrModeD node.
1115  */
1116 int is_ia32_AddrModeD(const ir_node *node) {
1117         const ia32_attr_t *attr = get_ia32_attr_const(node);
1118         return (attr->data.tp == ia32_AddrModeD);
1119 }
1120
1121 /**
1122  * Checks if node is a Load or xLoad/vfLoad.
1123  */
1124 int is_ia32_Ld(const ir_node *node) {
1125         int op = get_ia32_irn_opcode(node);
1126         return op == iro_ia32_Load ||
1127                op == iro_ia32_xLoad ||
1128                op == iro_ia32_vfld ||
1129                op == iro_ia32_fld;
1130 }
1131
1132 /**
1133  * Checks if node is a Store or xStore/vfStore.
1134  */
1135 int is_ia32_St(const ir_node *node) {
1136         int op = get_ia32_irn_opcode(node);
1137         return op == iro_ia32_Store ||
1138                op == iro_ia32_Store8Bit ||
1139                op == iro_ia32_xStore ||
1140                op == iro_ia32_vfst ||
1141                op == iro_ia32_fst ||
1142                op == iro_ia32_fstp;
1143 }
1144
1145 /**
1146  * Checks if node is a Const or xConst/vfConst.
1147  */
1148 int is_ia32_Cnst(const ir_node *node) {
1149         int op = get_ia32_irn_opcode(node);
1150         return op == iro_ia32_Const || op == iro_ia32_xConst || op == iro_ia32_vfConst;
1151 }
1152
1153 /**
1154  * Returns the name of the OUT register at position pos.
1155  */
1156 const char *get_ia32_out_reg_name(const ir_node *node, int pos) {
1157         const ia32_attr_t *attr = get_ia32_attr_const(node);
1158
1159         assert(pos < ARR_LEN(attr->slots) && "Invalid OUT position.");
1160         assert(attr->slots[pos]  && "No register assigned");
1161
1162         return arch_register_get_name(attr->slots[pos]);
1163 }
1164
1165 /**
1166  * Returns the index of the OUT register at position pos within its register class.
1167  */
1168 int get_ia32_out_regnr(const ir_node *node, int pos) {
1169         const ia32_attr_t *attr = get_ia32_attr_const(node);
1170
1171         assert(pos < ARR_LEN(attr->slots) && "Invalid OUT position.");
1172         assert(attr->slots[pos]  && "No register assigned");
1173
1174         return arch_register_get_index(attr->slots[pos]);
1175 }
1176
1177 void ia32_swap_left_right(ir_node *node)
1178 {
1179         ir_node *left  = get_irn_n(node, 2);
1180         ir_node *right = get_irn_n(node, 3);
1181         assert(is_ia32_commutative(node));
1182         set_irn_n(node, 2, right);
1183         set_irn_n(node, 3, left);
1184         set_ia32_pncode(node, get_inversed_pnc(get_ia32_pncode(node)));
1185 }
1186
1187 /**
1188  * Returns the OUT register at position pos.
1189  */
1190 const arch_register_t *get_ia32_out_reg(const ir_node *node, int pos) {
1191         const ia32_attr_t *attr = get_ia32_attr_const(node);
1192
1193         assert(pos < ARR_LEN(attr->slots) && "Invalid OUT position.");
1194         assert(attr->slots[pos]  && "No register assigned");
1195
1196         return attr->slots[pos];
1197 }
1198
1199 /**
1200  * Initializes the nodes attributes.
1201  */
1202 void init_ia32_attributes(ir_node *node, arch_irn_flags_t flags,
1203                           const arch_register_req_t **in_reqs,
1204                           const arch_register_req_t **out_reqs,
1205                           const be_execution_unit_t ***execution_units,
1206                           int n_res, unsigned latency)
1207 {
1208         ir_graph       *irg  = get_irn_irg(node);
1209         struct obstack *obst = get_irg_obstack(irg);
1210         ia32_attr_t    *attr = get_ia32_attr(node);
1211
1212         set_ia32_flags(node, flags);
1213         set_ia32_in_req_all(node, in_reqs);
1214         set_ia32_out_req_all(node, out_reqs);
1215         set_ia32_latency(node, latency);
1216
1217         attr->exec_units  = execution_units;
1218 #ifndef NDEBUG
1219         attr->attr_type  |= IA32_ATTR_ia32_attr_t;
1220 #endif
1221
1222         attr->out_flags = NEW_ARR_D(int, obst, n_res);
1223         memset(attr->out_flags, 0, n_res * sizeof(attr->out_flags[0]));
1224
1225         attr->slots = NEW_ARR_D(const arch_register_t*, obst, n_res);
1226         memset(attr->slots, 0, n_res * sizeof(attr->slots[0]));
1227 }
1228
1229 void
1230 init_ia32_x87_attributes(ir_node *res)
1231 {
1232 #ifndef NDEBUG
1233         ia32_attr_t *attr  = get_ia32_attr(res);
1234         attr->attr_type   |= IA32_ATTR_ia32_x87_attr_t;
1235 #endif
1236 }
1237
1238 void
1239 init_ia32_asm_attributes(ir_node *res)
1240 {
1241 #ifndef NDEBUG
1242         ia32_attr_t *attr  = get_ia32_attr(res);
1243         attr->attr_type   |= IA32_ATTR_ia32_asm_attr_t;
1244 #endif
1245 }
1246
1247 void
1248 init_ia32_immediate_attributes(ir_node *res, ir_entity *symconst,
1249                                int symconst_sign, long offset)
1250 {
1251         ia32_immediate_attr_t *attr = get_irn_generic_attr(res);
1252
1253 #ifndef NDEBUG
1254         attr->attr.attr_type   |= IA32_ATTR_ia32_immediate_attr_t;
1255 #endif
1256         attr->symconst             = symconst;
1257         attr->attr.data.am_sc_sign = symconst_sign;
1258         attr->offset               = offset;
1259 }
1260
1261 ir_node *get_ia32_result_proj(const ir_node *node)
1262 {
1263         const ir_edge_t *edge;
1264
1265         foreach_out_edge(node, edge) {
1266                 ir_node *proj = get_edge_src_irn(edge);
1267                 if(get_Proj_proj(proj) == 0) {
1268                         return proj;
1269                 }
1270         }
1271         return NULL;
1272 }
1273
1274 /***************************************************************************************
1275  *                  _                            _                   _
1276  *                 | |                          | |                 | |
1277  *  _ __   ___   __| | ___    ___ ___  _ __  ___| |_ _ __ _   _  ___| |_ ___  _ __ ___
1278  * | '_ \ / _ \ / _` |/ _ \  / __/ _ \| '_ \/ __| __| '__| | | |/ __| __/ _ \| '__/ __|
1279  * | | | | (_) | (_| |  __/ | (_| (_) | | | \__ \ |_| |  | |_| | (__| || (_) | |  \__ \
1280  * |_| |_|\___/ \__,_|\___|  \___\___/|_| |_|___/\__|_|   \__,_|\___|\__\___/|_|  |___/
1281  *
1282  ***************************************************************************************/
1283
1284 /* default compare operation to compare attributes */
1285 int ia32_compare_attr(const ia32_attr_t *a, const ia32_attr_t *b) {
1286         if (a->data.tp != b->data.tp
1287                         || a->data.imm_tp != b->data.imm_tp)
1288                 return 1;
1289
1290         if (a->data.imm_tp == ia32_ImmConst
1291                         && a->cnst_val.tv != b->cnst_val.tv)
1292                 return 1;
1293
1294         if (a->data.imm_tp == ia32_ImmSymConst
1295                         && a->cnst_val.sc != b->cnst_val.sc)
1296                 return 1;
1297
1298         if (a->data.am_flavour != b->data.am_flavour
1299             || a->data.am_scale != b->data.am_scale
1300             || a->data.am_sc_sign != b->data.am_sc_sign
1301             || a->am_offs != b->am_offs
1302             || a->am_sc != b->am_sc
1303             || a->ls_mode != b->ls_mode)
1304                 return 1;
1305
1306         if (a->data.use_frame != b->data.use_frame
1307             || a->data.use_frame != b->data.use_frame
1308             || a->frame_ent != b->frame_ent)
1309                 return 1;
1310
1311         if(a->pn_code != b->pn_code)
1312                 return 1;
1313
1314         if (a->data.tp != b->data.tp
1315             || a->data.op_flav != b->data.op_flav)
1316                 return 1;
1317
1318         if (a->data.except_label != b->data.except_label)
1319                 return 1;
1320
1321         return 0;
1322 }
1323
1324 static
1325 int ia32_compare_nodes_attr(ir_node *a, ir_node *b)
1326 {
1327         const ia32_attr_t* attr_a = get_ia32_attr_const(a);
1328         const ia32_attr_t* attr_b = get_ia32_attr_const(b);
1329
1330         return ia32_compare_attr(attr_a, attr_b);
1331 }
1332
1333 static
1334 int ia32_compare_x87_attr(ir_node *a, ir_node *b)
1335 {
1336         return ia32_compare_nodes_attr(a, b);
1337 }
1338
1339 static
1340 int ia32_compare_asm_attr(ir_node *a, ir_node *b)
1341 {
1342         const ia32_asm_attr_t *attr_a;
1343         const ia32_asm_attr_t *attr_b;
1344
1345         if(ia32_compare_nodes_attr(a, b))
1346                 return 1;
1347
1348         attr_a = get_ia32_asm_attr_const(a);
1349         attr_b = get_ia32_asm_attr_const(b);
1350
1351         if(attr_a->asm_text != attr_b->asm_text)
1352                 return 1;
1353
1354         return 0;
1355 }
1356
1357 static
1358 int ia32_compare_immediate_attr(ir_node *a, ir_node *b)
1359 {
1360         const ia32_immediate_attr_t *attr_a = get_ia32_immediate_attr_const(a);
1361         const ia32_immediate_attr_t *attr_b = get_ia32_immediate_attr_const(b);
1362
1363         if(attr_a->symconst != attr_b->symconst ||
1364            attr_a->attr.data.am_sc_sign != attr_b->attr.data.am_sc_sign ||
1365            attr_a->offset != attr_b->offset)
1366                 return 1;
1367
1368         return 0;
1369 }
1370
1371 /* copies the ia32 attributes */
1372 static void ia32_copy_attr(const ir_node *old_node, ir_node *new_node)
1373 {
1374         ir_graph          *irg      = get_irn_irg(new_node);
1375         struct obstack    *obst     = get_irg_obstack(irg);
1376         const ia32_attr_t *attr_old = get_ia32_attr_const(old_node);
1377         ia32_attr_t       *attr_new = get_ia32_attr(new_node);
1378
1379         /* copy the attributes */
1380         memcpy(attr_new, attr_old, get_op_attr_size(get_irn_op(old_node)));
1381
1382         /* copy out flags */
1383         attr_new->out_flags =
1384                 DUP_ARR_D(int, obst, attr_old->out_flags);
1385         /* copy register assignments */
1386         attr_new->slots =
1387                 DUP_ARR_D(arch_register_t*, obst, attr_old->slots);
1388 }
1389
1390 /* Include the generated constructor functions */
1391 #include "gen_ia32_new_nodes.c.inl"