076818d148e76af0d46a0ef363335d9100687520
[libfirm] / ir / ir / irop_t.h
1 /*
2  * Copyright (C) 1995-2007 University of Karlsruhe.  All right reserved.
3  *
4  * This file is part of libFirm.
5  *
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.
10  *
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.
14  *
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
17  * PURPOSE.
18  */
19
20 /*
21  * Project:     libFIRM
22  * File name:   ir/ir/irop_t.h
23  * Purpose:     Representation of opcode of intermediate operation -- private header.
24  * Author:      Christian Schaefer
25  * Modified by: Goetz Lindenmaier
26  * Created:
27  * CVS-ID:      $Id$
28  * Copyright:   (c) 1998-2003 Universität Karlsruhe
29  */
30 #ifndef _IROP_T_H_
31 #define _IROP_T_H_
32
33 #include "firm_config.h"
34 #include "irop.h"
35 #include "tv.h"
36 #include "irnode.h"
37
38
39 /** The type of an ir_op. */
40 struct ir_op {
41   ir_opcode code;         /**< The unique opcode of the op. */
42   ident *name;            /**< The name of the op. */
43   size_t attr_size;       /**< Space needed in memory for private attributes. */
44   op_pin_state op_pin_state_pinned; /**< How to deal with the node in CSE, PRE. */
45   op_arity opar;          /**< The arity of operator. */
46   int op_index;           /**< The index of the first data operand, 0 for most cases, 1 for Div etc. */
47   unsigned flags;         /**< Flags describing the behavior of the ir_op, a bitmasks of irop_flags. */
48   void *tag;              /**< Some custom pointer the op's creator can attach stuff to. */
49
50   ir_op_ops ops;          /**< The operations of the this op. */
51 };
52
53 /**
54  * Frees a newly created ir operation.
55  */
56 void free_ir_op(ir_op *code);
57
58 /** Initialize the irop module. */
59 void init_op(void);
60
61 /** Free memory used by irop module. */
62 void finish_op(void);
63
64 /**
65  * Copies simply all attributes stored in the old node to the new node.
66  * Assumes both have the same opcode and sufficient size.
67  *
68  * @param old_node  the old node from which the attributes are read
69  * @param new_node  the new node to which the attributes are written
70  */
71 void default_copy_attr(const ir_node *old_node, ir_node *new_node);
72
73 /**
74  * Returns the attribute size of nodes of this opcode.
75  * @note Use not encouraged, internal feature.
76  */
77 static INLINE size_t get_op_attr_size (const ir_op *op) {
78   return op->attr_size;
79 }
80
81 /**
82  * Returns non-zero if op is a control flow opcode,
83  * like Start, End, Jmp, Cond, Return, Raise or Bad.
84  */
85 static INLINE int is_cfopcode(const ir_op *op) {
86   return op->flags & irop_flag_cfopcode;
87 }
88
89 /**
90  * Returns non-zero if the operation manipulates interprocedural control flow:
91  * CallBegin, EndReg, EndExcept
92  */
93 static INLINE int is_ip_cfopcode(const ir_op *op) {
94   return op->flags & irop_flag_ip_cfopcode;
95 }
96
97 /** Returns non-zero if operation is commutative */
98 static INLINE int is_op_commutative(const ir_op *op) {
99   return op->flags & irop_flag_commutative;
100 }
101
102 /** Returns non-zero if operation is fragile */
103 static INLINE int is_op_fragile(const ir_op *op) {
104   return op->flags & irop_flag_fragile;
105 }
106
107 /** Returns non-zero if operation is forking control flow */
108 static INLINE int is_op_forking(const ir_op *op) {
109   return op->flags & irop_flag_forking;
110 }
111
112 /** Returns non-zero if operation is a high-level op */
113 static INLINE int is_op_highlevel(const ir_op *op) {
114   return op->flags & irop_flag_highlevel;
115 }
116
117 /** Returns non-zero if operation is a const-like op */
118 static INLINE int is_op_constlike(const ir_op *op) {
119   return op->flags & irop_flag_constlike;
120 }
121
122 /** Returns non-zero if operation must always be optimized */
123 static INLINE int is_op_always_opt(const ir_op *op) {
124   return op->flags & irop_flag_always_opt;
125 }
126
127 /** Returns non-zero if operation is a keep-like op */
128 static INLINE int is_op_keep(const ir_op *op) {
129   return op->flags & irop_flag_keep;
130 }
131
132 /** Returns non-zero if operation must always be placed in the start block. */
133 static INLINE int is_op_start_block_placed(const ir_op *op) {
134   return op->flags & irop_flag_start_block;
135 }
136
137 /** Returns non-zero if operation is a machine operation */
138 static INLINE int is_op_machine(const ir_op *op) {
139   return op->flags & irop_flag_machine;
140 }
141
142 /** Returns non-zero if operation is a machine operand */
143 static INLINE int is_op_machine_operand(const ir_op *op) {
144   return op->flags & irop_flag_machine_op;
145 }
146
147 /** Returns non-zero if operation is a machine user op number n */
148 static INLINE int is_op_machine_user(const ir_op *op, unsigned n) {
149   return op->flags & (irop_flag_user << n);
150 }
151
152 static INLINE ir_opcode _get_op_code(const ir_op *op) {
153   return op->code;
154 }
155
156 static INLINE ident *_get_op_ident(const ir_op *op){
157   return op->name;
158 }
159
160 static INLINE op_pin_state _get_op_pinned(const ir_op *op) {
161   return op->op_pin_state_pinned;
162 }
163
164 static INLINE void _set_generic_function_ptr(ir_op *op, op_func func) {
165   op->ops.generic = func;
166 }
167
168 static INLINE op_func _get_generic_function_ptr(const ir_op *op) {
169   return op->ops.generic;
170 }
171
172 static INLINE const ir_op_ops *_get_op_ops(const ir_op *op) {
173   return &op->ops;
174 }
175
176 static INLINE void _set_op_tag(ir_op *op, void *tag) {
177         op->tag = tag;
178 }
179
180 static INLINE void *_get_op_tag(ir_op *op) {
181         return op->tag;
182 }
183
184 #define get_op_code(op)         _get_op_code(op)
185 #define get_op_ident(op)        _get_op_ident(op)
186 #define get_op_pinned(op)       _get_op_pinned(op)
187 #define get_op_ops(op)          _get_op_ops(op)
188 #define set_op_tag(op, tag)     _set_op_tag((op), (tag))
189 #define get_op_tag(op)          _get_op_tag(op)
190
191 #endif /* _IROP_T_H_ */