1 /* Copyright (C) 2002 by Universitaet Karlsruhe
2 ** All rights reserved.
4 ** Authors: Goetz Lindenmaier
6 ** irbackedges.c Access function for backedges.
14 #include "irbackedge_t.h"
16 /**********************************************************************/
17 /** Backedge information. **/
18 /**********************************************************************/
21 /* Returns backarray if the node can have backedges. Else returns
22 NULL. Does not assert whether the backarray is correct -- use
24 static INLINE int *mere_get_backarray(ir_node *n) {
25 switch(get_irn_opcode(n)) {
27 if (interprocedural_view && n->attr.block.in_cg) {
28 assert(n->attr.block.cg_backedge && "backedge array not allocated!");
29 return n->attr.block.cg_backedge;
31 assert(n->attr.block.backedge && "backedge array not allocated!");
32 return n->attr.block.backedge;
36 assert(n->attr.phi_backedge && "backedge array not allocated!");
37 return n->attr.phi_backedge;
40 if (interprocedural_view) {
41 assert(n->attr.filter.backedge && "backedge array not allocated!");
42 return n->attr.filter.backedge;
50 /* Returns backarray if the node can have backedges. Else returns
52 static INLINE int *get_backarray(ir_node *n) {
53 int *ba = mere_get_backarray(n);
56 int bal = ARR_LEN(ba); /* avoid makro expansion in assertion. */
57 int inl = ARR_LEN(get_irn_in(n)) -1; /* Use get_irn_in -- sensitive to view! */
58 assert(bal == inl && "backedge array with faulty length");
64 /* returns true if node has no backarray, or
65 if size of backarray == size of in array. */
66 static INLINE bool legal_backarray (ir_node *n) {
67 int *ba = mere_get_backarray(n);
68 if (ba && (ARR_LEN(ba) != ARR_LEN(get_irn_in(n))-1)) /* Use get_irn_in -- sensitive to view! */
74 INLINE void fix_backedges(struct obstack *obst, ir_node *n) {
75 opcode opc = get_irn_opcode(n);
76 int *arr = mere_get_backarray(n);
77 if (ARR_LEN(arr) == ARR_LEN(get_irn_in(n))-1)
79 if (ARR_LEN(arr) != ARR_LEN(get_irn_in(n))-1) {
80 arr = new_backedge_arr(obst, ARR_LEN(get_irn_in(n))-1);
81 if (opc == iro_Phi) n->attr.phi_backedge = arr;
82 if ((opc == iro_Block) && !interprocedural_view)
83 n->attr.block.backedge = arr;
84 if ((opc == iro_Block) && interprocedural_view)
85 n->attr.block.cg_backedge = arr;
86 if (opc == iro_Filter) n->attr.filter.backedge = arr;
89 assert(legal_backarray(n));
90 // @@@ more efficient in memory consumption, not possible with
91 // array implementation.
92 //if (ARR_LEN(arr) < ARR_LEN(get_irn_in(n))-1) {
93 // ARR_SETLEN(int, arr, ARR_LEN(get_irn_in(n))-1);
97 /* Returns true if the predesessor pos is a backedge. */
98 bool is_backedge (ir_node *n, int pos) {
99 int *ba = get_backarray (n);
100 if (ba) return ba[pos];
104 /* Remarks that edge pos is a backedge. */
105 void set_backedge (ir_node *n, int pos) {
106 int *ba = get_backarray (n);
107 assert(ba && "can only set backedges at Phi, Filter, Block nodes.");
111 /* Remarks that edge pos is a backedge. */
112 void set_not_backedge (ir_node *n, int pos) {
113 int *ba = get_backarray (n);
114 assert(ba && "can only set backedges at Phi, Filter, Block nodes.");
118 /* Returns true if n has backedges. */
119 bool has_backedges (ir_node *n) {
121 int *ba = get_backarray (n);
123 for (i = 0; i < get_irn_arity(n); i++)
124 if (ba[i]) return true;
128 /* Sets all backedge information to zero. */
129 void clear_backedges (ir_node *n) {
130 int i, rem = interprocedural_view;
132 interprocedural_view = 0;
133 ba = get_backarray (n);
135 for (i = 0; i < get_irn_arity(n); i++)
137 interprocedural_view = 1;
138 ba = get_backarray (n);
140 for (i = 0; i < get_irn_arity(n); i++)
142 interprocedural_view = rem;