irprog_t.h 6.52 KB
Newer Older
Christian Würdig's avatar
Christian Würdig committed
1
2
/*
 * This file is part of libFirm.
3
 * Copyright (C) 2012 University of Karlsruhe.
Christian Würdig's avatar
Christian Würdig committed
4
5
 */

Michael Beck's avatar
Michael Beck committed
6
/**
Matthias Braun's avatar
Matthias Braun committed
7
8
9
10
 * @file
 * @brief    Entry point to the representation of a whole program 0-- private header.
 * @author   Goetz Lindenmaier
 * @date     2000
Michael Beck's avatar
Michael Beck committed
11
 */
Matthias Braun's avatar
Matthias Braun committed
12
13
#ifndef FIRM_IR_IRPROG_T_H
#define FIRM_IR_IRPROG_T_H
Götz Lindenmaier's avatar
Götz Lindenmaier committed
14
15

#include "irprog.h"
Götz Lindenmaier's avatar
Götz Lindenmaier committed
16

17
#include "array.h"
18
19
20
21
#include "callgraph.h"
#include "irmemory.h"
#include "pmap.h"
#include "typerep.h"
22

23
/* Inline functions. */
24
25
26
27
28
29
30
31
32
33
34
35
#define get_irp_n_irgs()                      get_irp_n_irgs_()
#define get_irp_irg(pos)                      get_irp_irg_(pos)
#define get_irp_n_types()                     get_irp_n_types_()
#define get_irp_type(pos)                     get_irp_type_(pos)
#define get_const_code_irg()                  get_const_code_irg_()
#define get_segment_type(s)                   get_segment_type_(s)
#define get_glob_type()                       get_glob_type_()
#define get_tls_type()                        get_tls_type_()
#define get_irp_next_label_nr()               get_irp_next_label_nr_()
#define irp_reserve_resources(irp, resources) irp_reserve_resources_(irp, resources)
#define irp_free_resources(irp, resources)    irp_free_resources_(irp, resources)
#define irp_resources_reserved(irp)           irp_resources_reserved_(irp)
36

37
38
39
40
41
42
43
44
45
/**
 * Data structure that holds central information about a program / module /
 * translation unit.
 */
struct ir_prog {
	ident     *name;                /**< A file name or the like. */
	ir_graph  *main_irg;            /**< The entry point to the compiled program
	                                     or NULL if no point exists. */
	ir_graph **graphs;              /**< A list of all graphs in the ir. */
Matthias Braun's avatar
Matthias Braun committed
46
	pmap      *globals;             /**< Map identifiers to global entities. */
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
	/** This graph holds nodes for global entity initialization expressions.
	 * It is not a function. */
	ir_graph  *const_code_irg;
	ir_entity *unknown_entity;      /**< unique 'unknown'-entity */
	ir_type   *segment_types[IR_SEGMENT_LAST+1];
	ir_type  **types;               /**< A list of all types in the ir. */
	ir_type   *code_type;           /**< unique 'code'-type */
	ir_type   *unknown_type;        /**< unique 'unknown'-type */
	ir_type   *dummy_owner;         /**< owner for internal entities */
	ir_type   *byte_type;           /**< type for a 'byte' */
	ident    **global_asms;         /**< An array of global ASM insertions. */

	/** Validity of callee information. Lowest value for all irgs. */
	irg_callee_info_state          callee_info_state;
	/** State of transitive closure of inheritance relations. */
	inh_transitive_closure_state   inh_trans_closure_state;
	irp_callgraph_state            callgraph_state; /**< State of callgraph. */
	/** Outermost callgraph loop */
	ir_loop                       *outermost_cg_loop;
	/** State of loop nesting depth information. */
	loop_nesting_depth_state       lnd_state;
	ir_entity_usage_computed_state globals_entity_usage_state;

	ir_label_t last_label_nr;        /**< Highest number for unique labels. */
	size_t     max_irg_idx;          /**< highest unused irg index */
	long       max_node_nr;          /**< Highest number unique node numbers. */
	unsigned   dump_nr;              /**< number of program info dumps */
#ifndef NDEBUG
	/** Bitset for tracking used global resources. */
	irp_resources_t reserved_resources;
#endif
};

80
static inline ir_type *get_segment_type_(ir_segment_t segment)
81
{
82
83
	assert(segment <= IR_SEGMENT_LAST);
	return irp->segment_types[segment];
84
85
}

86
static inline ir_type *get_glob_type_(void)
87
{
88
	return get_segment_type_(IR_SEGMENT_GLOBAL);
89
90
}

91
static inline ir_type *get_tls_type_(void)
92
{
93
	return get_segment_type_(IR_SEGMENT_THREAD_LOCAL);
94
95
}

96
static inline size_t get_irp_n_irgs_(void)
97
{
Matthias Braun's avatar
Matthias Braun committed
98
	return ARR_LEN(irp->graphs);
99
100
}

101
static inline ir_graph *get_irp_irg_(size_t pos)
102
{
Matthias Braun's avatar
Matthias Braun committed
103
	assert(pos < ARR_LEN(irp->graphs));
104
	return irp->graphs[pos];
105
106
}

107
static inline size_t get_irp_n_types_(void)
108
{
Matthias Braun's avatar
Matthias Braun committed
109
	return ARR_LEN(irp->types);
110
111
}

112
static inline ir_type *get_irp_type_(size_t pos)
113
{
Matthias Braun's avatar
Matthias Braun committed
114
	assert(pos < ARR_LEN(irp->types));
115
	/* Don't set the skip_tid result so that no double entries are generated. */
Matthias Braun's avatar
Matthias Braun committed
116
	return irp->types[pos];
117
118
}

Michael Beck's avatar
Michael Beck committed
119
/** Returns a new, unique number to number nodes or the like. */
120
121
static inline long get_irp_new_node_nr(void)
{
122
	return irp->max_node_nr++;
123
}
124

125
static inline size_t get_irp_new_irg_idx(void)
126
{
Matthias Braun's avatar
Matthias Braun committed
127
128
129
	return irp->max_irg_idx++;
}

130
static inline ir_graph *get_const_code_irg_(void)
131
{
132
133
134
	return irp->const_code_irg;
}

Michael Beck's avatar
Michael Beck committed
135
/** Returns a new, unique label number. */
136
static inline ir_label_t get_irp_next_label_nr_(void)
137
{
Michael Beck's avatar
Michael Beck committed
138
139
140
	return ++irp->last_label_nr;
}

141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#ifndef NDEBUG
static inline void irp_reserve_resources(ir_prog *irp,
                                         irp_resources_t resources)
{
	assert((irp->reserved_resources & resources) == 0);
	irp->reserved_resources |= resources;
}

static inline void irp_free_resources(ir_prog *irp, irp_resources_t resources)
{
	assert((irp->reserved_resources & resources) == resources);
	irp->reserved_resources &= ~resources;
}

static inline irp_resources_t irp_resources_reserved(const ir_prog *irp)
{
	return irp->reserved_resources;
}
#else
static inline void irp_reserve_resources(ir_prog *irp,
                                         irp_resources_t resources)
{
	(void)irp;
	(void)resources;
}

static inline void irp_free_resources(ir_prog *irp, irp_resources_t resources)
{
	(void)irp;
	(void)resources;
}

static inline irp_resources_t irp_resources_reserved(const ir_prog *irp)
{
	(void)irp;
	return IRP_RESOURCE_NONE;
}
#endif

180
181
182
183
184
/** initializes ir_prog. Constructs only the basic lists */
void init_irprog_1(void);

/** Completes ir_prog. */
void init_irprog_2(void);
185

Matthias Braun's avatar
Matthias Braun committed
186
/** Adds type to the list of types in irp. */
Matthias Braun's avatar
Matthias Braun committed
187
void add_irp_type(ir_type *typ);
Matthias Braun's avatar
Matthias Braun committed
188
189
190

/** Removes type from the list of types, deallocates it and
    shrinks the list by one. */
Matthias Braun's avatar
Matthias Braun committed
191
void remove_irp_type(ir_type *typ);
Matthias Braun's avatar
Matthias Braun committed
192

193
194
195
196
197
198
199
/** Adds irg to the list of ir graphs in the current irp. */
FIRM_API void add_irp_irg(ir_graph *irg);

/** Removes irg from the list of irgs and
    shrinks the list by one. */
FIRM_API void remove_irp_irg(ir_graph *irg);

200
201
202
203
204
205
206
207
208
209
210
#define foreach_irp_irg(idx, irg) \
	for (bool irg##__b = true; irg##__b; irg##__b = false) \
		for (size_t idx = 0, irg##__n = get_irp_n_irgs(); irg##__b && idx != irg##__n; ++idx) \
			for (ir_graph *const irg = (irg##__b = false, get_irp_irg(idx)); !irg##__b; irg##__b = true)

#define foreach_irp_irg_r(idx, irg) \
	for (bool irg##__b = true; irg##__b;) \
		for (; irg##__b; irg##__b = false) \
			for (size_t idx = get_irp_n_irgs(); irg##__b && idx-- != 0;) \
				for (ir_graph *const irg = (irg##__b = false, get_irp_irg(idx)); !irg##__b; irg##__b = true)

Matthias Braun's avatar
Matthias Braun committed
211
#endif