irop_flag_highlevel flag added to Confirm and Cast
[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
13
14 # ifndef _IROP_T_H_
15 # define _IROP_T_H_
16
17 # include "irop.h"
18 # include "tv.h"
19 # include "irnode.h"
20
21 /** The allowed parities */
22 typedef enum {
23   oparity_invalid = 0,
24   oparity_unary,              /**< an unary operator -- considering 'numeric' arguments. */
25   oparity_binary,             /**< an binary operator  -- considering 'numeric' arguments.*/
26   oparity_trinary,            /**< an trinary operator  -- considering 'numeric' arguments.*/
27   oparity_zero,               /**< no operators, as e.g. Const. */
28   oparity_variable,           /**< arity not fixed by opcode, but statically
29                                  known.  E.g., number of arguments to call. */
30   oparity_dynamic,            /**< arity depends on state of firm representation.
31                                  Can change by optimizations...
32                                  We must allocate a dynamic in array for the node! */
33   oparity_any,                /**< other arity */
34 } op_arity;
35
36
37 /** The irop flags */
38 typedef enum {
39   irop_flag_none        = 0x00000000, /**< nothing */
40   irop_flag_labeled     = 0x00000001,   /**< if set, Output edge labels on in-edges in vcg graph */
41   irop_flag_commutative = 0x00000002,   /**< operation is commutative */
42   irop_flag_cfopcode    = 0x00000004, /**< is a control flow operation */
43   irop_flag_ip_cfopcode = 0x00000008,   /**< operation manipulates interprocedural control flow */
44   irop_flag_fragile     = 0x00000010,   /**< set if the operation can change the control flow because
45                                              of an exception */
46   irop_flag_forking     = 0x00000020, /**< the operation is a forking control flow */
47   irop_flag_highlevel   = 0x00000040, /**< the operation is a pure high-level one and can be
48                                            skipped in low-level optimizations */
49 } irop_flags;
50
51
52 /**
53  * The compute value operation.
54  * This operation evaluates an IR node into a tarval if possible,
55  * returning tarval_bad otherwise.
56  */
57 typedef tarval *(*computed_value_func)(ir_node *self);
58
59 /**
60  * The equivalent node operation.
61  * This operation returns an equivalent node for the input node.
62  * It does not create new nodes.  It is therefore safe to free self
63  * if the node returned is not self.
64  * If a node returns a Tuple we can not just skip it.  If the size of the
65  * in array fits, we transform n into a tuple (e.g., possible for Div).
66  */
67 typedef ir_node *(*equivalent_node_func)(ir_node *self);
68
69 /**
70  * The transform node operation.
71  * This operation tries several [inplace] [optimizing] transformations
72  * and returns an equivalent node.
73  * The difference to equivalent_node() is that these
74  * transformations _do_ generate new nodes, and thus the old node must
75  * not be freed even if the equivalent node isn't the old one.
76  */
77 typedef ir_node *(*transform_node_func)(ir_node *self);
78
79 /**
80  * The node attribute compare operation.
81  * Compares the nodes attributes of two nodes of identical opcode
82  * and returns 0 if the attributes are identical, 1 if they differ.
83  */
84 typedef int (*node_cmp_attr_func)(ir_node *a, ir_node *b);
85
86 /**
87  * The reassociation operation.
88  * Called from a walker.  Returns non-zero if
89  * a reassociation rule was applied.
90  * The pointer n is set to the newly created node, if some reassociation
91  * was applied.
92  */
93 typedef int (*reassociate_func)(ir_node **n);
94
95 /**
96  * The copy attribute operation.
97  * Copy the node attributes from a 'old' node to a 'new' one.
98  */
99 typedef void (*copy_attr_func)(const ir_node *old_node, ir_node *new_node);
100
101 /**
102  * The get_type operation.
103  * Return the type of the node self.
104  */
105 typedef type *(*get_type_func)(ir_node *self);
106
107 /**
108  * The verify_node operation.
109  * Return non-zero if the node verification is ok, else 0.
110  * Depending on the node verification settings, may even assert.
111  *
112  * @see do_node_verification()
113  */
114 typedef int (*verify_node_func)(ir_node *self, ir_graph *irg);
115
116 /**
117  * The verify_node operation for Proj(X).
118  * Return non-zero if the node verification is ok, else 0.
119  * Depending on the node verification settings, may even assert.
120  *
121  * @see do_node_verification()
122  */
123 typedef int (*verify_proj_node_func)(ir_node *self, ir_node *proj);
124
125 /** The type of an ir_op. */
126 struct ir_op {
127   opcode code;            /**< the unique opcode of the op */
128   ident *name;            /**< the name of the op */
129   size_t attr_size;       /**< Space needed in memory for private attributes */
130   op_pin_state op_pin_state_pinned; /**< How to deal with the node in cse, pre. */
131   op_arity opar;          /**< arity of operator. */
132   int op_index;           /**< the index of the first data operand, 0 for most cases, 1 for Div etc. */
133   unsigned flags;         /**< flags describing the behavior of the ir_op, a bitmaks of irop_flags */
134
135   /* CallBacks */
136   computed_value_func     computed_value;               /**< evaluates a node into a tarval if possible. */
137   equivalent_node_func  equivalent_node;        /**< optimizes the node by returning an equivalent one. */
138   transform_node_func   transform_node;         /**< optimizes the node by transforming it. */
139   node_cmp_attr_func    node_cmp_attr;          /**< compares two node attributes. */
140   reassociate_func      reassociate;            /**< reassociate a tree */
141   copy_attr_func        copy_attr;              /**< copy node attributes */
142   get_type_func         get_type;               /**< return the type of a node */
143   verify_node_func      verify_node;            /**< verify the node */
144   verify_proj_node_func verify_proj_node;       /**< verify the Proj node */
145 };
146
147 /**
148  * Creates a new ir operation.
149  *
150  * @param code      the opcode, one of type \c opcode
151  * @param name      the printable name of this opcode
152  * @param p         whether operations of this opcode are op_pin_state_pinned or floating
153  * @param flags     a bitmask of irop_flags describing the behavior of the ir operation
154  * @param opar      the parity of this ir operation
155  * @param op_index  if the parity is oparity_unary, oparity_binary or oparity_trinary the index
156  *                  of the left operand
157  * @param attr_size attribute size for this ir operation
158  *
159  * @return The generated ir operation.
160  */
161 ir_op * new_ir_op(opcode code, const char *name, op_pin_state p,
162                    unsigned flags, op_arity opar, int op_index, size_t attr_size);
163
164 /**
165  * Frees a newly created ir operation.
166  */
167 void free_ir_op(ir_op *code);
168
169 /** Initialize the irop module. */
170 void init_op(void);
171
172 /** Free memory used by irop module. */
173 void finish_op(void);
174
175 /**
176  * Copies simply all attributes stored in the old node to the new node.
177  * Assumes both have the same opcode and sufficient size.
178  */
179 void default_copy_attr(const ir_node *old_node, ir_node *new_node);
180
181 /** Returns the attribute size of nodes of this opcode.
182    @note Use not encouraged, internal feature. */
183 static INLINE int get_op_attr_size (const ir_op *op) {
184   return op->attr_size;
185 }
186
187 /** Returns non-zero if op is one of Start, End, Jmp, Cond, Return, Raise or Bad. */
188 static INLINE int is_cfopcode(const ir_op *op) {
189   return op->flags & irop_flag_cfopcode;
190 }
191
192 /** Returns true if the operation manipulates interprocedural control flow:
193    CallBegin, EndReg, EndExcept */
194 static INLINE int is_ip_cfopcode(const ir_op *op) {
195   return op->flags & irop_flag_ip_cfopcode;
196 }
197
198 /* Returns non-zero if operation is commutative */
199 static INLINE int is_op_commutative(const ir_op *op) {
200   return op->flags & irop_flag_commutative;
201 }
202
203 /* Returns non-zero if operation is fragile */
204 static INLINE int is_op_fragile(const ir_op *op) {
205   return op->flags & irop_flag_fragile;
206 }
207
208 /* Returns non-zero if operation is forking control flow */
209 static INLINE int is_op_forking(const ir_op *op) {
210   return op->flags & irop_flag_forking;
211 }
212
213 /* Returns non-zero if operation is a high-level op */
214 static INLINE int is_op_highlevel(const ir_op *op) {
215   return op->flags & irop_flag_highlevel;
216 }
217
218 static INLINE opcode __get_op_code(const ir_op *op) {
219   return op->code;
220 }
221
222 static INLINE ident *__get_op_ident(const ir_op *op){
223   return op->name;
224 }
225
226 static INLINE op_pin_state __get_op_pinned(const ir_op *op) {
227   return op->op_pin_state_pinned;
228 }
229
230
231 #define get_op_code(op)         __get_op_code(op)
232 #define get_op_ident(op)        __get_op_ident(op)
233 #define get_op_pinned(op)       __get_op_pinned(op)
234
235
236 #endif /* _IROP_T_H_ */