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 /**********************************************************************/
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 (!get_Block_matured(n)) return NULL;
28 if (interprocedural_view && n->attr.block.in_cg) {
29 assert(n->attr.block.cg_backedge && "backedge array not allocated!");
30 return n->attr.block.cg_backedge;
32 assert(n->attr.block.backedge && "backedge array not allocated!");
33 return n->attr.block.backedge;
37 assert(n->attr.phi_backedge && "backedge array not allocated!");
38 return n->attr.phi_backedge;
41 if (interprocedural_view) {
42 assert(n->attr.filter.backedge && "backedge array not allocated!");
43 return n->attr.filter.backedge;
51 /* Returns backarray if the node can have backedges. Else returns
53 static INLINE int *get_backarray(ir_node *n) {
54 int *ba = mere_get_backarray(n);
57 int bal = ARR_LEN(ba); /* avoid makro expansion in assertion. */
58 int inl = ARR_LEN(get_irn_in(n)) -1; /* Use get_irn_in -- sensitive to view! */
59 assert(bal == inl && "backedge array with faulty length");
65 /* returns true if node has no backarray, or
66 if size of backarray == size of in array. */
67 static INLINE bool legal_backarray (ir_node *n) {
68 int *ba = mere_get_backarray(n);
69 if (ba && (ARR_LEN(ba) != ARR_LEN(get_irn_in(n))-1)) /* Use get_irn_in -- sensitive to view! */
75 INLINE void fix_backedges(struct obstack *obst, ir_node *n) {
76 opcode opc = get_irn_opcode(n);
77 int *arr = mere_get_backarray(n);
78 if (ARR_LEN(arr) == ARR_LEN(get_irn_in(n))-1)
80 if (ARR_LEN(arr) != ARR_LEN(get_irn_in(n))-1) {
81 arr = new_backedge_arr(obst, ARR_LEN(get_irn_in(n))-1);
82 if (opc == iro_Phi) n->attr.phi_backedge = arr;
83 if ((opc == iro_Block) && !interprocedural_view)
84 n->attr.block.backedge = arr;
85 if ((opc == iro_Block) && interprocedural_view)
86 n->attr.block.cg_backedge = arr;
87 if (opc == iro_Filter) n->attr.filter.backedge = arr;
90 assert(legal_backarray(n));
91 // @@@ more efficient in memory consumption, not possible with
92 // array implementation.
93 //if (ARR_LEN(arr) < ARR_LEN(get_irn_in(n))-1) {
94 // ARR_SETLEN(int, arr, ARR_LEN(get_irn_in(n))-1);
98 /* Returns true if the predesessor pos is a backedge. */
99 bool is_backedge (ir_node *n, int pos) {
100 int *ba = get_backarray (n);
101 if (ba) return ba[pos];
105 /* Remarks that edge pos is a backedge. */
106 void set_backedge (ir_node *n, int pos) {
107 int *ba = get_backarray (n);
108 assert(ba && "can only set backedges at Phi, Filter, Block nodes.");
112 /* Remarks that edge pos is a backedge. */
113 void set_not_backedge (ir_node *n, int pos) {
114 int *ba = get_backarray (n);
115 assert(ba && "can only set backedges at Phi, Filter, Block nodes.");
119 /* Returns true if n has backedges. */
120 bool has_backedges (ir_node *n) {
122 int *ba = get_backarray (n);
124 for (i = 0; i < get_irn_arity(n); i++)
125 if (ba[i]) return true;
129 /* Sets all backedge information to zero. */
130 void clear_backedges (ir_node *n) {
131 int i, rem = interprocedural_view;
133 interprocedural_view = 0;
134 ba = get_backarray (n);
136 for (i = 0; i < get_irn_arity(n); i++)
138 interprocedural_view = 1;
139 ba = get_backarray (n);
141 for (i = 0; i < get_irn_arity(n); i++)
143 interprocedural_view = rem;