more ir_op operations to public interface
[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;          /**< 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 bitmaks of irop_flags */
30
31   ir_op_ops ops;          /**< the operations of the this op. */
32 };
33
34 /**
35  * Frees a newly created ir operation.
36  */
37 void free_ir_op(ir_op *code);
38
39 /** Initialize the irop module. */
40 void init_op(void);
41
42 /** Free memory used by irop module. */
43 void finish_op(void);
44
45 /**
46  * Copies simply all attributes stored in the old node to the new node.
47  * Assumes both have the same opcode and sufficient size.
48  *
49  * @param old_node  the old node from which the attributes are read
50  * @param new_node  the new node to which the attributes are written
51  */
52 void default_copy_attr(const ir_node *old_node, ir_node *new_node);
53
54 /**
55  * Returns the attribute size of nodes of this opcode.
56  * @note Use not encouraged, internal feature.
57  */
58 static INLINE int get_op_attr_size (const ir_op *op) {
59   return op->attr_size;
60 }
61
62 /**
63  * Returns non-zero if op is a control flow opcode,
64  * like Start, End, Jmp, Cond, Return, Raise or Bad.
65  */
66 static INLINE int is_cfopcode(const ir_op *op) {
67   return op->flags & irop_flag_cfopcode;
68 }
69
70 /**
71  * Returns non-zero if the operation manipulates interprocedural control flow:
72  * CallBegin, EndReg, EndExcept
73  */
74 static INLINE int is_ip_cfopcode(const ir_op *op) {
75   return op->flags & irop_flag_ip_cfopcode;
76 }
77
78 /** Returns non-zero if operation is commutative */
79 static INLINE int is_op_commutative(const ir_op *op) {
80   return op->flags & irop_flag_commutative;
81 }
82
83 /** Returns non-zero if operation is fragile */
84 static INLINE int is_op_fragile(const ir_op *op) {
85   return op->flags & irop_flag_fragile;
86 }
87
88 /** Returns non-zero if operation is forking control flow */
89 static INLINE int is_op_forking(const ir_op *op) {
90   return op->flags & irop_flag_forking;
91 }
92
93 /** Returns non-zero if operation is a high-level op */
94 static INLINE int is_op_highlevel(const ir_op *op) {
95   return op->flags & irop_flag_highlevel;
96 }
97
98 /** Returns non-zero if operation is a const-like op */
99 static INLINE int is_op_constlike(const ir_op *op) {
100   return op->flags & irop_flag_constlike;
101 }
102
103 static INLINE opcode _get_op_code(const ir_op *op) {
104   return op->code;
105 }
106
107 static INLINE ident *_get_op_ident(const ir_op *op){
108   return op->name;
109 }
110
111 static INLINE op_pin_state _get_op_pinned(const ir_op *op) {
112   return op->op_pin_state_pinned;
113 }
114
115 static INLINE void _set_generic_function_ptr(ir_op *op, op_func func) {
116   op->ops.generic = func;
117 }
118
119 static INLINE op_func _get_generic_function_ptr(const ir_op *op) {
120   return op->ops.generic;
121 }
122
123 #define get_op_code(op)         _get_op_code(op)
124 #define get_op_ident(op)        _get_op_ident(op)
125 #define get_op_pinned(op)       _get_op_pinned(op)
126
127
128 #endif /* _IROP_T_H_ */