Initial revision
[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
11 /** !!!
12 *** Ideas for improvement:
13 ***
14  Handle construction of exceptions more comfortable:
15  Add new constructors that pass the exception region (or better the
16  Phi for the memories, the ex. region can be found from there) as parameter,
17  constructor then adds all Proj nodes and returns the pointer
18  to the Proj node that selects the result of the arithmetic operation.
19
20  Maybe hide the exception region in a global variable, especially if
21  it is always unambiguous.
22 **/
23
24
25 /**
26 ***  IRCONS
27
28   This file documents all datatypes and constructors needed to
29   build a FIRM representation of a pocedure.  The constructors are
30   also implemented in this file.
31
32   The documentation also gives a short manual how to use the library.
33
34   For extensive documentation of FIRM see UKA Techreport 1999-14.
35
36   DATATYPES
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 the
66                      procedure as output.  This is the Proj node on the third
67                      output of the start node.  This output of the start node
68                      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 _all_
75                      global things are held.  Select from this pointer with a Sel
76                      node the pointer to a global variable / procedure / compiler
77                      known function... .
78
79     *args            The ir_node that produces the arguments of the method as it's
80                      result.  This is a Proj node on the fourth output of the start
81                      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 one
91                      of the node constructors (new_<opcode>) are assigned to this
92                      block.  It can be set with switch_block(block).  Only needed
93                      for ir construction.
94
95     params/n_loc     An int giving the number of local variables in this procedure.
96                      This is neede for ir construction. Name will be changed.
97
98     *value_table     This pset is used for global value numbering for optimizing
99                      use in iropt.c.
100
101     *Phi_in_stack;   a stack needed for automatic Phi construction, needed only
102                      during ir construction.
103
104
105   Three kinds of nodes
106   --------------------
107
108     There are three kinds of nodes known to the ir:  enties,
109     types, and ir_nodes
110
111     + ir_nodes are the actual nodes of the FIRM intermediate representation.
112       They represent operations on the data of the program and control flow
113       operations.
114
115     + entity ==> implemented in entity.h
116       Refers to a single entity of the compiled program, e.g. a field of a class or
117       a method.
118
119     + types ==> implemented in type.h
120       With types type information is represented.  There are several type nodes.
121
122   Implementation of the FIRM operations: ir_node
123   ----------------------------------------------
124
125     Ir_nodes represent operations on the data of the program and control flow
126     operations.  Examples of ir_nodes:  Add, Jmp, Cmp
127
128     FIRM is a dataflow graph.  A dataflow graph is a directed graph,
129     so that every node has incoming and outgoing edges.  A node is
130     executable if every input at it's incoming edges is available.
131     Execution of the dataflow graph is started at the Start node which
132     has no incoming edges and ends when the End node executes, even if
133     there are still executable or not executed nodes.  (Is this true,
134     or must all executable nodes be executed?)  (There are exceptions
135     to the dataflow paradigma that all inputs have to be available
136     before a node can execute: Phi, Block.  See UKA Techreport
137     1999-14.)
138
139     The implementation of FIRM differs from the view as a dataflow
140     graph.  To allow fast traversion of the graph edges are
141     implemented as C-pointers.  Inputs to nodes are not ambiguous, the
142     results can be used by several other nodes.  Each input can be
143     implemented as a single pointer to a predecessor node, outputs
144     need to be lists of pointers to successors.  Therefore a node
145     contains pointers to it's predecessor so that the implementation is a
146     dataflow graph with reversed edges.  It has to be traversed bottom
147     up.
148
149     All nodes of the ir have the same basic structure.  They are
150     distinguished by a field containing the opcode.
151
152     The fields of an ir_node:
153
154     kind             A firm_kind tag containing k_ir_node.  This is useful for
155                      dynamically checking the type of a node.
156
157     *op              This ir_op gives the opcode as a tag and a string
158                      and the number of attributes of an ir_node.  There is
159                      one statically allocated struct ir_op for each opcode.
160
161     *mode            The ir_mode of the operation represented by this firm node.
162                      The mode of the operation is the mode of it's result.  A Firm
163                      mode is a datatype as known to the target, not a type of the
164                      source language.
165
166     visit            A flag for traversing the ir.
167
168     **in             An array with pointers to the node's predecessors.
169
170     *link            A pointer to an ir_node.  With this pointer all Phi nodes
171                      are attached to a Block, i.e., a Block points to it's
172                      first Phi node, this node points to the second Phi node
173                      in the Block and so fourth.  Used in mature_block
174                      to find all Phi nodes to be matured.  It's also used to
175                      annotate a node with a better, optimized version of it.
176
177     attr             An attr struct containing the attributes of the nodes. The
178                      attributes depend on the opcode of the node.  The number of
179                      these attributes is given in op.
180
181   The struct ir_op
182   ----------------
183                      Not yet documented. See irop.h.
184
185   The struct ir_mode
186   ------------------
187                      Not yet documented. See irmode.h.
188
189   GLOBAL VARIABLES
190   ================
191
192   current_ir_graph   Points to the current ir_graph.  All constructors for nodes
193                      add nodes to this graph.
194
195   ir_visited         A int used as flag to traverse the ir_graph.
196
197   block_visited      A int used as a flag to traverse block nodes in the graph.
198
199                      Others not yet documented.
200
201
202
203
204   CONSTRUCTOR FOR IR_GRAPH
205   ========================
206
207   ir_graph *new_ir_graph (entity *ent, int params);
208   -------------------------------------------------
209
210   This constructor generates the basic infrastructure needed to
211   represent a procedure in FIRM.
212
213   The parameters of new_ir_graph are:
214
215     *ent             A pointer to an entity representing the procedure.
216
217     params           An integer giving the number of local variables in the
218                      procedure.
219
220   It allocates an ir_graph and sets current_ir_graph to point to this
221   graph.  Further it allocates the following nodes needed for every
222   procedure:
223
224   * The start block containing a start node and Proj nodes for it's
225     four results (X, M, P, T).
226   * The end block containing an end node. This block is not matured
227     after executing new_ir_graph as predecessors need to be added to it.
228     (Maturing a block means fixing it's number of predecessors.)
229   * The current block, which is empty and also not matured.
230
231   Further it enters the global store into the datastructure of the start
232   block that contanis all valid values in this block (set_store()).  This
233   datastructure is used to build the Phi nodes and removed after completion
234   of the graph.
235   There is no path from end to start in the graph after calling ir_graph.
236
237
238   IR_NODES AND CONSTRUCTORS FOR IR_NODES
239   =======================================
240
241   All ir_nodes are defined by a common data structure.  They are distinguished
242   by their opcode and differ in the number of their attributes.
243
244   The constructor for the block node sets current_block to itself.
245   Const nodes are always added to the start block.
246   All other constructors add the created node to the current_block.
247   swich_block(block) allows to set the current block to block.
248
249   Watch for my inconsistent use of input and predecessor (dataflow view)
250   and `the node points to' (implementation view).
251
252   The following description of the nodes lists four properties them if these are
253   of interest:
254    - the parameters to the constructor
255    - the inputs of the Firm node
256    - the outputs of the Firm node
257    - attributes to the node
258
259
260   BASIC BLOCKS
261   ------------
262
263   ir_node *new_Block (void)
264   --------------------------
265
266   Creates a new block.  Sets current_block to itself.  When a new block is
267   created it cannot be known how many predecessors this block will have in the
268   control flow graph. Therefore the list of inputs can not be fixed at
269   creation.  Predecessors can be added with add_in_edge (block, control flow
270   operation).  With every added predecessor the number of inputs to Phi nodes
271   also changes.
272
273   The block can be completed by mature_block(block) if all predecessors are
274   known.  If several blocks are built at once, mature_block can only be called
275   after set_value has been called for all values that are life at the end
276   of the block.  This is necessary so that Phi nodes created by mature_block
277   get the right predecessors in case of cyclic dependencies.  If all set_values
278   of this block are called after maturing it and before calling get_value
279   in some block that is control flow dependent on this block, the construction
280   is correct.
281   Example for faulty ir construction:
282     block_before_loop = new_block();
283     set_value(x);
284     mature_block(block_before_loop);
285     before2header = new_Jmp;
286
287     loop_header = new_block ();
288     header2body - new_Jmp();
289
290     loop_body = new_block ();
291     body2header = new_Jmp();
292
293     add_in_edge(loop_header, before2header);
294     add_in_edge(loop_header, body2header);
295     add_in_edge(loop_body, header2body);
296
297     mature_block(loop_header);
298     mature_block(loop_body);
299
300     get_value(loop_body, x);   // gets the Phi in loop_header
301     set_value(loop_header, x); // sets the value the above get_value should
302                                // have returned!!!
303   Mature_block also fixes the number of inputs to the Phi nodes.  Mature_block
304   should be called as early as possible, as afterwards the generation of Phi
305   nodes is more efficient.
306
307   Inputs:
308     There is an input for each control flow predecessor of the block.
309     The input points to an instruction producing an output of type X.
310     Possible predecessors:  Start, Jmp, Cond, Raise or Return or any node
311     possibly causing an exception.  (Often the real predecessors are Projs.)
312   Output:
313     Mode R, all nodes belonging to this block should consume this output.
314     As they are strict (except Block and Phi node) it is a necessary condition
315     that the block node executed before any other node in this block
316     executes.
317   Attributes:
318     block.matured  Indicates whether the block is mature.
319     block.closed   ???
320     block.**graph_arr
321                     This attribute contains all local values valid in this
322                     block. This is needed to build the Phi nodes and removed
323                     if the graph is complete.
324
325
326   CONTROL FLOW OPERATIONS
327   -----------------------
328
329   In each block there must be exactly one of the control flow
330   operations Start, End, Jmp, Cond, Return or Raise.  The output of a
331   control flow operation points to the block to be executed next.
332
333   ir_node *new_Start (void)
334   -------------------------
335
336   Creates a start node.  Not actually needed public.  Created
337   by new_ir_graph.
338
339   Inputs:
340     No inputs except the block it belogns to.
341   Output:
342     A tuple of 4 (5, 6) distinct values. These are labeled by the following
343     projection numbers (pns_number):
344     * pns_initial_exec
345                      mode X, points to the first block to be executed.
346     * pns_global_store
347                      mode M, the global store
348     * pns_frame_base mode P, a pointer to the base of the procedures stack frame.
349     * pns_globals    mode P, a pointer to the part of the memory containing _all_
350                              global things.
351     * pns_args       mode T, a tuple containing all arguments of the procedure.
352
353
354   ir_node *new_End (void)
355   -----------------------
356
357   Creates an end node.  Not actually needed public.  Created by
358   new_ir_graph.
359
360   Inputs:
361     No inputs except the block it belogns to.
362   Output:
363     No output.
364
365   ir_node *new_Jmp (void)
366   -----------------------
367
368   Creates a Jmp node.
369
370   Inputs:
371     The block the node belongs to
372   Output:
373     Control flow to the next block.
374
375   ir_node *new_Cond (ir_node *c)
376   ------------------------------
377
378   Creates a Cond node.  There are two versions of this node.
379
380   The Boolean Cond:
381   Input:
382     A value of mode b.
383   Output:
384     A tuple of two control flows.  The first is taken if the input is
385     false, the second if it is true.
386
387   The Switch Cond:
388   Input:
389     A value of mode I_u. (i)
390   Output:
391     A tuple of n control flows.  If the Cond's input is i, control
392     flow will procede along output i. If the input is >= n control
393     flow proceeds along output n.
394
395   ir_node *new_Return (in_node *store, int arity, ir_node **in)
396   -------------------------------------------------------------
397
398   The return node has as inputs the results of the procedure.  It
399   passes the control flow to the end_block.
400
401   Inputs:
402     The memory state.
403     All results.
404   Output
405     Control flow to the end block.
406
407   ir_node *new_Raise (ir_node *store, ir_node *obj)
408   -------------------------------------------------
409
410   Raises an exception.  Unconditional change of control flow.  Writes
411   an explicit Except variable to memory to pass it to the exception
412   handler.  See TechReport 1999-14, chapter Exceptions.
413
414   Inputs:
415     The memory state.
416     A pointer to the Except variable.
417   Output:
418     A tuple of control flow and the changed memory state.  The control flow
419     points to the exception handler if it is definied in this procedure,
420     else it points to the end_block.
421
422
423   CONSTANTS
424   ---------
425
426   ir_node *new_Const (ir_mode *mode, tarval *con)
427   -----------------------------------------------
428
429   Creates a constant in the constant table and adds a Const node
430   returning this value to the start block.
431
432   Parameters:
433     *mode            The mode of the constant.
434     *con             Points to an entry in the constant table.
435                      This pointer is added to the attributes of
436                      the node (self->attr.con)
437   Inputs:
438     No inputs except the block it belogns to.
439   Output:
440     The constant value.
441   Attribute:
442     attr.con   A tarval* pointer to the proper entry in the constant
443                table.
444
445   ir_node *new_SymConst (type *type, symconst_kind kind)
446   ------------------------------------------------------------
447
448   There are two kinds of symbolic constants:
449     type_tag  The symbolic constant represents a type tag.
450     size      The symbolic constant represents the size of a class.
451     link_info Information for the linker.
452
453   Parameters
454     kind       The kind of the symbolic constant: type_tag or size.
455     *type      Points to the type the tag stands for or to the type
456                whose size is represented by the constant.
457
458   Inputs:
459     No inputs except the block it belogns to.
460   Output:
461     An unsigned integer (I_u) or a pointer (P).
462
463   Attributes:
464     attr.i.num       The symconst_kind, i.e. one of
465                       - type_tag
466                       - size
467                       - linkage_ptr_info
468       If the attr.i.num is type_tag of size, the node contains an attribute
469     attr.i.*type     A pointer to a type_class.
470       if it is linkage_ptr_info it contains
471     attr.i.*ptrinfo  A ident holding information for the linker.
472
473   THE SELECT NODE
474   ---------------
475
476   ir_node *new_simpleSel (ir_node *store, ir_node *frame, entity *sel)
477   --------------------------------------------------------------------
478
479
480   Selects an entity from a compound type. This entity can be a field or
481   a method.
482
483   Parameters:
484     *store     The memory in which the object the entity should be selected from
485                is allocated.
486     *frame     The pointer to the object.
487     *sel       The entity to select.
488
489   Inputs:
490     The memory containing the object.
491     A pointer to the object.
492     An unsigned integer.
493   Output:
494     A pointer to the selected entity.
495   Attributes:
496     attr.sel   Pointer to the entity
497
498
499   ir_node *new_Sel (ir_node *store, ir_node *frame, int arity, ir_node **in,
500   --------------------------------------------------------------------------
501                     entity *sel)
502                     ------------
503
504   Selects a field from an array type.  The entity has as owner the array, as
505   type the arrays element type.  The indexes to access an array element are
506   given also.
507
508   Parameters:
509     *store     The memory in which the object the entity should be selected from
510                is allocated.
511     *frame     The pointer to the object.
512     *arity     number of array indexes.
513     *in        array with index inputs to the node.
514     *sel       The entity to select.
515
516   Inputs:
517     The memory containing the object.
518     A pointer to the object.
519     As much unsigned integer as there are array expressions.
520   Output:
521     A pointer to the selected entity.
522   Attributes:
523     attr.sel   Pointer to the entity
524
525   The constructors new_Sel and new_simpleSel generate the same ir nodes.
526   simpleSel just sets the arity of the index inputs to zero.
527
528
529   ARITHMETIC OPERATIONS
530   ---------------------
531
532   ir_node *new_Call (ir_node *store, ir_node *callee, int arity, ir_node **in,
533   ----------------------------------------------------------------------------
534                      type_method *type)
535                      ------------------
536
537   Creates a procedure call.
538
539   Parameters
540     *store           The actual store.  Why not also the stack frame?
541     *callee          A pointer to the called procedure.
542     arity            The number of procedure parameters.
543     **in             An array with the pointers to the parameters.
544                      This array is copied in the constructor.
545     *type            Type information of the procedure called.
546
547   Inputs:
548     The store, the callee and the parameters.
549   Output:
550     A tuple containing the eventually changed store and the procedure
551     results.
552   Attributes:
553     attr.call        Contains the type information for the procedure.
554
555   ir_node *new_Add (ir_node *op1, ir_node *op2, ir_mode *mode)
556   ------------------------------------------------------------
557
558   Trivial.
559
560   ir_node *new_Sub (ir_node *op1, ir_node *op2, ir_mode *mode)
561   ------------------------------------------------------------
562
563   Trivial.
564
565   ir_node *new_Minus (ir_node *op, ir_mode *mode)
566   -----------------------------------------------
567
568   This constructor is for unary Minus operations on floating point
569   values.  Such a Minus can trap if it is implemented as a Sub from
570   zero due to rounding errors.
571
572   ir_node *new_Mul (ir_node *op1, ir_node *op2, ir_mode *mode)
573   ------------------------------------------------------------
574
575   Trivial.
576
577   ir_node *new_Quot (ir_node *memop, ir_node *op1, ir_node *op2)
578   --------------------------------------------------------------
579
580   Quot performs exact division of floating point numbers.  It's mode
581   is Tuple, the mode of the result must be annotated to the Proj
582   that extracts the result of the arithmetic operations.
583
584   Inputs:
585     The store needed to model exceptions and the two operands.
586   Output:
587     A tuple contaning a memory and a execution for modeling exceptions
588     and the result of the arithmetic operation.
589
590   ir_node *new_DivMod (ir_node *memop, ir_node *op1, ir_node *op2)
591   ----------------------------------------------------------------
592
593   Performs Div and Mod on interger values.
594
595   Output:
596     A tuple contaning a memory and a execution for modeling exceptions
597     and the two result of the arithmetic operations.
598
599   ir_node *new_Div (ir_node *memop, ir_node *op1, ir_node *op2)
600   -------------------------------------------------------------
601
602   Trivial.
603
604   ir_node *new_Mod (ir_node *memop, ir_node *op1, ir_node *op2)
605   -------------------------------------------------------------
606
607   Trivial.
608
609   ir_node *new_Abs (ir_node *op, ir_mode *mode)
610   ---------------------------------------------
611
612   Trivial.
613
614   ir_node *new_And (ir_node *op1, ir_node *op2, ir_mode *mode)
615   ------------------------------------------------------------
616
617   Trivial.
618
619   ir_node *new_Or (ir_node *op1, ir_node *op2, ir_mode *mode)
620   -----------------------------------------------------------
621
622   Trivial.
623
624   ir_node *new_Eor (ir_node *op1, ir_node *op2, ir_mode *mode)
625   ------------------------------------------------------------
626
627   Trivial.
628
629   ir_node *new_Not (ir_node *op, ir_mode *mode)
630   ---------------------------------------------
631
632   This node constructs a constant where all bits are set to one
633   and a Eor of this constant and the operator.  This simulates a
634   Not operation.
635
636   ir_node *new_Shl (ir_node *op, ir_node *k, ir_mode *mode)
637   ---------------------------------------------------------
638
639   Trivial.
640
641   ir_node *new_Shr (ir_node *op, ir_node *k, ir_mode *mode)
642   ---------------------------------------------------------
643
644   Logic shift right, i.e., zero extended.
645
646
647   ir_node *new_Shrs (ir_node *op, ir_node *k, ir_mode *mode)
648   ----------------------------------------------------------
649
650   Arithmetic shift right, i.e., sign extended.
651
652   ir_node *new_Rot (ir_node *op, ir_node *k, ir_mode *mode)
653   ---------------------------------------------------------
654
655   Rotates the operand to the (right??) by k bits.
656
657   ir_node *new_Conv (ir_node *op, ir_mode *mode)
658   ---------------------------------------------
659
660   Mode conversion.  For allowed conversions see UKA Tech Report
661   1999-14.
662
663   ir_node *new_Cmp (ir_node *op1, ir_node *op2)
664   ---------------------------------------------
665
666   Input:
667     The two values to be compared.
668   Output:
669     A 16-tuple containing the results of the 16 different comparisons.
670     The following is a list giving the comparisons and a projection
671     number (pnc_number) to use in Proj nodes to extract the proper result.
672       False     false
673       Eq        equal
674       Lt        less
675       Le        less or equal
676       Gt        greater
677       Ge        greater of equal
678       Lg        less or greater
679       Leg       less, equal or greater = ordered
680       Uo        unordered
681       Ue        unordered or equal
682       Ul        unordered or less
683       Ule       unordered, less or equal
684       Ug        unordered or greater
685       Uge       unordered, greater or equal
686       Ne        unordered, less or greater = not equal
687       True      true
688
689
690
691   THE PHI NODE
692   ------------
693
694   In general, Phi nodes are automaitcally inserted.  In some cases, if
695   all predecessors of a block are known, an explicit Phi node constructor
696   is needed.  E.g., to construct a FIRM graph for a statement as
697     a = (b==c) ? 2 : 5;
698
699   ir_node *new_Phi (int arity, ir_node **in, ir_mode *mode)
700   ---------------------------------------------------------
701
702   Creates a Phi node. The in's order has to correspond to the order
703   of in's of current_block.  This is not checked by the library!
704
705   Parameter
706     arity            number of predecessors
707     **in             array with predecessors
708     *mode            The mode of it's inputs and output.
709   Inputs:
710     A Phi node has as many inputs as the block it belongs to.
711     Each input points to a definition of the same value on a
712     different path in the control flow.
713   Output
714     The definition valid in this block.
715
716
717   OPERATIONS TO MANAGE MEMORY EXPLICITLY
718   --------------------------------------
719
720   ir_node *new_Load (ir_node *store, ir_node *addr)
721   ----------------------------------------------------------------
722
723   The Load operation reads a value from memory.
724
725   Parameters:
726   *store        The current memory.
727   *addr         A pointer to the variable to be read in this memory.
728   *mode         The mode of the loaded value.
729
730   Inputs:
731     The memory and a pointer to a variable in this memory.
732   Output:
733     A tuple of the memory, a control flow to be taken in case of
734     an exception and the loaded value.
735
736   ir_node *new_Store (ir_node *store, ir_node *addr, ir_node *val)
737   ----------------------------------------------------------------
738
739   The Store operation writes a value to a variable in memory.
740
741   Inputs:
742     The memory, a pointer to a variable in this memory and the value
743     to write to this variable.
744   Output:
745     A tuple of the changed memory and a control flow to be taken in
746     case of an exception.
747
748   ir_node *new_Alloc (ir_node *store, ir_node *size, type *alloc_type,
749   --------------------------------------------------------------------
750                       where_alloc where)
751                       ------------------
752
753   The Alloc node allocates a new variable.  It can be specified whether the
754   variable should be allocated to the stack or to the heap.
755
756   Parameters:
757     *store       The memory which shall contain the new variable.
758     **    *size        The number of bytes to allocate. Old. **
759     *size        We decided that the size easily can be derived from the type.
760                  This field is for allocating arrays, i.e., it gives the multiple
761                  of the size of alloc_type to allocate memory for.
762     *alloc_type  The type of the allocated variable.
763     where        Where to allocate the variable, either heap_alloc or stack_alloc.
764
765   Inputs:
766     A memory and an unsigned integer.
767   Output:
768     A tuple of the changed memory, a control flow to be taken in
769     case of an exception and the pointer to the new variable.
770   Attributes:
771     a.where          Indicates where the variable is allocated.
772     a.*type          A pointer to the class the allocated data object
773                      belongs to.
774
775   ir_node *new_Free (ir_node *store, ir_node *ptr, type *free_type)
776   ------------------------------------------------------------------
777
778   The Free node frees memory of the given variable.
779
780   Parameters:
781     *store       The memory which shall contain the new variable.
782     *ptr         The pointer to the object to free.
783     *size        The number of objects of type free_type to free in a sequence.
784     *free_type   The type of the freed variable.
785
786   Inputs:
787     A memory, a pointer and an unsigned integer.
788   Output:
789     The changed memory.
790   Attributes:
791     f.*type          A pointer to the type information of the freed data object.
792
793   Not Implemented!
794
795   ir_node *new_Sync (int arity, ir_node **in)
796   -------------------------------------------
797
798   The Sync operation unifies several partial memory blocks.  These blocks
799   have to be pairwise disjunct or the values in common locations have to
800   be identical.  This operation allows to specify all operations that eventually
801   need several partial memory blocks as input with a single entrance by
802   unifying the memories with a preceding Sync operation.
803
804   Parameters
805     arity    The number of memories to syncronize.
806     **in     An array of pointers to nodes that produce an output of
807              type memory.
808   Inputs
809     Several memories.
810   Output
811     The unified memory.
812
813
814   SPECIAL OPERATIONS
815   ------------------
816
817   ir_node *new_Bad (void)
818   -----------------------
819
820   Returns the unique Bad node current_ir_graph->bad.
821   This node is used to express results of dead code elimination.
822
823   ir_node *new_Proj (ir_node *arg, ir_mode *mode, long proj)
824   ----------------------------------------------------------
825
826   Selects one entry of a tuple.  This is a hidden `fat edge'.
827
828   Parameters
829     *arg      A node producing a tuple.
830     *mode     The mode of the value to project.
831     proj      The position of the value in the tuple.
832   Input:
833     The tuple.
834   Output:
835     The value.
836
837   ir_node *new_Tuple (int arity, ir_node **in)
838   --------------------------------------------
839
840   Builds a Tuple from single values.  This is needed to implement
841   optimizations that remove a node that produced a tuple.  The node can be
842   replaced by the Tuple operation so that the following Proj nodes have not to
843   be changed.  (They are hard to find due to the implementation with pointers
844   in only one direction.)  The Tuple node is smaller than any other
845   node, so that a node can be changed into a Tuple by just changing it's
846   opcode and giving it a new in array.
847
848   Parameters
849     arity    The number of tuple elements.
850     **in     An array containing pointers to the nodes producing the
851              tuple elements.
852
853   ir_node *new_Id (ir_node *val, ir_mode *mode)
854   ---------------------------------------------
855
856   The single output of the Id operation is it's input.  Also needed
857   for optimizations.
858
859
860   COPING WITH DATA OBJECTS
861   ========================
862
863   Two kinds of data objects have to be distinguished for generating
864   FIRM.  First there are local variables other than arrays that are
865   known to be alias free.  Second there are all other data objects.
866   For the first a common SSA representation is built, the second
867   are modeled by saving them to memory.  The memory is treated as
868   a single local variable, the alias problem is hidden in the
869   content of this variable.
870
871   All values known in a Block are listed in the block's attribute,
872   block.**graph_arr which is used to automatically insert Phi nodes.
873   The following two funcions can be used to add a newly computed value
874   to the array, or to get the producer of a value, i.e., the current
875   live value.
876
877   inline void set_value (int pos, ir_node *value)
878   -----------------------------------------------
879
880   Has to be called for every assignment to a local variable.  It
881   adds the value to the array of used values at position pos.  Pos
882   has to be a unique identifier for an entry in the procedure's
883   definition table.  It can be used to access the value again.
884
885   ir_node *get_value (int pos, ir_mode *mode)
886   -------------------------------------------
887
888   Returns the node defining the value referred to by pos. If the
889   value is not defined in this block a Phi node is generated and
890   all definitions reaching this Phi node are collected.  It can
891   happen that the algorithm allocates an unnecessary Phi node,
892   e.g. if there is only one definition of this value, but this
893   definition reaches the currend block on several different
894   paths.  This Phi node will be eliminated if optimizations are
895   turned on right after it's creation.
896
897
898   There are two special routines for the global store:
899
900   inline void set_store (ir_node *store)
901   --------------------------------------
902
903   Adds the store to the array of known values at a reserved
904   position.
905
906   inline ir_node *get_store (void)
907   --------------------------------
908
909   Returns the node defining the actual store.
910
911 **/
912
913
914 # ifndef _IRCONS_H_
915 # define _IRCONS_H_
916
917 # include "irgmod.h"
918 # include "irmode.h"
919 # include "entity.h"
920 # include "tv.h"
921 # include "common.h"
922 # include "irop.h"
923 # include "irgraph.h"
924 # include "type.h"
925 # include "pdeq.h"
926 # include "irvrfy.h"
927
928 /* irnode constructor                                             */
929 /* Create a new irnode in irg, with an op, mode, arity and        */
930 /* some incoming irnodes.                                         */
931 /* If arity is negative, a node with a dynamic array is created.  */
932 inline ir_node *new_ir_node (ir_graph *irg, ir_node *block, ir_op *op,
933                              ir_mode *mode, int arity, ir_node **in);
934
935 /** These headers need not to be here. They are never used by the
936     public.
937     That's not completely true.  They need not be seen by a frontend,
938     but they might be useful for optimizations changing the IR. **/
939
940 #if USE_EXPICIT_PHI_IN_STACK
941 /* A stack needed for the automatic Phi node construction in constructor
942    Phi_in. */
943 typedef struct Phi_in_stack {
944   ir_node **stack;
945   int       pos;
946 } Phi_in_stack;
947 #endif
948
949 /* privat interfaces */
950 /* more detailed construction */
951
952 ir_node *new_r_Jmp    (ir_graph *irg, ir_node *block);
953 ir_node *new_r_Cond   (ir_graph *irg, ir_node *block, ir_node *c);
954 ir_node *new_r_Return (ir_graph *irg, ir_node *block,
955                        ir_node *store, int arity, ir_node **in);
956 ir_node *new_r_Raise  (ir_graph *irg, ir_node *block,
957                        ir_node *store, ir_node *obj);
958 ir_node *new_r_Const  (ir_graph *irg, ir_node *block,
959                        ir_mode *mode, tarval *con);
960 ir_node *new_r_SymConst (ir_graph *irg, ir_node *block,
961                        type_or_id *value, symconst_kind symkind);
962 ir_node *new_r_Sel    (ir_graph *irg, ir_node *block, ir_node *store,
963                        ir_node *objptr, int n_index, ir_node **index,
964                        entity *ent);
965 ir_node *new_r_Call   (ir_graph *irg, ir_node *block, ir_node *store,
966                        ir_node *callee, int arity, ir_node **in, type_method *type);
967 ir_node *new_r_Add    (ir_graph *irg, ir_node *block,
968                        ir_node *op1, ir_node *op2, ir_mode *mode);
969 ir_node *new_r_Sub    (ir_graph *irg, ir_node *block,
970                        ir_node *op1, ir_node *op2, ir_mode *mode);
971 ir_node *new_r_Minus  (ir_graph *irg, ir_node *block,
972                        ir_node *op,  ir_mode *mode);
973 ir_node *new_r_Mul    (ir_graph *irg, ir_node *block,
974                        ir_node *op1, ir_node *op2, ir_mode *mode);
975 ir_node *new_r_Quot   (ir_graph *irg, ir_node *block, ir_node *memop,
976                        ir_node *op1, ir_node *op2);
977 ir_node *new_r_DivMod (ir_graph *irg, ir_node *block,
978                        ir_node *memop, ir_node *op1, ir_node *op2);
979 ir_node *new_r_Div    (ir_graph *irg, ir_node *block, ir_node *memop,
980                        ir_node *op1, ir_node *op2);
981 ir_node *new_r_Mod    (ir_graph *irg, ir_node *block, ir_node *memop,
982                        ir_node *op1, ir_node *op2);
983 ir_node *new_r_Abs    (ir_graph *irg, ir_node *block,
984                        ir_node *op, ir_mode *mode);
985 ir_node *new_r_And    (ir_graph *irg, ir_node *block,
986                        ir_node *op1, ir_node *op2, ir_mode *mode);
987 ir_node *new_r_Or     (ir_graph *irg, ir_node *block,
988                        ir_node *op1, ir_node *op2, ir_mode *mode);
989 ir_node *new_r_Eor    (ir_graph *irg, ir_node *block,
990                        ir_node *op1, ir_node *op2, ir_mode *mode);
991 ir_node *new_r_Not    (ir_graph *irg, ir_node *block,
992                        ir_node *op, ir_mode *mode);
993 ir_node *new_r_Shl    (ir_graph *irg, ir_node *block,
994                        ir_node *op, ir_node *k, ir_mode *mode);
995 ir_node *new_r_Shr    (ir_graph *irg, ir_node *block,
996                        ir_node *op, ir_node *k, ir_mode *mode);
997 ir_node *new_r_Shrs   (ir_graph *irg, ir_node *block,
998                        ir_node *op, ir_node *k, ir_mode *mode);
999 ir_node *new_r_Rot    (ir_graph *irg, ir_node *block,
1000                        ir_node *op, ir_node *k, ir_mode *mode);
1001 ir_node *new_r_Cmp    (ir_graph *irg, ir_node *block,
1002                        ir_node *op1, ir_node *op2);
1003 ir_node *new_r_Conv   (ir_graph *irg, ir_node *block,
1004                        ir_node *op, ir_mode *mode);
1005 ir_node *new_r_Phi    (ir_graph *irg, ir_node *block, int arity,
1006                        ir_node **in, ir_mode *mode);
1007 ir_node *new_r_Load   (ir_graph *irg, ir_node *block,
1008                        ir_node *store, ir_node *adr);
1009 ir_node *new_r_Store  (ir_graph *irg, ir_node *block,
1010                        ir_node *store, ir_node *adr, ir_node *val);
1011 ir_node *new_r_Alloc  (ir_graph *irg, ir_node *block, ir_node *store,
1012                        ir_node *size, type *alloc_type, where_alloc where);
1013 ir_node *new_r_Free   (ir_graph *irg, ir_node *block, ir_node *store,
1014                        ir_node *ptr, ir_node *size, type *free_type);
1015 ir_node *new_r_Sync   (ir_graph *irg, ir_node *block, int arity, ir_node **in);
1016 ir_node *new_r_Proj   (ir_graph *irg, ir_node *block, ir_node *arg,
1017                        ir_mode *mode, long proj);
1018 ir_node *new_r_Tuple  (ir_graph *irg, ir_node *block,
1019                        int arity, ir_node **in);
1020 ir_node *new_r_Id  (ir_graph *irg, ir_node *block,
1021                     ir_node *val, ir_mode *mode);
1022 ir_node *new_r_Bad (ir_node *block);
1023
1024
1025
1026 /* public interfaces */
1027 /* normal constructors */
1028
1029 ir_node *new_Block  (void);
1030 ir_node *new_Start  (void);
1031 ir_node *new_End    (void);
1032 ir_node *new_Jmp    (void);
1033 ir_node *new_Cond   (ir_node *c);
1034 ir_node *new_Return (ir_node *store, int arity, ir_node **in);
1035 ir_node *new_Raise  (ir_node *store, ir_node *obj);
1036 ir_node *new_Const  (ir_mode *mode, tarval *con);
1037 ir_node *new_SymConst (type_or_id *value, symconst_kind kind);
1038 ir_node *new_simpleSel (ir_node *store, ir_node *objptr, entity *ent);
1039 ir_node *new_Sel    (ir_node *store, ir_node *objptr, int arity, ir_node **in,
1040                      entity *ent);
1041 ir_node *new_Call   (ir_node *store, ir_node *callee, int arity, ir_node **in,
1042                      type_method *type);
1043 ir_node *new_Add    (ir_node *op1, ir_node *op2, ir_mode *mode);
1044 ir_node *new_Sub    (ir_node *op1, ir_node *op2, ir_mode *mode);
1045 ir_node *new_Minus  (ir_node *op,  ir_mode *mode);
1046 ir_node *new_Mul    (ir_node *op1, ir_node *op2, ir_mode *mode);
1047 ir_node *new_Quot   (ir_node *memop, ir_node *op1, ir_node *op2);
1048 ir_node *new_DivMod (ir_node *memop, ir_node *op1, ir_node *op2);
1049 ir_node *new_Div    (ir_node *memop, ir_node *op1, ir_node *op2);
1050 ir_node *new_Mod    (ir_node *memop, ir_node *op1, ir_node *op2);
1051 ir_node *new_Abs    (ir_node *op,                ir_mode *mode);
1052 ir_node *new_And    (ir_node *op1, ir_node *op2, ir_mode *mode);
1053 ir_node *new_Or     (ir_node *op1, ir_node *op2, ir_mode *mode);
1054 ir_node *new_Eor    (ir_node *op1, ir_node *op2, ir_mode *mode);
1055 ir_node *new_Not    (ir_node *op,                ir_mode *mode);
1056 ir_node *new_Shl    (ir_node *op,  ir_node *k,   ir_mode *mode);
1057 ir_node *new_Shr    (ir_node *op,  ir_node *k,   ir_mode *mode);
1058 ir_node *new_Shrs   (ir_node *op,  ir_node *k,   ir_mode *mode);
1059 ir_node *new_Rot    (ir_node *op,  ir_node *k,   ir_mode *mode);
1060 ir_node *new_Cmp    (ir_node *op1, ir_node *op2);
1061 ir_node *new_Conv   (ir_node *op, ir_mode *mode);
1062 ir_node *new_Phi    (int arity, ir_node **in, ir_mode *mode);
1063 ir_node *new_Load   (ir_node *store, ir_node *addr);
1064 ir_node *new_Store  (ir_node *store, ir_node *addr, ir_node *val);
1065 ir_node *new_Alloc  (ir_node *store, ir_node *size, type *alloc_type,
1066                      where_alloc where);
1067 ir_node *new_Free   (ir_node *store, ir_node *ptr, ir_node *size,
1068                      type *free_type);
1069 ir_node *new_Sync   (int arity, ir_node **in);
1070 ir_node *new_Proj   (ir_node *arg, ir_mode *mode, long proj);
1071 ir_node *new_Tuple  (int arity, ir_node **in);
1072 ir_node *new_Id     (ir_node *val, ir_mode *mode);
1073 ir_node *new_Bad    (void);
1074
1075
1076 #if USE_EXPICIT_PHI_IN_STACK
1077 Phi_in_stack *new_Phi_in_stack();
1078 #endif
1079
1080 /* initialize ir construction */
1081 void init_cons (void);
1082
1083
1084 # endif /* _IRCONS_H_ */