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