2 * Copyright (C) 1995-2007 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 achitecture specific firm
23 * opcodes and the coresponding node constructors for the TEMPLATE
34 #include "irgraph_t.h"
40 #include "firm_common_t.h"
45 #include "../bearch_t.h"
47 #include "TEMPLATE_nodes_attr.h"
48 #include "TEMPLATE_new_nodes.h"
49 #include "gen_TEMPLATE_regalloc_if.h"
53 /***********************************************************************************
56 * __| |_ _ _ __ ___ _ __ ___ _ __ _ _ __ | |_ ___ _ __| |_ __ _ ___ ___
57 * / _` | | | | '_ ` _ \| '_ \ / _ \ '__| | | '_ \| __/ _ \ '__| _/ _` |/ __/ _ \
58 * | (_| | |_| | | | | | | |_) | __/ | | | | | | || __/ | | || (_| | (_| __/
59 * \__,_|\__,_|_| |_| |_| .__/ \___|_| |_|_| |_|\__\___|_| |_| \__,_|\___\___|
62 ***********************************************************************************/
65 * Dumps the register requirements for either in or out.
67 static void dump_reg_req(FILE *F, ir_node *n, const arch_register_req_t **reqs,
69 char *dir = inout ? "out" : "in";
70 int max = inout ? get_TEMPLATE_n_res(n) : get_irn_arity(n);
74 memset(buf, 0, sizeof(buf));
77 for (i = 0; i < max; i++) {
78 fprintf(F, "%sreq #%d =", dir, i);
80 if (reqs[i]->type == arch_register_req_type_none) {
84 if (reqs[i]->type & arch_register_req_type_normal) {
85 fprintf(F, " %s", reqs[i]->cls->name);
88 if (reqs[i]->type & arch_register_req_type_limited) {
90 arch_register_req_format(buf, sizeof(buf), reqs[i], n));
93 if (reqs[i]->type & arch_register_req_type_should_be_same) {
94 ir_fprintf(F, " same as %+F", get_irn_n(n, reqs[i]->other_same));
97 if (reqs[i]->type & arch_register_req_type_should_be_different) {
98 ir_fprintf(F, " different from %+F", get_irn_n(n, reqs[i]->other_different));
106 fprintf(F, "%sreq = N/A\n", dir);
112 * Dumper interface for dumping TEMPLATE nodes in vcg.
113 * @param n the node to dump
114 * @param F the output file
115 * @param reason indicates which kind of information should be dumped
116 * @return 0 on success or != 0 on failure
118 static int TEMPLATE_dump_node(ir_node *n, FILE *F, dump_reason_t reason) {
119 ir_mode *mode = NULL;
122 const TEMPLATE_attr_t *attr;
123 const arch_register_req_t **reqs;
124 const arch_register_t **slots;
127 case dump_node_opcode_txt:
128 fprintf(F, "%s", get_irn_opname(n));
131 case dump_node_mode_txt:
132 mode = get_irn_mode(n);
135 fprintf(F, "[%s]", get_mode_name(mode));
138 fprintf(F, "[?NOMODE?]");
142 case dump_node_nodeattr_txt:
144 /* TODO: dump some attributes which should show up */
145 /* in node name in dump (e.g. consts or the like) */
149 case dump_node_info_txt:
150 attr = get_TEMPLATE_attr_const(n);
151 fprintf(F, "=== TEMPLATE attr begin ===\n");
153 /* dump IN requirements */
154 if (get_irn_arity(n) > 0) {
155 reqs = get_TEMPLATE_in_req_all(n);
156 dump_reg_req(F, n, reqs, 0);
159 /* dump OUT requirements */
160 if (attr->n_res > 0) {
161 reqs = get_TEMPLATE_out_req_all(n);
162 dump_reg_req(F, n, reqs, 1);
165 /* dump assigned registers */
166 slots = get_TEMPLATE_slots(n);
167 if (slots && attr->n_res > 0) {
168 for (i = 0; i < attr->n_res; i++) {
170 fprintf(F, "reg #%d = %s\n", i, slots[i]->name);
173 fprintf(F, "reg #%d = n/a\n", i);
180 fprintf(F, "n_res = %d\n", get_TEMPLATE_n_res(n));
183 fprintf(F, "flags =");
184 if (attr->flags == arch_irn_flags_none) {
188 if (attr->flags & arch_irn_flags_dont_spill) {
189 fprintf(F, " unspillable");
191 if (attr->flags & arch_irn_flags_rematerializable) {
192 fprintf(F, " remat");
194 if (attr->flags & arch_irn_flags_ignore) {
195 fprintf(F, " ignore");
198 fprintf(F, " (%d)\n", attr->flags);
200 /* TODO: dump all additional attributes */
202 fprintf(F, "=== TEMPLATE attr end ===\n");
203 /* end of: case dump_node_info_txt */
213 /***************************************************************************************************
215 * | | | | | | / / | | | | | | | |
216 * __ _| |_| |_ _ __ ___ ___| |_ / /_ _ ___| |_ _ __ ___ ___| |_| |__ ___ __| |___
217 * / _` | __| __| '__| / __|/ _ \ __| / / _` |/ _ \ __| | '_ ` _ \ / _ \ __| '_ \ / _ \ / _` / __|
218 * | (_| | |_| |_| | \__ \ __/ |_ / / (_| | __/ |_ | | | | | | __/ |_| | | | (_) | (_| \__ \
219 * \__,_|\__|\__|_| |___/\___|\__/_/ \__, |\___|\__| |_| |_| |_|\___|\__|_| |_|\___/ \__,_|___/
222 ***************************************************************************************************/
224 const TEMPLATE_attr_t *get_TEMPLATE_attr_const(const ir_node *node) {
225 assert(is_TEMPLATE_irn(node) && "need TEMPLATE node to get attributes");
226 return (const TEMPLATE_attr_t *)get_irn_generic_attr_const(node);
229 TEMPLATE_attr_t *get_TEMPLATE_attr(ir_node *node) {
230 assert(is_TEMPLATE_irn(node) && "need TEMPLATE node to get attributes");
231 return (TEMPLATE_attr_t *)get_irn_generic_attr(node);
235 * Returns the argument register requirements of a TEMPLATE node.
237 const arch_register_req_t **get_TEMPLATE_in_req_all(const ir_node *node) {
238 const TEMPLATE_attr_t *attr = get_TEMPLATE_attr_const(node);
243 * Returns the result register requirements of an TEMPLATE node.
245 const arch_register_req_t **get_TEMPLATE_out_req_all(const ir_node *node) {
246 const TEMPLATE_attr_t *attr = get_TEMPLATE_attr_const(node);
247 return attr->out_req;
251 * Returns the argument register requirement at position pos of an TEMPLATE node.
253 const arch_register_req_t *get_TEMPLATE_in_req(const ir_node *node, int pos) {
254 const TEMPLATE_attr_t *attr = get_TEMPLATE_attr_const(node);
255 return attr->in_req[pos];
259 * Returns the result register requirement at position pos of an TEMPLATE node.
261 const arch_register_req_t *get_TEMPLATE_out_req(const ir_node *node, int pos) {
262 const TEMPLATE_attr_t *attr = get_TEMPLATE_attr_const(node);
263 return attr->out_req[pos];
267 * Sets the OUT register requirements at position pos.
269 void set_TEMPLATE_req_out(ir_node *node, const arch_register_req_t *req, int pos) {
270 TEMPLATE_attr_t *attr = get_TEMPLATE_attr(node);
271 attr->out_req[pos] = req;
275 * Sets the IN register requirements at position pos.
277 void set_TEMPLATE_req_in(ir_node *node, const arch_register_req_t *req, int pos) {
278 TEMPLATE_attr_t *attr = get_TEMPLATE_attr(node);
279 attr->in_req[pos] = req;
283 * Returns the register flag of an TEMPLATE node.
285 arch_irn_flags_t get_TEMPLATE_flags(const ir_node *node) {
286 const TEMPLATE_attr_t *attr = get_TEMPLATE_attr_const(node);
291 * Sets the register flag of an TEMPLATE node.
293 void set_TEMPLATE_flags(ir_node *node, arch_irn_flags_t flags) {
294 TEMPLATE_attr_t *attr = get_TEMPLATE_attr(node);
299 * Returns the result register slots of an TEMPLATE node.
301 const arch_register_t **get_TEMPLATE_slots(ir_node *node) {
302 TEMPLATE_attr_t *attr = get_TEMPLATE_attr_const(node);
307 * Returns the result register slots of an TEMPLATE node.
309 const arch_register_t * const *get_TEMPLATE_slots_const(const ir_node *node) {
310 TEMPLATE_attr_t *attr = get_TEMPLATE_attr_const(node);
315 * Returns the name of the OUT register at position pos.
317 const char *get_TEMPLATE_out_reg_name(const ir_node *node, int pos) {
318 const TEMPLATE_attr_t *attr = get_TEMPLATE_attr_const(node);
320 assert(is_TEMPLATE_irn(node) && "Not an TEMPLATE node.");
321 assert(pos < attr->n_res && "Invalid OUT position.");
322 assert(attr->slots[pos] && "No register assigned");
324 return arch_register_get_name(attr->slots[pos]);
328 * Returns the index of the OUT register at position pos within its register class.
330 int get_TEMPLATE_out_regnr(const ir_node *node, int pos) {
331 const TEMPLATE_attr_t *attr = get_TEMPLATE_attr_const(node);
333 assert(is_TEMPLATE_irn(node) && "Not an TEMPLATE node.");
334 assert(pos < attr->n_res && "Invalid OUT position.");
335 assert(attr->slots[pos] && "No register assigned");
337 return arch_register_get_index(attr->slots[pos]);
341 * Returns the OUT register at position pos.
343 const arch_register_t *get_TEMPLATE_out_reg(const ir_node *node, int pos) {
344 const TEMPLATE_attr_t *attr = get_TEMPLATE_attr_const(node);
346 assert(is_TEMPLATE_irn(node) && "Not an TEMPLATE node.");
347 assert(pos < attr->n_res && "Invalid OUT position.");
348 assert(attr->slots[pos] && "No register assigned");
350 return attr->slots[pos];
354 * Sets the number of results.
356 void set_TEMPLATE_n_res(ir_node *node, int n_res) {
357 TEMPLATE_attr_t *attr = get_TEMPLATE_attr(node);
362 * Returns the number of results.
364 int get_TEMPLATE_n_res(const ir_node *node) {
365 const TEMPLATE_attr_t *attr = get_TEMPLATE_attr_const(node);
370 * Initializes the nodes attributes.
372 void init_TEMPLATE_attributes(ir_node *node, arch_irn_flags_t flags,
373 const arch_register_req_t **in_reqs,
374 const arch_register_req_t **out_reqs,
375 const be_execution_unit_t ***execution_units,
376 int n_res, unsigned latency)
378 TEMPLATE_attr_t *attr = get_TEMPLATE_attr(node);
381 attr->out_req = out_reqs;
382 attr->in_req = in_reqs;
385 memset((void *)attr->slots, 0, n_res * sizeof(attr->slots[0]));
388 /***************************************************************************************
391 * _ __ ___ __| | ___ ___ ___ _ __ ___| |_ _ __ _ _ ___| |_ ___ _ __ ___
392 * | '_ \ / _ \ / _` |/ _ \ / __/ _ \| '_ \/ __| __| '__| | | |/ __| __/ _ \| '__/ __|
393 * | | | | (_) | (_| | __/ | (_| (_) | | | \__ \ |_| | | |_| | (__| || (_) | | \__ \
394 * |_| |_|\___/ \__,_|\___| \___\___/|_| |_|___/\__|_| \__,_|\___|\__\___/|_| |___/
396 ***************************************************************************************/
398 /* Include the generated constructor functions */
399 #include "gen_TEMPLATE_new_nodes.c.inl"