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