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 n the node to dump
65 * @param F the output file
66 * @param reason indicates which kind of information should be dumped
67 * @return 0 on success or != 0 on failure
69 static int mips_dump_node(ir_node *n, FILE *F, dump_reason_t reason)
72 case dump_node_opcode_txt:
73 fprintf(F, "%s", get_irn_opname(n));
76 case dump_node_mode_txt:
79 case dump_node_nodeattr_txt:
81 if(is_mips_Immediate(n)) {
82 const mips_immediate_attr_t *attr
83 = get_mips_immediate_attr_const(n);
84 switch(attr->imm_type) {
86 fprintf(F, " %ld ", attr->val);
88 case MIPS_IMM_SYMCONST_LO:
89 fprintf(F, " lo(%s", get_entity_ld_name(attr->entity));
91 fprintf(F, "%+ld", attr->val);
95 case MIPS_IMM_SYMCONST_HI:
96 fprintf(F, " hi(%s", get_entity_ld_name(attr->entity));
98 fprintf(F, "%+ld", attr->val);
103 fprintf(F, " INVALID ");
109 case dump_node_info_txt:
110 arch_dump_reqs_and_registers(F, n);
119 /***************************************************************************************************
121 * | | | | | | / / | | | | | | | |
122 * __ _| |_| |_ _ __ ___ ___| |_ / /_ _ ___| |_ _ __ ___ ___| |_| |__ ___ __| |___
123 * / _` | __| __| '__| / __|/ _ \ __| / / _` |/ _ \ __| | '_ ` _ \ / _ \ __| '_ \ / _ \ / _` / __|
124 * | (_| | |_| |_| | \__ \ __/ |_ / / (_| | __/ |_ | | | | | | __/ |_| | | | (_) | (_| \__ \
125 * \__,_|\__|\__|_| |___/\___|\__/_/ \__, |\___|\__| |_| |_| |_|\___|\__|_| |_|\___/ \__,_|___/
128 ***************************************************************************************************/
130 mips_attr_t *get_mips_attr(ir_node *node)
132 assert(is_mips_irn(node) && "need mips node to get attributes");
133 return (mips_attr_t *) get_irn_generic_attr(node);
136 const mips_attr_t *get_mips_attr_const(const ir_node *node)
138 assert(is_mips_irn(node) && "need mips node to get attributes");
139 return get_irn_generic_attr_const(node);
142 const mips_immediate_attr_t *get_mips_immediate_attr_const(const ir_node *node)
144 assert(is_mips_irn(node) && "need mips node to get attributes");
145 return get_irn_generic_attr_const(node);
148 const mips_load_store_attr_t *get_mips_load_store_attr_const(
151 assert(is_mips_irn(node) && "need mips node to get attributes");
152 return get_irn_generic_attr_const(node);
156 * Returns the argument register requirements of a mips node.
158 const arch_register_req_t **get_mips_in_req_all(const ir_node *node)
160 const mips_attr_t *attr = get_mips_attr_const(node);
165 * Returns the argument register requirement at position pos of an mips node.
167 const arch_register_req_t *get_mips_in_req(const ir_node *node, int pos)
169 const mips_attr_t *attr = get_mips_attr_const(node);
170 return attr->in_req[pos];
174 * Sets the IN register requirements at position pos.
176 void set_mips_req_in(ir_node *node, const arch_register_req_t *req, int pos)
178 mips_attr_t *attr = get_mips_attr(node);
179 attr->in_req[pos] = req;
183 * Initializes the nodes attributes.
185 static void init_mips_attributes(ir_node *node, arch_irn_flags_t flags,
186 const arch_register_req_t **in_reqs,
187 const be_execution_unit_t ***execution_units,
190 ir_graph *irg = get_irn_irg(node);
191 struct obstack *obst = get_irg_obstack(irg);
192 mips_attr_t *attr = get_mips_attr(node);
193 backend_info_t *info;
194 (void) execution_units;
196 arch_irn_set_flags(node, flags);
197 attr->in_req = in_reqs;
199 info = be_get_info(node);
200 info->out_infos = NEW_ARR_D(reg_out_info_t, obst, n_res);
201 memset(info->out_infos, 0, n_res * sizeof(info->out_infos[0]));
204 static void init_mips_immediate_attributes(ir_node *node,
205 mips_immediate_type_t type,
206 ir_entity *entity, long val)
208 mips_immediate_attr_t *attr = get_irn_generic_attr(node);
210 attr->imm_type = type;
211 attr->entity = entity;
215 static void init_mips_load_store_attributes(ir_node *node, ir_entity *entity,
218 mips_load_store_attr_t *attr = get_irn_generic_attr(node);
219 attr->stack_entity = entity;
220 attr->offset = offset;
223 static int mips_compare_nodes_attr(ir_node *node_a, ir_node *node_b)
225 const mips_attr_t *a = get_mips_attr_const(node_a);
226 const mips_attr_t *b = get_mips_attr_const(node_b);
228 if(a->switch_default_pn != b->switch_default_pn)
234 static int mips_compare_immediate_attr(ir_node *node_a, ir_node *node_b)
236 const mips_immediate_attr_t *a = get_mips_immediate_attr_const(node_a);
237 const mips_immediate_attr_t *b = get_mips_immediate_attr_const(node_b);
245 static int mips_compare_load_store_attr(ir_node *node_a, ir_node *node_b)
247 const mips_load_store_attr_t *a = get_mips_load_store_attr_const(node_a);
248 const mips_load_store_attr_t *b = get_mips_load_store_attr_const(node_b);
250 if(mips_compare_nodes_attr(node_a, node_b))
252 if(a->stack_entity != b->stack_entity)
254 if(a->offset != b->offset)
260 static void mips_copy_attr(const ir_node *old_node , ir_node *new_node)
262 ir_graph *irg = get_irn_irg(new_node);
263 struct obstack *obst = get_irg_obstack(irg);
264 const mips_attr_t *attr_old = get_mips_attr_const(old_node);
265 mips_attr_t *attr_new = get_mips_attr(new_node);
266 backend_info_t *old_info = be_get_info(old_node);
267 backend_info_t *new_info = be_get_info(new_node);
269 /* copy the attributes */
270 memcpy(attr_new, attr_old, get_op_attr_size(get_irn_op(old_node)));
273 new_info->out_infos =
274 DUP_ARR_D(reg_out_info_t, obst, old_info->out_infos);
277 /***************************************************************************************
280 * _ __ ___ __| | ___ ___ ___ _ __ ___| |_ _ __ _ _ ___| |_ ___ _ __ ___
281 * | '_ \ / _ \ / _` |/ _ \ / __/ _ \| '_ \/ __| __| '__| | | |/ __| __/ _ \| '__/ __|
282 * | | | | (_) | (_| | __/ | (_| (_) | | | \__ \ |_| | | |_| | (__| || (_) | | \__ \
283 * |_| |_|\___/ \__,_|\___| \___\___/|_| |_|___/\__|_| \__,_|\___|\__\___/|_| |___/
285 ***************************************************************************************/
287 /* Include the generated constructor functions */
288 #include "gen_mips_new_nodes.c.inl"