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 achitecture specific firm
23 * opcodes and the coresponding node constructors for the TEMPLATE
32 #include "irgraph_t.h"
38 #include "firm_common_t.h"
43 #include "../bearch_t.h"
45 #include "TEMPLATE_nodes_attr.h"
46 #include "TEMPLATE_new_nodes.h"
47 #include "gen_TEMPLATE_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,
67 char *dir = inout ? "out" : "in";
68 int max = inout ? (int) arch_irn_get_n_outs(n) : get_irn_arity(n);
72 memset(buf, 0, sizeof(buf));
75 for (i = 0; i < max; i++) {
76 fprintf(F, "%sreq #%d =", dir, i);
78 if (reqs[i]->type == arch_register_req_type_none) {
82 if (reqs[i]->type & arch_register_req_type_normal) {
83 fprintf(F, " %s", reqs[i]->cls->name);
86 if (reqs[i]->type & arch_register_req_type_limited) {
88 arch_register_req_format(buf, sizeof(buf), reqs[i], n));
91 if (reqs[i]->type & arch_register_req_type_should_be_same) {
92 const unsigned other = reqs[i]->other_same;
95 ir_fprintf(F, " same as");
96 for (i = 0; 1U << i <= other; ++i) {
97 if (other & (1U << i)) {
98 ir_fprintf(F, " %+F", get_irn_n(n, i));
103 if (reqs[i]->type & arch_register_req_type_must_be_different) {
104 const unsigned other = reqs[i]->other_different;
107 ir_fprintf(F, " different from");
108 for (i = 0; 1U << i <= other; ++i) {
109 if (other & (1U << i)) {
110 ir_fprintf(F, " %+F", get_irn_n(n, i));
120 fprintf(F, "%sreq = N/A\n", dir);
126 * Dumper interface for dumping TEMPLATE nodes in vcg.
127 * @param n the node to dump
128 * @param F the output file
129 * @param reason indicates which kind of information should be dumped
130 * @return 0 on success or != 0 on failure
132 static int TEMPLATE_dump_node(ir_node *n, FILE *F, dump_reason_t reason) {
133 ir_mode *mode = NULL;
136 const arch_register_req_t **reqs;
139 case dump_node_opcode_txt:
140 fprintf(F, "%s", get_irn_opname(n));
143 case dump_node_mode_txt:
144 mode = get_irn_mode(n);
147 fprintf(F, "[%s]", get_mode_name(mode));
150 fprintf(F, "[?NOMODE?]");
154 case dump_node_nodeattr_txt:
156 /* TODO: dump some attributes which should show up */
157 /* in node name in dump (e.g. consts or the like) */
161 case dump_node_info_txt:
162 fprintf(F, "=== TEMPLATE attr begin ===\n");
164 /* dump IN requirements */
165 if (get_irn_arity(n) > 0) {
166 reqs = get_TEMPLATE_in_req_all(n);
167 dump_reg_req(F, n, reqs, 0);
170 n_res = arch_irn_get_n_outs(n);
172 /* dump OUT requirements */
173 reqs = get_TEMPLATE_out_req_all(n);
174 dump_reg_req(F, n, reqs, 1);
176 /* dump assigned registers */
177 for (i = 0; i < n_res; i++) {
178 const arch_register_t *reg = arch_irn_get_register(n, i);
180 fprintf(F, "reg #%d = %s\n", i, reg ? arch_register_get_name(reg) : "n/a");
186 fprintf(F, "n_res = %d\n", n_res);
189 fprintf(F, "flags =");
190 flags = arch_irn_get_flags(n);
191 if (flags == arch_irn_flags_none) {
195 if (flags & arch_irn_flags_dont_spill) {
196 fprintf(F, " unspillable");
198 if (flags & arch_irn_flags_rematerializable) {
199 fprintf(F, " remat");
201 if (flags & arch_irn_flags_modify_flags) {
202 fprintf(F, " modify_flags");
205 fprintf(F, " (%d)\n", flags);
207 /* TODO: dump all additional attributes */
209 fprintf(F, "=== TEMPLATE attr end ===\n");
210 /* end of: case dump_node_info_txt */
220 /***************************************************************************************************
222 * | | | | | | / / | | | | | | | |
223 * __ _| |_| |_ _ __ ___ ___| |_ / /_ _ ___| |_ _ __ ___ ___| |_| |__ ___ __| |___
224 * / _` | __| __| '__| / __|/ _ \ __| / / _` |/ _ \ __| | '_ ` _ \ / _ \ __| '_ \ / _ \ / _` / __|
225 * | (_| | |_| |_| | \__ \ __/ |_ / / (_| | __/ |_ | | | | | | __/ |_| | | | (_) | (_| \__ \
226 * \__,_|\__|\__|_| |___/\___|\__/_/ \__, |\___|\__| |_| |_| |_|\___|\__|_| |_|\___/ \__,_|___/
229 ***************************************************************************************************/
231 const TEMPLATE_attr_t *get_TEMPLATE_attr_const(const ir_node *node) {
232 assert(is_TEMPLATE_irn(node) && "need TEMPLATE node to get attributes");
233 return (const TEMPLATE_attr_t *)get_irn_generic_attr_const(node);
236 TEMPLATE_attr_t *get_TEMPLATE_attr(ir_node *node) {
237 assert(is_TEMPLATE_irn(node) && "need TEMPLATE node to get attributes");
238 return (TEMPLATE_attr_t *)get_irn_generic_attr(node);
242 * Returns the argument register requirements of a TEMPLATE node.
244 const arch_register_req_t **get_TEMPLATE_in_req_all(const ir_node *node) {
245 const TEMPLATE_attr_t *attr = get_TEMPLATE_attr_const(node);
250 * Returns the result register requirements of an TEMPLATE node.
252 const arch_register_req_t **get_TEMPLATE_out_req_all(const ir_node *node) {
253 const TEMPLATE_attr_t *attr = get_TEMPLATE_attr_const(node);
254 return attr->out_req;
258 * Returns the argument register requirement at position pos of an TEMPLATE node.
260 const arch_register_req_t *get_TEMPLATE_in_req(const ir_node *node, int pos) {
261 const TEMPLATE_attr_t *attr = get_TEMPLATE_attr_const(node);
262 return attr->in_req[pos];
266 * Returns the result register requirement at position pos of an TEMPLATE node.
268 const arch_register_req_t *get_TEMPLATE_out_req(const ir_node *node, int pos) {
269 const TEMPLATE_attr_t *attr = get_TEMPLATE_attr_const(node);
270 return attr->out_req[pos];
274 * Sets the OUT register requirements at position pos.
276 void set_TEMPLATE_req_out(ir_node *node, const arch_register_req_t *req, int pos) {
277 TEMPLATE_attr_t *attr = get_TEMPLATE_attr(node);
278 attr->out_req[pos] = req;
282 * Sets the IN register requirements at position pos.
284 void set_TEMPLATE_req_in(ir_node *node, const arch_register_req_t *req, int pos) {
285 TEMPLATE_attr_t *attr = get_TEMPLATE_attr(node);
286 attr->in_req[pos] = req;
290 * Initializes the nodes attributes.
292 void init_TEMPLATE_attributes(ir_node *node, arch_irn_flags_t flags,
293 const arch_register_req_t **in_reqs,
294 const arch_register_req_t **out_reqs,
295 const be_execution_unit_t ***execution_units,
298 ir_graph *irg = get_irn_irg(node);
299 struct obstack *obst = get_irg_obstack(irg);
300 TEMPLATE_attr_t *attr = get_TEMPLATE_attr(node);
301 backend_info_t *info;
302 (void) execution_units;
304 arch_irn_set_flags(node, flags);
305 attr->out_req = out_reqs;
306 attr->in_req = in_reqs;
308 info = be_get_info(node);
309 info->out_infos = NEW_ARR_D(reg_out_info_t, obst, n_res);
310 memset(info->out_infos, 0, n_res * sizeof(info->out_infos[0]));
313 /***************************************************************************************
316 * _ __ ___ __| | ___ ___ ___ _ __ ___| |_ _ __ _ _ ___| |_ ___ _ __ ___
317 * | '_ \ / _ \ / _` |/ _ \ / __/ _ \| '_ \/ __| __| '__| | | |/ __| __/ _ \| '__/ __|
318 * | | | | (_) | (_| | __/ | (_| (_) | | | \__ \ |_| | | |_| | (__| || (_) | | \__ \
319 * |_| |_|\___/ \__,_|\___| \___\___/|_| |_|___/\__|_| \__,_|\___|\__\___/|_| |___/
321 ***************************************************************************************/
324 int TEMPLATE_compare_attr(ir_node *a, ir_node *b)
326 const TEMPLATE_attr_t *attr_a = get_TEMPLATE_attr_const(a);
327 const TEMPLATE_attr_t *attr_b = get_TEMPLATE_attr_const(b);
335 /* Include the generated constructor functions */
336 #include "gen_TEMPLATE_new_nodes.c.inl"