rework ASM node, it always has a memory input now
[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  * 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.)
328  *
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.
333  */
334 FIRM_API ir_node *new_rd_Const_long(dbg_info *db, ir_graph *irg,
335                                     ir_mode *mode, long value);
336
337 /** Constructor for a Const node.
338  *
339  * Adds the node to the start block.
340  *
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.)
344  *
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.
348  */
349 FIRM_API ir_node *new_r_Const_long(ir_graph *irg, ir_mode *mode, long value);
350
351 /**
352  * @see new_rd_Const_long()
353  *
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.
357  */
358 FIRM_API ir_node *new_d_Const_long(dbg_info *db, ir_mode *mode, long value);
359
360 /**
361  * Make a const from a long.
362  * This is just convenience for the usual
363  * <code>
364  * new_Const(mode, tarval_from_long(mode, ...))
365  * </code>
366  * pain.
367  * @param mode The mode for the const.
368  * @param value The value of the constant.
369  * @return A new const node.
370  */
371 FIRM_API ir_node *new_Const_long(ir_mode *mode, long value);
372
373 /** @} */
374
375 /** addtogroup SymConst
376  * @{
377  */
378
379 /** Constructor for a SymConst node.
380  *
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.
396  *
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).
401  *
402  *    Mention union in declaration so that the firmjni generator recognizes that
403  *    it can not cast the argument to an int.
404  *
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
409  *                SymConst kind.
410  * @param kind    The kind of the symbolic constant, see the list above
411  */
412 FIRM_API ir_node *new_rd_SymConst(dbg_info *db, ir_graph *irg, ir_mode *mode,
413                                   union symconst_symbol value,
414                                   symconst_kind kind);
415
416 /** Constructor for a SymConst addr_ent node.
417  *
418  * Same as new_rd_SymConst, except that the constructor is tailored for
419  * symconst_addr_ent.
420  * Adds the SymConst to the start block of irg.
421  */
422 FIRM_API ir_node *new_rd_SymConst_addr_ent(dbg_info *db, ir_graph *irg,
423                                            ir_mode *mode, ir_entity *symbol);
424
425 /** Constructor for a SymConst ofs_ent node.
426  *
427  * Same as new_rd_SymConst, except that the constructor is tailored for
428  * symconst_ofs_ent.
429  * Adds the SymConst to the start block of irg.
430  */
431 FIRM_API ir_node *new_rd_SymConst_ofs_ent(dbg_info *db, ir_graph *irg,
432                                           ir_mode *mode, ir_entity *symbol);
433
434 /** Constructor for a SymConst size node.
435  *
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.
439  */
440 FIRM_API ir_node *new_rd_SymConst_size(dbg_info *db, ir_graph *irg,
441                                        ir_mode *mode, ir_type *symbol);
442
443 /** Constructor for a SymConst size node.
444  *
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.
448  */
449 FIRM_API ir_node *new_rd_SymConst_align(dbg_info *db, ir_graph *irg,
450                                         ir_mode *mode, ir_type *symbol);
451
452 /** Constructor for a SymConst node.
453  *
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.
469  *
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).
474  *
475  *    Mention union in declaration so that the firmjni generator recognizes that
476  *    it can not cast the argument to an int.
477  *
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
481  *                SymConst kind.
482  * @param kind    The kind of the symbolic constant, see the list above
483  */
484 FIRM_API ir_node *new_r_SymConst(ir_graph *irg, ir_mode *mode,
485                                  union symconst_symbol value,
486                                  symconst_kind kind);
487
488 /** Constructor for an SymConst node
489  *
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.
505  *
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).
510  *
511  *    Mention union in declaration so that the firmjni generator recognizes that
512  *    it can not cast the argument to an int.
513  *
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
517  *                SymConst kind.
518  * @param kind    The kind of the symbolic constant, see the list above
519  */
520 FIRM_API ir_node *new_d_SymConst(dbg_info *db, ir_mode *mode,
521                                  union symconst_symbol value,
522                                  symconst_kind kind);
523
524 /** Constructor for a SymConst node.
525  *
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.
541  *
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).
546  *
547  *    Mention union in declaration so that the firmjni generator recognizes that
548  *    it can not cast the argument to an int.
549  *
550  * @param mode    The mode for the SymConst.
551  * @param value   A type, ident, entity or enum constant depending on the
552  *                SymConst kind.
553  * @param kind    The kind of the symbolic constant, see the list above
554  */
555 FIRM_API ir_node *new_SymConst(ir_mode *mode, union symconst_symbol value,
556                                symconst_kind kind);
557
558 /** @} */
559
560 /** @addtogroup Conv
561  * @{
562  */
563
564 /** Constructor for a strictConv node.
565  *
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 .
570  */
571 FIRM_API ir_node *new_rd_strictConv(dbg_info *db, ir_node *block,
572                                     ir_node *op, ir_mode *mode);
573
574 /** Constructor for a strictConv node.
575  *
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 .
579  */
580 FIRM_API ir_node *new_r_strictConv(ir_node *block, ir_node *op, ir_mode *mode);
581
582 /** Constructor for a strict Conv node.
583  *
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 .
587  */
588 FIRM_API ir_node *new_d_strictConv(dbg_info *db, ir_node *op, ir_mode *mode);
589
590 /** Constructor for a strict Conv node.
591  *
592  * @param op    The operand.
593  * @param mode  The mode of this the operand muss be converted .
594  */
595 FIRM_API ir_node *new_strictConv(ir_node *op, ir_mode *mode);
596
597 /** @} */
598
599 /** @addtogroup Sel
600  * @{
601  */
602
603 /** Constructor for a simpleSel node.
604  *
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.
608  *
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.
616  */
617 FIRM_API ir_node *new_rd_simpleSel(dbg_info *db, ir_node *block, ir_node *store,
618                                    ir_node *objptr, ir_entity *ent);
619
620 /** Constructor for a simpleSel node.
621  *
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.
625  *
626  * @param *block     The IR block the node belongs to.
627  * @param *store     The memory in which the object the entity should be selected
628  *                   from is allocated.
629  * @param *objptr    The object from that the Sel operation selects a
630  *                   single attribute out.
631  * @param *ent       The entity to select.
632  * @ingroup Sel
633  */
634 FIRM_API ir_node *new_r_simpleSel(ir_node *block, ir_node *store,
635                                   ir_node *objptr, ir_entity *ent);
636
637 /** Constructor for a simpleSel node.
638  *
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.
642  *
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.
649  */
650 FIRM_API ir_node *new_d_simpleSel(dbg_info *db, ir_node *store, ir_node *objptr,
651                                   ir_entity *ent);
652
653 /** Constructor for a simpelSel node.
654  *
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.
658  *
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.
662  */
663 FIRM_API ir_node *new_simpleSel(ir_node *store, ir_node *objptr,
664                                 ir_entity *ent);
665
666 /** @} */
667
668 /** @addtogroup Div
669  * @{
670  */
671
672 /** Constructor for a remainderless Div node.
673  *
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.
681  */
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,
684                                op_pin_state state);
685
686 /** Constructor for a remainderless Div node.
687  *
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.
694  */
695 FIRM_API ir_node *new_r_DivRL(ir_node *block, ir_node *memop,
696                               ir_node *op1, ir_node *op2, ir_mode *mode,
697                               op_pin_state state);
698
699 /** Constructor for a remainderless Div node.
700  *
701  * Adds the node to the block in current_ir_block.
702  *
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.
709  */
710 FIRM_API ir_node *new_d_DivRL(dbg_info *db, ir_node *memop,
711                               ir_node *op1, ir_node *op2, ir_mode *mode,
712                               op_pin_state state);
713
714 /** Constructor for a remainderless Div node.
715  *
716  * Adds the node to the block in current_ir_block.
717  *
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.
723  */
724 FIRM_API ir_node *new_DivRL(ir_node *memop, ir_node *op1, ir_node *op2,
725                             ir_mode *mode, op_pin_state state);
726
727 /** @} */
728
729 /** @addtogroup ASM
730  * @{
731  */
732
733 /** Constructor for an ASM pseudo node.
734  *
735  * @param *db         A pointer for debug information.
736  * @param *block      The block the node belong to.
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  */
747 FIRM_API ir_node *new_rd_ASM(dbg_info *db, ir_node *block, ir_node *mem,
748                             int arity, ir_node *in[], ir_asm_constraint *inputs,
749                             size_t n_outs, ir_asm_constraint *outputs,
750                             size_t n_clobber, ident *clobber[],
751                             ident *asm_text);
752
753 /** Constructor for an ASM pseudo node.
754  *
755  * @param *block      The block the node belong to.
756  * @param *mem        memory dependency
757  * @param arity       The number of data inputs to the node.
758  * @param *in         The array of length arity of data inputs.
759  * @param *inputs     The array of length arity of input constraints.
760  * @param n_outs      The number of data outputs to the node.
761  * @param *outputs    The array of length n_outs of output constraints.
762  * @param n_clobber   The number of clobbered registers.
763  * @param *clobber    The array of length n_clobber of clobbered registers.
764  * @param *asm_text   The assembler text.
765  */
766 FIRM_API ir_node *new_r_ASM(ir_node *block, ir_node *mem,
767                             int arity, ir_node *in[], ir_asm_constraint *inputs,
768                             size_t n_outs, ir_asm_constraint *outputs,
769                             size_t n_clobber, ident *clobber[],
770                             ident *asm_text);
771
772 /** Constructor for an ASM pseudo node.
773  *
774  * @param *db         A pointer for debug information.
775  * @param *mem        memory dependency
776  * @param arity       The number of data inputs to the node.
777  * @param *in         The array of length arity of data inputs.
778  * @param *inputs     The array of length arity of input constraints.
779  * @param n_outs      The number of data outputs to the node.
780  * @param *outputs    The array of length n_outs of output constraints.
781  * @param n_clobber   The number of clobbered registers.
782  * @param *clobber    The array of length n_clobber of clobbered registers.
783  * @param *asm_text   The assembler text.
784  * @ingroup ASM
785  */
786 FIRM_API ir_node *new_d_ASM(dbg_info *db, ir_node *mem, int arity,
787                             ir_node *in[], ir_asm_constraint *inputs,
788                             size_t n_outs, ir_asm_constraint *outputs,
789                             size_t n_clobber, ident *clobber[],
790                             ident *asm_text);
791
792 /** Constructor for an ASM pseudo node.
793  *
794  * @param *mem        memory dependency
795  * @param arity       The number of data inputs to the node.
796  * @param *in         The array of length arity of data inputs.
797  * @param *inputs     The array of length arity of input constraints.
798  * @param n_outs      The number of data outputs to the node.
799  * @param *outputs    The array of length n_outs of output constraints.
800  * @param n_clobber   The number of clobbered registers.
801  * @param *clobber    The array of length n_clobber of clobbered registers.
802  * @param *asm_text   The assembler text.
803  * @ingroup ASM
804  */
805 FIRM_API ir_node *new_ASM(ir_node *mem, int arity, ir_node *in[],
806                           ir_asm_constraint *inputs, size_t n_outs,
807                           ir_asm_constraint *outputs,
808                           size_t n_clobber, ident *clobber[], ident *asm_text);
809
810 /** @} */
811
812 /**
813  * @ingroup ir_graph
814  * @defgroup ir_cons Construction Support
815  * @{
816  */
817
818 /**
819  * Global variable holding the graph which is currently constructed.
820  */
821 FIRM_API ir_graph *current_ir_graph;
822
823 /**
824  * Returns graph which is currently constructed
825  */
826 FIRM_API ir_graph *get_current_ir_graph(void);
827
828 /**
829  * Sets graph which is currently constructed
830  */
831 FIRM_API void set_current_ir_graph(ir_graph *graph);
832
833 /** Create an immature Block.
834  *
835  * An immature Block has an unknown number of predecessors.  Predecessors
836  * can be added with add_immBlock_pred().  Once all predecessors are
837  * added the block must be matured.
838  *
839  * Adds the block to the graph in current_ir_graph.
840  * This constructor can only be used if the graph is in state_building.
841  */
842 FIRM_API ir_node *new_d_immBlock(dbg_info *db);
843 /** Create an immature Block.
844  *
845  * An immature Block has an unknown number of predecessors.  Predecessors
846  * can be added with add_immBlock_pred().  Once all predecessors are
847  * added the block must be matured.
848  *
849  * Adds the block to the graph in current_ir_graph.
850  * This constructor can only be used if the graph is in state_building.
851  */
852 FIRM_API ir_node *new_immBlock(void);
853 /** Create an immature Block.
854  *
855  * An immature Block has an unknown number of predecessors.  Predecessors
856  * can be added with add_immBlock_pred().  Once all predecessors are
857  * added the block must be matured.
858  *
859  * This constructor can only be used if the graph is in state_building.
860  */
861 FIRM_API ir_node *new_r_immBlock(ir_graph *irg);
862 /** Create an immature Block.
863  *
864  * An immature Block has an unknown number of predecessors.  Predecessors
865  * can be added with add_immBlock_pred().  Once all predecessors are
866  * added the block must be matured.
867  *
868  * This constructor can only be used if the graph is in state_building.
869  */
870 FIRM_API ir_node *new_rd_immBlock(dbg_info *db, ir_graph *irg);
871
872 /** Add a control flow edge to an immature block. */
873 FIRM_API void add_immBlock_pred(ir_node *immblock, ir_node *jmp);
874
875 /** Finalize a Block node, when all control flows are known. */
876 FIRM_API void mature_immBlock(ir_node *block);
877
878 /**
879  * Sets the current block in which the following constructors place the
880  * nodes they construct.
881  *
882  * @param target  The new current block.
883  */
884 FIRM_API void set_cur_block(ir_node *target);
885 /**
886  * Sets current block of a given graph.
887  * @see set_cur_block()
888  */
889 FIRM_API void set_r_cur_block(ir_graph *irg, ir_node *target);
890
891 /** Returns the current block of the current graph. */
892 FIRM_API ir_node *get_cur_block(void);
893 /** Returns current block of a given graph */
894 FIRM_API ir_node *get_r_cur_block(ir_graph *irg);
895
896 /** Returns the current value of a local variable.
897  *
898  * Use this function to obtain the last definition of the local variable
899  * associated with pos.  pos must be less than the value passed as n_loc
900  * to new_ir_graph.  This call automatically inserts Phi nodes.
901  *
902  * @param  pos   The position/id of the local variable.
903  * @param *mode  The mode of the value to get.
904  */
905 FIRM_API ir_node *get_value(int pos, ir_mode *mode);
906 /** Returns the current value of a local variable in given graph
907  * @see get_value() */
908 FIRM_API ir_node *get_r_value(ir_graph *irg, int pos, ir_mode *mode);
909
910 /**
911  * Try to guess the mode of a local variable.
912  * This is done by recursively going up the control flow graph until
913  * we find a definition for the variable. The mode of the first found
914  * definition is returned. NULL in case no definition is found.
915  *
916  * @param  pos   The position/id of the local variable.
917  */
918 FIRM_API ir_mode *ir_guess_mode(int pos);
919 /**
920  * Try to guess the mode of a local variable in a given graph.
921  */
922 FIRM_API ir_mode *ir_r_guess_mode(ir_graph *irg, int pos);
923
924 /** Memorize a new definition of a variable.
925  *
926  * Use this function to remember a new definition of the value
927  * associated with pos.  pos must be less than the value passed as n_loc
928  * to new_ir_graph.  This call is needed to automatically inserts Phi
929  * nodes.
930  *
931  * @param  pos   The position/id of the local variable.
932  * @param *value The new value written to the local variable.
933  */
934 FIRM_API void set_value(int pos, ir_node *value);
935 /** Sets current value of a variable in a given graph */
936 FIRM_API void set_r_value(ir_graph *irg, int pos, ir_node *value);
937
938 /** Returns the current memory state.
939  *
940  * Use this function to obtain the last definition of the memory
941  * state.  This call automatically inserts Phi nodes for the memory
942  * state value.
943  */
944 FIRM_API ir_node *get_store(void);
945 /** Returns current memory state for a given graph
946  * @see get_store() */
947 FIRM_API ir_node *get_r_store(ir_graph *irg);
948
949 /** Memorize a new definition of the memory state.
950  *
951  * Use this function to remember a new definition of the memory state.
952  * This call is needed to automatically inserts Phi nodes.
953  *
954  * @param *store The new memory state.
955  */
956 FIRM_API void set_store(ir_node *store);
957 /** Sets current memory state for a given graph
958  * @see set_store() */
959 FIRM_API void set_r_store(ir_graph *irg, ir_node *store);
960
961 /** keep this node alive even if End is not control-reachable from it
962  *
963  * @param ka The node to keep alive.
964  */
965 FIRM_API void keep_alive(ir_node *ka);
966
967 /** Puts the graph into state "phase_high" */
968 FIRM_API void irg_finalize_cons(ir_graph *irg);
969
970 /** Puts the program and all graphs into state phase_high.
971  *
972  * This also remarks, the construction of types is finished,
973  * e.g., that no more subtypes will be added.  */
974 FIRM_API void irp_finalize_cons(void);
975
976 /**
977  * Register a new callback for the case that the value of an uninitialized
978  * variable is requested.
979  */
980 FIRM_API void ir_set_uninitialized_local_variable_func(
981                 uninitialized_local_variable_func_t *func);
982
983 /** @} */
984
985 #include "end.h"
986
987 #endif