d7dcd5e22c66839395528467f7ce77af340d6b7a
[libfirm] / ir / ir / irnode_t.h
1 /* Copyright (C) 1998 - 2000 by Universitaet Karlsruhe
2 ** All rights reserved.
3 **
4 ** Authors: Martin Trapp, Christian Schaefer
5 **
6 ** declarations of an ir node
7 */
8
9 /* $Id$ */
10
11 # ifndef _IRNODE_T_H_
12 # define _IRNODE_T_H_
13
14 # include "irnode.h"
15 # include "xprintf.h"
16 # include "irop_t.h"
17 # include "common_t.h"
18 # include "irdom_t.h" /* For size of struct dom_info. */
19
20 /** ir node attributes **/
21
22 /* Block attributes */
23 typedef struct {
24   unsigned long block_visited;  /* for the walker that walks over all blocks. */
25   /* Attributes private to construction: */
26   bool matured;               /* if set, all in-nodes of the block are fixed */
27   struct ir_node **graph_arr; /* array to store all parameters */
28   struct dom_info dom;        /* Datastructure that holds information about dominators.
29                                  @@@ Eventually overlay with graph_arr as only valid
30                                  in different phases.  Eventually inline the whole
31                                  datastructure. */
32 } block_attr;
33
34 /* Cond attributes */
35 typedef struct {
36   cond_kind kind;    /* flavor of Cond */
37   long default_proj; /* for optimization: biggest Proj number, i.e. the one
38                         used for default. */
39 } cond_attr;
40
41 /* SymConst attributes */
42 /*   This union contains the symbolic information represented by the node */
43 typedef union type_or_id {
44   type *typ;
45   ident *ptrinfo;
46 } type_or_id;
47
48 typedef struct {
49   type_or_id tori;
50   symconst_kind num;
51 } symconst_attr;
52
53 /* Sel attributes */
54 typedef struct {
55   entity *ent;          /* entity to select */
56   linkage_type ltyp;    /* linkage type of the entity */
57 } sel_attr;
58
59 typedef struct {
60   type *cld_tp;         /* type of called procedure */
61 #if PRECISE_EXC_CONTEXT
62   struct ir_node **frag_arr; /* For Phi node construction in case of exceptions */
63 #endif
64 } call_attr;
65
66 /* Alloc attributes */
67 typedef struct {
68   type *type;           /* Type of the allocated object.  */
69   where_alloc where;    /* stack, heap or other managed part of memory */
70 #if PRECISE_EXC_CONTEXT
71   struct ir_node **frag_arr; /* For Phi node construction in case of exceptions */
72 #endif
73 } alloc_attr;
74
75 /* Some irnodes just have one attribute, these are stored here,
76    some have more. Their name is 'irnodename_attr' */
77 typedef union {
78   block_attr     block; /* For Block: Fields needed to construct it */
79   cond_attr      c;     /* For Cond. */
80   struct tarval *con;   /* For Const: contains the value of the constant */
81   symconst_attr  i;     /* For SymConst. */
82   sel_attr       s;     /* For Sel. */
83   call_attr      call;  /* For Call: pointer to the type of the method to call */
84   alloc_attr     a;     /* For Alloc. */
85   type          *f;     /* For Free. */
86   int            phi0_pos;  /* For Phi. Used to remember the value defined by
87                                this Phi node.  Needed when the Phi is completed
88                                to call get_r_internal_value to find the
89                                predecessors. If this attribute is set, the Phi
90                                node takes the role of the obsolete Phi0 node,
91                                therefore the name. */
92   long           proj;  /* For Proj: contains the result position to project */
93 #if PRECISE_EXC_CONTEXT
94   struct ir_node **frag_arr; /* For Phi node construction in case of exceptions
95                                for nodes Store, Load, Div, Mod, Quot, DivMod. */
96 #endif
97 } attr;
98
99
100 /* common structure of an irnode */
101 /* if the node has some attributes, they are stored in attr */
102
103 struct ir_node {
104   /** Basics of the representation **/
105   firm_kind kind;          /* distinguishes this node from others */
106   ir_op *op;               /* Opcode of this node. */
107   ir_mode *mode;           /* Mode of this node. */
108   unsigned long visited;   /* visited counter for walks of the graph */
109   struct ir_node **in;     /* array with predecessors / operands */
110   struct ir_node *link;    /* for linking nodes somehow to a list, e.g.
111                               used while construction to link Phi0 nodes and
112                               during optimization to link to nodes that
113                               shall replace a node. */
114   /**  Fields for optimizations / analysis information **/
115   struct ir_node **out;    /* array of out edges */
116   /** For debugging **/
117 #ifdef DEBUG_libfirm
118   int node_nr;             /* a unique node number for each node to make output
119                               readable. */
120 #endif
121   attr attr;               /* attribute of this node. Depends on opcode. */
122                            /* Must be last field of struct ir_node. */
123 };
124
125 /* Copies all attributes stored in the old node  to the new node.
126    Assumes both have the same opcode and sufficient size. */
127 void
128 copy_attrs (ir_node *old, ir_node *new);
129
130
131 /* Print IR-Nodes with attributes */
132 /* @@@@ brauchen wir dienoch? dann fliegt ev. das xprint raus?*/
133 int ir_node_print (XP_PAR1, const xprintf_info *, XP_PARN);
134
135
136 /** access attributes directly **/
137 inline tarval       *get_irn_const_attr    (ir_node *node);
138 inline long          get_irn_proj_attr     (ir_node *node);
139 inline alloc_attr    get_irn_alloc_attr    (ir_node *node);
140 inline type         *get_irn_free_attr     (ir_node *node);
141 inline symconst_attr get_irn_symconst_attr (ir_node *node);
142 type         *get_irn_call_attr     (ir_node *node);
143 sel_attr      get_irn_sel_attr      (ir_node *node);
144 int           get_irn_phi_attr      (ir_node *node);
145 block_attr    get_irn_return_attr   (ir_node *node);
146
147 # endif /* _IRNODE_T_H_ */