2 * This file is part of libFirm.
3 * Copyright (C) 2012 University of Karlsruhe.
8 * @brief Various irnode constructors. Automatic construction of SSA
10 * @author Martin Trapp, Christian Schaefer, Goetz Lindenmaier, Boris Boesler,
17 * documentation no more supported since 2001
19 * IR node construction.
21 * This file documents all datatypes and constructors needed to
22 * build a FIRM representation of a procedure. The constructors are
23 * also implemented in this file.
25 * The documentation also gives a short manual how to use the library.
27 * For extensive documentation of FIRM see UKA Techreport 1999-14.
30 * Three kinds of nodes
31 * --------------------
33 * There are three kinds of nodes known to the IR: entities,
36 * + ir_nodes are the actual nodes of the FIRM intermediate representation.
37 * They represent operations on the data of the program and control flow
40 * + entity ==> implemented in entity.h
41 * Refers to a single entity of the compiled program, e.g. a field of a
42 * class or a method. If a method or variable can not be assigned to
43 * a method or class or the like, it is a global object.
45 * + types ==> implemented in type.h
46 * With types type information is represented. There are several type
49 * Implementation of the FIRM operations: ir_node
50 * ----------------------------------------------
52 * Ir_nodes represent operations on the data of the program and control flow
53 * operations. Examples of ir_nodes: Add, Jmp, Cmp
55 * FIRM is a dataflow graph. A dataflow graph is a directed graph,
56 * so that every node has incoming and outgoing edges. A node is
57 * executable if every input at its incoming edges is available.
58 * Execution of the dataflow graph is started at the Start node which
59 * has no incoming edges and ends when the End node executes, even if
60 * there are still executable or not executed nodes. (Is this true,
61 * or must all executable nodes be executed?) (There are exceptions
62 * to the dataflow paradigma that all inputs have to be available
63 * before a node can execute: Phi, Block. See UKA Techreport
66 * The implementation of FIRM differs from the view as a dataflow
67 * graph. To allow fast traversion of the graph edges are
68 * implemented as C-pointers. Inputs to nodes are not ambiguous, the
69 * results can be used by several other nodes. Each input can be
70 * implemented as a single pointer to a predecessor node, outputs
71 * need to be lists of pointers to successors. Therefore a node
72 * contains pointers to its predecessors so that the implementation is a
73 * dataflow graph with reversed edges. It has to be traversed bottom
76 * All nodes of the IR have the same basic structure. They are
77 * distinguished by a field containing the opcode.
79 * The fields of an ir_node:
81 * kind A firm_kind tag containing k_ir_node. This is useful for
82 * dynamically checking the type of a node.
84 * *op This ir_op gives the opcode as a tag and a string
85 * and the number of attributes of an ir_node. There is
86 * one statically allocated struct ir_op for each opcode.
88 * *mode The ir_mode of the operation represented by this firm
89 * node. The mode of the operation is the mode of its
90 * result. A Firm mode is a datatype as known to the
91 * target, not a type of the source language.
93 * visit A flag for traversing the IR.
95 * **in An array with pointers to the node's predecessors.
97 * *link A pointer to an ir_node. With this pointer all Phi nodes
98 * are attached to a Block, i.e. a Block points to its
99 * first Phi node, this node points to the second Phi node
100 * in the Block and so forth. Used in mature_immBlock
101 * to find all Phi nodes to be matured. It's also used to
102 * annotate a node with a better, optimized version of it.
104 * attr An attr struct containing the attributes of the nodes. The
105 * attributes depend on the opcode of the node. The number
106 * of these attributes is given in op.
110 * Not yet documented. See irop.h.
114 * Not yet documented. See irmode.h.
116 * GLOBAL VARIABLES -- now also fields of ir_graph.
119 * current_ir_graph Points to the current ir_graph. All constructors for
120 * nodes add nodes to this graph.
122 * ir_visited An int used as flag to traverse the ir_graph.
124 * block_visited An int used as a flag to traverse block nodes in the
127 * Others not yet documented.
131 * CONSTRUCTOR FOR IR_GRAPH --> see irgraph.h
132 * ========================
135 * PROCEDURE TO CONSTRUCT AN IR GRAPH --> see also Firm tutorial
136 * ==================================
138 * This library supplies several interfaces to construct a FIRM graph for
140 * - A "comfortable" interface generating SSA automatically. Automatically
141 * computed predecessors of nodes need not be specified in the constructors.
142 * (new_<Node> constructurs and a set of additional routines.)
143 * - A less comfortable interface where all predecessors except the block
144 * an operation belongs to need to be specified. SSA must be constructed
145 * by hand. (new_<Node> constructors and set_cur_block()). This interface
146 * is called "block oriented". It automatically calles the local optimizations
148 * - An even less comfortable interface where the block needs to be specified
149 * explicitly. This is called the "raw" interface. (new_r_<Node>
150 * constructors). These nodes are not optimized.
152 * To use the functionality of the comfortable interface correctly the Front
153 * End needs to follow certain protocols. This is explained in the following.
154 * To build a correct IR with the other interfaces study the semantics of
155 * the firm node (See tech-reprot UKA 1999-14). For the construction of
156 * types and entities see the documentation in those modules.
158 * First the Frontend needs to decide which variables and values used in
159 * a procedure can be represented by dataflow edges. These are variables
160 * that need not be saved to memory as they cause no side effects visible
161 * out of the procedure. Often these are all compiler generated
162 * variables and simple local variables of the procedure as integers,
163 * reals and pointers. The frontend has to count and number these variables.
165 * First an ir_graph needs to be constructed with new_ir_graph. The
166 * constructor gets the number of local variables. The graph is held in the
167 * global variable irg.
169 * Now the construction of the procedure can start. Several basic blocks can
170 * be constructed in parallel, but the code within each block needs to
171 * be constructed (almost) in program order.
173 * A global variable holds the current basic block. All (non block) nodes
174 * generated are added to this block. The current block can be set with
175 * set_cur_block(block). If several blocks are constructed in parallel block
176 * switches need to be performed constantly.
178 * To generate a Block node (with the comfortable interface), its predecessor
179 * control flow nodes need not be known. In case of cyclic control flow these
180 * can not be known when the block is constructed. With add_immBlock_pred(block,
181 * cfnode) predecessors can be added to the block. If all predecessors are
182 * added to the block mature_immBlock(b) needs to be called. Calling mature_immBlock
183 * early improves the efficiency of the Phi node construction algorithm.
184 * But if several blocks are constructed at once, mature_immBlock must only
185 * be called after performing all set_values and set_stores in the block!
186 * (See documentation of new_immBlock constructor.)
188 * The constructors of arithmetic nodes require that their predecessors
189 * are mentioned. Sometimes these are available in the Frontend as the
190 * predecessors have just been generated by the frontend. If they are local
191 * values, the predecessors can be obtained from the library with a call to
192 * get_value(local_val_nr). (local_val_nr needs to be administered by
193 * the Frontend.) A call to get_value triggers the generation of Phi nodes.
194 * If an arithmetic operation produces a local value, this value needs to be
195 * passed to the library by set_value(node, local_val_nr).
196 * In straight line code these two operations just remember and return the
197 * pointer to nodes producing the value. If the value passes block boundaries
198 * Phi nodes can be inserted.
199 * Similar routines exist to manage the Memory operands: set_store and
202 * Several nodes produce more than one result. An example is the Div node.
203 * Such nodes return tuples of values. From these individual values can be
204 * extracted by proj nodes.
206 * The following example illustrates the construction of a simple basic block
207 * with two predecessors stored in variables cf_pred1 and cf_pred2, containing
210 * and finally jumping to an other block. The variable a got the local_val_nr
211 * 42 by the frontend.
213 * ir_node *this_block, *cf_pred1, *cf_pred2, *a_val, *mem, *div, *res, *cf_op;
215 * this_block = new_immBlock();
216 * add_immBlock_pred(this_block, cf_pred1);
217 * add_immBlock_pred(this_block, cf_pred2);
218 * mature_immBlock(this_block);
219 * a_val = get_value(42, mode_Iu);
221 * div = new_Div(mem, a_val, a_val, mode_Iu);
222 * mem = new_Proj(div, mode_M, pn_Div_M); * for the numbers for Proj see docu *
223 * res = new_Proj(div, mode_Iu, pn_Div_res);
225 * set_value(res, 42);
228 * For further information look at the documentation of the nodes and
229 * constructors and at the paragraph COPING WITH DATA OBJECTS at the
230 * end of this documentation.
232 * IR_NODES AND CONSTRUCTORS FOR IR_NODES
233 * =======================================
235 * All ir_nodes are defined by a common data structure. They are distinguished
236 * by their opcode and differ in the number of their attributes.
238 * Const nodes are always added to the start block.
239 * All other constructors add the created node to the current_block.
240 * swich_block(block) allows to set the current block to block.
242 * Watch for my inconsistent use of input and predecessor (dataflow view)
243 * and `the node points to' (implementation view).
245 * The following description of the nodes lists four properties them if these
247 * - the parameters to the constructor
248 * - the inputs of the Firm node
249 * - the outputs of the Firm node
250 * - attributes to the node
254 * COPING WITH DATA OBJECTS
255 * ========================
257 * Two kinds of data objects have to be distinguished for generating
258 * FIRM. First there are local variables other than arrays that are
259 * known to be alias free. Second there are all other data objects.
260 * For the first a common SSA representation is built, the second
261 * are modeled by saving them to memory. The memory is treated as
262 * a single local variable, the alias problem is hidden in the
263 * content of this variable.
265 * All values known in a Block are listed in the block's attribute,
266 * block.**graph_arr which is used to automatically insert Phi nodes.
267 * The following two functions can be used to add a newly computed value
268 * to the array, or to get the producer of a value, i.e., the current
271 * inline void set_value (int pos, ir_node *value)
272 * -----------------------------------------------
274 * Has to be called for every assignment to a local variable. It
275 * adds the value to the array of used values at position pos. Pos
276 * has to be a unique identifier for an entry in the procedure's
277 * definition table. It can be used to access the value again.
278 * Requires current_block to be set correctly.
280 * ir_node *get_value (int pos, ir_mode *mode)
281 * -------------------------------------------
283 * Returns the node defining the value referred to by pos. If the
284 * value is not defined in this block a Phi node is generated and
285 * all definitions reaching this Phi node are collected. It can
286 * happen that the algorithm allocates an unnecessary Phi node,
287 * e.g. if there is only one definition of this value, but this
288 * definition reaches the currend block on several different
289 * paths. This Phi node will be eliminated if optimizations are
290 * turned on right after its creation.
291 * Requires current_block to be set correctly.
293 * There are two special routines for the global store:
295 #ifndef FIRM_IR_IRCONS_H
296 #define FIRM_IR_IRCONS_H
298 #include "firm_types.h"
302 /** @addtogroup Const
307 * Constructor for a Const node.
309 * Adds the node to the start block.
311 * The constant represents a target value.
313 * @param *db A pointer for debug information.
314 * @param *irg The IR graph the node belongs to.
315 * @param *mode The mode of the operands and results.
316 * @param value A value from which the tarval is made.
318 FIRM_API ir_node *new_rd_Const_long(dbg_info *db, ir_graph *irg,
319 ir_mode *mode, long value);
321 /** Constructor for a Const node.
323 * Adds the node to the start block.
325 * The constant represents a target value.
327 * @param *irg The IR graph the node belongs to.
328 * @param *mode The mode of the operands and the results.
329 * @param value A value from which the tarval is made.
331 FIRM_API ir_node *new_r_Const_long(ir_graph *irg, ir_mode *mode, long value);
334 * @see new_rd_Const_long()
336 * @param *db A pointer for debug information.
337 * @param *mode The mode of the operands and results.
338 * @param value A value from which the tarval is made.
340 FIRM_API ir_node *new_d_Const_long(dbg_info *db, ir_mode *mode, long value);
343 * Make a const from a long.
344 * This is just convenience for the usual
346 * new_Const(mode, tarval_from_long(mode, ...))
349 * @param mode The mode for the const.
350 * @param value The value of the constant.
351 * @return A new const node.
353 FIRM_API ir_node *new_Const_long(ir_mode *mode, long value);
357 /** addtogroup SymConst
361 /** Constructor for a SymConst node.
363 * This is the constructor for a symbolic constant.
364 * There are several kinds of symbolic constants:
365 * - symconst_type_size The symbolic constant represents the size of a type.
366 * The type of which the constant represents the size
367 * is given explicitly.
368 * - symconst_type_align The symbolic constant represents the alignment of a
369 * type. The type of which the constant represents the
370 * size is given explicitly.
371 * - symconst_addr_ent The symbolic constant represents the address of an
372 * entity (variable or method). The variable is given
373 * explicitly by a firm entity.
374 * - symconst_ofs_ent The symbolic constant represents the offset of an
375 * entity in its owner type.
376 * - symconst_enum_const The symbolic constant is a enumeration constant of
377 * an enumeration type.
379 * Inputs to the node:
380 * No inputs except the block it belongs to.
381 * Outputs of the node.
382 * An unsigned integer (I_u) or a pointer (P).
384 * Mention union in declaration so that the firmjni generator recognizes that
385 * it can not cast the argument to an int.
387 * @param *db A pointer for debug information.
388 * @param *irg The IR graph the node belongs to.
389 * @param mode The mode for the SymConst.
390 * @param value A type, ident, entity or enum constant depending on the
392 * @param kind The kind of the symbolic constant, see the list above
394 FIRM_API ir_node *new_rd_SymConst(dbg_info *db, ir_graph *irg, ir_mode *mode,
395 union symconst_symbol value,
398 /** Constructor for a SymConst addr_ent node.
400 * Same as new_rd_SymConst, except that the constructor is tailored for
402 * Adds the SymConst to the start block of irg.
404 FIRM_API ir_node *new_rd_SymConst_addr_ent(dbg_info *db, ir_graph *irg,
405 ir_mode *mode, ir_entity *symbol);
407 /** Constructor for a SymConst ofs_ent node.
409 * Same as new_rd_SymConst, except that the constructor is tailored for
411 * Adds the SymConst to the start block of irg.
413 FIRM_API ir_node *new_rd_SymConst_ofs_ent(dbg_info *db, ir_graph *irg,
414 ir_mode *mode, ir_entity *symbol);
416 /** Constructor for a SymConst size node.
418 * Same as new_rd_SymConst, except that the constructor is tailored for
419 * symconst_type_size.
420 * Adds the SymConst to the start block of irg.
422 FIRM_API ir_node *new_rd_SymConst_size(dbg_info *db, ir_graph *irg,
423 ir_mode *mode, ir_type *symbol);
425 /** Constructor for a SymConst size node.
427 * Same as new_rd_SymConst, except that the constructor is tailored for
428 * symconst_type_align.
429 * Adds the SymConst to the start block of irg.
431 FIRM_API ir_node *new_rd_SymConst_align(dbg_info *db, ir_graph *irg,
432 ir_mode *mode, ir_type *symbol);
434 /** Constructor for a SymConst node.
436 * This is the constructor for a symbolic constant.
437 * There are several kinds of symbolic constants:
438 * - symconst_type_size The symbolic constant represents the size of a type.
439 * The type of which the constant represents the size
440 * is given explicitly.
441 * - symconst_type_align The symbolic constant represents the alignment of a
442 * type. The type of which the constant represents the
443 * size is given explicitly.
444 * - symconst_addr_ent The symbolic constant represents the address of an
445 * entity (variable or method). The variable is given
446 * explicitly by a firm entity.
447 * - symconst_ofs_ent The symbolic constant represents the offset of an
448 * entity in its owner type.
449 * - symconst_enum_const The symbolic constant is a enumeration constant of
450 * an enumeration type.
452 * Inputs to the node:
453 * No inputs except the block it belongs to.
454 * Outputs of the node.
455 * An unsigned integer (I_u) or a pointer (P).
457 * Mention union in declaration so that the firmjni generator recognizes that
458 * it can not cast the argument to an int.
460 * @param *irg The IR graph the node belongs to.
461 * @param mode The mode for the SymConst.
462 * @param value A type, ident, entity or enum constant depending on the
464 * @param kind The kind of the symbolic constant, see the list above
466 FIRM_API ir_node *new_r_SymConst(ir_graph *irg, ir_mode *mode,
467 union symconst_symbol value,
470 /** Constructor for an SymConst node
472 * This is the constructor for a symbolic constant.
473 * There are several kinds of symbolic constants:
474 * - symconst_type_size The symbolic constant represents the size of a type.
475 * The type of which the constant represents the size
476 * is given explicitly.
477 * - symconst_type_align The symbolic constant represents the alignment of a
478 * type. The type of which the constant represents the
479 * size is given explicitly.
480 * - symconst_addr_ent The symbolic constant represents the address of an
481 * entity (variable or method). The variable is given
482 * explicitly by a firm entity.
483 * - symconst_ofs_ent The symbolic constant represents the offset of an
484 * entity in its owner type.
485 * - symconst_enum_const The symbolic constant is a enumeration constant of
486 * an enumeration type.
488 * Inputs to the node:
489 * No inputs except the block it belongs to.
490 * Outputs of the node.
491 * An unsigned integer (I_u) or a pointer (P).
493 * Mention union in declaration so that the firmjni generator recognizes that
494 * it can not cast the argument to an int.
496 * @param *db A pointer for debug information.
497 * @param mode The mode for the SymConst.
498 * @param value A type, ident, entity or enum constant depending on the
500 * @param kind The kind of the symbolic constant, see the list above
502 FIRM_API ir_node *new_d_SymConst(dbg_info *db, ir_mode *mode,
503 union symconst_symbol value,
506 /** Constructor for a SymConst node.
508 * This is the constructor for a symbolic constant.
509 * There are several kinds of symbolic constants:
510 * - symconst_type_size The symbolic constant represents the size of a type.
511 * The type of which the constant represents the size
512 * is given explicitly.
513 * - symconst_type_align The symbolic constant represents the alignment of a
514 * type. The type of which the constant represents the
515 * size is given explicitly.
516 * - symconst_addr_ent The symbolic constant represents the address of an
517 * entity (variable or method). The variable is given
518 * explicitly by a firm entity.
519 * - symconst_ofs_ent The symbolic constant represents the offset of an
520 * entity in its owner type.
521 * - symconst_enum_const The symbolic constant is a enumeration constant of
522 * an enumeration type.
524 * Inputs to the node:
525 * No inputs except the block it belongs to.
526 * Outputs of the node.
527 * An unsigned integer (I_u) or a pointer (P).
529 * Mention union in declaration so that the firmjni generator recognizes that
530 * it can not cast the argument to an int.
532 * @param mode The mode for the SymConst.
533 * @param value A type, ident, entity or enum constant depending on the
535 * @param kind The kind of the symbolic constant, see the list above
537 FIRM_API ir_node *new_SymConst(ir_mode *mode, union symconst_symbol value,
546 /** Constructor for a simpleSel node.
548 * This is a shortcut for the new_rd_Sel() constructor. To be used for
549 * Sel nodes that do not select from an array, i.e., have no index
550 * inputs. It adds the two parameters 0, NULL.
552 * @param *db A pointer for debug information.
553 * @param *block The IR block the node belongs to.
554 * @param *store The memory in which the object the entity should be
555 * selected from is allocated.
556 * @param *objptr The object from that the Sel operation selects a
557 * single attribute out.
558 * @param *ent The entity to select.
560 FIRM_API ir_node *new_rd_simpleSel(dbg_info *db, ir_node *block, ir_node *store,
561 ir_node *objptr, ir_entity *ent);
563 /** Constructor for a simpleSel node.
565 * This is a shortcut for the new_d_Sel() constructor. To be used for
566 * Sel nodes that do not select from an array, i.e., have no index
567 * inputs. It adds the two parameters 0, NULL.
569 * @param *block The IR block the node belongs to.
570 * @param *store The memory in which the object the entity should be selected
572 * @param *objptr The object from that the Sel operation selects a
573 * single attribute out.
574 * @param *ent The entity to select.
577 FIRM_API ir_node *new_r_simpleSel(ir_node *block, ir_node *store,
578 ir_node *objptr, ir_entity *ent);
580 /** Constructor for a simpleSel node.
582 * This is a shortcut for the new_d_Sel() constructor. To be used for
583 * Sel nodes that do not select from an array, i.e., have no index
584 * inputs. It adds the two parameters 0, NULL.
586 * @param *db A pointer for debug information.
587 * @param *store The memory in which the object the entity should be
588 * selected from is allocated.
589 * @param *objptr The object from that the Sel operation selects a
590 * single attribute out.
591 * @param *ent The entity to select.
593 FIRM_API ir_node *new_d_simpleSel(dbg_info *db, ir_node *store, ir_node *objptr,
596 /** Constructor for a simpelSel node.
598 * This is a shortcut for the new_Sel() constructor. To be used for
599 * Sel nodes that do not select from an array, i.e., have no index
600 * inputs. It adds the two parameters 0, NULL.
602 * @param *store The memory in which the object the entity should be selected from is allocated.
603 * @param *objptr The object from that the Sel operation selects a single attribute out.
604 * @param *ent The entity to select.
606 FIRM_API ir_node *new_simpleSel(ir_node *store, ir_node *objptr,
615 /** Constructor for a remainderless Div node.
617 * @param *db A pointer for debug information.
618 * @param *block The IR block the node belongs to.
619 * @param *memop The store needed to model exceptions
620 * @param *op1 The first operand.
621 * @param *op2 The second operand.
622 * @param *mode The mode of the result.
623 * @param state The pinned state.
625 FIRM_API ir_node *new_rd_DivRL(dbg_info *db, ir_node *block, ir_node *memop,
626 ir_node *op1, ir_node *op2, ir_mode *mode,
629 /** Constructor for a remainderless Div node.
631 * @param *block The IR block the node belongs to.
632 * @param *memop The store needed to model exceptions
633 * @param *op1 The first operand.
634 * @param *op2 The second operand.
635 * @param *mode The mode of the result.
636 * @param state The pinned state.
638 FIRM_API ir_node *new_r_DivRL(ir_node *block, ir_node *memop,
639 ir_node *op1, ir_node *op2, ir_mode *mode,
642 /** Constructor for a remainderless Div node.
644 * Adds the node to the block in current_ir_block.
646 * @param *db A pointer for debug information.
647 * @param *memop The store needed to model exceptions
648 * @param *op1 The first operand.
649 * @param *op2 The second operand.
650 * @param *mode The mode of the result.
651 * @param state The pinned state.
653 FIRM_API ir_node *new_d_DivRL(dbg_info *db, ir_node *memop,
654 ir_node *op1, ir_node *op2, ir_mode *mode,
657 /** Constructor for a remainderless Div node.
659 * Adds the node to the block in current_ir_block.
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_DivRL(ir_node *memop, ir_node *op1, ir_node *op2,
668 ir_mode *mode, op_pin_state state);
676 /** Constructor for an ASM pseudo node.
678 * @param *db A pointer for debug information.
679 * @param *block The block the node belong to.
680 * @param *mem memory dependency
681 * @param arity The number of data inputs to the node.
682 * @param *in The array of length arity of data inputs.
683 * @param *inputs The array of length arity of input constraints.
684 * @param n_outs The number of data outputs to the node.
685 * @param *outputs The array of length n_outs of output constraints.
686 * @param n_clobber The number of clobbered registers.
687 * @param *clobber The array of length n_clobber of clobbered registers.
688 * @param *asm_text The assembler text.
690 FIRM_API ir_node *new_rd_ASM(dbg_info *db, ir_node *block, ir_node *mem,
691 int arity, ir_node *in[], ir_asm_constraint *inputs,
692 size_t n_outs, ir_asm_constraint *outputs,
693 size_t n_clobber, ident *clobber[],
696 /** Constructor for an ASM pseudo node.
698 * @param *block The block the node belong to.
699 * @param *mem memory dependency
700 * @param arity The number of data inputs to the node.
701 * @param *in The array of length arity of data inputs.
702 * @param *inputs The array of length arity of input constraints.
703 * @param n_outs The number of data outputs to the node.
704 * @param *outputs The array of length n_outs of output constraints.
705 * @param n_clobber The number of clobbered registers.
706 * @param *clobber The array of length n_clobber of clobbered registers.
707 * @param *asm_text The assembler text.
709 FIRM_API ir_node *new_r_ASM(ir_node *block, ir_node *mem,
710 int arity, ir_node *in[], ir_asm_constraint *inputs,
711 size_t n_outs, ir_asm_constraint *outputs,
712 size_t n_clobber, ident *clobber[],
715 /** Constructor for an ASM pseudo node.
717 * @param *db A pointer for debug information.
718 * @param *mem memory dependency
719 * @param arity The number of data inputs to the node.
720 * @param *in The array of length arity of data inputs.
721 * @param *inputs The array of length arity of input constraints.
722 * @param n_outs The number of data outputs to the node.
723 * @param *outputs The array of length n_outs of output constraints.
724 * @param n_clobber The number of clobbered registers.
725 * @param *clobber The array of length n_clobber of clobbered registers.
726 * @param *asm_text The assembler text.
729 FIRM_API ir_node *new_d_ASM(dbg_info *db, ir_node *mem, int arity,
730 ir_node *in[], ir_asm_constraint *inputs,
731 size_t n_outs, ir_asm_constraint *outputs,
732 size_t n_clobber, ident *clobber[],
735 /** Constructor for an ASM pseudo node.
737 * @param *mem memory dependency
738 * @param arity The number of data inputs to the node.
739 * @param *in The array of length arity of data inputs.
740 * @param *inputs The array of length arity of input constraints.
741 * @param n_outs The number of data outputs to the node.
742 * @param *outputs The array of length n_outs of output constraints.
743 * @param n_clobber The number of clobbered registers.
744 * @param *clobber The array of length n_clobber of clobbered registers.
745 * @param *asm_text The assembler text.
748 FIRM_API ir_node *new_ASM(ir_node *mem, int arity, ir_node *in[],
749 ir_asm_constraint *inputs, size_t n_outs,
750 ir_asm_constraint *outputs,
751 size_t n_clobber, ident *clobber[], ident *asm_text);
757 * @defgroup ir_cons Construction Support
762 * Global variable holding the graph which is currently constructed.
764 FIRM_API ir_graph *current_ir_graph;
767 * Returns graph which is currently constructed
769 FIRM_API ir_graph *get_current_ir_graph(void);
772 * Sets graph which is currently constructed
774 FIRM_API void set_current_ir_graph(ir_graph *graph);
776 /** Create an immature Block.
778 * An immature Block has an unknown number of predecessors. Predecessors
779 * can be added with add_immBlock_pred(). Once all predecessors are
780 * added the block must be matured.
782 * Adds the block to the graph in current_ir_graph.
783 * This constructor can only be used if the graph is in state_building.
785 FIRM_API ir_node *new_d_immBlock(dbg_info *db);
786 /** Create an immature Block.
788 * An immature Block has an unknown number of predecessors. Predecessors
789 * can be added with add_immBlock_pred(). Once all predecessors are
790 * added the block must be matured.
792 * Adds the block to the graph in current_ir_graph.
793 * This constructor can only be used if the graph is in state_building.
795 FIRM_API ir_node *new_immBlock(void);
796 /** Create an immature Block.
798 * An immature Block has an unknown number of predecessors. Predecessors
799 * can be added with add_immBlock_pred(). Once all predecessors are
800 * added the block must be matured.
802 * This constructor can only be used if the graph is in state_building.
804 FIRM_API ir_node *new_r_immBlock(ir_graph *irg);
805 /** Create an immature Block.
807 * An immature Block has an unknown number of predecessors. Predecessors
808 * can be added with add_immBlock_pred(). Once all predecessors are
809 * added the block must be matured.
811 * This constructor can only be used if the graph is in state_building.
813 FIRM_API ir_node *new_rd_immBlock(dbg_info *db, ir_graph *irg);
815 /** Add a control flow edge to an immature block. */
816 FIRM_API void add_immBlock_pred(ir_node *immblock, ir_node *jmp);
818 /** Finalize a Block node, when all control flows are known. */
819 FIRM_API void mature_immBlock(ir_node *block);
822 * Sets the current block in which the following constructors place the
823 * nodes they construct.
825 * @param target The new current block.
827 FIRM_API void set_cur_block(ir_node *target);
829 * Sets current block of a given graph.
830 * @see set_cur_block()
832 FIRM_API void set_r_cur_block(ir_graph *irg, ir_node *target);
834 /** Returns the current block of the current graph. */
835 FIRM_API ir_node *get_cur_block(void);
836 /** Returns current block of a given graph */
837 FIRM_API ir_node *get_r_cur_block(ir_graph *irg);
839 /** Returns the current value of a local variable.
841 * Use this function to obtain the last definition of the local variable
842 * associated with pos. pos must be less than the value passed as n_loc
843 * to new_ir_graph. This call automatically inserts Phi nodes.
845 * @param pos The position/id of the local variable.
846 * @param *mode The mode of the value to get.
848 FIRM_API ir_node *get_value(int pos, ir_mode *mode);
849 /** Returns the current value of a local variable in given graph
850 * @see get_value() */
851 FIRM_API ir_node *get_r_value(ir_graph *irg, int pos, ir_mode *mode);
854 * Try to guess the mode of a local variable.
855 * This is done by recursively going up the control flow graph until
856 * we find a definition for the variable. The mode of the first found
857 * definition is returned. NULL in case no definition is found.
859 * @param pos The position/id of the local variable.
861 FIRM_API ir_mode *ir_guess_mode(int pos);
863 * Try to guess the mode of a local variable in a given graph.
865 FIRM_API ir_mode *ir_r_guess_mode(ir_graph *irg, int pos);
867 /** Memorize a new definition of a variable.
869 * Use this function to remember a new definition of the value
870 * associated with pos. pos must be less than the value passed as n_loc
871 * to new_ir_graph. This call is needed to automatically inserts Phi
874 * @param pos The position/id of the local variable.
875 * @param *value The new value written to the local variable.
877 FIRM_API void set_value(int pos, ir_node *value);
878 /** Sets current value of a variable in a given graph */
879 FIRM_API void set_r_value(ir_graph *irg, int pos, ir_node *value);
881 /** Returns the current memory state.
883 * Use this function to obtain the last definition of the memory
884 * state. This call automatically inserts Phi nodes for the memory
887 FIRM_API ir_node *get_store(void);
888 /** Returns current memory state for a given graph
889 * @see get_store() */
890 FIRM_API ir_node *get_r_store(ir_graph *irg);
892 /** Memorize a new definition of the memory state.
894 * Use this function to remember a new definition of the memory state.
895 * This call is needed to automatically inserts Phi nodes.
897 * @param *store The new memory state.
899 FIRM_API void set_store(ir_node *store);
900 /** Sets current memory state for a given graph
901 * @see set_store() */
902 FIRM_API void set_r_store(ir_graph *irg, ir_node *store);
904 /** keep this node alive even if End is not control-reachable from it
906 * @param ka The node to keep alive.
908 FIRM_API void keep_alive(ir_node *ka);
910 /** Puts the graph into state "phase_high" */
911 FIRM_API void irg_finalize_cons(ir_graph *irg);
913 /** Puts the program and all graphs into state phase_high.
915 * This also remarks, the construction of types is finished,
916 * e.g., that no more subtypes will be added. */
917 FIRM_API void irp_finalize_cons(void);
920 * Register a new callback for the case that the value of an uninitialized
921 * variable is requested.
923 FIRM_API void ir_set_uninitialized_local_variable_func(
924 uninitialized_local_variable_func_t *func);