1 /*
2  * Copyright (C) 1995-2008 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  * @file
22  * @brief    Representation of opcode of intermediate operation -- private header.
23  * @author   Christian Schaefer, Goetz Lindenmaier, Michael Beck
24  */
25 #ifndef FIRM_IR_IROP_T_H
26 #define FIRM_IR_IROP_T_H
27 
28 #include "irop.h"
29 
30 #include <stdbool.h>
31 
32 #include "irtypes.h"
33 #include "tv.h"
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 firm_init_op(void);
42 
43 /** frees memory allocated by irop module */
44 void firm_finish_op(void);
45 
46 /**
47  * Returns the attribute size of nodes of this opcode.
48  * @note Use not encouraged, internal feature.
49  */
get_op_attr_size(const ir_op * op)50 static inline size_t get_op_attr_size (const ir_op *op)
51 {
52 	return op->attr_size;
53 }
54 
55 /**
56  * Returns non-zero if op is a control flow opcode,
57  * like Start, End, Jmp, Cond, Return, Raise or Bad.
58  */
is_op_cfopcode(const ir_op * op)59 static inline bool is_op_cfopcode(const ir_op *op)
60 {
61 	return op->flags & irop_flag_cfopcode;
62 }
63 
is_op_unknown_jump(const ir_op * op)64 static inline bool is_op_unknown_jump(const ir_op *op)
65 {
66 	return op->flags & irop_flag_unknown_jump;
67 }
68 
69 /** Returns non-zero if operation is commutative */
is_op_commutative(const ir_op * op)70 static inline bool is_op_commutative(const ir_op *op)
71 {
72 	return op->flags & irop_flag_commutative;
73 }
74 
75 /** Returns non-zero if operation is fragile */
is_op_fragile(const ir_op * op)76 static inline bool is_op_fragile(const ir_op *op)
77 {
78 	return op->flags & irop_flag_fragile;
79 }
80 
81 /** Returns non-zero if operation is forking control flow */
is_op_forking(const ir_op * op)82 static inline bool is_op_forking(const ir_op *op)
83 {
84 	return op->flags & irop_flag_forking;
85 }
86 
87 /** Returns non-zero if operation is a high-level op */
is_op_highlevel(const ir_op * op)88 static inline bool is_op_highlevel(const ir_op *op)
89 {
90 	return op->flags & irop_flag_highlevel;
91 }
92 
93 /** Returns non-zero if operation is a const-like op */
is_op_constlike(const ir_op * op)94 static inline bool is_op_constlike(const ir_op *op)
95 {
96 	return op->flags & irop_flag_constlike;
97 }
98 
is_op_uses_memory(const ir_op * op)99 static inline bool is_op_uses_memory(const ir_op *op)
100 {
101 	return op->flags & irop_flag_uses_memory;
102 }
103 
104 /** Returns non-zero if operation is a keep-like op */
is_op_keep(const ir_op * op)105 static inline bool is_op_keep(const ir_op *op)
106 {
107 	return op->flags & irop_flag_keep;
108 }
109 
110 /** Returns non-zero if operation must always be placed in the start block. */
is_op_start_block_placed(const ir_op * op)111 static inline bool is_op_start_block_placed(const ir_op *op)
112 {
113 	return op->flags & irop_flag_start_block;
114 }
115 
116 /** Returns non-zero if operation is CSE neutral */
is_op_cse_neutral(const ir_op * op)117 static inline bool is_op_cse_neutral(const ir_op *op)
118 {
119 	return op->flags & irop_flag_cse_neutral;
120 }
121 
get_op_code_(const ir_op * op)122 static inline unsigned get_op_code_(const ir_op *op)
123 {
124 	return op->code;
125 }
126 
get_op_ident_(const ir_op * op)127 static inline ident *get_op_ident_(const ir_op *op)
128 {
129 	return op->name;
130 }
131 
get_op_pinned_(const ir_op * op)132 static inline op_pin_state get_op_pinned_(const ir_op *op)
133 {
134 	return op->pin_state;
135 }
136 
set_generic_function_ptr_(ir_op * op,op_func func)137 static inline void set_generic_function_ptr_(ir_op *op, op_func func)
138 {
139 	op->ops.generic = func;
140 }
141 
get_generic_function_ptr_(const ir_op * op)142 static inline op_func get_generic_function_ptr_(const ir_op *op)
143 {
144 	return op->ops.generic;
145 }
146 
get_op_ops_(ir_op * op)147 static inline ir_op_ops *get_op_ops_(ir_op *op)
148 {
149 	return &op->ops;
150 }
151 
set_op_tag_(ir_op * op,unsigned tag)152 static inline void set_op_tag_(ir_op *op, unsigned tag)
153 {
154 	op->tag = tag;
155 }
156 
get_op_tag_(const ir_op * op)157 static inline unsigned get_op_tag_(const ir_op *op)
158 {
159 	return op->tag;
160 }
161 
set_op_attr_(ir_op * op,void * attr)162 static inline void set_op_attr_(ir_op *op, void *attr)
163 {
164 	op->attr = attr;
165 }
166 
get_op_attr_(const ir_op * op)167 static inline void *get_op_attr_(const ir_op *op)
168 {
169 	return op->attr;
170 }
171 
172 #define get_op_code(op)         get_op_code_(op)
173 #define get_op_ident(op)        get_op_ident_(op)
174 #define get_op_pinned(op)       get_op_pinned_(op)
175 #define get_op_ops(op)          get_op_ops_(op)
176 #define set_op_tag(op, tag)     set_op_tag_((op), (tag))
177 #define get_op_tag(op)          get_op_tag_(op)
178 #define set_op_attr(op, attr)   set_op_attr_((op), (attr))
179 #define get_op_attr(op)         get_op_attr_(op)
180 
181 #endif
182