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"
22 * The compute value operation.
23 * This operation evaluates an IR node into a tarval if possible,
24 * returning tarval_bad otherwise.
26 typedef tarval *(*computed_value_func)(ir_node *self);
29 * The equivalent node operation.
30 * This operation returns an equivalent node for the input node.
31 * It does not create new nodes. It is therefore safe to free self
32 * if the node returned is not self.
33 * If a node returns a Tuple we can not just skip it. If the size of the
34 * in array fits, we transform n into a tuple (e.g., possible for Div).
36 typedef ir_node *(*equivalent_node_func)(ir_node *self);
39 * The transform node operation.
40 * This operation tries several [inplace] [optimizing] transformations
41 * and returns an equivalent node.
42 * The difference to equivalent_node() is that these
43 * transformations _do_ generate new nodes, and thus the old node must
44 * not be freed even if the equivalent node isn't the old one.
46 typedef ir_node *(*transform_node_func)(ir_node *self);
49 * The node attribute compare operation.
50 * Compares the nodes attributes of two nodes of identical opcode
51 * and returns 0 if the attributes are identical, 1 if they differ.
53 typedef int (*node_cmp_attr_func)(ir_node *a, ir_node *b);
56 * The reassociation operation.
57 * Called from a walker. Returns non-zero if
58 * a reassociation rule was applied.
59 * The pointer n is set to the newly created node, if some reassociation
62 typedef int (*reassociate_func)(ir_node **n);
65 * The copy attribute operation.
66 * Copy the node attributes from a 'old' node to a 'new' one.
68 typedef void (*copy_attr_func)(const ir_node *old_node, ir_node *new_node);
71 * The get_type operation.
72 * Return the type of the node self.
74 typedef type *(*get_type_func)(ir_node *self);
77 * The verify_node operation.
78 * Return non-zero if the node verification is ok, else 0.
79 * Depending on the node verification settings, may even assert.
81 * @see do_node_verification()
83 typedef int (*verify_node_func)(ir_node *self, ir_graph *irg);
86 * The verify_node operation for Proj(X).
87 * Return non-zero if the node verification is ok, else 0.
88 * Depending on the node verification settings, may even assert.
90 * @see do_node_verification()
92 typedef int (*verify_proj_node_func)(ir_node *self, ir_node *proj);
94 /** The type of an ir_op. */
96 opcode code; /**< the unique opcode of the op */
97 ident *name; /**< the name of the op */
98 size_t attr_size; /**< Space needed in memory for private attributes */
99 op_pin_state op_pin_state_pinned; /**< How to deal with the node in cse, pre. */
100 op_arity opar; /**< arity of operator. */
101 int op_index; /**< the index of the first data operand, 0 for most cases, 1 for Div etc. */
102 unsigned flags; /**< flags describing the behavior of the ir_op, a bitmaks of irop_flags */
105 computed_value_func computed_value; /**< evaluates a node into a tarval if possible. */
106 equivalent_node_func equivalent_node; /**< optimizes the node by returning an equivalent one. */
107 transform_node_func transform_node; /**< optimizes the node by transforming it. */
108 node_cmp_attr_func node_cmp_attr; /**< compares two node attributes. */
109 reassociate_func reassociate; /**< reassociate a tree */
110 copy_attr_func copy_attr; /**< copy node attributes */
111 get_type_func get_type; /**< return the type of a node */
112 verify_node_func verify_node; /**< verify the node */
113 verify_proj_node_func verify_proj_node; /**< verify the Proj node */
117 * Frees a newly created ir operation.
119 void free_ir_op(ir_op *code);
121 /** Initialize the irop module. */
124 /** Free memory used by irop module. */
125 void finish_op(void);
128 * Copies simply all attributes stored in the old node to the new node.
129 * Assumes both have the same opcode and sufficient size.
131 void default_copy_attr(const ir_node *old_node, ir_node *new_node);
133 /** Returns the attribute size of nodes of this opcode.
134 @note Use not encouraged, internal feature. */
135 static INLINE int get_op_attr_size (const ir_op *op) {
136 return op->attr_size;
139 /** Returns non-zero if op is one of Start, End, Jmp, Cond, Return, Raise or Bad. */
140 static INLINE int is_cfopcode(const ir_op *op) {
141 return op->flags & irop_flag_cfopcode;
144 /** Returns true if the operation manipulates interprocedural control flow:
145 CallBegin, EndReg, EndExcept */
146 static INLINE int is_ip_cfopcode(const ir_op *op) {
147 return op->flags & irop_flag_ip_cfopcode;
150 /* Returns non-zero if operation is commutative */
151 static INLINE int is_op_commutative(const ir_op *op) {
152 return op->flags & irop_flag_commutative;
155 /* Returns non-zero if operation is fragile */
156 static INLINE int is_op_fragile(const ir_op *op) {
157 return op->flags & irop_flag_fragile;
160 /* Returns non-zero if operation is forking control flow */
161 static INLINE int is_op_forking(const ir_op *op) {
162 return op->flags & irop_flag_forking;
165 /* Returns non-zero if operation is a high-level op */
166 static INLINE int is_op_highlevel(const ir_op *op) {
167 return op->flags & irop_flag_highlevel;
170 static INLINE opcode _get_op_code(const ir_op *op) {
174 static INLINE ident *_get_op_ident(const ir_op *op){
178 static INLINE op_pin_state _get_op_pinned(const ir_op *op) {
179 return op->op_pin_state_pinned;
183 #define get_op_code(op) _get_op_code(op)
184 #define get_op_ident(op) _get_op_ident(op)
185 #define get_op_pinned(op) _get_op_pinned(op)
188 #endif /* _IROP_T_H_ */