2 * Copyright (C) 1995-2010 University of Karlsruhe. All right reserved.
4 * This file is part of libFirm.
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.
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.
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
22 * @brief Various irnode constructors. Automatic construction of SSA
24 * @author Martin Trapp, Christian Schaefer, Goetz Lindenmaier, Boris Boesler,
31 * documentation no more supported since 2001
33 * IR node construction.
35 * This file documents all datatypes and constructors needed to
36 * build a FIRM representation of a procedure. The constructors are
37 * also implemented in this file.
39 * The documentation also gives a short manual how to use the library.
41 * For extensive documentation of FIRM see UKA Techreport 1999-14.
44 * Three kinds of nodes
45 * --------------------
47 * There are three kinds of nodes known to the IR: entities,
50 * + ir_nodes are the actual nodes of the FIRM intermediate representation.
51 * They represent operations on the data of the program and control flow
54 * + entity ==> implemented in entity.h
55 * Refers to a single entity of the compiled program, e.g. a field of a
56 * class or a method. If a method or variable can not be assigned to
57 * a method or class or the like, it is a global object.
59 * + types ==> implemented in type.h
60 * With types type information is represented. There are several type
63 * Implementation of the FIRM operations: ir_node
64 * ----------------------------------------------
66 * Ir_nodes represent operations on the data of the program and control flow
67 * operations. Examples of ir_nodes: Add, Jmp, Cmp
69 * FIRM is a dataflow graph. A dataflow graph is a directed graph,
70 * so that every node has incoming and outgoing edges. A node is
71 * executable if every input at its incoming edges is available.
72 * Execution of the dataflow graph is started at the Start node which
73 * has no incoming edges and ends when the End node executes, even if
74 * there are still executable or not executed nodes. (Is this true,
75 * or must all executable nodes be executed?) (There are exceptions
76 * to the dataflow paradigma that all inputs have to be available
77 * before a node can execute: Phi, Block. See UKA Techreport
80 * The implementation of FIRM differs from the view as a dataflow
81 * graph. To allow fast traversion of the graph edges are
82 * implemented as C-pointers. Inputs to nodes are not ambiguous, the
83 * results can be used by several other nodes. Each input can be
84 * implemented as a single pointer to a predecessor node, outputs
85 * need to be lists of pointers to successors. Therefore a node
86 * contains pointers to its predecessors so that the implementation is a
87 * dataflow graph with reversed edges. It has to be traversed bottom
90 * All nodes of the IR have the same basic structure. They are
91 * distinguished by a field containing the opcode.
93 * The fields of an ir_node:
95 * kind A firm_kind tag containing k_ir_node. This is useful for
96 * dynamically checking the type of a node.
98 * *op This ir_op gives the opcode as a tag and a string
99 * and the number of attributes of an ir_node. There is
100 * one statically allocated struct ir_op for each opcode.
102 * *mode The ir_mode of the operation represented by this firm
103 * node. The mode of the operation is the mode of its
104 * result. A Firm mode is a datatype as known to the
105 * target, not a type of the source language.
107 * visit A flag for traversing the IR.
109 * **in An array with pointers to the node's predecessors.
111 * *link A pointer to an ir_node. With this pointer all Phi nodes
112 * are attached to a Block, i.e. a Block points to its
113 * first Phi node, this node points to the second Phi node
114 * in the Block and so forth. Used in mature_immBlock
115 * to find all Phi nodes to be matured. It's also used to
116 * annotate a node with a better, optimized version of it.
118 * attr An attr struct containing the attributes of the nodes. The
119 * attributes depend on the opcode of the node. The number
120 * of these attributes is given in op.
124 * Not yet documented. See irop.h.
128 * Not yet documented. See irmode.h.
130 * GLOBAL VARIABLES -- now also fields of ir_graph.
133 * current_ir_graph Points to the current ir_graph. All constructors for
134 * nodes add nodes to this graph.
136 * ir_visited An int used as flag to traverse the ir_graph.
138 * block_visited An int used as a flag to traverse block nodes in the
141 * Others not yet documented.
145 * CONSTRUCTOR FOR IR_GRAPH --> see irgraph.h
146 * ========================
149 * PROCEDURE TO CONSTRUCT AN IR GRAPH --> see also Firm tutorial
150 * ==================================
152 * This library supplies several interfaces to construct a FIRM graph for
154 * - A "comfortable" interface generating SSA automatically. Automatically
155 * computed predecessors of nodes need not be specified in the constructors.
156 * (new_<Node> constructurs and a set of additional routines.)
157 * - A less comfortable interface where all predecessors except the block
158 * an operation belongs to need to be specified. SSA must be constructed
159 * by hand. (new_<Node> constructors and set_cur_block()). This interface
160 * is called "block oriented". It automatically calles the local optimizations
162 * - An even less comfortable interface where the block needs to be specified
163 * explicitly. This is called the "raw" interface. (new_r_<Node>
164 * constructors). These nodes are not optimized.
166 * To use the functionality of the comfortable interface correctly the Front
167 * End needs to follow certain protocols. This is explained in the following.
168 * To build a correct IR with the other interfaces study the semantics of
169 * the firm node (See tech-reprot UKA 1999-14). For the construction of
170 * types and entities see the documentation in those modules.
172 * First the Frontend needs to decide which variables and values used in
173 * a procedure can be represented by dataflow edges. These are variables
174 * that need not be saved to memory as they cause no side effects visible
175 * out of the procedure. Often these are all compiler generated
176 * variables and simple local variables of the procedure as integers,
177 * reals and pointers. The frontend has to count and number these variables.
179 * First an ir_graph needs to be constructed with new_ir_graph. The
180 * constructor gets the number of local variables. The graph is held in the
181 * global variable irg.
183 * Now the construction of the procedure can start. Several basic blocks can
184 * be constructed in parallel, but the code within each block needs to
185 * be constructed (almost) in program order.
187 * A global variable holds the current basic block. All (non block) nodes
188 * generated are added to this block. The current block can be set with
189 * set_cur_block(block). If several blocks are constructed in parallel block
190 * switches need to be performed constantly.
192 * To generate a Block node (with the comfortable interface), its predecessor
193 * control flow nodes need not be known. In case of cyclic control flow these
194 * can not be known when the block is constructed. With add_immBlock_pred(block,
195 * cfnode) predecessors can be added to the block. If all predecessors are
196 * added to the block mature_immBlock(b) needs to be called. Calling mature_immBlock
197 * early improves the efficiency of the Phi node construction algorithm.
198 * But if several blocks are constructed at once, mature_immBlock must only
199 * be called after performing all set_values and set_stores in the block!
200 * (See documentation of new_immBlock constructor.)
202 * The constructors of arithmetic nodes require that their predecessors
203 * are mentioned. Sometimes these are available in the Frontend as the
204 * predecessors have just been generated by the frontend. If they are local
205 * values, the predecessors can be obtained from the library with a call to
206 * get_value(local_val_nr). (local_val_nr needs to be administered by
207 * the Frontend.) A call to get_value triggers the generation of Phi nodes.
208 * If an arithmetic operation produces a local value, this value needs to be
209 * passed to the library by set_value(node, local_val_nr).
210 * In straight line code these two operations just remember and return the
211 * pointer to nodes producing the value. If the value passes block boundaries
212 * Phi nodes can be inserted.
213 * Similar routines exist to manage the Memory operands: set_store and
216 * Several nodes produce more than one result. An example is the Div node.
217 * Such nodes return tuples of values. From these individual values can be
218 * extracted by proj nodes.
220 * The following example illustrates the construction of a simple basic block
221 * with two predecessors stored in variables cf_pred1 and cf_pred2, containing
224 * and finally jumping to an other block. The variable a got the local_val_nr
225 * 42 by the frontend.
227 * ir_node *this_block, *cf_pred1, *cf_pred2, *a_val, *mem, *div, *res, *cf_op;
229 * this_block = new_immBlock();
230 * add_immBlock_pred(this_block, cf_pred1);
231 * add_immBlock_pred(this_block, cf_pred2);
232 * mature_immBlock(this_block);
233 * a_val = get_value(42, mode_Iu);
235 * div = new_Div(mem, a_val, a_val, mode_Iu);
236 * mem = new_Proj(div, mode_M, pn_Div_M); * for the numbers for Proj see docu *
237 * res = new_Proj(div, mode_Iu, pn_Div_res);
239 * set_value(res, 42);
242 * For further information look at the documentation of the nodes and
243 * constructors and at the paragraph COPING WITH DATA OBJECTS at the
244 * end of this documentation.
246 * IR_NODES AND CONSTRUCTORS FOR IR_NODES
247 * =======================================
249 * All ir_nodes are defined by a common data structure. They are distinguished
250 * by their opcode and differ in the number of their attributes.
252 * Const nodes are always added to the start block.
253 * All other constructors add the created node to the current_block.
254 * swich_block(block) allows to set the current block to block.
256 * Watch for my inconsistent use of input and predecessor (dataflow view)
257 * and `the node points to' (implementation view).
259 * The following description of the nodes lists four properties them if these
261 * - the parameters to the constructor
262 * - the inputs of the Firm node
263 * - the outputs of the Firm node
264 * - attributes to the node
268 * COPING WITH DATA OBJECTS
269 * ========================
271 * Two kinds of data objects have to be distinguished for generating
272 * FIRM. First there are local variables other than arrays that are
273 * known to be alias free. Second there are all other data objects.
274 * For the first a common SSA representation is built, the second
275 * are modeled by saving them to memory. The memory is treated as
276 * a single local variable, the alias problem is hidden in the
277 * content of this variable.
279 * All values known in a Block are listed in the block's attribute,
280 * block.**graph_arr which is used to automatically insert Phi nodes.
281 * The following two functions can be used to add a newly computed value
282 * to the array, or to get the producer of a value, i.e., the current
285 * inline void set_value (int pos, ir_node *value)
286 * -----------------------------------------------
288 * Has to be called for every assignment to a local variable. It
289 * adds the value to the array of used values at position pos. Pos
290 * has to be a unique identifier for an entry in the procedure's
291 * definition table. It can be used to access the value again.
292 * Requires current_block to be set correctly.
294 * ir_node *get_value (int pos, ir_mode *mode)
295 * -------------------------------------------
297 * Returns the node defining the value referred to by pos. If the
298 * value is not defined in this block a Phi node is generated and
299 * all definitions reaching this Phi node are collected. It can
300 * happen that the algorithm allocates an unnecessary Phi node,
301 * e.g. if there is only one definition of this value, but this
302 * definition reaches the currend block on several different
303 * paths. This Phi node will be eliminated if optimizations are
304 * turned on right after its creation.
305 * Requires current_block to be set correctly.
307 * There are two special routines for the global store:
309 #ifndef FIRM_IR_IRCONS_H
310 #define FIRM_IR_IRCONS_H
312 #include "firm_types.h"
316 /** @addtogroup Const
321 * Constructor for a Const node.
323 * Adds the node to the start block.
325 * The constant represents a target value.
327 * @param *db A pointer for debug information.
328 * @param *irg The IR graph the node belongs to.
329 * @param *mode The mode of the operands and results.
330 * @param value A value from which the tarval is made.
332 FIRM_API ir_node *new_rd_Const_long(dbg_info *db, ir_graph *irg,
333 ir_mode *mode, long value);
335 /** Constructor for a Const node.
337 * Adds the node to the start block.
339 * The constant represents a target value.
341 * @param *irg The IR graph the node belongs to.
342 * @param *mode The mode of the operands and the results.
343 * @param value A value from which the tarval is made.
345 FIRM_API ir_node *new_r_Const_long(ir_graph *irg, ir_mode *mode, long value);
348 * @see new_rd_Const_long()
350 * @param *db A pointer for debug information.
351 * @param *mode The mode of the operands and results.
352 * @param value A value from which the tarval is made.
354 FIRM_API ir_node *new_d_Const_long(dbg_info *db, ir_mode *mode, long value);
357 * Make a const from a long.
358 * This is just convenience for the usual
360 * new_Const(mode, tarval_from_long(mode, ...))
363 * @param mode The mode for the const.
364 * @param value The value of the constant.
365 * @return A new const node.
367 FIRM_API ir_node *new_Const_long(ir_mode *mode, long value);
371 /** addtogroup SymConst
375 /** Constructor for a SymConst node.
377 * This is the constructor for a symbolic constant.
378 * There are several kinds of symbolic constants:
379 * - symconst_type_size The symbolic constant represents the size of a type.
380 * The type of which the constant represents the size
381 * is given explicitly.
382 * - symconst_type_align The symbolic constant represents the alignment of a
383 * type. The type of which the constant represents the
384 * size is given explicitly.
385 * - symconst_addr_ent The symbolic constant represents the address of an
386 * entity (variable or method). The variable is given
387 * explicitly by a firm entity.
388 * - symconst_ofs_ent The symbolic constant represents the offset of an
389 * entity in its owner type.
390 * - symconst_enum_const The symbolic constant is a enumeration constant of
391 * an enumeration type.
393 * Inputs to the node:
394 * No inputs except the block it belongs to.
395 * Outputs of the node.
396 * An unsigned integer (I_u) or a pointer (P).
398 * Mention union in declaration so that the firmjni generator recognizes that
399 * it can not cast the argument to an int.
401 * @param *db A pointer for debug information.
402 * @param *irg The IR graph the node belongs to.
403 * @param mode The mode for the SymConst.
404 * @param value A type, ident, entity or enum constant depending on the
406 * @param kind The kind of the symbolic constant, see the list above
408 FIRM_API ir_node *new_rd_SymConst(dbg_info *db, ir_graph *irg, ir_mode *mode,
409 union symconst_symbol value,
412 /** Constructor for a SymConst addr_ent node.
414 * Same as new_rd_SymConst, except that the constructor is tailored for
416 * Adds the SymConst to the start block of irg.
418 FIRM_API ir_node *new_rd_SymConst_addr_ent(dbg_info *db, ir_graph *irg,
419 ir_mode *mode, ir_entity *symbol);
421 /** Constructor for a SymConst ofs_ent node.
423 * Same as new_rd_SymConst, except that the constructor is tailored for
425 * Adds the SymConst to the start block of irg.
427 FIRM_API ir_node *new_rd_SymConst_ofs_ent(dbg_info *db, ir_graph *irg,
428 ir_mode *mode, ir_entity *symbol);
430 /** Constructor for a SymConst size node.
432 * Same as new_rd_SymConst, except that the constructor is tailored for
433 * symconst_type_size.
434 * Adds the SymConst to the start block of irg.
436 FIRM_API ir_node *new_rd_SymConst_size(dbg_info *db, ir_graph *irg,
437 ir_mode *mode, ir_type *symbol);
439 /** Constructor for a SymConst size node.
441 * Same as new_rd_SymConst, except that the constructor is tailored for
442 * symconst_type_align.
443 * Adds the SymConst to the start block of irg.
445 FIRM_API ir_node *new_rd_SymConst_align(dbg_info *db, ir_graph *irg,
446 ir_mode *mode, ir_type *symbol);
448 /** Constructor for a SymConst node.
450 * This is the constructor for a symbolic constant.
451 * There are several kinds of symbolic constants:
452 * - symconst_type_size The symbolic constant represents the size of a type.
453 * The type of which the constant represents the size
454 * is given explicitly.
455 * - symconst_type_align The symbolic constant represents the alignment of a
456 * type. The type of which the constant represents the
457 * size is given explicitly.
458 * - symconst_addr_ent The symbolic constant represents the address of an
459 * entity (variable or method). The variable is given
460 * explicitly by a firm entity.
461 * - symconst_ofs_ent The symbolic constant represents the offset of an
462 * entity in its owner type.
463 * - symconst_enum_const The symbolic constant is a enumeration constant of
464 * an enumeration type.
466 * Inputs to the node:
467 * No inputs except the block it belongs to.
468 * Outputs of the node.
469 * An unsigned integer (I_u) or a pointer (P).
471 * Mention union in declaration so that the firmjni generator recognizes that
472 * it can not cast the argument to an int.
474 * @param *irg The IR graph the node belongs to.
475 * @param mode The mode for the SymConst.
476 * @param value A type, ident, entity or enum constant depending on the
478 * @param kind The kind of the symbolic constant, see the list above
480 FIRM_API ir_node *new_r_SymConst(ir_graph *irg, ir_mode *mode,
481 union symconst_symbol value,
484 /** Constructor for an SymConst node
486 * This is the constructor for a symbolic constant.
487 * There are several kinds of symbolic constants:
488 * - symconst_type_size The symbolic constant represents the size of a type.
489 * The type of which the constant represents the size
490 * is given explicitly.
491 * - symconst_type_align The symbolic constant represents the alignment of a
492 * type. The type of which the constant represents the
493 * size is given explicitly.
494 * - symconst_addr_ent The symbolic constant represents the address of an
495 * entity (variable or method). The variable is given
496 * explicitly by a firm entity.
497 * - symconst_ofs_ent The symbolic constant represents the offset of an
498 * entity in its owner type.
499 * - symconst_enum_const The symbolic constant is a enumeration constant of
500 * an enumeration type.
502 * Inputs to the node:
503 * No inputs except the block it belongs to.
504 * Outputs of the node.
505 * An unsigned integer (I_u) or a pointer (P).
507 * Mention union in declaration so that the firmjni generator recognizes that
508 * it can not cast the argument to an int.
510 * @param *db A pointer for debug information.
511 * @param mode The mode for the SymConst.
512 * @param value A type, ident, entity or enum constant depending on the
514 * @param kind The kind of the symbolic constant, see the list above
516 FIRM_API ir_node *new_d_SymConst(dbg_info *db, ir_mode *mode,
517 union symconst_symbol value,
520 /** Constructor for a SymConst node.
522 * This is the constructor for a symbolic constant.
523 * There are several kinds of symbolic constants:
524 * - symconst_type_size The symbolic constant represents the size of a type.
525 * The type of which the constant represents the size
526 * is given explicitly.
527 * - symconst_type_align The symbolic constant represents the alignment of a
528 * type. The type of which the constant represents the
529 * size is given explicitly.
530 * - symconst_addr_ent The symbolic constant represents the address of an
531 * entity (variable or method). The variable is given
532 * explicitly by a firm entity.
533 * - symconst_ofs_ent The symbolic constant represents the offset of an
534 * entity in its owner type.
535 * - symconst_enum_const The symbolic constant is a enumeration constant of
536 * an enumeration type.
538 * Inputs to the node:
539 * No inputs except the block it belongs to.
540 * Outputs of the node.
541 * An unsigned integer (I_u) or a pointer (P).
543 * Mention union in declaration so that the firmjni generator recognizes that
544 * it can not cast the argument to an int.
546 * @param mode The mode for the SymConst.
547 * @param value A type, ident, entity or enum constant depending on the
549 * @param kind The kind of the symbolic constant, see the list above
551 FIRM_API ir_node *new_SymConst(ir_mode *mode, union symconst_symbol value,
560 /** Constructor for a simpleSel node.
562 * This is a shortcut for the new_rd_Sel() constructor. To be used for
563 * Sel nodes that do not select from an array, i.e., have no index
564 * inputs. It adds the two parameters 0, NULL.
566 * @param *db A pointer for debug information.
567 * @param *block The IR block the node belongs to.
568 * @param *store The memory in which the object the entity should be
569 * selected from is allocated.
570 * @param *objptr The object from that the Sel operation selects a
571 * single attribute out.
572 * @param *ent The entity to select.
574 FIRM_API ir_node *new_rd_simpleSel(dbg_info *db, ir_node *block, ir_node *store,
575 ir_node *objptr, ir_entity *ent);
577 /** Constructor for a simpleSel node.
579 * This is a shortcut for the new_d_Sel() constructor. To be used for
580 * Sel nodes that do not select from an array, i.e., have no index
581 * inputs. It adds the two parameters 0, NULL.
583 * @param *block The IR block the node belongs to.
584 * @param *store The memory in which the object the entity should be selected
586 * @param *objptr The object from that the Sel operation selects a
587 * single attribute out.
588 * @param *ent The entity to select.
591 FIRM_API ir_node *new_r_simpleSel(ir_node *block, ir_node *store,
592 ir_node *objptr, ir_entity *ent);
594 /** Constructor for a simpleSel node.
596 * This is a shortcut for the new_d_Sel() constructor. To be used for
597 * Sel nodes that do not select from an array, i.e., have no index
598 * inputs. It adds the two parameters 0, NULL.
600 * @param *db A pointer for debug information.
601 * @param *store The memory in which the object the entity should be
602 * selected from is allocated.
603 * @param *objptr The object from that the Sel operation selects a
604 * single attribute out.
605 * @param *ent The entity to select.
607 FIRM_API ir_node *new_d_simpleSel(dbg_info *db, ir_node *store, ir_node *objptr,
610 /** Constructor for a simpelSel node.
612 * This is a shortcut for the new_Sel() constructor. To be used for
613 * Sel nodes that do not select from an array, i.e., have no index
614 * inputs. It adds the two parameters 0, NULL.
616 * @param *store The memory in which the object the entity should be selected from is allocated.
617 * @param *objptr The object from that the Sel operation selects a single attribute out.
618 * @param *ent The entity to select.
620 FIRM_API ir_node *new_simpleSel(ir_node *store, ir_node *objptr,
629 /** Constructor for a remainderless Div node.
631 * @param *db A pointer for debug information.
632 * @param *block The IR block the node belongs to.
633 * @param *memop The store needed to model exceptions
634 * @param *op1 The first operand.
635 * @param *op2 The second operand.
636 * @param *mode The mode of the result.
637 * @param state The pinned state.
639 FIRM_API ir_node *new_rd_DivRL(dbg_info *db, ir_node *block, ir_node *memop,
640 ir_node *op1, ir_node *op2, ir_mode *mode,
643 /** Constructor for a remainderless Div node.
645 * @param *block The IR block the node belongs to.
646 * @param *memop The store needed to model exceptions
647 * @param *op1 The first operand.
648 * @param *op2 The second operand.
649 * @param *mode The mode of the result.
650 * @param state The pinned state.
652 FIRM_API ir_node *new_r_DivRL(ir_node *block, ir_node *memop,
653 ir_node *op1, ir_node *op2, ir_mode *mode,
656 /** Constructor for a remainderless Div node.
658 * Adds the node to the block in current_ir_block.
660 * @param *db A pointer for debug information.
661 * @param *memop The store needed to model exceptions
662 * @param *op1 The first operand.
663 * @param *op2 The second operand.
664 * @param *mode The mode of the result.
665 * @param state The pinned state.
667 FIRM_API ir_node *new_d_DivRL(dbg_info *db, ir_node *memop,
668 ir_node *op1, ir_node *op2, ir_mode *mode,
671 /** Constructor for a remainderless Div node.
673 * Adds the node to the block in current_ir_block.
675 * @param *memop The store needed to model exceptions
676 * @param *op1 The first operand.
677 * @param *op2 The second operand.
678 * @param *mode The mode of the result.
679 * @param state The pinned state.
681 FIRM_API ir_node *new_DivRL(ir_node *memop, ir_node *op1, ir_node *op2,
682 ir_mode *mode, op_pin_state state);
690 /** Constructor for an ASM pseudo node.
692 * @param *db A pointer for debug information.
693 * @param *block The block the node belong to.
694 * @param *mem memory dependency
695 * @param arity The number of data inputs to the node.
696 * @param *in The array of length arity of data inputs.
697 * @param *inputs The array of length arity of input constraints.
698 * @param n_outs The number of data outputs to the node.
699 * @param *outputs The array of length n_outs of output constraints.
700 * @param n_clobber The number of clobbered registers.
701 * @param *clobber The array of length n_clobber of clobbered registers.
702 * @param *asm_text The assembler text.
704 FIRM_API ir_node *new_rd_ASM(dbg_info *db, ir_node *block, ir_node *mem,
705 int arity, ir_node *in[], ir_asm_constraint *inputs,
706 size_t n_outs, ir_asm_constraint *outputs,
707 size_t n_clobber, ident *clobber[],
710 /** Constructor for an ASM pseudo node.
712 * @param *block The block the node belong to.
713 * @param *mem memory dependency
714 * @param arity The number of data inputs to the node.
715 * @param *in The array of length arity of data inputs.
716 * @param *inputs The array of length arity of input constraints.
717 * @param n_outs The number of data outputs to the node.
718 * @param *outputs The array of length n_outs of output constraints.
719 * @param n_clobber The number of clobbered registers.
720 * @param *clobber The array of length n_clobber of clobbered registers.
721 * @param *asm_text The assembler text.
723 FIRM_API ir_node *new_r_ASM(ir_node *block, ir_node *mem,
724 int arity, ir_node *in[], ir_asm_constraint *inputs,
725 size_t n_outs, ir_asm_constraint *outputs,
726 size_t n_clobber, ident *clobber[],
729 /** Constructor for an ASM pseudo node.
731 * @param *db A pointer for debug information.
732 * @param *mem memory dependency
733 * @param arity The number of data inputs to the node.
734 * @param *in The array of length arity of data inputs.
735 * @param *inputs The array of length arity of input constraints.
736 * @param n_outs The number of data outputs to the node.
737 * @param *outputs The array of length n_outs of output constraints.
738 * @param n_clobber The number of clobbered registers.
739 * @param *clobber The array of length n_clobber of clobbered registers.
740 * @param *asm_text The assembler text.
743 FIRM_API ir_node *new_d_ASM(dbg_info *db, ir_node *mem, int arity,
744 ir_node *in[], ir_asm_constraint *inputs,
745 size_t n_outs, ir_asm_constraint *outputs,
746 size_t n_clobber, ident *clobber[],
749 /** Constructor for an ASM pseudo node.
751 * @param *mem memory dependency
752 * @param arity The number of data inputs to the node.
753 * @param *in The array of length arity of data inputs.
754 * @param *inputs The array of length arity of input constraints.
755 * @param n_outs The number of data outputs to the node.
756 * @param *outputs The array of length n_outs of output constraints.
757 * @param n_clobber The number of clobbered registers.
758 * @param *clobber The array of length n_clobber of clobbered registers.
759 * @param *asm_text The assembler text.
762 FIRM_API ir_node *new_ASM(ir_node *mem, int arity, ir_node *in[],
763 ir_asm_constraint *inputs, size_t n_outs,
764 ir_asm_constraint *outputs,
765 size_t n_clobber, ident *clobber[], ident *asm_text);
771 * @defgroup ir_cons Construction Support
776 * Global variable holding the graph which is currently constructed.
778 FIRM_API ir_graph *current_ir_graph;
781 * Returns graph which is currently constructed
783 FIRM_API ir_graph *get_current_ir_graph(void);
786 * Sets graph which is currently constructed
788 FIRM_API void set_current_ir_graph(ir_graph *graph);
790 /** Create an immature Block.
792 * An immature Block has an unknown number of predecessors. Predecessors
793 * can be added with add_immBlock_pred(). Once all predecessors are
794 * added the block must be matured.
796 * Adds the block to the graph in current_ir_graph.
797 * This constructor can only be used if the graph is in state_building.
799 FIRM_API ir_node *new_d_immBlock(dbg_info *db);
800 /** Create an immature Block.
802 * An immature Block has an unknown number of predecessors. Predecessors
803 * can be added with add_immBlock_pred(). Once all predecessors are
804 * added the block must be matured.
806 * Adds the block to the graph in current_ir_graph.
807 * This constructor can only be used if the graph is in state_building.
809 FIRM_API ir_node *new_immBlock(void);
810 /** Create an immature Block.
812 * An immature Block has an unknown number of predecessors. Predecessors
813 * can be added with add_immBlock_pred(). Once all predecessors are
814 * added the block must be matured.
816 * This constructor can only be used if the graph is in state_building.
818 FIRM_API ir_node *new_r_immBlock(ir_graph *irg);
819 /** Create an immature Block.
821 * An immature Block has an unknown number of predecessors. Predecessors
822 * can be added with add_immBlock_pred(). Once all predecessors are
823 * added the block must be matured.
825 * This constructor can only be used if the graph is in state_building.
827 FIRM_API ir_node *new_rd_immBlock(dbg_info *db, ir_graph *irg);
829 /** Add a control flow edge to an immature block. */
830 FIRM_API void add_immBlock_pred(ir_node *immblock, ir_node *jmp);
832 /** Finalize a Block node, when all control flows are known. */
833 FIRM_API void mature_immBlock(ir_node *block);
836 * Sets the current block in which the following constructors place the
837 * nodes they construct.
839 * @param target The new current block.
841 FIRM_API void set_cur_block(ir_node *target);
843 * Sets current block of a given graph.
844 * @see set_cur_block()
846 FIRM_API void set_r_cur_block(ir_graph *irg, ir_node *target);
848 /** Returns the current block of the current graph. */
849 FIRM_API ir_node *get_cur_block(void);
850 /** Returns current block of a given graph */
851 FIRM_API ir_node *get_r_cur_block(ir_graph *irg);
853 /** Returns the current value of a local variable.
855 * Use this function to obtain the last definition of the local variable
856 * associated with pos. pos must be less than the value passed as n_loc
857 * to new_ir_graph. This call automatically inserts Phi nodes.
859 * @param pos The position/id of the local variable.
860 * @param *mode The mode of the value to get.
862 FIRM_API ir_node *get_value(int pos, ir_mode *mode);
863 /** Returns the current value of a local variable in given graph
864 * @see get_value() */
865 FIRM_API ir_node *get_r_value(ir_graph *irg, int pos, ir_mode *mode);
868 * Try to guess the mode of a local variable.
869 * This is done by recursively going up the control flow graph until
870 * we find a definition for the variable. The mode of the first found
871 * definition is returned. NULL in case no definition is found.
873 * @param pos The position/id of the local variable.
875 FIRM_API ir_mode *ir_guess_mode(int pos);
877 * Try to guess the mode of a local variable in a given graph.
879 FIRM_API ir_mode *ir_r_guess_mode(ir_graph *irg, int pos);
881 /** Memorize a new definition of a variable.
883 * Use this function to remember a new definition of the value
884 * associated with pos. pos must be less than the value passed as n_loc
885 * to new_ir_graph. This call is needed to automatically inserts Phi
888 * @param pos The position/id of the local variable.
889 * @param *value The new value written to the local variable.
891 FIRM_API void set_value(int pos, ir_node *value);
892 /** Sets current value of a variable in a given graph */
893 FIRM_API void set_r_value(ir_graph *irg, int pos, ir_node *value);
895 /** Returns the current memory state.
897 * Use this function to obtain the last definition of the memory
898 * state. This call automatically inserts Phi nodes for the memory
901 FIRM_API ir_node *get_store(void);
902 /** Returns current memory state for a given graph
903 * @see get_store() */
904 FIRM_API ir_node *get_r_store(ir_graph *irg);
906 /** Memorize a new definition of the memory state.
908 * Use this function to remember a new definition of the memory state.
909 * This call is needed to automatically inserts Phi nodes.
911 * @param *store The new memory state.
913 FIRM_API void set_store(ir_node *store);
914 /** Sets current memory state for a given graph
915 * @see set_store() */
916 FIRM_API void set_r_store(ir_graph *irg, ir_node *store);
918 /** keep this node alive even if End is not control-reachable from it
920 * @param ka The node to keep alive.
922 FIRM_API void keep_alive(ir_node *ka);
924 /** Puts the graph into state "phase_high" */
925 FIRM_API void irg_finalize_cons(ir_graph *irg);
927 /** Puts the program and all graphs into state phase_high.
929 * This also remarks, the construction of types is finished,
930 * e.g., that no more subtypes will be added. */
931 FIRM_API void irp_finalize_cons(void);
934 * Register a new callback for the case that the value of an uninitialized
935 * variable is requested.
937 FIRM_API void ir_set_uninitialized_local_variable_func(
938 uninitialized_local_variable_func_t *func);