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