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 * Constructor for a Const node. The constant represents a target
326 * value. Sets the type information to type_unknown. (No more
327 * supported: If tv is entity derives a somehow useful type.)
329 * @param *db A pointer for debug information.
330 * @param *irg The IR graph the node belongs to.
331 * @param *mode The mode of the operands and results.
332 * @param value A value from which the tarval is made.
334 FIRM_API ir_node *new_rd_Const_long(dbg_info *db, ir_graph *irg,
335 ir_mode *mode, long value);
337 /** Constructor for a Const node.
339 * Adds the node to the start block.
341 * Constructor for a Const node. The constant represents a target
342 * value. Sets the type information to type_unknown. (No more
343 * supported: If tv is entity derives a somehow useful type.)
345 * @param *irg The IR graph the node belongs to.
346 * @param *mode The mode of the operands and the results.
347 * @param value A value from which the tarval is made.
349 FIRM_API ir_node *new_r_Const_long(ir_graph *irg, ir_mode *mode, long value);
352 * @see new_rd_Const_long()
354 * @param *db A pointer for debug information.
355 * @param *mode The mode of the operands and results.
356 * @param value A value from which the tarval is made.
358 FIRM_API ir_node *new_d_Const_long(dbg_info *db, ir_mode *mode, long value);
361 * Make a const from a long.
362 * This is just convenience for the usual
364 * new_Const(mode, tarval_from_long(mode, ...))
367 * @param mode The mode for the const.
368 * @param value The value of the constant.
369 * @return A new const node.
371 FIRM_API ir_node *new_Const_long(ir_mode *mode, long value);
375 /** addtogroup SymConst
379 /** Constructor for a SymConst node.
381 * This is the constructor for a symbolic constant.
382 * There are several kinds of symbolic constants:
383 * - symconst_type_size The symbolic constant represents the size of a type.
384 * The type of which the constant represents the size
385 * is given explicitly.
386 * - symconst_type_align The symbolic constant represents the alignment of a
387 * type. The type of which the constant represents the
388 * size is given explicitly.
389 * - symconst_addr_ent The symbolic constant represents the address of an
390 * entity (variable or method). The variable is given
391 * explicitly by a firm entity.
392 * - symconst_ofs_ent The symbolic constant represents the offset of an
393 * entity in its owner type.
394 * - symconst_enum_const The symbolic constant is a enumeration constant of
395 * an enumeration type.
397 * Inputs to the node:
398 * No inputs except the block it belongs to.
399 * Outputs of the node.
400 * An unsigned integer (I_u) or a pointer (P).
402 * Mention union in declaration so that the firmjni generator recognizes that
403 * it can not cast the argument to an int.
405 * @param *db A pointer for debug information.
406 * @param *irg The IR graph the node belongs to.
407 * @param mode The mode for the SymConst.
408 * @param value A type, ident, entity or enum constant depending on the
410 * @param kind The kind of the symbolic constant, see the list above
412 FIRM_API ir_node *new_rd_SymConst(dbg_info *db, ir_graph *irg, ir_mode *mode,
413 union symconst_symbol value,
416 /** Constructor for a SymConst addr_ent node.
418 * Same as new_rd_SymConst, except that the constructor is tailored for
420 * Adds the SymConst to the start block of irg.
422 FIRM_API ir_node *new_rd_SymConst_addr_ent(dbg_info *db, ir_graph *irg,
423 ir_mode *mode, ir_entity *symbol);
425 /** Constructor for a SymConst ofs_ent node.
427 * Same as new_rd_SymConst, except that the constructor is tailored for
429 * Adds the SymConst to the start block of irg.
431 FIRM_API ir_node *new_rd_SymConst_ofs_ent(dbg_info *db, ir_graph *irg,
432 ir_mode *mode, ir_entity *symbol);
434 /** Constructor for a SymConst size node.
436 * Same as new_rd_SymConst, except that the constructor is tailored for
437 * symconst_type_size.
438 * Adds the SymConst to the start block of irg.
440 FIRM_API ir_node *new_rd_SymConst_size(dbg_info *db, ir_graph *irg,
441 ir_mode *mode, ir_type *symbol);
443 /** Constructor for a SymConst size node.
445 * Same as new_rd_SymConst, except that the constructor is tailored for
446 * symconst_type_align.
447 * Adds the SymConst to the start block of irg.
449 FIRM_API ir_node *new_rd_SymConst_align(dbg_info *db, ir_graph *irg,
450 ir_mode *mode, ir_type *symbol);
452 /** Constructor for a SymConst node.
454 * This is the constructor for a symbolic constant.
455 * There are several kinds of symbolic constants:
456 * - symconst_type_size The symbolic constant represents the size of a type.
457 * The type of which the constant represents the size
458 * is given explicitly.
459 * - symconst_type_align The symbolic constant represents the alignment of a
460 * type. The type of which the constant represents the
461 * size is given explicitly.
462 * - symconst_addr_ent The symbolic constant represents the address of an
463 * entity (variable or method). The variable is given
464 * explicitly by a firm entity.
465 * - symconst_ofs_ent The symbolic constant represents the offset of an
466 * entity in its owner type.
467 * - symconst_enum_const The symbolic constant is a enumeration constant of
468 * an enumeration type.
470 * Inputs to the node:
471 * No inputs except the block it belongs to.
472 * Outputs of the node.
473 * An unsigned integer (I_u) or a pointer (P).
475 * Mention union in declaration so that the firmjni generator recognizes that
476 * it can not cast the argument to an int.
478 * @param *irg The IR graph the node belongs to.
479 * @param mode The mode for the SymConst.
480 * @param value A type, ident, entity or enum constant depending on the
482 * @param kind The kind of the symbolic constant, see the list above
484 FIRM_API ir_node *new_r_SymConst(ir_graph *irg, ir_mode *mode,
485 union symconst_symbol value,
488 /** Constructor for an SymConst node
490 * This is the constructor for a symbolic constant.
491 * There are several kinds of symbolic constants:
492 * - symconst_type_size The symbolic constant represents the size of a type.
493 * The type of which the constant represents the size
494 * is given explicitly.
495 * - symconst_type_align The symbolic constant represents the alignment of a
496 * type. The type of which the constant represents the
497 * size is given explicitly.
498 * - symconst_addr_ent The symbolic constant represents the address of an
499 * entity (variable or method). The variable is given
500 * explicitly by a firm entity.
501 * - symconst_ofs_ent The symbolic constant represents the offset of an
502 * entity in its owner type.
503 * - symconst_enum_const The symbolic constant is a enumeration constant of
504 * an enumeration type.
506 * Inputs to the node:
507 * No inputs except the block it belongs to.
508 * Outputs of the node.
509 * An unsigned integer (I_u) or a pointer (P).
511 * Mention union in declaration so that the firmjni generator recognizes that
512 * it can not cast the argument to an int.
514 * @param *db A pointer for debug information.
515 * @param mode The mode for the SymConst.
516 * @param value A type, ident, entity or enum constant depending on the
518 * @param kind The kind of the symbolic constant, see the list above
520 FIRM_API ir_node *new_d_SymConst(dbg_info *db, ir_mode *mode,
521 union symconst_symbol value,
524 /** Constructor for a SymConst node.
526 * This is the constructor for a symbolic constant.
527 * There are several kinds of symbolic constants:
528 * - symconst_type_size The symbolic constant represents the size of a type.
529 * The type of which the constant represents the size
530 * is given explicitly.
531 * - symconst_type_align The symbolic constant represents the alignment of a
532 * type. The type of which the constant represents the
533 * size is given explicitly.
534 * - symconst_addr_ent The symbolic constant represents the address of an
535 * entity (variable or method). The variable is given
536 * explicitly by a firm entity.
537 * - symconst_ofs_ent The symbolic constant represents the offset of an
538 * entity in its owner type.
539 * - symconst_enum_const The symbolic constant is a enumeration constant of
540 * an enumeration type.
542 * Inputs to the node:
543 * No inputs except the block it belongs to.
544 * Outputs of the node.
545 * An unsigned integer (I_u) or a pointer (P).
547 * Mention union in declaration so that the firmjni generator recognizes that
548 * it can not cast the argument to an int.
550 * @param mode The mode for the SymConst.
551 * @param value A type, ident, entity or enum constant depending on the
553 * @param kind The kind of the symbolic constant, see the list above
555 FIRM_API ir_node *new_SymConst(ir_mode *mode, union symconst_symbol value,
564 /** Constructor for a strictConv node.
566 * @param db A pointer for debug information.
567 * @param block The IR block the node belongs to.
568 * @param op The operand.
569 * @param mode The mode of this the operand muss be converted .
571 FIRM_API ir_node *new_rd_strictConv(dbg_info *db, ir_node *block,
572 ir_node *op, ir_mode *mode);
574 /** Constructor for a strictConv node.
576 * @param block The IR block the node belongs to.
577 * @param op The operand.
578 * @param mode The mode of this the operand muss be converted .
580 FIRM_API ir_node *new_r_strictConv(ir_node *block, ir_node *op, ir_mode *mode);
582 /** Constructor for a strict Conv node.
584 * @param db A pointer for debug information.
585 * @param op The operand.
586 * @param mode The mode of this the operand muss be converted .
588 FIRM_API ir_node *new_d_strictConv(dbg_info *db, ir_node *op, ir_mode *mode);
590 /** Constructor for a strict Conv node.
592 * @param op The operand.
593 * @param mode The mode of this the operand muss be converted .
595 FIRM_API ir_node *new_strictConv(ir_node *op, ir_mode *mode);
603 /** Constructor for a simpleSel node.
605 * This is a shortcut for the new_rd_Sel() constructor. To be used for
606 * Sel nodes that do not select from an array, i.e., have no index
607 * inputs. It adds the two parameters 0, NULL.
609 * @param *db A pointer for debug information.
610 * @param *block The IR block the node belongs to.
611 * @param *store The memory in which the object the entity should be
612 * selected from is allocated.
613 * @param *objptr The object from that the Sel operation selects a
614 * single attribute out.
615 * @param *ent The entity to select.
617 FIRM_API ir_node *new_rd_simpleSel(dbg_info *db, ir_node *block, ir_node *store,
618 ir_node *objptr, ir_entity *ent);
620 /** Constructor for a simpleSel node.
622 * This is a shortcut for the new_d_Sel() constructor. To be used for
623 * Sel nodes that do not select from an array, i.e., have no index
624 * inputs. It adds the two parameters 0, NULL.
626 * @param *block The IR block the node belongs to.
627 * @param *store The memory in which the object the entity should be selected
629 * @param *objptr The object from that the Sel operation selects a
630 * single attribute out.
631 * @param *ent The entity to select.
634 FIRM_API ir_node *new_r_simpleSel(ir_node *block, ir_node *store,
635 ir_node *objptr, ir_entity *ent);
637 /** Constructor for a simpleSel node.
639 * This is a shortcut for the new_d_Sel() constructor. To be used for
640 * Sel nodes that do not select from an array, i.e., have no index
641 * inputs. It adds the two parameters 0, NULL.
643 * @param *db A pointer for debug information.
644 * @param *store The memory in which the object the entity should be
645 * selected from is allocated.
646 * @param *objptr The object from that the Sel operation selects a
647 * single attribute out.
648 * @param *ent The entity to select.
650 FIRM_API ir_node *new_d_simpleSel(dbg_info *db, ir_node *store, ir_node *objptr,
653 /** Constructor for a simpelSel node.
655 * This is a shortcut for the new_Sel() constructor. To be used for
656 * Sel nodes that do not select from an array, i.e., have no index
657 * inputs. It adds the two parameters 0, NULL.
659 * @param *store The memory in which the object the entity should be selected from is allocated.
660 * @param *objptr The object from that the Sel operation selects a single attribute out.
661 * @param *ent The entity to select.
663 FIRM_API ir_node *new_simpleSel(ir_node *store, ir_node *objptr,
672 /** Constructor for a remainderless Div node.
674 * @param *db A pointer for debug information.
675 * @param *block The IR block the node belongs to.
676 * @param *memop The store needed to model exceptions
677 * @param *op1 The first operand.
678 * @param *op2 The second operand.
679 * @param *mode The mode of the result.
680 * @param state The pinned state.
682 FIRM_API ir_node *new_rd_DivRL(dbg_info *db, ir_node *block, ir_node *memop,
683 ir_node *op1, ir_node *op2, ir_mode *mode,
686 /** Constructor for a remainderless Div node.
688 * @param *block The IR block the node belongs to.
689 * @param *memop The store needed to model exceptions
690 * @param *op1 The first operand.
691 * @param *op2 The second operand.
692 * @param *mode The mode of the result.
693 * @param state The pinned state.
695 FIRM_API ir_node *new_r_DivRL(ir_node *block, ir_node *memop,
696 ir_node *op1, ir_node *op2, ir_mode *mode,
699 /** Constructor for a remainderless Div node.
701 * Adds the node to the block in current_ir_block.
703 * @param *db A pointer for debug information.
704 * @param *memop The store needed to model exceptions
705 * @param *op1 The first operand.
706 * @param *op2 The second operand.
707 * @param *mode The mode of the result.
708 * @param state The pinned state.
710 FIRM_API ir_node *new_d_DivRL(dbg_info *db, ir_node *memop,
711 ir_node *op1, ir_node *op2, ir_mode *mode,
714 /** Constructor for a remainderless Div node.
716 * Adds the node to the block in current_ir_block.
718 * @param *memop The store needed to model exceptions
719 * @param *op1 The first operand.
720 * @param *op2 The second operand.
721 * @param *mode The mode of the result.
722 * @param state The pinned state.
724 FIRM_API ir_node *new_DivRL(ir_node *memop, ir_node *op1, ir_node *op2,
725 ir_mode *mode, op_pin_state state);
733 /** Constructor for an ASM pseudo node.
735 * @param *db A pointer for debug information.
736 * @param *block The block the node belong to.
737 * @param arity The number of data inputs to the node.
738 * @param *in The array of length arity of data inputs.
739 * @param *inputs The array of length arity of input constraints.
740 * @param n_outs The number of data outputs to the node.
741 * @param *outputs The array of length n_outs of output constraints.
742 * @param n_clobber The number of clobbered registers.
743 * @param *clobber The array of length n_clobber of clobbered registers.
744 * @param *asm_text The assembler text.
746 FIRM_API ir_node *new_rd_ASM(dbg_info *db, ir_node *block,
747 int arity, ir_node *in[], ir_asm_constraint *inputs,
748 size_t n_outs, ir_asm_constraint *outputs,
749 size_t n_clobber, ident *clobber[],
752 /** Constructor for an ASM pseudo node.
754 * @param *block The block the node belong to.
755 * @param arity The number of data inputs to the node.
756 * @param *in The array of length arity of data inputs.
757 * @param *inputs The array of length arity of input constraints.
758 * @param n_outs The number of data outputs to the node.
759 * @param *outputs The array of length n_outs of output constraints.
760 * @param n_clobber The number of clobbered registers.
761 * @param *clobber The array of length n_clobber of clobbered registers.
762 * @param *asm_text The assembler text.
764 FIRM_API ir_node *new_r_ASM(ir_node *block,
765 int arity, ir_node *in[], ir_asm_constraint *inputs,
766 size_t n_outs, ir_asm_constraint *outputs,
767 size_t n_clobber, ident *clobber[],
770 /** Constructor for an ASM pseudo node.
772 * @param *db A pointer for debug information.
773 * @param arity The number of data inputs to the node.
774 * @param *in The array of length arity of data inputs.
775 * @param *inputs The array of length arity of input constraints.
776 * @param n_outs The number of data outputs to the node.
777 * @param *outputs The array of length n_outs of output constraints.
778 * @param n_clobber The number of clobbered registers.
779 * @param *clobber The array of length n_clobber of clobbered registers.
780 * @param *asm_text The assembler text.
783 FIRM_API ir_node *new_d_ASM(dbg_info *db, int arity, ir_node *in[],
784 ir_asm_constraint *inputs,
785 size_t n_outs, ir_asm_constraint *outputs,
786 size_t n_clobber, ident *clobber[],
789 /** Constructor for an ASM pseudo node.
791 * @param arity The number of data inputs to the node.
792 * @param *in The array of length arity of data inputs.
793 * @param *inputs The array of length arity of input constraints.
794 * @param n_outs The number of data outputs to the node.
795 * @param *outputs The array of length n_outs of output constraints.
796 * @param n_clobber The number of clobbered registers.
797 * @param *clobber The array of length n_clobber of clobbered registers.
798 * @param *asm_text The assembler text.
801 FIRM_API ir_node *new_ASM(int arity, ir_node *in[], ir_asm_constraint *inputs,
802 size_t n_outs, ir_asm_constraint *outputs,
803 size_t n_clobber, ident *clobber[], ident *asm_text);
809 * @defgroup ir_cons Construction Support
814 * Global variable holding the graph which is currently constructed.
816 FIRM_API ir_graph *current_ir_graph;
819 * Returns graph which is currently constructed
821 FIRM_API ir_graph *get_current_ir_graph(void);
824 * Sets graph which is currently constructed
826 FIRM_API void set_current_ir_graph(ir_graph *graph);
828 /** Create an immature Block.
830 * An immature Block has an unknown number of predecessors. Predecessors
831 * can be added with add_immBlock_pred(). Once all predecessors are
832 * added the block must be matured.
834 * Adds the block to the graph in current_ir_graph.
835 * This constructor can only be used if the graph is in state_building.
837 FIRM_API ir_node *new_d_immBlock(dbg_info *db);
838 /** Create an immature Block.
840 * An immature Block has an unknown number of predecessors. Predecessors
841 * can be added with add_immBlock_pred(). Once all predecessors are
842 * added the block must be matured.
844 * Adds the block to the graph in current_ir_graph.
845 * This constructor can only be used if the graph is in state_building.
847 FIRM_API ir_node *new_immBlock(void);
848 /** Create an immature Block.
850 * An immature Block has an unknown number of predecessors. Predecessors
851 * can be added with add_immBlock_pred(). Once all predecessors are
852 * added the block must be matured.
854 * This constructor can only be used if the graph is in state_building.
856 FIRM_API ir_node *new_r_immBlock(ir_graph *irg);
857 /** Create an immature Block.
859 * An immature Block has an unknown number of predecessors. Predecessors
860 * can be added with add_immBlock_pred(). Once all predecessors are
861 * added the block must be matured.
863 * This constructor can only be used if the graph is in state_building.
865 FIRM_API ir_node *new_rd_immBlock(dbg_info *db, ir_graph *irg);
867 /** Add a control flow edge to an immature block. */
868 FIRM_API void add_immBlock_pred(ir_node *immblock, ir_node *jmp);
870 /** Finalize a Block node, when all control flows are known. */
871 FIRM_API void mature_immBlock(ir_node *block);
874 * Sets the current block in which the following constructors place the
875 * nodes they construct.
877 * @param target The new current block.
879 FIRM_API void set_cur_block(ir_node *target);
881 * Sets current block of a given graph.
882 * @see set_cur_block()
884 FIRM_API void set_r_cur_block(ir_graph *irg, ir_node *target);
886 /** Returns the current block of the current graph. */
887 FIRM_API ir_node *get_cur_block(void);
888 /** Returns current block of a given graph */
889 FIRM_API ir_node *get_r_cur_block(ir_graph *irg);
891 /** Returns the current value of a local variable.
893 * Use this function to obtain the last definition of the local variable
894 * associated with pos. pos must be less than the value passed as n_loc
895 * to new_ir_graph. This call automatically inserts Phi nodes.
897 * @param pos The position/id of the local variable.
898 * @param *mode The mode of the value to get.
900 FIRM_API ir_node *get_value(int pos, ir_mode *mode);
901 /** Returns the current value of a local variable in given graph
902 * @see get_value() */
903 FIRM_API ir_node *get_r_value(ir_graph *irg, int pos, ir_mode *mode);
906 * Try to guess the mode of a local variable.
907 * This is done by recursively going up the control flow graph until
908 * we find a definition for the variable. The mode of the first found
909 * definition is returned. NULL in case no definition is found.
911 * @param pos The position/id of the local variable.
913 FIRM_API ir_mode *ir_guess_mode(int pos);
915 * Try to guess the mode of a local variable in a given graph.
917 FIRM_API ir_mode *ir_r_guess_mode(ir_graph *irg, int pos);
919 /** Memorize a new definition of a variable.
921 * Use this function to remember a new definition of the value
922 * associated with pos. pos must be less than the value passed as n_loc
923 * to new_ir_graph. This call is needed to automatically inserts Phi
926 * @param pos The position/id of the local variable.
927 * @param *value The new value written to the local variable.
929 FIRM_API void set_value(int pos, ir_node *value);
930 /** Sets current value of a variable in a given graph */
931 FIRM_API void set_r_value(ir_graph *irg, int pos, ir_node *value);
934 * Find the value number for a node in the current block.
936 * @param value the searched value
938 * @return the value number of the value or -1 if this value has
939 * no value number in the current block.
941 FIRM_API int find_value(ir_node *value);
943 * Find value number for a node in the current block of a given graph
946 FIRM_API int r_find_value(ir_graph *irg, ir_node *value);
948 /** Returns the current memory state.
950 * Use this function to obtain the last definition of the memory
951 * state. This call automatically inserts Phi nodes for the memory
954 FIRM_API ir_node *get_store(void);
955 /** Returns current memory state for a given graph
956 * @see get_store() */
957 FIRM_API ir_node *get_r_store(ir_graph *irg);
959 /** Memorize a new definition of the memory state.
961 * Use this function to remember a new definition of the memory state.
962 * This call is needed to automatically inserts Phi nodes.
964 * @param *store The new memory state.
966 FIRM_API void set_store(ir_node *store);
967 /** Sets current memory state for a given graph
968 * @see set_store() */
969 FIRM_API void set_r_store(ir_graph *irg, ir_node *store);
971 /** keep this node alive even if End is not control-reachable from it
973 * @param ka The node to keep alive.
975 FIRM_API void keep_alive(ir_node *ka);
977 /** Puts the graph into state "phase_high" */
978 FIRM_API void irg_finalize_cons(ir_graph *irg);
980 /** Puts the program and all graphs into state phase_high.
982 * This also remarks, the construction of types is finished,
983 * e.g., that no more subtypes will be added. */
984 FIRM_API void irp_finalize_cons(void);
987 * Register a new callback for the case that the value of an uninitialized
988 * variable is requested.
990 FIRM_API void ir_set_uninitialized_local_variable_func(
991 uninitialized_local_variable_func_t *func);