2 * This file implements the creation of the achitecture specific firm opcodes
3 * and the coresponding node constructors for the TEMPLATE assembler irg.
19 #include "irgraph_t.h"
25 #include "firm_common_t.h"
29 #include "../bearch.h"
31 #include "TEMPLATE_nodes_attr.h"
32 #include "TEMPLATE_new_nodes.h"
33 #include "gen_TEMPLATE_regalloc_if.h"
37 /***********************************************************************************
40 * __| |_ _ _ __ ___ _ __ ___ _ __ _ _ __ | |_ ___ _ __| |_ __ _ ___ ___
41 * / _` | | | | '_ ` _ \| '_ \ / _ \ '__| | | '_ \| __/ _ \ '__| _/ _` |/ __/ _ \
42 * | (_| | |_| | | | | | | |_) | __/ | | | | | | || __/ | | || (_| | (_| __/
43 * \__,_|\__,_|_| |_| |_| .__/ \___|_| |_|_| |_|\__\___|_| |_| \__,_|\___\___|
46 ***********************************************************************************/
49 * Dumps the register requirements for either in or out.
51 static void dump_reg_req(FILE *F, ir_node *n, const arch_register_req_t **reqs,
53 char *dir = inout ? "out" : "in";
54 int max = inout ? get_TEMPLATE_n_res(n) : get_irn_arity(n);
58 memset(buf, 0, sizeof(buf));
61 for (i = 0; i < max; i++) {
62 fprintf(F, "%sreq #%d =", dir, i);
64 if (reqs[i]->type == arch_register_req_type_none) {
68 if (reqs[i]->type & arch_register_req_type_normal) {
69 fprintf(F, " %s", reqs[i]->cls->name);
72 if (reqs[i]->type & arch_register_req_type_limited) {
74 arch_register_req_format(buf, sizeof(buf), reqs[i], n));
77 if (reqs[i]->type & arch_register_req_type_should_be_same) {
78 ir_fprintf(F, " same as %+F", get_irn_n(n, reqs[i]->other_same));
81 if (reqs[i]->type & arch_register_req_type_should_be_different) {
82 ir_fprintf(F, " different from %+F", get_irn_n(n, reqs[i]->other_different));
90 fprintf(F, "%sreq = N/A\n", dir);
96 * Dumper interface for dumping TEMPLATE nodes in vcg.
97 * @param n the node to dump
98 * @param F the output file
99 * @param reason indicates which kind of information should be dumped
100 * @return 0 on success or != 0 on failure
102 static int TEMPLATE_dump_node(ir_node *n, FILE *F, dump_reason_t reason) {
103 ir_mode *mode = NULL;
106 TEMPLATE_attr_t *attr;
107 const arch_register_req_t **reqs;
108 const arch_register_t **slots;
111 case dump_node_opcode_txt:
112 fprintf(F, "%s", get_irn_opname(n));
115 case dump_node_mode_txt:
116 mode = get_irn_mode(n);
119 fprintf(F, "[%s]", get_mode_name(mode));
122 fprintf(F, "[?NOMODE?]");
126 case dump_node_nodeattr_txt:
128 /* TODO: dump some attributes which should show up */
129 /* in node name in dump (e.g. consts or the like) */
133 case dump_node_info_txt:
134 attr = get_TEMPLATE_attr(n);
135 fprintf(F, "=== TEMPLATE attr begin ===\n");
137 /* dump IN requirements */
138 if (get_irn_arity(n) > 0) {
139 reqs = get_TEMPLATE_in_req_all(n);
140 dump_reg_req(F, n, reqs, 0);
143 /* dump OUT requirements */
144 if (attr->n_res > 0) {
145 reqs = get_TEMPLATE_out_req_all(n);
146 dump_reg_req(F, n, reqs, 1);
149 /* dump assigned registers */
150 slots = get_TEMPLATE_slots(n);
151 if (slots && attr->n_res > 0) {
152 for (i = 0; i < attr->n_res; i++) {
154 fprintf(F, "reg #%d = %s\n", i, slots[i]->name);
157 fprintf(F, "reg #%d = n/a\n", i);
164 fprintf(F, "n_res = %d\n", get_TEMPLATE_n_res(n));
167 fprintf(F, "flags =");
168 if (attr->flags == arch_irn_flags_none) {
172 if (attr->flags & arch_irn_flags_dont_spill) {
173 fprintf(F, " unspillable");
175 if (attr->flags & arch_irn_flags_rematerializable) {
176 fprintf(F, " remat");
178 if (attr->flags & arch_irn_flags_ignore) {
179 fprintf(F, " ignore");
182 fprintf(F, " (%d)\n", attr->flags);
184 /* TODO: dump all additional attributes */
186 fprintf(F, "=== TEMPLATE attr end ===\n");
187 /* end of: case dump_node_info_txt */
197 /***************************************************************************************************
199 * | | | | | | / / | | | | | | | |
200 * __ _| |_| |_ _ __ ___ ___| |_ / /_ _ ___| |_ _ __ ___ ___| |_| |__ ___ __| |___
201 * / _` | __| __| '__| / __|/ _ \ __| / / _` |/ _ \ __| | '_ ` _ \ / _ \ __| '_ \ / _ \ / _` / __|
202 * | (_| | |_| |_| | \__ \ __/ |_ / / (_| | __/ |_ | | | | | | __/ |_| | | | (_) | (_| \__ \
203 * \__,_|\__|\__|_| |___/\___|\__/_/ \__, |\___|\__| |_| |_| |_|\___|\__|_| |_|\___/ \__,_|___/
206 ***************************************************************************************************/
209 * Wraps get_irn_generic_attr() as it takes no const ir_node, so we need to do a cast.
210 * Firm was made by people hating const :-(
212 TEMPLATE_attr_t *get_TEMPLATE_attr(const ir_node *node) {
213 assert(is_TEMPLATE_irn(node) && "need TEMPLATE node to get attributes");
214 return (TEMPLATE_attr_t *)get_irn_generic_attr((ir_node *)node);
218 * Returns the argument register requirements of a TEMPLATE node.
220 const arch_register_req_t **get_TEMPLATE_in_req_all(const ir_node *node) {
221 TEMPLATE_attr_t *attr = get_TEMPLATE_attr(node);
226 * Returns the result register requirements of an TEMPLATE node.
228 const arch_register_req_t **get_TEMPLATE_out_req_all(const ir_node *node) {
229 TEMPLATE_attr_t *attr = get_TEMPLATE_attr(node);
230 return attr->out_req;
234 * Returns the argument register requirement at position pos of an TEMPLATE node.
236 const arch_register_req_t *get_TEMPLATE_in_req(const ir_node *node, int pos) {
237 TEMPLATE_attr_t *attr = get_TEMPLATE_attr(node);
238 return attr->in_req[pos];
242 * Returns the result register requirement at position pos of an TEMPLATE node.
244 const arch_register_req_t *get_TEMPLATE_out_req(const ir_node *node, int pos) {
245 TEMPLATE_attr_t *attr = get_TEMPLATE_attr(node);
246 return attr->out_req[pos];
250 * Sets the OUT register requirements at position pos.
252 void set_TEMPLATE_req_out(ir_node *node, const arch_register_req_t *req, int pos) {
253 TEMPLATE_attr_t *attr = get_TEMPLATE_attr(node);
254 attr->out_req[pos] = req;
258 * Sets the IN register requirements at position pos.
260 void set_TEMPLATE_req_in(ir_node *node, const arch_register_req_t *req, int pos) {
261 TEMPLATE_attr_t *attr = get_TEMPLATE_attr(node);
262 attr->in_req[pos] = req;
266 * Returns the register flag of an TEMPLATE node.
268 arch_irn_flags_t get_TEMPLATE_flags(const ir_node *node) {
269 TEMPLATE_attr_t *attr = get_TEMPLATE_attr(node);
274 * Sets the register flag of an TEMPLATE node.
276 void set_TEMPLATE_flags(const ir_node *node, arch_irn_flags_t flags) {
277 TEMPLATE_attr_t *attr = get_TEMPLATE_attr(node);
282 * Returns the result register slots of an TEMPLATE node.
284 const arch_register_t **get_TEMPLATE_slots(const ir_node *node) {
285 TEMPLATE_attr_t *attr = get_TEMPLATE_attr(node);
290 * Returns the name of the OUT register at position pos.
292 const char *get_TEMPLATE_out_reg_name(const ir_node *node, int pos) {
293 TEMPLATE_attr_t *attr = get_TEMPLATE_attr(node);
295 assert(is_TEMPLATE_irn(node) && "Not an TEMPLATE node.");
296 assert(pos < attr->n_res && "Invalid OUT position.");
297 assert(attr->slots[pos] && "No register assigned");
299 return arch_register_get_name(attr->slots[pos]);
303 * Returns the index of the OUT register at position pos within its register class.
305 int get_TEMPLATE_out_regnr(const ir_node *node, int pos) {
306 TEMPLATE_attr_t *attr = get_TEMPLATE_attr(node);
308 assert(is_TEMPLATE_irn(node) && "Not an TEMPLATE node.");
309 assert(pos < attr->n_res && "Invalid OUT position.");
310 assert(attr->slots[pos] && "No register assigned");
312 return arch_register_get_index(attr->slots[pos]);
316 * Returns the OUT register at position pos.
318 const arch_register_t *get_TEMPLATE_out_reg(const ir_node *node, int pos) {
319 TEMPLATE_attr_t *attr = get_TEMPLATE_attr(node);
321 assert(is_TEMPLATE_irn(node) && "Not an TEMPLATE node.");
322 assert(pos < attr->n_res && "Invalid OUT position.");
323 assert(attr->slots[pos] && "No register assigned");
325 return attr->slots[pos];
329 * Sets the number of results.
331 void set_TEMPLATE_n_res(ir_node *node, int n_res) {
332 TEMPLATE_attr_t *attr = get_TEMPLATE_attr(node);
337 * Returns the number of results.
339 int get_TEMPLATE_n_res(const ir_node *node) {
340 TEMPLATE_attr_t *attr = get_TEMPLATE_attr(node);
345 * Initializes the nodes attributes.
347 void init_TEMPLATE_attributes(ir_node *node, arch_irn_flags_t flags,
348 const arch_register_req_t **in_reqs,
349 const arch_register_req_t **out_reqs,
350 const be_execution_unit_t ***execution_units,
351 int n_res, unsigned latency)
353 TEMPLATE_attr_t *attr = get_TEMPLATE_attr(node);
356 attr->out_req = out_reqs;
357 attr->in_req = in_reqs;
360 memset((void *)attr->slots, 0, n_res * sizeof(attr->slots[0]));
363 /***************************************************************************************
366 * _ __ ___ __| | ___ ___ ___ _ __ ___| |_ _ __ _ _ ___| |_ ___ _ __ ___
367 * | '_ \ / _ \ / _` |/ _ \ / __/ _ \| '_ \/ __| __| '__| | | |/ __| __/ _ \| '__/ __|
368 * | | | | (_) | (_| | __/ | (_| (_) | | | \__ \ |_| | | |_| | (__| || (_) | | \__ \
369 * |_| |_|\___/ \__,_|\___| \___\___/|_| |_|___/\__|_| \__,_|\___|\__\___/|_| |___/
371 ***************************************************************************************/
373 /* Include the generated constructor functions */
374 #include "gen_TEMPLATE_new_nodes.c.inl"