irnode.h 19.2 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
 */

Matthias Braun's avatar
Matthias Braun committed
6
7
8
9
/**
 * @file
 * @brief   Representation of an intermediate operation.
 * @author  Martin Trapp, Christian Schaefer, Goetz Lindenmaier, Michael Beck
Michael Beck's avatar
Michael Beck committed
10
 */
Matthias Braun's avatar
Matthias Braun committed
11
12
#ifndef FIRM_IR_IRNODE_H
#define FIRM_IR_IRNODE_H
Christian Schäfer's avatar
Christian Schäfer committed
13

14
15
#include <stddef.h>

Michael Beck's avatar
Michael Beck committed
16
#include "firm_common.h"
17
#include "typerep.h"
Michael Beck's avatar
Michael Beck committed
18
19
#include "irop.h"
#include "irmode.h"
20
#include "begin.h"
21
#include "nodes.h"
Michael Beck's avatar
Michael Beck committed
22
23

/**
Matthias Braun's avatar
Matthias Braun committed
24
 * @ingroup ir_graph
Matthias Braun's avatar
Matthias Braun committed
25
 * @defgroup ir_node Nodes
Götz Lindenmaier's avatar
Götz Lindenmaier committed
26
 *
Michael Beck's avatar
Michael Beck committed
27
 * ir_node - a datatype representing a Firm node
Götz Lindenmaier's avatar
Götz Lindenmaier committed
28
 *
Michael Beck's avatar
Michael Beck committed
29
30
31
32
33
34
35
36
37
38
39
40
41
 *  The common fields are:
 *
 *  - arity     - The number of predecessors in the Firm graph.
 *  - in        - A list with the predecessors in the Firm graph.  There are
 *                routines to access individual elements and to obtain the
 *                array.  The method returning the array should not be used.
 *  - mode      - The mode of the node.  There are routines to get the mode
 *                but also to access the mode's fields directly.
 *  - opcode    - The opcode of the node. There are routines to get the opcode
 *                but also to access the opcode's fields directly.
 *  - node_nr   - A unique number for the node.  Available only if debugging
 *                is turned on.
 * @{
Götz Lindenmaier's avatar
Götz Lindenmaier committed
42
 */
Michael Beck's avatar
Michael Beck committed
43

44
45
46
47
48
/**
 * Returns the number of predecessors without the block predecessor.
 *
 * @param node   the IR-node
 */
49
FIRM_API int get_irn_arity(const ir_node *node);
50
51

/**
52
 * Returns the n-th predecessor of a node.
53
54
 * This function removes Id predecessors.
 */
Michael Beck's avatar
Michael Beck committed
55
FIRM_API ir_node *get_irn_n(const ir_node *node, int n);
Michael Beck's avatar
Michael Beck committed
56

57
58
59
60
61
62
/**
 * Replaces the old in array by a new one that will contain the ins given in
 * the parameters. Conserves the block predecessor. It copies the array passed.
 * This function is necessary to adjust in arrays of blocks, calls and phis.
 * "in" must contain all predecessors except the block that are required for
 * the nodes opcode. */
63
FIRM_API void set_irn_in(ir_node *node, int arity, ir_node *const in[]);
64

Sebastian Hack's avatar
Sebastian Hack committed
65
/**
66
 * Add an artificial dependency to the node.
67
68
69
70
 *
 * @param node The node.
 * @param dep  The dependency target.
 */
71
FIRM_API void add_irn_dep(ir_node *node, ir_node *dep);
Sebastian Hack's avatar
Sebastian Hack committed
72
73
74

/**
 * Copy all dependencies from a node to another.
75
76
 * This is only allowed in phase_backend!
 *
77
 * @param tgt The node which should be enriched.
Sebastian Hack's avatar
Sebastian Hack committed
78
79
 * @param src The node whose dependencies shall be copied.
 */
Michael Beck's avatar
Michael Beck committed
80
FIRM_API void add_irn_deps(ir_node *tgt, ir_node *src);
Sebastian Hack's avatar
Sebastian Hack committed
81
82

/**
83
 * Returns the number of dependency predecessors/edges of node @p node.
Michael Beck's avatar
Michael Beck committed
84
 * @param node The node.
85
86
 * @return The length of the dependency array or 0 if it has not yet been
 *         allocated.
Michael Beck's avatar
Michael Beck committed
87
 */
88
FIRM_API int get_irn_n_deps(const ir_node *node);
Sebastian Hack's avatar
Sebastian Hack committed
89
90

/**
91
 * Returns an entry of the dependency array.
Michael Beck's avatar
Michael Beck committed
92
93
94
95
 * @param node The node.
 * @param pos  The position.
 * @return The node at that position.
 */
Michael Beck's avatar
Michael Beck committed
96
FIRM_API ir_node *get_irn_dep(const ir_node *node, int pos);
Sebastian Hack's avatar
Sebastian Hack committed
97
98

/**
99
 * Sets an entry of the dependency array.
Michael Beck's avatar
Michael Beck committed
100
101
102
103
 * @param node The node.
 * @param pos  The position.
 * @param dep  The dependency target.
 */
Michael Beck's avatar
Michael Beck committed
104
FIRM_API void set_irn_dep(ir_node *node, int pos, ir_node *dep);
Sebastian Hack's avatar
Sebastian Hack committed
105

106
107
108
109
110
111
112
113
114
/**
 * Deletes the entry of the dependency array, that points to dep. Does nothing
 * if no dependency exists.
 *
 * @param node the node to delete the dependency at
 * @param dep the target of the dependency to delete
 */
FIRM_API void delete_irn_dep(ir_node *node, ir_node *dep);

115
/** Replaces the n-th predecessor of a node with a new one. */
Michael Beck's avatar
Michael Beck committed
116
FIRM_API void set_irn_n(ir_node *node, int n, ir_node *in);
117
118
119
120
121
/**
 * Appends a new predecessor to a node. This only works for nodes with
 * variable arity!
 * @returns   the number of the new input
 */
Michael Beck's avatar
Michael Beck committed
122
FIRM_API int add_irn_n(ir_node *node, ir_node *in);
123
/** Sets the mode struct of node.  */
Michael Beck's avatar
Michael Beck committed
124
FIRM_API void set_irn_mode(ir_node *node, ir_mode *mode);
125
/** Returns the mode struct of a node.  */
Michael Beck's avatar
Michael Beck committed
126
FIRM_API ir_mode *get_irn_mode(const ir_node *node);
127
/** Returns the opcode struct of the node. */
Michael Beck's avatar
Michael Beck committed
128
FIRM_API ir_op *get_irn_op(const ir_node *node);
Michael Beck's avatar
Michael Beck committed
129
/** Sets the opcode struct of the node. */
Michael Beck's avatar
Michael Beck committed
130
FIRM_API void set_irn_op(ir_node *node, ir_op *op);
131
/** Returns the opcode-enum of the node. */
Michael Beck's avatar
Michael Beck committed
132
FIRM_API unsigned get_irn_opcode(const ir_node *node);
133
/** Returns the string representation of the opcode. */
Michael Beck's avatar
Michael Beck committed
134
FIRM_API const char *get_irn_opname(const ir_node *node);
135
/** Returns the ident for a string representation of the opcode. */
Michael Beck's avatar
Michael Beck committed
136
FIRM_API ident *get_irn_opident(const ir_node *node);
137
/** Returns the visited counter of a node. */
Michael Beck's avatar
Michael Beck committed
138
FIRM_API ir_visited_t get_irn_visited(const ir_node *node);
139
/** Sets the visited counter of a node. */
Michael Beck's avatar
Michael Beck committed
140
FIRM_API void set_irn_visited(ir_node *node, ir_visited_t visited);
141
/** Sets visited to get_irg_visited(get_irn_irg(node)). */
Michael Beck's avatar
Michael Beck committed
142
FIRM_API void mark_irn_visited(ir_node *node);
143
/** Returns 1 if visited >= get_irg_visited(get_irn_irg(node)). */
Michael Beck's avatar
Michael Beck committed
144
FIRM_API int irn_visited(const ir_node *node);
145
/** Returns 1 if visited >= get_irg_visited(get_irn_irg(node)). Marks the node
146
 * visited, if it was not. */
Michael Beck's avatar
Michael Beck committed
147
FIRM_API int irn_visited_else_mark(ir_node *node);
148
149
150
151
152

/**
 * Sets the link of a node.
 * Only allowed if the graph is NOT in phase_building.
 */
Michael Beck's avatar
Michael Beck committed
153
FIRM_API void set_irn_link(ir_node *node, void *link);
154
155

/** Returns the link of a node.  */
Michael Beck's avatar
Michael Beck committed
156
FIRM_API void *get_irn_link(const ir_node *node);
157

158
/** Returns the ir_graph this node belongs to. */
Michael Beck's avatar
Michael Beck committed
159
FIRM_API ir_graph *get_irn_irg(const ir_node *node);
Michael Beck's avatar
Michael Beck committed
160

161
/** Outputs a unique number for this node if libFIRM is compiled for
162
163
   debugging, (configure with --enable-debug) else returns address
   of node cast to long. */
Michael Beck's avatar
Michael Beck committed
164
FIRM_API long get_irn_node_nr(const ir_node *node);
Michael Beck's avatar
Michael Beck committed
165

166
167
168
169
170
171
172
/** Returns the pinned state of a node.
 *
 *  Returns whether the node _always_ must be pinned.
 *  I.e., the node is not floating after global cse.
 *
 * @returns Either state op_pin_state_pinned or op_pin_state_floats.
 */
Michael Beck's avatar
Michael Beck committed
173
FIRM_API op_pin_state get_irn_pinned(const ir_node *node);
Michael Beck's avatar
Michael Beck committed
174

175
/** Sets pin state for nodes with op pin state op_pin_state_exc_pinned */
Michael Beck's avatar
Michael Beck committed
176
FIRM_API void set_irn_pinned(ir_node *node, op_pin_state state);
Götz Lindenmaier's avatar
Götz Lindenmaier committed
177

Michael Beck's avatar
Michael Beck committed
178
/**
179
180
181
 * IR node constructor.
 * Create a new IR node in irg, with an op, mode, arity and
 * some incoming IR nodes.
Matthias Braun's avatar
Matthias Braun committed
182
183
 * Normally you should not use this constructor directly unless you registered
 * custom opcodes. For the default opcodes firm provides specific constructors.
184
185
186
 *
 * @param db    Debug info.
 * @param irg   IR-graph on with this new node should be constructed.
Michael Beck's avatar
Michael Beck committed
187
 * @param block The block the new node belongs to
188
189
 * @param op    The opcode of the new node.
 * @param mode  The mode of the new node.
190
 * @param arity The arity of the new node, <0 if can be changed dynamically.
191
 * @param in    An array of arity predecessor nodes.
Michael Beck's avatar
Michael Beck committed
192
 */
Michael Beck's avatar
Michael Beck committed
193
FIRM_API ir_node *new_ir_node(dbg_info *db, ir_graph *irg, ir_node *block,
194
                              ir_op *op, ir_mode *mode,
195
                              int arity, ir_node *const *in);
Christian Schäfer's avatar
Christian Schäfer committed
196

197
/**
198
 * Returns the block the node belongs to.  This is only
199
200
201
 * possible for pinned nodes or if the graph is in pinned state.
 * Otherwise the block may be incorrect.  This condition is
 * now checked by an assertion.
Götz Lindenmaier's avatar
Götz Lindenmaier committed
202
203
204
205
206
 *
 * This works for all except Block.  It can return Blocks or the Bad node.
 *
 * To express the difference to access routines that work for all
 * nodes we use infix "nodes" and do not name this function
207
 * get_irn_block(). */
208
FIRM_API ir_node *get_nodes_block(const ir_node *node);
Michael Beck's avatar
Michael Beck committed
209
210

/** Sets the Block of a node. */
211
FIRM_API void set_nodes_block(ir_node *node, ir_node *block);
Götz Lindenmaier's avatar
Götz Lindenmaier committed
212

Matthias Braun's avatar
Matthias Braun committed
213
214
215
216
217
/**
 * @addtogroup Block
 * @{
 */

218
/**
219
 * Returns the position of the predecessor block pred in the inputs
220
221
222
223
224
225
226
 * of the block block.
 *
 * @param block  the block
 * @param pred   a predecessor block of block
 *
 * @return the position of pred in block or -1
 */
Michael Beck's avatar
Michael Beck committed
227
FIRM_API int get_Block_cfgpred_pos(const ir_node *block, const ir_node *pred);
228

229
230
/**
 * Returns the predecessor block.
231
 *
232
 * Returns the block corresponding to the predecessor pos of block.
233
 *
234
 * If we encounter the Bad node as controlflow predecessor NULL is returned.
235
 */
Michael Beck's avatar
Michael Beck committed
236
FIRM_API ir_node *get_Block_cfgpred_block(const ir_node *node, int pos);
237

238
/** Returns the matured flag of a block */
Michael Beck's avatar
Michael Beck committed
239
FIRM_API int get_Block_matured(const ir_node *block);
240
/** set the matured flag of a block. */
Michael Beck's avatar
Michael Beck committed
241
FIRM_API void set_Block_matured(ir_node *block, int matured);
Götz Lindenmaier's avatar
Götz Lindenmaier committed
242
243
244

/** A visited flag only for block nodes.
 *  @see also: get_irn_visited() inc_irg_visited() inc_irg_block_visited()*/
Michael Beck's avatar
Michael Beck committed
245
FIRM_API ir_visited_t get_Block_block_visited(const ir_node *block);
246
/** set block visited flag */
Michael Beck's avatar
Michael Beck committed
247
FIRM_API void set_Block_block_visited(ir_node *block, ir_visited_t visit);
248

249
/** Marks a block as visited by setting its visited counter */
Michael Beck's avatar
Michael Beck committed
250
FIRM_API void mark_Block_block_visited(ir_node *node);
251
/** Returns 1 if a block is marked as visited */
Michael Beck's avatar
Michael Beck committed
252
FIRM_API int Block_block_visited(const ir_node *node);
Christian Schäfer's avatar
Christian Schäfer committed
253

254
/** Returns the entity for a Block (creating it if necessary) */
Michael Beck's avatar
Michael Beck committed
255
FIRM_API ir_entity *create_Block_entity(ir_node *block);
256
/** Returns the head of the Phi list for this block. */
Michael Beck's avatar
Michael Beck committed
257
FIRM_API ir_node *get_Block_phis(const ir_node *block);
258
/** Sets the head of the Phi list for this block. */
Michael Beck's avatar
Michael Beck committed
259
FIRM_API void set_Block_phis(ir_node *block, ir_node *phi);
Michael Beck's avatar
Michael Beck committed
260
/** Add a Phi node to the list of Block Phi's. */
Michael Beck's avatar
Michael Beck committed
261
FIRM_API void add_Block_phi(ir_node *block, ir_node *phi);
262
/** Returns the Block mark (single bit). */
Michael Beck's avatar
Michael Beck committed
263
FIRM_API unsigned get_Block_mark(const ir_node *block);
264
/** Sets the Block mark (single bit). */
Michael Beck's avatar
Michael Beck committed
265
FIRM_API void set_Block_mark(ir_node *block, unsigned mark);
Michael Beck's avatar
Michael Beck committed
266

Matthias Braun's avatar
Matthias Braun committed
267
268
269
270
271
272
/** @} */

/** @addtogroup End
 * @{
 */

Michael Beck's avatar
Michael Beck committed
273
/** Keep alive dedicated nodes.  These must be either PhiM or Block nodes. */
Michael Beck's avatar
Michael Beck committed
274
FIRM_API void add_End_keepalive(ir_node *end, ir_node *ka);
275
276

/**
277
 * Sets new keep-alives.
278
279
280
 * Beware: This might be an expensive operation if dynamic edges are enabled,
 * so avoid it in the backend.
 */
Michael Beck's avatar
Michael Beck committed
281
FIRM_API void set_End_keepalives(ir_node *end, int n, ir_node *in[]);
282

283
/** Removes irn from the keep-alive set. */
Matthias Braun's avatar
Matthias Braun committed
284
FIRM_API void remove_End_keepalive(ir_node *end, const ir_node *irn);
285

286
287
288
/** Removes predecessor (a keepalive) at index @p idx from End node @p end. */
FIRM_API void remove_End_n(ir_node *end, int idx);

289
/** Removes Bads, NoMem and doublets from the keep-alive set. */
Michael Beck's avatar
Michael Beck committed
290
FIRM_API void remove_End_Bads_and_doublets(ir_node *end);
291

Michael Beck's avatar
Michael Beck committed
292
/** Some parts of the End node are allocated separately -- their memory
293
294
295
 * is not recovered by dead_node_elimination if a End node is dead.
 * free_End() frees these data structures.
 */
Michael Beck's avatar
Michael Beck committed
296
FIRM_API void free_End(ir_node *end);
297

Matthias Braun's avatar
Matthias Braun committed
298
299
300
301
302
303
/** @} */

/** @addtogroup Const
 * @{
 */

304
/** Returns non-zero if the given Const node represents the 0 constant. */
Michael Beck's avatar
Michael Beck committed
305
FIRM_API int is_Const_null(const ir_node *node);
306

307
/** Returns non-zero if the given Const node represents the 1 constant. */
Michael Beck's avatar
Michael Beck committed
308
FIRM_API int is_Const_one(const ir_node *node);
309

310
/** Returns non-zero if the given Const node represents the constant with all bits set. */
Michael Beck's avatar
Michael Beck committed
311
FIRM_API int is_Const_all_one(const ir_node *node);
Sebastian Hack's avatar
Sebastian Hack committed
312

Matthias Braun's avatar
Matthias Braun committed
313
314
/** @} */

315
316
317
318
319
320
321
322
/**
 * @addtogroup Call
 * @{
 */

/**
 * Convenience function: Return method that will be called by a call.
 *
323
 * This matches for an address at the Call ptr input, return
324
325
326
327
328
329
330
 * the referenced entity if it has a method type.
 */
FIRM_API ir_entity *get_Call_callee(const ir_node *call);

/** @} */


331
/** Returns a human readable string for the ir_builtin_kind. */
Michael Beck's avatar
Michael Beck committed
332
FIRM_API const char *get_builtin_kind_name(ir_builtin_kind kind);
333

334
/** Returns left operand of binary operation @p node. */
Michael Beck's avatar
Michael Beck committed
335
FIRM_API ir_node *get_binop_left(const ir_node *node);
336
337
338
/** Sets left operand of binary operation @p node. */
FIRM_API void set_binop_left(ir_node *node, ir_node *left);
/** Returns rights operand of binary operation @p node. */
Michael Beck's avatar
Michael Beck committed
339
FIRM_API ir_node *get_binop_right(const ir_node *node);
340
341
/** Sets right operand of binary operation @p node. */
FIRM_API void set_binop_right(ir_node *node, ir_node *right);
Michael Beck's avatar
Michael Beck committed
342

Matthias Braun's avatar
Matthias Braun committed
343
/**
344
 * Tests whether a node is the X_except Proj of a fragile operation
Matthias Braun's avatar
Matthias Braun committed
345
 */
346
FIRM_API int is_x_except_Proj(const ir_node *node);
Matthias Braun's avatar
Matthias Braun committed
347
348

/**
349
 * Tests whether a node is the X_regular Proj of a fragile operation
Matthias Braun's avatar
Matthias Braun committed
350
 */
351
FIRM_API int is_x_regular_Proj(const ir_node *node);
352
353

/**
354
 * Sets throws exception attribute of a fragile node
355
356
 * @p throws_exception must be 0 or 1
 */
357
FIRM_API void ir_set_throws_exception(ir_node *node, int throws_exception);
358

359
360
/** Returns throws_exception attribute of a fragile node */
FIRM_API int ir_throws_exception(const ir_node *node);
Matthias Braun's avatar
Matthias Braun committed
361

362
/** Returns the name of an ir_relation */
363
FIRM_API const char *get_relation_string(ir_relation relation);
Michael Beck's avatar
Michael Beck committed
364

365
366
/** Calculates the negated (Complement(R)) relation, i.e. "<" --> ">=" */
FIRM_API ir_relation get_negated_relation(ir_relation relation);
Michael Beck's avatar
Michael Beck committed
367

368
369
/** Calculates the inversed (R^-1) relation, i.e., "<" --> ">" */
FIRM_API ir_relation get_inversed_relation(ir_relation relation);
370

Matthias Braun's avatar
Matthias Braun committed
371
372
373
374
375
/**
 * @addtogroup Phi
 * @{
 */

376
377
378
/**
 * Returns the next element of a block phi list.
 */
379
FIRM_API ir_node *get_Phi_next(const ir_node *phi);
380
381
382
/**
 * Sets the next link of a block Phi list.
 */
383
FIRM_API void set_Phi_next(ir_node *phi, ir_node *next);
384

Matthias Braun's avatar
Matthias Braun committed
385
386
/** @} */

387
/** Returns true if @p node is a memory operation.
388
 *
389
390
391
392
393
394
 * A memory operation is a node with an opcode that has irop_flag_uses_memory
 * set. It is guaranteed to have (exactly) one memory input.
 */
FIRM_API int is_memop(const ir_node *node);
/**
 * Returns the memory input of a memory operation.
395
 */
Michael Beck's avatar
Michael Beck committed
396
FIRM_API ir_node *get_memop_mem(const ir_node *node);
397
398
399
400
401
402
403
404
/**
 * Sets the memory input of a memory operation.
 */
FIRM_API void set_memop_mem(ir_node *node, ir_node *mem);

/** @addtogroup Sync
 * @{
 */
405

406
407
/** Adds @p pred to predecessor list of Sync node @p node. */
FIRM_API void add_Sync_pred(ir_node *node, ir_node *pred);
408
409
/** Removes predecessor @p i from Sync @p n */
FIRM_API void remove_Sync_n(ir_node *n, int i);
410
411

/** @} */
412

Matthias Braun's avatar
Matthias Braun committed
413
414
415
416
/** @addtogroup ASM
 * @{
 */

417
/** Returns the number of output constraints for an ASM node.  */
418
FIRM_API size_t get_ASM_n_output_constraints(const ir_node *node);
419
/** Returns the number of clobbered registers for an ASM node.  */
420
FIRM_API size_t get_ASM_n_clobbers(const ir_node *node);
Michael Beck's avatar
Michael Beck committed
421

Matthias Braun's avatar
Matthias Braun committed
422
423
/** @} */

Michael Beck's avatar
Michael Beck committed
424
/** Returns operand of node if node is a Proj. */
Michael Beck's avatar
Michael Beck committed
425
FIRM_API ir_node *skip_Proj(ir_node *node);
Michael Beck's avatar
Michael Beck committed
426
/** Returns operand of node if node is a Proj. */
Michael Beck's avatar
Michael Beck committed
427
FIRM_API const ir_node *skip_Proj_const(const ir_node *node);
Michael Beck's avatar
Michael Beck committed
428
/** Returns operand of node if node is a Id. */
429
430
FIRM_API ir_node *skip_Id(ir_node *node);
/** Returns corresponding operand of Tuple if node is a Proj from a Tuple. */
Michael Beck's avatar
Michael Beck committed
431
FIRM_API ir_node *skip_Tuple(ir_node *node);
Michael Beck's avatar
Michael Beck committed
432
/** Returns operand of node if node is a Pin. */
Michael Beck's avatar
Michael Beck committed
433
FIRM_API ir_node *skip_Pin(ir_node *node);
Michael Beck's avatar
Michael Beck committed
434
/** Returns operand of node if node is a Confirm */
Michael Beck's avatar
Michael Beck committed
435
FIRM_API ir_node *skip_Confirm(ir_node *node);
436
/** Returns true if the operation manipulates control flow */
Michael Beck's avatar
Michael Beck committed
437
FIRM_API int is_cfop(const ir_node *node);
438
/** Returns true if the operation jumps to an unknown destination.
439
440
 * See irop_flag_unknown_jump for a detailed explanation */
FIRM_API int is_unknown_jump(const ir_node *node);
441

442
443
444
445
446
/**
 * Returns true if the operation can change the control flow because
 * of an exception: Call, Div, Mod, Load, Store, Alloc,
 * Bad. Raise is not fragile, but a unconditional jump.
 */
Michael Beck's avatar
Michael Beck committed
447
FIRM_API int is_fragile_op(const ir_node *node);
Christian Schäfer's avatar
Christian Schäfer committed
448

Michael Beck's avatar
Michael Beck committed
449
450
/** Returns true if the operation is a forking control flow
 *  operation: Cond. */
Michael Beck's avatar
Michael Beck committed
451
FIRM_API int is_irn_forking(const ir_node *node);
Michael Beck's avatar
Michael Beck committed
452

453
454
455
456
/** Returns true if the operation does not change anymemory contents although
 * it has a memory input/output. */
FIRM_API int is_irn_const_memory(const ir_node *node);

457
/**
458
 * Copies attributes stored in the old node to a new node.
459
 * Assumes both have the same opcode and sufficient size.
460
461
462
463
464
465
466
 *
 * @param irg       The irg of the new_node (get_irn_irg on it might not work
 *                  yet)
 * @param old_node  the node where the attributes are copied from
 * @param new_node  node the attributes get copies to.
 *
 * This copies all essential information to the new node. It does not copy
467
468
 * temporary or calculated information like visited flags or results of
 * dominance or loop calculations.
469
 */
Michael Beck's avatar
Michael Beck committed
470
FIRM_API void copy_node_attr(ir_graph *irg, const ir_node *old_node, ir_node *new_node);
471

472
/** Returns the type attribute of a node n (TypeConst, Call, Alloc, Free)
Matthias Braun's avatar
Matthias Braun committed
473
 *  or NULL.*/
Michael Beck's avatar
Michael Beck committed
474
FIRM_API ir_type *get_irn_type_attr(ir_node *n);
Michael Beck's avatar
Michael Beck committed
475

476
/** Returns the entity attribute of a node n (Address, Offset, Sel) or NULL. */
Michael Beck's avatar
Michael Beck committed
477
FIRM_API ir_entity *get_irn_entity_attr(ir_node *n);
478

Michael Beck's avatar
Michael Beck committed
479
/** Returns non-zero for constant-like nodes. */
Michael Beck's avatar
Michael Beck committed
480
FIRM_API int is_irn_constlike(const ir_node *node);
Michael Beck's avatar
Michael Beck committed
481

Michael Beck's avatar
Michael Beck committed
482
483
484
485
/**
 * Returns non-zero for nodes that are allowed to have keep-alives and
 * are neither Block nor PhiM.
 */
Michael Beck's avatar
Michael Beck committed
486
FIRM_API int is_irn_keep(const ir_node *node);
Michael Beck's avatar
Michael Beck committed
487

488
489
490
/**
 * Returns non-zero for nodes that are always placed in the start block.
 */
Michael Beck's avatar
Michael Beck committed
491
FIRM_API int is_irn_start_block_placed(const ir_node *node);
492

493
494
495
/**
 * Returns non-zero for nodes that are CSE neutral to its users.
 */
Michael Beck's avatar
Michael Beck committed
496
FIRM_API int is_irn_cse_neutral(const ir_node *node);
497

498
/** Returns the string representation of the jump prediction. */
Michael Beck's avatar
Michael Beck committed
499
FIRM_API const char *get_cond_jmp_predicate_name(cond_jmp_predicate pred);
500

501
/**
502
503
 * Returns a pointer to the node attributes.
 * Used for accessing attributes of user-defined nodes.
504
 */
Michael Beck's avatar
Michael Beck committed
505
FIRM_API void *get_irn_generic_attr(ir_node *node);
506
507
508
509
/**
 * Returns a pointer to the node attributes.
 * Used for accessing attributes of user-defined nodes.
 */
Michael Beck's avatar
Michael Beck committed
510
FIRM_API const void *get_irn_generic_attr_const(const ir_node *node);
511

512
513
514
/**
 * Returns the unique node index for the node in its graph.
 * This index is used to access phase information for this node.
515
 * @see get_idx_irn()
516
 */
Michael Beck's avatar
Michael Beck committed
517
FIRM_API unsigned get_irn_idx(const ir_node *node);
518

519
520
521
522
523
524
/**
 * Sets the debug information of a node.
 *
 * @param n   The node.
 * @param db  The debug info.
 */
Michael Beck's avatar
Michael Beck committed
525
FIRM_API void set_irn_dbg_info(ir_node *n, dbg_info *db);
526
527
528
529
530
531

/**
 * Returns the debug information of an node.
 *
 * @param n   The node.
 */
Michael Beck's avatar
Michael Beck committed
532
FIRM_API dbg_info *get_irn_dbg_info(const ir_node *n);
533

534
/**
535
 * Returns a descriptive name of a node (containing type+number)
536
 */
537
FIRM_API const char *gdb_node_helper(const void *firm_object);
538

539
540
541
542
543
544
545
546
547
/**
 * @addtogroup Switch
 * @{
 */

/**
 * Creates a new switch_table datastructure with @p n_entries entries.
 * The datastructure is allocated on the obstack of @p irg.
 */
Matthias Braun's avatar
Matthias Braun committed
548
549
FIRM_API ir_switch_table *ir_new_switch_table(ir_graph *irg, size_t n_entries);

550
551
552
/**
 * Returns number of entries available in switch table @p table.
 */
Matthias Braun's avatar
Matthias Braun committed
553
554
FIRM_API size_t ir_switch_table_get_n_entries(const ir_switch_table *table);

555
556
557
558
559
560
561
562
/**
 * Sets entry number @p entry in the switch table @p table.
 * @param table  the switch table
 * @param entry  entry number to set
 * @param min    The minimum tarval that matches this entry
 * @param max    The maximum tarval that matches this entry
 * @param pn     Proj number taken on match
 */
Matthias Braun's avatar
Matthias Braun committed
563
FIRM_API void ir_switch_table_set(ir_switch_table *table, size_t entry,
564
                                  ir_tarval *min, ir_tarval *max, unsigned pn);
Matthias Braun's avatar
Matthias Braun committed
565

566
/** Returns maximum tarval value of switch table entry @p entry */
Matthias Braun's avatar
Matthias Braun committed
567
568
569
FIRM_API ir_tarval *ir_switch_table_get_max(const ir_switch_table *table,
                                            size_t entry);

570
/** Returns minimum tarval value of switch table entry @p entry */
Matthias Braun's avatar
Matthias Braun committed
571
572
573
FIRM_API ir_tarval *ir_switch_table_get_min(const ir_switch_table *table,
                                            size_t entry);

574
/** Returns proj number taken if switch table entry @p entry matches */
575
576
FIRM_API unsigned ir_switch_table_get_pn(const ir_switch_table *table,
                                         size_t entry);
Matthias Braun's avatar
Matthias Braun committed
577

578
/** Duplicates switch table @p table on obstack of @p irg */
Matthias Braun's avatar
Matthias Braun committed
579
FIRM_API ir_switch_table *ir_switch_table_duplicate(ir_graph *irg, const ir_switch_table *table);
580
/** @} */
Matthias Braun's avatar
Matthias Braun committed
581

582
/** @} */
583

584
585
#include "end.h"

Matthias Braun's avatar
Matthias Braun committed
586
#endif