irgraph.h 20.2 KB
Newer Older
Christian Würdig's avatar
Christian Würdig committed
1
/*
Michael Beck's avatar
Michael Beck committed
2
 * Copyright (C) 1995-2008 University of Karlsruhe.  All right reserved.
Christian Würdig's avatar
Christian Würdig committed
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
 *
 * This file is part of libFirm.
 *
 * This file may be distributed and/or modified under the terms of the
 * GNU General Public License version 2 as published by the Free Software
 * Foundation and appearing in the file LICENSE.GPL included in the
 * packaging of this file.
 *
 * Licensees holding valid libFirm Professional Edition licenses may use
 * this file in accordance with the libFirm Commercial License.
 * Agreement provided with the Software.
 *
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE.
 */

Michael Beck's avatar
Michael Beck committed
20
/**
Matthias Braun's avatar
Matthias Braun committed
21
22
23
 * @file
 * @brief    Entry point to the representation of procedure code.
 * @author   Martin Trapp, Christian Schaefer, Goetz Lindenmaier
Michael Beck's avatar
Michael Beck committed
24
 */
Matthias Braun's avatar
Matthias Braun committed
25
26
#ifndef FIRM_IR_IRGRAPH_H
#define FIRM_IR_IRGRAPH_H
Michael Beck's avatar
Michael Beck committed
27

28
#include <stddef.h>
Boris Boesler's avatar
Boris Boesler committed
29

Michael Beck's avatar
Michael Beck committed
30
#include "firm_types.h"
31
#include "begin.h"
32

Sebastian Felis's avatar
Sebastian Felis committed
33
/**
Matthias Braun's avatar
Matthias Braun committed
34
 * @defgroup ir_graph  Procedure Graph
Götz Lindenmaier's avatar
Götz Lindenmaier committed
35
 *
Michael Beck's avatar
Michael Beck committed
36
37
 * This struct contains all information about a procedure.
 * It's allocated directly to memory.
Götz Lindenmaier's avatar
Götz Lindenmaier committed
38
 *
Michael Beck's avatar
Michael Beck committed
39
 * The fields of ir_graph:
Götz Lindenmaier's avatar
Götz Lindenmaier committed
40
 *
Michael Beck's avatar
Michael Beck committed
41
 * - ent             The entity describing this procedure.
Götz Lindenmaier's avatar
Götz Lindenmaier committed
42
 *
Michael Beck's avatar
Michael Beck committed
43
 * The beginning and end of a graph:
Götz Lindenmaier's avatar
Götz Lindenmaier committed
44
 *
Michael Beck's avatar
Michael Beck committed
45
46
47
48
49
 * - start_block     This ir_node is the block that contains the unique
 *                   start node of the procedure.  With it it contains
 *                   the Proj's on starts results.
 *                   Further all Const nodes are placed in the start block.
 * - start           This ir_node is the unique start node of the procedure.
Götz Lindenmaier's avatar
Götz Lindenmaier committed
50
 *
Michael Beck's avatar
Michael Beck committed
51
52
53
54
 * - end_block       This ir_node is the block that contains the unique
 *                   end node of the procedure.  This block contains no
 *                   further nodes.
 * - end             This ir_node is the unique end node of the procedure.
Götz Lindenmaier's avatar
Götz Lindenmaier committed
55
 *
Michael Beck's avatar
Michael Beck committed
56
57
 * The following nodes are Projs from the Start node, held in ir_graph for
 * simple access:
Götz Lindenmaier's avatar
Götz Lindenmaier committed
58
 *
Michael Beck's avatar
Michael Beck committed
59
60
61
62
63
64
65
66
 * - frame           The ir_node producing the pointer to the stack frame of
 *                   the procedure as output.  This is the Proj node on the
 *                   third output of the start node.  This output of the start
 *                   node is tagged as pns_frame_base.  In FIRM most local
 *                   variables are modeled as data flow edges.  Static
 *                   allocated arrays can not be represented as data flow
 *                   edges. Therefore FIRM has to represent them in the stack
 *                   frame.
Götz Lindenmaier's avatar
Götz Lindenmaier committed
67
 *
Michael Beck's avatar
Michael Beck committed
68
69
70
71
 * - globals         This models a pointer to a space in the memory where
 *                   _all_ global things are held.  Select from this pointer
 *                   with a Sel node the pointer to a global variable /
 *                   procedure / compiler known function... .
Michael Beck's avatar
Michael Beck committed
72
 *
Michael Beck's avatar
Michael Beck committed
73
74
75
 * - tls             This models a pointer to a space in the memory where
 *                   thread local things are held.  Select from this pointer
 *                   with a Sel node the pointer to a thread local variable.
Michael Beck's avatar
Michael Beck committed
76
 *
Michael Beck's avatar
Michael Beck committed
77
 * - args            The ir_node that produces the arguments of the method as
78
 *                   its result.  This is a Proj node on the fourth output of
Michael Beck's avatar
Michael Beck committed
79
 *                   the start node.  This output is tagged as pn_Start_T_args.
80
 *
Michael Beck's avatar
Michael Beck committed
81
 * - proj_args       The proj nodes of the args node.
82
 *
Michael Beck's avatar
Michael Beck committed
83
84
 * - no_mem          The NoMem node is an auxiliary node. It is needed only once,
 *                   so there is this globally reachable node.
Michael Beck's avatar
Michael Beck committed
85
 *
Michael Beck's avatar
Michael Beck committed
86
 * Data structures that are private to a graph:
Michael Beck's avatar
Michael Beck committed
87
 *
Michael Beck's avatar
Michael Beck committed
88
 * - obst            An obstack that contains all nodes.
Michael Beck's avatar
Michael Beck committed
89
 *
Michael Beck's avatar
Michael Beck committed
90
91
92
93
 * - current_block   A pointer to the current block.  Any node created with
 *                   one of the node constructors (new_<opcode>) are assigned
 *                   to this block.  It can be set with set_cur_block(block).
 *                   Only needed for ir construction.
Michael Beck's avatar
Michael Beck committed
94
 *
Michael Beck's avatar
Michael Beck committed
95
96
97
 * - params/n_loc    An int giving the number of local variables in this
 *                  procedure.  This is needed for ir construction. Name will
 *                   be changed.
Michael Beck's avatar
Michael Beck committed
98
 *
Michael Beck's avatar
Michael Beck committed
99
100
 * - value_table     This hash table (pset) is used for global value numbering
 *                   for optimizing use in iropt.c.
Michael Beck's avatar
Michael Beck committed
101
 *
Michael Beck's avatar
Michael Beck committed
102
103
 * - Phi_in_stack;   a stack needed for automatic Phi construction, needed only
 *                   during ir construction.
Michael Beck's avatar
Michael Beck committed
104
 *
Matthias Braun's avatar
Matthias Braun committed
105
 * - visited         A int used as flag to traverse the ir_graph.
Michael Beck's avatar
Michael Beck committed
106
 *
Michael Beck's avatar
Michael Beck committed
107
 * - block_visited    A int used as a flag to traverse block nodes in the graph.
Matthias Braun's avatar
Matthias Braun committed
108
109
 *
 * @{
Götz Lindenmaier's avatar
Götz Lindenmaier committed
110
111
 */

Michael Beck's avatar
Michael Beck committed
112
113
114
115
116
117
118
119
120
121
122
123
124
/**
 * Create a new ir graph to build ir for a procedure.
 *
 * @param ent    A pointer to an entity representing the procedure,
 *               i.e., the type of the entity must be of a method type.
 *
 * @param n_loc  The number of local variables in this procedure including
 *               the procedure parameters.
 *
 * This constructor generates the basic infrastructure needed to
 * represent a procedure in FIRM.
 *
 * It allocates an ir_graph and sets the field irg of the entity ent
125
126
 * to point to this graph. Further it allocates the following nodes needed
 * for every procedure:
Michael Beck's avatar
Michael Beck committed
127
 *
128
 * - The start block containing a start node and Proj nodes for its
129
 *   seven results (X, M, P, P, P, T, P).
Michael Beck's avatar
Michael Beck committed
130
 * - The end block containing an end node. This block is not matured
Michael Beck's avatar
Michael Beck committed
131
 *   after executing new_ir_graph() as predecessors need to be added to it.
132
 *   (Maturing a block means fixing its number of predecessors.)
133
 * - The current block, which is empty and matured.
Michael Beck's avatar
Michael Beck committed
134
 *
Michael Beck's avatar
Michael Beck committed
135
136
137
 * Further it enters the global store into the data structure of the start
 * block that contains all valid values in this block (set_store()).  This
 * data structure is used to build the Phi nodes and removed after
Michael Beck's avatar
Michael Beck committed
138
139
140
141
142
143
144
145
146
147
148
 * completion of the graph.  There is no path from end to start in the
 * graph after calling ir_graph.
 *
 * The op_pin_state of the graph is set to "op_pin_state_pinned"
 * if no global cse was performed on the graph.
 * It is set to "op_pin_state_floats" if global cse was performed
 * (and during construction: did actually change something).
 * Code placement is necessary.
 *
 * @see new_pseudo_ir_graph()
 */
Michael Beck's avatar
Michael Beck committed
149
FIRM_API ir_graph *new_ir_graph(ir_entity *ent, int n_loc);
Christian Schäfer's avatar
Christian Schäfer committed
150

Michael Beck's avatar
Michael Beck committed
151
/** Frees the passed irgraph.
152
153
154
155
156
157
158
 * Deallocates all nodes in this graph and the ir_graph structure.
 * Sets the field irgraph in the corresponding entity to NULL.
 * Does not remove the irgraph from the list in irprog (requires
 * inefficient search, call remove_irp_irg by hand).
 * Does not free types, entities or modes that are used only by this
 * graph, nor the entity standing for this graph.
 */
Michael Beck's avatar
Michael Beck committed
159
FIRM_API void free_ir_graph(ir_graph *irg);
160

Sebastian Felis's avatar
Sebastian Felis committed
161
162
163
164
165
166
/**
 *   Checks whether a pointer points to a ir graph.
 *
 *   @param thing     an arbitrary pointer
 *
 *   @return
167
 *       true if the thing is a IR graph, else false
Sebastian Felis's avatar
Sebastian Felis committed
168
 */
Michael Beck's avatar
Michael Beck committed
169
FIRM_API int is_ir_graph(const void *thing);
Sebastian Felis's avatar
Sebastian Felis committed
170

171
/** Returns the entity of an IR graph. */
Michael Beck's avatar
Michael Beck committed
172
FIRM_API ir_entity *get_irg_entity(const ir_graph *irg);
173
/** Sets the entity of an IR graph. */
Michael Beck's avatar
Michael Beck committed
174
FIRM_API void set_irg_entity(ir_graph *irg, ir_entity *ent);
175

176
/** Returns the frame type of an IR graph. */
Michael Beck's avatar
Michael Beck committed
177
FIRM_API ir_type *get_irg_frame_type(ir_graph *irg);
178
/** Sets the frame type of an IR graph. */
Michael Beck's avatar
Michael Beck committed
179
FIRM_API void set_irg_frame_type(ir_graph *irg, ir_type *ftp);
180

181
/** Returns the start block of an IR graph. */
Michael Beck's avatar
Michael Beck committed
182
FIRM_API ir_node *get_irg_start_block(const ir_graph *irg);
183
/** Sets the start block of an IR graph. */
Michael Beck's avatar
Michael Beck committed
184
FIRM_API void set_irg_start_block(ir_graph *irg, ir_node *node);
Christian Schäfer's avatar
Christian Schäfer committed
185

186
/** Returns the Start node of an IR graph. */
Michael Beck's avatar
Michael Beck committed
187
FIRM_API ir_node *get_irg_start(const ir_graph *irg);
188
/** Sets the Start node of an IR graph. */
Michael Beck's avatar
Michael Beck committed
189
FIRM_API void set_irg_start(ir_graph *irg, ir_node *node);
Christian Schäfer's avatar
Christian Schäfer committed
190

191
/** Returns the end block of an IR graph. */
Michael Beck's avatar
Michael Beck committed
192
FIRM_API ir_node *get_irg_end_block(const ir_graph *irg);
193
/** Sets the end block of an IR graph. */
Michael Beck's avatar
Michael Beck committed
194
FIRM_API void set_irg_end_block(ir_graph *irg, ir_node *node);
Christian Schäfer's avatar
Christian Schäfer committed
195

196
/** Returns the End node of an IR graph. */
Michael Beck's avatar
Michael Beck committed
197
FIRM_API ir_node *get_irg_end(const ir_graph *irg);
198
/** Sets the End node of an IR graph. */
Michael Beck's avatar
Michael Beck committed
199
FIRM_API void set_irg_end(ir_graph *irg, ir_node *node);
Christian Schäfer's avatar
Christian Schäfer committed
200

201
202
/** Returns the node that represents the initial control flow of the given
 * IR graph. */
Michael Beck's avatar
Michael Beck committed
203
FIRM_API ir_node *get_irg_initial_exec(const ir_graph *irg);
204
/** Sets the node that represents the initial control of the given IR graph. */
Michael Beck's avatar
Michael Beck committed
205
FIRM_API void set_irg_initial_exec(ir_graph *irg, ir_node *node);
206

207
/** Returns the node that represents the frame pointer of the given IR graph. */
Michael Beck's avatar
Michael Beck committed
208
FIRM_API ir_node *get_irg_frame(const ir_graph *irg);
209
/** Sets the node that represents the frame pointer of the given IR graph. */
Michael Beck's avatar
Michael Beck committed
210
FIRM_API void set_irg_frame(ir_graph *irg, ir_node *node);
211
212

/** Returns the node that represents the initial memory of the given IR graph. */
Michael Beck's avatar
Michael Beck committed
213
FIRM_API ir_node *get_irg_initial_mem(const ir_graph *irg);
214
/** Sets the node that represents the initial memory of the given IR graph. */
Michael Beck's avatar
Michael Beck committed
215
FIRM_API void set_irg_initial_mem(ir_graph *irg, ir_node *node);
216
217

/** Returns the node that represents the argument pointer of the given IR graph. */
Michael Beck's avatar
Michael Beck committed
218
FIRM_API ir_node *get_irg_args(const ir_graph *irg);
219
/** Sets the node that represents the argument pointer of the given IR graph. */
Michael Beck's avatar
Michael Beck committed
220
FIRM_API void set_irg_args(ir_graph *irg, ir_node *node);
221

Matthias Braun's avatar
Matthias Braun committed
222
/** Returns the NoMem node of the given IR graph. */
Michael Beck's avatar
Michael Beck committed
223
FIRM_API ir_node *get_irg_no_mem(const ir_graph *irg);
224
/** Sets the NoMem node of graph @p irg. */
Michael Beck's avatar
Michael Beck committed
225
FIRM_API void set_irg_no_mem(ir_graph *irg, ir_node *node);
226
227

/** Returns the number of value numbers of an IR graph. */
Michael Beck's avatar
Michael Beck committed
228
FIRM_API int get_irg_n_locs(ir_graph *irg);
229

230
/** Returns the graph number. */
Michael Beck's avatar
Michael Beck committed
231
FIRM_API long get_irg_graph_nr(const ir_graph *irg);
Matthias Braun's avatar
Matthias Braun committed
232
233
234
235

/**
 * Returns the graph number. This is a unique number for the graph and is
 * smaller than get_irp_last_idx()
236
 * Note: you cannot use this number for get_irp_irg()
Matthias Braun's avatar
Matthias Braun committed
237
 */
238
FIRM_API size_t get_irg_idx(const ir_graph *irg);
239

240
/**
241
 * Returns the node for an index.
242
243
 * @param irg The graph.
 * @param idx The index you want the node for.
244
245
 * @return    The node with that index or NULL, if there is no node with that
 *            index.
246
 * @note      The node you got might be dead.
247
 * @see get_irn_idx()
248
 */
249
FIRM_API ir_node *get_idx_irn(const ir_graph *irg, unsigned idx);
250

251
252
253
254
/** state: op_pin_state_pinned
   The graph is "op_pin_state_pinned" if all nodes are associated with a basic block.
   It is in state "op_pin_state_floats" if nodes are in arbitrary blocks.  In state
   "op_pin_state_floats" the block predecessor is set in all nodes, but this can be an
255
256
   invalid block, i.e., the block is not a dominator of all the uses of
   the node.
257
   The enum op_pin_state is defined in irop.h. */
Michael Beck's avatar
Michael Beck committed
258
FIRM_API op_pin_state get_irg_pinned(const ir_graph *irg);
259

Götz Lindenmaier's avatar
Götz Lindenmaier committed
260
261
/** state: callee_information_state
 *  Call nodes contain a list of possible callees.  This list must be
Michael Beck's avatar
Michael Beck committed
262
 *  computed by an analysis.
Götz Lindenmaier's avatar
Götz Lindenmaier committed
263
264
265
266
 *
 *  It's strange that this state is administered on irg basis, as the
 *  information must be computed for the whole program, or not?
 */
Götz Lindenmaier's avatar
Götz Lindenmaier committed
267
typedef enum {
Michael Beck's avatar
Michael Beck committed
268
269
270
	irg_callee_info_none,
	irg_callee_info_consistent,
	irg_callee_info_inconsistent
Götz Lindenmaier's avatar
Götz Lindenmaier committed
271
} irg_callee_info_state;
272

Michael Beck's avatar
Michael Beck committed
273
/** Returns the callee_info_state of an IR graph. */
Michael Beck's avatar
Michael Beck committed
274
FIRM_API irg_callee_info_state get_irg_callee_info_state(const ir_graph *irg);
275

Michael Beck's avatar
Michael Beck committed
276
/** Sets the callee_info_state of an IR graph. */
Michael Beck's avatar
Michael Beck committed
277
FIRM_API void set_irg_callee_info_state(ir_graph *irg, irg_callee_info_state s);
Götz Lindenmaier's avatar
Götz Lindenmaier committed
278

279
/** A void * field to link arbitrary information to the node. */
Michael Beck's avatar
Michael Beck committed
280
FIRM_API void set_irg_link(ir_graph *irg, void *thing);
281
/** Return void* field previously set by set_irg_link() */
Michael Beck's avatar
Michael Beck committed
282
FIRM_API void *get_irg_link(const ir_graph *irg);
283

284
285
/** Increments node visited counter by one.
 *  @see @ref visited_counters, irn_visited(), mark_irn_visited() */
Michael Beck's avatar
Michael Beck committed
286
FIRM_API void inc_irg_visited(ir_graph *irg);
287
288
/** Returns node visited counter.
 * @see @ref visited_counters */
Michael Beck's avatar
Michael Beck committed
289
FIRM_API ir_visited_t get_irg_visited(const ir_graph *irg);
290
291
/** Sets node visited counter.
 * @see @ref visited_counters */
Michael Beck's avatar
Michael Beck committed
292
FIRM_API void set_irg_visited(ir_graph *irg, ir_visited_t i);
293
294
/** Returns interprocedural node visited counter.
 * @see @ref visited_counters */
Michael Beck's avatar
Michael Beck committed
295
FIRM_API ir_visited_t get_max_irg_visited(void);
296
297
/** Sets interprocedural node visited counter.
 * @see @ref visited_counters */
Michael Beck's avatar
Michael Beck committed
298
FIRM_API void set_max_irg_visited(int val);
299
300
/** Increment interprocedural node visited counter by one.
 * @see @ref visited_counters */
Michael Beck's avatar
Michael Beck committed
301
FIRM_API ir_visited_t inc_max_irg_visited(void);
Christian Schäfer's avatar
Christian Schäfer committed
302

303
304
/** Increments block visited counter by one.
 *  @see @ref visited_counters, Block_block_visited(), mark_Block_block_visited() */
Michael Beck's avatar
Michael Beck committed
305
FIRM_API void inc_irg_block_visited(ir_graph *irg);
306
307
/** Returns block visited counter.
 * @see @ref visited_counters */
Michael Beck's avatar
Michael Beck committed
308
FIRM_API ir_visited_t get_irg_block_visited(const ir_graph *irg);
309
310
/** Sets block visited counter.
 * @see @ref visited_counters */
Michael Beck's avatar
Michael Beck committed
311
FIRM_API void set_irg_block_visited(ir_graph *irg, ir_visited_t i);
Christian Schäfer's avatar
Christian Schäfer committed
312

313
/**
Michael Beck's avatar
Michael Beck committed
314
 * Debug helpers: You can indicate whether you are currently using visited or
315
316
317
 * block_visited flags. If NDEBUG is not defined, then the compiler will abort
 * if 2 parties try to use the flags.
 */
318
typedef enum ir_resources_t {
319
	IR_RESOURCE_NONE          = 0,       /**< no resource */
Michael Beck's avatar
Michael Beck committed
320
321
322
323
324
	IR_RESOURCE_BLOCK_VISITED = 1 << 0,  /**< Block visited flags are used. */
	IR_RESOURCE_BLOCK_MARK    = 1 << 1,  /**< Block mark bits are used. */
	IR_RESOURCE_IRN_VISITED   = 1 << 2,  /**< IR-node visited flags are used. */
	IR_RESOURCE_IRN_LINK      = 1 << 3,  /**< IR-node link fields are used. */
	IR_RESOURCE_LOOP_LINK     = 1 << 4,  /**< IR-loop link fields are used. */
325
	IR_RESOURCE_PHI_LIST      = 1 << 5   /**< Block Phi lists are used. */
326
327
} ir_resources_t;
ENUM_BITSET(ir_resources_t)
328

Matthias Braun's avatar
Matthias Braun committed
329
#ifndef NDEBUG
330
331
332
333
334
335
336
/**
 * Reserves resources of a graph.
 *
 * This is a debug tool: All code should properly allocate the resources it uses
 * so if two interlocked algorithms use the same resources that bug will get
 * detected.
 */
Michael Beck's avatar
Michael Beck committed
337
FIRM_API void ir_reserve_resources(ir_graph *irg, ir_resources_t resources);
338
/** Frees previously reserved resources. */
Michael Beck's avatar
Michael Beck committed
339
FIRM_API void ir_free_resources(ir_graph *irg, ir_resources_t resources);
340
/** Returns currently reserved resources. */
Michael Beck's avatar
Michael Beck committed
341
FIRM_API ir_resources_t ir_resources_reserved(const ir_graph *irg);
342
#else
343
344
#define ir_reserve_resources(irg,resources)  (void)0
#define ir_free_resources(irg,resources)     (void)0
345
#define ir_resources_reserved(irg)           0
346
#endif
347

348
/**
349
350
351
352
 * graph constraints:
 * These are typically used when lowering a graph for a target machine,
 * typically you get stricter constraints the closer you get to a real
 * machine.
353
 */
354
typedef enum ir_graph_constraints_t {
355
356
357
	/**
	 * Should not construct more nodes which irarch potentially breaks down
	 */
358
	IR_GRAPH_CONSTRAINT_ARCH_DEP                  = 1U << 0,
359
360
361
362
	/**
	 * mode_b nodes have been lowered so you should not create any new nodes
	 * with mode_b (except for Cmp)
	 */
363
	IR_GRAPH_CONSTRAINT_MODEB_LOWERED             = 1U << 1,
364
365
366
367
368
	/**
	 * There are normalisations where there is no "best" representative.
	 * In this case we first normalise into 1 direction (!NORMALISATION2) and
	 * later in the other (NORMALISATION2).
	 */
369
	IR_GRAPH_CONSTRAINT_NORMALISATION2            = 1U << 2,
370
	/**
371
	 * Allows localopts to remove edges to unreachable code.
372
373
374
	 * Warning: It is only safe to enable this when you are sure that you
	 * apply all localopts to the fixpunkt. (=in optimize_graph_df)
	 */
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
	IR_GRAPH_CONSTRAINT_OPTIMIZE_UNREACHABLE_CODE = 1U << 3,
	/**
	 * The graph is being constructed: We have a current_block set,
	 * and blocks contain mapping of variable numbers to current
	 * values.
	 */
	IR_GRAPH_CONSTRAINT_CONSTRUCTION              = 1U << 4,
	/**
	 * Intermediate language constructs not supported by the backend have
	 * been lowered.
	 */
	IR_GRAPH_CONSTRAINT_TARGET_LOWERED            = 1U << 5,
	/**
	 * We have a backend graph: all data values have register constraints
	 * annotated.
	 */
	IR_GRAPH_CONSTRAINT_BACKEND                   = 1U << 6,
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
} ir_graph_constraints_t;
ENUM_BITSET(ir_graph_constraints_t)

/** sets @p constraints on the graph @p irg */
FIRM_API void add_irg_constraints(ir_graph *irg,
                                  ir_graph_constraints_t constraints);
/** clears some graph constraints */
FIRM_API void clear_irg_constraints(ir_graph *irg,
                                    ir_graph_constraints_t constraints);
/** queries whether @p irg is at least as constrained as @p constraints. */
FIRM_API int irg_is_constrained(const ir_graph *irg,
                                ir_graph_constraints_t constraints);

/**
 * graph state. They properties about a graph.
 * Graph transformations may destroy these properties and have to explicitely
 * state when they did not affect some properties and want to keep them.
 */
typedef enum ir_graph_properties_t {
Matthias Braun's avatar
Matthias Braun committed
411
	IR_GRAPH_PROPERTIES_NONE                         = 0,
412
	/** graph contains no critical edges */
Matthias Braun's avatar
Matthias Braun committed
413
	IR_GRAPH_PROPERTY_NO_CRITICAL_EDGES              = 1U << 0,
414
	/** graph contains no Bad nodes */
Matthias Braun's avatar
Matthias Braun committed
415
	IR_GRAPH_PROPERTY_NO_BADS                        = 1U << 1,
416
	/** No tuple nodes exist in the graph */
Matthias Braun's avatar
Matthias Braun committed
417
	IR_GRAPH_PROPERTY_NO_TUPLES                      = 1U << 2,
418
419
420
421
422
	/**
	 * there exists no (obviously) unreachable code in the graph.
	 * Unreachable in this context is code that you can't reach by following
	 * execution flow from the start block.
	 */
Matthias Braun's avatar
Matthias Braun committed
423
	IR_GRAPH_PROPERTY_NO_UNREACHABLE_CODE            = 1U << 3,
424
	/** graph contains at most one return */
Matthias Braun's avatar
Matthias Braun committed
425
	IR_GRAPH_PROPERTY_ONE_RETURN                     = 1U << 4,
426
	/** dominance information about the graph is valid */
Matthias Braun's avatar
Matthias Braun committed
427
	IR_GRAPH_PROPERTY_CONSISTENT_DOMINANCE           = 1U << 5,
428
	/** postdominance information about the graph is valid */
Matthias Braun's avatar
Matthias Braun committed
429
430
431
	IR_GRAPH_PROPERTY_CONSISTENT_POSTDOMINANCE       = 1U << 6,
	/** dominance frontiers information is calculated */
	IR_GRAPH_PROPERTY_CONSISTENT_DOMINANCE_FRONTIERS = 1U << 7,
432
433
434
	/**
	 * out edges (=iredges) are enable and there is no dead code that can be
	 * reached by following them
435
	 */
Matthias Braun's avatar
Matthias Braun committed
436
	IR_GRAPH_PROPERTY_CONSISTENT_OUT_EDGES           = 1U << 8,
437
	/** outs (irouts) are computed and up to date */
Matthias Braun's avatar
Matthias Braun committed
438
	IR_GRAPH_PROPERTY_CONSISTENT_OUTS                = 1U << 9,
439
	/** loopinfo is computed and up to date */
Matthias Braun's avatar
Matthias Braun committed
440
	IR_GRAPH_PROPERTY_CONSISTENT_LOOPINFO            = 1U << 10,
441
	/** entity usage information is computed and up to date */
Matthias Braun's avatar
Matthias Braun committed
442
	IR_GRAPH_PROPERTY_CONSISTENT_ENTITY_USAGE        = 1U << 11,
443
	/** graph contains as many returns as possible */
Matthias Braun's avatar
Matthias Braun committed
444
	IR_GRAPH_PROPERTY_MANY_RETURNS                   = 1U << 12,
445
446

	/**
yb9976's avatar
yb9976 committed
447
	 * List of all graph properties that are only affected by control flow
448
449
450
451
452
453
454
455
	 * changes.
	 */
	IR_GRAPH_PROPERTIES_CONTROL_FLOW =
		  IR_GRAPH_PROPERTY_NO_CRITICAL_EDGES
		| IR_GRAPH_PROPERTY_ONE_RETURN
		| IR_GRAPH_PROPERTY_NO_UNREACHABLE_CODE
		| IR_GRAPH_PROPERTY_CONSISTENT_LOOPINFO
		| IR_GRAPH_PROPERTY_CONSISTENT_DOMINANCE
Matthias Braun's avatar
Matthias Braun committed
456
457
		| IR_GRAPH_PROPERTY_CONSISTENT_POSTDOMINANCE
		| IR_GRAPH_PROPERTY_CONSISTENT_DOMINANCE_FRONTIERS,
458
459
460
461
462
463
464
465
466
467
468
469
470

	/**
	 * List of all graph properties.
	 */
	IR_GRAPH_PROPERTIES_ALL =
		  IR_GRAPH_PROPERTIES_CONTROL_FLOW
	    | IR_GRAPH_PROPERTY_NO_BADS
	    | IR_GRAPH_PROPERTY_NO_TUPLES
	    | IR_GRAPH_PROPERTY_CONSISTENT_OUT_EDGES
	    | IR_GRAPH_PROPERTY_CONSISTENT_OUTS
	    | IR_GRAPH_PROPERTY_CONSISTENT_ENTITY_USAGE
	    | IR_GRAPH_PROPERTY_MANY_RETURNS,

471
472
473
474
475
476
477
478
479
480
} ir_graph_properties_t;
ENUM_BITSET(ir_graph_properties_t)

/** sets some state properties on the graph */
FIRM_API void add_irg_properties(ir_graph *irg, ir_graph_properties_t props);
/** clears some graph properties */
FIRM_API void clear_irg_properties(ir_graph *irg, ir_graph_properties_t props);
/** queries whether @p irg has the @p props properties set */
FIRM_API int irg_has_properties(const ir_graph *irg,
                                ir_graph_properties_t props);
481

482
/** Sets a description for local value n. */
Michael Beck's avatar
Michael Beck committed
483
FIRM_API void set_irg_loc_description(ir_graph *irg, int n, void *description);
484

485
/** Returns the description for local value n. */
Michael Beck's avatar
Michael Beck committed
486
FIRM_API void *get_irg_loc_description(ir_graph *irg, int n);
487

488
/** Returns the last irn index for this graph. */
Michael Beck's avatar
Michael Beck committed
489
FIRM_API unsigned get_irg_last_idx(const ir_graph *irg);
490

491
/** Returns the floating point model of this graph. */
Michael Beck's avatar
Michael Beck committed
492
FIRM_API unsigned get_irg_fp_model(const ir_graph *irg);
493
494

/** Sets a floating point model for this graph. */
Michael Beck's avatar
Michael Beck committed
495
FIRM_API void set_irg_fp_model(ir_graph *irg, unsigned model);
496

497
498
499
500
501
502
503
504
505
506
507
508
509
/**
 * Ensures that a graph fulfills all properties stated in @p state.
 * Performs graph transformations if necessary.
 */
FIRM_API void assure_irg_properties(ir_graph *irg, ir_graph_properties_t props);

/**
 * Invalidates all graph properties/analysis data except the ones specified
 * in @p props.
 * This should be called after a transformation phase.
 */
FIRM_API void confirm_irg_properties(ir_graph *irg, ir_graph_properties_t props);

Matthias Braun's avatar
Matthias Braun committed
510
511
/** @} */

512
#include "end.h"
513

Matthias Braun's avatar
Matthias Braun committed
514
#endif