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