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 ppc assembler
25 * @author Moritz Kroll, Jens Mueller
33 #include "irgraph_t.h"
39 #include "firm_common_t.h"
44 #include "../bearch_t.h"
46 #include "ppc32_nodes_attr.h"
47 #include "ppc32_new_nodes.h"
48 #include "gen_ppc32_regalloc_if.h"
52 /***********************************************************************************
55 * __| |_ _ _ __ ___ _ __ ___ _ __ _ _ __ | |_ ___ _ __| |_ __ _ ___ ___
56 * / _` | | | | '_ ` _ \| '_ \ / _ \ '__| | | '_ \| __/ _ \ '__| _/ _` |/ __/ _ \
57 * | (_| | |_| | | | | | | |_) | __/ | | | | | | || __/ | | || (_| | (_| __/
58 * \__,_|\__,_|_| |_| |_| .__/ \___|_| |_|_| |_|\__\___|_| |_| \__,_|\___\___|
61 ***********************************************************************************/
64 * Dumps the register requirements for either in or out.
66 static void dump_reg_req(FILE *F, ir_node *n, const arch_register_req_t **reqs, int inout) {
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 ppc32 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 ppc32_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, "=== ppc attr begin ===\n");
164 /* dump IN requirements */
165 if (get_irn_arity(n) > 0) {
166 reqs = get_ppc32_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_ppc32_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, "=== ppc attr end ===\n");
210 /* end of: case dump_node_info_txt */
220 /***************************************************************************************************
222 * | | | | | | / / | | | | | | | |
223 * __ _| |_| |_ _ __ ___ ___| |_ / /_ _ ___| |_ _ __ ___ ___| |_| |__ ___ __| |___
224 * / _` | __| __| '__| / __|/ _ \ __| / / _` |/ _ \ __| | '_ ` _ \ / _ \ __| '_ \ / _ \ / _` / __|
225 * | (_| | |_| |_| | \__ \ __/ |_ / / (_| | __/ |_ | | | | | | __/ |_| | | | (_) | (_| \__ \
226 * \__,_|\__|\__|_| |___/\___|\__/_/ \__, |\___|\__| |_| |_| |_|\___|\__|_| |_|\___/ \__,_|___/
229 ***************************************************************************************************/
231 ppc32_attr_t *get_ppc32_attr(ir_node *node) {
232 assert(is_ppc32_irn(node) && "need ppc node to get attributes");
233 return (ppc32_attr_t *)get_irn_generic_attr(node);
236 const ppc32_attr_t *get_ppc32_attr_const(const ir_node *node) {
237 assert(is_ppc32_irn(node) && "need ppc node to get attributes");
238 return (const ppc32_attr_t *)get_irn_generic_attr_const(node);
244 * Returns the argument register requirements of a ppc node.
246 const arch_register_req_t **get_ppc32_in_req_all(const ir_node *node) {
247 const ppc32_attr_t *attr = get_ppc32_attr_const(node);
252 * Returns the result register requirements of an ppc node.
254 const arch_register_req_t **get_ppc32_out_req_all(const ir_node *node) {
255 const ppc32_attr_t *attr = get_ppc32_attr_const(node);
256 return attr->out_req;
260 * Returns the argument register requirement at position pos of an ppc node.
262 const arch_register_req_t *get_ppc32_in_req(const ir_node *node, int pos) {
263 const ppc32_attr_t *attr = get_ppc32_attr_const(node);
264 return attr->in_req[pos];
268 * Returns the result register requirement at position pos of an ppc node.
270 const arch_register_req_t *get_ppc32_out_req(const ir_node *node, int pos) {
271 const ppc32_attr_t *attr = get_ppc32_attr_const(node);
272 return attr->out_req[pos];
276 * Sets the OUT register requirements at position pos.
278 void set_ppc32_req_out(ir_node *node, const arch_register_req_t *req, int pos) {
279 ppc32_attr_t *attr = get_ppc32_attr(node);
280 attr->out_req[pos] = req;
284 * Sets the IN register requirements at position pos.
286 void set_ppc32_req_in(ir_node *node, const arch_register_req_t *req, int pos) {
287 ppc32_attr_t *attr = get_ppc32_attr(node);
288 attr->in_req[pos] = req;
292 * Sets the type of the constant (if any)
293 * May be either iro_Const or iro_SymConst
295 /* void set_ppc32_type(const ir_node *node, opcode type) {
296 ppc32_attr_t *attr = get_ppc32_attr(node);
301 * Returns the type of the content (if any)
303 ppc32_attr_content_type get_ppc32_type(const ir_node *node) {
304 const ppc32_attr_t *attr = get_ppc32_attr_const(node);
305 return attr->content_type;
309 * Sets a tarval type content (also updating the content_type)
311 void set_ppc32_constant_tarval(ir_node *node, tarval *const_tarval) {
312 ppc32_attr_t *attr = get_ppc32_attr(node);
313 attr->content_type = ppc32_ac_Const;
314 attr->data.constant_tarval = const_tarval;
318 * Returns a tarval type constant
320 tarval *get_ppc32_constant_tarval(const ir_node *node) {
321 const ppc32_attr_t *attr = get_ppc32_attr_const(node);
322 return attr->data.constant_tarval;
326 * Sets an ident type constant (also updating the content_type)
328 void set_ppc32_symconst_ident(ir_node *node, ident *symconst_ident) {
329 ppc32_attr_t *attr = get_ppc32_attr(node);
330 attr->content_type = ppc32_ac_SymConst;
331 attr->data.symconst_ident = symconst_ident;
335 * Returns an ident type constant
337 ident *get_ppc32_symconst_ident(const ir_node *node) {
338 const ppc32_attr_t *attr = get_ppc32_attr_const(node);
339 return attr->data.symconst_ident;
344 * Sets an entity (also updating the content_type)
346 void set_ppc32_frame_entity(ir_node *node, ir_entity *ent) {
347 ppc32_attr_t *attr = get_ppc32_attr(node);
348 attr->content_type = ppc32_ac_FrameEntity;
349 attr->data.frame_entity = ent;
355 ir_entity *get_ppc32_frame_entity(const ir_node *node) {
356 const ppc32_attr_t *attr = get_ppc32_attr_const(node);
357 return attr->data.frame_entity;
361 * Sets a Rlwimi const (also updating the content_type)
363 void set_ppc32_rlwimi_const(ir_node *node, unsigned shift, unsigned maskA, unsigned maskB) {
364 ppc32_attr_t *attr = get_ppc32_attr(node);
365 attr->content_type = ppc32_ac_RlwimiConst;
366 attr->data.rlwimi_const.shift = shift;
367 attr->data.rlwimi_const.maskA = maskA;
368 attr->data.rlwimi_const.maskB = maskB;
372 * Returns the rlwimi const structure
374 const rlwimi_const_t *get_ppc32_rlwimi_const(const ir_node *node) {
375 const ppc32_attr_t *attr = get_ppc32_attr_const(node);
376 return &attr->data.rlwimi_const;
380 * Sets a Proj number (also updating the content_type)
382 void set_ppc32_proj_nr(ir_node *node, int proj_nr) {
383 ppc32_attr_t *attr = get_ppc32_attr(node);
384 attr->content_type = ppc32_ac_BranchProj;
385 attr->data.proj_nr = proj_nr;
389 * Returns the proj number
391 int get_ppc32_proj_nr(const ir_node *node) {
392 const ppc32_attr_t *attr = get_ppc32_attr_const(node);
393 return attr->data.proj_nr;
397 * Sets an offset for a memory access (also updating the content_type)
399 void set_ppc32_offset(ir_node *node, int offset) {
400 ppc32_attr_t *attr = get_ppc32_attr(node);
401 attr->content_type = ppc32_ac_Offset;
402 attr->data.offset = offset;
408 int get_ppc32_offset(const ir_node *node) {
409 const ppc32_attr_t *attr = get_ppc32_attr_const(node);
410 return attr->data.offset;
414 * Sets the offset mode (ppc32_ao_None, ppc32_ao_Lo16, ppc32_ao_Hi16 or ppc32_ao_Ha16)
416 void set_ppc32_offset_mode(ir_node *node, ppc32_attr_offset_mode mode) {
417 ppc32_attr_t *attr = get_ppc32_attr(node);
418 attr->offset_mode = mode;
422 * Returns the offset mode
424 ppc32_attr_offset_mode get_ppc32_offset_mode(const ir_node *node) {
425 const ppc32_attr_t *attr = get_ppc32_attr_const(node);
426 return attr->offset_mode;
431 * Initializes ppc specific node attributes
433 void init_ppc32_attributes(ir_node *node, int flags,
434 const arch_register_req_t **in_reqs, const arch_register_req_t **out_reqs,
435 const be_execution_unit_t ***execution_units,
437 ir_graph *irg = get_irn_irg(node);
438 struct obstack *obst = get_irg_obstack(irg);
439 ppc32_attr_t *attr = get_ppc32_attr(node);
440 backend_info_t *info;
441 (void) execution_units;
443 arch_irn_set_flags(node, flags);
444 attr->in_req = in_reqs;
445 attr->out_req = out_reqs;
447 attr->content_type = ppc32_ac_None;
448 attr->offset_mode = ppc32_ao_Illegal;
449 attr->data.empty = NULL;
451 info = be_get_info(node);
452 info->out_infos = NEW_ARR_D(reg_out_info_t, obst, n_res);
453 memset(info->out_infos, 0, n_res * sizeof(info->out_infos[0]));
457 /***************************************************************************************
460 * _ __ ___ __| | ___ ___ ___ _ __ ___| |_ _ __ _ _ ___| |_ ___ _ __ ___
461 * | '_ \ / _ \ / _` |/ _ \ / __/ _ \| '_ \/ __| __| '__| | | |/ __| __/ _ \| '__/ __|
462 * | | | | (_) | (_| | __/ | (_| (_) | | | \__ \ |_| | | |_| | (__| || (_) | | \__ \
463 * |_| |_|\___/ \__,_|\___| \___\___/|_| |_|___/\__|_| \__,_|\___|\__\___/|_| |___/
465 ***************************************************************************************/
467 /* Include the generated constructor functions */
468 #include "gen_ppc32_new_nodes.c.inl"