isolated optimizations in cgana to run them separately.
[libfirm] / ir / ana / irbackedge.c
1 /* Copyright (C) 2002 by Universitaet Karlsruhe
2 ** All rights reserved.
3 **
4 ** Authors:  Goetz Lindenmaier
5 **
6 ** irbackedges.c  Access function for backedges.
7 **
8 */
9
10 /* $Id$ */
11
12 #include "irnode_t.h"
13
14 /**********************************************************************/
15 /** Backedge information.                                            **/
16 /**********************************************************************/
17
18
19 /* Returns backarray if the node can have backedges.  Else returns
20    NULL. */
21 inline int *get_backarray(ir_node *n) {
22   switch(get_irn_opcode(n)) {
23   case iro_Block:
24     if (interprocedural_view && n->attr.block.in_cg) {
25       assert(n->attr.block.cg_backedge && "backedge array not allocated!");
26       return n->attr.block.cg_backedge;
27     } else {
28       assert(n->attr.block.backedge && "backedge array not allocated!");
29       return n->attr.block.backedge;
30     }
31     break;
32   case iro_Phi:
33       assert(n->attr.phi_backedge && "backedge array not allocated!");
34     return n->attr.phi_backedge;
35     break;
36   case iro_Filter:
37     if (interprocedural_view) {
38       assert(n->attr.filter.backedge && "backedge array not allocated!");
39       return n->attr.filter.backedge;
40     }
41     break;
42   default: ;
43   }
44   return NULL;
45 }
46
47 /* Returns true if the predesessor pos is a backedge. */
48 bool is_backedge (ir_node *n, int pos) {
49   int *ba = get_backarray (n);
50   if (ba) return ba[pos];
51   return false;
52 }
53
54 /* Remarks that edge pos is a backedge. */
55 void set_backedge (ir_node *n, int pos) {
56   int *ba = get_backarray (n);
57   assert(ba && "can only set backedges at Phi, Filter, Block nodes.");
58   ba[pos] = 1;
59 }
60
61 /* Remarks that edge pos is a backedge. */
62 void set_not_backedge (ir_node *n, int pos) {
63   int *ba = get_backarray (n);
64   assert(ba && "can only set backedges at Phi, Filter, Block nodes.");
65   ba[pos] = 0;
66 }
67
68 /* Returns true if n has backedges. */
69 bool has_backedges (ir_node *n) {
70   int i;
71   int *ba = get_backarray (n);
72   if (ba)
73     for (i = 0; i < get_irn_arity(n); i++)
74       if (ba[i]) return true;
75   return false;
76 }
77
78 /* Sets all backedge information to zero. */
79 void clear_backedges (ir_node *n) {
80   int i, rem = interprocedural_view;
81   int *ba;
82   interprocedural_view = 0;
83   ba = get_backarray (n);
84   if (ba)
85     for (i = 0; i < get_irn_arity(n); i++)
86       ba[i] = 0;
87   interprocedural_view = 1;
88   ba = get_backarray (n);
89   if (ba)
90     for (i = 0; i < get_irn_arity(n); i++)
91       ba[i] = 0;
92   interprocedural_view = rem;
93 }