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 Representation of opcode of intermediate operation.
23 * @author Christian Schaefer, Goetz Lindenmaier, Michael Beck
33 #include "irbackedge_t.h"
37 #include "reassoc_t.h"
41 void be_init_op(void);
43 /** the available next opcode */
44 static unsigned next_iro = iro_MaxOpcode;
47 * Copies all attributes stored in the old node to the new node.
48 * Assumes both have the same opcode and sufficient size.
50 void default_copy_attr(const ir_node *old_node, ir_node *new_node)
52 unsigned size = firm_add_node_size;
54 assert(get_irn_op(old_node) == get_irn_op(new_node));
55 memcpy(&new_node->attr, &old_node->attr, get_op_attr_size(get_irn_op(old_node)));
58 /* copy additional node data */
59 memcpy(get_irn_data(new_node, void, size), get_irn_data(old_node, void, size), size);
61 } /* default_copy_attr */
64 * Copies all Call attributes stored in the old node to the new node.
67 call_copy_attr(const ir_node *old_node, ir_node *new_node)
69 default_copy_attr(old_node, new_node);
70 remove_Call_callee_arr(new_node);
71 } /* call_copy_attr */
74 * Copies all Block attributes stored in the old node to the new node.
77 block_copy_attr(const ir_node *old_node, ir_node *new_node)
79 ir_graph *irg = current_ir_graph;
81 default_copy_attr(old_node, new_node);
82 new_node->attr.block.phis = NULL;
83 new_node->attr.block.cg_backedge = NULL;
84 new_node->attr.block.backedge = new_backedge_arr(irg->obst, get_irn_arity(new_node));
85 INIT_LIST_HEAD(&new_node->attr.block.succ_head);
86 } /* block_copy_attr */
89 * Copies all phi attributes stored in old node to the new node
92 phi_copy_attr(const ir_node *old_node, ir_node *new_node)
94 ir_graph *irg = current_ir_graph;
96 default_copy_attr(old_node, new_node);
97 new_node->attr.phi.next = NULL;
98 new_node->attr.phi.u.backedge = new_backedge_arr(irg->obst, get_irn_arity(new_node));
102 * Copies all filter attributes stored in old node to the new node
105 filter_copy_attr(const ir_node *old_node, ir_node *new_node)
107 ir_graph *irg = current_ir_graph;
109 default_copy_attr(old_node, new_node);
110 new_node->attr.filter.backedge = new_backedge_arr(irg->obst, get_irn_arity(new_node));
114 * Copies all ASM attributes stored in old node to the new node
117 ASM_copy_attr(const ir_node *old_node, ir_node *new_node)
119 ir_graph *irg = current_ir_graph;
121 default_copy_attr(old_node, new_node);
122 new_node->attr.assem.inputs = DUP_ARR_D(ir_asm_constraint, irg->obst, old_node->attr.assem.inputs);
123 new_node->attr.assem.outputs = DUP_ARR_D(ir_asm_constraint, irg->obst, old_node->attr.assem.outputs);
124 new_node->attr.assem.clobber = DUP_ARR_D(ir_asm_constraint, irg->obst, old_node->attr.assem.clobber);
128 * Sets the default copy_attr operation for an ir_ops
130 * @param code the opcode for the default operation
131 * @param ops the operations initialized
136 static ir_op_ops *firm_set_default_copy_attr(ir_opcode code, ir_op_ops *ops)
140 ops->copy_attr = call_copy_attr;
143 ops->copy_attr = block_copy_attr;
146 ops->copy_attr = phi_copy_attr;
149 ops->copy_attr = filter_copy_attr;
152 ops->copy_attr = ASM_copy_attr;
155 /* not allowed to be NULL */
156 if (! ops->copy_attr)
157 ops->copy_attr = default_copy_attr;
160 } /* firm_set_default_copy_attr */
162 /* Creates a new ir operation. */
164 new_ir_op(unsigned code, const char *name, op_pin_state p,
165 unsigned flags, op_arity opar, int op_index, size_t attr_size,
166 const ir_op_ops *ops)
168 ir_op *res = XMALLOCZ(ir_op);
171 res->name = new_id_from_chars(name, strlen(name));
173 res->attr_size = attr_size;
176 res->op_index = op_index;
180 memcpy(&res->ops, ops, sizeof(res->ops));
181 else /* no given ops, set all operations to NULL */
182 memset(&res->ops, 0, sizeof(res->ops));
184 firm_set_default_operations(code, &res->ops);
185 firm_set_default_copy_attr(code, &res->ops);
186 firm_set_default_verifyer(code, &res->ops);
187 firm_set_default_reassoc(code, &res->ops);
195 void free_ir_op(ir_op *code)
197 hook_free_ir_op(code);
199 remove_irp_opcode(code);
203 /* Returns the string for the opcode. */
204 const char *get_op_name (const ir_op *op)
206 return get_id_str(op->name);
209 unsigned (get_op_code)(const ir_op *op)
211 return _get_op_code(op);
214 ident *(get_op_ident)(const ir_op *op)
216 return _get_op_ident(op);
219 const char *get_op_pin_state_name(op_pin_state s)
222 #define XXX(s) case s: return #s
223 XXX(op_pin_state_floats);
224 XXX(op_pin_state_pinned);
225 XXX(op_pin_state_exc_pinned);
226 XXX(op_pin_state_mem_pinned);
230 } /* get_op_pin_state_name */
232 op_pin_state (get_op_pinned)(const ir_op *op)
234 return _get_op_pinned(op);
235 } /* get_op_pinned */
237 /* Sets op_pin_state_pinned in the opcode. Setting it to floating has no effect
238 for Phi, Block and control flow nodes. */
239 void set_op_pinned(ir_op *op, op_pin_state pinned)
241 if (op == op_Block || op == op_Phi || is_op_cfopcode(op)) return;
242 op->pin_state = pinned;
243 } /* set_op_pinned */
245 /* retrieve the next free opcode */
246 unsigned get_next_ir_opcode(void)
249 } /* get_next_ir_opcode */
251 /* Returns the next free n IR opcode number, allows to register a bunch of user ops */
252 unsigned get_next_ir_opcodes(unsigned num)
254 unsigned base = next_iro;
257 } /* get_next_ir_opcodes */
259 /* Returns the generic function pointer from an ir operation. */
260 op_func (get_generic_function_ptr)(const ir_op *op)
262 return _get_generic_function_ptr(op);
263 } /* get_generic_function_ptr */
265 /* Store a generic function pointer into an ir operation. */
266 void (set_generic_function_ptr)(ir_op *op, op_func func)
268 _set_generic_function_ptr(op, func);
269 } /* set_generic_function_ptr */
271 /* Returns the ir_op_ops of an ir_op. */
272 const ir_op_ops *(get_op_ops)(const ir_op *op)
274 return _get_op_ops(op);
277 irop_flags get_op_flags(const ir_op *op)
282 #include "gen_irop.c.inl"