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