70c3f169ef9e416e23f2d6c514aac9628aca4ccb
[libfirm] / ir / ir / irgraph.h
1 /* Copyright (C) 1998 - 2000 by Universitaet Karlsruhe
2 ** All rights reserved.
3 **
4 ** Authors: Martin Trapp, Christian Schaefer
5 **
6 ** irgraph.h: ir graph construction
7 */
8
9 # ifndef _IRGRAPH_H_
10 # define _IRGRAPH_H_
11 # include "tv.h"
12
13 /* to resolve recursion between irnode.h and irgraph.h */
14 #ifndef _IR_NODE_TYPEDEF_
15 #define _IR_NODE_TYPEDEF_
16 typedef struct ir_node ir_node;
17 #endif
18
19 /* to resolve recursion between entity.h and irgraph.h */
20 #ifndef _IR_GRAPH_TYPEDEF_
21 #define _IR_GRAPH_TYPEDEF_
22 typedef struct ir_graph ir_graph;
23 #endif
24
25 /***** irgraph/irgraph
26  *
27  * NAME  Datastructure that holds central information about a procedure
28  *
29  * NOTE
30  **    ir_graph *new_ir_graph (entity *ent, int params);
31  *    -------------------------------------------------
32  *
33  *    This constructor generates the basic infrastructure needed to
34  *    represent a procedure in FIRM.
35  *
36  *    The parameters of new_ir_graph are:
37  *
38  *      *ent             A pointer to an entity representing the procedure.
39  *
40  *      params           An integer giving the number of local variables in the
41  *                       procedure.
42  *
43  *    It allocates an ir_graph and sets current_ir_graph to point to this
44  *    graph.  Further it allocates the following nodes needed for every
45  *    procedure:
46  *
47  *    * The start block containing a start node and Proj nodes for it's
48  *      five results (X, M, P, P, T).
49  *    * The end block containing an end node. This block is not matured
50  *      after executing new_ir_graph as predecessors need to be added to it.
51  *      (Maturing a block means fixing it's number of predecessors.)
52  *    * The current block, which is empty and also not matured.
53  *
54  *    Further it enters the global store into the datastructure of the start
55  *    block that contanis all valid values in this block (set_store()).  This
56  *    datastructure is used to build the Phi nodes and removed after
57  *    completion of the graph.  There is no path from end to start in the
58  *    graph after calling ir_graph.
59  * SOURCE
60  */
61
62 /* Global variable holding the current_ir_graph.  This global variable
63    is used by the ir construction interface in ircons and by the
64    optimizations. */
65 extern ir_graph *current_ir_graph;
66
67 /* Create a new ir graph to built ir for a procedure.
68    ent is the entity representing this procedure, i.e., the type of the
69    entity must be of a method type.  The constructor automatically sets the
70    field irg of the entity as well as current_ir_graph to the new ir graph.
71    n_loc is the number of local variables in this procedure including
72    the procedure parameters. */
73 ir_graph *new_ir_graph (entity *ent, int n_loc);
74
75 /* Frees the passed irgraph.
76    Deallocates all nodes in this graph and the ir_graph structure.
77    Sets the field irgraph in the corresponding entity to NULL.
78    Does not free types, entities or modes that are used only by this
79    graph, nor the entity standing for this graph. */
80 void free_ir_graph (ir_graph *irg);
81
82 /* access routines for all ir_graph attributes */
83 ir_node *get_irg_start_block (ir_graph *irg);
84 void     set_irg_start_block (ir_graph *irg, ir_node *node);
85
86 ir_node *get_irg_start (ir_graph *irg);
87 void     set_irg_start (ir_graph *irg, ir_node *node);
88
89 ir_node *get_irg_end_block (ir_graph *irg);
90 void     set_irg_end_block (ir_graph *irg, ir_node *node);
91
92 ir_node *get_irg_end (ir_graph *irg);
93 void     set_irg_end (ir_graph *irg, ir_node *node);
94
95 ir_node *get_irg_cstore (ir_graph *irg);
96 void     set_irg_cstore (ir_graph *irg, ir_node *node);
97
98 ir_node *get_irg_frame (ir_graph *irg);
99 void     set_irg_frame (ir_graph *irg, ir_node *node);
100
101 ir_node *get_irg_globals (ir_graph *irg);
102 void     set_irg_globals (ir_graph *irg, ir_node *node);
103
104 ir_node *get_irg_args (ir_graph *irg);
105 void     set_irg_args (ir_graph *irg, ir_node *node);
106
107 /* Use new_Bad() instead!! */
108 ir_node *get_irg_bad (ir_graph *irg);
109 void     set_irg_bad (ir_graph *irg, ir_node *node);
110
111 ir_node *get_irg_current_block (ir_graph *irg);
112 void     set_irg_current_block (ir_graph *irg, ir_node *node);
113
114 entity  *get_irg_ent (ir_graph *irg);
115 void     set_irg_ent (ir_graph *irg, entity *ent);
116
117 /* Use not encouraged, internal of Phi construction algorithm. */
118 int      get_irg_n_loc (ir_graph *irg);
119 void     set_irg_n_loc (ir_graph *irg, int n_loc);
120
121 /* increments visited by one */
122 void     inc_irg_visited(ir_graph *irg);
123 unsigned long get_irg_visited (ir_graph *irg);
124 void     set_irg_visited(ir_graph *irg, unsigned long i);
125
126 /* increments block_visited by one */
127 void     inc_irg_block_visited(ir_graph *irg);
128 unsigned long get_irg_block_visited (ir_graph *irg);
129 void     set_irg_block_visited(ir_graph *irg, unsigned long i);
130 /*****/
131
132 # endif /* _IRGRAPH_H_ */