bc76b2abf5be9d146a81d3d15c926e063b6d3665
[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_InstOf (ir_node *store, ir_node *objptr, type *ent);
333  *    ir_node *new_Call   (ir_node *store, ir_node *callee, int arity,
334  *                     ir_node **in, type_method *type);
335  *    ir_node *new_Add    (ir_node *op1, ir_node *op2, ir_mode *mode);
336  *    ir_node *new_Sub    (ir_node *op1, ir_node *op2, ir_mode *mode);
337  *    ir_node *new_Minus  (ir_node *op,  ir_mode *mode);
338  *    ir_node *new_Mul    (ir_node *op1, ir_node *op2, ir_mode *mode);
339  *    ir_node *new_Quot   (ir_node *memop, ir_node *op1, ir_node *op2);
340  *    ir_node *new_DivMod (ir_node *memop, ir_node *op1, ir_node *op2);
341  *    ir_node *new_Div    (ir_node *memop, ir_node *op1, ir_node *op2);
342  *    ir_node *new_Mod    (ir_node *memop, ir_node *op1, ir_node *op2);
343  *    ir_node *new_Abs    (ir_node *op,                ir_mode *mode);
344  *    ir_node *new_And    (ir_node *op1, ir_node *op2, ir_mode *mode);
345  *    ir_node *new_Or     (ir_node *op1, ir_node *op2, ir_mode *mode);
346  *    ir_node *new_Eor    (ir_node *op1, ir_node *op2, ir_mode *mode);
347  *    ir_node *new_Not    (ir_node *op,                ir_mode *mode);
348  *    ir_node *new_Shl    (ir_node *op,  ir_node *k,   ir_mode *mode);
349  *    ir_node *new_Shr    (ir_node *op,  ir_node *k,   ir_mode *mode);
350  *    ir_node *new_Shrs   (ir_node *op,  ir_node *k,   ir_mode *mode);
351  *    ir_node *new_Rot    (ir_node *op,  ir_node *k,   ir_mode *mode);
352  *    ir_node *new_Cmp    (ir_node *op1, ir_node *op2);
353  *    ir_node *new_Conv   (ir_node *op, ir_mode *mode);
354  *    ir_node *new_Cast   (ir_node *op, type *to_tp);
355  *    ir_node *new_Load   (ir_node *store, ir_node *addr);
356  *    ir_node *new_Store  (ir_node *store, ir_node *addr, ir_node *val);
357  *    ir_node *new_Alloc  (ir_node *store, ir_node *size, type *alloc_type,
358  *                         where_alloc where);
359  *    ir_node *new_Free   (ir_node *store, ir_node *ptr, ir_node *size,
360  *                   type *free_type);
361  *    ir_node *new_Proj   (ir_node *arg, ir_mode *mode, long proj);
362  *
363  *    void add_in_edge (ir_node *block, ir_node *jmp);
364  *    void     mature_block (ir_node *block);
365  *    void switch_block (ir_node *target);
366  *    ir_node *get_value (int pos, ir_mode *mode);
367  *    void set_value (int pos, ir_node *value);
368  *    ir_node *get_store (void);
369  *    void set_store (ir_node *store);
370  *    keep_alive (ir_node ka)
371  *
372  *    IR_NODES AND CONSTRUCTORS FOR IR_NODES
373  *    =======================================
374  *
375  *    All ir_nodes are defined by a common data structure.  They are distinguished
376  *    by their opcode and differ in the number of their attributes.
377  *
378  *    The constructor for the block node sets current_block to itself.
379  *    Const nodes are always added to the start block.
380  *    All other constructors add the created node to the current_block.
381  *    swich_block(block) allows to set the current block to block.
382  *
383  *    Watch for my inconsistent use of input and predecessor (dataflow view)
384  *    and `the node points to' (implementation view).
385  *
386  *    The following description of the nodes lists four properties them if these
387  *    are of interest:
388  *     - the parameters to the constructor
389  *     - the inputs of the Firm node
390  *     - the outputs of the Firm node
391  *     - attributes to the node
392  *
393  *    ------------
394  *
395  *    ir_node *new_immBlock (void)
396  *    ----------------------------
397  *
398  *    Creates a new block.  Sets current_block to itself.  When a new block is
399  *    created it cannot be known how many predecessors this block will have in the
400  *    control flow graph. Therefore the list of inputs can not be fixed at
401  *    creation.  Predecessors can be added with add_in_edge (block, control flow
402  *    operation).  With every added predecessor the number of inputs to Phi nodes
403  *    also changes.
404  *
405  *    The block can be completed by mature_block(block) if all predecessors are
406  *    known.  If several blocks are built at once, mature_block can only be called
407  *    after set_value has been called for all values that are life at the end
408  *    of the block.  This is necessary so that Phi nodes created by mature_block
409  *    get the right predecessors in case of cyclic dependencies.  If all set_values
410  *    of this block are called after maturing it and before calling get_value
411  *    in some block that is control flow dependent on this block, the construction
412  *    is correct.
413  *
414  *    Example for faulty ir construction:  (draw the graph on a paper and you'll
415  *                                          get it ;-)
416  *
417  *      block_before_loop = new_block();
418  *      set_value(x);
419  *      mature_block(block_before_loop);
420  *      before2header = new_Jmp;
421  *
422  *      loop_header = new_block ();
423  *      header2body - new_Jmp();
424  *
425  *      loop_body = new_block ();
426  *      body2header = new_Jmp();
427  *
428  *      add_in_edge(loop_header, before2header);
429  *      add_in_edge(loop_header, body2header);
430  *      add_in_edge(loop_body, header2body);
431  *
432  *      mature_block(loop_header);
433  *      mature_block(loop_body);
434  *
435  *      get_value(loop_body, x);   // gets the Phi in loop_header
436  *      set_value(loop_header, x); // sets the value the above get_value should
437  *                                 // have returned!!!
438  *
439  *    Mature_block also fixes the number of inputs to the Phi nodes.  Mature_block
440  *    should be called as early as possible, as afterwards the generation of Phi
441  *    nodes is more efficient.
442  *
443  *    Inputs:
444  *      There is an input for each control flow predecessor of the block.
445  *      The input points to an instruction producing an output of type X.
446  *      Possible predecessors:  Start, Jmp, Cond, Raise or Return or any node
447  *      possibly causing an exception.  (Often the real predecessors are Projs.)
448  *    Output:
449  *      Mode BB (R), all nodes belonging to this block should consume this output.
450  *      As they are strict (except Block and Phi node) it is a necessary condition
451  *      that the block node executed before any other node in this block executes.
452  *    Attributes:
453  *      block.matured  Indicates whether the block is mature.
454  *      block.**graph_arr
455  *                      This attribute contains all local values valid in this
456  *                      block. This is needed to build the Phi nodes and removed
457  *                      if the graph is complete.  This field is used by the
458  *                  internal construction algorithm and should not be accessed
459  *                  from outside.
460  *
461  *
462  *    ir_node *new_Block (int arity, ir_node **in)
463  *    --------------------------------------------
464  *
465  *    Creates a new Block with the given list of predecessors.  This block
466  *    is mature.  As other constructors calls optimization and vrfy for the
467  *    block.  If one of the predecessors is Unknown (as it has to be filled in
468  *    later) optimizations are skipped.  This is necessary to
469  *    construct Blocks in loops.  Leaving Unknown in the Block after finishing
470  *    the construction may have strange effects, especially for interprocedural
471  *    representation and analyses.
472  *
473  *
474  *    CONTROL FLOW OPERATIONS
475  *    -----------------------
476  *
477  *    In each block there must be exactly one of the control flow
478  *    operations Start, End, Jmp, Cond, Return or Raise.  The output of a
479  *    control flow operation points to the block to be executed next.
480  *
481  *    ir_node *new_Start (void)
482  *    -------------------------
483  *
484  *    Creates a start node.  Not actually needed public.  There is only one such
485  *    node in each procedure which is automatically created by new_ir_graph.
486  *
487  *    Inputs:
488  *      No inputs except the block it belogns to.
489  *    Output:
490  *      A tuple of 4 (5, 6) distinct values. These are labeled by the following
491  *      projection numbers (pns_number):
492  *      * pns_initial_exec
493  *                       mode X, points to the first block to be executed.
494  *      * pns_global_store
495  *                       mode M, the global store
496  *      * pns_frame_base mode P, a pointer to the base of the procedures
497  *                           stack frame.
498  *      * pns_globals    mode P, a pointer to the part of the memory containing
499  *                               _all_ global things.
500  *      * pns_args       mode T, a tuple containing all arguments of the procedure.
501  *
502  *
503  *    ir_node *new_End (void)
504  *    -----------------------
505  *
506  *    Creates an end node.  Not actually needed public.  There is only one such
507  *    node in each procedure which is automatically created by new_ir_graph.
508  *
509  *    Inputs:
510  *      No inputs except the block it belongs to.
511  *    Output:
512  *      No output.
513  *
514  *    ir_node *new_Jmp (void)
515  *    -----------------------
516  *
517  *    Creates a Jmp node.
518  *
519  *    Inputs:
520  *      The block the node belongs to
521  *    Output:
522  *      Control flow to the next block.
523  *
524  *    ir_node *new_Cond (ir_node *c)
525  *    ------------------------------
526  *
527  *    Creates a Cond node.  There are two versions of this node.
528  *
529  *    The Boolean Cond:
530  *    Input:
531  *      A value of mode b.
532  *    Output:
533  *      A tuple of two control flows.  The first is taken if the input is
534  *      false, the second if it is true.
535  *
536  *    The Switch Cond:
537  *    Input:
538  *      A value of mode I_u. (i)
539  *    Output:
540  *      A tuple of n control flows.  If the Cond's input is i, control
541  *      flow will procede along output i. If the input is >= n control
542  *      flow proceeds along output n.
543  *
544  *    ir_node *new_Return (in_node *store, int arity, ir_node **in)
545  *    -------------------------------------------------------------
546  *
547  *    The return node has as inputs the results of the procedure.  It
548  *    passes the control flow to the end_block.
549  *
550  *    Inputs:
551  *      The memory state.
552  *      All results.
553  *    Output
554  *      Control flow to the end block.
555  *
556  *    ir_node *new_Raise (ir_node *store, ir_node *obj)
557  *    -------------------------------------------------
558  *
559  *    Raises an exception.  Unconditional change of control flow.  Writes
560  *    an explicit Except variable to memory to pass it to the exception
561  *    handler.  See TechReport 1999-14, chapter Exceptions.
562  *
563  *    Inputs:
564  *      The memory state.
565  *      A pointer to the Except variable.
566  *    Output:
567  *      A tuple of control flow and the changed memory state.  The control flow
568  *      points to the exception handler if it is definied in this procedure,
569  *      else it points to the end_block.
570  *
571  *
572  *    ---------
573  *
574  *    ir_node *new_Const (ir_mode *mode, tarval *con)
575  *    -----------------------------------------------
576  *
577  *    Creates a constant in the constant table and adds a Const node
578  *    returning this value to the start block.
579  *
580  *    Parameters:
581  *      *mode            The mode of the constant.
582  *      *con             Points to an entry in the constant table.
583  *                       This pointer is added to the attributes of
584  *                       the node (self->attr.con)
585  *    Inputs:
586  *      No inputs except the block it belogns to.
587  *    Output:
588  *      The constant value.
589  *    Attribute:
590  *      attr.con   A tarval* pointer to the proper entry in the constant
591  *                 table.
592  *
593  *    ir_node *new_SymConst (type *tp, symconst_kind kind)
594  *    ------------------------------------------------------------
595  *
596  *    There are three kinds of symbolic constants:
597  *      type_tag  The symbolic constant represents a type tag.
598  *      size      The symbolic constant represents the size of a class.
599  *      link_info Information for the linker, e.g. the name of a global
600  *                variable.
601  *    To represent a pointer to an entity that is represented by an entity
602  *    datastructure don't use
603  *      new_SymConst((type_or_id*)get_entity_ld_ident(ent), linkage_ptr_info);.
604  *    Use a real const instead:
605  *      new_Const(mode_P_mach, tarval_p_from_entity(ent));
606  *    This makes the Constant independent of name changes of the entity due to
607  *    mangling.
608  *
609  *    Parameters
610  *      kind        The kind of the symbolic constant: type_tag, size or link_info.
611  *      *type_or_id Points to the type the tag stands for or to the type
612  *                  whose size is represented by the constant or to an ident
613  *                  representing the linkage info.
614  *
615  *    Inputs:
616  *      No inputs except the block it belogns to.
617  *    Output:
618  *      An unsigned integer (I_u) or a pointer (P).
619  *
620  *    Attributes:
621  *      attr.i.num       The symconst_kind, i.e. one of
622  *                        - type_tag
623  *                        - size
624  *                    - linkage_ptr_info
625  *        If the attr.i.num is type_tag or size, the node contains an attribute
626  *      attr.i.*type,    a pointer to a type_class.  The mode of the node is mode_Is.
627  *        if it is linkage_ptr_info it contains
628  *      attr.i.*ptrinfo,  an ident holding information for the linker.  The mode
629  *        of the node is mode_P_mach.
630  *
631  *    ---------------
632  *
633  *    ir_node *new_simpleSel (ir_node *store, ir_node *frame, entity *sel)
634  *    --------------------------------------------------------------------
635  *
636  *
637  *    Selects an entity from a compound type. This entity can be a field or
638  *    a method.
639  *
640  *    Parameters:
641  *      *store     The memory in which the object the entity should be selected
642  *                 from is allocated.
643  *      *frame     The pointer to the object.
644  *      *sel       The entity to select.
645  *
646  *    Inputs:
647  *      The memory containing the object.
648  *      A pointer to the object.
649  *      An unsigned integer.
650  *    Output:
651  *      A pointer to the selected entity.
652  *    Attributes:
653  *      attr.sel   Pointer to the entity
654  *
655  *
656  *    ir_node *new_Sel (ir_node *store, ir_node *frame, int arity, ir_node **in,
657  *    --------------------------------------------------------------------------
658  *                      entity *sel)
659  *                      ------------
660  *
661  *    Selects a field from an array type.  The entity has as owner the array, as
662  *    type the arrays element type.  The indexes to access an array element are
663  *    given also.
664  *
665  *    Parameters:
666  *      *store     The memory in which the object the entity should be selected from
667  *                 is allocated.
668  *      *frame     The pointer to the object.
669  *      *arity     number of array indexes.
670  *      *in        array with index inputs to the node.
671  *      *sel       The entity to select.
672  *
673  *    Inputs:
674  *      The memory containing the object.
675  *      A pointer to the object.
676  *      As much unsigned integer as there are array expressions.
677  *    Output:
678  *      A pointer to the selected entity.
679  *    Attributes:
680  *      attr.sel   Pointer to the entity
681  *
682  *    The constructors new_Sel and new_simpleSel generate the same ir nodes.
683  *    simpleSel just sets the arity of the index inputs to zero.
684  *
685  *
686  *    ARITHMETIC OPERATIONS
687  *    ---------------------
688  *
689  *    ir_node *new_Call (ir_node *store, ir_node *callee, int arity, ir_node **in,
690  *    ----------------------------------------------------------------------------
691  *                       type_method *type)
692  *                       ------------------
693  *
694  *    Creates a procedure call.
695  *
696  *    Parameters
697  *      *store           The actual store.
698  *      *callee          A pointer to the called procedure.
699  *      arity            The number of procedure parameters.
700  *      **in             An array with the pointers to the parameters.
701  *                       The constructor copies this array.
702  *      *type            Type information of the procedure called.
703  *
704  *    Inputs:
705  *      The store, the callee and the parameters.
706  *    Output:
707  *      A tuple containing the eventually changed store and the procedure
708  *      results.
709  *    Attributes:
710  *      attr.call        Contains the type information for the procedure.
711  *
712  *    ir_node *new_Add (ir_node *op1, ir_node *op2, ir_mode *mode)
713  *    ------------------------------------------------------------
714  *
715  *    Trivial.
716  *
717  *    ir_node *new_Sub (ir_node *op1, ir_node *op2, ir_mode *mode)
718  *    ------------------------------------------------------------
719  *
720  *    Trivial.
721  *
722  *    ir_node *new_Minus (ir_node *op, ir_mode *mode)
723  *    -----------------------------------------------
724  *
725  *    Unary Minus operations on floating point values.
726  *
727  *    ir_node *new_Mul (ir_node *op1, ir_node *op2, ir_mode *mode)
728  *    ------------------------------------------------------------
729  *
730  *    Trivial.
731  *
732  *    ir_node *new_Quot (ir_node *memop, ir_node *op1, ir_node *op2)
733  *    --------------------------------------------------------------
734  *
735  *    Quot performs exact division of floating point numbers.  It's mode
736  *    is Tuple, the mode of the result must be annotated to the Proj
737  *    that extracts the result of the arithmetic operations.
738  *
739  *    Inputs:
740  *      The store needed to model exceptions and the two operands.
741  *    Output:
742  *      A tuple contaning a memory and a execution for modeling exceptions
743  *      and the result of the arithmetic operation.
744  *
745  *    ir_node *new_DivMod (ir_node *memop, ir_node *op1, ir_node *op2)
746  *    ----------------------------------------------------------------
747  *
748  *    Performs Div and Mod on interger values.
749  *
750  *    Output:
751  *      A tuple contaning a memory and a execution for modeling exceptions
752  *      and the two result of the arithmetic operations.
753  *
754  *    ir_node *new_Div (ir_node *memop, ir_node *op1, ir_node *op2)
755  *    -------------------------------------------------------------
756  *
757  *    Trivial.
758  *
759  *    ir_node *new_Mod (ir_node *memop, ir_node *op1, ir_node *op2)
760  *    -------------------------------------------------------------
761  *
762  *    Trivial.
763  *
764  *    ir_node *new_Abs (ir_node *op, ir_mode *mode)
765  *    ---------------------------------------------
766  *
767  *    Trivial.
768  *
769  *    ir_node *new_And (ir_node *op1, ir_node *op2, ir_mode *mode)
770  *    ------------------------------------------------------------
771  *
772  *    Trivial.
773  *
774  *    ir_node *new_Or (ir_node *op1, ir_node *op2, ir_mode *mode)
775  *    -----------------------------------------------------------
776  *
777  *    Trivial.
778  *
779  *    ir_node *new_Eor (ir_node *op1, ir_node *op2, ir_mode *mode)
780  *    ------------------------------------------------------------
781  *
782  *    Trivial.
783  *
784  *    ir_node *new_Not (ir_node *op, ir_mode *mode)
785  *    ---------------------------------------------
786  *
787  *    This node constructs a constant where all bits are set to one
788  *    and a Eor of this constant and the operator.  This simulates a
789  *    Not operation.
790  *
791  *    ir_node *new_Shl (ir_node *op, ir_node *k, ir_mode *mode)
792  *    ---------------------------------------------------------
793  *
794  *    Trivial.
795  *
796  *    ir_node *new_Shr (ir_node *op, ir_node *k, ir_mode *mode)
797  *    ---------------------------------------------------------
798  *
799  *    Logic shift right, i.e., zero extended.
800  *
801  *
802  *    ir_node *new_Shrs (ir_node *op, ir_node *k, ir_mode *mode)
803  *    ----------------------------------------------------------
804  *
805  *    Arithmetic shift right, i.e., sign extended.
806  *
807  *    ir_node *new_Rot (ir_node *op, ir_node *k, ir_mode *mode)
808  *    ---------------------------------------------------------
809  *
810  *    Rotates the operand to the (right??) by k bits.
811  *
812  *    ir_node *new_Conv (ir_node *op, ir_mode *mode)
813  *    ---------------------------------------------
814  *
815  *    Mode conversion.  For allowed conversions see UKA Tech Report
816  *    1999-14.
817  *
818  *    ir_node *new_Cmp (ir_node *op1, ir_node *op2)
819  *    ---------------------------------------------
820  *
821  *    Input:
822  *      The two values to be compared.
823  *    Output:
824  *      A 16-tuple containing the results of the 16 different comparisons.
825  *      The following is a list giving the comparisons and a projection
826  *      number (pnc_number) to use in Proj nodes to extract the proper result.
827  *        False     false
828  *        Eq        equal
829  *        Lt    less
830  *        Le    less or equal
831  *        Gt    greater
832  *        Ge    greater of equal
833  *        Lg    less or greater
834  *        Leg   less, equal or greater = ordered
835  *        Uo    unordered
836  *        Ue    unordered or equal
837  *        Ul    unordered or less
838  *        Ule   unordered, less or equal
839  *        Ug    unordered or greater
840  *        Uge   unordered, greater or equal
841  *        Ne    unordered, less or greater = not equal
842  *        True  true
843  *
844  *
845  *
846  *    ------------
847  *
848  *    In general, Phi nodes are automaitcally inserted.  In some cases, if
849  *    all predecessors of a block are known, an explicit Phi node constructor
850  *    is needed.  E.g., to construct a FIRM graph for a statement as
851  *      a = (b==c) ? 2 : 5;
852  *
853  *    ir_node *new_Phi (int arity, ir_node **in, ir_mode *mode)
854  *    ---------------------------------------------------------
855  *
856  *    Creates a Phi node. The in's order has to correspond to the order
857  *    of in's of current_block.  This is not checked by the library!
858  *    If one of the predecessors is Unknown (as it has to be filled in
859  *    later) optimizations are skipped.  This is necessary to
860  *    construct Phi nodes in loops.  Leaving Unknown in the Phi after finishing
861  *    the construction may have strange effects, especially for interprocedural
862  *    representation and analyses.
863  *
864  *    Parameter
865  *      arity            number of predecessors
866  *      **in             array with predecessors
867  *      *mode            The mode of it's inputs and output.
868  *    Inputs:
869  *      A Phi node has as many inputs as the block it belongs to.
870  *      Each input points to a definition of the same value on a
871  *      different path in the control flow.
872  *    Output
873  *      The definition valid in this block.
874  *
875  *
876  *    OPERATIONS TO MANAGE MEMORY EXPLICITLY
877  *    --------------------------------------
878  *
879  *    ir_node *new_Load (ir_node *store, ir_node *addr)
880  *    ----------------------------------------------------------------
881  *
882  *    The Load operation reads a value from memory.
883  *
884  *    Parameters:
885  *    *store        The current memory.
886  *    *addr         A pointer to the variable to be read in this memory.
887  *
888  *    Inputs:
889  *      The memory and a pointer to a variable in this memory.
890  *    Output:
891  *      A tuple of the memory, a control flow to be taken in case of
892  *      an exception and the loaded value.
893  *
894  *    ir_node *new_Store (ir_node *store, ir_node *addr, ir_node *val)
895  *    ----------------------------------------------------------------
896  *
897  *    The Store operation writes a value to a variable in memory.
898  *
899  *    Inputs:
900  *      The memory, a pointer to a variable in this memory and the value
901  *      to write to this variable.
902  *    Output:
903  *      A tuple of the changed memory and a control flow to be taken in
904  *      case of an exception.
905  *
906  *    ir_node *new_Alloc (ir_node *store, ir_node *size, type *alloc_type,
907  *    --------------------------------------------------------------------
908  *                        where_alloc where)
909  *                        ------------------
910  *
911  *    The Alloc node allocates a new variable.  It can be specified whether the
912  *    variable should be allocated to the stack or to the heap.
913  *
914  *    Parameters:
915  *      *store       The memory which shall contain the new variable.
916  *      **    *size        The number of bytes to allocate. Old. **
917  *      *size        We decided that the size easily can be derived from the type.
918  *                   This field is for allocating arrays, i.e., it gives the multiple
919  *               of the size of alloc_type to allocate memory for.
920  *      *alloc_type  The type of the allocated variable.
921  *      where        Where to allocate the variable, either heap_alloc or stack_alloc.
922  *
923  *    Inputs:
924  *      A memory and an unsigned integer.
925  *    Output:
926  *      A tuple of the changed memory, a control flow to be taken in
927  *      case of an exception and the pointer to the new variable.
928  *    Attributes:
929  *      a.where          Indicates where the variable is allocated.
930  *      a.*type          A pointer to the class the allocated data object
931  *                       belongs to.
932  *
933  *    ir_node *new_Free (ir_node *store, ir_node *ptr, type *free_type)
934  *    ------------------------------------------------------------------
935  *
936  *    The Free node frees memory of the given variable.
937  *
938  *    Parameters:
939  *      *store       The memory which shall contain the new variable.
940  *      *ptr         The pointer to the object to free.
941  *      *size        The number of objects of type free_type to free in a sequence.
942  *      *free_type   The type of the freed variable.
943  *
944  *    Inputs:
945  *      A memory, a pointer and an unsigned integer.
946  *    Output:
947  *      The changed memory.
948  *    Attributes:
949  *      f.*type          A pointer to the type information of the freed data object.
950  *
951  *    Not Implemented!
952  *
953  *    ir_node *new_Sync (int arity, ir_node **in)
954  *    -------------------------------------------
955  *
956  *    The Sync operation unifies several partial memory blocks.  These blocks
957  *    have to be pairwise disjunct or the values in common locations have to
958  *    be identical.  This operation allows to specify all operations that eventually
959  *    need several partial memory blocks as input with a single entrance by
960  *    unifying the memories with a preceding Sync operation.
961  *
962  *    Parameters
963  *      arity    The number of memories to syncronize.
964  *      **in     An array of pointers to nodes that produce an output of
965  *               type memory.
966  *    Inputs
967  *      Several memories.
968  *    Output
969  *      The unified memory.
970  *
971  *
972  *    SPECIAL OPERATIONS
973  *    ------------------
974  *
975  *    ir_node *new_Bad (void)
976  *    -----------------------
977  *
978  *    Returns the unique Bad node current_ir_graph->bad.
979  *    This node is used to express results of dead code elimination.
980  *
981  *    ir_node *new_Proj (ir_node *arg, ir_mode *mode, long proj)
982  *    ----------------------------------------------------------
983  *
984  *    Selects one entry of a tuple.  This is a hidden `fat edge'.
985  *
986  *    Parameters
987  *      *arg      A node producing a tuple.
988  *      *mode     The mode of the value to project.
989  *      proj      The position of the value in the tuple.
990  *    Input:
991  *      The tuple.
992  *    Output:
993  *      The value.
994  *
995  *    ir_node *new_Tuple (int arity, ir_node **in)
996  *    --------------------------------------------
997  *
998  *    Builds a Tuple from single values.  This is needed to implement
999  *    optimizations that remove a node that produced a tuple.  The node can be
1000  *    replaced by the Tuple operation so that the following Proj nodes have not to
1001  *    be changed.  (They are hard to find due to the implementation with pointers
1002  *    in only one direction.)  The Tuple node is smaller than any other
1003  *    node, so that a node can be changed into a Tuple by just changing it's
1004  *    opcode and giving it a new in array.
1005  *
1006  *    Parameters
1007  *      arity    The number of tuple elements.
1008  *      **in     An array containing pointers to the nodes producing the
1009  *               tuple elements.
1010  *
1011  *    ir_node *new_Id (ir_node *val, ir_mode *mode)
1012  *    ---------------------------------------------
1013  *
1014  *    The single output of the Id operation is it's input.  Also needed
1015  *    for optimizations.
1016  *
1017  *
1018  *    COPING WITH DATA OBJECTS
1019  *    ========================
1020  *
1021  *    Two kinds of data objects have to be distinguished for generating
1022  *    FIRM.  First there are local variables other than arrays that are
1023  *    known to be alias free.  Second there are all other data objects.
1024  *    For the first a common SSA representation is built, the second
1025  *    are modeled by saving them to memory.  The memory is treated as
1026  *    a single local variable, the alias problem is hidden in the
1027  *    content of this variable.
1028  *
1029  *    All values known in a Block are listed in the block's attribute,
1030  *    block.**graph_arr which is used to automatically insert Phi nodes.
1031  *    The following two funcions can be used to add a newly computed value
1032  *    to the array, or to get the producer of a value, i.e., the current
1033  *    live value.
1034  *
1035  *    inline void set_value (int pos, ir_node *value)
1036  *    -----------------------------------------------
1037  *
1038  *    Has to be called for every assignment to a local variable.  It
1039  *    adds the value to the array of used values at position pos.  Pos
1040  *    has to be a unique identifier for an entry in the procedure's
1041  *    definition table.  It can be used to access the value again.
1042  *    Requires current_block to be set correctly.
1043  *
1044  *    ir_node *get_value (int pos, ir_mode *mode)
1045  *    -------------------------------------------
1046  *
1047  *    Returns the node defining the value referred to by pos. If the
1048  *    value is not defined in this block a Phi node is generated and
1049  *    all definitions reaching this Phi node are collected.  It can
1050  *    happen that the algorithm allocates an unnecessary Phi node,
1051  *    e.g. if there is only one definition of this value, but this
1052  *    definition reaches the currend block on several different
1053  *    paths.  This Phi node will be eliminated if optimizations are
1054  *    turned on right after it's creation.
1055  *    Requires current_block to be set correctly.
1056  *
1057  *    There are two special routines for the global store:
1058  *
1059  *    inline void set_store (ir_node *store)
1060  *    --------------------------------------
1061  *
1062  *    Adds the store to the array of known values at a reserved
1063  *    position.
1064  *    Requires current_block to be set correctly.
1065  *
1066  *    inline ir_node *get_store (void)
1067  *    --------------------------------
1068  *
1069  *    Returns the node defining the actual store.
1070  *    Requires current_block to be set correctly.
1071  *
1072  *
1073  *    inline void keep_alive (ir_node *ka)
1074  *    ------------------------------------
1075  *
1076  *    Keep this node alive because it is (might be) not in the control
1077  *    flow from Start to End.  Adds the node to the list in the end
1078  *    node.
1079  *
1080  */
1081
1082
1083 # ifndef _IRCONS_H_
1084 # define _IRCONS_H_
1085
1086 # include "firm_common.h"
1087 # include "irgraph.h"
1088 # include "irnode.h"
1089 # include "irmode.h"
1090 # include "entity.h"
1091 # include "tv.h"
1092 # include "type.h"
1093 # include "dbginfo.h"
1094
1095 /*-------------------------------------------------------------------------*/
1096 /* The raw interface                                                       */
1097 /*-------------------------------------------------------------------------*/
1098
1099 /* Constructs a Block with a fixed number of predecessors.
1100    Does not set current_block.  Can not be used with automatic
1101    Phi node construction. */
1102 ir_node *new_rd_Block  (dbg_info *db, ir_graph *irg,  int arity, ir_node *in[]);
1103 ir_node *new_rd_Start  (dbg_info *db, ir_graph *irg, ir_node *block);
1104 ir_node *new_rd_End    (dbg_info *db, ir_graph *irg, ir_node *block);
1105 ir_node *new_rd_Jmp    (dbg_info *db, ir_graph *irg, ir_node *block);
1106 ir_node *new_rd_Cond   (dbg_info *db, ir_graph *irg, ir_node *block, ir_node *c);
1107 ir_node *new_rd_Return (dbg_info *db, ir_graph *irg, ir_node *block,
1108                        ir_node *store, int arity, ir_node *in[]);
1109 ir_node *new_rd_Raise  (dbg_info *db, ir_graph *irg, ir_node *block,
1110                        ir_node *store, ir_node *obj);
1111 ir_node *new_rd_Const  (dbg_info *db, ir_graph *irg, ir_node *block,
1112                        ir_mode *mode, tarval *con);
1113 ir_node *new_rd_SymConst (dbg_info *db, ir_graph *irg, ir_node *block,
1114                        type_or_id_p value, symconst_kind symkind);
1115 ir_node *new_rd_Sel    (dbg_info *db, ir_graph *irg, ir_node *block, ir_node *store,
1116                        ir_node *objptr, int n_index, ir_node *index[],
1117                        entity *ent);
1118 ir_node *new_rd_Call   (dbg_info *db, ir_graph *irg, ir_node *block, ir_node *store,
1119                        ir_node *callee, int arity, ir_node *in[],
1120                        type *tp);
1121 ir_node *new_rd_Add    (dbg_info *db, ir_graph *irg, ir_node *block,
1122                        ir_node *op1, ir_node *op2, ir_mode *mode);
1123 ir_node *new_rd_Sub    (dbg_info *db, ir_graph *irg, ir_node *block,
1124                        ir_node *op1, ir_node *op2, ir_mode *mode);
1125 ir_node *new_rd_Minus  (dbg_info *db, ir_graph *irg, ir_node *block,
1126                        ir_node *op,  ir_mode *mode);
1127 ir_node *new_rd_Mul    (dbg_info *db, ir_graph *irg, ir_node *block,
1128                        ir_node *op1, ir_node *op2, ir_mode *mode);
1129 ir_node *new_rd_Quot   (dbg_info *db, ir_graph *irg, ir_node *block,
1130                        ir_node *memop, ir_node *op1, ir_node *op2);
1131 ir_node *new_rd_DivMod (dbg_info *db, ir_graph *irg, ir_node *block,
1132                        ir_node *memop, ir_node *op1, ir_node *op2);
1133 ir_node *new_rd_Div    (dbg_info *db, ir_graph *irg, ir_node *block,
1134                        ir_node *memop, ir_node *op1, ir_node *op2);
1135 ir_node *new_rd_Mod    (dbg_info *db, ir_graph *irg, ir_node *block,
1136                        ir_node *memop, ir_node *op1, ir_node *op2);
1137 ir_node *new_rd_Abs    (dbg_info *db, ir_graph *irg, ir_node *block,
1138                        ir_node *op, ir_mode *mode);
1139 ir_node *new_rd_And    (dbg_info *db, ir_graph *irg, ir_node *block,
1140                        ir_node *op1, ir_node *op2, ir_mode *mode);
1141 ir_node *new_rd_Or     (dbg_info *db, ir_graph *irg, ir_node *block,
1142                        ir_node *op1, ir_node *op2, ir_mode *mode);
1143 ir_node *new_rd_Eor    (dbg_info *db, ir_graph *irg, ir_node *block,
1144                        ir_node *op1, ir_node *op2, ir_mode *mode);
1145 ir_node *new_rd_Not    (dbg_info *db, ir_graph *irg, ir_node *block,
1146                        ir_node *op, ir_mode *mode);
1147 ir_node *new_rd_Cmp    (dbg_info *db, ir_graph *irg, ir_node *block,
1148                        ir_node *op1, ir_node *op2);
1149 ir_node *new_rd_Shl    (dbg_info *db, ir_graph *irg, ir_node *block,
1150                        ir_node *op, ir_node *k, ir_mode *mode);
1151 ir_node *new_rd_Shr    (dbg_info *db, ir_graph *irg, ir_node *block,
1152                        ir_node *op, ir_node *k, ir_mode *mode);
1153 ir_node *new_rd_Shrs   (dbg_info *db, ir_graph *irg, ir_node *block,
1154                        ir_node *op, ir_node *k, ir_mode *mode);
1155 ir_node *new_rd_Rot    (dbg_info *db, ir_graph *irg, ir_node *block,
1156                        ir_node *op, ir_node *k, ir_mode *mode);
1157 ir_node *new_rd_Conv   (dbg_info *db, ir_graph *irg, ir_node *block,
1158                        ir_node *op, ir_mode *mode);
1159 ir_node *new_rd_Cast   (dbg_info* db, ir_graph *irg, ir_node *block,
1160                        ir_node *op, type *to_tp);
1161 ir_node *new_rd_Phi    (dbg_info *db, ir_graph *irg, ir_node *block, int arity,
1162                        ir_node *in[], ir_mode *mode);
1163 ir_node *new_rd_Load   (dbg_info *db, ir_graph *irg, ir_node *block,
1164                        ir_node *store, ir_node *adr);
1165 ir_node *new_rd_Store  (dbg_info *db, ir_graph *irg, ir_node *block,
1166                        ir_node *store, ir_node *adr, ir_node *val);
1167 ir_node *new_rd_Alloc  (dbg_info *db, ir_graph *irg, ir_node *block, ir_node *store,
1168                        ir_node *size, type *alloc_type, where_alloc where);
1169 ir_node *new_rd_Free   (dbg_info *db, ir_graph *irg, ir_node *block, ir_node *store,
1170                        ir_node *ptr, ir_node *size, type *free_type);
1171 ir_node *new_rd_Sync   (dbg_info *db, ir_graph *irg, ir_node *block, int arity, ir_node *in[]);
1172 ir_node *new_rd_Proj   (dbg_info *db, ir_graph *irg, ir_node *block, ir_node *arg,
1173                        ir_mode *mode, long proj);
1174 ir_node *new_rd_defaultProj (dbg_info *db, ir_graph *irg, ir_node *block, ir_node *arg,
1175                             long max_proj);
1176 ir_node *new_rd_Tuple  (dbg_info *db, ir_graph *irg, ir_node *block,
1177                        int arity, ir_node *in[]);
1178 ir_node *new_rd_Id     (dbg_info *db, ir_graph *irg, ir_node *block,
1179                        ir_node *val, ir_mode *mode);
1180 ir_node *new_rd_Bad    (ir_graph *irg);
1181 ir_node *new_rd_Unknown(ir_graph *irg);
1182 ir_node *new_rd_CallBegin(dbg_info *db, ir_graph *irg, ir_node *block, ir_node *callee);
1183 ir_node *new_rd_EndReg (dbg_info *db, ir_graph *irg, ir_node *block);
1184 ir_node *new_rd_EndExcept(dbg_info *db, ir_graph *irg, ir_node *block);
1185 ir_node *new_rd_Break  (dbg_info *db, ir_graph *irg, ir_node *block);
1186 ir_node *new_rd_Filter (dbg_info *db, ir_graph *irg, ir_node *block, ir_node *arg,
1187                        ir_mode *mode, long proj);
1188
1189 /*-------------------------------------------------------------------------*/
1190 /* The raw interface without debug support                                 */
1191 /*-------------------------------------------------------------------------*/
1192
1193 /* Constructs a Block with a fixed number of predecessors.
1194    Does not set current_block.  Can not be used with automatic
1195    Phi node costruction. */
1196 ir_node *new_r_Block  (ir_graph *irg,  int arity, ir_node *in[]);
1197 ir_node *new_r_Start  (ir_graph *irg, ir_node *block);
1198 ir_node *new_r_End    (ir_graph *irg, ir_node *block);
1199 ir_node *new_r_Jmp    (ir_graph *irg, ir_node *block);
1200 ir_node *new_r_Cond   (ir_graph *irg, ir_node *block, ir_node *c);
1201 ir_node *new_r_Return (ir_graph *irg, ir_node *block,
1202                        ir_node *store, int arity, ir_node *in[]);
1203 ir_node *new_r_Raise  (ir_graph *irg, ir_node *block,
1204                        ir_node *store, ir_node *obj);
1205 ir_node *new_r_Const  (ir_graph *irg, ir_node *block,
1206                        ir_mode *mode, tarval *con);
1207 ir_node *new_r_SymConst (ir_graph *irg, ir_node *block,
1208                        type_or_id_p value, symconst_kind symkind);
1209 ir_node *new_r_Sel    (ir_graph *irg, ir_node *block, ir_node *store,
1210                        ir_node *objptr, int n_index, ir_node *index[],
1211                        entity *ent);
1212 ir_node *new_r_Call   (ir_graph *irg, ir_node *block, ir_node *store,
1213                        ir_node *callee, int arity, ir_node *in[],
1214                        type *tp);
1215 ir_node *new_r_Add    (ir_graph *irg, ir_node *block,
1216                        ir_node *op1, ir_node *op2, ir_mode *mode);
1217 ir_node *new_r_Sub    (ir_graph *irg, ir_node *block,
1218                        ir_node *op1, ir_node *op2, ir_mode *mode);
1219 ir_node *new_r_Minus  (ir_graph *irg, ir_node *block,
1220                        ir_node *op,  ir_mode *mode);
1221 ir_node *new_r_Mul    (ir_graph *irg, ir_node *block,
1222                        ir_node *op1, ir_node *op2, ir_mode *mode);
1223 ir_node *new_r_Quot   (ir_graph *irg, ir_node *block,
1224                        ir_node *memop, ir_node *op1, ir_node *op2);
1225 ir_node *new_r_DivMod (ir_graph *irg, ir_node *block,
1226                        ir_node *memop, ir_node *op1, ir_node *op2);
1227 ir_node *new_r_Div    (ir_graph *irg, ir_node *block,
1228                        ir_node *memop, ir_node *op1, ir_node *op2);
1229 ir_node *new_r_Mod    (ir_graph *irg, ir_node *block,
1230                        ir_node *memop, ir_node *op1, ir_node *op2);
1231 ir_node *new_r_Abs    (ir_graph *irg, ir_node *block,
1232                        ir_node *op, ir_mode *mode);
1233 ir_node *new_r_And    (ir_graph *irg, ir_node *block,
1234                        ir_node *op1, ir_node *op2, ir_mode *mode);
1235 ir_node *new_r_Or     (ir_graph *irg, ir_node *block,
1236                        ir_node *op1, ir_node *op2, ir_mode *mode);
1237 ir_node *new_r_Eor    (ir_graph *irg, ir_node *block,
1238                        ir_node *op1, ir_node *op2, ir_mode *mode);
1239 ir_node *new_r_Not    (ir_graph *irg, ir_node *block,
1240                        ir_node *op, ir_mode *mode);
1241 ir_node *new_r_Cmp    (ir_graph *irg, ir_node *block,
1242                        ir_node *op1, ir_node *op2);
1243 ir_node *new_r_Shl    (ir_graph *irg, ir_node *block,
1244                        ir_node *op, ir_node *k, ir_mode *mode);
1245 ir_node *new_r_Shr    (ir_graph *irg, ir_node *block,
1246                        ir_node *op, ir_node *k, ir_mode *mode);
1247 ir_node *new_r_Shrs   (ir_graph *irg, ir_node *block,
1248                        ir_node *op, ir_node *k, ir_mode *mode);
1249 ir_node *new_r_Rot    (ir_graph *irg, ir_node *block,
1250                        ir_node *op, ir_node *k, ir_mode *mode);
1251 ir_node *new_r_Conv   (ir_graph *irg, ir_node *block,
1252                        ir_node *op, ir_mode *mode);
1253 ir_node *new_r_Cast   (ir_graph *irg, ir_node *block,
1254                        ir_node *op, type *to_tp);
1255 ir_node *new_r_Phi    (ir_graph *irg, ir_node *block, int arity,
1256                        ir_node *in[], ir_mode *mode);
1257 ir_node *new_r_Load   (ir_graph *irg, ir_node *block,
1258                        ir_node *store, ir_node *adr);
1259 ir_node *new_r_Store  (ir_graph *irg, ir_node *block,
1260                        ir_node *store, ir_node *adr, ir_node *val);
1261 ir_node *new_r_Alloc  (ir_graph *irg, ir_node *block, ir_node *store,
1262                        ir_node *size, type *alloc_type, where_alloc where);
1263 ir_node *new_r_Free   (ir_graph *irg, ir_node *block, ir_node *store,
1264                        ir_node *ptr, ir_node *size, type *free_type);
1265 ir_node *new_r_Sync   (ir_graph *irg, ir_node *block, int arity, ir_node *in[]);
1266 ir_node *new_r_Proj   (ir_graph *irg, ir_node *block, ir_node *arg,
1267                        ir_mode *mode, long proj);
1268 ir_node *new_r_defaultProj (ir_graph *irg, ir_node *block, ir_node *arg,
1269                             long max_proj);
1270 ir_node *new_r_Tuple  (ir_graph *irg, ir_node *block,
1271                        int arity, ir_node *in[]);
1272 ir_node *new_r_Id     (ir_graph *irg, ir_node *block,
1273                        ir_node *val, ir_mode *mode);
1274 ir_node *new_r_Bad    (ir_graph *irg);
1275 ir_node *new_r_Unknown(ir_graph *irg);
1276 ir_node *new_r_CallBegin(ir_graph *irg, ir_node *block, ir_node *callee);
1277 ir_node *new_r_EndReg (ir_graph *irg, ir_node *block);
1278 ir_node *new_r_EndExcept(ir_graph *irg, ir_node *block);
1279 ir_node *new_r_Break  (ir_graph *irg, ir_node *block);
1280 ir_node *new_r_Filter (ir_graph *irg, ir_node *block, ir_node *arg,
1281                        ir_mode *mode, long proj);
1282
1283 /*-----------------------------------------------------------------------*/
1284 /* The block oriented interface                                          */
1285 /*-----------------------------------------------------------------------*/
1286
1287 /** Sets the current block in which the following constructors place the
1288    nodes they construct. */
1289 void switch_block (ir_node *target);
1290
1291 /* Constructs a Block with a fixed number of predecessors.
1292    Does set current_block.  Can be used with automatic Phi
1293    node construction. */
1294
1295
1296 ir_node *new_d_Block(dbg_info* db, int arity, ir_node *in[]);
1297 ir_node *new_d_Start  (dbg_info* db);
1298 ir_node *new_d_End    (dbg_info* db);
1299 ir_node *new_d_Jmp    (dbg_info* db);
1300 ir_node *new_d_Cond   (dbg_info* db, ir_node *c);
1301 ir_node *new_d_Return (dbg_info* db, ir_node *store, int arity, ir_node *in[]);
1302 ir_node *new_d_Raise  (dbg_info* db, ir_node *store, ir_node *obj);
1303 ir_node *new_d_Const  (dbg_info* db, ir_mode *mode, tarval *con);
1304 ir_node *new_d_SymConst (dbg_info* db, type_or_id_p value, symconst_kind kind);
1305 ir_node *new_d_simpleSel(dbg_info* db, ir_node *store, ir_node *objptr, entity *ent);
1306 ir_node *new_d_Sel    (dbg_info* db, ir_node *store, ir_node *objptr, int arity, ir_node *in[],
1307                      entity *ent);
1308 ir_node *new_d_Call   (dbg_info* db, ir_node *store, ir_node *callee, int arity, ir_node *in[],
1309                      type *tp);
1310 ir_node *new_d_Add    (dbg_info* db, ir_node *op1, ir_node *op2, ir_mode *mode);
1311 ir_node *new_d_Sub    (dbg_info* db, ir_node *op1, ir_node *op2, ir_mode *mode);
1312 ir_node *new_d_Minus  (dbg_info* db, ir_node *op,  ir_mode *mode);
1313 ir_node *new_d_Mul    (dbg_info* db, ir_node *op1, ir_node *op2, ir_mode *mode);
1314 ir_node *new_d_Quot   (dbg_info* db, ir_node *memop, ir_node *op1, ir_node *op2);
1315 ir_node *new_d_DivMod (dbg_info* db, ir_node *memop, ir_node *op1, ir_node *op2);
1316 ir_node *new_d_Div    (dbg_info* db, ir_node *memop, ir_node *op1, ir_node *op2);
1317 ir_node *new_d_Mod    (dbg_info* db, ir_node *memop, ir_node *op1, ir_node *op2);
1318 ir_node *new_d_Abs    (dbg_info* db, ir_node *op,                ir_mode *mode);
1319 ir_node *new_d_And    (dbg_info* db, ir_node *op1, ir_node *op2, ir_mode *mode);
1320 ir_node *new_d_Or     (dbg_info* db, ir_node *op1, ir_node *op2, ir_mode *mode);
1321 ir_node *new_d_Eor    (dbg_info* db, ir_node *op1, ir_node *op2, ir_mode *mode);
1322 ir_node *new_d_Not    (dbg_info* db, ir_node *op,                ir_mode *mode);
1323 ir_node *new_d_Shl    (dbg_info* db, ir_node *op,  ir_node *k,   ir_mode *mode);
1324 ir_node *new_d_Shr    (dbg_info* db, ir_node *op,  ir_node *k,   ir_mode *mode);
1325 ir_node *new_d_Shrs   (dbg_info* db, ir_node *op,  ir_node *k,   ir_mode *mode);
1326 ir_node *new_d_Rot    (dbg_info* db, ir_node *op,  ir_node *k,   ir_mode *mode);
1327 ir_node *new_d_Cmp    (dbg_info* db, ir_node *op1, ir_node *op2);
1328 ir_node *new_d_Conv   (dbg_info* db, ir_node *op, ir_mode *mode);
1329 ir_node *new_d_Cast   (dbg_info* db, ir_node *op, type *to_tp);
1330 ir_node *new_d_Phi    (dbg_info* db, int arity, ir_node *in[], ir_mode *mode);
1331 ir_node *new_d_Load   (dbg_info* db, ir_node *store, ir_node *addr);
1332 ir_node *new_d_Store  (dbg_info* db, ir_node *store, ir_node *addr, ir_node *val);
1333 ir_node *new_d_Alloc  (dbg_info* db, ir_node *store, ir_node *size, type *alloc_type,
1334                      where_alloc where);
1335 ir_node *new_d_Free   (dbg_info* db, ir_node *store, ir_node *ptr, ir_node *size,
1336                      type *free_type);
1337 ir_node *new_d_Sync   (dbg_info* db, int arity, ir_node *in[]);
1338 ir_node *new_d_Proj   (dbg_info* db, ir_node *arg, ir_mode *mode, long proj);
1339 ir_node *new_d_defaultProj (dbg_info* db, ir_node *arg, long max_proj);
1340 ir_node *new_d_Tuple  (dbg_info* db, int arity, ir_node *in[]);
1341 ir_node *new_d_Id     (dbg_info* db, ir_node *val, ir_mode *mode);
1342 ir_node *new_d_Bad    (void);
1343 ir_node *new_d_Unknown(void);
1344 ir_node *new_d_CallBegin(dbg_info *db, ir_node *callee);
1345 ir_node *new_d_EndReg (dbg_info *db);
1346 ir_node *new_d_EndExcept(dbg_info *db);
1347 ir_node *new_d_Break (dbg_info *db);
1348 ir_node *new_d_Filter (dbg_info *db, ir_node *arg, ir_mode *mode, long proj);
1349
1350 /*-----------------------------------------------------------------------*/
1351 /* The block oriented interface without debug support                    */
1352 /*-----------------------------------------------------------------------*/
1353
1354 /* Needed from the interfase with debug support:
1355 void switch_block (ir_node *target);   */
1356
1357 /* Constructs a Block with a fixed number of predecessors.
1358    Does set current_block.  Can be used with automatic Phi
1359    node construction. */
1360 ir_node *new_Block(int arity, ir_node *in[]);
1361 ir_node *new_Start  (void);
1362 ir_node *new_End    (void);
1363 ir_node *new_EndReg (void);
1364 ir_node *new_EndExcept(void);
1365 ir_node *new_Jmp    (void);
1366 ir_node *new_Break  (void);
1367 ir_node *new_Cond   (ir_node *c);
1368 ir_node *new_Return (ir_node *store, int arity, ir_node *in[]);
1369 ir_node *new_Raise  (ir_node *store, ir_node *obj);
1370 ir_node *new_Const  (ir_mode *mode, tarval *con);
1371 ir_node *new_SymConst (type_or_id_p value, symconst_kind kind);
1372 ir_node *new_simpleSel(ir_node *store, ir_node *objptr, entity *ent);
1373 ir_node *new_Sel    (ir_node *store, ir_node *objptr, int arity, ir_node *in[],
1374                      entity *ent);
1375 ir_node *new_InstOf (ir_node *store, ir_node *objptr, type *ent);
1376 ir_node *new_Call   (ir_node *store, ir_node *callee, int arity, ir_node *in[],
1377                      type *tp);
1378 ir_node *new_CallBegin(ir_node *callee);
1379 ir_node *new_Add    (ir_node *op1, ir_node *op2, ir_mode *mode);
1380 ir_node *new_Sub    (ir_node *op1, ir_node *op2, ir_mode *mode);
1381 ir_node *new_Minus  (ir_node *op,  ir_mode *mode);
1382 ir_node *new_Mul    (ir_node *op1, ir_node *op2, ir_mode *mode);
1383 ir_node *new_Quot   (ir_node *memop, ir_node *op1, ir_node *op2);
1384 ir_node *new_DivMod (ir_node *memop, ir_node *op1, ir_node *op2);
1385 ir_node *new_Div    (ir_node *memop, ir_node *op1, ir_node *op2);
1386 ir_node *new_Mod    (ir_node *memop, ir_node *op1, ir_node *op2);
1387 ir_node *new_Abs    (ir_node *op,                ir_mode *mode);
1388 ir_node *new_And    (ir_node *op1, ir_node *op2, ir_mode *mode);
1389 ir_node *new_Or     (ir_node *op1, ir_node *op2, ir_mode *mode);
1390 ir_node *new_Eor    (ir_node *op1, ir_node *op2, ir_mode *mode);
1391 ir_node *new_Not    (ir_node *op,                ir_mode *mode);
1392 ir_node *new_Shl    (ir_node *op,  ir_node *k,   ir_mode *mode);
1393 ir_node *new_Shr    (ir_node *op,  ir_node *k,   ir_mode *mode);
1394 ir_node *new_Shrs   (ir_node *op,  ir_node *k,   ir_mode *mode);
1395 ir_node *new_Rot    (ir_node *op,  ir_node *k,   ir_mode *mode);
1396 ir_node *new_Cmp    (ir_node *op1, ir_node *op2);
1397 ir_node *new_Conv   (ir_node *op, ir_mode *mode);
1398 ir_node *new_Cast   (ir_node *op, type *to_tp);
1399 ir_node *new_Phi    (int arity, ir_node *in[], ir_mode *mode);
1400 ir_node *new_Load   (ir_node *store, ir_node *addr);
1401 ir_node *new_Store  (ir_node *store, ir_node *addr, ir_node *val);
1402 ir_node *new_Alloc  (ir_node *store, ir_node *size, type *alloc_type,
1403                      where_alloc where);
1404 ir_node *new_Free   (ir_node *store, ir_node *ptr, ir_node *size,
1405                      type *free_type);
1406 ir_node *new_Sync   (int arity, ir_node *in[]);
1407 ir_node *new_Proj   (ir_node *arg, ir_mode *mode, long proj);
1408 ir_node *new_Filter (ir_node *arg, ir_mode *mode, long proj);
1409 ir_node *new_defaultProj (ir_node *arg, long max_proj);
1410 ir_node *new_Tuple  (int arity, ir_node *in[]);
1411 ir_node *new_Id     (ir_node *val, ir_mode *mode);
1412 ir_node *new_Bad    (void);
1413 ir_node *new_Unknown(void);
1414
1415 /*---------------------------------------------------------------------*/
1416 /* The comfortable interface.                                          */
1417 /* Supports automatic Phi node construction.                           */
1418 /* All routines of the block oriented interface except new_Block are   */
1419 /* needed also.                                                        */
1420 /*---------------------------------------------------------------------*/
1421
1422 /* --- Block construction --- */
1423 /* immature Block without predecessors */
1424 ir_node *new_d_immBlock (dbg_info* db);
1425 ir_node *new_immBlock (void);
1426
1427 /** Add a control flow edge to an immature block. */
1428 void add_in_edge (ir_node *immblock, ir_node *jmp);
1429
1430 /** fixes the number of predecessors of a block. */
1431 void mature_block (ir_node *block);
1432
1433 /* --- Parameter administration --- */
1434 /* Read a value from the array with the local variables.  Use this
1435    function to obtain the last definition of the value associated with
1436    pos.  Pos may not exceed the value passed as n_loc to new_ir_graph. */
1437 ir_node *get_d_value (dbg_info* db, int pos, ir_mode *mode);
1438 ir_node *get_value (int pos, ir_mode *mode);
1439
1440 /** Write a value in the array with the local variables. Use this function
1441    to remember a new definition of the value associated with pos. Pos may
1442    not exceed the value passed as n_loc to new_ir_graph. */
1443 void set_value (int pos, ir_node *value);
1444
1445 /** Read a store.
1446    Use this function to get the most recent version of the store (type M).
1447    Internally it does the same as get_value. */
1448 ir_node *get_store (void);
1449
1450 /** Write a store. */
1451 void set_store (ir_node *store);
1452
1453 /** keep this node alive even if End is not control-reachable from it */
1454 void keep_alive (ir_node *ka);
1455
1456 /* --- Useful access routines --- */
1457 /** Returns the current block of the current graph.  To set the current
1458    block use switch_block(). */
1459 ir_node *get_cur_block(void);
1460
1461 /** Returns the frame type of the current graph */
1462 type *get_cur_frame_type(void);
1463
1464
1465 /* --- initialize and finalize ir construction --- */
1466
1467 /** Puts the graph into state "phase_high" */
1468 void finalize_cons (ir_graph *irg);
1469
1470 /* --- Initialization --- */
1471
1472 /**
1473  * This function is called, whenever a local variable is used before definition
1474  *
1475  * @parameter mode      the mode of the local var
1476  * @pos                 position choosen be the frontend for this var
1477  *
1478  * @return a firm node of mode @p mode that initialises the var at position pos
1479  *
1480  * @note
1481  *      Do not return NULL
1482  *      If this function is not set, FIRM will create a const node with tarval BAD
1483  */
1484 typedef ir_node *default_initialize_local_variable_func_t(ir_mode *mode, int pos);
1485
1486 /**
1487  * Initializes the graph construction.
1488  *
1489  * @param func  @see default_initialize_local_variable_func_t
1490  */
1491 void init_cons (default_initialize_local_variable_func_t *func);
1492
1493 # endif /* _IRCONS_H_ */