2 * Copyright (C) 1995-2008 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 corresponding node constructors for the ia32 assembler irg.
35 #include "irgraph_t.h"
45 #include "raw_bitset.h"
48 #include "../bearch.h"
49 #include "../beinfo.h"
51 #include "bearch_ia32_t.h"
52 #include "ia32_common_transform.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 * Dumper interface for dumping ia32 nodes in vcg.
71 * @param n the node to dump
72 * @param F the output file
73 * @param reason indicates which kind of information should be dumped
74 * @return 0 on success or != 0 on failure
76 static int ia32_dump_node(ir_node *n, FILE *F, dump_reason_t reason) {
81 case dump_node_opcode_txt:
82 fprintf(F, "%s", get_irn_opname(n));
84 if(is_ia32_Immediate(n) || is_ia32_Const(n)) {
85 const ia32_immediate_attr_t *attr
86 = get_ia32_immediate_attr_const(n);
93 fputs(get_entity_name(attr->symconst), F);
95 if(attr->offset != 0 || attr->symconst == NULL) {
96 if(attr->offset > 0 && attr->symconst != NULL) {
99 fprintf(F, "%ld", attr->offset);
100 if (attr->no_pic_adjust) {
101 fputs("(no_pic_adjust)", F);
106 const ia32_attr_t *attr = get_ia32_attr_const(n);
108 if(attr->am_sc != NULL || attr->am_offs != 0)
111 if(attr->am_sc != NULL) {
112 if(attr->data.am_sc_sign) {
115 fputs(get_entity_name(attr->am_sc), F);
116 if(attr->data.am_sc_no_pic_adjust) {
117 fputs("(no_pic_adjust)", F);
120 if(attr->am_offs != 0) {
121 if(attr->am_offs > 0 && attr->am_sc != NULL) {
124 fprintf(F, "%d", attr->am_offs);
127 if(attr->am_sc != NULL || attr->am_offs != 0)
132 case dump_node_mode_txt:
133 mode = get_ia32_ls_mode(n);
135 fprintf(F, "[%s]", get_mode_name(mode));
138 case dump_node_nodeattr_txt:
139 if (! is_ia32_Lea(n)) {
140 if (is_ia32_AddrModeS(n)) {
141 fprintf(F, "[AM S] ");
142 } else if (is_ia32_AddrModeD(n)) {
143 fprintf(F, "[AM D] ");
149 case dump_node_info_txt:
150 arch_dump_reqs_and_registers(F, n);
154 switch (get_ia32_op_type(n)) {
156 fprintf(F, "Normal");
159 fprintf(F, "AM Dest (Load+Store)");
162 fprintf(F, "AM Source (Load)");
165 fprintf(F, "unknown (%d)", get_ia32_op_type(n));
170 /* dump supported am */
171 fprintf(F, "AM support = ");
172 switch (get_ia32_am_support(n)) {
173 case ia32_am_none: fputs("none\n", F); break;
174 case ia32_am_unary: fputs("source (unary)\n", F); break;
175 case ia32_am_binary: fputs("source (binary)\n", F); break;
178 fprintf(F, "unknown (%d)\n", get_ia32_am_support(n));
183 if(get_ia32_am_offs_int(n) != 0) {
184 fprintf(F, "AM offset = %d\n", get_ia32_am_offs_int(n));
187 /* dump AM symconst */
188 if(get_ia32_am_sc(n) != NULL) {
189 ir_entity *ent = get_ia32_am_sc(n);
190 ident *id = get_entity_ld_ident(ent);
191 fprintf(F, "AM symconst = %s\n", get_id_str(id));
195 fprintf(F, "AM scale = %d\n", get_ia32_am_scale(n));
198 if (is_ia32_SwitchJmp(n)) {
199 fprintf(F, "pn_code = %ld\n", get_ia32_condcode(n));
200 } else if (is_ia32_CMov(n) || is_ia32_Set(n) || is_ia32_Jcc(n)) {
201 ia32_attr_t *attr = get_ia32_attr(n);
202 long pnc = get_ia32_condcode(n);
203 fprintf(F, "pn_code = 0x%lX (%s)\n", pnc, get_pnc_string(pnc & pn_Cmp_True));
204 fprintf(F, "ins_permuted = %u \n", attr->data.ins_permuted);
205 fprintf(F, "cmp_unsigned = %u \n", attr->data.cmp_unsigned);
207 else if (is_ia32_CopyB(n) || is_ia32_CopyB_i(n)) {
208 fprintf(F, "size = %u\n", get_ia32_copyb_size(n));
211 fprintf(F, "use_frame = %d\n", is_ia32_use_frame(n));
212 fprintf(F, "commutative = %d\n", is_ia32_commutative(n));
213 fprintf(F, "need stackent = %d\n", is_ia32_need_stackent(n));
214 fprintf(F, "is reload = %d\n", is_ia32_is_reload(n));
215 fprintf(F, "latency = %d\n", get_ia32_latency(n));
217 /* dump frame entity */
218 fprintf(F, "frame entity = ");
219 if (get_ia32_frame_ent(n)) {
220 ir_fprintf(F, "%+F", get_ia32_frame_ent(n));
228 fprintf(F, "ls_mode = ");
229 if (get_ia32_ls_mode(n)) {
230 ir_fprintf(F, "%+F", get_ia32_ls_mode(n));
238 /* dump original ir node name */
239 fprintf(F, "orig node = ");
240 if (get_ia32_orig_node(n)) {
241 fprintf(F, "%s", get_ia32_orig_node(n));
257 /***************************************************************************************************
259 * | | | | | | / / | | | | | | | |
260 * __ _| |_| |_ _ __ ___ ___| |_ / /_ _ ___| |_ _ __ ___ ___| |_| |__ ___ __| |___
261 * / _` | __| __| '__| / __|/ _ \ __| / / _` |/ _ \ __| | '_ ` _ \ / _ \ __| '_ \ / _ \ / _` / __|
262 * | (_| | |_| |_| | \__ \ __/ |_ / / (_| | __/ |_ | | | | | | __/ |_| | | | (_) | (_| \__ \
263 * \__,_|\__|\__|_| |___/\___|\__/_/ \__, |\___|\__| |_| |_| |_|\___|\__|_| |_|\___/ \__,_|___/
266 ***************************************************************************************************/
268 ia32_attr_t *get_ia32_attr(ir_node *node) {
269 assert(is_ia32_irn(node) && "need ia32 node to get ia32 attributes");
270 return (ia32_attr_t *)get_irn_generic_attr(node);
273 const ia32_attr_t *get_ia32_attr_const(const ir_node *node) {
274 assert(is_ia32_irn(node) && "need ia32 node to get ia32 attributes");
275 return (const ia32_attr_t*) get_irn_generic_attr_const(node);
278 ia32_x87_attr_t *get_ia32_x87_attr(ir_node *node) {
279 ia32_attr_t *attr = get_ia32_attr(node);
280 ia32_x87_attr_t *x87_attr = CAST_IA32_ATTR(ia32_x87_attr_t, attr);
284 const ia32_x87_attr_t *get_ia32_x87_attr_const(const ir_node *node) {
285 const ia32_attr_t *attr = get_ia32_attr_const(node);
286 const ia32_x87_attr_t *x87_attr = CONST_CAST_IA32_ATTR(ia32_x87_attr_t, attr);
290 const ia32_asm_attr_t *get_ia32_asm_attr_const(const ir_node *node) {
291 const ia32_attr_t *attr = get_ia32_attr_const(node);
292 const ia32_asm_attr_t *asm_attr = CONST_CAST_IA32_ATTR(ia32_asm_attr_t, attr);
297 ia32_immediate_attr_t *get_ia32_immediate_attr(ir_node *node) {
298 ia32_attr_t *attr = get_ia32_attr(node);
299 ia32_immediate_attr_t *imm_attr = CAST_IA32_ATTR(ia32_immediate_attr_t, attr);
304 const ia32_immediate_attr_t *get_ia32_immediate_attr_const(const ir_node *node)
306 const ia32_attr_t *attr = get_ia32_attr_const(node);
307 const ia32_immediate_attr_t *imm_attr = CONST_CAST_IA32_ATTR(ia32_immediate_attr_t, attr);
312 ia32_condcode_attr_t *get_ia32_condcode_attr(ir_node *node) {
313 ia32_attr_t *attr = get_ia32_attr(node);
314 ia32_condcode_attr_t *cc_attr = CAST_IA32_ATTR(ia32_condcode_attr_t, attr);
319 const ia32_condcode_attr_t *get_ia32_condcode_attr_const(const ir_node *node) {
320 const ia32_attr_t *attr = get_ia32_attr_const(node);
321 const ia32_condcode_attr_t *cc_attr = CONST_CAST_IA32_ATTR(ia32_condcode_attr_t, attr);
326 ia32_call_attr_t *get_ia32_call_attr(ir_node *node)
328 ia32_attr_t *attr = get_ia32_attr(node);
329 ia32_call_attr_t *call_attr = CAST_IA32_ATTR(ia32_call_attr_t, attr);
334 const ia32_call_attr_t *get_ia32_call_attr_const(const ir_node *node)
336 const ia32_attr_t *attr = get_ia32_attr_const(node);
337 const ia32_call_attr_t *call_attr = CONST_CAST_IA32_ATTR(ia32_call_attr_t, attr);
342 ia32_copyb_attr_t *get_ia32_copyb_attr(ir_node *node) {
343 ia32_attr_t *attr = get_ia32_attr(node);
344 ia32_copyb_attr_t *copyb_attr = CAST_IA32_ATTR(ia32_copyb_attr_t, attr);
349 const ia32_copyb_attr_t *get_ia32_copyb_attr_const(const ir_node *node) {
350 const ia32_attr_t *attr = get_ia32_attr_const(node);
351 const ia32_copyb_attr_t *copyb_attr = CONST_CAST_IA32_ATTR(ia32_copyb_attr_t, attr);
356 ia32_climbframe_attr_t *get_ia32_climbframe_attr(ir_node *node) {
357 ia32_attr_t *attr = get_ia32_attr(node);
358 ia32_climbframe_attr_t *climbframe_attr = CAST_IA32_ATTR(ia32_climbframe_attr_t, attr);
360 return climbframe_attr;
363 const ia32_climbframe_attr_t *get_ia32_climbframe_attr_const(const ir_node *node) {
364 const ia32_attr_t *attr = get_ia32_attr_const(node);
365 const ia32_climbframe_attr_t *climbframe_attr = CONST_CAST_IA32_ATTR(ia32_climbframe_attr_t, attr);
367 return climbframe_attr;
371 * Gets the type of an ia32 node.
373 ia32_op_type_t get_ia32_op_type(const ir_node *node) {
374 const ia32_attr_t *attr = get_ia32_attr_const(node);
375 return attr->data.tp;
379 * Sets the type of an ia32 node.
381 void set_ia32_op_type(ir_node *node, ia32_op_type_t tp) {
382 ia32_attr_t *attr = get_ia32_attr(node);
386 ia32_am_type_t get_ia32_am_support(const ir_node *node)
388 const ia32_attr_t *attr = get_ia32_attr_const(node);
389 return attr->data.am_arity;
393 * Sets the supported address mode of an ia32 node
395 void set_ia32_am_support(ir_node *node, ia32_am_type_t arity)
397 ia32_attr_t *attr = get_ia32_attr(node);
398 attr->data.am_arity = arity;
402 * Gets the address mode offset as int.
404 int get_ia32_am_offs_int(const ir_node *node) {
405 const ia32_attr_t *attr = get_ia32_attr_const(node);
406 return attr->am_offs;
410 * Sets the address mode offset from an int.
412 void set_ia32_am_offs_int(ir_node *node, int offset) {
413 ia32_attr_t *attr = get_ia32_attr(node);
414 attr->am_offs = offset;
417 void add_ia32_am_offs_int(ir_node *node, int offset) {
418 ia32_attr_t *attr = get_ia32_attr(node);
419 attr->am_offs += offset;
423 * Returns the symconst entity associated to address mode.
425 ir_entity *get_ia32_am_sc(const ir_node *node) {
426 const ia32_attr_t *attr = get_ia32_attr_const(node);
431 * Sets the symconst entity associated to address mode.
433 void set_ia32_am_sc(ir_node *node, ir_entity *entity) {
434 ia32_attr_t *attr = get_ia32_attr(node);
435 attr->am_sc = entity;
439 * Sets the sign bit for address mode symconst.
441 void set_ia32_am_sc_sign(ir_node *node) {
442 ia32_attr_t *attr = get_ia32_attr(node);
443 attr->data.am_sc_sign = 1;
447 * Clears the sign bit for address mode symconst.
449 void clear_ia32_am_sc_sign(ir_node *node) {
450 ia32_attr_t *attr = get_ia32_attr(node);
451 attr->data.am_sc_sign = 0;
455 * Returns the sign bit for address mode symconst.
457 int is_ia32_am_sc_sign(const ir_node *node) {
458 const ia32_attr_t *attr = get_ia32_attr_const(node);
459 return attr->data.am_sc_sign;
463 * Gets the addr mode const.
465 unsigned get_ia32_am_scale(const ir_node *node) {
466 const ia32_attr_t *attr = get_ia32_attr_const(node);
467 return attr->data.am_scale;
471 * Sets the index register scale for address mode.
473 void set_ia32_am_scale(ir_node *node, unsigned scale) {
474 ia32_attr_t *attr = get_ia32_attr(node);
475 assert(scale <= 3 && "AM scale out of range [0 ... 3]");
476 attr->data.am_scale = scale;
479 void ia32_copy_am_attrs(ir_node *to, const ir_node *from)
481 set_ia32_ls_mode(to, get_ia32_ls_mode(from));
482 set_ia32_am_scale(to, get_ia32_am_scale(from));
483 set_ia32_am_sc(to, get_ia32_am_sc(from));
484 if(is_ia32_am_sc_sign(from))
485 set_ia32_am_sc_sign(to);
486 add_ia32_am_offs_int(to, get_ia32_am_offs_int(from));
487 set_ia32_frame_ent(to, get_ia32_frame_ent(from));
488 if (is_ia32_use_frame(from))
489 set_ia32_use_frame(to);
493 * Sets the uses_frame flag.
495 void set_ia32_use_frame(ir_node *node) {
496 ia32_attr_t *attr = get_ia32_attr(node);
497 attr->data.use_frame = 1;
501 * Clears the uses_frame flag.
503 void clear_ia32_use_frame(ir_node *node) {
504 ia32_attr_t *attr = get_ia32_attr(node);
505 attr->data.use_frame = 0;
509 * Gets the uses_frame flag.
511 int is_ia32_use_frame(const ir_node *node) {
512 const ia32_attr_t *attr = get_ia32_attr_const(node);
513 return attr->data.use_frame;
517 * Sets node to commutative.
519 void set_ia32_commutative(ir_node *node) {
520 ia32_attr_t *attr = get_ia32_attr(node);
521 attr->data.is_commutative = 1;
525 * Sets node to non-commutative.
527 void clear_ia32_commutative(ir_node *node) {
528 ia32_attr_t *attr = get_ia32_attr(node);
529 attr->data.is_commutative = 0;
533 * Checks if node is commutative.
535 int is_ia32_commutative(const ir_node *node) {
536 const ia32_attr_t *attr = get_ia32_attr_const(node);
537 return attr->data.is_commutative;
540 void set_ia32_need_stackent(ir_node *node) {
541 ia32_attr_t *attr = get_ia32_attr(node);
542 attr->data.need_stackent = 1;
545 void clear_ia32_need_stackent(ir_node *node) {
546 ia32_attr_t *attr = get_ia32_attr(node);
547 attr->data.need_stackent = 0;
550 int is_ia32_need_stackent(const ir_node *node) {
551 const ia32_attr_t *attr = get_ia32_attr_const(node);
552 return attr->data.need_stackent;
555 void set_ia32_is_reload(ir_node *node) {
556 ia32_attr_t *attr = get_ia32_attr(node);
557 attr->data.is_reload = 1;
560 int is_ia32_is_reload(const ir_node *node) {
561 const ia32_attr_t *attr = get_ia32_attr_const(node);
562 return attr->data.is_reload;
565 void set_ia32_is_spill(ir_node *node) {
566 ia32_attr_t *attr = get_ia32_attr(node);
567 attr->data.is_spill = 1;
570 int is_ia32_is_spill(const ir_node *node) {
571 const ia32_attr_t *attr = get_ia32_attr_const(node);
572 return attr->data.is_spill;
575 void set_ia32_is_remat(ir_node *node) {
576 ia32_attr_t *attr = get_ia32_attr(node);
577 attr->data.is_remat = 1;
580 int is_ia32_is_remat(const ir_node *node) {
581 const ia32_attr_t *attr = get_ia32_attr_const(node);
582 return attr->data.is_remat;
586 * Gets the mode of the stored/loaded value (only set for Store/Load)
588 ir_mode *get_ia32_ls_mode(const ir_node *node) {
589 const ia32_attr_t *attr = get_ia32_attr_const(node);
590 return attr->ls_mode;
594 * Sets the mode of the stored/loaded value (only set for Store/Load)
596 void set_ia32_ls_mode(ir_node *node, ir_mode *mode) {
597 ia32_attr_t *attr = get_ia32_attr(node);
598 attr->ls_mode = mode;
602 * Gets the frame entity assigned to this node.
604 ir_entity *get_ia32_frame_ent(const ir_node *node) {
605 const ia32_attr_t *attr = get_ia32_attr_const(node);
606 return attr->frame_ent;
610 * Sets the frame entity for this node.
612 void set_ia32_frame_ent(ir_node *node, ir_entity *ent) {
613 ia32_attr_t *attr = get_ia32_attr(node);
614 attr->frame_ent = ent;
616 set_ia32_use_frame(node);
618 clear_ia32_use_frame(node);
623 * Gets the instruction latency.
625 unsigned get_ia32_latency(const ir_node *node) {
626 const ir_op *op = get_irn_op(node);
627 const ia32_op_attr_t *op_attr = (ia32_op_attr_t*) get_op_attr(op);
628 return op_attr->latency;
632 * Returns the argument register requirements of an ia32 node.
634 const arch_register_req_t **get_ia32_in_req_all(const ir_node *node) {
635 const ia32_attr_t *attr = get_ia32_attr_const(node);
640 * Sets the argument register requirements of an ia32 node.
642 void set_ia32_in_req_all(ir_node *node, const arch_register_req_t **reqs) {
643 ia32_attr_t *attr = get_ia32_attr(node);
648 * Returns the argument register requirement at position pos of an ia32 node.
650 const arch_register_req_t *get_ia32_in_req(const ir_node *node, int pos) {
651 const ia32_attr_t *attr = get_ia32_attr_const(node);
652 if(attr->in_req == NULL)
653 return arch_no_register_req;
655 return attr->in_req[pos];
659 * Sets the IN register requirements at position pos.
661 void set_ia32_req_in(ir_node *node, const arch_register_req_t *req, int pos)
663 ia32_attr_t *attr = get_ia32_attr(node);
664 attr->in_req[pos] = req;
668 * Returns the condition code of a node.
670 long get_ia32_condcode(const ir_node *node)
672 const ia32_condcode_attr_t *attr = get_ia32_condcode_attr_const(node);
673 return attr->pn_code;
677 * Sets the condition code of a node
679 void set_ia32_condcode(ir_node *node, long code)
681 ia32_condcode_attr_t *attr = get_ia32_condcode_attr(node);
682 attr->pn_code = code;
686 * Returns the condition code of a node.
688 unsigned get_ia32_copyb_size(const ir_node *node)
690 const ia32_copyb_attr_t *attr = get_ia32_copyb_attr_const(node);
695 * Get the list of available execution units.
697 const be_execution_unit_t ***get_ia32_exec_units(const ir_node *node)
699 const ia32_attr_t *attr = get_ia32_attr_const(node);
700 return attr->exec_units;
704 * Get the exception label attribute.
706 unsigned get_ia32_exc_label(const ir_node *node)
708 const ia32_attr_t *attr = get_ia32_attr_const(node);
709 return attr->data.has_except_label;
713 * Set the exception label attribute.
715 void set_ia32_exc_label(ir_node *node, unsigned flag)
717 ia32_attr_t *attr = get_ia32_attr(node);
718 attr->data.has_except_label = flag;
722 * Return the exception label id.
724 ir_label_t get_ia32_exc_label_id(const ir_node *node)
726 const ia32_attr_t *attr = get_ia32_attr_const(node);
728 assert(attr->data.has_except_label);
729 return attr->exc_label;
733 * Assign the exception label id.
735 void set_ia32_exc_label_id(ir_node *node, ir_label_t id)
737 ia32_attr_t *attr = get_ia32_attr(node);
739 assert(attr->data.has_except_label);
740 attr->exc_label = id;
746 * Returns the name of the original ir node.
748 const char *get_ia32_orig_node(const ir_node *node)
750 const ia32_attr_t *attr = get_ia32_attr_const(node);
751 return attr->orig_node;
754 static const char *ia32_get_old_node_name(const ir_node *irn)
756 struct obstack *obst = env_cg->isa->name_obst;
758 lc_eoprintf(firm_get_arg_env(), obst, "%+F", irn);
759 obstack_1grow(obst, 0);
760 return obstack_finish(obst);
764 * Sets the name of the original ir node.
766 void set_ia32_orig_node(ir_node *node, const ir_node *old)
768 const char *name = ia32_get_old_node_name(old);
769 ia32_attr_t *attr = get_ia32_attr(node);
770 attr->orig_node = name;
775 /******************************************************************************************************
777 * (_) | | | | | | / _| | | (_)
778 * ___ _ __ ___ ___ _ __ _| | __ _| |_| |_ _ __ | |_ _ _ _ __ ___| |_ _ ___ _ __ ___
779 * / __| '_ \ / _ \/ __| |/ _` | | / _` | __| __| '__| | _| | | | '_ \ / __| __| |/ _ \| '_ \ / __|
780 * \__ \ |_) | __/ (__| | (_| | | | (_| | |_| |_| | | | | |_| | | | | (__| |_| | (_) | | | | \__ \
781 * |___/ .__/ \___|\___|_|\__,_|_| \__,_|\__|\__|_| |_| \__,_|_| |_|\___|\__|_|\___/|_| |_| |___/
784 ******************************************************************************************************/
787 * Returns whether or not the node is an AddrModeS node.
789 int is_ia32_AddrModeS(const ir_node *node) {
790 const ia32_attr_t *attr = get_ia32_attr_const(node);
791 return (attr->data.tp == ia32_AddrModeS);
795 * Returns whether or not the node is an AddrModeD node.
797 int is_ia32_AddrModeD(const ir_node *node) {
798 const ia32_attr_t *attr = get_ia32_attr_const(node);
799 return (attr->data.tp == ia32_AddrModeD);
802 void ia32_swap_left_right(ir_node *node)
804 ia32_attr_t *attr = get_ia32_attr(node);
805 ir_node *left = get_irn_n(node, n_ia32_binary_left);
806 ir_node *right = get_irn_n(node, n_ia32_binary_right);
808 assert(is_ia32_commutative(node));
809 attr->data.ins_permuted = !attr->data.ins_permuted;
810 set_irn_n(node, n_ia32_binary_left, right);
811 set_irn_n(node, n_ia32_binary_right, left);
815 * Initializes the nodes attributes.
817 void init_ia32_attributes(ir_node *node, arch_irn_flags_t flags,
818 const arch_register_req_t **in_reqs,
819 const be_execution_unit_t ***execution_units,
822 ir_graph *irg = get_irn_irg(node);
823 struct obstack *obst = get_irg_obstack(irg);
824 ia32_attr_t *attr = get_ia32_attr(node);
825 backend_info_t *info;
827 arch_irn_set_flags(node, flags);
828 set_ia32_in_req_all(node, in_reqs);
830 attr->exec_units = execution_units;
832 attr->attr_type |= IA32_ATTR_ia32_attr_t;
835 info = be_get_info(node);
836 info->out_infos = NEW_ARR_D(reg_out_info_t, obst, n_res);
837 memset(info->out_infos, 0, n_res * sizeof(info->out_infos[0]));
841 init_ia32_x87_attributes(ir_node *res)
844 ia32_attr_t *attr = get_ia32_attr(res);
845 attr->attr_type |= IA32_ATTR_ia32_x87_attr_t;
849 ia32_current_cg->do_x87_sim = 1;
853 init_ia32_asm_attributes(ir_node *res)
856 ia32_attr_t *attr = get_ia32_attr(res);
857 attr->attr_type |= IA32_ATTR_ia32_asm_attr_t;
864 init_ia32_immediate_attributes(ir_node *res, ir_entity *symconst,
865 int symconst_sign, int no_pic_adjust,
868 ia32_immediate_attr_t *attr = get_irn_generic_attr(res);
871 attr->attr.attr_type |= IA32_ATTR_ia32_immediate_attr_t;
873 attr->symconst = symconst;
874 attr->sc_sign = symconst_sign;
875 attr->no_pic_adjust = no_pic_adjust;
876 attr->offset = offset;
879 void init_ia32_call_attributes(ir_node* res, unsigned pop, ir_type* call_tp)
881 ia32_call_attr_t *attr = get_irn_generic_attr(res);
884 attr->attr.attr_type |= IA32_ATTR_ia32_call_attr_t;
887 attr->call_tp = call_tp;
891 init_ia32_copyb_attributes(ir_node *res, unsigned size) {
892 ia32_copyb_attr_t *attr = get_irn_generic_attr(res);
895 attr->attr.attr_type |= IA32_ATTR_ia32_copyb_attr_t;
901 init_ia32_condcode_attributes(ir_node *res, long pnc) {
902 ia32_condcode_attr_t *attr = get_irn_generic_attr(res);
905 attr->attr.attr_type |= IA32_ATTR_ia32_condcode_attr_t;
911 init_ia32_climbframe_attributes(ir_node *res, unsigned count) {
912 ia32_climbframe_attr_t *attr = get_irn_generic_attr(res);
915 attr->attr.attr_type |= IA32_ATTR_ia32_climbframe_attr_t;
920 /***************************************************************************************
923 * _ __ ___ __| | ___ ___ ___ _ __ ___| |_ _ __ _ _ ___| |_ ___ _ __ ___
924 * | '_ \ / _ \ / _` |/ _ \ / __/ _ \| '_ \/ __| __| '__| | | |/ __| __/ _ \| '__/ __|
925 * | | | | (_) | (_| | __/ | (_| (_) | | | \__ \ |_| | | |_| | (__| || (_) | | \__ \
926 * |_| |_|\___/ \__,_|\___| \___\___/|_| |_|___/\__|_| \__,_|\___|\__\___/|_| |___/
928 ***************************************************************************************/
930 /* default compare operation to compare attributes */
931 int ia32_compare_attr(const ia32_attr_t *a, const ia32_attr_t *b)
933 if (a->data.tp != b->data.tp)
936 if (a->data.am_scale != b->data.am_scale
937 || a->data.am_sc_sign != b->data.am_sc_sign
938 || a->am_offs != b->am_offs
939 || a->am_sc != b->am_sc
940 || a->data.am_sc_no_pic_adjust != b->data.am_sc_no_pic_adjust
941 || a->ls_mode != b->ls_mode)
944 /* nodes with not yet assigned entities shouldn't be CSEd (important for
945 * unsigned int -> double conversions */
946 if(a->data.use_frame && a->frame_ent == NULL)
948 if(b->data.use_frame && b->frame_ent == NULL)
951 if (a->data.use_frame != b->data.use_frame
952 || a->frame_ent != b->frame_ent)
955 if (a->data.has_except_label != b->data.has_except_label)
958 if (a->data.ins_permuted != b->data.ins_permuted
959 || a->data.cmp_unsigned != b->data.cmp_unsigned)
965 /** Compare nodes attributes for all "normal" nodes. */
967 int ia32_compare_nodes_attr(ir_node *a, ir_node *b)
969 const ia32_attr_t* attr_a = get_ia32_attr_const(a);
970 const ia32_attr_t* attr_b = get_ia32_attr_const(b);
972 return ia32_compare_attr(attr_a, attr_b);
975 /** Compare node attributes for nodes with condition code. */
977 int ia32_compare_condcode_attr(ir_node *a, ir_node *b)
979 const ia32_condcode_attr_t *attr_a;
980 const ia32_condcode_attr_t *attr_b;
982 if (ia32_compare_nodes_attr(a, b))
985 attr_a = get_ia32_condcode_attr_const(a);
986 attr_b = get_ia32_condcode_attr_const(b);
988 if (attr_a->pn_code != attr_b->pn_code)
994 /** Compare node attributes for call nodes. */
995 static int ia32_compare_call_attr(ir_node *a, ir_node *b)
997 const ia32_call_attr_t *attr_a;
998 const ia32_call_attr_t *attr_b;
1000 if (ia32_compare_nodes_attr(a, b))
1003 attr_a = get_ia32_call_attr_const(a);
1004 attr_b = get_ia32_call_attr_const(b);
1006 if (attr_a->pop != attr_b->pop)
1009 if (attr_a->call_tp != attr_b->call_tp)
1015 /** Compare node attributes for CopyB nodes. */
1017 int ia32_compare_copyb_attr(ir_node *a, ir_node *b)
1019 const ia32_copyb_attr_t *attr_a;
1020 const ia32_copyb_attr_t *attr_b;
1022 if (ia32_compare_nodes_attr(a, b))
1025 attr_a = get_ia32_copyb_attr_const(a);
1026 attr_b = get_ia32_copyb_attr_const(b);
1028 if (attr_a->size != attr_b->size)
1035 /** Compare ASM node attributes. */
1037 int ia32_compare_asm_attr(ir_node *a, ir_node *b)
1039 const ia32_asm_attr_t *attr_a;
1040 const ia32_asm_attr_t *attr_b;
1042 if (ia32_compare_nodes_attr(a, b))
1045 attr_a = get_ia32_asm_attr_const(a);
1046 attr_b = get_ia32_asm_attr_const(b);
1048 if(attr_a->asm_text != attr_b->asm_text)
1055 * Hash function for Immediates
1057 static unsigned ia32_hash_Immediate(const ir_node *irn) {
1058 const ia32_immediate_attr_t *a = get_ia32_immediate_attr_const(irn);
1060 return HASH_PTR(a->symconst) + (a->sc_sign << 16) + a->offset;
1063 /** Compare node attributes for Immediates. */
1065 int ia32_compare_immediate_attr(ir_node *a, ir_node *b)
1067 const ia32_immediate_attr_t *attr_a = get_ia32_immediate_attr_const(a);
1068 const ia32_immediate_attr_t *attr_b = get_ia32_immediate_attr_const(b);
1070 if (attr_a->symconst != attr_b->symconst
1071 || attr_a->sc_sign != attr_b->sc_sign
1072 || attr_a->no_pic_adjust != attr_b->no_pic_adjust
1073 || attr_a->offset != attr_b->offset) {
1080 /** Compare node attributes for x87 nodes. */
1082 int ia32_compare_x87_attr(ir_node *a, ir_node *b)
1084 return ia32_compare_nodes_attr(a, b);
1087 /** Compare node attributes for ClimbFrame nodes. */
1089 int ia32_compare_climbframe_attr(ir_node *a, ir_node *b)
1091 const ia32_climbframe_attr_t *attr_a;
1092 const ia32_climbframe_attr_t *attr_b;
1094 if (ia32_compare_nodes_attr(a, b))
1097 attr_a = get_ia32_climbframe_attr_const(a);
1098 attr_b = get_ia32_climbframe_attr_const(b);
1100 if (attr_a->count != attr_b->count)
1106 /* copies the ia32 attributes */
1107 static void ia32_copy_attr(const ir_node *old_node, ir_node *new_node)
1109 ir_graph *irg = get_irn_irg(new_node);
1110 struct obstack *obst = get_irg_obstack(irg);
1111 const ia32_attr_t *attr_old = get_ia32_attr_const(old_node);
1112 ia32_attr_t *attr_new = get_ia32_attr(new_node);
1113 backend_info_t *old_info = be_get_info(old_node);
1114 backend_info_t *new_info = be_get_info(new_node);
1116 /* copy the attributes */
1117 memcpy(attr_new, attr_old, get_op_attr_size(get_irn_op(old_node)));
1119 /* copy out flags */
1120 new_info->out_infos =
1121 DUP_ARR_D(reg_out_info_t, obst, old_info->out_infos);
1124 /* Include the generated constructor functions */
1125 #include "gen_ia32_new_nodes.c.inl"