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