Added flags to irop determining the behaviour, this saves some switches.
[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
19 /** The allowed parities */
20 typedef enum {
21   oparity_invalid = 0,
22   oparity_unary,              /**< an unary operator -- considering 'numeric' arguments. */
23   oparity_binary,             /**< an binary operator  -- considering 'numeric' arguments.*/
24   oparity_trinary,            /**< an trinary operator  -- considering 'numeric' arguments.*/
25   oparity_zero,               /**< no operators, as e.g. Const. */
26   oparity_variable,           /**< arity not fixed by opcode, but statically
27                                  known.  E.g., number of arguments to call. */
28   oparity_dynamic,            /**< arity depends on state of firm representation.
29                                  Can change by optimizations...
30                                  We must allocate a dynamic in array for the node! */
31   oparity_any,                /**< other arity */
32 } op_arity;
33
34
35 /** The irop flags */
36 typedef enum {
37   irop_flag_labeled     = 0x00000001,   /**< if set, Output edge labels on in-edges in vcg graph */
38   irop_flag_commutative = 0x00000002,   /**< operation is commutative */
39   irop_flag_cfopcode    = 0x00000004,   /**< is a control flow operation */
40   irop_flag_ip_cfopcode = 0x00000008,   /**< operation manipulates interprocedural control flow */
41   irop_flag_fragile     = 0x00000010,   /**< set if the operation can change the control flow because
42                                              of an exception */
43 } irop_flags;
44
45
46 /** the type of an ir_op */
47 struct ir_op {
48   opcode code;            /**< the unique opcode of the op */
49   ident *name;            /**< the name of the op */
50   size_t attr_size;       /**< Space needed in memory for private attributes */
51   op_pinned pinned;       /**< How to deal with the node in cse, pre. */
52   op_arity opar;          /**< arity of operator. */
53   int op_index;           /**< the index of the first data operand, 0 for most cases, 1 for Div etc. */
54   unsigned flags;         /**< flags describing the behavior of the ir_op, a bitmaks of irop_flags */
55 };
56
57 /**
58  * Creates a new ir operation.
59  *
60  * @param code      the opcode, one of type \c opcode
61  * @param name      the printable name of this opcode
62  * @param p         wheater operations of this opcode are pinned or floating
63  * @param flags     a bitmask of irop_flags describing the behavior of the ir operation
64  * @param opar      the parity of this ir operation
65  * @param op_index  if the parity is oparity_unary, oparity_binary or oparity_trinary the index
66  *                  of the left operand
67  * @param attr_size attribute size for this ir operation
68  *
69  * @return The genenerated ir operation.
70  */
71 ir_op * new_ir_op(opcode code, const char *name, op_pinned p,
72                    unsigned flags, op_arity opar, int op_index, size_t attr_size);
73
74 /**
75  * Frees a newly created ir operation.
76  */
77 void free_ir_op(ir_op *code);
78
79 /** Initialize the irop module. */
80 void init_op(void);
81
82 /** Free memory used by irop module. */
83 void finish_op(void);
84
85 /** Returns the attribute size of nodes of this opcode.
86    @note Use not encouraged, internal feature. */
87 static INLINE int get_op_attr_size (const ir_op *op) {
88   return op->attr_size;
89 }
90
91 /** Returns non-zero if op is one of Start, End, Jmp, Cond, Return, Raise or Bad. */
92 static INLINE int is_cfopcode(const ir_op *op) {
93   return op->flags & irop_flag_cfopcode;
94 }
95
96 /** Returns true if the operation manipulates interprocedural control flow:
97    CallBegin, EndReg, EndExcept */
98 static INLINE int is_ip_cfopcode(const ir_op *op) {
99   return op->flags & irop_flag_ip_cfopcode;
100 }
101
102 /* Returns non-zero if operation is commutative */
103 static INLINE int is_op_commutative(const ir_op *op) {
104   return op->flags & irop_flag_commutative;
105 }
106
107 /* Returns non-zero if operation is fragile */
108 static INLINE int is_op_fragile(const ir_op *op) {
109   return op->flags & irop_flag_fragile;
110 }
111
112 #endif /* _IROP_T_H_ */