3 * File name: ir/ana/irbackedge.c
4 * Purpose: Access function for backedges.
5 * Author: Goetz Lindenmaier
9 * Copyright: (c) 2002-2003 Universität Karlsruhe
10 * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
15 #include "irbackedge_t.h"
17 /*--------------------------------------------------------------------*/
18 /* Backedge information. */
19 /*--------------------------------------------------------------------*/
23 * Returns backarray if the node can have backedges, else returns
26 * Does not assert whether the backarray is correct -- use
29 static INLINE int *mere_get_backarray(ir_node *n) {
30 switch(get_irn_opcode(n)) {
32 if (!get_Block_matured(n)) return NULL;
33 if (interprocedural_view && n->attr.block.in_cg) {
34 assert(n->attr.block.cg_backedge && "backedge array not allocated!");
35 return n->attr.block.cg_backedge;
37 assert(n->attr.block.backedge && "backedge array not allocated!");
38 return n->attr.block.backedge;
42 assert(n->attr.phi_backedge && "backedge array not allocated!");
43 return n->attr.phi_backedge;
46 if (interprocedural_view) {
47 assert(n->attr.filter.backedge && "backedge array not allocated!");
48 return n->attr.filter.backedge;
57 * Returns backarray if the node can have backedges, else returns
60 static INLINE int *get_backarray(ir_node *n) {
61 int *ba = mere_get_backarray(n);
64 int bal = ARR_LEN(ba); /* avoid makro expansion in assertion. */
65 int inl = ARR_LEN(get_irn_in(n)) -1; /* Use get_irn_in -- sensitive to view! */
66 assert(bal == inl && "backedge array with faulty length");
73 * Returns true if node has no backarray, or
74 * if size of backarray == size of in array.
76 static INLINE bool legal_backarray (ir_node *n) {
77 int *ba = mere_get_backarray(n);
78 if (ba && (ARR_LEN(ba) != ARR_LEN(get_irn_in(n))-1)) /* Use get_irn_in -- sensitive to view! */
84 INLINE void fix_backedges(struct obstack *obst, ir_node *n) {
85 opcode opc = get_irn_opcode(n);
86 int *arr = mere_get_backarray(n);
87 if (ARR_LEN(arr) == ARR_LEN(get_irn_in(n))-1)
89 if (ARR_LEN(arr) != ARR_LEN(get_irn_in(n))-1) {
90 arr = new_backedge_arr(obst, ARR_LEN(get_irn_in(n))-1);
91 if (opc == iro_Phi) n->attr.phi_backedge = arr;
92 if ((opc == iro_Block) && !interprocedural_view)
93 n->attr.block.backedge = arr;
94 if ((opc == iro_Block) && interprocedural_view)
95 n->attr.block.cg_backedge = arr;
96 if (opc == iro_Filter) n->attr.filter.backedge = arr;
99 assert(legal_backarray(n));
100 /* @@@ more efficient in memory consumption, not possible with
101 array implementation.
102 if (ARR_LEN(arr) < ARR_LEN(get_irn_in(n))-1) {
103 ARR_SETLEN(int, arr, ARR_LEN(get_irn_in(n))-1);
107 /** Returns true if the predesessor pos is a backedge. */
108 bool is_backedge (ir_node *n, int pos) {
109 int *ba = get_backarray (n);
110 if (ba) return ba[pos];
114 /** Remarks that edge pos is a backedge. */
115 void set_backedge (ir_node *n, int pos) {
116 int *ba = get_backarray (n);
117 assert(ba && "can only set backedges at Phi, Filter, Block nodes.");
121 /** Remarks that edge pos is a backedge. */
122 void set_not_backedge (ir_node *n, int pos) {
123 int *ba = get_backarray (n);
124 assert(ba && "can only set backedges at Phi, Filter, Block nodes.");
128 /** Returns true if n has backedges. */
129 bool has_backedges (ir_node *n) {
131 int *ba = get_backarray (n);
133 for (i = 0; i < get_irn_arity(n); i++)
134 if (ba[i]) return true;
138 /** Sets all backedge information to zero. */
139 void clear_backedges (ir_node *n) {
140 int i, rem = interprocedural_view;
142 interprocedural_view = 0;
143 ba = get_backarray (n);
145 for (i = 0; i < get_irn_arity(n); i++)
147 interprocedural_view = 1;
148 ba = get_backarray (n);
150 for (i = 0; i < get_irn_arity(n); i++)
152 interprocedural_view = rem;