remove $Id$, it doesn't work with git anyway
[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  *    The comfortable interface contains the following routines further explained
247  *    below:
248  *
249  *    ir_node *new_immBlock (void);
250  *    ir_node *new_Start    (void);
251  *    ir_node *new_End      (void);
252  *    ir_node *new_Jmp      (void);
253  *    ir_node *new_IJmp     (ir_node *tgt);
254  *    ir_node *new_Cond     (ir_node *c);
255  *    ir_node *new_Return   (ir_node *store, int arity, ir_node **in);
256  *    ir_node *new_Const    (ir_tarval *con);
257  *    ir_node *new_SymConst (ir_mode *mode, symconst_symbol value, symconst_kind kind);
258  *    ir_node *new_simpleSel (ir_node *store, ir_node *objptr, ir_entity *ent);
259  *    ir_node *new_Sel    (ir_node *store, ir_node *objptr, int arity,
260  *                         ir_node **in, ir_entity *ent);
261  *    ir_node *new_Call   (ir_node *store, ir_node *callee, int arity,
262  *                         ir_node **in, type_method *type);
263  *    ir_node *new_Builtin(ir_node *store, ir_builtin_kind kind, int arity,
264  *                         ir_node **in, type_method *type);
265  *    ir_node *new_Add    (ir_node *op1, ir_node *op2, ir_mode *mode);
266  *    ir_node *new_Sub    (ir_node *op1, ir_node *op2, ir_mode *mode);
267  *    ir_node *new_Minus  (ir_node *op,  ir_mode *mode);
268  *    ir_node *new_Mul    (ir_node *op1, ir_node *op2, ir_mode *mode);
269  *    ir_node *new_Mulh   (ir_node *op1, ir_node *op2, ir_mode *mode);
270  *    ir_node *new_Div    (ir_node *memop, ir_node *op1, ir_node *op2, ir_mode *mode, op_pin_state state);
271  *    ir_node *new_Mod    (ir_node *memop, ir_node *op1, ir_node *op2, ir_mode *mode, op_pin_state state;
272  *    ir_node *new_And    (ir_node *op1, ir_node *op2, ir_mode *mode);
273  *    ir_node *new_Or     (ir_node *op1, ir_node *op2, ir_mode *mode);
274  *    ir_node *new_Eor    (ir_node *op1, ir_node *op2, ir_mode *mode);
275  *    ir_node *new_Not    (ir_node *op,                ir_mode *mode);
276  *    ir_node *new_Shl    (ir_node *op,  ir_node *k,   ir_mode *mode);
277  *    ir_node *new_Shr    (ir_node *op,  ir_node *k,   ir_mode *mode);
278  *    ir_node *new_Shrs   (ir_node *op,  ir_node *k,   ir_mode *mode);
279  *    ir_node *new_Rotl   (ir_node *op,  ir_node *k,   ir_mode *mode);
280  *    ir_node *new_Cmp    (ir_node *op1, ir_node *op2);
281  *    ir_node *new_Conv   (ir_node *op, ir_mode *mode);
282  *    ir_node *new_Cast   (ir_node *op, ir_type *to_tp);
283  *    ir_node *new_Carry  (ir_node *op1, ir_node *op2, ir_mode *mode);
284  *    ir_node *new_Borrow (ir_node *op1, ir_node *op2, ir_mode *mode);
285  *    ir_node *new_Load   (ir_node *store, ir_node *addr, ir_mode *mode, ir_cons_flags flags);
286  *    ir_node *new_Store  (ir_node *store, ir_node *addr, ir_node *val, ir_cons_flags flags);
287  *    ir_node *new_Alloc  (ir_node *store, ir_node *count, ir_type *alloc_type,
288  *                         where_alloc where);
289  *    ir_node *new_Free   (ir_node *store, ir_node *ptr, ir_node *size,
290  *               ir_type *free_type, where_alloc where);
291  *    ir_node *new_Proj   (ir_node *arg, ir_mode *mode, long proj);
292  *    ir_node *new_NoMem  (void);
293  *    ir_node *new_Mux    (ir_node *sel, ir_node *ir_false, ir_node *ir_true, ir_mode *mode);
294  *    ir_node *new_CopyB  (ir_node *store, ir_node *dst, ir_node *src, ir_type *data_type);
295  *    ir_node *new_InstOf (ir_node *store, ir_node obj, ir_type *ent);
296  *    ir_node *new_Raise  (ir_node *store, ir_node *obj);
297  *    ir_node *new_Bound  (ir_node *store, ir_node *idx, ir_node *lower, ir_node *upper);
298  *    ir_node *new_Pin    (ir_node *node);
299  *
300  *    void add_immBlock_pred (ir_node *block, ir_node *jmp);
301  *    void mature_immBlock (ir_node *block);
302  *    void set_cur_block (ir_node *target);
303  *    ir_node *get_value (int pos, ir_mode *mode);
304  *    void set_value (int pos, ir_node *value);
305  *    ir_node *get_store (void);
306  *    void set_store (ir_node *store);
307  *    keep_alive (ir_node ka)
308  *
309  *    IR_NODES AND CONSTRUCTORS FOR IR_NODES
310  *    =======================================
311  *
312  *    All ir_nodes are defined by a common data structure.  They are distinguished
313  *    by their opcode and differ in the number of their attributes.
314  *
315  *    Const nodes are always added to the start block.
316  *    All other constructors add the created node to the current_block.
317  *    swich_block(block) allows to set the current block to block.
318  *
319  *    Watch for my inconsistent use of input and predecessor (dataflow view)
320  *    and `the node points to' (implementation view).
321  *
322  *    The following description of the nodes lists four properties them if these
323  *    are of interest:
324  *     - the parameters to the constructor
325  *     - the inputs of the Firm node
326  *     - the outputs of the Firm node
327  *     - attributes to the node
328  *
329  *    ------------
330  *
331  *    ir_node *new_immBlock (void)
332  *    ----------------------------
333  *
334  *    Creates a new block. When a new block is created it cannot be known how
335  *    many predecessors this block will have in the control flow graph.
336  *    Therefore the list of inputs can not be fixed at creation.  Predecessors
337  *    can be added with add_immBlock_pred (block, control flow operation).
338  *    With every added predecessor the number of inputs to Phi nodes also
339  *    changes.
340  *
341  *    The block can be completed by mature_immBlock(block) if all predecessors are
342  *    known.  If several blocks are built at once, mature_immBlock can only be called
343  *    after set_value has been called for all values that are life at the end
344  *    of the block.  This is necessary so that Phi nodes created mature_immBlock
345  *    get the right predecessors in case of cyclic dependencies.  If all set_values
346  *    of this block are called after maturing it and before calling get_value
347  *    in some block that is control flow dependent on this block, the construction
348  *    is correct.
349  *
350  *    Example for faulty IR construction:  (draw the graph on a paper and you'll
351  *                                          get it ;-)
352  *
353  *      block_before_loop = new_immBlock();
354  *      set_cur_block(block_before_loop);
355  *      set_value(x);
356  *      mature_immBlock(block_before_loop);
357  *      before2header = new_Jmp;
358  *
359  *      loop_header = new_immBlock ();
360  *      set_cur_block(loop_header);
361  *      header2body - new_Jmp();
362  *
363  *      loop_body = new_immBlock ();
364  *      set_cur_block(loop_body);
365  *      body2header = new_Jmp();
366  *
367  *      add_immBlock_pred(loop_header, before2header);
368  *      add_immBlock_pred(loop_header, body2header);
369  *      add_immBlock_pred(loop_body, header2body);
370  *
371  *      mature_immBlock(loop_header);
372  *      mature_immBlock(loop_body);
373  *
374  *      get_value(loop_body, x);   //  gets the Phi in loop_header
375  *      set_value(loop_header, x); //  sets the value the above get_value should
376  *                                 //  have returned!!!
377  *
378  *    Mature_immBlock also fixes the number of inputs to the Phi nodes.  Mature_immBlock
379  *    should be called as early as possible, as afterwards the generation of Phi
380  *    nodes is more efficient.
381  *
382  *    Inputs:
383  *      There is an input for each control flow predecessor of the block.
384  *      The input points to an instruction producing an output of type X.
385  *      Possible predecessors:  Start, Jmp, Cond, Raise or Return or any node
386  *      possibly causing an exception.  (Often the real predecessors are Projs.)
387  *    Output:
388  *      Mode BB (R), all nodes belonging to this block should consume this output.
389  *      As they are strict (except Block and Phi node) it is a necessary condition
390  *      that the block node executed before any other node in this block executes.
391  *    Attributes:
392  *      block.matured  Indicates whether the block is mature.
393  *      block.**graph_arr
394  *                      This attribute contains all local values valid in this
395  *                      block. This is needed to build the Phi nodes and removed
396  *                      if the graph is complete.  This field is used by the
397  *              internal construction algorithm and should not be accessed
398  *              from outside.
399  *
400  *
401  *    ir_node *new_Block (int arity, ir_node **in)
402  *    --------------------------------------------
403  *
404  *    Creates a new Block with the given list of predecessors.  This block
405  *    is mature.  As other constructors calls optimization and verify for the
406  *    block.  If one of the predecessors is Unknown (as it has to be filled in
407  *    later) optimizations are skipped.  This is necessary to
408  *    construct Blocks in loops.
409  *
410  *
411  *    CONTROL FLOW OPERATIONS
412  *    -----------------------
413  *
414  *    In each block there must be exactly one of the control flow
415  *    operations Start, End, Jmp, Cond, Return or Raise.  The output of a
416  *    control flow operation points to the block to be executed next.
417  *
418  *    ir_node *new_Start (void)
419  *    -------------------------
420  *
421  *    Creates a start node.  Not actually needed public.  There is only one such
422  *   node in each procedure which is automatically created by new_ir_graph.
423  *
424  *    Inputs:
425  *      No inputs except the block it belongs to.
426  *    Output:
427  *      A tuple of 4 (5, 6) distinct values. These are labeled by the following
428  *      projection numbers (pn_Start):
429  *      * pn_Start_X_initial_exec    mode X, points to the first block to be exe *                                   cuted.
430  *      * pn_Start_M                 mode M, the global store
431  *      * pn_Start_P_frame_base      mode P, a pointer to the base of the proce  *                                   dures stack frame.
432  *      * pn_Start_P_globals         mode P, a pointer to the part of the memory *                                   containing_all_ global things.
433  *      * pn_Start_T_args            mode T, a tuple containing all arguments of *                                   the procedure.
434  *
435  *
436  *    ir_node *new_End (void)
437  *    -----------------------
438  *
439  *    Creates an end node.  Not actually needed public.  There is only one such
440  *   node in each procedure which is automatically created by new_ir_graph.
441  *
442  *    Inputs:
443  *      No inputs except the block it belongs to.
444  *    Output:
445  *      No output.
446  *
447  *    ir_node *new_Jmp (void)
448  *    -----------------------
449  *
450  *    Creates a Jmp node.
451  *
452  *    Inputs:
453  *      The block the node belongs to
454  *    Output:
455  *      Control flow to the next block.
456  *
457  *    ir_node *new_IJmp (ir_node *tgt)
458  *    -----------------------
459  *
460  *    Creates an IJmp node.
461  *
462  *    Inputs:
463  *      The node that represents the target jump address
464  *    Output:
465  *      Control flow to an unknown target, must be pinned by
466  *      the End node.
467  *
468  *    ir_node *new_Cond (ir_node *c)
469  *    ------------------------------
470  *
471  *    Creates a Cond node.  There are two versions of this node.
472  *
473  *    The Boolean Cond:
474  *    Input:
475  *      A value of mode b.
476  *    Output:
477  *      A tuple of two control flows.  The first is taken if the input is
478  *      false, the second if it is true.
479  *
480  *    The Switch Cond:
481  *    Input:
482  *      A value of mode I_u. (i)
483  *    Output:
484  *      A tuple of n control flows.  If the Cond's input is i, control
485  *      flow will proceed along output i. If the input is >= n control
486  *      flow proceeds along output n.
487  *
488  *    ir_node *new_Return (ir_node *store, int arity, ir_node **in)
489  *    -------------------------------------------------------------
490  *
491  *    The Return node has as inputs the results of the procedure.  It
492  *    passes the control flow to the end_block.
493  *
494  *    Inputs:
495  *      The memory state.
496  *      All results.
497  *    Output
498  *      Control flow to the end block.
499  *
500  *
501  *    ir_node *new_Const (ir_tarval *con)
502  *    -----------------------------------------------
503  *
504  *    Creates a constant in the constant table and adds a Const node
505  *    returning this value to the start block. The mode is derived
506  *    from the tarval.
507  *
508  *    Parameters:
509  *      *con             Points to an entry in the constant table.
510  *                       This pointer is added to the attributes of
511  *                       the node (self->attr.con)
512  *    Inputs:
513  *      No inputs except the block it belogns to.
514  *    Output:
515  *      The constant value.
516  *    Attribute:
517  *      attr.con   A tarval* pointer to the proper entry in the constant
518  *                 table.
519  *
520  *    ir_node *new_SymConst (ir_mode *mode, union symconst_symbol value, symconst_addr_ent kind)
521  *    -----------------------------------------------------------------------------------------
522  *
523  *    There are several symbolic constants:
524  *     symconst_type_tag   The symbolic constant represents a type tag.
525  *     symconst_type_size  The symbolic constant represents the size of a type.
526  *     symconst_type_align The symbolic constant represents the alignment of a type.
527  *     symconst_addr_ent   The symbolic constant represents the address of an entity.
528  *     symconst_ofs_ent    The symbolic constant represents the offset of an
529  *                         entity in its owner type.
530  *     symconst_enum_const The symbolic constant is a enumeration constant of an
531  *                         enumeration type.
532  *
533  *    Parameters
534  *      mode        P for SymConsts representing addresses, Iu otherwise.
535  *      value       The type, ident, entity or enum constant, depending on the
536  *                  kind
537  *      kind        The kind of the symbolic constant, see the list above.
538  *
539  *    Inputs:
540  *      No inputs except the block it belongs to.
541  *    Output:
542  *      A symbolic constant.
543  *
544  *    Attributes:
545  *      attr.i.num       The symconst_addr_ent, i.e. one of
546  *                        -symconst_type_tag
547  *                        -symconst_type_size
548  *                        -symconst_type_align
549  *                        -symconst_addr_ent
550  *
551  *    If the attr.i.num is symconst_type_tag, symconst_type_size or symconst_type_align,
552  *    the node contains an attribute:
553  *
554  *      attr.i.*type,    a pointer to a type_class.
555  *        if it is linkage_ptr_info it contains
556  *      attr.i.*ptrinfo,  an ident holding information for the linker.
557  *
558  *    ---------------
559  *
560  *    ir_node *new_simpleSel (ir_node *store, ir_node *frame, ir_entity *sel)
561  *    -----------------------------------------------------------------------
562  *
563  *
564  *    Selects an entity from a compound type. This entity can be a field or
565  *    a method.
566  *
567  *    Parameters:
568  *      *store     The memory in which the object the entity should be selected
569  *                 from is allocated.
570  *      *frame     The pointer to the object.
571  *      *sel       The entity to select.
572  *
573  *    Inputs:
574  *      The memory containing the object.
575  *      A pointer to the object.
576  *      An unsigned integer.
577  *    Output:
578  *      A pointer to the selected entity.
579  *    Attributes:
580  *      attr.sel   Pointer to the entity
581  *
582  *
583  *    ir_node *new_Sel (ir_node *store, ir_node *frame, int arity, ir_node **in,
584  *    --------------------------------------------------------------------------
585  *                      ir_entity *sel)
586  *                      ---------------
587  *
588  *    Selects a field from an array type.  The entity has as owner the array, as
589  *    type the arrays element type.  The indices to access an array element are
590  *    given also.
591  *
592  *    Parameters:
593  *      *store     The memory in which the object the entity should be selected from
594  *                 is allocated.
595  *      *frame     The pointer to the object.
596  *      *arity     number of array indices.
597  *      *in        array with index inputs to the node.
598  *      *sel       The entity to select.
599  *
600  *    Inputs:
601  *      The memory containing the object.
602  *      A pointer to the object.
603  *      As much unsigned integer as there are array expressions.
604  *    Output:
605  *      A pointer to the selected entity.
606  *    Attributes:
607  *      attr.sel   Pointer to the entity
608  *
609  *    The constructors new_Sel and new_simpleSel generate the same IR nodes.
610  *    simpleSel just sets the arity of the index inputs to zero.
611  *
612  *
613  *    ARITHMETIC OPERATIONS
614  *    ---------------------
615  *
616  *    ir_node *new_Call (ir_node *store, ir_node *callee, int arity, ir_node **in,
617  *    ----------------------------------------------------------------------------
618  *                       type_method *type)
619  *                       ------------------
620  *
621  *    Creates a procedure call.
622  *
623  *    Parameters
624  *      *store           The actual store.
625  *      *callee          A pointer to the called procedure.
626  *      arity            The number of procedure parameters.
627  *      **in             An array with the pointers to the parameters.
628  *                       The constructor copies this array.
629  *      *type            Type information of the procedure called.
630  *
631  *    Inputs:
632  *      The store, the callee and the parameters.
633  *    Output:
634  *      A tuple containing the eventually changed store and the procedure
635  *      results.
636  *    Attributes:
637  *      attr.call        Contains the attributes for the procedure.
638  *
639  *    ir_node *new_Builtin(ir_node *store, ir_builtin_kind kind, int arity, ir_node **in,
640  *    -----------------------------------------------------------------------------------
641  *                       type_method *type)
642  *                       ------------------
643  *
644  *    Creates a builtin call.
645  *
646  *    Parameters
647  *      *store           The actual store.
648  *      kind             Describes the called builtin.
649  *      arity            The number of procedure parameters.
650  *      **in             An array with the pointers to the parameters.
651  *                       The constructor copies this array.
652  *      *type            Type information of the procedure called.
653  *
654  *    Inputs:
655  *      The store, the kind and the parameters.
656  *    Output:
657  *      A tuple containing the eventually changed store and the procedure
658  *      results.
659  *    Attributes:
660  *      attr.builtin     Contains the attributes for the called builtin.
661  *
662  *    ir_node *new_Add (ir_node *op1, ir_node *op2, ir_mode *mode)
663  *    ------------------------------------------------------------
664  *
665  *    Trivial.
666  *
667  *    ir_node *new_Sub (ir_node *op1, ir_node *op2, ir_mode *mode)
668  *    ------------------------------------------------------------
669  *
670  *    Trivial.
671  *
672  *    ir_node *new_Minus (ir_node *op, ir_mode *mode)
673  *    -----------------------------------------------
674  *
675  *    Unary Minus operations on integer and floating point values.
676  *
677  *    ir_node *new_Mul (ir_node *op1, ir_node *op2, ir_mode *mode)
678  *    ------------------------------------------------------------
679  *
680  *    Trivial.
681  *
682  *    ir_node *new_Mulh (ir_node *op1, ir_node *op2, ir_mode *mode)
683  *    ------------------------------------------------------------
684  *
685  *    Returns the high order bits of a n*n=2n multiplication.
686  *
687  *    ir_node *new_Div (ir_node *memop, ir_node *op1, ir_node *op2, ir_mode *mode, op_pin_state state)
688  *    ------------------------------------------------------------------------------------------------
689  *
690  *    Trivial.
691  *
692  *    ir_node *new_Mod (ir_node *memop, ir_node *op1, ir_node *op2, ir_mode *mode, op_pin_state state)
693  *    ------------------------------------------------------------------------------------------------
694  *
695  *    Trivial.
696  *
697  *    ir_node *new_And (ir_node *op1, ir_node *op2, ir_mode *mode)
698  *    ------------------------------------------------------------
699  *
700  *    Trivial.
701  *
702  *    ir_node *new_Or (ir_node *op1, ir_node *op2, ir_mode *mode)
703  *    -----------------------------------------------------------
704  *
705  *    Trivial.
706  *
707  *    ir_node *new_Eor (ir_node *op1, ir_node *op2, ir_mode *mode)
708  *    ------------------------------------------------------------
709  *
710  *    Trivial.
711  *
712  *    ir_node *new_Not (ir_node *op, ir_mode *mode)
713  *    ---------------------------------------------
714  *
715  *    This node constructs a constant where all bits are set to one
716  *    and a Eor of this constant and the operator.  This simulates a
717  *    Not operation.
718  *
719  *    ir_node *new_Shl (ir_node *op, ir_node *k, ir_mode *mode)
720  *    ---------------------------------------------------------
721  *
722  *    Trivial.
723  *
724  *    ir_node *new_Shr (ir_node *op, ir_node *k, ir_mode *mode)
725  *    ---------------------------------------------------------
726  *
727  *    Logic shift right, i.e., zero extended.
728  *
729  *
730  *    ir_node *new_Shrs (ir_node *op, ir_node *k, ir_mode *mode)
731  *    ----------------------------------------------------------
732  *
733  *    Arithmetic shift right, i.e., sign extended.
734  *
735  *    ir_node *new_Rotl (ir_node *op, ir_node *k, ir_mode *mode)
736  *    ---------------------------------------------------------
737  *
738  *    Rotates the operand to the left by k bits.
739  *
740  *    ir_node *new_Carry (ir_node *op1, ir_node *op2, ir_mode *mode)
741  *    ------------------------------------------------------------
742  *
743  *    Calculates the Carry value for integer addition. Used only
744  *    in lowering code.
745  *
746  *    ir_node *new_Borrow (ir_node *op1, ir_node *op2, ir_mode *mode)
747  *    ------------------------------------------------------------
748  *
749  *    Calculates the Borrow value for integer substraction. Used only
750  *    in lowering code.
751  *
752  *    ir_node *new_Conv (ir_node *op, ir_mode *mode)
753  *    ---------------------------------------------
754  *
755  *    Mode conversion.  For allowed conversions see UKA Tech Report
756  *    1999-14.
757  *
758  *    ir_node *new_Cmp (ir_node *op1, ir_node *op2)
759  *    ---------------------------------------------
760  *
761  *    Input:
762  *      The two values to be compared.
763  *    Output:
764  *      A 16-tuple containing the results of the 16 different comparisons.
765  *      The following is a list giving the comparisons and a projection
766  *      number (pn_Cmp) to use in Proj nodes to extract the proper result.
767  *        pn_Cmp_False false
768  *        pn_Cmp_Eq    equal
769  *        pn_Cmp_Lt    less
770  *        pn_Cmp_Le    less or equal
771  *        pn_Cmp_Gt    greater
772  *        pn_Cmp_Ge    greater of equal
773  *        pn_Cmp_Lg    less or greater
774  *        pn_Cmp_Leg   less, equal or greater = ordered
775  *        pn_Cmp_Uo    unordered
776  *        pn_Cmp_Ue    unordered or equal
777  *        pn_Cmp_Ul    unordered or less
778  *        pn_Cmp_Ule   unordered, less or equal
779  *        pn_Cmp_Ug    unordered or greater
780  *        pn_Cmp_Uge   unordered, greater or equal
781  *        pn_Cmp_Ne    unordered, less or greater = not equal
782  *        pn_Cmp_True  true
783  *
784  *
785  *
786  *    ------------
787  *
788  *    In general, Phi nodes are automaitcally inserted.  In some cases, if
789  *    all predecessors of a block are known, an explicit Phi node constructor
790  *    is needed.  E.g., to construct a FIRM graph for a statement as
791  *      a = (b==c) ? 2 : 5;
792  *
793  *    ir_node *new_Phi (int arity, ir_node **in, ir_mode *mode)
794  *    ---------------------------------------------------------
795  *
796  *    Creates a Phi node. The in's order has to correspond to the order
797  *    of in's of current_block.  This is not checked by the library!
798  *    If one of the predecessors is Unknown (as it has to be filled in
799  *    later) optimizations are skipped.  This is necessary to
800  *    construct Phi nodes in loops.
801  *
802  *    Parameter
803  *      arity            number of predecessors
804  *      **in             array with predecessors
805  *      *mode            The mode of its inputs and output.
806  *    Inputs:
807  *      A Phi node has as many inputs as the block it belongs to.
808  *      Each input points to a definition of the same value on a
809  *      different path in the control flow.
810  *    Output
811  *      The definition valid in this block.
812  *
813  *    ir_node *new_Mux (ir_node *sel, ir_node *ir_false, ir_node *ir_true, ir_mode *mode)
814  *    -----------------------------------------------------------------------------------
815  *
816  *    Creates a Mux node. This node implements the following semantic:
817  *    If the sel node (which must be of mode_b) evaluates to true, its value is
818  *    ir_true, else ir_false;
819  *
820  *
821  *
822  *    OPERATIONS TO MANAGE MEMORY EXPLICITLY
823  *    --------------------------------------
824  *
825  *    ir_node *new_Load (ir_node *store, ir_node *addr, ir_mode *mode, ir_cons_flags flags)
826  *    -------------------------------------------------------------------------------------
827  *
828  *    The Load operation reads a value from memory.
829  *
830  *    Parameters:
831  *    *store        The current memory.
832  *    *addr         A pointer to the variable to be read in this memory.
833  *    *mode         The mode of the value to be loaded.
834  *     flags        Additional flags for alignment, volatility and pin state.
835  *
836  *    Inputs:
837  *      The memory and a pointer to a variable in this memory.
838  *    Output:
839  *      A tuple of the memory, a control flow to be taken in case of
840  *      an exception and the loaded value.
841  *
842  *    ir_node *new_Store (ir_node *store, ir_node *addr, ir_node *val, ir_cons_flags flags)
843  *    -------------------------------------------------------------------------------------
844  *
845  *    The Store operation writes a value to a variable in memory.
846  *
847  *    Inputs:
848  *      The memory, a pointer to a variable in this memory and the value
849  *      to write to this variable.
850  *    Output:
851  *      A tuple of the changed memory and a control flow to be taken in
852  *      case of an exception.
853  *
854  *    ir_node *new_Alloc (ir_node *store, ir_node *count, ir_type *alloc_type,
855  *    -----------------------------------------------------------------------
856  *                        where_alloc where)
857  *                        ------------------
858  *
859  *    The Alloc node allocates a new variable.  It can be specified whether the
860  *    variable should be allocated to the stack or to the heap.
861  *
862  *    Parameters:
863  *      *store       The memory which shall contain the new variable.
864  *      *count       This field is for allocating arrays, it specifies how
865  *                   many array elements are to be allocated.
866  *      *alloc_type  The type of the allocated variable. In case of allocating
867  *                   arrays this has to be the array type, not the type of the
868  *                   array elements.
869  *      where        Where to allocate the variable, either heap_alloc or stack_alloc.
870  *
871  *    Inputs:
872  *      A memory and an unsigned integer.
873  *    Output:
874  *      A tuple of the changed memory, a control flow to be taken in
875  *      case of an exception and the pointer to the new variable.
876  *    Attributes:
877  *      a.where          Indicates where the variable is allocated.
878  *      a.*type          A pointer to the class the allocated data object
879  *                       belongs to.
880  *
881  *    ir_node *new_Free (ir_node *store, ir_node *ptr, ir_node *size, ir_type *free_type,
882  *    -----------------------------------------------------------------------------------
883  *                        where_alloc where)
884  *                        ------------------
885  *
886  *    The Free node frees memory of the given variable.
887  *
888  *    Parameters:
889  *      *store       The memory which shall contain the new variable.
890  *      *ptr         The pointer to the object to free.
891  *      *size        The number of objects of type free_type to free in a sequence.
892  *      *free_type   The type of the freed variable.
893  *      where        Where the variable was allocated, either heap_alloc or stack_alloc.
894  *
895  *    Inputs:
896  *      A memory, a pointer and an unsigned integer.
897  *    Output:
898  *      The changed memory.
899  *    Attributes:
900  *      f.*type          A pointer to the type information of the freed data object.
901  *
902  *    Not Implemented!
903  *
904  *    ir_node *new_Sync (int arity, ir_node **in)
905  *    -------------------------------------------
906  *
907  *    The Sync operation unifies several partial memory blocks.  These blocks
908  *    have to be pairwise disjunct or the values in common locations have to
909  *    be identical.  This operation allows to specify all operations that eventually
910  *    need several partial memory blocks as input with a single entrance by
911  *    unifying the memories with a preceding Sync operation.
912  *
913  *    Parameters
914  *      arity    The number of memories to synchronize.
915  *      **in     An array of pointers to nodes that produce an output of
916  *               type memory.
917  *    Inputs
918  *      Several memories.
919  *    Output
920  *      The unified memory.
921  *
922  *
923  *    SPECIAL OPERATIONS
924  *    ------------------
925  *
926  *    ir_node *new_NoMem (void)
927  *    -----------------------------------------------------------------------------------
928  *
929  *    Returns the unique NoMem node current_ir_graph->no_mem.
930  *    This node is used as input for operations that need a Memory, but do not
931  *    change it like Div by const != 0, analyzed calls etc.
932  *
933  *    ir_node *new_Proj (ir_node *arg, ir_mode *mode, long proj)
934  *    ----------------------------------------------------------
935  *
936  *    Selects one entry of a tuple.  This is a hidden edge with attributes.
937  *
938  *    Parameters
939  *      *arg      A node producing a tuple.
940  *      *mode     The mode of the value to project.
941  *      proj      The position of the value in the tuple.
942  *    Input:
943  *      The tuple.
944  *    Output:
945  *      The value.
946  *
947  *    ir_node *new_Tuple (int arity, ir_node **in)
948  *    --------------------------------------------
949  *
950  *    Builds a Tuple from single values.  This is needed to implement
951  *    optimizations that remove a node that produced a tuple.  The node can be
952  *    replaced by the Tuple operation so that the following Proj nodes have not to
953  *    be changed.  (They are hard to find due to the implementation with pointers
954  *    in only one direction.)  The Tuple node is smaller than any other
955  *    node, so that a node can be changed into a Tuple by just changing its
956  *    opcode and giving it a new in array.
957  *
958  *    Parameters
959  *      arity    The number of tuple elements.
960  *      **in     An array containing pointers to the nodes producing the
961  *               tuple elements.
962  *
963  *    ir_node *new_Id (ir_node *val, ir_mode *mode)
964  *    ---------------------------------------------
965  *
966  *    The single output of the Id operation is its input.  Also needed
967  *    for optimizations.
968  *
969  *
970  *    HIGH LEVEL OPERATIONS
971  *    ---------------------
972  *
973  *    ir_node *new_CopyB (ir_node *store, ir_node *dst, ir_node *src, ir_type *data_type)
974  *    -----------------------------------------------------------------------------------
975  *
976  *    Describes a high level block copy of a compound type from address src to
977  *    address dst. Must be lowered to a Call to a runtime memory copy function.
978  *
979  *
980  *    HIGH LEVEL OPERATIONS: Exception Support
981  *    ----------------------------------------
982  *    See TechReport 1999-14, chapter Exceptions.
983  *
984  *    ir_node *new_InstOf(ir_node *store, ir_node *ptr, ir_type *type);
985  *    -----------------------------------------------------------------------------------
986  *
987  *    Describes a high level type check. Must be lowered to a Call to a runtime check
988  *    function.
989  *
990  *    ir_node *new_Raise (ir_node *store, ir_node *obj)
991  *    -------------------------------------------------
992  *
993  *    Raises an exception.  Unconditional change of control flow.  Writes
994  *    an explicit Except variable to memory to pass it to the exception
995  *    handler.  Must be lowered to a Call to a runtime check
996  *    function.
997  *
998  *    Inputs:
999  *      The memory state.
1000  *      A pointer to the Except variable.
1001  *    Output:
1002  *      A tuple of control flow and the changed memory state.  The control flow
1003  *      points to the exception handler if it is definied in this procedure,
1004  *      else it points to the end_block.
1005  *
1006  *    ir_node *new_Bound  (ir_node *store, ir_node *idx, ir_node *lower, ir_node *upper);
1007  *    -----------------------------------------------------------------------------------
1008  *
1009  *    Describes a high level bounds check. Must be lowered to a Call to a runtime check
1010  *    function.
1011  *
1012  *    ir_node *new_Pin  (ir_node *node);
1013  *    -----------------------------------------------------------------------------------
1014  *
1015  *    Pin the value of the node node in the current block  No users of the Pin node can
1016  *    float above the Block of the Pin. The node cannot float behind this block. Often
1017  *    used to Pin the NoMem node.
1018  *
1019  *
1020  *    COPING WITH DATA OBJECTS
1021  *    ========================
1022  *
1023  *    Two kinds of data objects have to be distinguished for generating
1024  *    FIRM.  First there are local variables other than arrays that are
1025  *    known to be alias free.  Second there are all other data objects.
1026  *    For the first a common SSA representation is built, the second
1027  *    are modeled by saving them to memory.  The memory is treated as
1028  *    a single local variable, the alias problem is hidden in the
1029  *    content of this variable.
1030  *
1031  *    All values known in a Block are listed in the block's attribute,
1032  *    block.**graph_arr which is used to automatically insert Phi nodes.
1033  *    The following two functions can be used to add a newly computed value
1034  *    to the array, or to get the producer of a value, i.e., the current
1035  *    live value.
1036  *
1037  *    inline void set_value (int pos, ir_node *value)
1038  *    -----------------------------------------------
1039  *
1040  *    Has to be called for every assignment to a local variable.  It
1041  *    adds the value to the array of used values at position pos.  Pos
1042  *    has to be a unique identifier for an entry in the procedure's
1043  *    definition table.  It can be used to access the value again.
1044  *    Requires current_block to be set correctly.
1045  *
1046  *    ir_node *get_value (int pos, ir_mode *mode)
1047  *    -------------------------------------------
1048  *
1049  *    Returns the node defining the value referred to by pos. If the
1050  *    value is not defined in this block a Phi node is generated and
1051  *    all definitions reaching this Phi node are collected.  It can
1052  *    happen that the algorithm allocates an unnecessary Phi node,
1053  *    e.g. if there is only one definition of this value, but this
1054  *    definition reaches the currend block on several different
1055  *    paths.  This Phi node will be eliminated if optimizations are
1056  *    turned on right after its creation.
1057  *    Requires current_block to be set correctly.
1058  *
1059  *    There are two special routines for the global store:
1060  *
1061  *    void set_store (ir_node *store)
1062  *    -------------------------------
1063  *
1064  *    Adds the store to the array of known values at a reserved
1065  *    position.
1066  *    Requires current_block to be set correctly.
1067  *
1068  *    ir_node *get_store (void)
1069  *    -------------------------
1070  *
1071  *    Returns the node defining the actual store.
1072  *    Requires current_block to be set correctly.
1073  *
1074  *
1075  *    inline void keep_alive (ir_node *ka)
1076  *    ------------------------------------
1077  *
1078  *    Keep this node alive because it is (might be) not in the control
1079  *    flow from Start to End.  Adds the node to the list in the end
1080  *   node.
1081  *
1082  */
1083 #ifndef FIRM_IR_IRCONS_H
1084 #define FIRM_IR_IRCONS_H
1085
1086 #include "firm_types.h"
1087 #include "begin.h"
1088 #include "irnode.h"
1089
1090 /*-------------------------------------------------------------------------*/
1091 /* The raw interface                                                       */
1092 /*-------------------------------------------------------------------------*/
1093
1094 /**
1095  * Constructor for a Const node.
1096  *
1097  * Adds the node to the start block.
1098  *
1099  * Constructor for a Const node. The constant represents a target
1100  * value.  Sets the type information to type_unknown.  (No more
1101  * supported: If tv is entity derives a somehow useful type.)
1102  *
1103  * @param *db    A pointer for debug information.
1104  * @param *irg   The IR graph the node  belongs to.
1105  * @param *mode  The mode of the operands and results.
1106  * @param value  A value from which the tarval is made.
1107  */
1108 FIRM_API ir_node *new_rd_Const_long(dbg_info *db, ir_graph *irg,
1109                                     ir_mode *mode, long value);
1110
1111 /** Constructor for a SymConst node.
1112  *
1113  *  This is the constructor for a symbolic constant.
1114  *    There are several kinds of symbolic constants:
1115  *    - symconst_type_tag   The symbolic constant represents a type tag.  The
1116  *                          type the tag stands for is given explicitly.
1117  *    - symconst_type_size  The symbolic constant represents the size of a type.
1118  *                          The type of which the constant represents the size
1119  *                          is given explicitly.
1120  *    - symconst_type_align The symbolic constant represents the alignment of a
1121  *                          type.  The type of which the constant represents the
1122  *                          size is given explicitly.
1123  *    - symconst_addr_ent   The symbolic constant represents the address of an
1124  *                          entity (variable or method).  The variable is given
1125  *                          explicitly by a firm entity.
1126  *    - symconst_ofs_ent    The symbolic constant represents the offset of an
1127  *                          entity in its owner type.
1128  *    - symconst_enum_const The symbolic constant is a enumeration constant of
1129  *                          an enumeration type.
1130  *
1131  *    Inputs to the node:
1132  *      No inputs except the block it belongs to.
1133  *    Outputs of the node.
1134  *      An unsigned integer (I_u) or a pointer (P).
1135  *
1136  *    Mention union in declaration so that the firmjni generator recognizes that
1137  *    it can not cast the argument to an int.
1138  *
1139  * @param *db     A pointer for debug information.
1140  * @param *irg    The IR graph the node  belongs to.
1141  * @param mode    The mode for the SymConst.
1142  * @param value   A type, ident, entity or enum constant depending on the
1143  *                SymConst kind.
1144  * @param kind    The kind of the symbolic constant, see the list above
1145  */
1146 FIRM_API ir_node *new_rd_SymConst(dbg_info *db, ir_graph *irg, ir_mode *mode,
1147                                   union symconst_symbol value,
1148                                   symconst_kind kind);
1149
1150 /** Constructor for a SymConst addr_ent node.
1151  *
1152  * Same as new_rd_SymConst, except that the constructor is tailored for
1153  * symconst_addr_ent.
1154  * Adds the SymConst to the start block of irg. */
1155 FIRM_API ir_node *new_rd_SymConst_addr_ent(dbg_info *db, ir_graph *irg,
1156                                            ir_mode *mode, ir_entity *symbol);
1157
1158 /** Constructor for a SymConst ofs_ent node.
1159  *
1160  * Same as new_rd_SymConst, except that the constructor is tailored for
1161  * symconst_ofs_ent.
1162  * Adds the SymConst to the start block of irg.
1163  */
1164 FIRM_API ir_node *new_rd_SymConst_ofs_ent(dbg_info *db, ir_graph *irg,
1165                                           ir_mode *mode, ir_entity *symbol);
1166
1167 /** Constructor for a SymConst type_tag node.
1168  *
1169  * Same as new_rd_SymConst, except that the constructor is tailored for
1170  * symconst_type_tag.
1171  * Adds the SymConst to the start block of irg.
1172  */
1173 FIRM_API ir_node *new_rd_SymConst_type_tag(dbg_info *db, ir_graph *irg,
1174                                            ir_mode *mode, ir_type *symbol);
1175
1176 /** Constructor for a SymConst size node.
1177  *
1178  * Same as new_rd_SymConst, except that the constructor is tailored for
1179  * symconst_type_size.
1180  * Adds the SymConst to the start block of irg. */
1181 FIRM_API ir_node *new_rd_SymConst_size(dbg_info *db, ir_graph *irg,
1182                                        ir_mode *mode, ir_type *symbol);
1183
1184 /** Constructor for a SymConst size node.
1185  *
1186  * Same as new_rd_SymConst, except that the constructor is tailored for
1187  * symconst_type_align.
1188  * Adds the SymConst to the start block of irg.
1189  */
1190 FIRM_API ir_node *new_rd_SymConst_align(dbg_info *db, ir_graph *irg,
1191                                         ir_mode *mode, ir_type *symbol);
1192
1193 /** Constructor for a simpleSel node.
1194  *
1195  *  This is a shortcut for the new_rd_Sel() constructor.  To be used for
1196  *  Sel nodes that do not select from an array, i.e., have no index
1197  *  inputs.  It adds the two parameters 0, NULL.
1198  *
1199  * @param   *db        A pointer for debug information.
1200  * @param   *block     The IR block the node belongs to.
1201  * @param   *store     The memory in which the object the entity should be
1202  *                     selected from is allocated.
1203  * @param   *objptr    The object from that the Sel operation selects a
1204  *                     single attribute out.
1205  * @param   *ent       The entity to select.
1206  */
1207 FIRM_API ir_node *new_rd_simpleSel(dbg_info *db, ir_node *block, ir_node *store,
1208                                    ir_node *objptr, ir_entity *ent);
1209
1210 /** Constructor for a remainderless Div node.
1211  *
1212  * @param   *db    A pointer for debug information.
1213  * @param   *block The IR block the node belongs to.
1214  * @param   *memop The store needed to model exceptions
1215  * @param   *op1   The first operand.
1216  * @param   *op2   The second operand.
1217  * @param   *mode  The mode of the result.
1218  * @param   state  The pinned state.
1219  */
1220 FIRM_API ir_node *new_rd_DivRL(dbg_info *db, ir_node *block, ir_node *memop,
1221                                ir_node *op1, ir_node *op2, ir_mode *mode,
1222                                op_pin_state state);
1223
1224 /** Constructor for a strictConv node.
1225  *
1226  * @param   *db    A pointer for debug information.
1227  * @param   *block The IR block the node belongs to.
1228  * @param   *op    The operand.
1229  * @param   *mode  The mode of this the operand muss be converted .
1230  */
1231 FIRM_API ir_node *new_rd_strictConv(dbg_info *db, ir_node *block,
1232                                     ir_node *op, ir_mode *mode);
1233
1234 /** Constructor for a defaultProj node.
1235  *
1236  * Represents the default control flow of a Switch-Cond node.
1237  *
1238  * @param *db       A pointer for debug information.
1239  * @param arg       A node producing a tuple.
1240  * @param max_proj  The end position of the value in the tuple.
1241  */
1242 FIRM_API ir_node *new_rd_defaultProj(dbg_info *db, ir_node *arg, long max_proj);
1243
1244 /** Constructor for an ASM pseudo node.
1245  *
1246  * @param *db         A pointer for debug information.
1247  * @param *block      The block the node belong to.
1248  * @param arity       The number of data inputs to the node.
1249  * @param *in         The array of length arity of data inputs.
1250  * @param *inputs     The array of length arity of input constraints.
1251  * @param n_outs      The number of data outputs to the node.
1252  * @param *outputs    The array of length n_outs of output constraints.
1253  * @param n_clobber   The number of clobbered registers.
1254  * @param *clobber    The array of length n_clobber of clobbered registers.
1255  * @param *asm_text   The assembler text.
1256  */
1257 FIRM_API ir_node *new_rd_ASM(dbg_info *db, ir_node *block,
1258                             int arity, ir_node *in[], ir_asm_constraint *inputs,
1259                             int n_outs, ir_asm_constraint *outputs,
1260                             int n_clobber, ident *clobber[], ident *asm_text);
1261
1262 /*-------------------------------------------------------------------------*/
1263 /* The raw interface without debug support                                 */
1264 /*-------------------------------------------------------------------------*/
1265
1266 /** Constructor for a Const node.
1267  *
1268  * Adds the node to the start block.
1269  *
1270  * Constructor for a Const node. The constant represents a target
1271  * value.  Sets the type information to type_unknown.  (No more
1272  * supported: If tv is entity derives a somehow useful type.)
1273  *
1274  * @param *irg   The IR graph the node  belongs to.
1275  * @param *mode  The mode of the operands and the results.
1276  * @param value  A value from which the tarval is made.
1277  */
1278 FIRM_API ir_node *new_r_Const_long(ir_graph *irg, ir_mode *mode, long value);
1279
1280 /** Constructor for a SymConst node.
1281  *
1282  *  This is the constructor for a symbolic constant.
1283  *    There are several kinds of symbolic constants:
1284  *    - symconst_type_tag   The symbolic constant represents a type tag.  The
1285  *                          type the tag stands for is given explicitly.
1286  *    - symconst_type_size  The symbolic constant represents the size of a type.
1287  *                          The type of which the constant represents the size
1288  *                          is given explicitly.
1289  *    - symconst_type_align The symbolic constant represents the alignment of a
1290  *                          type.  The type of which the constant represents the
1291  *                          size is given explicitly.
1292  *    - symconst_addr_ent   The symbolic constant represents the address of an
1293  *                          entity (variable or method).  The variable is given
1294  *                          explicitly by a firm entity.
1295  *    - symconst_ofs_ent    The symbolic constant represents the offset of an
1296  *                          entity in its owner type.
1297  *    - symconst_enum_const The symbolic constant is a enumeration constant of
1298  *                          an enumeration type.
1299  *
1300  *    Inputs to the node:
1301  *      No inputs except the block it belongs to.
1302  *    Outputs of the node.
1303  *      An unsigned integer (I_u) or a pointer (P).
1304  *
1305  *    Mention union in declaration so that the firmjni generator recognizes that
1306  *    it can not cast the argument to an int.
1307  *
1308  * @param *irg    The IR graph the node  belongs to.
1309  * @param mode    The mode for the SymConst.
1310  * @param value   A type, ident, entity or enum constant depending on the
1311  *                SymConst kind.
1312  * @param kind    The kind of the symbolic constant, see the list above
1313  */
1314 FIRM_API ir_node *new_r_SymConst(ir_graph *irg, ir_mode *mode,
1315                                  union symconst_symbol value,
1316                                  symconst_kind kind);
1317
1318 /** Constructor for a simpleSel node.
1319  *
1320  *  This is a shortcut for the new_d_Sel() constructor.  To be used for
1321  *  Sel nodes that do not select from an array, i.e., have no index
1322  *  inputs.  It adds the two parameters 0, NULL.
1323  *
1324  * @param *block     The IR block the node belongs to.
1325  * @param *store     The memory in which the object the entity should be selected
1326  *                   from is allocated.
1327  * @param *objptr    The object from that the Sel operation selects a
1328  *                   single attribute out.
1329  * @param *ent       The entity to select.
1330  */
1331 FIRM_API ir_node *new_r_simpleSel(ir_node *block, ir_node *store,
1332                                   ir_node *objptr, ir_entity *ent);
1333
1334 /** Constructor for a remainderless Div node.
1335  *
1336  * @param *block The IR block the node belongs to.
1337  * @param *memop The store needed to model exceptions
1338  * @param *op1   The first operand.
1339  * @param *op2   The second operand.
1340  * @param *mode  The mode of the result.
1341  * @param state  The pinned state.
1342  */
1343 FIRM_API ir_node *new_r_DivRL(ir_node *block, ir_node *memop,
1344                               ir_node *op1, ir_node *op2, ir_mode *mode,
1345                               op_pin_state state);
1346 /** Constructor for a strict Conv node.
1347  *
1348  * @param *block The IR block the node belongs to.
1349  * @param *op    The operand.
1350  * @param *mode  The mode of this the operand muss be converted .
1351  */
1352 FIRM_API ir_node *new_r_strictConv(ir_node *block, ir_node *op, ir_mode *mode);
1353
1354 /** Constructor for a defaultProj node.
1355  *
1356  * Represents the default control flow of a Switch-Cond node.
1357  *
1358  * @param arg       A node producing a tuple.
1359  * @param max_proj  The end  position of the value in the tuple.
1360  */
1361 FIRM_API ir_node *new_r_defaultProj(ir_node *arg, long max_proj);
1362
1363 /** Constructor for an ASM pseudo node.
1364  *
1365  * @param *block      The block the node belong to.
1366  * @param arity       The number of data inputs to the node.
1367  * @param *in         The array of length arity of data inputs.
1368  * @param *inputs     The array of length arity of input constraints.
1369  * @param n_outs      The number of data outputs to the node.
1370  * @param *outputs    The array of length n_outs of output constraints.
1371  * @param n_clobber   The number of clobbered registers.
1372  * @param *clobber    The array of length n_clobber of clobbered registers.
1373  * @param *asm_text   The assembler text.
1374  */
1375 FIRM_API ir_node *new_r_ASM(ir_node *block,
1376                             int arity, ir_node *in[], ir_asm_constraint *inputs,
1377                             int n_outs, ir_asm_constraint *outputs,
1378                             int n_clobber, ident *clobber[], ident *asm_text);
1379
1380 /*-----------------------------------------------------------------------*/
1381 /* The block oriented interface                                          */
1382 /*-----------------------------------------------------------------------*/
1383
1384 /** Sets the current block in which the following constructors place the
1385  *  nodes they construct.
1386  *
1387  *  @param target  The new current block.
1388  */
1389 FIRM_API void set_cur_block(ir_node *target);
1390 FIRM_API void set_r_cur_block(ir_graph *irg, ir_node *target);
1391
1392 /** Returns the current block of the current graph. */
1393 FIRM_API ir_node *get_cur_block(void);
1394 FIRM_API ir_node *get_r_cur_block(ir_graph *irg);
1395
1396 /**
1397  * @see new_rd_Const_long()
1398  *
1399  * @param *db    A pointer for debug information.
1400  * @param *mode  The mode of the operands and results.
1401  * @param value  A value from which the tarval is made.
1402  */
1403 FIRM_API ir_node *new_d_Const_long(dbg_info *db, ir_mode *mode, long value);
1404
1405 /** Constructor for a SymConst node.
1406  *
1407  *  This is the constructor for a symbolic constant.
1408  *    There are several kinds of symbolic constants:
1409  *    - symconst_type_tag   The symbolic constant represents a type tag.  The
1410  *                          type the tag stands for is given explicitly.
1411  *    - symconst_type_size  The symbolic constant represents the size of a type.
1412  *                          The type of which the constant represents the size
1413  *                          is given explicitly.
1414  *    - symconst_type_align The symbolic constant represents the alignment of a
1415  *                          type.  The type of which the constant represents the
1416  *                          size is given explicitly.
1417  *    - symconst_addr_ent   The symbolic constant represents the address of an
1418  *                          entity (variable or method).  The variable is given
1419  *                          explicitly by a firm entity.
1420  *    - symconst_ofs_ent    The symbolic constant represents the offset of an
1421  *                          entity in its owner type.
1422  *    - symconst_enum_const The symbolic constant is a enumeration constant of
1423  *                          an enumeration type.
1424  *
1425  *    Inputs to the node:
1426  *      No inputs except the block it belongs to.
1427  *    Outputs of the node.
1428  *      An unsigned integer (I_u) or a pointer (P).
1429  *
1430  *    Mention union in declaration so that the firmjni generator recognizes that
1431  *    it can not cast the argument to an int.
1432  *
1433  * @param *db     A pointer for debug information.
1434  * @param mode    The mode for the SymConst.
1435  * @param value   A type, ident, entity or enum constant depending on the
1436  *                SymConst kind.
1437  * @param kind    The kind of the symbolic constant, see the list above
1438  */
1439 FIRM_API ir_node *new_d_SymConst(dbg_info *db, ir_mode *mode,
1440                                  union symconst_symbol value,
1441                                  symconst_kind kind);
1442
1443 /** Constructor for a simpleSel node.
1444  *
1445  *  This is a shortcut for the new_d_Sel() constructor.  To be used for
1446  *  Sel nodes that do not select from an array, i.e., have no index
1447  *  inputs.  It adds the two parameters 0, NULL.
1448  *
1449  * @param   *db        A pointer for debug information.
1450  * @param   *store     The memory in which the object the entity should be
1451  *                     selected from is allocated.
1452  * @param   *objptr    The object from that the Sel operation selects a
1453  *                     single attribute out.
1454  * @param   *ent       The entity to select.
1455  */
1456 FIRM_API ir_node *new_d_simpleSel(dbg_info *db, ir_node *store, ir_node *objptr,
1457                                   ir_entity *ent);
1458 /** Constructor for a remainderless Div node.
1459  *
1460  * Adds the node to the block in current_ir_block.
1461  *
1462  * @param   *db    A pointer for debug information.
1463  * @param   *memop The store needed to model exceptions
1464  * @param   *op1   The first operand.
1465  * @param   *op2   The second operand.
1466  * @param   *mode  The mode of the result.
1467  * @param   state  The pinned state.
1468  */
1469 FIRM_API ir_node *new_d_DivRL(dbg_info *db, ir_node *memop,
1470                               ir_node *op1, ir_node *op2, ir_mode *mode,
1471                               op_pin_state state);
1472 /** Constructor for a strict Conv node.
1473  *
1474  * Adds the node to the block in current_ir_block.
1475  *
1476  * @param   *db    A pointer for debug information.
1477  * @param   *op    The operand.
1478  * @param   *mode  The mode of this the operand muss be converted .
1479  */
1480 FIRM_API ir_node *new_d_strictConv(dbg_info *db, ir_node *op, ir_mode *mode);
1481
1482 /** Constructor for a defaultProj node.
1483  *
1484  * Represents the default control flow of a Switch-Cond node.
1485  * Adds the node to the block in current_ir_block.
1486  *
1487  * @param *db       A pointer for debug information.
1488  * @param arg       A node producing a tuple.
1489  * @param max_proj  The end  position of the value in the tuple.
1490  */
1491 FIRM_API ir_node *new_d_defaultProj(dbg_info *db, ir_node *arg, long max_proj);
1492
1493 /** Constructor for an ASM pseudo node.
1494  *
1495  * @param *db         A pointer for debug information.
1496  * @param arity       The number of data inputs to the node.
1497  * @param *in         The array of length arity of data inputs.
1498  * @param *inputs     The array of length arity of input constraints.
1499  * @param n_outs      The number of data outputs to the node.
1500  * @param *outputs    The array of length n_outs of output constraints.
1501  * @param n_clobber   The number of clobbered registers.
1502  * @param *clobber    The array of length n_clobber of clobbered registers.
1503  * @param *asm_text   The assembler text.
1504  */
1505 FIRM_API ir_node *new_d_ASM(dbg_info *db, int arity, ir_node *in[],
1506                             ir_asm_constraint *inputs,
1507                             int n_outs, ir_asm_constraint *outputs,
1508                             int n_clobber, ident *clobber[], ident *asm_text);
1509
1510 /*-----------------------------------------------------------------------*/
1511 /* The block oriented interface without debug support                    */
1512 /*-----------------------------------------------------------------------*/
1513
1514 /**
1515  * Make a const from a long.
1516  * This is just convenience for the usual
1517  * <code>
1518  * new_Const(mode, tarval_from_long(mode, ...))
1519  * </code>
1520  * pain.
1521  * @param mode The mode for the const.
1522  * @param value The value of the constant.
1523  * @return A new const node.
1524  */
1525 FIRM_API ir_node *new_Const_long(ir_mode *mode, long value);
1526
1527 /** Constructor for a SymConst node.
1528  *
1529  *  This is the constructor for a symbolic constant.
1530  *    There are several kinds of symbolic constants:
1531  *    - symconst_type_tag   The symbolic constant represents a type tag.  The
1532  *                          type the tag stands for is given explicitly.
1533  *    - symconst_type_size  The symbolic constant represents the size of a type.
1534  *                          The type of which the constant represents the size
1535  *                          is given explicitly.
1536  *    - symconst_type_align The symbolic constant represents the alignment of a
1537  *                          type.  The type of which the constant represents the
1538  *                          size is given explicitly.
1539  *    - symconst_addr_ent   The symbolic constant represents the address of an
1540  *                          entity (variable or method).  The variable is given
1541  *                          explicitly by a firm entity.
1542  *    - symconst_ofs_ent    The symbolic constant represents the offset of an
1543  *                          entity in its owner type.
1544  *    - symconst_enum_const The symbolic constant is a enumeration constant of
1545  *                          an enumeration type.
1546  *
1547  *    Inputs to the node:
1548  *      No inputs except the block it belongs to.
1549  *    Outputs of the node.
1550  *      An unsigned integer (I_u) or a pointer (P).
1551  *
1552  *    Mention union in declaration so that the firmjni generator recognizes that
1553  *    it can not cast the argument to an int.
1554  *
1555  * @param mode    The mode for the SymConst.
1556  * @param value   A type, ident, entity or enum constant depending on the
1557  *                SymConst kind.
1558  * @param kind    The kind of the symbolic constant, see the list above
1559  */
1560 FIRM_API ir_node *new_SymConst(ir_mode *mode, union symconst_symbol value,
1561                                symconst_kind kind);
1562
1563 /** Constructor for a simpelSel node.
1564  *
1565  *  This is a shortcut for the new_Sel() constructor.  To be used for
1566  *  Sel nodes that do not select from an array, i.e., have no index
1567  *  inputs.  It adds the two parameters 0, NULL.
1568  *
1569  * @param   *store     The memory in which the object the entity should be selected from is allocated.
1570  * @param   *objptr    The object from that the Sel operation selects a single attribute out.
1571  * @param   *ent       The entity to select.
1572  */
1573 FIRM_API ir_node *new_simpleSel(ir_node *store, ir_node *objptr,
1574                                 ir_entity *ent);
1575
1576 /** Constructor for a remainderless Div node.
1577  *
1578  * Adds the node to the block in current_ir_block.
1579  *
1580  * @param   *memop The store needed to model exceptions
1581  * @param   *op1   The first operand.
1582  * @param   *op2   The second operand.
1583  * @param   *mode  The mode of the result.
1584  * @param   state  The pinned state.
1585  */
1586 FIRM_API ir_node *new_DivRL(ir_node *memop, ir_node *op1, ir_node *op2,
1587                             ir_mode *mode, op_pin_state state);
1588
1589 /** Constructor for a strict Conv node.
1590  *
1591  * Adds the node to the block in current_ir_block.
1592  *
1593  * @param   *op          The operand.
1594  * @param   *mode        The mode of this the operand muss be converted.
1595  */
1596 FIRM_API ir_node *new_strictConv(ir_node *op, ir_mode *mode);
1597
1598 /** Constructor for a defaultProj node.
1599  *
1600  * Represents the default control flow of a Switch-Cond node.
1601  * Adds the node to the block in current_ir_block.
1602  *
1603  * @param arg       A node producing a tuple.
1604  * @param max_proj  The end  position of the value in the tuple.
1605  */
1606 FIRM_API ir_node *new_defaultProj(ir_node *arg, long max_proj);
1607
1608 /** Constructor for an ASM pseudo node.
1609  *
1610  * @param arity       The number of data inputs to the node.
1611  * @param *in         The array of length arity of data inputs.
1612  * @param *inputs     The array of length arity of input constraints.
1613  * @param n_outs      The number of data outputs to the node.
1614  * @param *outputs    The array of length n_outs of output constraints.
1615  * @param n_clobber   The number of clobbered registers.
1616  * @param *clobber    The array of length n_clobber of clobbered registers.
1617  * @param *asm_text   The assembler text.
1618  */
1619 FIRM_API ir_node *new_ASM(int arity, ir_node *in[], ir_asm_constraint *inputs,
1620                           int n_outs, ir_asm_constraint *outputs,
1621                           int n_clobber, ident *clobber[], ident *asm_text);
1622
1623 /*---------------------------------------------------------------------*/
1624 /* The comfortable interface.                                          */
1625 /* Supports automatic Phi node construction.                           */
1626 /* All routines of the block oriented interface except new_Block are   */
1627 /* needed also.                                                        */
1628 /*---------------------------------------------------------------------*/
1629
1630 /** Create an immature Block.
1631  *
1632  * An immature Block has an unknown number of predecessors.  Predecessors
1633  * can be added with add_immBlock_pred().  Once all predecessors are
1634  * added the block must be matured.
1635  *
1636  * Adds the block to the graph in current_ir_graph. Can be used with automatic
1637  * Phi node construction.
1638  * This constructor can only be used if the graph is in state_building.
1639  */
1640 FIRM_API ir_node *new_d_immBlock(dbg_info *db);
1641 FIRM_API ir_node *new_immBlock(void);
1642 FIRM_API ir_node *new_r_immBlock(ir_graph *irg);
1643 FIRM_API ir_node *new_rd_immBlock(dbg_info *db, ir_graph *irg);
1644
1645 /** Add a control flow edge to an immature block. */
1646 FIRM_API void add_immBlock_pred(ir_node *immblock, ir_node *jmp);
1647
1648 /** Finalize a Block node, when all control flows are known. */
1649 FIRM_API void mature_immBlock(ir_node *block);
1650
1651 /** Get the current value of a local variable.
1652  *
1653  * Use this function to obtain the last definition of the local variable
1654  * associated with pos.  Pos may not exceed the value passed as n_loc
1655  * to new_ir_graph.  This call automatically inserts Phi nodes.
1656  *
1657  * @param  pos   The position/id of the local variable.
1658  * @param *mode  The mode of the value to get.
1659  */
1660 FIRM_API ir_node *get_value(int pos, ir_mode *mode);
1661 FIRM_API ir_node *get_r_value(ir_graph *irg, int pos, ir_mode *mode);
1662
1663 /**
1664  * Try to guess the mode of a local variable.
1665  * This is done by recursively going up the control flow graph until
1666  * we find a definition for the variable. The mode of the first found
1667  * definition is returned. NULL in case no definition is found.
1668  *
1669  * @param  pos   The position/id of the local variable.
1670  */
1671 FIRM_API ir_mode *ir_guess_mode(int pos);
1672 FIRM_API ir_mode *ir_r_guess_mode(ir_graph *irg, int pos);
1673
1674 /** Remark a new definition of a variable.
1675  *
1676  * Use this function to remember a new definition of the value
1677  * associated with pos. Pos may not exceed the value passed as n_loc
1678  * to new_ir_graph.  This call is needed to automatically inserts Phi
1679  * nodes.
1680  *
1681  * @param  pos   The position/id of the local variable.
1682  * @param *value The new value written to the local variable.
1683  */
1684 FIRM_API void set_value(int pos, ir_node *value);
1685 FIRM_API void set_r_value(ir_graph *irg, int pos, ir_node *value);
1686
1687 /**
1688  * Find the value number for a node in the current block.
1689  *
1690  * @param value  the searched value
1691  *
1692  * @return the value number of the value or -1 if this value has
1693  * no value number in the current block.
1694  */
1695 FIRM_API int find_value(ir_node *value);
1696 FIRM_API int r_find_value(ir_graph *irg, ir_node *value);
1697
1698 /** Get the current memory state.
1699  *
1700  * Use this function to obtain the last definition of the memory
1701  * state.  This call automatically inserts Phi nodes for the memory
1702  * state value.
1703  */
1704 FIRM_API ir_node *get_store(void);
1705 FIRM_API ir_node *get_r_store(ir_graph *irg);
1706
1707 /** Remark a new definition of the memory state.
1708  *
1709  * Use this function to remember a new definition of the memory state.
1710  * This call is needed to automatically inserts Phi nodes.
1711  *
1712  * @param *store The new memory state.
1713  */
1714 FIRM_API void set_store(ir_node *store);
1715 FIRM_API void set_r_store(ir_graph *irg, ir_node *store);
1716
1717 /** keep this node alive even if End is not control-reachable from it
1718  *
1719  * @param ka The node to keep alive.
1720  */
1721 FIRM_API void keep_alive(ir_node *ka);
1722
1723 /* --- initialize and finalize IR construction --- */
1724
1725 /** Puts the graph into state "phase_high" */
1726 FIRM_API void irg_finalize_cons(ir_graph *irg);
1727
1728 /** Puts the program and all graphs into state phase_high.
1729  *
1730  * This also remarks, the construction of types is finished,
1731  * e.g., that no more subtypes will be added.  */
1732 FIRM_API void irp_finalize_cons(void);
1733
1734 FIRM_API void ir_set_uninitialized_local_variable_func(
1735                 uninitialized_local_variable_func_t *func);
1736
1737 #include "end.h"
1738
1739 #endif