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