iropt: cmp(~x & 1, 0) => !cmp(x & 1, 0)
[libfirm] / ir / ir / irprog_t.h
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    Entry point to the representation of a whole program 0-- private header.
23  * @author   Goetz Lindenmaier
24  * @date     2000
25  * @version  $Id$
26  */
27 #ifndef FIRM_IR_IRPROG_T_H
28 #define FIRM_IR_IRPROG_T_H
29
30 #include "irprog.h"
31 #include "irtypes.h"
32 #include "irtypeinfo.h"
33 #include "irmemory.h"
34
35 #include "callgraph.h"
36
37 #include "array.h"
38
39 /** Adds mode to the list of modes in irp. */
40 void add_irp_mode(ir_mode *mode);
41
42 /* inline functions */
43 static inline ir_type *get_segment_type_(ir_segment_t segment)
44 {
45         assert(segment <= IR_SEGMENT_LAST);
46         return irp->segment_types[segment];
47 }
48
49 static inline ir_type *get_glob_type_(void)
50 {
51         return get_segment_type_(IR_SEGMENT_GLOBAL);
52 }
53
54 static inline ir_type *get_tls_type_(void)
55 {
56         return get_segment_type_(IR_SEGMENT_THREAD_LOCAL);
57 }
58
59 static inline size_t get_irp_n_irgs_(void)
60 {
61         assert(irp && irp->graphs);
62         return ARR_LEN(irp->graphs);
63 }
64
65 static inline ir_graph *get_irp_irg_(size_t pos)
66 {
67         assert(pos < ARR_LEN(irp->graphs));
68         return irp->graphs[pos];
69 }
70
71 static inline size_t get_irp_n_types_(void)
72 {
73         assert(irp && irp->types);
74         return ARR_LEN(irp->types);
75 }
76
77 static inline ir_type *get_irp_type_(size_t pos)
78 {
79         assert(irp->types);
80         assert(pos < ARR_LEN(irp->types));
81         /* Don't set the skip_tid result so that no double entries are generated. */
82         return irp->types[pos];
83 }
84
85 static inline size_t get_irp_n_modes_(void)
86 {
87         assert(irp->modes);
88         return ARR_LEN(irp->modes);
89 }
90
91 static inline ir_mode *get_irp_mode_(size_t pos)
92 {
93         assert(irp && irp->modes);
94         return irp->modes[pos];
95 }
96
97 static inline size_t get_irp_n_opcodes_(void)
98 {
99         assert(irp && irp->opcodes);
100         return ARR_LEN(irp->opcodes);
101 }
102
103 static inline ir_op *get_irp_opcode_(size_t pos)
104 {
105         assert(irp && irp->opcodes);
106         return irp->opcodes[pos];
107 }
108
109 /** Returns a new, unique number to number nodes or the like. */
110 static inline long get_irp_new_node_nr(void)
111 {
112         assert(irp);
113         return irp->max_node_nr++;
114 }
115
116 static inline size_t get_irp_new_irg_idx(void)
117 {
118         assert(irp);
119         return irp->max_irg_idx++;
120 }
121
122 static inline ir_graph *get_const_code_irg_(void)
123 {
124         return irp->const_code_irg;
125 }
126
127 /** Returns a new, unique exception region number. */
128 static inline ir_exc_region_t get_irp_next_region_nr_(void)
129 {
130         assert(irp);
131         return ++irp->last_region_nr;
132 }
133
134 /** Returns a new, unique label number. */
135 static inline ir_label_t get_irp_next_label_nr_(void)
136 {
137         assert(irp);
138         return ++irp->last_label_nr;
139 }
140
141 /** Whether optimizations should dump irgs */
142 static inline int get_irp_optimization_dumps_(void)
143 {
144         assert(irp);
145         return irp->optimization_dumps;
146 }
147
148 /** Set optimizations to dump irgs */
149 static inline void enable_irp_optimization_dumps_(void)
150 {
151         assert(irp);
152         irp->optimization_dumps = 1;
153 }
154
155 void      set_irp_ip_outedges(ir_node ** ip_outedges);
156 ir_node** get_irp_ip_outedges(void);
157
158 /** initializes ir_prog. Constructs only the basic lists */
159 void init_irprog_1(void);
160
161 /** Completes ir_prog. */
162 void init_irprog_2(void);
163
164 /* Inline functions. */
165 #define get_irp_n_irgs()                 get_irp_n_irgs_()
166 #define get_irp_irg(pos)                 get_irp_irg_(pos)
167 #define get_irp_n_types()                get_irp_n_types_()
168 #define get_irp_type(pos)                get_irp_type_(pos)
169 #define get_irp_n_modes()                get_irp_n_modes_()
170 #define get_irp_mode(pos)                get_irp_mode_(pos)
171 #define get_irp_n_opcodes()              get_irp_n_opcodes_()
172 #define get_irp_opcode(pos)              get_irp_opcode_(pos)
173 #define get_const_code_irg()             get_const_code_irg_()
174 #define get_segment_type(s)              get_segment_type_(s)
175 #define get_glob_type()                  get_glob_type_()
176 #define get_tls_type()                   get_tls_type_()
177 #define get_irp_next_region_nr()         get_irp_next_region_nr_()
178 #define get_irp_next_label_nr()          get_irp_next_label_nr_()
179 #define get_irp_optimization_dumps()     get_irp_optimization_dumps_()
180 #define enable_irp_optimization_dumps()  enable_irp_optimization_dumps_()
181
182 #endif