documentation: Update stale comments of new_{r,rd}_Const_long().
[libfirm] / include / libfirm / ircons.h
1 /*
2  * Copyright (C) 1995-2010 University of Karlsruhe.  All right reserved.
3  *
4  * This file is part of libFirm.
5  *
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.
10  *
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.
14  *
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
17  * PURPOSE.
18  */
19
20 /**
21  * @file
22  * @brief   Various irnode constructors. Automatic construction of SSA
23  *          representation.
24  * @author  Martin Trapp, Christian Schaefer, Goetz Lindenmaier, Boris Boesler,
25  *          Michael Beck
26  */
27
28 /**
29  *  @file
30  *
31  *  documentation no more supported since 2001
32  *
33  *  IR node construction.
34  *
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.
38  *
39  *    The documentation also gives a short manual how to use the library.
40  *
41  *    For extensive documentation of FIRM see UKA Techreport 1999-14.
42  *
43  *
44  *    Three kinds of nodes
45  *    --------------------
46  *
47  *      There are three kinds of nodes known to the IR:  entities,
48  *      types, and ir_nodes
49  *
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
52  *        operations.
53  *
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.
58  *
59  *      + types ==> implemented in type.h
60  *        With types type information is represented.  There are several type
61  *       nodes.
62  *
63  *    Implementation of the FIRM operations: ir_node
64  *    ----------------------------------------------
65  *
66  *      Ir_nodes represent operations on the data of the program and control flow
67  *      operations.  Examples of ir_nodes:  Add, Jmp, Cmp
68  *
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
78  *      1999-14.)
79  *
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
88  *      up.
89  *
90  *      All nodes of the IR have the same basic structure.  They are
91  *      distinguished by a field containing the opcode.
92  *
93  *      The fields of an ir_node:
94  *
95  *      kind             A firm_kind tag containing k_ir_node.  This is useful for
96  *                       dynamically checking the type of a node.
97  *
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.
101  *
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.
106  *
107  *      visit            A flag for traversing the IR.
108  *
109  *      **in             An array with pointers to the node's predecessors.
110  *
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.
117  *
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.
121  *
122  *    The struct ir_op
123  *    ----------------
124  *                       Not yet documented. See irop.h.
125  *
126  *    The struct ir_mode
127  *    ------------------
128  *                       Not yet documented. See irmode.h.
129  *
130  *    GLOBAL VARIABLES -- now also fields of ir_graph.
131  *    ================
132  *
133  *    current_ir_graph   Points to the current ir_graph.  All constructors for
134  *                       nodes add nodes to this graph.
135  *
136  *    ir_visited         An int used as flag to traverse the ir_graph.
137  *
138  *    block_visited      An int used as a flag to traverse block nodes in the
139  *                       graph.
140  *
141  *                       Others not yet documented.
142  *
143  *
144  *
145  *    CONSTRUCTOR FOR IR_GRAPH --> see irgraph.h
146  *    ========================
147  *
148  *
149  *    PROCEDURE TO CONSTRUCT AN IR GRAPH --> see also Firm tutorial
150  *    ==================================
151  *
152  *    This library supplies several interfaces to construct a FIRM graph for
153  *    a program:
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
161  *      for each new node.
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.
165  *
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.
171  *
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.
178  *
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.
182  *
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.
186  *
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.
191  *
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.)
201  *
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
214  *    get_store.
215  *
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.
219  *
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
222  *    the code
223  *      a = a div a;
224  *    and finally jumping to an other block.  The variable a got the local_val_nr
225  *    42 by the frontend.
226  *
227  *    ir_node *this_block, *cf_pred1, *cf_pred2, *a_val, *mem, *div, *res, *cf_op;
228  *
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);
234  *    mem = get_store();
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);
238  *    set_store(mem);
239  *    set_value(res, 42);
240  *    cf_op = new_Jmp();
241  *
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.
245  *
246  *    IR_NODES AND CONSTRUCTORS FOR IR_NODES
247  *    =======================================
248  *
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.
251  *
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.
255  *
256  *    Watch for my inconsistent use of input and predecessor (dataflow view)
257  *    and `the node points to' (implementation view).
258  *
259  *    The following description of the nodes lists four properties them if these
260  *    are of interest:
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
265  *
266  *    ------------
267  *
268  *    COPING WITH DATA OBJECTS
269  *    ========================
270  *
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.
278  *
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
283  *    live value.
284  *
285  *    inline void set_value (int pos, ir_node *value)
286  *    -----------------------------------------------
287  *
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.
293  *
294  *    ir_node *get_value (int pos, ir_mode *mode)
295  *    -------------------------------------------
296  *
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.
306  *
307  *    There are two special routines for the global store:
308  */
309 #ifndef FIRM_IR_IRCONS_H
310 #define FIRM_IR_IRCONS_H
311
312 #include "firm_types.h"
313 #include "begin.h"
314 #include "irnode.h"
315
316 /** @addtogroup Const
317  * @{
318  */
319
320 /**
321  * Constructor for a Const node.
322  *
323  * Adds the node to the start block.
324  *
325  * The constant represents a target value.
326  *
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.
331  */
332 FIRM_API ir_node *new_rd_Const_long(dbg_info *db, ir_graph *irg,
333                                     ir_mode *mode, long value);
334
335 /** Constructor for a Const node.
336  *
337  * Adds the node to the start block.
338  *
339  * The constant represents a target value.
340  *
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.
344  */
345 FIRM_API ir_node *new_r_Const_long(ir_graph *irg, ir_mode *mode, long value);
346
347 /**
348  * @see new_rd_Const_long()
349  *
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.
353  */
354 FIRM_API ir_node *new_d_Const_long(dbg_info *db, ir_mode *mode, long value);
355
356 /**
357  * Make a const from a long.
358  * This is just convenience for the usual
359  * <code>
360  * new_Const(mode, tarval_from_long(mode, ...))
361  * </code>
362  * pain.
363  * @param mode The mode for the const.
364  * @param value The value of the constant.
365  * @return A new const node.
366  */
367 FIRM_API ir_node *new_Const_long(ir_mode *mode, long value);
368
369 /** @} */
370
371 /** addtogroup SymConst
372  * @{
373  */
374
375 /** Constructor for a SymConst node.
376  *
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.
392  *
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).
397  *
398  *    Mention union in declaration so that the firmjni generator recognizes that
399  *    it can not cast the argument to an int.
400  *
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
405  *                SymConst kind.
406  * @param kind    The kind of the symbolic constant, see the list above
407  */
408 FIRM_API ir_node *new_rd_SymConst(dbg_info *db, ir_graph *irg, ir_mode *mode,
409                                   union symconst_symbol value,
410                                   symconst_kind kind);
411
412 /** Constructor for a SymConst addr_ent node.
413  *
414  * Same as new_rd_SymConst, except that the constructor is tailored for
415  * symconst_addr_ent.
416  * Adds the SymConst to the start block of irg.
417  */
418 FIRM_API ir_node *new_rd_SymConst_addr_ent(dbg_info *db, ir_graph *irg,
419                                            ir_mode *mode, ir_entity *symbol);
420
421 /** Constructor for a SymConst ofs_ent node.
422  *
423  * Same as new_rd_SymConst, except that the constructor is tailored for
424  * symconst_ofs_ent.
425  * Adds the SymConst to the start block of irg.
426  */
427 FIRM_API ir_node *new_rd_SymConst_ofs_ent(dbg_info *db, ir_graph *irg,
428                                           ir_mode *mode, ir_entity *symbol);
429
430 /** Constructor for a SymConst size node.
431  *
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.
435  */
436 FIRM_API ir_node *new_rd_SymConst_size(dbg_info *db, ir_graph *irg,
437                                        ir_mode *mode, ir_type *symbol);
438
439 /** Constructor for a SymConst size node.
440  *
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.
444  */
445 FIRM_API ir_node *new_rd_SymConst_align(dbg_info *db, ir_graph *irg,
446                                         ir_mode *mode, ir_type *symbol);
447
448 /** Constructor for a SymConst node.
449  *
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.
465  *
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).
470  *
471  *    Mention union in declaration so that the firmjni generator recognizes that
472  *    it can not cast the argument to an int.
473  *
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
477  *                SymConst kind.
478  * @param kind    The kind of the symbolic constant, see the list above
479  */
480 FIRM_API ir_node *new_r_SymConst(ir_graph *irg, ir_mode *mode,
481                                  union symconst_symbol value,
482                                  symconst_kind kind);
483
484 /** Constructor for an SymConst node
485  *
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.
501  *
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).
506  *
507  *    Mention union in declaration so that the firmjni generator recognizes that
508  *    it can not cast the argument to an int.
509  *
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
513  *                SymConst kind.
514  * @param kind    The kind of the symbolic constant, see the list above
515  */
516 FIRM_API ir_node *new_d_SymConst(dbg_info *db, ir_mode *mode,
517                                  union symconst_symbol value,
518                                  symconst_kind kind);
519
520 /** Constructor for a SymConst node.
521  *
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.
537  *
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).
542  *
543  *    Mention union in declaration so that the firmjni generator recognizes that
544  *    it can not cast the argument to an int.
545  *
546  * @param mode    The mode for the SymConst.
547  * @param value   A type, ident, entity or enum constant depending on the
548  *                SymConst kind.
549  * @param kind    The kind of the symbolic constant, see the list above
550  */
551 FIRM_API ir_node *new_SymConst(ir_mode *mode, union symconst_symbol value,
552                                symconst_kind kind);
553
554 /** @} */
555
556 /** @addtogroup Sel
557  * @{
558  */
559
560 /** Constructor for a simpleSel node.
561  *
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.
565  *
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.
573  */
574 FIRM_API ir_node *new_rd_simpleSel(dbg_info *db, ir_node *block, ir_node *store,
575                                    ir_node *objptr, ir_entity *ent);
576
577 /** Constructor for a simpleSel node.
578  *
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.
582  *
583  * @param *block     The IR block the node belongs to.
584  * @param *store     The memory in which the object the entity should be selected
585  *                   from is allocated.
586  * @param *objptr    The object from that the Sel operation selects a
587  *                   single attribute out.
588  * @param *ent       The entity to select.
589  * @ingroup Sel
590  */
591 FIRM_API ir_node *new_r_simpleSel(ir_node *block, ir_node *store,
592                                   ir_node *objptr, ir_entity *ent);
593
594 /** Constructor for a simpleSel node.
595  *
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.
599  *
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.
606  */
607 FIRM_API ir_node *new_d_simpleSel(dbg_info *db, ir_node *store, ir_node *objptr,
608                                   ir_entity *ent);
609
610 /** Constructor for a simpelSel node.
611  *
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.
615  *
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.
619  */
620 FIRM_API ir_node *new_simpleSel(ir_node *store, ir_node *objptr,
621                                 ir_entity *ent);
622
623 /** @} */
624
625 /** @addtogroup Div
626  * @{
627  */
628
629 /** Constructor for a remainderless Div node.
630  *
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.
638  */
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,
641                                op_pin_state state);
642
643 /** Constructor for a remainderless Div node.
644  *
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.
651  */
652 FIRM_API ir_node *new_r_DivRL(ir_node *block, ir_node *memop,
653                               ir_node *op1, ir_node *op2, ir_mode *mode,
654                               op_pin_state state);
655
656 /** Constructor for a remainderless Div node.
657  *
658  * Adds the node to the block in current_ir_block.
659  *
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.
666  */
667 FIRM_API ir_node *new_d_DivRL(dbg_info *db, ir_node *memop,
668                               ir_node *op1, ir_node *op2, ir_mode *mode,
669                               op_pin_state state);
670
671 /** Constructor for a remainderless Div node.
672  *
673  * Adds the node to the block in current_ir_block.
674  *
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.
680  */
681 FIRM_API ir_node *new_DivRL(ir_node *memop, ir_node *op1, ir_node *op2,
682                             ir_mode *mode, op_pin_state state);
683
684 /** @} */
685
686 /** @addtogroup ASM
687  * @{
688  */
689
690 /** Constructor for an ASM pseudo node.
691  *
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.
703  */
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[],
708                             ident *asm_text);
709
710 /** Constructor for an ASM pseudo node.
711  *
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.
722  */
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[],
727                             ident *asm_text);
728
729 /** Constructor for an ASM pseudo node.
730  *
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.
741  * @ingroup ASM
742  */
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[],
747                             ident *asm_text);
748
749 /** Constructor for an ASM pseudo node.
750  *
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.
760  * @ingroup ASM
761  */
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);
766
767 /** @} */
768
769 /**
770  * @ingroup ir_graph
771  * @defgroup ir_cons Construction Support
772  * @{
773  */
774
775 /**
776  * Global variable holding the graph which is currently constructed.
777  */
778 FIRM_API ir_graph *current_ir_graph;
779
780 /**
781  * Returns graph which is currently constructed
782  */
783 FIRM_API ir_graph *get_current_ir_graph(void);
784
785 /**
786  * Sets graph which is currently constructed
787  */
788 FIRM_API void set_current_ir_graph(ir_graph *graph);
789
790 /** Create an immature Block.
791  *
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.
795  *
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.
798  */
799 FIRM_API ir_node *new_d_immBlock(dbg_info *db);
800 /** Create an immature Block.
801  *
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.
805  *
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.
808  */
809 FIRM_API ir_node *new_immBlock(void);
810 /** Create an immature Block.
811  *
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.
815  *
816  * This constructor can only be used if the graph is in state_building.
817  */
818 FIRM_API ir_node *new_r_immBlock(ir_graph *irg);
819 /** Create an immature Block.
820  *
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.
824  *
825  * This constructor can only be used if the graph is in state_building.
826  */
827 FIRM_API ir_node *new_rd_immBlock(dbg_info *db, ir_graph *irg);
828
829 /** Add a control flow edge to an immature block. */
830 FIRM_API void add_immBlock_pred(ir_node *immblock, ir_node *jmp);
831
832 /** Finalize a Block node, when all control flows are known. */
833 FIRM_API void mature_immBlock(ir_node *block);
834
835 /**
836  * Sets the current block in which the following constructors place the
837  * nodes they construct.
838  *
839  * @param target  The new current block.
840  */
841 FIRM_API void set_cur_block(ir_node *target);
842 /**
843  * Sets current block of a given graph.
844  * @see set_cur_block()
845  */
846 FIRM_API void set_r_cur_block(ir_graph *irg, ir_node *target);
847
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);
852
853 /** Returns the current value of a local variable.
854  *
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.
858  *
859  * @param  pos   The position/id of the local variable.
860  * @param *mode  The mode of the value to get.
861  */
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);
866
867 /**
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.
872  *
873  * @param  pos   The position/id of the local variable.
874  */
875 FIRM_API ir_mode *ir_guess_mode(int pos);
876 /**
877  * Try to guess the mode of a local variable in a given graph.
878  */
879 FIRM_API ir_mode *ir_r_guess_mode(ir_graph *irg, int pos);
880
881 /** Memorize a new definition of a variable.
882  *
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
886  * nodes.
887  *
888  * @param  pos   The position/id of the local variable.
889  * @param *value The new value written to the local variable.
890  */
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);
894
895 /** Returns the current memory state.
896  *
897  * Use this function to obtain the last definition of the memory
898  * state.  This call automatically inserts Phi nodes for the memory
899  * state value.
900  */
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);
905
906 /** Memorize a new definition of the memory state.
907  *
908  * Use this function to remember a new definition of the memory state.
909  * This call is needed to automatically inserts Phi nodes.
910  *
911  * @param *store The new memory state.
912  */
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);
917
918 /** keep this node alive even if End is not control-reachable from it
919  *
920  * @param ka The node to keep alive.
921  */
922 FIRM_API void keep_alive(ir_node *ka);
923
924 /** Puts the graph into state "phase_high" */
925 FIRM_API void irg_finalize_cons(ir_graph *irg);
926
927 /** Puts the program and all graphs into state phase_high.
928  *
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);
932
933 /**
934  * Register a new callback for the case that the value of an uninitialized
935  * variable is requested.
936  */
937 FIRM_API void ir_set_uninitialized_local_variable_func(
938                 uninitialized_local_variable_func_t *func);
939
940 /** @} */
941
942 #include "end.h"
943
944 #endif