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 * Dumps the register requirements for either in or out.
65 static void dump_reg_req(FILE *F, ir_node *n, const arch_register_req_t **reqs,
68 char *dir = inout ? "out" : "in";
69 int max = inout ? (int) arch_irn_get_n_outs(n) : get_irn_arity(n);
73 memset(buf, 0, sizeof(buf));
76 for (i = 0; i < max; i++) {
77 fprintf(F, "%sreq #%d =", dir, i);
78 arch_dump_register_req(F, reqs[i], n);
84 fprintf(F, "%sreq = N/A\n", dir);
90 * Dumper interface for dumping mips nodes in vcg.
91 * @param n the node to dump
92 * @param F the output file
93 * @param reason indicates which kind of information should be dumped
94 * @return 0 on success or != 0 on failure
96 static int mips_dump_node(ir_node *n, FILE *F, dump_reason_t reason) {
99 const arch_register_req_t **reqs;
102 case dump_node_opcode_txt:
103 fprintf(F, "%s", get_irn_opname(n));
106 case dump_node_mode_txt:
109 case dump_node_nodeattr_txt:
111 if(is_mips_Immediate(n)) {
112 const mips_immediate_attr_t *attr
113 = get_mips_immediate_attr_const(n);
114 switch(attr->imm_type) {
116 fprintf(F, " %ld ", attr->val);
118 case MIPS_IMM_SYMCONST_LO:
119 fprintf(F, " lo(%s", get_entity_ld_name(attr->entity));
121 fprintf(F, "%+ld", attr->val);
125 case MIPS_IMM_SYMCONST_HI:
126 fprintf(F, " hi(%s", get_entity_ld_name(attr->entity));
128 fprintf(F, "%+ld", attr->val);
133 fprintf(F, " INVALID ");
139 case dump_node_info_txt:
140 fprintf(F, "=== mips attr begin ===\n");
142 /* dump IN requirements */
143 if (get_irn_arity(n) > 0) {
144 reqs = get_mips_in_req_all(n);
145 dump_reg_req(F, n, reqs, 0);
148 n_res = arch_irn_get_n_outs(n);
150 /* dump OUT requirements */
151 reqs = get_mips_out_req_all(n);
152 dump_reg_req(F, n, reqs, 1);
154 /* dump assigned registers */
155 for (i = 0; i < n_res; i++) {
156 const arch_register_t *reg = arch_irn_get_register(n, i);
158 fprintf(F, "reg #%d = %s\n", i, reg ? arch_register_get_name(reg) : "n/a");
164 fprintf(F, "n_res = %d\n", n_res);
167 fprintf(F, "flags =");
168 flags = arch_irn_get_flags(n);
169 if (flags == arch_irn_flags_none) {
173 if (flags & arch_irn_flags_dont_spill) {
174 fprintf(F, " unspillable");
176 if (flags & arch_irn_flags_rematerializable) {
177 fprintf(F, " remat");
179 if (flags & arch_irn_flags_modify_flags) {
180 fprintf(F, " modify_flags");
183 fprintf(F, " (%d)\n", flags);
185 fprintf(F, "=== mips attr end ===\n");
186 /* end of: case dump_node_info_txt */
196 /***************************************************************************************************
198 * | | | | | | / / | | | | | | | |
199 * __ _| |_| |_ _ __ ___ ___| |_ / /_ _ ___| |_ _ __ ___ ___| |_| |__ ___ __| |___
200 * / _` | __| __| '__| / __|/ _ \ __| / / _` |/ _ \ __| | '_ ` _ \ / _ \ __| '_ \ / _ \ / _` / __|
201 * | (_| | |_| |_| | \__ \ __/ |_ / / (_| | __/ |_ | | | | | | __/ |_| | | | (_) | (_| \__ \
202 * \__,_|\__|\__|_| |___/\___|\__/_/ \__, |\___|\__| |_| |_| |_|\___|\__|_| |_|\___/ \__,_|___/
205 ***************************************************************************************************/
207 mips_attr_t *get_mips_attr(ir_node *node)
209 assert(is_mips_irn(node) && "need mips node to get attributes");
210 return (mips_attr_t *) get_irn_generic_attr(node);
213 const mips_attr_t *get_mips_attr_const(const ir_node *node)
215 assert(is_mips_irn(node) && "need mips node to get attributes");
216 return get_irn_generic_attr_const(node);
219 const mips_immediate_attr_t *get_mips_immediate_attr_const(const ir_node *node)
221 assert(is_mips_irn(node) && "need mips node to get attributes");
222 return get_irn_generic_attr_const(node);
225 const mips_load_store_attr_t *get_mips_load_store_attr_const(
228 assert(is_mips_irn(node) && "need mips node to get attributes");
229 return get_irn_generic_attr_const(node);
233 * Returns the argument register requirements of a mips node.
235 const arch_register_req_t **get_mips_in_req_all(const ir_node *node)
237 const mips_attr_t *attr = get_mips_attr_const(node);
242 * Returns the result register requirements of an mips node.
244 const arch_register_req_t **get_mips_out_req_all(const ir_node *node)
246 const mips_attr_t *attr = get_mips_attr_const(node);
247 return attr->out_req;
251 * Returns the argument register requirement at position pos of an mips node.
253 const arch_register_req_t *get_mips_in_req(const ir_node *node, int pos)
255 const mips_attr_t *attr = get_mips_attr_const(node);
256 return attr->in_req[pos];
260 * Returns the result register requirement at position pos of an mips node.
262 const arch_register_req_t *get_mips_out_req(const ir_node *node, int pos)
264 const mips_attr_t *attr = get_mips_attr_const(node);
265 return attr->out_req[pos];
269 * Sets the OUT register requirements at position pos.
271 void set_mips_req_out(ir_node *node, const arch_register_req_t *req, int pos)
273 mips_attr_t *attr = get_mips_attr(node);
274 attr->out_req[pos] = req;
278 * Sets the IN register requirements at position pos.
280 void set_mips_req_in(ir_node *node, const arch_register_req_t *req, int pos)
282 mips_attr_t *attr = get_mips_attr(node);
283 attr->in_req[pos] = req;
287 * Initializes the nodes attributes.
289 static void init_mips_attributes(ir_node *node, arch_irn_flags_t flags,
290 const arch_register_req_t **in_reqs,
291 const arch_register_req_t **out_reqs,
292 const be_execution_unit_t ***execution_units,
295 ir_graph *irg = get_irn_irg(node);
296 struct obstack *obst = get_irg_obstack(irg);
297 mips_attr_t *attr = get_mips_attr(node);
298 backend_info_t *info;
299 (void) execution_units;
301 arch_irn_set_flags(node, flags);
302 attr->out_req = out_reqs;
303 attr->in_req = in_reqs;
305 info = be_get_info(node);
306 info->out_infos = NEW_ARR_D(reg_out_info_t, obst, n_res);
307 memset(info->out_infos, 0, n_res * sizeof(info->out_infos[0]));
310 static void init_mips_immediate_attributes(ir_node *node,
311 mips_immediate_type_t type,
312 ir_entity *entity, long val)
314 mips_immediate_attr_t *attr = get_irn_generic_attr(node);
316 attr->imm_type = type;
317 attr->entity = entity;
321 static void init_mips_load_store_attributes(ir_node *node, ir_entity *entity,
324 mips_load_store_attr_t *attr = get_irn_generic_attr(node);
325 attr->stack_entity = entity;
326 attr->offset = offset;
329 static int mips_compare_nodes_attr(ir_node *node_a, ir_node *node_b)
331 const mips_attr_t *a = get_mips_attr_const(node_a);
332 const mips_attr_t *b = get_mips_attr_const(node_b);
334 if(a->switch_default_pn != b->switch_default_pn)
340 static int mips_compare_immediate_attr(ir_node *node_a, ir_node *node_b)
342 const mips_immediate_attr_t *a = get_mips_immediate_attr_const(node_a);
343 const mips_immediate_attr_t *b = get_mips_immediate_attr_const(node_b);
351 static int mips_compare_load_store_attr(ir_node *node_a, ir_node *node_b)
353 const mips_load_store_attr_t *a = get_mips_load_store_attr_const(node_a);
354 const mips_load_store_attr_t *b = get_mips_load_store_attr_const(node_b);
356 if(mips_compare_nodes_attr(node_a, node_b))
358 if(a->stack_entity != b->stack_entity)
360 if(a->offset != b->offset)
366 static void mips_copy_attr(const ir_node *old_node , ir_node *new_node)
368 ir_graph *irg = get_irn_irg(new_node);
369 struct obstack *obst = get_irg_obstack(irg);
370 const mips_attr_t *attr_old = get_mips_attr_const(old_node);
371 mips_attr_t *attr_new = get_mips_attr(new_node);
372 backend_info_t *old_info = be_get_info(old_node);
373 backend_info_t *new_info = be_get_info(new_node);
375 /* copy the attributes */
376 memcpy(attr_new, attr_old, get_op_attr_size(get_irn_op(old_node)));
379 new_info->out_infos =
380 DUP_ARR_D(reg_out_info_t, obst, old_info->out_infos);
383 /***************************************************************************************
386 * _ __ ___ __| | ___ ___ ___ _ __ ___| |_ _ __ _ _ ___| |_ ___ _ __ ___
387 * | '_ \ / _ \ / _` |/ _ \ / __/ _ \| '_ \/ __| __| '__| | | |/ __| __/ _ \| '__/ __|
388 * | | | | (_) | (_| | __/ | (_| (_) | | | \__ \ |_| | | |_| | (__| || (_) | | \__ \
389 * |_| |_|\___/ \__,_|\___| \___\___/|_| |_|___/\__|_| \__,_|\___|\__\___/|_| |___/
391 ***************************************************************************************/
393 /* Include the generated constructor functions */
394 #include "gen_mips_new_nodes.c.inl"