added Cast node.
[libfirm] / ir / ir / ircons.h
1 /* Copyright (C) 1998 - 2000 by Universitaet Karlsruhe
2 * All rights reserved.
3 */
4
5 /* $Id$ */
6
7 /**
8  @todo
9  Ideas for imrovement:
10  -# Handle construction of exceptions more comfortable:
11     Add new constructors that pass the exception region (or better the
12     Phi for the memories, the ex. region can be found from there) as parameter,
13     constructor then adds all Proj nodes and returns the pointer
14     to the Proj node that selects the result of the arithmetic operation.
15  -# Maybe hide the exception region in a global variable, especially if
16     it is always unambiguous.
17 */
18
19 /**
20  *  @file ircons.h
21  *
22  *  ir node construction.
23  *
24  *  @author Martin Trapp, Christian Schaefer, Goetz Lindenmaier
25  *
26  *    This file documents all datatypes and constructors needed to
27  *    build a FIRM representation of a pocedure.  The constructors are
28  *    also implemented in this file.
29  *
30  *    The documentation also gives a short manual how to use the library.
31  *
32  *    For extensive documentation of FIRM see UKA Techreport 1999-14.
33  *
34  *    =========
35  *
36  *    The struct ir_graph
37  *    -------------------
38  *
39  *      This struct contains all information about a procedure.
40  *      It's allocated directly to memory.
41  *
42  *      The fields of ir_graph:
43  *
44  *      *ent             The entity describing this procedure.
45  *
46  *      The beginning and end of a graph:
47  *
48  *      *start_block     This ir_node is the block that contains the unique
49  *                       start node of the procedure.  With it it contains
50  *                       the Proj's on starts results.
51  *                       Further all Const nodes are placed in the start block.
52  *      *start           This ir_node is the unique start node of the procedure.
53  *
54  *      *end_block       This ir_node is the block that contains the unique
55  *                       end node of the procedure.  This block contains no
56  *                       further nodes.
57  *      *end             This ir_node is the unique end node of the procedure.
58  *
59  *      The following nodes are Projs from the start node, held in ir_graph for
60  *      simple access:
61  *
62  *      *frame           The ir_node producing the pointer to the stack frame of
63  *                       the procedure as output.  This is the Proj node on the
64  *                       third output of the start node.  This output of the start
65  *                       node is tagged as pns_frame_base.  In FIRM most lokal
66  *                       variables are modeled as data flow edges.  Static
67  *                       allocated arrays can not be represented as dataflow
68  *                       edges. Therefore FIRM has to represent them in the stack
69  *                       frame.
70  *
71  *      *globals             This models a pointer to a space in the memory where
72  *                   _all_ global things are held.  Select from this pointer
73  *                   with a Sel node the pointer to a global variable /
74  *                   procedure / compiler known function... .
75  *
76  *      *args        The ir_node that produces the arguments of the method as
77  *                   it's result.  This is a Proj node on the fourth output of
78  *                   the start node.  This output is tagged as pns_args.
79  *
80  *      *bad             The bad node is an auxiliary node. It is needed only once,
81  *                       so there is this globally reachable node.
82  *
83  *      Datastructures that are private to a graph:
84  *
85  *      *obst            An obstack that contains all nodes.
86  *
87  *      *current_block   A pointer to the current block.  Any node created with
88  *                       one of the node constructors (new_<opcode>) are assigned
89  *                       to this block.  It can be set with switch_block(block).
90  *                       Only needed for ir construction.
91  *
92  *      params/n_loc     An int giving the number of local variables in this
93  *                   procedure.  This is neede for ir construction. Name will
94  *                   be changed.
95  *
96  *      *value_table     This hash table (pset) is used for global value numbering
97  *                   for optimizing use in iropt.c.
98  *
99  *      *Phi_in_stack;   a stack needed for automatic Phi construction, needed only
100  *                   during ir construction.
101  *
102  *      visited          A int used as flag to traverse the ir_graph.
103  *
104  *      block_visited    A int used as a flag to traverse block nodes in the graph.
105  *
106  *    Three kinds of nodes
107  *    --------------------
108  *
109  *      There are three kinds of nodes known to the ir:  entities,
110  *      types, and ir_nodes
111  *
112  *      + ir_nodes are the actual nodes of the FIRM intermediate representation.
113  *        They represent operations on the data of the program and control flow
114  *        operations.
115  *
116  *      + entity ==> implemented in entity.h
117  *        Refers to a single entity of the compiled program, e.g. a field of a
118  *        class or a method.  If a method or variable can not be assigned to
119  *        a method or class or the like, it is a global object.
120  *
121  *      + types ==> implemented in type.h
122  *        With types type information is represented.  There are several type
123  *        nodes.
124  *
125  *    Implementation of the FIRM operations: ir_node
126  *    ----------------------------------------------
127  *
128  *      Ir_nodes represent operations on the data of the program and control flow
129  *      operations.  Examples of ir_nodes:  Add, Jmp, Cmp
130  *
131  *      FIRM is a dataflow graph.  A dataflow graph is a directed graph,
132  *      so that every node has incoming and outgoing edges.  A node is
133  *      executable if every input at it's incoming edges is available.
134  *      Execution of the dataflow graph is started at the Start node which
135  *      has no incoming edges and ends when the End node executes, even if
136  *      there are still executable or not executed nodes.  (Is this true,
137  *      or must all executable nodes be executed?)  (There are exceptions
138  *      to the dataflow paradigma that all inputs have to be available
139  *      before a node can execute: Phi, Block.  See UKA Techreport
140  *      1999-14.)
141  *
142  *      The implementation of FIRM differs from the view as a dataflow
143  *      graph.  To allow fast traversion of the graph edges are
144  *      implemented as C-pointers.  Inputs to nodes are not ambiguous, the
145  *      results can be used by several other nodes.  Each input can be
146  *      implemented as a single pointer to a predecessor node, outputs
147  *      need to be lists of pointers to successors.  Therefore a node
148  *      contains pointers to it's predecessor so that the implementation is a
149  *      dataflow graph with reversed edges.  It has to be traversed bottom
150  *      up.
151  *
152  *      All nodes of the ir have the same basic structure.  They are
153  *      distinguished by a field containing the opcode.
154  *
155  *      The fields of an ir_node:
156  *
157  *      kind             A firm_kind tag containing k_ir_node.  This is useful for
158  *                       dynamically checking the type of a node.
159  *
160  *      *op              This ir_op gives the opcode as a tag and a string
161  *                       and the number of attributes of an ir_node.  There is
162  *                       one statically allocated struct ir_op for each opcode.
163  *
164  *      *mode            The ir_mode of the operation represented by this firm
165  *                       node.  The mode of the operation is the mode of it's
166  *                       result.  A Firm mode is a datatype as known to the target,
167  *                   not a type of the source language.
168  *
169  *      visit            A flag for traversing the ir.
170  *
171  *      **in             An array with pointers to the node's predecessors.
172  *
173  *      *link            A pointer to an ir_node.  With this pointer all Phi nodes
174  *                       are attached to a Block, i.e., a Block points to it's
175  *                       first Phi node, this node points to the second Phi node
176  *                       in the Block and so fourth.  Used in mature_block
177  *                       to find all Phi nodes to be matured.  It's also used to
178  *                   annotate a node with a better, optimized version of it.
179  *
180  *      attr             An attr struct containing the attributes of the nodes. The
181  *                       attributes depend on the opcode of the node.  The number
182  *                   of these attributes is given in op.
183  *
184  *    The struct ir_op
185  *    ----------------
186  *                       Not yet documented. See irop.h.
187  *
188  *    The struct ir_mode
189  *    ------------------
190  *                       Not yet documented. See irmode.h.
191  *
192  *    GLOBAL VARIABLES -- now also fields of ir_graph.
193  *    ================
194  *
195  *    current_ir_graph   Points to the current ir_graph.  All constructors for
196  *                       nodes add nodes to this graph.
197  *
198  *    ir_visited         An int used as flag to traverse the ir_graph.
199  *
200  *    block_visited      An int used as a flag to traverse block nodes in the
201  *                       graph.
202  *
203  *                       Others not yet documented.
204  *
205  *
206  *
207  *    CONSTRUCTOR FOR IR_GRAPH --> see irgraph.h
208  *    ========================
209  *
210  *
211  *    PROCEDURE TO CONSTRUCT AN IR GRAPH --> see also Firm tutorial
212  *    ==================================
213  *
214  *    This library supplies several interfaces to construct a FIRM graph for
215  *    a program:
216  *    * A "comfortable" interface generating SSA automatically.  Automatically
217  *      computed predecessors of nodes need not be specified in the constructors.
218  *      (new_<Node> constructurs and a set of additional routines.)
219  *    * A less comfortable interface where all predecessors except the block
220  *      an operation belongs to need to be specified.  SSA must be constructed
221  *      by hand.  (new_<Node> constructors and switch_block()).  This interface
222  *      is called "block oriented".  It automatically calles the local optimizations
223  *      for each new node.
224  *    * An even less comfortable interface where the block needs to be specified
225  *      explicitly.  This is called the "raw" interface. (new_r_<Node>
226  *      constructors).  These nodes are not optimized.
227  *
228  *    To use the functionality of the comfortable interface correctly the Front
229  *    End needs to follow certain protocols.  This is explained in the following.
230  *    To build a correct IR with the other interfaces study the semantics of
231  *    the firm node (See tech-reprot UKA 1999-14).  For the construction of
232  *    types and entities see the documentation in those modules.
233  *
234  *    First the Frontend needs to decide which variables and values used in
235  *    a procedure can be represented by dataflow edges.  These are variables
236  *    that need not be saved to memory as they cause no side effects visible
237  *    out of the procedure.  Often these are all compiler generated
238  *    variables and simple local variables of the procedure as integers,
239  *    reals and pointers.  The frontend has to count and number these variables.
240  *
241  *    First an ir_graph needs to be constructed with new_ir_graph.  The
242  *    constructor gets the number of local variables.  The graph is hold in the
243  *    global variable irg.
244  *
245  *    Now the construction of the procedure can start.  Several basic blocks can
246  *    be constructed in parallel, but the code within each block needs to
247  *    be constructed (almost) in program order.
248  *
249  *    A global variable holds the current basic block.  All (non block) nodes
250  *    generated are added to this block.  The current block can be set with
251  *    switch_block(block).  If several blocks are constructed in parallel block
252  *    switches need to be performed constantly.
253  *
254  *    To generate a Block node (with the comfortable interface) it's predecessor
255  *    control flow nodes need not be known.  In case of cyclic control flow these
256  *    can not be known when the block is constructed.  With add_in_edge(block,
257  *    cfnode) predecessors can be added to the block.  If all predecessors are
258  *    added to the block mature_block(b) needs to be called.  Calling mature_block
259  *    early improves the efficiency of the Phi node construction algorithm.
260  *    But if several  blocks are constructed at once, mature_block must only
261  *    be called after performing all set_values and set_stores in the block!
262  *    (See documentation of new_immBlock constructor.)
263  *
264  *    The constructors of arithmetic nodes require that their predecessors
265  *    are mentioned.  Sometimes these are available in the Frontend as the
266  *    predecessors have just been generated by the frontend.  If they are local
267  *    values the predecessors can be obtained from the library with a call to
268  *    get_value(local_val_nr).  (local_val_nr needs to be administered by
269  *    the Frontend.)  A call to get_value triggers the generation of Phi nodes.
270  *    If an arithmetic operation produces a local value this value needs to be
271  *    passed to the library by set_value(node, local_val_nr).
272  *    In straight line code these two operations just remember and return the
273  *    pointer to nodes producing the value.  If the value passes block boundaries
274  *    Phi nodes can be inserted.
275  *    Similar routines exist to manage the Memory operands: set_store and
276  *    get_store.
277  *
278  *    Several nodes produce more than one result.  An example is the Div node.
279  *    Such nodes return tuples of values.  From these individual values can be
280  *    extracted by proj nodes.
281  *
282  *    The following example illustrates the construction of a simple basic block
283  *    with two predecessors stored in variables cf_pred1 and cf_pred2, containing
284  *    the code
285  *      a = a div a;
286  *    and finally jumping to an other block.  The variable a got the local_val_nr
287  *    42 by the frontend.
288  *
289  *    ir_node *this_block, *cf_pred1, *cf_pred2, *a_val, *mem, *div, *res, *cf_op;
290  *
291  *    this_block = new_immBlock();
292  *    add_in_edge(this_block, cf_pred1);
293  *    add_in_edge(this_block, cf_pred2);
294  *    mature_block(this_block);
295  *    a_val = get_value(42, mode_Iu);
296  *    mem = get_store();
297  *    div = new_Div(mem, a_val, a_val);
298  *    mem = new_Proj(div, mode_M, 0);   * for the numbers for Proj see docu *
299  *    res = new_Proj(div, mode_Iu, 2);
300  *    set_store(mem);
301  *    set_value(res, 42);
302  *    cf_op = new_Jmp();
303  *
304  *    For further information look at the documentation of the nodes and
305  *    constructors and at the paragraph COPING WITH DATA OBJECTS at the
306  *    end of this documentation.
307  *
308  *    The comfortable interface contains the following routines further explained
309  *    below:
310  *
311  *    ir_node *new_immBlock  (void);
312  *    ir_node *new_Start  (void);
313  *    ir_node *new_End    (void);
314  *    ir_node *new_Jmp    (void);
315  *    ir_node *new_Cond   (ir_node *c);
316  *    ir_node *new_Return (ir_node *store, int arity, ir_node **in);
317  *    ir_node *new_Raise  (ir_node *store, ir_node *obj);
318  *    ir_node *new_Const  (ir_mode *mode, tarval *con);
319  *    ir_node *new_SymConst (type_or_id *value, symconst_kind kind);
320  *    ir_node *new_simpleSel (ir_node *store, ir_node *objptr, entity *ent);
321  *    ir_node *new_Sel    (ir_node *store, ir_node *objptr, int arity,
322  *                         ir_node **in, entity *ent);
323  *    ir_node *new_InstOf (ir_node *store, ir_node *objptr, type *ent);
324  *    ir_node *new_Call   (ir_node *store, ir_node *callee, int arity,
325  *                     ir_node **in, type_method *type);
326  *    ir_node *new_Add    (ir_node *op1, ir_node *op2, ir_mode *mode);
327  *    ir_node *new_Sub    (ir_node *op1, ir_node *op2, ir_mode *mode);
328  *    ir_node *new_Minus  (ir_node *op,  ir_mode *mode);
329  *    ir_node *new_Mul    (ir_node *op1, ir_node *op2, ir_mode *mode);
330  *    ir_node *new_Quot   (ir_node *memop, ir_node *op1, ir_node *op2);
331  *    ir_node *new_DivMod (ir_node *memop, ir_node *op1, ir_node *op2);
332  *    ir_node *new_Div    (ir_node *memop, ir_node *op1, ir_node *op2);
333  *    ir_node *new_Mod    (ir_node *memop, ir_node *op1, ir_node *op2);
334  *    ir_node *new_Abs    (ir_node *op,                ir_mode *mode);
335  *    ir_node *new_And    (ir_node *op1, ir_node *op2, ir_mode *mode);
336  *    ir_node *new_Or     (ir_node *op1, ir_node *op2, ir_mode *mode);
337  *    ir_node *new_Eor    (ir_node *op1, ir_node *op2, ir_mode *mode);
338  *    ir_node *new_Not    (ir_node *op,                ir_mode *mode);
339  *    ir_node *new_Shl    (ir_node *op,  ir_node *k,   ir_mode *mode);
340  *    ir_node *new_Shr    (ir_node *op,  ir_node *k,   ir_mode *mode);
341  *    ir_node *new_Shrs   (ir_node *op,  ir_node *k,   ir_mode *mode);
342  *    ir_node *new_Rot    (ir_node *op,  ir_node *k,   ir_mode *mode);
343  *    ir_node *new_Cmp    (ir_node *op1, ir_node *op2);
344  *    ir_node *new_Conv   (ir_node *op, ir_mode *mode);
345  *    ir_node *new_Cast   (ir_node *op, type *to_tp);
346  *    ir_node *new_Load   (ir_node *store, ir_node *addr);
347  *    ir_node *new_Store  (ir_node *store, ir_node *addr, ir_node *val);
348  *    ir_node *new_Alloc  (ir_node *store, ir_node *size, type *alloc_type,
349  *                         where_alloc where);
350  *    ir_node *new_Free   (ir_node *store, ir_node *ptr, ir_node *size,
351  *                   type *free_type);
352  *    ir_node *new_Proj   (ir_node *arg, ir_mode *mode, long proj);
353  *
354  *    void add_in_edge (ir_node *block, ir_node *jmp);
355  *    void     mature_block (ir_node *block);
356  *    void switch_block (ir_node *target);
357  *    ir_node *get_value (int pos, ir_mode *mode);
358  *    void set_value (int pos, ir_node *value);
359  *    ir_node *get_store (void);
360  *    void set_store (ir_node *store);
361  *    keep_alive (ir_node ka)
362  *
363  *    IR_NODES AND CONSTRUCTORS FOR IR_NODES
364  *    =======================================
365  *
366  *    All ir_nodes are defined by a common data structure.  They are distinguished
367  *    by their opcode and differ in the number of their attributes.
368  *
369  *    The constructor for the block node sets current_block to itself.
370  *    Const nodes are always added to the start block.
371  *    All other constructors add the created node to the current_block.
372  *    swich_block(block) allows to set the current block to block.
373  *
374  *    Watch for my inconsistent use of input and predecessor (dataflow view)
375  *    and `the node points to' (implementation view).
376  *
377  *    The following description of the nodes lists four properties them if these
378  *    are of interest:
379  *     - the parameters to the constructor
380  *     - the inputs of the Firm node
381  *     - the outputs of the Firm node
382  *     - attributes to the node
383  *
384  *    ------------
385  *
386  *    ir_node *new_immBlock (void)
387  *    ----------------------------
388  *
389  *    Creates a new block.  Sets current_block to itself.  When a new block is
390  *    created it cannot be known how many predecessors this block will have in the
391  *    control flow graph. Therefore the list of inputs can not be fixed at
392  *    creation.  Predecessors can be added with add_in_edge (block, control flow
393  *    operation).  With every added predecessor the number of inputs to Phi nodes
394  *    also changes.
395  *
396  *    The block can be completed by mature_block(block) if all predecessors are
397  *    known.  If several blocks are built at once, mature_block can only be called
398  *    after set_value has been called for all values that are life at the end
399  *    of the block.  This is necessary so that Phi nodes created by mature_block
400  *    get the right predecessors in case of cyclic dependencies.  If all set_values
401  *    of this block are called after maturing it and before calling get_value
402  *    in some block that is control flow dependent on this block, the construction
403  *    is correct.
404  *
405  *    Example for faulty ir construction:  (draw the graph on a paper and you'll
406  *                                          get it ;-)
407  *
408  *      block_before_loop = new_block();
409  *      set_value(x);
410  *      mature_block(block_before_loop);
411  *      before2header = new_Jmp;
412  *
413  *      loop_header = new_block ();
414  *      header2body - new_Jmp();
415  *
416  *      loop_body = new_block ();
417  *      body2header = new_Jmp();
418  *
419  *      add_in_edge(loop_header, before2header);
420  *      add_in_edge(loop_header, body2header);
421  *      add_in_edge(loop_body, header2body);
422  *
423  *      mature_block(loop_header);
424  *      mature_block(loop_body);
425  *
426  *      get_value(loop_body, x);   // gets the Phi in loop_header
427  *      set_value(loop_header, x); // sets the value the above get_value should
428  *                                 // have returned!!!
429  *
430  *    Mature_block also fixes the number of inputs to the Phi nodes.  Mature_block
431  *    should be called as early as possible, as afterwards the generation of Phi
432  *    nodes is more efficient.
433  *
434  *    Inputs:
435  *      There is an input for each control flow predecessor of the block.
436  *      The input points to an instruction producing an output of type X.
437  *      Possible predecessors:  Start, Jmp, Cond, Raise or Return or any node
438  *      possibly causing an exception.  (Often the real predecessors are Projs.)
439  *    Output:
440  *      Mode BB (R), all nodes belonging to this block should consume this output.
441  *      As they are strict (except Block and Phi node) it is a necessary condition
442  *      that the block node executed before any other node in this block executes.
443  *    Attributes:
444  *      block.matured  Indicates whether the block is mature.
445  *      block.**graph_arr
446  *                      This attribute contains all local values valid in this
447  *                      block. This is needed to build the Phi nodes and removed
448  *                      if the graph is complete.  This field is used by the
449  *                  internal construction algorithm and should not be accessed
450  *                  from outside.
451  *
452  *
453  *    ir_node *new_Block (int arity, ir_node **in)
454  *    --------------------------------------------
455  *
456  *    Creates a new Block with the given list of predecessors.  This block
457  *    is mature.  As other constructors calls optimization and vrfy for the
458  *    block.  If one of the predecessors is Unknown (as it has to be filled in
459  *    later) optimizations are skipped.  This is necessary to
460  *    construct Blocks in loops.  Leaving Unknown in the Block after finishing
461  *    the construction may have strange effects, especially for interprocedural
462  *    representation and analyses.
463  *
464  *
465  *    CONTROL FLOW OPERATIONS
466  *    -----------------------
467  *
468  *    In each block there must be exactly one of the control flow
469  *    operations Start, End, Jmp, Cond, Return or Raise.  The output of a
470  *    control flow operation points to the block to be executed next.
471  *
472  *    ir_node *new_Start (void)
473  *    -------------------------
474  *
475  *    Creates a start node.  Not actually needed public.  There is only one such
476  *    node in each procedure which is automatically created by new_ir_graph.
477  *
478  *    Inputs:
479  *      No inputs except the block it belogns to.
480  *    Output:
481  *      A tuple of 4 (5, 6) distinct values. These are labeled by the following
482  *      projection numbers (pns_number):
483  *      * pns_initial_exec
484  *                       mode X, points to the first block to be executed.
485  *      * pns_global_store
486  *                       mode M, the global store
487  *      * pns_frame_base mode P, a pointer to the base of the procedures
488  *                           stack frame.
489  *      * pns_globals    mode P, a pointer to the part of the memory containing
490  *                               _all_ global things.
491  *      * pns_args       mode T, a tuple containing all arguments of the procedure.
492  *
493  *
494  *    ir_node *new_End (void)
495  *    -----------------------
496  *
497  *    Creates an end node.  Not actually needed public.  There is only one such
498  *    node in each procedure which is automatically created by new_ir_graph.
499  *
500  *    Inputs:
501  *      No inputs except the block it belongs to.
502  *    Output:
503  *      No output.
504  *
505  *    ir_node *new_Jmp (void)
506  *    -----------------------
507  *
508  *    Creates a Jmp node.
509  *
510  *    Inputs:
511  *      The block the node belongs to
512  *    Output:
513  *      Control flow to the next block.
514  *
515  *    ir_node *new_Cond (ir_node *c)
516  *    ------------------------------
517  *
518  *    Creates a Cond node.  There are two versions of this node.
519  *
520  *    The Boolean Cond:
521  *    Input:
522  *      A value of mode b.
523  *    Output:
524  *      A tuple of two control flows.  The first is taken if the input is
525  *      false, the second if it is true.
526  *
527  *    The Switch Cond:
528  *    Input:
529  *      A value of mode I_u. (i)
530  *    Output:
531  *      A tuple of n control flows.  If the Cond's input is i, control
532  *      flow will procede along output i. If the input is >= n control
533  *      flow proceeds along output n.
534  *
535  *    ir_node *new_Return (in_node *store, int arity, ir_node **in)
536  *    -------------------------------------------------------------
537  *
538  *    The return node has as inputs the results of the procedure.  It
539  *    passes the control flow to the end_block.
540  *
541  *    Inputs:
542  *      The memory state.
543  *      All results.
544  *    Output
545  *      Control flow to the end block.
546  *
547  *    ir_node *new_Raise (ir_node *store, ir_node *obj)
548  *    -------------------------------------------------
549  *
550  *    Raises an exception.  Unconditional change of control flow.  Writes
551  *    an explicit Except variable to memory to pass it to the exception
552  *    handler.  See TechReport 1999-14, chapter Exceptions.
553  *
554  *    Inputs:
555  *      The memory state.
556  *      A pointer to the Except variable.
557  *    Output:
558  *      A tuple of control flow and the changed memory state.  The control flow
559  *      points to the exception handler if it is definied in this procedure,
560  *      else it points to the end_block.
561  *
562  *
563  *    ---------
564  *
565  *    ir_node *new_Const (ir_mode *mode, tarval *con)
566  *    -----------------------------------------------
567  *
568  *    Creates a constant in the constant table and adds a Const node
569  *    returning this value to the start block.
570  *
571  *    Parameters:
572  *      *mode            The mode of the constant.
573  *      *con             Points to an entry in the constant table.
574  *                       This pointer is added to the attributes of
575  *                       the node (self->attr.con)
576  *    Inputs:
577  *      No inputs except the block it belogns to.
578  *    Output:
579  *      The constant value.
580  *    Attribute:
581  *      attr.con   A tarval* pointer to the proper entry in the constant
582  *                 table.
583  *
584  *    ir_node *new_SymConst (type *tp, symconst_kind kind)
585  *    ------------------------------------------------------------
586  *
587  *    There are three kinds of symbolic constants:
588  *      type_tag  The symbolic constant represents a type tag.
589  *      size      The symbolic constant represents the size of a class.
590  *      link_info Information for the linker, e.g. the name of a global
591  *                variable.
592  *    To represent a pointer to an entity that is represented by an entity
593  *    datastructure don't use
594  *      new_SymConst((type_or_id*)get_entity_ld_ident(ent), linkage_ptr_info);.
595  *    Use a real const instead:
596  *      new_Const(mode_P_mach, tarval_p_from_entity(ent));
597  *    This makes the Constant independent of name changes of the entity due to
598  *    mangling.
599  *
600  *    Parameters
601  *      kind        The kind of the symbolic constant: type_tag, size or link_info.
602  *      *type_or_id Points to the type the tag stands for or to the type
603  *                  whose size is represented by the constant or to an ident
604  *                  representing the linkage info.
605  *
606  *    Inputs:
607  *      No inputs except the block it belogns to.
608  *    Output:
609  *      An unsigned integer (I_u) or a pointer (P).
610  *
611  *    Attributes:
612  *      attr.i.num       The symconst_kind, i.e. one of
613  *                        - type_tag
614  *                        - size
615  *                    - linkage_ptr_info
616  *        If the attr.i.num is type_tag or size, the node contains an attribute
617  *      attr.i.*type,    a pointer to a type_class.  The mode of the node is mode_Is.
618  *        if it is linkage_ptr_info it contains
619  *      attr.i.*ptrinfo,  an ident holding information for the linker.  The mode
620  *        of the node is mode_P_mach.
621  *
622  *    ---------------
623  *
624  *    ir_node *new_simpleSel (ir_node *store, ir_node *frame, entity *sel)
625  *    --------------------------------------------------------------------
626  *
627  *
628  *    Selects an entity from a compound type. This entity can be a field or
629  *    a method.
630  *
631  *    Parameters:
632  *      *store     The memory in which the object the entity should be selected
633  *                 from is allocated.
634  *      *frame     The pointer to the object.
635  *      *sel       The entity to select.
636  *
637  *    Inputs:
638  *      The memory containing the object.
639  *      A pointer to the object.
640  *      An unsigned integer.
641  *    Output:
642  *      A pointer to the selected entity.
643  *    Attributes:
644  *      attr.sel   Pointer to the entity
645  *
646  *
647  *    ir_node *new_Sel (ir_node *store, ir_node *frame, int arity, ir_node **in,
648  *    --------------------------------------------------------------------------
649  *                      entity *sel)
650  *                      ------------
651  *
652  *    Selects a field from an array type.  The entity has as owner the array, as
653  *    type the arrays element type.  The indexes to access an array element are
654  *    given also.
655  *
656  *    Parameters:
657  *      *store     The memory in which the object the entity should be selected from
658  *                 is allocated.
659  *      *frame     The pointer to the object.
660  *      *arity     number of array indexes.
661  *      *in        array with index inputs to the node.
662  *      *sel       The entity to select.
663  *
664  *    Inputs:
665  *      The memory containing the object.
666  *      A pointer to the object.
667  *      As much unsigned integer as there are array expressions.
668  *    Output:
669  *      A pointer to the selected entity.
670  *    Attributes:
671  *      attr.sel   Pointer to the entity
672  *
673  *    The constructors new_Sel and new_simpleSel generate the same ir nodes.
674  *    simpleSel just sets the arity of the index inputs to zero.
675  *
676  *
677  *    ARITHMETIC OPERATIONS
678  *    ---------------------
679  *
680  *    ir_node *new_Call (ir_node *store, ir_node *callee, int arity, ir_node **in,
681  *    ----------------------------------------------------------------------------
682  *                       type_method *type)
683  *                       ------------------
684  *
685  *    Creates a procedure call.
686  *
687  *    Parameters
688  *      *store           The actual store.
689  *      *callee          A pointer to the called procedure.
690  *      arity            The number of procedure parameters.
691  *      **in             An array with the pointers to the parameters.
692  *                       The constructor copies this array.
693  *      *type            Type information of the procedure called.
694  *
695  *    Inputs:
696  *      The store, the callee and the parameters.
697  *    Output:
698  *      A tuple containing the eventually changed store and the procedure
699  *      results.
700  *    Attributes:
701  *      attr.call        Contains the type information for the procedure.
702  *
703  *    ir_node *new_Add (ir_node *op1, ir_node *op2, ir_mode *mode)
704  *    ------------------------------------------------------------
705  *
706  *    Trivial.
707  *
708  *    ir_node *new_Sub (ir_node *op1, ir_node *op2, ir_mode *mode)
709  *    ------------------------------------------------------------
710  *
711  *    Trivial.
712  *
713  *    ir_node *new_Minus (ir_node *op, ir_mode *mode)
714  *    -----------------------------------------------
715  *
716  *    Unary Minus operations on floating point values.
717  *
718  *    ir_node *new_Mul (ir_node *op1, ir_node *op2, ir_mode *mode)
719  *    ------------------------------------------------------------
720  *
721  *    Trivial.
722  *
723  *    ir_node *new_Quot (ir_node *memop, ir_node *op1, ir_node *op2)
724  *    --------------------------------------------------------------
725  *
726  *    Quot performs exact division of floating point numbers.  It's mode
727  *    is Tuple, the mode of the result must be annotated to the Proj
728  *    that extracts the result of the arithmetic operations.
729  *
730  *    Inputs:
731  *      The store needed to model exceptions and the two operands.
732  *    Output:
733  *      A tuple contaning a memory and a execution for modeling exceptions
734  *      and the result of the arithmetic operation.
735  *
736  *    ir_node *new_DivMod (ir_node *memop, ir_node *op1, ir_node *op2)
737  *    ----------------------------------------------------------------
738  *
739  *    Performs Div and Mod on interger values.
740  *
741  *    Output:
742  *      A tuple contaning a memory and a execution for modeling exceptions
743  *      and the two result of the arithmetic operations.
744  *
745  *    ir_node *new_Div (ir_node *memop, ir_node *op1, ir_node *op2)
746  *    -------------------------------------------------------------
747  *
748  *    Trivial.
749  *
750  *    ir_node *new_Mod (ir_node *memop, ir_node *op1, ir_node *op2)
751  *    -------------------------------------------------------------
752  *
753  *    Trivial.
754  *
755  *    ir_node *new_Abs (ir_node *op, ir_mode *mode)
756  *    ---------------------------------------------
757  *
758  *    Trivial.
759  *
760  *    ir_node *new_And (ir_node *op1, ir_node *op2, ir_mode *mode)
761  *    ------------------------------------------------------------
762  *
763  *    Trivial.
764  *
765  *    ir_node *new_Or (ir_node *op1, ir_node *op2, ir_mode *mode)
766  *    -----------------------------------------------------------
767  *
768  *    Trivial.
769  *
770  *    ir_node *new_Eor (ir_node *op1, ir_node *op2, ir_mode *mode)
771  *    ------------------------------------------------------------
772  *
773  *    Trivial.
774  *
775  *    ir_node *new_Not (ir_node *op, ir_mode *mode)
776  *    ---------------------------------------------
777  *
778  *    This node constructs a constant where all bits are set to one
779  *    and a Eor of this constant and the operator.  This simulates a
780  *    Not operation.
781  *
782  *    ir_node *new_Shl (ir_node *op, ir_node *k, ir_mode *mode)
783  *    ---------------------------------------------------------
784  *
785  *    Trivial.
786  *
787  *    ir_node *new_Shr (ir_node *op, ir_node *k, ir_mode *mode)
788  *    ---------------------------------------------------------
789  *
790  *    Logic shift right, i.e., zero extended.
791  *
792  *
793  *    ir_node *new_Shrs (ir_node *op, ir_node *k, ir_mode *mode)
794  *    ----------------------------------------------------------
795  *
796  *    Arithmetic shift right, i.e., sign extended.
797  *
798  *    ir_node *new_Rot (ir_node *op, ir_node *k, ir_mode *mode)
799  *    ---------------------------------------------------------
800  *
801  *    Rotates the operand to the (right??) by k bits.
802  *
803  *    ir_node *new_Conv (ir_node *op, ir_mode *mode)
804  *    ---------------------------------------------
805  *
806  *    Mode conversion.  For allowed conversions see UKA Tech Report
807  *    1999-14.
808  *
809  *    ir_node *new_Cmp (ir_node *op1, ir_node *op2)
810  *    ---------------------------------------------
811  *
812  *    Input:
813  *      The two values to be compared.
814  *    Output:
815  *      A 16-tuple containing the results of the 16 different comparisons.
816  *      The following is a list giving the comparisons and a projection
817  *      number (pnc_number) to use in Proj nodes to extract the proper result.
818  *        False     false
819  *        Eq        equal
820  *        Lt    less
821  *        Le    less or equal
822  *        Gt    greater
823  *        Ge    greater of equal
824  *        Lg    less or greater
825  *        Leg   less, equal or greater = ordered
826  *        Uo    unordered
827  *        Ue    unordered or equal
828  *        Ul    unordered or less
829  *        Ule   unordered, less or equal
830  *        Ug    unordered or greater
831  *        Uge   unordered, greater or equal
832  *        Ne    unordered, less or greater = not equal
833  *        True  true
834  *
835  *
836  *
837  *    ------------
838  *
839  *    In general, Phi nodes are automaitcally inserted.  In some cases, if
840  *    all predecessors of a block are known, an explicit Phi node constructor
841  *    is needed.  E.g., to construct a FIRM graph for a statement as
842  *      a = (b==c) ? 2 : 5;
843  *
844  *    ir_node *new_Phi (int arity, ir_node **in, ir_mode *mode)
845  *    ---------------------------------------------------------
846  *
847  *    Creates a Phi node. The in's order has to correspond to the order
848  *    of in's of current_block.  This is not checked by the library!
849  *    If one of the predecessors is Unknown (as it has to be filled in
850  *    later) optimizations are skipped.  This is necessary to
851  *    construct Phi nodes in loops.  Leaving Unknown in the Phi after finishing
852  *    the construction may have strange effects, especially for interprocedural
853  *    representation and analyses.
854  *
855  *    Parameter
856  *      arity            number of predecessors
857  *      **in             array with predecessors
858  *      *mode            The mode of it's inputs and output.
859  *    Inputs:
860  *      A Phi node has as many inputs as the block it belongs to.
861  *      Each input points to a definition of the same value on a
862  *      different path in the control flow.
863  *    Output
864  *      The definition valid in this block.
865  *
866  *
867  *    OPERATIONS TO MANAGE MEMORY EXPLICITLY
868  *    --------------------------------------
869  *
870  *    ir_node *new_Load (ir_node *store, ir_node *addr)
871  *    ----------------------------------------------------------------
872  *
873  *    The Load operation reads a value from memory.
874  *
875  *    Parameters:
876  *    *store        The current memory.
877  *    *addr         A pointer to the variable to be read in this memory.
878  *
879  *    Inputs:
880  *      The memory and a pointer to a variable in this memory.
881  *    Output:
882  *      A tuple of the memory, a control flow to be taken in case of
883  *      an exception and the loaded value.
884  *
885  *    ir_node *new_Store (ir_node *store, ir_node *addr, ir_node *val)
886  *    ----------------------------------------------------------------
887  *
888  *    The Store operation writes a value to a variable in memory.
889  *
890  *    Inputs:
891  *      The memory, a pointer to a variable in this memory and the value
892  *      to write to this variable.
893  *    Output:
894  *      A tuple of the changed memory and a control flow to be taken in
895  *      case of an exception.
896  *
897  *    ir_node *new_Alloc (ir_node *store, ir_node *size, type *alloc_type,
898  *    --------------------------------------------------------------------
899  *                        where_alloc where)
900  *                        ------------------
901  *
902  *    The Alloc node allocates a new variable.  It can be specified whether the
903  *    variable should be allocated to the stack or to the heap.
904  *
905  *    Parameters:
906  *      *store       The memory which shall contain the new variable.
907  *      **    *size        The number of bytes to allocate. Old. **
908  *      *size        We decided that the size easily can be derived from the type.
909  *                   This field is for allocating arrays, i.e., it gives the multiple
910  *               of the size of alloc_type to allocate memory for.
911  *      *alloc_type  The type of the allocated variable.
912  *      where        Where to allocate the variable, either heap_alloc or stack_alloc.
913  *
914  *    Inputs:
915  *      A memory and an unsigned integer.
916  *    Output:
917  *      A tuple of the changed memory, a control flow to be taken in
918  *      case of an exception and the pointer to the new variable.
919  *    Attributes:
920  *      a.where          Indicates where the variable is allocated.
921  *      a.*type          A pointer to the class the allocated data object
922  *                       belongs to.
923  *
924  *    ir_node *new_Free (ir_node *store, ir_node *ptr, type *free_type)
925  *    ------------------------------------------------------------------
926  *
927  *    The Free node frees memory of the given variable.
928  *
929  *    Parameters:
930  *      *store       The memory which shall contain the new variable.
931  *      *ptr         The pointer to the object to free.
932  *      *size        The number of objects of type free_type to free in a sequence.
933  *      *free_type   The type of the freed variable.
934  *
935  *    Inputs:
936  *      A memory, a pointer and an unsigned integer.
937  *    Output:
938  *      The changed memory.
939  *    Attributes:
940  *      f.*type          A pointer to the type information of the freed data object.
941  *
942  *    Not Implemented!
943  *
944  *    ir_node *new_Sync (int arity, ir_node **in)
945  *    -------------------------------------------
946  *
947  *    The Sync operation unifies several partial memory blocks.  These blocks
948  *    have to be pairwise disjunct or the values in common locations have to
949  *    be identical.  This operation allows to specify all operations that eventually
950  *    need several partial memory blocks as input with a single entrance by
951  *    unifying the memories with a preceding Sync operation.
952  *
953  *    Parameters
954  *      arity    The number of memories to syncronize.
955  *      **in     An array of pointers to nodes that produce an output of
956  *               type memory.
957  *    Inputs
958  *      Several memories.
959  *    Output
960  *      The unified memory.
961  *
962  *
963  *    SPECIAL OPERATIONS
964  *    ------------------
965  *
966  *    ir_node *new_Bad (void)
967  *    -----------------------
968  *
969  *    Returns the unique Bad node current_ir_graph->bad.
970  *    This node is used to express results of dead code elimination.
971  *
972  *    ir_node *new_Proj (ir_node *arg, ir_mode *mode, long proj)
973  *    ----------------------------------------------------------
974  *
975  *    Selects one entry of a tuple.  This is a hidden `fat edge'.
976  *
977  *    Parameters
978  *      *arg      A node producing a tuple.
979  *      *mode     The mode of the value to project.
980  *      proj      The position of the value in the tuple.
981  *    Input:
982  *      The tuple.
983  *    Output:
984  *      The value.
985  *
986  *    ir_node *new_Tuple (int arity, ir_node **in)
987  *    --------------------------------------------
988  *
989  *    Builds a Tuple from single values.  This is needed to implement
990  *    optimizations that remove a node that produced a tuple.  The node can be
991  *    replaced by the Tuple operation so that the following Proj nodes have not to
992  *    be changed.  (They are hard to find due to the implementation with pointers
993  *    in only one direction.)  The Tuple node is smaller than any other
994  *    node, so that a node can be changed into a Tuple by just changing it's
995  *    opcode and giving it a new in array.
996  *
997  *    Parameters
998  *      arity    The number of tuple elements.
999  *      **in     An array containing pointers to the nodes producing the
1000  *               tuple elements.
1001  *
1002  *    ir_node *new_Id (ir_node *val, ir_mode *mode)
1003  *    ---------------------------------------------
1004  *
1005  *    The single output of the Id operation is it's input.  Also needed
1006  *    for optimizations.
1007  *
1008  *
1009  *    COPING WITH DATA OBJECTS
1010  *    ========================
1011  *
1012  *    Two kinds of data objects have to be distinguished for generating
1013  *    FIRM.  First there are local variables other than arrays that are
1014  *    known to be alias free.  Second there are all other data objects.
1015  *    For the first a common SSA representation is built, the second
1016  *    are modeled by saving them to memory.  The memory is treated as
1017  *    a single local variable, the alias problem is hidden in the
1018  *    content of this variable.
1019  *
1020  *    All values known in a Block are listed in the block's attribute,
1021  *    block.**graph_arr which is used to automatically insert Phi nodes.
1022  *    The following two funcions can be used to add a newly computed value
1023  *    to the array, or to get the producer of a value, i.e., the current
1024  *    live value.
1025  *
1026  *    inline void set_value (int pos, ir_node *value)
1027  *    -----------------------------------------------
1028  *
1029  *    Has to be called for every assignment to a local variable.  It
1030  *    adds the value to the array of used values at position pos.  Pos
1031  *    has to be a unique identifier for an entry in the procedure's
1032  *    definition table.  It can be used to access the value again.
1033  *    Requires current_block to be set correctly.
1034  *
1035  *    ir_node *get_value (int pos, ir_mode *mode)
1036  *    -------------------------------------------
1037  *
1038  *    Returns the node defining the value referred to by pos. If the
1039  *    value is not defined in this block a Phi node is generated and
1040  *    all definitions reaching this Phi node are collected.  It can
1041  *    happen that the algorithm allocates an unnecessary Phi node,
1042  *    e.g. if there is only one definition of this value, but this
1043  *    definition reaches the currend block on several different
1044  *    paths.  This Phi node will be eliminated if optimizations are
1045  *    turned on right after it's creation.
1046  *    Requires current_block to be set correctly.
1047  *
1048  *    There are two special routines for the global store:
1049  *
1050  *    inline void set_store (ir_node *store)
1051  *    --------------------------------------
1052  *
1053  *    Adds the store to the array of known values at a reserved
1054  *    position.
1055  *    Requires current_block to be set correctly.
1056  *
1057  *    inline ir_node *get_store (void)
1058  *    --------------------------------
1059  *
1060  *    Returns the node defining the actual store.
1061  *    Requires current_block to be set correctly.
1062  *
1063  *
1064  *    inline void keep_alive (ir_node *ka)
1065  *    ------------------------------------
1066  *
1067  *    Keep this node alive because it is (might be) not in the control
1068  *    flow from Start to End.  Adds the node to the list in the end
1069  *    node.
1070  *
1071  */
1072
1073
1074 # ifndef _IRCONS_H_
1075 # define _IRCONS_H_
1076
1077 # include "firm_common.h"
1078 # include "irgraph.h"
1079 # include "irnode.h"
1080 # include "irmode.h"
1081 # include "entity.h"
1082 # include "tv.h"
1083 # include "type.h"
1084 # include "dbginfo.h"
1085
1086 /*-------------------------------------------------------------------------*/
1087 /* The raw interface                                                       */
1088 /*-------------------------------------------------------------------------*/
1089
1090 /* Constructs a Block with a fixed number of predecessors.
1091    Does not set current_block.  Can not be used with automatic
1092    Phi node construction. */
1093 ir_node *new_rd_Block  (dbg_info *db, ir_graph *irg,  int arity, ir_node *in[]);
1094 ir_node *new_rd_Start  (dbg_info *db, ir_graph *irg, ir_node *block);
1095 ir_node *new_rd_End    (dbg_info *db, ir_graph *irg, ir_node *block);
1096 ir_node *new_rd_Jmp    (dbg_info *db, ir_graph *irg, ir_node *block);
1097 ir_node *new_rd_Cond   (dbg_info *db, ir_graph *irg, ir_node *block, ir_node *c);
1098 ir_node *new_rd_Return (dbg_info *db, ir_graph *irg, ir_node *block,
1099                        ir_node *store, int arity, ir_node *in[]);
1100 ir_node *new_rd_Raise  (dbg_info *db, ir_graph *irg, ir_node *block,
1101                        ir_node *store, ir_node *obj);
1102 ir_node *new_rd_Const  (dbg_info *db, ir_graph *irg, ir_node *block,
1103                        ir_mode *mode, tarval *con);
1104 ir_node *new_rd_SymConst (dbg_info *db, ir_graph *irg, ir_node *block,
1105                        type_or_id_p value, symconst_kind symkind);
1106 ir_node *new_rd_Sel    (dbg_info *db, ir_graph *irg, ir_node *block, ir_node *store,
1107                        ir_node *objptr, int n_index, ir_node *index[],
1108                        entity *ent);
1109 ir_node *new_rd_Call   (dbg_info *db, ir_graph *irg, ir_node *block, ir_node *store,
1110                        ir_node *callee, int arity, ir_node *in[],
1111                        type *tp);
1112 ir_node *new_rd_Add    (dbg_info *db, ir_graph *irg, ir_node *block,
1113                        ir_node *op1, ir_node *op2, ir_mode *mode);
1114 ir_node *new_rd_Sub    (dbg_info *db, ir_graph *irg, ir_node *block,
1115                        ir_node *op1, ir_node *op2, ir_mode *mode);
1116 ir_node *new_rd_Minus  (dbg_info *db, ir_graph *irg, ir_node *block,
1117                        ir_node *op,  ir_mode *mode);
1118 ir_node *new_rd_Mul    (dbg_info *db, ir_graph *irg, ir_node *block,
1119                        ir_node *op1, ir_node *op2, ir_mode *mode);
1120 ir_node *new_rd_Quot   (dbg_info *db, ir_graph *irg, ir_node *block,
1121                        ir_node *memop, ir_node *op1, ir_node *op2);
1122 ir_node *new_rd_DivMod (dbg_info *db, ir_graph *irg, ir_node *block,
1123                        ir_node *memop, ir_node *op1, ir_node *op2);
1124 ir_node *new_rd_Div    (dbg_info *db, ir_graph *irg, ir_node *block,
1125                        ir_node *memop, ir_node *op1, ir_node *op2);
1126 ir_node *new_rd_Mod    (dbg_info *db, ir_graph *irg, ir_node *block,
1127                        ir_node *memop, ir_node *op1, ir_node *op2);
1128 ir_node *new_rd_Abs    (dbg_info *db, ir_graph *irg, ir_node *block,
1129                        ir_node *op, ir_mode *mode);
1130 ir_node *new_rd_And    (dbg_info *db, ir_graph *irg, ir_node *block,
1131                        ir_node *op1, ir_node *op2, ir_mode *mode);
1132 ir_node *new_rd_Or     (dbg_info *db, ir_graph *irg, ir_node *block,
1133                        ir_node *op1, ir_node *op2, ir_mode *mode);
1134 ir_node *new_rd_Eor    (dbg_info *db, ir_graph *irg, ir_node *block,
1135                        ir_node *op1, ir_node *op2, ir_mode *mode);
1136 ir_node *new_rd_Not    (dbg_info *db, ir_graph *irg, ir_node *block,
1137                        ir_node *op, ir_mode *mode);
1138 ir_node *new_rd_Cmp    (dbg_info *db, ir_graph *irg, ir_node *block,
1139                        ir_node *op1, ir_node *op2);
1140 ir_node *new_rd_Shl    (dbg_info *db, ir_graph *irg, ir_node *block,
1141                        ir_node *op, ir_node *k, ir_mode *mode);
1142 ir_node *new_rd_Shr    (dbg_info *db, ir_graph *irg, ir_node *block,
1143                        ir_node *op, ir_node *k, ir_mode *mode);
1144 ir_node *new_rd_Shrs   (dbg_info *db, ir_graph *irg, ir_node *block,
1145                        ir_node *op, ir_node *k, ir_mode *mode);
1146 ir_node *new_rd_Rot    (dbg_info *db, ir_graph *irg, ir_node *block,
1147                        ir_node *op, ir_node *k, ir_mode *mode);
1148 ir_node *new_rd_Conv   (dbg_info *db, ir_graph *irg, ir_node *block,
1149                        ir_node *op, ir_mode *mode);
1150 ir_node *new_rd_Cast   (dbg_info* db, ir_graph *irg, ir_node *block,
1151                        ir_node *op, type *to_tp);
1152 ir_node *new_rd_Phi    (dbg_info *db, ir_graph *irg, ir_node *block, int arity,
1153                        ir_node *in[], ir_mode *mode);
1154 ir_node *new_rd_Load   (dbg_info *db, ir_graph *irg, ir_node *block,
1155                        ir_node *store, ir_node *adr);
1156 ir_node *new_rd_Store  (dbg_info *db, ir_graph *irg, ir_node *block,
1157                        ir_node *store, ir_node *adr, ir_node *val);
1158 ir_node *new_rd_Alloc  (dbg_info *db, ir_graph *irg, ir_node *block, ir_node *store,
1159                        ir_node *size, type *alloc_type, where_alloc where);
1160 ir_node *new_rd_Free   (dbg_info *db, ir_graph *irg, ir_node *block, ir_node *store,
1161                        ir_node *ptr, ir_node *size, type *free_type);
1162 ir_node *new_rd_Sync   (dbg_info *db, ir_graph *irg, ir_node *block, int arity, ir_node *in[]);
1163 ir_node *new_rd_Proj   (dbg_info *db, ir_graph *irg, ir_node *block, ir_node *arg,
1164                        ir_mode *mode, long proj);
1165 ir_node *new_rd_defaultProj (dbg_info *db, ir_graph *irg, ir_node *block, ir_node *arg,
1166                             long max_proj);
1167 ir_node *new_rd_Tuple  (dbg_info *db, ir_graph *irg, ir_node *block,
1168                        int arity, ir_node *in[]);
1169 ir_node *new_rd_Id     (dbg_info *db, ir_graph *irg, ir_node *block,
1170                        ir_node *val, ir_mode *mode);
1171 ir_node *new_rd_Bad    (ir_graph *irg);
1172 ir_node *new_rd_Unknown(ir_graph *irg);
1173 ir_node *new_rd_CallBegin(dbg_info *db, ir_graph *irg, ir_node *block, ir_node *callee);
1174 ir_node *new_rd_EndReg (dbg_info *db, ir_graph *irg, ir_node *block);
1175 ir_node *new_rd_EndExcept(dbg_info *db, ir_graph *irg, ir_node *block);
1176 ir_node *new_rd_Break  (dbg_info *db, ir_graph *irg, ir_node *block);
1177 ir_node *new_rd_Filter (dbg_info *db, ir_graph *irg, ir_node *block, ir_node *arg,
1178                        ir_mode *mode, long proj);
1179
1180 /*-------------------------------------------------------------------------*/
1181 /* The raw interface without debug support                                 */
1182 /*-------------------------------------------------------------------------*/
1183
1184 /* Constructs a Block with a fixed number of predecessors.
1185    Does not set current_block.  Can not be used with automatic
1186    Phi node costruction. */
1187 ir_node *new_r_Block  (ir_graph *irg,  int arity, ir_node *in[]);
1188 ir_node *new_r_Start  (ir_graph *irg, ir_node *block);
1189 ir_node *new_r_End    (ir_graph *irg, ir_node *block);
1190 ir_node *new_r_Jmp    (ir_graph *irg, ir_node *block);
1191 ir_node *new_r_Cond   (ir_graph *irg, ir_node *block, ir_node *c);
1192 ir_node *new_r_Return (ir_graph *irg, ir_node *block,
1193                        ir_node *store, int arity, ir_node *in[]);
1194 ir_node *new_r_Raise  (ir_graph *irg, ir_node *block,
1195                        ir_node *store, ir_node *obj);
1196 ir_node *new_r_Const  (ir_graph *irg, ir_node *block,
1197                        ir_mode *mode, tarval *con);
1198 ir_node *new_r_SymConst (ir_graph *irg, ir_node *block,
1199                        type_or_id_p value, symconst_kind symkind);
1200 ir_node *new_r_Sel    (ir_graph *irg, ir_node *block, ir_node *store,
1201                        ir_node *objptr, int n_index, ir_node *index[],
1202                        entity *ent);
1203 ir_node *new_r_Call   (ir_graph *irg, ir_node *block, ir_node *store,
1204                        ir_node *callee, int arity, ir_node *in[],
1205                        type *tp);
1206 ir_node *new_r_Add    (ir_graph *irg, ir_node *block,
1207                        ir_node *op1, ir_node *op2, ir_mode *mode);
1208 ir_node *new_r_Sub    (ir_graph *irg, ir_node *block,
1209                        ir_node *op1, ir_node *op2, ir_mode *mode);
1210 ir_node *new_r_Minus  (ir_graph *irg, ir_node *block,
1211                        ir_node *op,  ir_mode *mode);
1212 ir_node *new_r_Mul    (ir_graph *irg, ir_node *block,
1213                        ir_node *op1, ir_node *op2, ir_mode *mode);
1214 ir_node *new_r_Quot   (ir_graph *irg, ir_node *block,
1215                        ir_node *memop, ir_node *op1, ir_node *op2);
1216 ir_node *new_r_DivMod (ir_graph *irg, ir_node *block,
1217                        ir_node *memop, ir_node *op1, ir_node *op2);
1218 ir_node *new_r_Div    (ir_graph *irg, ir_node *block,
1219                        ir_node *memop, ir_node *op1, ir_node *op2);
1220 ir_node *new_r_Mod    (ir_graph *irg, ir_node *block,
1221                        ir_node *memop, ir_node *op1, ir_node *op2);
1222 ir_node *new_r_Abs    (ir_graph *irg, ir_node *block,
1223                        ir_node *op, ir_mode *mode);
1224 ir_node *new_r_And    (ir_graph *irg, ir_node *block,
1225                        ir_node *op1, ir_node *op2, ir_mode *mode);
1226 ir_node *new_r_Or     (ir_graph *irg, ir_node *block,
1227                        ir_node *op1, ir_node *op2, ir_mode *mode);
1228 ir_node *new_r_Eor    (ir_graph *irg, ir_node *block,
1229                        ir_node *op1, ir_node *op2, ir_mode *mode);
1230 ir_node *new_r_Not    (ir_graph *irg, ir_node *block,
1231                        ir_node *op, ir_mode *mode);
1232 ir_node *new_r_Cmp    (ir_graph *irg, ir_node *block,
1233                        ir_node *op1, ir_node *op2);
1234 ir_node *new_r_Shl    (ir_graph *irg, ir_node *block,
1235                        ir_node *op, ir_node *k, ir_mode *mode);
1236 ir_node *new_r_Shr    (ir_graph *irg, ir_node *block,
1237                        ir_node *op, ir_node *k, ir_mode *mode);
1238 ir_node *new_r_Shrs   (ir_graph *irg, ir_node *block,
1239                        ir_node *op, ir_node *k, ir_mode *mode);
1240 ir_node *new_r_Rot    (ir_graph *irg, ir_node *block,
1241                        ir_node *op, ir_node *k, ir_mode *mode);
1242 ir_node *new_r_Conv   (ir_graph *irg, ir_node *block,
1243                        ir_node *op, ir_mode *mode);
1244 ir_node *new_r_Cast   (ir_graph *irg, ir_node *block,
1245                        ir_node *op, type *to_tp);
1246 ir_node *new_r_Phi    (ir_graph *irg, ir_node *block, int arity,
1247                        ir_node *in[], ir_mode *mode);
1248 ir_node *new_r_Load   (ir_graph *irg, ir_node *block,
1249                        ir_node *store, ir_node *adr);
1250 ir_node *new_r_Store  (ir_graph *irg, ir_node *block,
1251                        ir_node *store, ir_node *adr, ir_node *val);
1252 ir_node *new_r_Alloc  (ir_graph *irg, ir_node *block, ir_node *store,
1253                        ir_node *size, type *alloc_type, where_alloc where);
1254 ir_node *new_r_Free   (ir_graph *irg, ir_node *block, ir_node *store,
1255                        ir_node *ptr, ir_node *size, type *free_type);
1256 ir_node *new_r_Sync   (ir_graph *irg, ir_node *block, int arity, ir_node *in[]);
1257 ir_node *new_r_Proj   (ir_graph *irg, ir_node *block, ir_node *arg,
1258                        ir_mode *mode, long proj);
1259 ir_node *new_r_defaultProj (ir_graph *irg, ir_node *block, ir_node *arg,
1260                             long max_proj);
1261 ir_node *new_r_Tuple  (ir_graph *irg, ir_node *block,
1262                        int arity, ir_node *in[]);
1263 ir_node *new_r_Id     (ir_graph *irg, ir_node *block,
1264                        ir_node *val, ir_mode *mode);
1265 ir_node *new_r_Bad    (ir_graph *irg);
1266 ir_node *new_r_Unknown(ir_graph *irg);
1267 ir_node *new_r_CallBegin(ir_graph *irg, ir_node *block, ir_node *callee);
1268 ir_node *new_r_EndReg (ir_graph *irg, ir_node *block);
1269 ir_node *new_r_EndExcept(ir_graph *irg, ir_node *block);
1270 ir_node *new_r_Break  (ir_graph *irg, ir_node *block);
1271 ir_node *new_r_Filter (ir_graph *irg, ir_node *block, ir_node *arg,
1272                        ir_mode *mode, long proj);
1273
1274 /*-----------------------------------------------------------------------*/
1275 /* The block oriented interface                                          */
1276 /*-----------------------------------------------------------------------*/
1277
1278 /** Sets the current block in which the following constructors place the
1279    nodes they construct. */
1280 void switch_block (ir_node *target);
1281
1282 /* Constructs a Block with a fixed number of predecessors.
1283    Does set current_block.  Can be used with automatic Phi
1284    node construction. */
1285
1286
1287 ir_node *new_d_Block(dbg_info* db, int arity, ir_node *in[]);
1288 ir_node *new_d_Start  (dbg_info* db);
1289 ir_node *new_d_End    (dbg_info* db);
1290 ir_node *new_d_Jmp    (dbg_info* db);
1291 ir_node *new_d_Cond   (dbg_info* db, ir_node *c);
1292 ir_node *new_d_Return (dbg_info* db, ir_node *store, int arity, ir_node *in[]);
1293 ir_node *new_d_Raise  (dbg_info* db, ir_node *store, ir_node *obj);
1294 ir_node *new_d_Const  (dbg_info* db, ir_mode *mode, tarval *con);
1295 ir_node *new_d_SymConst (dbg_info* db, type_or_id_p value, symconst_kind kind);
1296 ir_node *new_d_simpleSel(dbg_info* db, ir_node *store, ir_node *objptr, entity *ent);
1297 ir_node *new_d_Sel    (dbg_info* db, ir_node *store, ir_node *objptr, int arity, ir_node *in[],
1298                      entity *ent);
1299 ir_node *new_d_Call   (dbg_info* db, ir_node *store, ir_node *callee, int arity, ir_node *in[],
1300                      type *tp);
1301 ir_node *new_d_Add    (dbg_info* db, ir_node *op1, ir_node *op2, ir_mode *mode);
1302 ir_node *new_d_Sub    (dbg_info* db, ir_node *op1, ir_node *op2, ir_mode *mode);
1303 ir_node *new_d_Minus  (dbg_info* db, ir_node *op,  ir_mode *mode);
1304 ir_node *new_d_Mul    (dbg_info* db, ir_node *op1, ir_node *op2, ir_mode *mode);
1305 ir_node *new_d_Quot   (dbg_info* db, ir_node *memop, ir_node *op1, ir_node *op2);
1306 ir_node *new_d_DivMod (dbg_info* db, ir_node *memop, ir_node *op1, ir_node *op2);
1307 ir_node *new_d_Div    (dbg_info* db, ir_node *memop, ir_node *op1, ir_node *op2);
1308 ir_node *new_d_Mod    (dbg_info* db, ir_node *memop, ir_node *op1, ir_node *op2);
1309 ir_node *new_d_Abs    (dbg_info* db, ir_node *op,                ir_mode *mode);
1310 ir_node *new_d_And    (dbg_info* db, ir_node *op1, ir_node *op2, ir_mode *mode);
1311 ir_node *new_d_Or     (dbg_info* db, ir_node *op1, ir_node *op2, ir_mode *mode);
1312 ir_node *new_d_Eor    (dbg_info* db, ir_node *op1, ir_node *op2, ir_mode *mode);
1313 ir_node *new_d_Not    (dbg_info* db, ir_node *op,                ir_mode *mode);
1314 ir_node *new_d_Shl    (dbg_info* db, ir_node *op,  ir_node *k,   ir_mode *mode);
1315 ir_node *new_d_Shr    (dbg_info* db, ir_node *op,  ir_node *k,   ir_mode *mode);
1316 ir_node *new_d_Shrs   (dbg_info* db, ir_node *op,  ir_node *k,   ir_mode *mode);
1317 ir_node *new_d_Rot    (dbg_info* db, ir_node *op,  ir_node *k,   ir_mode *mode);
1318 ir_node *new_d_Cmp    (dbg_info* db, ir_node *op1, ir_node *op2);
1319 ir_node *new_d_Conv   (dbg_info* db, ir_node *op, ir_mode *mode);
1320 ir_node *new_d_Cast   (dbg_info* db, ir_node *op, type *to_tp);
1321 ir_node *new_d_Phi    (dbg_info* db, int arity, ir_node *in[], ir_mode *mode);
1322 ir_node *new_d_Load   (dbg_info* db, ir_node *store, ir_node *addr);
1323 ir_node *new_d_Store  (dbg_info* db, ir_node *store, ir_node *addr, ir_node *val);
1324 ir_node *new_d_Alloc  (dbg_info* db, ir_node *store, ir_node *size, type *alloc_type,
1325                      where_alloc where);
1326 ir_node *new_d_Free   (dbg_info* db, ir_node *store, ir_node *ptr, ir_node *size,
1327                      type *free_type);
1328 ir_node *new_d_Sync   (dbg_info* db, int arity, ir_node *in[]);
1329 ir_node *new_d_Proj   (dbg_info* db, ir_node *arg, ir_mode *mode, long proj);
1330 ir_node *new_d_defaultProj (dbg_info* db, ir_node *arg, long max_proj);
1331 ir_node *new_d_Tuple  (dbg_info* db, int arity, ir_node *in[]);
1332 ir_node *new_d_Id     (dbg_info* db, ir_node *val, ir_mode *mode);
1333 ir_node *new_d_Bad    (void);
1334 ir_node *new_d_Unknown(void);
1335 ir_node *new_d_CallBegin(dbg_info *db, ir_node *callee);
1336 ir_node *new_d_EndReg (dbg_info *db);
1337 ir_node *new_d_EndExcept(dbg_info *db);
1338 ir_node *new_d_Break (dbg_info *db);
1339 ir_node *new_d_Filter (dbg_info *db, ir_node *arg, ir_mode *mode, long proj);
1340
1341 /*-----------------------------------------------------------------------*/
1342 /* The block oriented interface without debug support                    */
1343 /*-----------------------------------------------------------------------*/
1344
1345 /* Needed from the interfase with debug support:
1346 void switch_block (ir_node *target);   */
1347
1348 /* Constructs a Block with a fixed number of predecessors.
1349    Does set current_block.  Can be used with automatic Phi
1350    node construction. */
1351 ir_node *new_Block(int arity, ir_node *in[]);
1352 ir_node *new_Start  (void);
1353 ir_node *new_End    (void);
1354 ir_node *new_EndReg (void);
1355 ir_node *new_EndExcept(void);
1356 ir_node *new_Jmp    (void);
1357 ir_node *new_Break  (void);
1358 ir_node *new_Cond   (ir_node *c);
1359 ir_node *new_Return (ir_node *store, int arity, ir_node *in[]);
1360 ir_node *new_Raise  (ir_node *store, ir_node *obj);
1361 ir_node *new_Const  (ir_mode *mode, tarval *con);
1362 ir_node *new_SymConst (type_or_id_p value, symconst_kind kind);
1363 ir_node *new_simpleSel(ir_node *store, ir_node *objptr, entity *ent);
1364 ir_node *new_Sel    (ir_node *store, ir_node *objptr, int arity, ir_node *in[],
1365                      entity *ent);
1366 ir_node *new_InstOf (ir_node *store, ir_node *objptr, type *ent);
1367 ir_node *new_Call   (ir_node *store, ir_node *callee, int arity, ir_node *in[],
1368                      type *tp);
1369 ir_node *new_CallBegin(ir_node *callee);
1370 ir_node *new_Add    (ir_node *op1, ir_node *op2, ir_mode *mode);
1371 ir_node *new_Sub    (ir_node *op1, ir_node *op2, ir_mode *mode);
1372 ir_node *new_Minus  (ir_node *op,  ir_mode *mode);
1373 ir_node *new_Mul    (ir_node *op1, ir_node *op2, ir_mode *mode);
1374 ir_node *new_Quot   (ir_node *memop, ir_node *op1, ir_node *op2);
1375 ir_node *new_DivMod (ir_node *memop, ir_node *op1, ir_node *op2);
1376 ir_node *new_Div    (ir_node *memop, ir_node *op1, ir_node *op2);
1377 ir_node *new_Mod    (ir_node *memop, ir_node *op1, ir_node *op2);
1378 ir_node *new_Abs    (ir_node *op,                ir_mode *mode);
1379 ir_node *new_And    (ir_node *op1, ir_node *op2, ir_mode *mode);
1380 ir_node *new_Or     (ir_node *op1, ir_node *op2, ir_mode *mode);
1381 ir_node *new_Eor    (ir_node *op1, ir_node *op2, ir_mode *mode);
1382 ir_node *new_Not    (ir_node *op,                ir_mode *mode);
1383 ir_node *new_Shl    (ir_node *op,  ir_node *k,   ir_mode *mode);
1384 ir_node *new_Shr    (ir_node *op,  ir_node *k,   ir_mode *mode);
1385 ir_node *new_Shrs   (ir_node *op,  ir_node *k,   ir_mode *mode);
1386 ir_node *new_Rot    (ir_node *op,  ir_node *k,   ir_mode *mode);
1387 ir_node *new_Cmp    (ir_node *op1, ir_node *op2);
1388 ir_node *new_Conv   (ir_node *op, ir_mode *mode);
1389 ir_node *new_Cast   (ir_node *op, type *to_tp);
1390 ir_node *new_Phi    (int arity, ir_node *in[], ir_mode *mode);
1391 ir_node *new_Load   (ir_node *store, ir_node *addr);
1392 ir_node *new_Store  (ir_node *store, ir_node *addr, ir_node *val);
1393 ir_node *new_Alloc  (ir_node *store, ir_node *size, type *alloc_type,
1394                      where_alloc where);
1395 ir_node *new_Free   (ir_node *store, ir_node *ptr, ir_node *size,
1396                      type *free_type);
1397 ir_node *new_Sync   (int arity, ir_node *in[]);
1398 ir_node *new_Proj   (ir_node *arg, ir_mode *mode, long proj);
1399 ir_node *new_Filter (ir_node *arg, ir_mode *mode, long proj);
1400 ir_node *new_defaultProj (ir_node *arg, long max_proj);
1401 ir_node *new_Tuple  (int arity, ir_node *in[]);
1402 ir_node *new_Id     (ir_node *val, ir_mode *mode);
1403 ir_node *new_Bad    (void);
1404 ir_node *new_Unknown(void);
1405
1406 /*---------------------------------------------------------------------*/
1407 /* The comfortable interface.                                          */
1408 /* Supports automatic Phi node construction.                           */
1409 /* All routines of the block oriented interface except new_Block are   */
1410 /* needed also.                                                        */
1411 /*---------------------------------------------------------------------*/
1412
1413 /* --- Block construction --- */
1414 /* immature Block without predecessors */
1415 ir_node *new_d_immBlock (dbg_info* db);
1416 ir_node *new_immBlock (void);
1417
1418 /** Add a control flow edge to an immature block. */
1419 void add_in_edge (ir_node *immblock, ir_node *jmp);
1420
1421 /** fixes the number of predecessors of a block. */
1422 void mature_block (ir_node *block);
1423
1424 /* --- Parameter administration --- */
1425 /* Read a value from the array with the local variables.  Use this
1426    function to obtain the last definition of the value associated with
1427    pos.  Pos may not exceed the value passed as n_loc to new_ir_graph. */
1428 ir_node *get_d_value (dbg_info* db, int pos, ir_mode *mode);
1429 ir_node *get_value (int pos, ir_mode *mode);
1430
1431 /** Write a value in the array with the local variables. Use this function
1432    to remember a new definition of the value associated with pos. Pos may
1433    not exceed the value passed as n_loc to new_ir_graph. */
1434 void set_value (int pos, ir_node *value);
1435
1436 /** Read a store.
1437    Use this function to get the most recent version of the store (type M).
1438    Internally it does the same as get_value. */
1439 ir_node *get_store (void);
1440
1441 /** Write a store. */
1442 void set_store (ir_node *store);
1443
1444 /** keep this node alive even if End is not control-reachable from it */
1445 void keep_alive (ir_node *ka);
1446
1447 /* --- Useful access routines --- */
1448 /** Returns the current block of the current graph.  To set the current
1449    block use switch_block(). */
1450 ir_node *get_cur_block(void);
1451
1452 /** Returns the frame type of the current graph */
1453 type *get_cur_frame_type(void);
1454
1455
1456 /* --- initialize and finalize ir construction --- */
1457
1458 /** Puts the graph into state "phase_high" */
1459 void finalize_cons (ir_graph *irg);
1460
1461 /* --- Initialization --- */
1462
1463 /**
1464  * This function is called, whenever a local variable is used before definition
1465  *
1466  * @parameter mode      the mode of the local var
1467  * @pos                 position choosen be the frontend for this var
1468  *
1469  * @return a firm node of mode @p mode that initialises the var at position pos
1470  *
1471  * @note
1472  *      Do not return NULL
1473  *      If this function is not set, FIRM will create a const node with tarval BAD
1474  */
1475 typedef ir_node *default_initialize_local_variable_func_t(ir_mode *mode, int pos);
1476
1477 /**
1478  * Initializes the graph construction.
1479  *
1480  * @param func  @see default_initialize_local_variable_func_t
1481  */
1482 void init_cons (default_initialize_local_variable_func_t *func);
1483
1484 # endif /* _IRCONS_H_ */