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