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