2 * This file is part of libFirm.
3 * Copyright (C) 2012 University of Karlsruhe.
8 * @brief This file implements the creation of the achitecture specific firm
9 * opcodes and the coresponding node constructors for the amd64
17 #include "irgraph_t.h"
28 #include "amd64_nodes_attr.h"
29 #include "amd64_new_nodes.h"
30 #include "gen_amd64_regalloc_if.h"
32 void set_amd64_ls_mode(ir_node *node, ir_mode *mode)
34 amd64_attr_t *attr = get_amd64_attr(node);
39 * Dumper interface for dumping amd64 nodes in vcg.
40 * @param F the output file
41 * @param n the node to dump
42 * @param reason indicates which kind of information should be dumped
44 static void amd64_dump_node(FILE *F, const ir_node *n, dump_reason_t reason)
49 case dump_node_opcode_txt:
50 fprintf(F, "%s", get_irn_opname(n));
53 case dump_node_mode_txt:
54 mode = get_irn_mode(n);
57 fprintf(F, "[%s]", get_mode_name(mode));
59 fprintf(F, "[?NOMODE?]");
63 case dump_node_nodeattr_txt:
65 /* TODO: dump some attributes which should show up */
66 /* in node name in dump (e.g. consts or the like) */
70 case dump_node_info_txt:
71 arch_dump_reqs_and_registers(F, n);
76 const amd64_attr_t *get_amd64_attr_const(const ir_node *node)
78 assert(is_amd64_irn(node) && "need amd64 node to get attributes");
79 return (const amd64_attr_t *)get_irn_generic_attr_const(node);
82 amd64_attr_t *get_amd64_attr(ir_node *node)
84 assert(is_amd64_irn(node) && "need amd64 node to get attributes");
85 return (amd64_attr_t *)get_irn_generic_attr(node);
88 const amd64_SymConst_attr_t *get_amd64_SymConst_attr_const(const ir_node *node)
90 const amd64_SymConst_attr_t *attr
91 = (const amd64_SymConst_attr_t*)get_irn_generic_attr_const(node);
95 amd64_SymConst_attr_t *get_amd64_SymConst_attr(ir_node *node)
97 amd64_SymConst_attr_t *attr
98 = (amd64_SymConst_attr_t*)get_irn_generic_attr(node);
103 * Initializes the nodes attributes.
105 static void init_amd64_attributes(ir_node *node, arch_irn_flags_t flags,
106 const arch_register_req_t **in_reqs,
109 ir_graph *irg = get_irn_irg(node);
110 struct obstack *obst = get_irg_obstack(irg);
111 amd64_attr_t *attr = get_amd64_attr(node);
113 backend_info_t *info;
115 arch_set_irn_flags(node, flags);
116 arch_set_irn_register_reqs_in(node, in_reqs);
118 info = be_get_info(node);
119 info->out_infos = NEW_ARR_DZ(reg_out_info_t, obst, n_res);
121 attr->data.ins_permuted = 0;
122 attr->data.cmp_unsigned = 0;
123 attr->ext.relation = ir_relation_false;
124 attr->ext.imm_value = 0;
128 * Initialize SymConst attributes.
130 static void init_amd64_SymConst_attributes(ir_node *node, ir_entity *entity)
132 amd64_SymConst_attr_t *attr = get_amd64_SymConst_attr(node);
133 attr->entity = entity;
137 /** Compare node attributes for SymConst. */
138 static int cmp_amd64_attr_SymConst(const ir_node *a, const ir_node *b)
140 const amd64_SymConst_attr_t *attr_a = get_amd64_SymConst_attr_const(a);
141 const amd64_SymConst_attr_t *attr_b = get_amd64_SymConst_attr_const(b);
143 if (attr_a->entity != attr_b->entity
144 || attr_a->fp_offset != attr_b->fp_offset)
150 /** Compare common amd64 node attributes. */
151 static int cmp_amd64_attr(const ir_node *a, const ir_node *b)
153 const amd64_attr_t *attr_a = get_amd64_attr_const(a);
154 const amd64_attr_t *attr_b = get_amd64_attr_const(b);
156 return attr_a->ext.imm_value != attr_b->ext.imm_value;
159 /** copies the AMD64 attributes of a node. */
160 static void amd64_copy_attr(ir_graph *irg, const ir_node *old_node,
163 struct obstack *obst = get_irg_obstack(irg);
164 const amd64_attr_t *attr_old = get_amd64_attr_const(old_node);
165 amd64_attr_t *attr_new = get_amd64_attr(new_node);
166 backend_info_t *old_info = be_get_info(old_node);
167 backend_info_t *new_info = be_get_info(new_node);
169 /* copy the attributes */
170 memcpy(attr_new, attr_old, get_op_attr_size(get_irn_op(old_node)));
173 new_info->flags = old_info->flags;
174 new_info->out_infos =
175 DUP_ARR_D(reg_out_info_t, obst, old_info->out_infos);
176 new_info->in_reqs = old_info->in_reqs;
179 /* Include the generated constructor functions */
180 #include "gen_amd64_new_nodes.c.inl"