1 /* Copyright (C) 2002 by Universitaet Karlsruhe
4 * Authors: Goetz Lindenmaier
6 * irbackedges.c Access function for backedges.
14 #include "irbackedge_t.h"
16 /*--------------------------------------------------------------------*/
17 /* Backedge information. * */
18 /*--------------------------------------------------------------------*/
22 * Returns backarray if the node can have backedges, else returns
25 * Does not assert whether the backarray is correct -- use
28 static INLINE int *mere_get_backarray(ir_node *n) {
29 switch(get_irn_opcode(n)) {
31 if (!get_Block_matured(n)) return NULL;
32 if (interprocedural_view && n->attr.block.in_cg) {
33 assert(n->attr.block.cg_backedge && "backedge array not allocated!");
34 return n->attr.block.cg_backedge;
36 assert(n->attr.block.backedge && "backedge array not allocated!");
37 return n->attr.block.backedge;
41 assert(n->attr.phi_backedge && "backedge array not allocated!");
42 return n->attr.phi_backedge;
45 if (interprocedural_view) {
46 assert(n->attr.filter.backedge && "backedge array not allocated!");
47 return n->attr.filter.backedge;
56 * Returns backarray if the node can have backedges, else returns
59 static INLINE int *get_backarray(ir_node *n) {
60 int *ba = mere_get_backarray(n);
63 int bal = ARR_LEN(ba); /* avoid makro expansion in assertion. */
64 int inl = ARR_LEN(get_irn_in(n)) -1; /* Use get_irn_in -- sensitive to view! */
65 assert(bal == inl && "backedge array with faulty length");
72 * Returns true if node has no backarray, or
73 * if size of backarray == size of in array.
75 static INLINE bool legal_backarray (ir_node *n) {
76 int *ba = mere_get_backarray(n);
77 if (ba && (ARR_LEN(ba) != ARR_LEN(get_irn_in(n))-1)) /* Use get_irn_in -- sensitive to view! */
83 INLINE void fix_backedges(struct obstack *obst, ir_node *n) {
84 opcode opc = get_irn_opcode(n);
85 int *arr = mere_get_backarray(n);
86 if (ARR_LEN(arr) == ARR_LEN(get_irn_in(n))-1)
88 if (ARR_LEN(arr) != ARR_LEN(get_irn_in(n))-1) {
89 arr = new_backedge_arr(obst, ARR_LEN(get_irn_in(n))-1);
90 if (opc == iro_Phi) n->attr.phi_backedge = arr;
91 if ((opc == iro_Block) && !interprocedural_view)
92 n->attr.block.backedge = arr;
93 if ((opc == iro_Block) && interprocedural_view)
94 n->attr.block.cg_backedge = arr;
95 if (opc == iro_Filter) n->attr.filter.backedge = arr;
98 assert(legal_backarray(n));
99 /* @@@ more efficient in memory consumption, not possible with
100 array implementation.
101 if (ARR_LEN(arr) < ARR_LEN(get_irn_in(n))-1) {
102 ARR_SETLEN(int, arr, ARR_LEN(get_irn_in(n))-1);
106 /** Returns true if the predesessor pos is a backedge. */
107 bool is_backedge (ir_node *n, int pos) {
108 int *ba = get_backarray (n);
109 if (ba) return ba[pos];
113 /** Remarks that edge pos is a backedge. */
114 void set_backedge (ir_node *n, int pos) {
115 int *ba = get_backarray (n);
116 assert(ba && "can only set backedges at Phi, Filter, Block nodes.");
120 /** Remarks that edge pos is a backedge. */
121 void set_not_backedge (ir_node *n, int pos) {
122 int *ba = get_backarray (n);
123 assert(ba && "can only set backedges at Phi, Filter, Block nodes.");
127 /** Returns true if n has backedges. */
128 bool has_backedges (ir_node *n) {
130 int *ba = get_backarray (n);
132 for (i = 0; i < get_irn_arity(n); i++)
133 if (ba[i]) return true;
137 /** Sets all backedge information to zero. */
138 void clear_backedges (ir_node *n) {
139 int i, rem = interprocedural_view;
141 interprocedural_view = 0;
142 ba = get_backarray (n);
144 for (i = 0; i < get_irn_arity(n); i++)
146 interprocedural_view = 1;
147 ba = get_backarray (n);
149 for (i = 0; i < get_irn_arity(n); i++)
151 interprocedural_view = rem;