removed wrong INLINE
[libfirm] / ir / ana / irbackedge.c
1 /*
2  * Project:     libFIRM
3  * File name:   ir/ana/irbackedge.c
4  * Purpose:     Access function for backedges.
5  * Author:      Goetz Lindenmaier
6  * Modified by:
7  * Created:     7.2002
8  * CVS-ID:      $Id$
9  * Copyright:   (c) 2002-2003 Universität Karlsruhe
10  * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
11  */
12
13 #include "irnode_t.h"
14 #include "irgraph_t.h"
15 #include "array.h"
16 #include "irbackedge_t.h"
17
18 /*--------------------------------------------------------------------*/
19 /* Backedge information.                                              */
20 /*--------------------------------------------------------------------*/
21
22
23 /**
24  * Returns backarray if the node can have backedges, else returns
25  * NULL.
26  *
27  * Does not assert whether the backarray is correct -- use
28  * very careful!
29  */
30 static INLINE int *mere_get_backarray(ir_node *n) {
31   switch (get_irn_opcode(n)) {
32   case iro_Block:
33     if (!get_Block_matured(n)) return NULL;
34     if (get_interprocedural_view() && n->attr.block.in_cg) {
35       assert(n->attr.block.cg_backedge && "backedge array not allocated!");
36       return n->attr.block.cg_backedge;
37     } else {
38       assert(n->attr.block.backedge && "backedge array not allocated!");
39       return n->attr.block.backedge;
40     }
41     break;
42   case iro_Phi:
43       assert(n->attr.phi_backedge && "backedge array not allocated!");
44     return n->attr.phi_backedge;
45     break;
46   case iro_Filter:
47     if (get_interprocedural_view()) {
48       assert(n->attr.filter.backedge && "backedge array not allocated!");
49       return n->attr.filter.backedge;
50     }
51     break;
52   default: ;
53   }
54   return NULL;
55 }
56
57 /**
58  * Returns backarray if the node can have backedges, else returns
59  * NULL.
60  */
61 static INLINE int *get_backarray(ir_node *n) {
62   int *ba = mere_get_backarray(n);
63
64   if (ba) {
65     int bal = ARR_LEN(ba);  /* avoid makro expansion in assertion. */
66     int inl = ARR_LEN(get_irn_in(n)) -1;  /* Use get_irn_in -- sensitive to view! */
67     assert(bal == inl && "backedge array with faulty length");
68   }
69
70   return ba;
71 }
72
73 /**
74  * Returns true if node has no backarray, or
75  *              if size of backarray == size of in array.
76  */
77 static INLINE bool legal_backarray (ir_node *n) {
78   int *ba = mere_get_backarray(n);
79   if (ba && (ARR_LEN(ba) != ARR_LEN(get_irn_in(n))-1))  /* Use get_irn_in -- sensitive to view! */
80     return false;
81   return true;
82 }
83
84
85 void fix_backedges(struct obstack *obst, ir_node *n) {
86   opcode opc = get_irn_opcode(n);
87   int *arr = mere_get_backarray(n);
88   if (ARR_LEN(arr) == ARR_LEN(get_irn_in(n))-1)
89     return;
90   if (ARR_LEN(arr) != ARR_LEN(get_irn_in(n))-1) {
91     arr = new_backedge_arr(obst, ARR_LEN(get_irn_in(n))-1);
92     if (opc == iro_Phi)    n->attr.phi_backedge = arr;
93     if ((opc == iro_Block) && !get_interprocedural_view())
94       n->attr.block.backedge = arr;
95     if ((opc == iro_Block) && get_interprocedural_view())
96       n->attr.block.cg_backedge = arr;
97     if (opc == iro_Filter) n->attr.filter.backedge = arr;
98     return;
99   }
100   assert(legal_backarray(n));
101   /* @@@ more efficient in memory consumption, not possible with
102    array implementation.
103   if (ARR_LEN(arr) < ARR_LEN(get_irn_in(n))-1) {
104     ARR_SETLEN(int, arr, ARR_LEN(get_irn_in(n))-1);
105   }*/
106 }
107
108 int is_inter_backedge(ir_node *n, int pos) {
109   int res;
110   int rem = get_interprocedural_view();
111   set_interprocedural_view(0);
112   res = is_backedge(n, pos);
113   set_interprocedural_view(rem);
114   return res;
115 }
116
117 int is_intra_backedge(ir_node *n, int pos) {
118   int res;
119   int rem = get_interprocedural_view();
120   set_interprocedural_view(1);
121   res = is_backedge(n, pos);
122   set_interprocedural_view(rem);
123   return res;
124 }
125
126
127 /** Returns true if the predecessor pos is a backedge. */
128 bool is_backedge (ir_node *n, int pos) {
129   int *ba = get_backarray (n);
130   if (ba) return ba[pos];
131   return false;
132 }
133
134 /** Remarks that edge pos is a backedge. */
135 void set_backedge (ir_node *n, int pos) {
136   int *ba = get_backarray (n);
137   assert(ba && "can only set backedges at Phi, Filter, Block nodes.");
138   ba[pos] = 1;
139 }
140
141 /** Remarks that edge pos is a backedge. */
142 void set_not_backedge (ir_node *n, int pos) {
143   int *ba = get_backarray (n);
144   assert(ba && "can only set backedges at Phi, Filter, Block nodes.");
145   ba[pos] = 0;
146 }
147
148 /** Returns true if n has backedges. */
149 bool has_backedges (ir_node *n) {
150   int i;
151   int *ba = get_backarray (n);
152   if (ba) {
153     int arity = get_irn_arity(n);
154     for (i = 0; i < arity; i++)
155       if (ba[i]) return true;
156   }
157   return false;
158 }
159
160 /** Sets all backedge information to zero. */
161 void clear_backedges (ir_node *n) {
162   int i, arity;
163   int rem = get_interprocedural_view();
164   int *ba;
165   set_interprocedural_view(false);
166   ba = get_backarray (n);
167   if (ba) {
168     arity = get_irn_arity(n);
169     for (i = 0; i < arity; i++)
170       ba[i] = 0;
171   }
172   set_interprocedural_view(true);
173   ba = get_backarray (n);
174   if (ba) {
175     arity = get_irn_arity(n);
176     for (i = 0; i < arity; i++)
177       ba[i] = 0;
178   }
179   set_interprocedural_view(rem);
180 }