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 This file implements the creation of the architecture specific firm
23 * opcodes and the corresponding node constructors for the MIPS
25 * @author Matthias Braun, Mehdi
33 #include "irgraph_t.h"
43 #include "../bearch.h"
45 #include "mips_nodes_attr.h"
46 #include "mips_new_nodes.h"
47 #include "gen_mips_regalloc_if.h"
51 /***********************************************************************************
54 * __| |_ _ _ __ ___ _ __ ___ _ __ _ _ __ | |_ ___ _ __| |_ __ _ ___ ___
55 * / _` | | | | '_ ` _ \| '_ \ / _ \ '__| | | '_ \| __/ _ \ '__| _/ _` |/ __/ _ \
56 * | (_| | |_| | | | | | | |_) | __/ | | | | | | || __/ | | || (_| | (_| __/
57 * \__,_|\__,_|_| |_| |_| .__/ \___|_| |_|_| |_|\__\___|_| |_| \__,_|\___\___|
60 ***********************************************************************************/
63 * Dumper interface for dumping mips nodes in vcg.
64 * @param F the output file
65 * @param n the node to dump
66 * @param reason indicates which kind of information should be dumped
68 static void mips_dump_node(FILE *F, ir_node *n, dump_reason_t reason)
71 case dump_node_opcode_txt:
72 fprintf(F, "%s", get_irn_opname(n));
75 case dump_node_mode_txt:
78 case dump_node_nodeattr_txt:
80 if (is_mips_Immediate(n)) {
81 const mips_immediate_attr_t *attr
82 = get_mips_immediate_attr_const(n);
83 switch (attr->imm_type) {
85 fprintf(F, " %ld ", attr->val);
87 case MIPS_IMM_SYMCONST_LO:
88 fprintf(F, " lo(%s", get_entity_ld_name(attr->entity));
90 fprintf(F, "%+ld", attr->val);
94 case MIPS_IMM_SYMCONST_HI:
95 fprintf(F, " hi(%s", get_entity_ld_name(attr->entity));
97 fprintf(F, "%+ld", attr->val);
102 fprintf(F, " INVALID ");
108 case dump_node_info_txt:
109 arch_dump_reqs_and_registers(F, n);
116 /***************************************************************************************************
118 * | | | | | | / / | | | | | | | |
119 * __ _| |_| |_ _ __ ___ ___| |_ / /_ _ ___| |_ _ __ ___ ___| |_| |__ ___ __| |___
120 * / _` | __| __| '__| / __|/ _ \ __| / / _` |/ _ \ __| | '_ ` _ \ / _ \ __| '_ \ / _ \ / _` / __|
121 * | (_| | |_| |_| | \__ \ __/ |_ / / (_| | __/ |_ | | | | | | __/ |_| | | | (_) | (_| \__ \
122 * \__,_|\__|\__|_| |___/\___|\__/_/ \__, |\___|\__| |_| |_| |_|\___|\__|_| |_|\___/ \__,_|___/
125 ***************************************************************************************************/
127 mips_attr_t *get_mips_attr(ir_node *node)
129 assert(is_mips_irn(node) && "need mips node to get attributes");
130 return (mips_attr_t *) get_irn_generic_attr(node);
133 const mips_attr_t *get_mips_attr_const(const ir_node *node)
135 assert(is_mips_irn(node) && "need mips node to get attributes");
136 return get_irn_generic_attr_const(node);
139 const mips_immediate_attr_t *get_mips_immediate_attr_const(const ir_node *node)
141 assert(is_mips_irn(node) && "need mips node to get attributes");
142 return get_irn_generic_attr_const(node);
145 const mips_load_store_attr_t *get_mips_load_store_attr_const(
148 assert(is_mips_irn(node) && "need mips node to get attributes");
149 return get_irn_generic_attr_const(node);
153 * Returns the argument register requirements of a mips node.
155 const arch_register_req_t **get_mips_in_req_all(const ir_node *node)
157 const mips_attr_t *attr = get_mips_attr_const(node);
162 * Returns the argument register requirement at position pos of an mips node.
164 const arch_register_req_t *get_mips_in_req(const ir_node *node, int pos)
166 const mips_attr_t *attr = get_mips_attr_const(node);
167 return attr->in_req[pos];
171 * Sets the IN register requirements at position pos.
173 void set_mips_req_in(ir_node *node, const arch_register_req_t *req, int pos)
175 mips_attr_t *attr = get_mips_attr(node);
176 attr->in_req[pos] = req;
180 * Initializes the nodes attributes.
182 static void init_mips_attributes(ir_node *node, arch_irn_flags_t flags,
183 const arch_register_req_t **in_reqs,
184 const be_execution_unit_t ***execution_units,
187 ir_graph *irg = get_irn_irg(node);
188 struct obstack *obst = get_irg_obstack(irg);
189 mips_attr_t *attr = get_mips_attr(node);
190 backend_info_t *info;
191 (void) execution_units;
193 arch_irn_set_flags(node, flags);
194 attr->in_req = in_reqs;
196 info = be_get_info(node);
197 info->out_infos = NEW_ARR_D(reg_out_info_t, obst, n_res);
198 memset(info->out_infos, 0, n_res * sizeof(info->out_infos[0]));
201 static void init_mips_immediate_attributes(ir_node *node,
202 mips_immediate_type_t type,
203 ir_entity *entity, long val)
205 mips_immediate_attr_t *attr = get_irn_generic_attr(node);
207 attr->imm_type = type;
208 attr->entity = entity;
212 static void init_mips_load_store_attributes(ir_node *node, ir_entity *entity,
215 mips_load_store_attr_t *attr = get_irn_generic_attr(node);
216 attr->stack_entity = entity;
217 attr->offset = offset;
220 static int mips_compare_nodes_attr(ir_node *node_a, ir_node *node_b)
222 const mips_attr_t *a = get_mips_attr_const(node_a);
223 const mips_attr_t *b = get_mips_attr_const(node_b);
225 if (a->switch_default_pn != b->switch_default_pn)
231 static int mips_compare_immediate_attr(ir_node *node_a, ir_node *node_b)
233 const mips_immediate_attr_t *a = get_mips_immediate_attr_const(node_a);
234 const mips_immediate_attr_t *b = get_mips_immediate_attr_const(node_b);
236 if (a->val != b->val)
242 static int mips_compare_load_store_attr(ir_node *node_a, ir_node *node_b)
244 const mips_load_store_attr_t *a = get_mips_load_store_attr_const(node_a);
245 const mips_load_store_attr_t *b = get_mips_load_store_attr_const(node_b);
247 if (mips_compare_nodes_attr(node_a, node_b))
249 if (a->stack_entity != b->stack_entity)
251 if (a->offset != b->offset)
257 static void mips_copy_attr(ir_graph *irg, const ir_node *old_node,
260 struct obstack *obst = get_irg_obstack(irg);
261 const mips_attr_t *attr_old = get_mips_attr_const(old_node);
262 mips_attr_t *attr_new = get_mips_attr(new_node);
263 backend_info_t *old_info = be_get_info(old_node);
264 backend_info_t *new_info = be_get_info(new_node);
266 /* copy the attributes */
267 memcpy(attr_new, attr_old, get_op_attr_size(get_irn_op(old_node)));
270 new_info->out_infos =
271 DUP_ARR_D(reg_out_info_t, obst, old_info->out_infos);
274 /***************************************************************************************
277 * _ __ ___ __| | ___ ___ ___ _ __ ___| |_ _ __ _ _ ___| |_ ___ _ __ ___
278 * | '_ \ / _ \ / _` |/ _ \ / __/ _ \| '_ \/ __| __| '__| | | |/ __| __/ _ \| '__/ __|
279 * | | | | (_) | (_| | __/ | (_| (_) | | | \__ \ |_| | | |_| | (__| || (_) | | \__ \
280 * |_| |_|\___/ \__,_|\___| \___\___/|_| |_|___/\__|_| \__,_|\___|\__\___/|_| |___/
282 ***************************************************************************************/
284 /* Include the generated constructor functions */
285 #include "gen_mips_new_nodes.c.inl"