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"
43 #include "../bearch.h"
45 #include "ppc32_nodes_attr.h"
46 #include "ppc32_new_nodes.h"
47 #include "gen_ppc32_regalloc_if.h"
51 /***********************************************************************************
54 * __| |_ _ _ __ ___ _ __ ___ _ __ _ _ __ | |_ ___ _ __| |_ __ _ ___ ___
55 * / _` | | | | '_ ` _ \| '_ \ / _ \ '__| | | '_ \| __/ _ \ '__| _/ _` |/ __/ _ \
56 * | (_| | |_| | | | | | | |_) | __/ | | | | | | || __/ | | || (_| | (_| __/
57 * \__,_|\__,_|_| |_| |_| .__/ \___|_| |_|_| |_|\__\___|_| |_| \__,_|\___\___|
60 ***********************************************************************************/
63 * Dumper interface for dumping ppc32 nodes in vcg.
64 * @param n the node to dump
65 * @param F the output file
66 * @param reason indicates which kind of information should be dumped
67 * @return 0 on success or != 0 on failure
69 static int ppc32_dump_node(ir_node *n, FILE *F, dump_reason_t reason)
75 case dump_node_opcode_txt:
76 fprintf(F, "%s", get_irn_opname(n));
79 case dump_node_mode_txt:
80 mode = get_irn_mode(n);
83 fprintf(F, "[%s]", get_mode_name(mode));
86 fprintf(F, "[?NOMODE?]");
90 case dump_node_nodeattr_txt:
92 /* TODO: dump some attributes which should show up */
93 /* in node name in dump (e.g. consts or the like) */
97 case dump_node_info_txt:
98 arch_dump_reqs_and_registers(F, n);
108 /***************************************************************************************************
110 * | | | | | | / / | | | | | | | |
111 * __ _| |_| |_ _ __ ___ ___| |_ / /_ _ ___| |_ _ __ ___ ___| |_| |__ ___ __| |___
112 * / _` | __| __| '__| / __|/ _ \ __| / / _` |/ _ \ __| | '_ ` _ \ / _ \ __| '_ \ / _ \ / _` / __|
113 * | (_| | |_| |_| | \__ \ __/ |_ / / (_| | __/ |_ | | | | | | __/ |_| | | | (_) | (_| \__ \
114 * \__,_|\__|\__|_| |___/\___|\__/_/ \__, |\___|\__| |_| |_| |_|\___|\__|_| |_|\___/ \__,_|___/
117 ***************************************************************************************************/
119 ppc32_attr_t *get_ppc32_attr(ir_node *node)
121 assert(is_ppc32_irn(node) && "need ppc node to get attributes");
122 return (ppc32_attr_t *)get_irn_generic_attr(node);
125 const ppc32_attr_t *get_ppc32_attr_const(const ir_node *node)
127 assert(is_ppc32_irn(node) && "need ppc node to get attributes");
128 return (const ppc32_attr_t *)get_irn_generic_attr_const(node);
134 * Returns the argument register requirements of a ppc node.
136 const arch_register_req_t **get_ppc32_in_req_all(const ir_node *node)
138 const ppc32_attr_t *attr = get_ppc32_attr_const(node);
143 * Returns the argument register requirement at position pos of an ppc node.
145 const arch_register_req_t *get_ppc32_in_req(const ir_node *node, int pos)
147 const ppc32_attr_t *attr = get_ppc32_attr_const(node);
148 return attr->in_req[pos];
152 * Sets the IN register requirements at position pos.
154 void set_ppc32_req_in(ir_node *node, const arch_register_req_t *req, int pos)
156 ppc32_attr_t *attr = get_ppc32_attr(node);
157 attr->in_req[pos] = req;
161 * Sets the type of the constant (if any)
162 * May be either iro_Const or iro_SymConst
164 /* void set_ppc32_type(const ir_node *node, opcode type) {
165 ppc32_attr_t *attr = get_ppc32_attr(node);
170 * Returns the type of the content (if any)
172 ppc32_attr_content_type get_ppc32_type(const ir_node *node)
174 const ppc32_attr_t *attr = get_ppc32_attr_const(node);
175 return attr->content_type;
179 * Sets a tarval type content (also updating the content_type)
181 void set_ppc32_constant_tarval(ir_node *node, tarval *const_tarval)
183 ppc32_attr_t *attr = get_ppc32_attr(node);
184 attr->content_type = ppc32_ac_Const;
185 attr->data.constant_tarval = const_tarval;
189 * Returns a tarval type constant
191 tarval *get_ppc32_constant_tarval(const ir_node *node)
193 const ppc32_attr_t *attr = get_ppc32_attr_const(node);
194 return attr->data.constant_tarval;
198 * Sets an ident type constant (also updating the content_type)
200 void set_ppc32_symconst_ident(ir_node *node, ident *symconst_ident)
202 ppc32_attr_t *attr = get_ppc32_attr(node);
203 attr->content_type = ppc32_ac_SymConst;
204 attr->data.symconst_ident = symconst_ident;
208 * Returns an ident type constant
210 ident *get_ppc32_symconst_ident(const ir_node *node)
212 const ppc32_attr_t *attr = get_ppc32_attr_const(node);
213 return attr->data.symconst_ident;
218 * Sets an entity (also updating the content_type)
220 void set_ppc32_frame_entity(ir_node *node, ir_entity *ent)
222 ppc32_attr_t *attr = get_ppc32_attr(node);
223 attr->content_type = ppc32_ac_FrameEntity;
224 attr->data.frame_entity = ent;
230 ir_entity *get_ppc32_frame_entity(const ir_node *node)
232 const ppc32_attr_t *attr = get_ppc32_attr_const(node);
233 return attr->data.frame_entity;
237 * Sets a Rlwimi const (also updating the content_type)
239 void set_ppc32_rlwimi_const(ir_node *node, unsigned shift, unsigned maskA, unsigned maskB)
241 ppc32_attr_t *attr = get_ppc32_attr(node);
242 attr->content_type = ppc32_ac_RlwimiConst;
243 attr->data.rlwimi_const.shift = shift;
244 attr->data.rlwimi_const.maskA = maskA;
245 attr->data.rlwimi_const.maskB = maskB;
249 * Returns the rlwimi const structure
251 const rlwimi_const_t *get_ppc32_rlwimi_const(const ir_node *node)
253 const ppc32_attr_t *attr = get_ppc32_attr_const(node);
254 return &attr->data.rlwimi_const;
258 * Sets a Proj number (also updating the content_type)
260 void set_ppc32_proj_nr(ir_node *node, int proj_nr)
262 ppc32_attr_t *attr = get_ppc32_attr(node);
263 attr->content_type = ppc32_ac_BranchProj;
264 attr->data.proj_nr = proj_nr;
268 * Returns the proj number
270 int get_ppc32_proj_nr(const ir_node *node)
272 const ppc32_attr_t *attr = get_ppc32_attr_const(node);
273 return attr->data.proj_nr;
277 * Sets an offset for a memory access (also updating the content_type)
279 void set_ppc32_offset(ir_node *node, int offset)
281 ppc32_attr_t *attr = get_ppc32_attr(node);
282 attr->content_type = ppc32_ac_Offset;
283 attr->data.offset = offset;
289 int get_ppc32_offset(const ir_node *node)
291 const ppc32_attr_t *attr = get_ppc32_attr_const(node);
292 return attr->data.offset;
296 * Sets the offset mode (ppc32_ao_None, ppc32_ao_Lo16, ppc32_ao_Hi16 or ppc32_ao_Ha16)
298 void set_ppc32_offset_mode(ir_node *node, ppc32_attr_offset_mode mode)
300 ppc32_attr_t *attr = get_ppc32_attr(node);
301 attr->offset_mode = mode;
305 * Returns the offset mode
307 ppc32_attr_offset_mode get_ppc32_offset_mode(const ir_node *node)
309 const ppc32_attr_t *attr = get_ppc32_attr_const(node);
310 return attr->offset_mode;
315 * Initializes ppc specific node attributes
317 static void init_ppc32_attributes(ir_node *node, int flags,
318 const arch_register_req_t **in_reqs,
319 const be_execution_unit_t ***execution_units,
322 ir_graph *irg = get_irn_irg(node);
323 struct obstack *obst = get_irg_obstack(irg);
324 ppc32_attr_t *attr = get_ppc32_attr(node);
325 backend_info_t *info;
326 (void) execution_units;
328 arch_irn_set_flags(node, flags);
329 attr->in_req = in_reqs;
331 attr->content_type = ppc32_ac_None;
332 attr->offset_mode = ppc32_ao_Illegal;
333 attr->data.empty = NULL;
335 info = be_get_info(node);
336 info->out_infos = NEW_ARR_D(reg_out_info_t, obst, n_res);
337 memset(info->out_infos, 0, n_res * sizeof(info->out_infos[0]));
341 /***************************************************************************************
344 * _ __ ___ __| | ___ ___ ___ _ __ ___| |_ _ __ _ _ ___| |_ ___ _ __ ___
345 * | '_ \ / _ \ / _` |/ _ \ / __/ _ \| '_ \/ __| __| '__| | | |/ __| __/ _ \| '__/ __|
346 * | | | | (_) | (_| | __/ | (_| (_) | | | \__ \ |_| | | |_| | (__| || (_) | | \__ \
347 * |_| |_|\___/ \__,_|\___| \___\___/|_| |_|___/\__|_| \__,_|\___|\__\___/|_| |___/
349 ***************************************************************************************/
351 /* Include the generated constructor functions */
352 #include "gen_ppc32_new_nodes.c.inl"