2 * This file implements the creation of the achitecture specific firm opcodes
3 * and the coresponding node constructors for the TEMPLATE assembler irg.
13 #include "irgraph_t.h"
19 #include "firm_common_t.h"
24 #include "../bearch.h"
26 #include "TEMPLATE_nodes_attr.h"
27 #include "TEMPLATE_new_nodes.h"
28 #include "gen_TEMPLATE_regalloc_if.h"
32 /***********************************************************************************
35 * __| |_ _ _ __ ___ _ __ ___ _ __ _ _ __ | |_ ___ _ __| |_ __ _ ___ ___
36 * / _` | | | | '_ ` _ \| '_ \ / _ \ '__| | | '_ \| __/ _ \ '__| _/ _` |/ __/ _ \
37 * | (_| | |_| | | | | | | |_) | __/ | | | | | | || __/ | | || (_| | (_| __/
38 * \__,_|\__,_|_| |_| |_| .__/ \___|_| |_|_| |_|\__\___|_| |_| \__,_|\___\___|
41 ***********************************************************************************/
44 * Dumps the register requirements for either in or out.
46 static void dump_reg_req(FILE *F, ir_node *n, const arch_register_req_t **reqs,
48 char *dir = inout ? "out" : "in";
49 int max = inout ? get_TEMPLATE_n_res(n) : get_irn_arity(n);
53 memset(buf, 0, sizeof(buf));
56 for (i = 0; i < max; i++) {
57 fprintf(F, "%sreq #%d =", dir, i);
59 if (reqs[i]->type == arch_register_req_type_none) {
63 if (reqs[i]->type & arch_register_req_type_normal) {
64 fprintf(F, " %s", reqs[i]->cls->name);
67 if (reqs[i]->type & arch_register_req_type_limited) {
69 arch_register_req_format(buf, sizeof(buf), reqs[i], n));
72 if (reqs[i]->type & arch_register_req_type_should_be_same) {
73 ir_fprintf(F, " same as %+F", get_irn_n(n, reqs[i]->other_same));
76 if (reqs[i]->type & arch_register_req_type_should_be_different) {
77 ir_fprintf(F, " different from %+F", get_irn_n(n, reqs[i]->other_different));
85 fprintf(F, "%sreq = N/A\n", dir);
91 * Dumper interface for dumping TEMPLATE nodes in vcg.
92 * @param n the node to dump
93 * @param F the output file
94 * @param reason indicates which kind of information should be dumped
95 * @return 0 on success or != 0 on failure
97 static int TEMPLATE_dump_node(ir_node *n, FILE *F, dump_reason_t reason) {
101 TEMPLATE_attr_t *attr;
102 const arch_register_req_t **reqs;
103 const arch_register_t **slots;
106 case dump_node_opcode_txt:
107 fprintf(F, "%s", get_irn_opname(n));
110 case dump_node_mode_txt:
111 mode = get_irn_mode(n);
114 fprintf(F, "[%s]", get_mode_name(mode));
117 fprintf(F, "[?NOMODE?]");
121 case dump_node_nodeattr_txt:
123 /* TODO: dump some attributes which should show up */
124 /* in node name in dump (e.g. consts or the like) */
128 case dump_node_info_txt:
129 attr = get_TEMPLATE_attr(n);
130 fprintf(F, "=== TEMPLATE attr begin ===\n");
132 /* dump IN requirements */
133 if (get_irn_arity(n) > 0) {
134 reqs = get_TEMPLATE_in_req_all(n);
135 dump_reg_req(F, n, reqs, 0);
138 /* dump OUT requirements */
139 if (attr->n_res > 0) {
140 reqs = get_TEMPLATE_out_req_all(n);
141 dump_reg_req(F, n, reqs, 1);
144 /* dump assigned registers */
145 slots = get_TEMPLATE_slots(n);
146 if (slots && attr->n_res > 0) {
147 for (i = 0; i < attr->n_res; i++) {
149 fprintf(F, "reg #%d = %s\n", i, slots[i]->name);
152 fprintf(F, "reg #%d = n/a\n", i);
159 fprintf(F, "n_res = %d\n", get_TEMPLATE_n_res(n));
162 fprintf(F, "flags =");
163 if (attr->flags == arch_irn_flags_none) {
167 if (attr->flags & arch_irn_flags_dont_spill) {
168 fprintf(F, " unspillable");
170 if (attr->flags & arch_irn_flags_rematerializable) {
171 fprintf(F, " remat");
173 if (attr->flags & arch_irn_flags_ignore) {
174 fprintf(F, " ignore");
177 fprintf(F, " (%d)\n", attr->flags);
179 /* TODO: dump all additional attributes */
181 fprintf(F, "=== TEMPLATE attr end ===\n");
182 /* end of: case dump_node_info_txt */
192 /***************************************************************************************************
194 * | | | | | | / / | | | | | | | |
195 * __ _| |_| |_ _ __ ___ ___| |_ / /_ _ ___| |_ _ __ ___ ___| |_| |__ ___ __| |___
196 * / _` | __| __| '__| / __|/ _ \ __| / / _` |/ _ \ __| | '_ ` _ \ / _ \ __| '_ \ / _ \ / _` / __|
197 * | (_| | |_| |_| | \__ \ __/ |_ / / (_| | __/ |_ | | | | | | __/ |_| | | | (_) | (_| \__ \
198 * \__,_|\__|\__|_| |___/\___|\__/_/ \__, |\___|\__| |_| |_| |_|\___|\__|_| |_|\___/ \__,_|___/
201 ***************************************************************************************************/
204 * Wraps get_irn_generic_attr() as it takes no const ir_node, so we need to do a cast.
205 * Firm was made by people hating const :-(
207 TEMPLATE_attr_t *get_TEMPLATE_attr(const ir_node *node) {
208 assert(is_TEMPLATE_irn(node) && "need TEMPLATE node to get attributes");
209 return (TEMPLATE_attr_t *)get_irn_generic_attr((ir_node *)node);
213 * Returns the argument register requirements of a TEMPLATE node.
215 const arch_register_req_t **get_TEMPLATE_in_req_all(const ir_node *node) {
216 TEMPLATE_attr_t *attr = get_TEMPLATE_attr(node);
221 * Returns the result register requirements of an TEMPLATE node.
223 const arch_register_req_t **get_TEMPLATE_out_req_all(const ir_node *node) {
224 TEMPLATE_attr_t *attr = get_TEMPLATE_attr(node);
225 return attr->out_req;
229 * Returns the argument register requirement at position pos of an TEMPLATE node.
231 const arch_register_req_t *get_TEMPLATE_in_req(const ir_node *node, int pos) {
232 TEMPLATE_attr_t *attr = get_TEMPLATE_attr(node);
233 return attr->in_req[pos];
237 * Returns the result register requirement at position pos of an TEMPLATE node.
239 const arch_register_req_t *get_TEMPLATE_out_req(const ir_node *node, int pos) {
240 TEMPLATE_attr_t *attr = get_TEMPLATE_attr(node);
241 return attr->out_req[pos];
245 * Sets the OUT register requirements at position pos.
247 void set_TEMPLATE_req_out(ir_node *node, const arch_register_req_t *req, int pos) {
248 TEMPLATE_attr_t *attr = get_TEMPLATE_attr(node);
249 attr->out_req[pos] = req;
253 * Sets the IN register requirements at position pos.
255 void set_TEMPLATE_req_in(ir_node *node, const arch_register_req_t *req, int pos) {
256 TEMPLATE_attr_t *attr = get_TEMPLATE_attr(node);
257 attr->in_req[pos] = req;
261 * Returns the register flag of an TEMPLATE node.
263 arch_irn_flags_t get_TEMPLATE_flags(const ir_node *node) {
264 TEMPLATE_attr_t *attr = get_TEMPLATE_attr(node);
269 * Sets the register flag of an TEMPLATE node.
271 void set_TEMPLATE_flags(const ir_node *node, arch_irn_flags_t flags) {
272 TEMPLATE_attr_t *attr = get_TEMPLATE_attr(node);
277 * Returns the result register slots of an TEMPLATE node.
279 const arch_register_t **get_TEMPLATE_slots(const ir_node *node) {
280 TEMPLATE_attr_t *attr = get_TEMPLATE_attr(node);
285 * Returns the name of the OUT register at position pos.
287 const char *get_TEMPLATE_out_reg_name(const ir_node *node, int pos) {
288 TEMPLATE_attr_t *attr = get_TEMPLATE_attr(node);
290 assert(is_TEMPLATE_irn(node) && "Not an TEMPLATE node.");
291 assert(pos < attr->n_res && "Invalid OUT position.");
292 assert(attr->slots[pos] && "No register assigned");
294 return arch_register_get_name(attr->slots[pos]);
298 * Returns the index of the OUT register at position pos within its register class.
300 int get_TEMPLATE_out_regnr(const ir_node *node, int pos) {
301 TEMPLATE_attr_t *attr = get_TEMPLATE_attr(node);
303 assert(is_TEMPLATE_irn(node) && "Not an TEMPLATE node.");
304 assert(pos < attr->n_res && "Invalid OUT position.");
305 assert(attr->slots[pos] && "No register assigned");
307 return arch_register_get_index(attr->slots[pos]);
311 * Returns the OUT register at position pos.
313 const arch_register_t *get_TEMPLATE_out_reg(const ir_node *node, int pos) {
314 TEMPLATE_attr_t *attr = get_TEMPLATE_attr(node);
316 assert(is_TEMPLATE_irn(node) && "Not an TEMPLATE node.");
317 assert(pos < attr->n_res && "Invalid OUT position.");
318 assert(attr->slots[pos] && "No register assigned");
320 return attr->slots[pos];
324 * Sets the number of results.
326 void set_TEMPLATE_n_res(ir_node *node, int n_res) {
327 TEMPLATE_attr_t *attr = get_TEMPLATE_attr(node);
332 * Returns the number of results.
334 int get_TEMPLATE_n_res(const ir_node *node) {
335 TEMPLATE_attr_t *attr = get_TEMPLATE_attr(node);
340 * Initializes the nodes attributes.
342 void init_TEMPLATE_attributes(ir_node *node, arch_irn_flags_t flags,
343 const arch_register_req_t **in_reqs,
344 const arch_register_req_t **out_reqs,
345 const be_execution_unit_t ***execution_units,
346 int n_res, unsigned latency)
348 TEMPLATE_attr_t *attr = get_TEMPLATE_attr(node);
351 attr->out_req = out_reqs;
352 attr->in_req = in_reqs;
355 memset((void *)attr->slots, 0, n_res * sizeof(attr->slots[0]));
358 /***************************************************************************************
361 * _ __ ___ __| | ___ ___ ___ _ __ ___| |_ _ __ _ _ ___| |_ ___ _ __ ___
362 * | '_ \ / _ \ / _` |/ _ \ / __/ _ \| '_ \/ __| __| '__| | | |/ __| __/ _ \| '__/ __|
363 * | | | | (_) | (_| | __/ | (_| (_) | | | \__ \ |_| | | |_| | (__| || (_) | | \__ \
364 * |_| |_|\___/ \__,_|\___| \___\___/|_| |_|___/\__|_| \__,_|\___|\__\___/|_| |___/
366 ***************************************************************************************/
368 /* Include the generated constructor functions */
369 #include "gen_TEMPLATE_new_nodes.c.inl"