becopyopt: Inline the thin wrapper nodes_interfere(), so we do not need to fetch...
[libfirm] / include / libfirm / ircons.h
1 /*
2  * This file is part of libFirm.
3  * Copyright (C) 2012 University of Karlsruhe.
4  */
5
6 /**
7  * @file
8  * @brief   Various irnode constructors. Automatic construction of SSA
9  *          representation.
10  * @author  Martin Trapp, Christian Schaefer, Goetz Lindenmaier, Boris Boesler,
11  *          Michael Beck
12  */
13
14 /**
15  *  @file
16  *
17  *  documentation no more supported since 2001
18  *
19  *  IR node construction.
20  *
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.
24  *
25  *    The documentation also gives a short manual how to use the library.
26  *
27  *    For extensive documentation of FIRM see UKA Techreport 1999-14.
28  *
29  *
30  *    Three kinds of nodes
31  *    --------------------
32  *
33  *      There are three kinds of nodes known to the IR:  entities,
34  *      types, and ir_nodes
35  *
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
38  *        operations.
39  *
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.
44  *
45  *      + types ==> implemented in type.h
46  *        With types type information is represented.  There are several type
47  *       nodes.
48  *
49  *    Implementation of the FIRM operations: ir_node
50  *    ----------------------------------------------
51  *
52  *      Ir_nodes represent operations on the data of the program and control flow
53  *      operations.  Examples of ir_nodes:  Add, Jmp, Cmp
54  *
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
64  *      1999-14.)
65  *
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
74  *      up.
75  *
76  *      All nodes of the IR have the same basic structure.  They are
77  *      distinguished by a field containing the opcode.
78  *
79  *      The fields of an ir_node:
80  *
81  *      kind             A firm_kind tag containing k_ir_node.  This is useful for
82  *                       dynamically checking the type of a node.
83  *
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.
87  *
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.
92  *
93  *      visit            A flag for traversing the IR.
94  *
95  *      **in             An array with pointers to the node's predecessors.
96  *
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.
103  *
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.
107  *
108  *    The struct ir_op
109  *    ----------------
110  *                       Not yet documented. See irop.h.
111  *
112  *    The struct ir_mode
113  *    ------------------
114  *                       Not yet documented. See irmode.h.
115  *
116  *    GLOBAL VARIABLES -- now also fields of ir_graph.
117  *    ================
118  *
119  *    current_ir_graph   Points to the current ir_graph.  All constructors for
120  *                       nodes add nodes to this graph.
121  *
122  *    ir_visited         An int used as flag to traverse the ir_graph.
123  *
124  *    block_visited      An int used as a flag to traverse block nodes in the
125  *                       graph.
126  *
127  *                       Others not yet documented.
128  *
129  *
130  *
131  *    CONSTRUCTOR FOR IR_GRAPH --> see irgraph.h
132  *    ========================
133  *
134  *
135  *    PROCEDURE TO CONSTRUCT AN IR GRAPH --> see also Firm tutorial
136  *    ==================================
137  *
138  *    This library supplies several interfaces to construct a FIRM graph for
139  *    a program:
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
147  *      for each new node.
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.
151  *
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.
157  *
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.
164  *
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.
168  *
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.
172  *
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.
177  *
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.)
187  *
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
200  *    get_store.
201  *
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.
205  *
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
208  *    the code
209  *      a = a div a;
210  *    and finally jumping to an other block.  The variable a got the local_val_nr
211  *    42 by the frontend.
212  *
213  *    ir_node *this_block, *cf_pred1, *cf_pred2, *a_val, *mem, *div, *res, *cf_op;
214  *
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);
220  *    mem = get_store();
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);
224  *    set_store(mem);
225  *    set_value(res, 42);
226  *    cf_op = new_Jmp();
227  *
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.
231  *
232  *    IR_NODES AND CONSTRUCTORS FOR IR_NODES
233  *    =======================================
234  *
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.
237  *
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.
241  *
242  *    Watch for my inconsistent use of input and predecessor (dataflow view)
243  *    and `the node points to' (implementation view).
244  *
245  *    The following description of the nodes lists four properties them if these
246  *    are of interest:
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
251  *
252  *    ------------
253  *
254  *    COPING WITH DATA OBJECTS
255  *    ========================
256  *
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.
264  *
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
269  *    live value.
270  *
271  *    inline void set_value (int pos, ir_node *value)
272  *    -----------------------------------------------
273  *
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.
279  *
280  *    ir_node *get_value (int pos, ir_mode *mode)
281  *    -------------------------------------------
282  *
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.
292  *
293  *    There are two special routines for the global store:
294  */
295 #ifndef FIRM_IR_IRCONS_H
296 #define FIRM_IR_IRCONS_H
297
298 #include "firm_types.h"
299 #include "begin.h"
300 #include "irnode.h"
301
302 /** @addtogroup Const
303  * @{
304  */
305
306 /**
307  * Constructor for a Const node.
308  *
309  * Adds the node to the start block.
310  *
311  * The constant represents a target value.
312  *
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.
317  */
318 FIRM_API ir_node *new_rd_Const_long(dbg_info *db, ir_graph *irg,
319                                     ir_mode *mode, long value);
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 *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.
330  */
331 FIRM_API ir_node *new_r_Const_long(ir_graph *irg, ir_mode *mode, long value);
332
333 /**
334  * @see new_rd_Const_long()
335  *
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.
339  */
340 FIRM_API ir_node *new_d_Const_long(dbg_info *db, ir_mode *mode, long value);
341
342 /**
343  * Make a const from a long.
344  * This is just convenience for the usual
345  * <code>
346  * new_Const(mode, tarval_from_long(mode, ...))
347  * </code>
348  * pain.
349  * @param mode The mode for the const.
350  * @param value The value of the constant.
351  * @return A new const node.
352  */
353 FIRM_API ir_node *new_Const_long(ir_mode *mode, long value);
354
355 /** @} */
356
357 /** addtogroup SymConst
358  * @{
359  */
360
361 /** Constructor for a SymConst node.
362  *
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.
378  *
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).
383  *
384  *    Mention union in declaration so that the firmjni generator recognizes that
385  *    it can not cast the argument to an int.
386  *
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
391  *                SymConst kind.
392  * @param kind    The kind of the symbolic constant, see the list above
393  */
394 FIRM_API ir_node *new_rd_SymConst(dbg_info *db, ir_graph *irg, ir_mode *mode,
395                                   union symconst_symbol value,
396                                   symconst_kind kind);
397
398 /** Constructor for a SymConst addr_ent node.
399  *
400  * Same as new_rd_SymConst, except that the constructor is tailored for
401  * symconst_addr_ent.
402  * Adds the SymConst to the start block of irg.
403  */
404 FIRM_API ir_node *new_rd_SymConst_addr_ent(dbg_info *db, ir_graph *irg,
405                                            ir_mode *mode, ir_entity *symbol);
406
407 /** Constructor for a SymConst ofs_ent node.
408  *
409  * Same as new_rd_SymConst, except that the constructor is tailored for
410  * symconst_ofs_ent.
411  * Adds the SymConst to the start block of irg.
412  */
413 FIRM_API ir_node *new_rd_SymConst_ofs_ent(dbg_info *db, ir_graph *irg,
414                                           ir_mode *mode, ir_entity *symbol);
415
416 /** Constructor for a SymConst size node.
417  *
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.
421  */
422 FIRM_API ir_node *new_rd_SymConst_size(dbg_info *db, ir_graph *irg,
423                                        ir_mode *mode, ir_type *symbol);
424
425 /** Constructor for a SymConst size node.
426  *
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.
430  */
431 FIRM_API ir_node *new_rd_SymConst_align(dbg_info *db, ir_graph *irg,
432                                         ir_mode *mode, ir_type *symbol);
433
434 /** Constructor for a SymConst node.
435  *
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.
451  *
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).
456  *
457  *    Mention union in declaration so that the firmjni generator recognizes that
458  *    it can not cast the argument to an int.
459  *
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
463  *                SymConst kind.
464  * @param kind    The kind of the symbolic constant, see the list above
465  */
466 FIRM_API ir_node *new_r_SymConst(ir_graph *irg, ir_mode *mode,
467                                  union symconst_symbol value,
468                                  symconst_kind kind);
469
470 /** Constructor for an SymConst node
471  *
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.
487  *
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).
492  *
493  *    Mention union in declaration so that the firmjni generator recognizes that
494  *    it can not cast the argument to an int.
495  *
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
499  *                SymConst kind.
500  * @param kind    The kind of the symbolic constant, see the list above
501  */
502 FIRM_API ir_node *new_d_SymConst(dbg_info *db, ir_mode *mode,
503                                  union symconst_symbol value,
504                                  symconst_kind kind);
505
506 /** Constructor for a SymConst node.
507  *
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.
523  *
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).
528  *
529  *    Mention union in declaration so that the firmjni generator recognizes that
530  *    it can not cast the argument to an int.
531  *
532  * @param mode    The mode for the SymConst.
533  * @param value   A type, ident, entity or enum constant depending on the
534  *                SymConst kind.
535  * @param kind    The kind of the symbolic constant, see the list above
536  */
537 FIRM_API ir_node *new_SymConst(ir_mode *mode, union symconst_symbol value,
538                                symconst_kind kind);
539
540 /** @} */
541
542 /** @addtogroup Sel
543  * @{
544  */
545
546 /** Constructor for a simpleSel node.
547  *
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.
551  *
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.
559  */
560 FIRM_API ir_node *new_rd_simpleSel(dbg_info *db, ir_node *block, ir_node *store,
561                                    ir_node *objptr, ir_entity *ent);
562
563 /** Constructor for a simpleSel node.
564  *
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.
568  *
569  * @param *block     The IR block the node belongs to.
570  * @param *store     The memory in which the object the entity should be selected
571  *                   from is allocated.
572  * @param *objptr    The object from that the Sel operation selects a
573  *                   single attribute out.
574  * @param *ent       The entity to select.
575  * @ingroup Sel
576  */
577 FIRM_API ir_node *new_r_simpleSel(ir_node *block, ir_node *store,
578                                   ir_node *objptr, ir_entity *ent);
579
580 /** Constructor for a simpleSel node.
581  *
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.
585  *
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.
592  */
593 FIRM_API ir_node *new_d_simpleSel(dbg_info *db, ir_node *store, ir_node *objptr,
594                                   ir_entity *ent);
595
596 /** Constructor for a simpelSel node.
597  *
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.
601  *
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.
605  */
606 FIRM_API ir_node *new_simpleSel(ir_node *store, ir_node *objptr,
607                                 ir_entity *ent);
608
609 /** @} */
610
611 /** @addtogroup Div
612  * @{
613  */
614
615 /** Constructor for a remainderless Div node.
616  *
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.
624  */
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,
627                                op_pin_state state);
628
629 /** Constructor for a remainderless Div node.
630  *
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.
637  */
638 FIRM_API ir_node *new_r_DivRL(ir_node *block, ir_node *memop,
639                               ir_node *op1, ir_node *op2, ir_mode *mode,
640                               op_pin_state state);
641
642 /** Constructor for a remainderless Div node.
643  *
644  * Adds the node to the block in current_ir_block.
645  *
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.
652  */
653 FIRM_API ir_node *new_d_DivRL(dbg_info *db, ir_node *memop,
654                               ir_node *op1, ir_node *op2, ir_mode *mode,
655                               op_pin_state state);
656
657 /** Constructor for a remainderless Div node.
658  *
659  * Adds the node to the block in current_ir_block.
660  *
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_DivRL(ir_node *memop, ir_node *op1, ir_node *op2,
668                             ir_mode *mode, op_pin_state state);
669
670 /** @} */
671
672 /** @addtogroup ASM
673  * @{
674  */
675
676 /** Constructor for an ASM pseudo node.
677  *
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.
689  */
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[],
694                             ident *asm_text);
695
696 /** Constructor for an ASM pseudo node.
697  *
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.
708  */
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[],
713                             ident *asm_text);
714
715 /** Constructor for an ASM pseudo node.
716  *
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.
727  * @ingroup ASM
728  */
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[],
733                             ident *asm_text);
734
735 /** Constructor for an ASM pseudo node.
736  *
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.
746  * @ingroup ASM
747  */
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);
752
753 /** @} */
754
755 /**
756  * @ingroup ir_graph
757  * @defgroup ir_cons Construction Support
758  * @{
759  */
760
761 /**
762  * Global variable holding the graph which is currently constructed.
763  */
764 FIRM_API ir_graph *current_ir_graph;
765
766 /**
767  * Returns graph which is currently constructed
768  */
769 FIRM_API ir_graph *get_current_ir_graph(void);
770
771 /**
772  * Sets graph which is currently constructed
773  */
774 FIRM_API void set_current_ir_graph(ir_graph *graph);
775
776 /** Create an immature Block.
777  *
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.
781  *
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.
784  */
785 FIRM_API ir_node *new_d_immBlock(dbg_info *db);
786 /** Create an immature Block.
787  *
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.
791  *
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.
794  */
795 FIRM_API ir_node *new_immBlock(void);
796 /** Create an immature Block.
797  *
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.
801  *
802  * This constructor can only be used if the graph is in state_building.
803  */
804 FIRM_API ir_node *new_r_immBlock(ir_graph *irg);
805 /** Create an immature Block.
806  *
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.
810  *
811  * This constructor can only be used if the graph is in state_building.
812  */
813 FIRM_API ir_node *new_rd_immBlock(dbg_info *db, ir_graph *irg);
814
815 /** Add a control flow edge to an immature block. */
816 FIRM_API void add_immBlock_pred(ir_node *immblock, ir_node *jmp);
817
818 /** Finalize a Block node, when all control flows are known. */
819 FIRM_API void mature_immBlock(ir_node *block);
820
821 /**
822  * Sets the current block in which the following constructors place the
823  * nodes they construct.
824  *
825  * @param target  The new current block.
826  */
827 FIRM_API void set_cur_block(ir_node *target);
828 /**
829  * Sets current block of a given graph.
830  * @see set_cur_block()
831  */
832 FIRM_API void set_r_cur_block(ir_graph *irg, ir_node *target);
833
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);
838
839 /** Returns the current value of a local variable.
840  *
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.
844  *
845  * @param  pos   The position/id of the local variable.
846  * @param *mode  The mode of the value to get.
847  */
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);
852
853 /**
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.
858  *
859  * @param  pos   The position/id of the local variable.
860  */
861 FIRM_API ir_mode *ir_guess_mode(int pos);
862 /**
863  * Try to guess the mode of a local variable in a given graph.
864  */
865 FIRM_API ir_mode *ir_r_guess_mode(ir_graph *irg, int pos);
866
867 /** Memorize a new definition of a variable.
868  *
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
872  * nodes.
873  *
874  * @param  pos   The position/id of the local variable.
875  * @param *value The new value written to the local variable.
876  */
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);
880
881 /** Returns the current memory state.
882  *
883  * Use this function to obtain the last definition of the memory
884  * state.  This call automatically inserts Phi nodes for the memory
885  * state value.
886  */
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);
891
892 /** Memorize a new definition of the memory state.
893  *
894  * Use this function to remember a new definition of the memory state.
895  * This call is needed to automatically inserts Phi nodes.
896  *
897  * @param *store The new memory state.
898  */
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);
903
904 /** keep this node alive even if End is not control-reachable from it
905  *
906  * @param ka The node to keep alive.
907  */
908 FIRM_API void keep_alive(ir_node *ka);
909
910 /** Puts the graph into state "phase_high" */
911 FIRM_API void irg_finalize_cons(ir_graph *irg);
912
913 /** Puts the program and all graphs into state phase_high.
914  *
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);
918
919 /**
920  * Register a new callback for the case that the value of an uninitialized
921  * variable is requested.
922  */
923 FIRM_API void ir_set_uninitialized_local_variable_func(
924                 uninitialized_local_variable_func_t *func);
925
926 /** @} */
927
928 #include "end.h"
929
930 #endif