3 * File name: ir/ir/irop_t.h
4 * Purpose: Representation of opcode of intermediate operation -- private header.
5 * Author: Christian Schaefer
6 * Modified by: Goetz Lindenmaier
9 * Copyright: (c) 1998-2003 Universität Karlsruhe
10 * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
15 #include "firm_config.h"
20 /** The allowed parities */
23 oparity_unary, /**< an unary operator -- considering 'numeric' arguments. */
24 oparity_binary, /**< an binary operator -- considering 'numeric' arguments.*/
25 oparity_trinary, /**< an trinary operator -- considering 'numeric' arguments.*/
26 oparity_zero, /**< no operators, as e.g. Const. */
27 oparity_variable, /**< arity not fixed by opcode, but statically
28 known. E.g., number of arguments to call. */
29 oparity_dynamic, /**< arity depends on state of firm representation.
30 Can change by optimizations...
31 We must allocate a dynamic in array for the node! */
32 oparity_any, /**< other arity */
38 irop_flag_none = 0x00000000, /**< nothing */
39 irop_flag_labeled = 0x00000001, /**< if set, Output edge labels on in-edges in vcg graph */
40 irop_flag_commutative = 0x00000002, /**< operation is commutative */
41 irop_flag_cfopcode = 0x00000004, /**< is a control flow operation */
42 irop_flag_ip_cfopcode = 0x00000008, /**< operation manipulates interprocedural control flow */
43 irop_flag_fragile = 0x00000010, /**< set if the operation can change the control flow because
45 irop_flag_forking = 0x00000020, /**< the operation is a forking control flow */
46 irop_flag_highlevel = 0x00000040, /**< the operation is a pure high-level one and can be
47 skipped in low-level optimizations */
52 * The compute value operation.
53 * This operation evaluates an IR node into a tarval if possible,
54 * returning tarval_bad otherwise.
56 typedef tarval *(*computed_value_func)(ir_node *self);
59 * The equivalent node operation.
60 * This operation returns an equivalent node for the input node.
61 * It does not create new nodes. It is therefore safe to free self
62 * if the node returned is not self.
63 * If a node returns a Tuple we can not just skip it. If the size of the
64 * in array fits, we transform n into a tuple (e.g., possible for Div).
66 typedef ir_node *(*equivalent_node_func)(ir_node *self);
69 * The transform node operation.
70 * This operation tries several [inplace] [optimizing] transformations
71 * and returns an equivalent node.
72 * The difference to equivalent_node() is that these
73 * transformations _do_ generate new nodes, and thus the old node must
74 * not be freed even if the equivalent node isn't the old one.
76 typedef ir_node *(*transform_node_func)(ir_node *self);
79 * The node attribute compare operation.
80 * Compares the nodes attributes of two nodes of identical opcode
81 * and returns 0 if the attributes are identical, 1 if they differ.
83 typedef int (*node_cmp_attr_func)(ir_node *a, ir_node *b);
86 * The reassociation operation.
87 * Called from a walker. Returns non-zero if
88 * a reassociation rule was applied.
89 * The pointer n is set to the newly created node, if some reassociation
92 typedef int (*reassociate_func)(ir_node **n);
95 * The copy attribute operation.
96 * Copy the node attributes from a 'old' node to a 'new' one.
98 typedef void (*copy_attr_func)(const ir_node *old_node, ir_node *new_node);
101 * The get_type operation.
102 * Return the type of the node self.
104 typedef type *(*get_type_func)(ir_node *self);
107 * The verify_node operation.
108 * Return non-zero if the node verification is ok, else 0.
109 * Depending on the node verification settings, may even assert.
111 * @see do_node_verification()
113 typedef int (*verify_node_func)(ir_node *self, ir_graph *irg);
116 * The verify_node operation for Proj(X).
117 * Return non-zero if the node verification is ok, else 0.
118 * Depending on the node verification settings, may even assert.
120 * @see do_node_verification()
122 typedef int (*verify_proj_node_func)(ir_node *self, ir_node *proj);
124 /** The type of an ir_op. */
126 opcode code; /**< the unique opcode of the op */
127 ident *name; /**< the name of the op */
128 size_t attr_size; /**< Space needed in memory for private attributes */
129 op_pin_state op_pin_state_pinned; /**< How to deal with the node in cse, pre. */
130 op_arity opar; /**< arity of operator. */
131 int op_index; /**< the index of the first data operand, 0 for most cases, 1 for Div etc. */
132 unsigned flags; /**< flags describing the behavior of the ir_op, a bitmaks of irop_flags */
135 computed_value_func computed_value; /**< evaluates a node into a tarval if possible. */
136 equivalent_node_func equivalent_node; /**< optimizes the node by returning an equivalent one. */
137 transform_node_func transform_node; /**< optimizes the node by transforming it. */
138 node_cmp_attr_func node_cmp_attr; /**< compares two node attributes. */
139 reassociate_func reassociate; /**< reassociate a tree */
140 copy_attr_func copy_attr; /**< copy node attributes */
141 get_type_func get_type; /**< return the type of a node */
142 verify_node_func verify_node; /**< verify the node */
143 verify_proj_node_func verify_proj_node; /**< verify the Proj node */
147 * Creates a new ir operation.
149 * @param code the opcode, one of type \c opcode
150 * @param name the printable name of this opcode
151 * @param p whether operations of this opcode are op_pin_state_pinned or floating
152 * @param flags a bitmask of irop_flags describing the behavior of the ir operation
153 * @param opar the parity of this ir operation
154 * @param op_index if the parity is oparity_unary, oparity_binary or oparity_trinary the index
155 * of the left operand
156 * @param attr_size attribute size for this ir operation
158 * @return The generated ir operation.
160 ir_op * new_ir_op(opcode code, const char *name, op_pin_state p,
161 unsigned flags, op_arity opar, int op_index, size_t attr_size);
164 * Frees a newly created ir operation.
166 void free_ir_op(ir_op *code);
168 /** Initialize the irop module. */
171 /** Free memory used by irop module. */
172 void finish_op(void);
175 * Copies simply all attributes stored in the old node to the new node.
176 * Assumes both have the same opcode and sufficient size.
178 void default_copy_attr(const ir_node *old_node, ir_node *new_node);
180 /** Returns the attribute size of nodes of this opcode.
181 @note Use not encouraged, internal feature. */
182 static INLINE int get_op_attr_size (const ir_op *op) {
183 return op->attr_size;
186 /** Returns non-zero if op is one of Start, End, Jmp, Cond, Return, Raise or Bad. */
187 static INLINE int is_cfopcode(const ir_op *op) {
188 return op->flags & irop_flag_cfopcode;
191 /** Returns true if the operation manipulates interprocedural control flow:
192 CallBegin, EndReg, EndExcept */
193 static INLINE int is_ip_cfopcode(const ir_op *op) {
194 return op->flags & irop_flag_ip_cfopcode;
197 /* Returns non-zero if operation is commutative */
198 static INLINE int is_op_commutative(const ir_op *op) {
199 return op->flags & irop_flag_commutative;
202 /* Returns non-zero if operation is fragile */
203 static INLINE int is_op_fragile(const ir_op *op) {
204 return op->flags & irop_flag_fragile;
207 /* Returns non-zero if operation is forking control flow */
208 static INLINE int is_op_forking(const ir_op *op) {
209 return op->flags & irop_flag_forking;
212 /* Returns non-zero if operation is a high-level op */
213 static INLINE int is_op_highlevel(const ir_op *op) {
214 return op->flags & irop_flag_highlevel;
217 static INLINE opcode _get_op_code(const ir_op *op) {
221 static INLINE ident *_get_op_ident(const ir_op *op){
225 static INLINE op_pin_state _get_op_pinned(const ir_op *op) {
226 return op->op_pin_state_pinned;
230 #define get_op_code(op) _get_op_code(op)
231 #define get_op_ident(op) _get_op_ident(op)
232 #define get_op_pinned(op) _get_op_pinned(op)
235 #endif /* _IROP_T_H_ */