Moved new_ir_op from irop_t.h to irop.h since backends might need it
[libfirm] / ir / ir / irop_t.h
1 /*
2  * Project:     libFIRM
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
7  * Created:
8  * CVS-ID:      $Id$
9  * Copyright:   (c) 1998-2003 Universität Karlsruhe
10  * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
11  */
12 #ifndef _IROP_T_H_
13 #define _IROP_T_H_
14
15 #include "firm_config.h"
16 #include "irop.h"
17 #include "tv.h"
18 #include "irnode.h"
19
20
21 /**
22  * The compute value operation.
23  * This operation evaluates an IR node into a tarval if possible,
24  * returning tarval_bad otherwise.
25  */
26 typedef tarval *(*computed_value_func)(ir_node *self);
27
28 /**
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).
35  */
36 typedef ir_node *(*equivalent_node_func)(ir_node *self);
37
38 /**
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.
45  */
46 typedef ir_node *(*transform_node_func)(ir_node *self);
47
48 /**
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.
52  */
53 typedef int (*node_cmp_attr_func)(ir_node *a, ir_node *b);
54
55 /**
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
60  * was applied.
61  */
62 typedef int (*reassociate_func)(ir_node **n);
63
64 /**
65  * The copy attribute operation.
66  * Copy the node attributes from a 'old' node to a 'new' one.
67  */
68 typedef void (*copy_attr_func)(const ir_node *old_node, ir_node *new_node);
69
70 /**
71  * The get_type operation.
72  * Return the type of the node self.
73  */
74 typedef type *(*get_type_func)(ir_node *self);
75
76 /**
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.
80  *
81  * @see do_node_verification()
82  */
83 typedef int (*verify_node_func)(ir_node *self, ir_graph *irg);
84
85 /**
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.
89  *
90  * @see do_node_verification()
91  */
92 typedef int (*verify_proj_node_func)(ir_node *self, ir_node *proj);
93
94 /** The type of an ir_op. */
95 struct 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 */
103
104   /* CallBacks */
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 */
114 };
115
116 /**
117  * Frees a newly created ir operation.
118  */
119 void free_ir_op(ir_op *code);
120
121 /** Initialize the irop module. */
122 void init_op(void);
123
124 /** Free memory used by irop module. */
125 void finish_op(void);
126
127 /**
128  * Copies simply all attributes stored in the old node to the new node.
129  * Assumes both have the same opcode and sufficient size.
130  */
131 void default_copy_attr(const ir_node *old_node, ir_node *new_node);
132
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;
137 }
138
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;
142 }
143
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;
148 }
149
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;
153 }
154
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;
158 }
159
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;
163 }
164
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;
168 }
169
170 static INLINE opcode _get_op_code(const ir_op *op) {
171   return op->code;
172 }
173
174 static INLINE ident *_get_op_ident(const ir_op *op){
175   return op->name;
176 }
177
178 static INLINE op_pin_state _get_op_pinned(const ir_op *op) {
179   return op->op_pin_state_pinned;
180 }
181
182
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)
186
187
188 #endif /* _IROP_T_H_ */