2 * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved.
4 * This file is part of libFirm.
6 * This file may be distributed and/or modified under the terms of the
7 * GNU General Public License version 2 as published by the Free Software
8 * Foundation and appearing in the file LICENSE.GPL included in the
9 * packaging of this file.
11 * Licensees holding valid libFirm Professional Edition licenses may use
12 * this file in accordance with the libFirm Commercial License.
13 * Agreement provided with the Software.
15 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * @brief Handling of ia32 specific firm opcodes.
23 * @author Christian Wuerdig
26 * This file implements the creation of the achitecture specific firm opcodes
27 * and the coresponding node constructors for the ia32 assembler irg.
36 #include "irgraph_t.h"
42 #include "firm_common_t.h"
47 #include "raw_bitset.h"
50 #include "../bearch_t.h"
52 #include "bearch_ia32_t.h"
53 #include "ia32_nodes_attr.h"
54 #include "ia32_new_nodes.h"
55 #include "gen_ia32_regalloc_if.h"
56 #include "gen_ia32_machine.h"
58 /***********************************************************************************
61 * __| |_ _ _ __ ___ _ __ ___ _ __ _ _ __ | |_ ___ _ __| |_ __ _ ___ ___
62 * / _` | | | | '_ ` _ \| '_ \ / _ \ '__| | | '_ \| __/ _ \ '__| _/ _` |/ __/ _ \
63 * | (_| | |_| | | | | | | |_) | __/ | | | | | | || __/ | | || (_| | (_| __/
64 * \__,_|\__,_|_| |_| |_| .__/ \___|_| |_|_| |_|\__\___|_| |_| \__,_|\___\___|
67 ***********************************************************************************/
70 * Dumps the register requirements for either in or out.
72 static void dump_reg_req(FILE *F, ir_node *n, const arch_register_req_t **reqs,
74 char *dir = inout ? "out" : "in";
75 int max = inout ? get_ia32_n_res(n) : get_irn_arity(n);
79 memset(buf, 0, sizeof(buf));
82 for (i = 0; i < max; i++) {
83 fprintf(F, "%sreq #%d =", dir, i);
85 if (reqs[i]->type == arch_register_req_type_none) {
89 if (reqs[i]->type & arch_register_req_type_normal) {
90 fprintf(F, " %s", reqs[i]->cls->name);
93 if (reqs[i]->type & arch_register_req_type_limited) {
95 arch_register_req_format(buf, sizeof(buf), reqs[i], n));
98 if (reqs[i]->type & arch_register_req_type_should_be_same) {
99 ir_fprintf(F, " same as %+F", get_irn_n(n, reqs[i]->other_same));
102 if (reqs[i]->type & arch_register_req_type_should_be_different) {
103 ir_fprintf(F, " different from %+F", get_irn_n(n, reqs[i]->other_different));
112 fprintf(F, "%sreq = N/A\n", dir);
117 * Dumper interface for dumping ia32 nodes in vcg.
118 * @param n the node to dump
119 * @param F the output file
120 * @param reason indicates which kind of information should be dumped
121 * @return 0 on success or != 0 on failure
123 static int ia32_dump_node(ir_node *n, FILE *F, dump_reason_t reason) {
124 ir_mode *mode = NULL;
126 int i, n_res, am_flav, flags;
127 const arch_register_req_t **reqs;
128 const arch_register_t **slots;
131 case dump_node_opcode_txt:
132 fprintf(F, "%s", get_irn_opname(n));
135 case dump_node_mode_txt:
136 mode = get_irn_mode(n);
138 if (is_ia32_Ld(n) || is_ia32_St(n)) {
139 mode = get_ia32_ls_mode(n);
142 fprintf(F, "[%s]", mode ? get_mode_name(mode) : "?NOMODE?");
145 case dump_node_nodeattr_txt:
146 if (is_ia32_ImmConst(n) || is_ia32_ImmSymConst(n)) {
147 if(is_ia32_ImmSymConst(n)) {
148 ir_entity *ent = get_ia32_Immop_symconst(n);
149 ident *id = get_entity_ld_ident(ent);
150 fprintf(F, "[SymC %s]", get_id_str(id));
153 tarval *tv = get_ia32_Immop_tarval(n);
155 tarval_snprintf(buf, sizeof(buf), tv);
156 fprintf(F, "[%s]", buf);
160 if (! is_ia32_Lea(n)) {
161 if (is_ia32_AddrModeS(n)) {
162 fprintf(F, "[AM S] ");
164 else if (is_ia32_AddrModeD(n)) {
165 fprintf(F, "[AM D] ");
171 case dump_node_info_txt:
172 n_res = get_ia32_n_res(n);
173 fprintf(F, "=== IA32 attr begin ===\n");
175 /* dump IN requirements */
176 if (get_irn_arity(n) > 0) {
177 reqs = get_ia32_in_req_all(n);
178 dump_reg_req(F, n, reqs, 0);
181 /* dump OUT requirements */
183 reqs = get_ia32_out_req_all(n);
184 dump_reg_req(F, n, reqs, 1);
187 /* dump assigned registers */
188 slots = get_ia32_slots(n);
189 if (slots && n_res > 0) {
190 for (i = 0; i < n_res; i++) {
191 const arch_register_t *reg;
195 fprintf(F, "reg #%d = %s\n", i, reg ? arch_register_get_name(reg) : "n/a");
202 switch (get_ia32_op_type(n)) {
204 fprintf(F, "Normal");
207 fprintf(F, "AM Dest (Load+Store)");
210 fprintf(F, "AM Source (Load)");
213 fprintf(F, "unknown (%d)", get_ia32_op_type(n));
218 /* dump immop type */
219 fprintf(F, "immediate = ");
220 switch (get_ia32_immop_type(n)) {
227 case ia32_ImmSymConst:
228 fprintf(F, "SymConst");
231 fprintf(F, "unknown (%d)", get_ia32_immop_type(n));
236 /* dump supported am */
237 fprintf(F, "AM support = ");
238 switch (get_ia32_am_support(n)) {
243 fprintf(F, "source only (Load)");
246 fprintf(F, "dest only (Load+Store)");
252 fprintf(F, "unknown (%d)", get_ia32_am_support(n));
257 /* dump am flavour */
258 fprintf(F, "AM flavour =");
259 am_flav = get_ia32_am_flavour(n);
260 if (am_flav == ia32_am_N) {
264 if (am_flav & ia32_O) {
267 if (am_flav & ia32_B) {
270 if (am_flav & ia32_I) {
273 if (am_flav & ia32_S) {
277 fprintf(F, " (%d)\n", am_flav);
280 if(get_ia32_am_offs_int(n) != 0) {
281 fprintf(F, "AM offset = %d\n", get_ia32_am_offs_int(n));
284 /* dump AM symconst */
285 if(get_ia32_am_sc(n) != NULL) {
286 ir_entity *ent = get_ia32_am_sc(n);
287 ident *id = get_entity_ld_ident(ent);
288 fprintf(F, "AM symconst = %s\n", get_id_str(id));
292 fprintf(F, "AM scale = %d\n", get_ia32_am_scale(n));
295 if(is_ia32_SwitchJmp(n)) {
296 fprintf(F, "pn_code = %d\n", get_ia32_pncode(n));
298 if(get_ia32_pncode(n) & ia32_pn_Cmp_Unsigned) {
299 int pnc = get_ia32_pncode(n);
300 fprintf(F, "pn_code = %d (%s, unsigned)\n",
301 pnc, get_pnc_string(pnc & ~ia32_pn_Cmp_Unsigned));
303 fprintf(F, "pn_code = %d (%s)\n", get_ia32_pncode(n),
304 get_pnc_string(get_ia32_pncode(n)));
309 fprintf(F, "n_res = %d\n", get_ia32_n_res(n));
312 fprintf(F, "use_frame = %d\n", is_ia32_use_frame(n));
315 fprintf(F, "commutative = %d\n", is_ia32_commutative(n));
318 fprintf(F, "emit cl instead of ecx = %d\n", is_ia32_emit_cl(n));
321 fprintf(F, "got loea = %d\n", is_ia32_got_lea(n));
324 fprintf(F, "need stackent = %d\n", is_ia32_need_stackent(n));
327 fprintf(F, "latency = %d\n", get_ia32_latency(n));
330 fprintf(F, "flags =");
331 flags = get_ia32_flags(n);
332 if (flags == arch_irn_flags_none) {
336 if (flags & arch_irn_flags_dont_spill) {
337 fprintf(F, " unspillable");
339 if (flags & arch_irn_flags_rematerializable) {
340 fprintf(F, " remat");
342 if (flags & arch_irn_flags_ignore) {
343 fprintf(F, " ignore");
345 if (flags & arch_irn_flags_modify_sp) {
346 fprintf(F, " modify_sp");
349 fprintf(F, " (%d)\n", flags);
351 /* dump frame entity */
352 fprintf(F, "frame entity = ");
353 if (get_ia32_frame_ent(n)) {
354 ir_fprintf(F, "%+F", get_ia32_frame_ent(n));
362 fprintf(F, "ls_mode = ");
363 if (get_ia32_ls_mode(n)) {
364 ir_fprintf(F, "%+F", get_ia32_ls_mode(n));
372 /* dump original ir node name */
373 fprintf(F, "orig node = ");
374 if (get_ia32_orig_node(n)) {
375 fprintf(F, "%s", get_ia32_orig_node(n));
383 fprintf(F, "=== IA32 attr end ===\n");
384 /* end of: case dump_node_info_txt */
393 /***************************************************************************************************
395 * | | | | | | / / | | | | | | | |
396 * __ _| |_| |_ _ __ ___ ___| |_ / /_ _ ___| |_ _ __ ___ ___| |_| |__ ___ __| |___
397 * / _` | __| __| '__| / __|/ _ \ __| / / _` |/ _ \ __| | '_ ` _ \ / _ \ __| '_ \ / _ \ / _` / __|
398 * | (_| | |_| |_| | \__ \ __/ |_ / / (_| | __/ |_ | | | | | | __/ |_| | | | (_) | (_| \__ \
399 * \__,_|\__|\__|_| |___/\___|\__/_/ \__, |\___|\__| |_| |_| |_|\___|\__|_| |_|\___/ \__,_|___/
402 ***************************************************************************************************/
404 ia32_attr_t *get_ia32_attr(ir_node *node) {
405 assert(is_ia32_irn(node) && "need ia32 node to get ia32 attributes");
406 return (ia32_attr_t *)get_irn_generic_attr(node);
409 const ia32_attr_t *get_ia32_attr_const(const ir_node *node) {
410 assert(is_ia32_irn(node) && "need ia32 node to get ia32 attributes");
411 return (const ia32_attr_t*) get_irn_generic_attr_const(node);
414 ia32_x87_attr_t *get_ia32_x87_attr(ir_node *node) {
415 ia32_attr_t *attr = get_ia32_attr(node);
416 ia32_x87_attr_t *x87_attr = CAST_IA32_ATTR(ia32_x87_attr_t, attr);
420 const ia32_x87_attr_t *get_ia32_x87_attr_const(const ir_node *node) {
421 const ia32_attr_t *attr = get_ia32_attr_const(node);
422 const ia32_x87_attr_t *x87_attr = CONST_CAST_IA32_ATTR(ia32_x87_attr_t, attr);
426 const ia32_asm_attr_t *get_ia32_asm_attr_const(const ir_node *node) {
427 const ia32_attr_t *attr = get_ia32_attr_const(node);
428 const ia32_asm_attr_t *asm_attr = CONST_CAST_IA32_ATTR(ia32_asm_attr_t, attr);
433 const ia32_immediate_attr_t *get_ia32_immediate_attr_const(const ir_node *node)
435 const ia32_attr_t *attr = get_ia32_attr_const(node);
436 const ia32_immediate_attr_t *immediate_attr
437 = CONST_CAST_IA32_ATTR(ia32_immediate_attr_t, attr);
439 return immediate_attr;
443 * Gets the type of an ia32 node.
445 ia32_op_type_t get_ia32_op_type(const ir_node *node) {
446 const ia32_attr_t *attr = get_ia32_attr_const(node);
447 return attr->data.tp;
451 * Sets the type of an ia32 node.
453 void set_ia32_op_type(ir_node *node, ia32_op_type_t tp) {
454 ia32_attr_t *attr = get_ia32_attr(node);
459 * Gets the immediate op type of an ia32 node.
461 ia32_immop_type_t get_ia32_immop_type(const ir_node *node) {
462 const ia32_attr_t *attr = get_ia32_attr_const(node);
463 return attr->data.imm_tp;
467 * Gets the supported address mode of an ia32 node
469 ia32_am_type_t get_ia32_am_support(const ir_node *node) {
470 const ia32_attr_t *attr = get_ia32_attr_const(node);
471 return attr->data.am_support;
475 * Sets the supported address mode of an ia32 node
477 void set_ia32_am_support(ir_node *node, ia32_am_type_t am_tp) {
478 ia32_attr_t *attr = get_ia32_attr(node);
479 attr->data.am_support = am_tp;
483 * Gets the address mode flavour of an ia32 node
485 ia32_am_flavour_t get_ia32_am_flavour(const ir_node *node) {
486 const ia32_attr_t *attr = get_ia32_attr_const(node);
487 return attr->data.am_flavour;
491 * Sets the address mode flavour of an ia32 node
493 void set_ia32_am_flavour(ir_node *node, ia32_am_flavour_t am_flavour) {
494 ia32_attr_t *attr = get_ia32_attr(node);
495 attr->data.am_flavour = am_flavour;
499 * Gets the address mode offset as int.
501 int get_ia32_am_offs_int(const ir_node *node) {
502 const ia32_attr_t *attr = get_ia32_attr_const(node);
503 return attr->am_offs;
507 * Sets the address mode offset from an int.
509 void set_ia32_am_offs_int(ir_node *node, int offset) {
510 ia32_attr_t *attr = get_ia32_attr(node);
511 attr->am_offs = offset;
514 void add_ia32_am_offs_int(ir_node *node, int offset) {
515 ia32_attr_t *attr = get_ia32_attr(node);
516 attr->am_offs += offset;
520 * Returns the symconst entity associated to address mode.
522 ir_entity *get_ia32_am_sc(const ir_node *node) {
523 const ia32_attr_t *attr = get_ia32_attr_const(node);
528 * Sets the symconst entity associated to address mode.
530 void set_ia32_am_sc(ir_node *node, ir_entity *entity) {
531 ia32_attr_t *attr = get_ia32_attr(node);
532 attr->am_sc = entity;
536 * Sets the sign bit for address mode symconst.
538 void set_ia32_am_sc_sign(ir_node *node) {
539 ia32_attr_t *attr = get_ia32_attr(node);
540 attr->data.am_sc_sign = 1;
544 * Clears the sign bit for address mode symconst.
546 void clear_ia32_am_sc_sign(ir_node *node) {
547 ia32_attr_t *attr = get_ia32_attr(node);
548 attr->data.am_sc_sign = 0;
552 * Returns the sign bit for address mode symconst.
554 int is_ia32_am_sc_sign(const ir_node *node) {
555 const ia32_attr_t *attr = get_ia32_attr_const(node);
556 return attr->data.am_sc_sign;
560 * Gets the addr mode const.
562 int get_ia32_am_scale(const ir_node *node) {
563 const ia32_attr_t *attr = get_ia32_attr_const(node);
564 return attr->data.am_scale;
568 * Sets the index register scale for address mode.
570 void set_ia32_am_scale(ir_node *node, int scale) {
571 ia32_attr_t *attr = get_ia32_attr(node);
572 attr->data.am_scale = scale;
576 * Return the tarval of an immediate operation or NULL in case of SymConst
578 tarval *get_ia32_Immop_tarval(const ir_node *node) {
579 const ia32_attr_t *attr = get_ia32_attr_const(node);
580 assert(attr->data.imm_tp == ia32_ImmConst);
581 return attr->cnst_val.tv;
585 * Sets the attributes of an immediate operation to the specified tarval
587 void set_ia32_Immop_tarval(ir_node *node, tarval *tv) {
588 ia32_attr_t *attr = get_ia32_attr(node);
589 attr->data.imm_tp = ia32_ImmConst;
590 attr->cnst_val.tv = tv;
593 void set_ia32_Immop_symconst(ir_node *node, ir_entity *entity) {
594 ia32_attr_t *attr = get_ia32_attr(node);
595 attr->data.imm_tp = ia32_ImmSymConst;
596 attr->cnst_val.sc = entity;
599 ir_entity *get_ia32_Immop_symconst(const ir_node *node) {
600 const ia32_attr_t *attr = get_ia32_attr_const(node);
601 assert(attr->data.imm_tp == ia32_ImmSymConst);
602 return attr->cnst_val.sc;
606 * Sets the uses_frame flag.
608 void set_ia32_use_frame(ir_node *node) {
609 ia32_attr_t *attr = get_ia32_attr(node);
610 attr->data.use_frame = 1;
614 * Clears the uses_frame flag.
616 void clear_ia32_use_frame(ir_node *node) {
617 ia32_attr_t *attr = get_ia32_attr(node);
618 attr->data.use_frame = 0;
622 * Gets the uses_frame flag.
624 int is_ia32_use_frame(const ir_node *node) {
625 const ia32_attr_t *attr = get_ia32_attr_const(node);
626 return attr->data.use_frame;
630 * Sets node to commutative.
632 void set_ia32_commutative(ir_node *node) {
633 ia32_attr_t *attr = get_ia32_attr(node);
634 attr->data.is_commutative = 1;
638 * Sets node to non-commutative.
640 void clear_ia32_commutative(ir_node *node) {
641 ia32_attr_t *attr = get_ia32_attr(node);
642 attr->data.is_commutative = 0;
646 * Checks if node is commutative.
648 int is_ia32_commutative(const ir_node *node) {
649 const ia32_attr_t *attr = get_ia32_attr_const(node);
650 return attr->data.is_commutative;
656 void set_ia32_emit_cl(ir_node *node) {
657 ia32_attr_t *attr = get_ia32_attr(node);
658 attr->data.emit_cl = 1;
662 * Clears node emit_cl.
664 void clear_ia32_emit_cl(ir_node *node) {
665 ia32_attr_t *attr = get_ia32_attr(node);
666 attr->data.emit_cl = 0;
670 * Checks if node needs %cl.
672 int is_ia32_emit_cl(const ir_node *node) {
673 const ia32_attr_t *attr = get_ia32_attr_const(node);
674 return attr->data.emit_cl;
680 void set_ia32_got_lea(ir_node *node) {
681 ia32_attr_t *attr = get_ia32_attr(node);
682 attr->data.got_lea = 1;
686 * Clears node got_lea.
688 void clear_ia32_got_lea(ir_node *node) {
689 ia32_attr_t *attr = get_ia32_attr(node);
690 attr->data.got_lea = 0;
694 * Checks if node got lea.
696 int is_ia32_got_lea(const ir_node *node) {
697 const ia32_attr_t *attr = get_ia32_attr_const(node);
698 return attr->data.got_lea;
701 void set_ia32_need_stackent(ir_node *node) {
702 ia32_attr_t *attr = get_ia32_attr(node);
703 attr->data.need_stackent = 1;
706 void clear_ia32_need_stackent(ir_node *node) {
707 ia32_attr_t *attr = get_ia32_attr(node);
708 attr->data.need_stackent = 0;
711 int is_ia32_need_stackent(const ir_node *node) {
712 const ia32_attr_t *attr = get_ia32_attr_const(node);
713 return attr->data.need_stackent;
717 * Gets the mode of the stored/loaded value (only set for Store/Load)
719 ir_mode *get_ia32_ls_mode(const ir_node *node) {
720 const ia32_attr_t *attr = get_ia32_attr_const(node);
721 return attr->ls_mode;
725 * Sets the mode of the stored/loaded value (only set for Store/Load)
727 void set_ia32_ls_mode(ir_node *node, ir_mode *mode) {
728 ia32_attr_t *attr = get_ia32_attr(node);
729 attr->ls_mode = mode;
733 * Gets the frame entity assigned to this node.
735 ir_entity *get_ia32_frame_ent(const ir_node *node) {
736 const ia32_attr_t *attr = get_ia32_attr_const(node);
737 return attr->frame_ent;
741 * Sets the frame entity for this node.
743 void set_ia32_frame_ent(ir_node *node, ir_entity *ent) {
744 ia32_attr_t *attr = get_ia32_attr(node);
745 attr->frame_ent = ent;
747 set_ia32_use_frame(node);
749 clear_ia32_use_frame(node);
754 * Gets the instruction latency.
756 unsigned get_ia32_latency(const ir_node *node) {
757 const ia32_attr_t *attr = get_ia32_attr_const(node);
758 return attr->latency;
762 * Sets the instruction latency.
764 void set_ia32_latency(ir_node *node, unsigned latency) {
765 ia32_attr_t *attr = get_ia32_attr(node);
766 attr->latency = latency;
770 * Returns the argument register requirements of an ia32 node.
772 const arch_register_req_t **get_ia32_in_req_all(const ir_node *node) {
773 const ia32_attr_t *attr = get_ia32_attr_const(node);
778 * Sets the argument register requirements of an ia32 node.
780 void set_ia32_in_req_all(ir_node *node, const arch_register_req_t **reqs) {
781 ia32_attr_t *attr = get_ia32_attr(node);
786 * Returns the result register requirements of an ia32 node.
788 const arch_register_req_t **get_ia32_out_req_all(const ir_node *node) {
789 const ia32_attr_t *attr = get_ia32_attr_const(node);
790 return attr->out_req;
794 * Sets the result register requirements of an ia32 node.
796 void set_ia32_out_req_all(ir_node *node, const arch_register_req_t **reqs) {
797 ia32_attr_t *attr = get_ia32_attr(node);
798 attr->out_req = reqs;
802 * Returns the argument register requirement at position pos of an ia32 node.
804 const arch_register_req_t *get_ia32_in_req(const ir_node *node, int pos) {
805 const ia32_attr_t *attr = get_ia32_attr_const(node);
806 if(attr->in_req == NULL)
807 return arch_no_register_req;
809 return attr->in_req[pos];
813 * Returns the result register requirement at position pos of an ia32 node.
815 const arch_register_req_t *get_ia32_out_req(const ir_node *node, int pos) {
816 const ia32_attr_t *attr = get_ia32_attr_const(node);
817 if(attr->out_req == NULL)
818 return arch_no_register_req;
820 return attr->out_req[pos];
824 * Sets the OUT register requirements at position pos.
826 void set_ia32_req_out(ir_node *node, const arch_register_req_t *req, int pos) {
827 ia32_attr_t *attr = get_ia32_attr(node);
828 attr->out_req[pos] = req;
832 * Sets the IN register requirements at position pos.
834 void set_ia32_req_in(ir_node *node, const arch_register_req_t *req, int pos) {
835 ia32_attr_t *attr = get_ia32_attr(node);
836 attr->in_req[pos] = req;
840 * Returns the register flag of an ia32 node.
842 arch_irn_flags_t get_ia32_flags(const ir_node *node) {
843 const ia32_attr_t *attr = get_ia32_attr_const(node);
844 return attr->data.flags;
848 * Sets the register flag of an ia32 node.
850 void set_ia32_flags(ir_node *node, arch_irn_flags_t flags) {
851 ia32_attr_t *attr = get_ia32_attr(node);
852 attr->data.flags = flags;
856 * Returns the result register slots of an ia32 node.
858 const arch_register_t **get_ia32_slots(const ir_node *node) {
859 const ia32_attr_t *attr = get_ia32_attr_const(node);
864 * Returns the number of results.
866 int get_ia32_n_res(const ir_node *node) {
867 const ia32_attr_t *attr = get_ia32_attr_const(node);
868 return ARR_LEN(attr->slots);
872 * Returns the flavour of an ia32 node,
874 ia32_op_flavour_t get_ia32_flavour(const ir_node *node) {
875 const ia32_attr_t *attr = get_ia32_attr_const(node);
876 return attr->data.op_flav;
880 * Sets the flavour of an ia32 node to flavour_Div/Mod/DivMod/Mul/Mulh.
882 void set_ia32_flavour(ir_node *node, ia32_op_flavour_t op_flav) {
883 ia32_attr_t *attr = get_ia32_attr(node);
884 attr->data.op_flav = op_flav;
888 * Returns the projnum code.
890 pn_Cmp get_ia32_pncode(const ir_node *node) {
891 const ia32_attr_t *attr = get_ia32_attr_const(node);
892 return attr->pn_code;
896 * Sets the projnum code
898 void set_ia32_pncode(ir_node *node, pn_Cmp code) {
899 ia32_attr_t *attr = get_ia32_attr(node);
900 attr->pn_code = code;
904 * Sets the flags for the n'th out.
906 void set_ia32_out_flags(ir_node *node, arch_irn_flags_t flags, int pos) {
907 ia32_attr_t *attr = get_ia32_attr(node);
908 assert(pos < ARR_LEN(attr->out_flags) && "Invalid OUT position.");
909 attr->out_flags[pos] = flags;
913 * Gets the flags for the n'th out.
915 arch_irn_flags_t get_ia32_out_flags(const ir_node *node, int pos) {
916 const ia32_attr_t *attr = get_ia32_attr_const(node);
917 assert(pos < ARR_LEN(attr->out_flags) && "Invalid OUT position.");
918 return attr->out_flags[pos];
922 * Get the list of available execution units.
924 const be_execution_unit_t ***get_ia32_exec_units(const ir_node *node) {
925 const ia32_attr_t *attr = get_ia32_attr_const(node);
926 return attr->exec_units;
930 * Get the exception label attribute.
932 unsigned get_ia32_exc_label(const ir_node *node) {
933 const ia32_attr_t *attr = get_ia32_attr_const(node);
934 return attr->data.except_label;
938 * Set the exception label attribute.
940 void set_ia32_exc_label(ir_node *node, unsigned flag) {
941 ia32_attr_t *attr = get_ia32_attr(node);
942 attr->data.except_label = flag;
948 * Returns the name of the original ir node.
950 const char *get_ia32_orig_node(const ir_node *node) {
951 const ia32_attr_t *attr = get_ia32_attr_const(node);
952 return attr->orig_node;
956 * Sets the name of the original ir node.
958 void set_ia32_orig_node(ir_node *node, const char *name) {
959 ia32_attr_t *attr = get_ia32_attr(node);
960 attr->orig_node = name;
965 /******************************************************************************************************
967 * (_) | | | | | | / _| | | (_)
968 * ___ _ __ ___ ___ _ __ _| | __ _| |_| |_ _ __ | |_ _ _ _ __ ___| |_ _ ___ _ __ ___
969 * / __| '_ \ / _ \/ __| |/ _` | | / _` | __| __| '__| | _| | | | '_ \ / __| __| |/ _ \| '_ \ / __|
970 * \__ \ |_) | __/ (__| | (_| | | | (_| | |_| |_| | | | | |_| | | | | (__| |_| | (_) | | | | \__ \
971 * |___/ .__/ \___|\___|_|\__,_|_| \__,_|\__|\__|_| |_| \__,_|_| |_|\___|\__|_|\___/|_| |_| |___/
974 ******************************************************************************************************/
977 * Copy the attributes from an ia32_Const to an Immop (Add_i, Sub_i, ...) node
979 void copy_ia32_Immop_attr(ir_node *node, ir_node *from) {
980 ia32_immop_type_t immop_type = get_ia32_immop_type(from);
982 if(immop_type == ia32_ImmConst) {
983 set_ia32_Immop_tarval(node, get_ia32_Immop_tarval(from));
984 } else if(immop_type == ia32_ImmSymConst) {
985 set_ia32_Immop_symconst(node, get_ia32_Immop_symconst(from));
987 ia32_attr_t *attr = get_ia32_attr(node);
988 assert(immop_type == ia32_ImmNone);
989 attr->data.imm_tp = ia32_ImmNone;
994 * Copy the attributes from a Firm Const/SymConst to an ia32_Const
996 void set_ia32_Const_attr(ir_node *ia32_cnst, ir_node *cnst) {
997 assert(is_ia32_Cnst(ia32_cnst) && "Need ia32_Const to set Const attr");
999 switch (get_irn_opcode(cnst)) {
1001 set_ia32_Const_tarval(ia32_cnst, get_Const_tarval(cnst));
1004 assert(get_SymConst_kind(cnst) == symconst_addr_ent);
1005 set_ia32_Immop_symconst(ia32_cnst, get_SymConst_entity(cnst));
1008 assert(0 && "Unknown Const NYI");
1011 assert(0 && "Cannot create ia32_Const for this opcode");
1015 void set_ia32_Const_tarval(ir_node *ia32_cnst, tarval *tv) {
1017 if(mode_is_reference(get_tarval_mode(tv))) {
1018 if(tarval_is_null(tv)) {
1019 tv = get_tarval_null(mode_Iu);
1023 if(!tarval_is_long(tv))
1024 panic("Can't convert reference tarval to mode_Iu at %+F", ia32_cnst);
1025 val = get_tarval_long(tv);
1026 tv = new_tarval_from_long(val, mode_Iu);
1029 tv = tarval_convert_to(tv, mode_Iu);
1032 tv = tarval_convert_to(tv, mode_Iu);
1035 assert(tv != get_tarval_bad() && tv != get_tarval_undefined()
1037 set_ia32_Immop_tarval(ia32_cnst, tv);
1042 * Sets the AddrMode(S|D) attribute
1044 void set_ia32_AddrMode(ir_node *node, char direction) {
1045 ia32_attr_t *attr = get_ia32_attr(node);
1047 switch (direction) {
1049 attr->data.tp = ia32_AddrModeD;
1052 attr->data.tp = ia32_AddrModeS;
1055 assert(0 && "wrong AM type");
1060 * Returns whether or not the node is an immediate operation with Const.
1062 int is_ia32_ImmConst(const ir_node *node) {
1063 const ia32_attr_t *attr = get_ia32_attr_const(node);
1064 return (attr->data.imm_tp == ia32_ImmConst);
1068 * Returns whether or not the node is an immediate operation with SymConst.
1070 int is_ia32_ImmSymConst(const ir_node *node) {
1071 const ia32_attr_t *attr = get_ia32_attr_const(node);
1072 return (attr->data.imm_tp == ia32_ImmSymConst);
1076 * Returns whether or not the node is an AddrModeS node.
1078 int is_ia32_AddrModeS(const ir_node *node) {
1079 const ia32_attr_t *attr = get_ia32_attr_const(node);
1080 return (attr->data.tp == ia32_AddrModeS);
1084 * Returns whether or not the node is an AddrModeD node.
1086 int is_ia32_AddrModeD(const ir_node *node) {
1087 const ia32_attr_t *attr = get_ia32_attr_const(node);
1088 return (attr->data.tp == ia32_AddrModeD);
1092 * Checks if node is a Load or xLoad/vfLoad.
1094 int is_ia32_Ld(const ir_node *node) {
1095 int op = get_ia32_irn_opcode(node);
1096 return op == iro_ia32_Load ||
1097 op == iro_ia32_xLoad ||
1098 op == iro_ia32_vfld ||
1103 * Checks if node is a Store or xStore/vfStore.
1105 int is_ia32_St(const ir_node *node) {
1106 int op = get_ia32_irn_opcode(node);
1107 return op == iro_ia32_Store ||
1108 op == iro_ia32_Store8Bit ||
1109 op == iro_ia32_xStore ||
1110 op == iro_ia32_vfst ||
1111 op == iro_ia32_fst ||
1112 op == iro_ia32_fstp;
1116 * Checks if node is a Const or xConst/vfConst.
1118 int is_ia32_Cnst(const ir_node *node) {
1119 int op = get_ia32_irn_opcode(node);
1120 return op == iro_ia32_Const || op == iro_ia32_xConst || op == iro_ia32_vfConst;
1124 * Returns the name of the OUT register at position pos.
1126 const char *get_ia32_out_reg_name(const ir_node *node, int pos) {
1127 const ia32_attr_t *attr = get_ia32_attr_const(node);
1129 assert(pos < ARR_LEN(attr->slots) && "Invalid OUT position.");
1130 assert(attr->slots[pos] && "No register assigned");
1132 return arch_register_get_name(attr->slots[pos]);
1136 * Returns the index of the OUT register at position pos within its register class.
1138 int get_ia32_out_regnr(const ir_node *node, int pos) {
1139 const ia32_attr_t *attr = get_ia32_attr_const(node);
1141 assert(pos < ARR_LEN(attr->slots) && "Invalid OUT position.");
1142 assert(attr->slots[pos] && "No register assigned");
1144 return arch_register_get_index(attr->slots[pos]);
1148 * Returns the OUT register at position pos.
1150 const arch_register_t *get_ia32_out_reg(const ir_node *node, int pos) {
1151 const ia32_attr_t *attr = get_ia32_attr_const(node);
1153 assert(pos < ARR_LEN(attr->slots) && "Invalid OUT position.");
1154 assert(attr->slots[pos] && "No register assigned");
1156 return attr->slots[pos];
1160 * Initializes the nodes attributes.
1162 void init_ia32_attributes(ir_node *node, arch_irn_flags_t flags,
1163 const arch_register_req_t **in_reqs,
1164 const arch_register_req_t **out_reqs,
1165 const be_execution_unit_t ***execution_units,
1166 int n_res, unsigned latency)
1168 ir_graph *irg = get_irn_irg(node);
1169 struct obstack *obst = get_irg_obstack(irg);
1170 ia32_attr_t *attr = get_ia32_attr(node);
1172 set_ia32_flags(node, flags);
1173 set_ia32_in_req_all(node, in_reqs);
1174 set_ia32_out_req_all(node, out_reqs);
1175 set_ia32_latency(node, latency);
1177 attr->exec_units = execution_units;
1179 attr->attr_type |= IA32_ATTR_ia32_attr_t;
1182 attr->out_flags = NEW_ARR_D(int, obst, n_res);
1183 memset(attr->out_flags, 0, n_res * sizeof(attr->out_flags[0]));
1185 attr->slots = NEW_ARR_D(const arch_register_t*, obst, n_res);
1186 memset(( arch_register_t **)attr->slots, 0, n_res * sizeof(attr->slots[0]));
1190 init_ia32_x87_attributes(ir_node *res)
1193 ia32_attr_t *attr = get_ia32_attr(res);
1194 attr->attr_type |= IA32_ATTR_ia32_x87_attr_t;
1199 init_ia32_asm_attributes(ir_node *res)
1202 ia32_attr_t *attr = get_ia32_attr(res);
1203 attr->attr_type |= IA32_ATTR_ia32_asm_attr_t;
1208 init_ia32_immediate_attributes(ir_node *res, ir_entity *symconst,
1209 int symconst_sign, tarval *offset)
1211 ia32_immediate_attr_t *attr = get_irn_generic_attr(res);
1214 attr->attr.attr_type |= IA32_ATTR_ia32_immediate_attr_t;
1216 attr->symconst = symconst;
1217 attr->attr.data.am_sc_sign = symconst_sign;
1218 attr->offset = offset;
1221 ir_node *get_ia32_result_proj(const ir_node *node)
1223 const ir_edge_t *edge;
1225 foreach_out_edge(node, edge) {
1226 ir_node *proj = get_edge_src_irn(edge);
1227 if(get_Proj_proj(proj) == 0) {
1234 /***************************************************************************************
1237 * _ __ ___ __| | ___ ___ ___ _ __ ___| |_ _ __ _ _ ___| |_ ___ _ __ ___
1238 * | '_ \ / _ \ / _` |/ _ \ / __/ _ \| '_ \/ __| __| '__| | | |/ __| __/ _ \| '__/ __|
1239 * | | | | (_) | (_| | __/ | (_| (_) | | | \__ \ |_| | | |_| | (__| || (_) | | \__ \
1240 * |_| |_|\___/ \__,_|\___| \___\___/|_| |_|___/\__|_| \__,_|\___|\__\___/|_| |___/
1242 ***************************************************************************************/
1244 /* default compare operation to compare attributes */
1245 int ia32_compare_attr(const ia32_attr_t *a, const ia32_attr_t *b) {
1246 if (a->data.tp != b->data.tp
1247 || a->data.imm_tp != b->data.imm_tp)
1250 if (a->data.imm_tp == ia32_ImmConst
1251 && a->cnst_val.tv != b->cnst_val.tv)
1254 if (a->data.imm_tp == ia32_ImmSymConst
1255 && a->cnst_val.sc != b->cnst_val.sc)
1258 if (a->data.am_flavour != b->data.am_flavour
1259 || a->data.am_scale != b->data.am_scale
1260 || a->data.am_sc_sign != b->data.am_sc_sign
1261 || a->am_offs != b->am_offs
1262 || a->am_sc != b->am_sc
1263 || a->ls_mode != b->ls_mode)
1266 if (a->data.use_frame != b->data.use_frame
1267 || a->data.use_frame != b->data.use_frame
1268 || a->frame_ent != b->frame_ent)
1271 if(a->pn_code != b->pn_code)
1274 if (a->data.tp != b->data.tp
1275 || a->data.op_flav != b->data.op_flav)
1278 if (a->data.except_label != b->data.except_label)
1285 int ia32_compare_nodes_attr(ir_node *a, ir_node *b)
1287 const ia32_attr_t* attr_a = get_ia32_attr_const(a);
1288 const ia32_attr_t* attr_b = get_ia32_attr_const(b);
1290 return ia32_compare_attr(attr_a, attr_b);
1294 int ia32_compare_x87_attr(ir_node *a, ir_node *b)
1296 return ia32_compare_nodes_attr(a, b);
1300 int ia32_compare_asm_attr(ir_node *a, ir_node *b)
1302 const ia32_asm_attr_t *attr_a;
1303 const ia32_asm_attr_t *attr_b;
1305 if(ia32_compare_nodes_attr(a, b))
1308 attr_a = get_ia32_asm_attr_const(a);
1309 attr_b = get_ia32_asm_attr_const(b);
1311 if(attr_a->asm_text != attr_b->asm_text)
1318 int ia32_compare_immediate_attr(ir_node *a, ir_node *b)
1320 const ia32_immediate_attr_t *attr_a = get_ia32_immediate_attr_const(a);
1321 const ia32_immediate_attr_t *attr_b = get_ia32_immediate_attr_const(b);
1323 if(attr_a->symconst != attr_b->symconst ||
1324 attr_a->attr.data.am_sc_sign != attr_b->attr.data.am_sc_sign ||
1325 attr_a->offset != attr_b->offset)
1331 /* copies the ia32 attributes */
1332 static void ia32_copy_attr(const ir_node *old_node, ir_node *new_node)
1334 ir_graph *irg = get_irn_irg(new_node);
1335 struct obstack *obst = get_irg_obstack(irg);
1336 const ia32_attr_t *attr_old = get_ia32_attr_const(old_node);
1337 ia32_attr_t *attr_new = get_ia32_attr(new_node);
1339 /* copy the attributes */
1340 memcpy(attr_new, attr_old, get_op_attr_size(get_irn_op(old_node)));
1342 /* copy out flags */
1343 attr_new->out_flags =
1344 DUP_ARR_D(int, obst, attr_old->out_flags);
1345 /* copy register assignments */
1347 DUP_ARR_D(arch_register_t*, obst, attr_old->slots);
1350 /* Include the generated constructor functions */
1351 #include "gen_ia32_new_nodes.c.inl"
1354 * Registers the ia32_copy_attr function for all ia32 opcodes.
1356 void ia32_register_copy_attr_func(void) {
1359 for (i = get_irp_n_opcodes() - 1; i >= 0; --i) {
1360 ir_op *op = get_irp_opcode(i);
1362 op->ops.copy_attr = ia32_copy_attr;