- new spillslots dump phase
[libfirm] / ir / be / bemachnode.c
1 #include "bemachnode.h"
2 #include "irnode_t.h"
3
4 /** Helper: fills in the array for machine ops */
5 static int fill_arr(ir_node *op, mirn_handle res) {
6         ir_node **ins = get_irn_in(op);
7         int i, j, l = ARR_LEN(ins);
8
9         for (i = j = 0; i <= l; ++i) {
10                 if (is_irn_machine_operand(ins[i]))
11                         j += fill_arr(ins[i], &res[j]);
12                 else
13                         res[j++] = &ins[i];
14         }
15         return j;
16 }
17
18 /*
19  * Returns the machine handle for a machine node with machine operands.
20  * The order of the predecessors in this handle is not guaranteed, except that
21  * lists of operands as predecessors of Block or arguments of a Call are
22  * consecutive.
23  */
24 mirn_handle get_mirn_in(ir_node *n) {
25         ir_node **ins = get_irn_in(n);
26         mirn_handle res = NULL;
27         int i, j, l = ARR_LEN(ins);
28         int lr = l + 8;
29
30         res = NEW_ARR_F(ir_node **, lr);
31
32         for (i = j = 0; i <= l; ++i) {
33                 if (is_irn_machine_operand(ins[i]))
34                         j += fill_arr(ins[i], &res[j]);
35                 else
36                         res[j++] = &ins[i];
37         }
38
39         assert(j > lr && "to many machine predecessors");
40
41         return res;
42 }
43
44 /* Frees a machine handle. */
45 void free_mirn_in(mirn_handle h) {
46         DEL_ARR_F(h);
47 }
48
49 /* Get the pos-th predecessor of a machine node represented by it's
50     handle. */
51 ir_node *get_mirn_n(mirn_handle h, int pos) {
52         assert(-1 <= pos && pos < ARR_LEN(h) - 1);
53         return *(h[pos + 1]);
54 }
55
56 /* Get the pos-th predecessor of a machine node. */
57 ir_node *_get_mirn_n(ir_node *n, int pos) {
58         mirn_handle h = get_mirn_in(n);
59         ir_node *res = get_mirn_n(h, pos);
60         free_mirn_in(h);
61         return res;
62 }
63
64 /* Set the pos-th predecessor of a machine node represented by it's
65     handle. */
66 void set_mirn_n(mirn_handle h, int pos, ir_node *n) {
67         assert(-1 <= pos && pos < ARR_LEN(h) - 1);
68         *(h[pos + 1]) = n;
69 }
70
71 /* Set the pos-th predecessor of a machine node. */
72 void _set_mirn_n(ir_node *irn, int pos, ir_node *n) {
73         mirn_handle h = get_mirn_in(irn);
74         set_mirn_n(h, pos, n);
75         free_mirn_in(h);
76 }
77
78 /* Returns the arity of a machine node represented by it's
79     handle. */
80 int get_mirn_arity(mirn_handle h) {
81         return ARR_LEN(h) - 1;
82 }
83
84 /** Helper: calculate the arity for a machine ops */
85 static int arrity_of_op(ir_node *op) {
86         ir_node **ins = get_irn_in(op);
87         int i, j, l = ARR_LEN(ins);
88
89         for (i = j = 0; i <= l; ++i) {
90                 if (is_irn_machine_operand(ins[i]))
91                         j += arrity_of_op(ins[i]);
92                 else
93                         ++j;
94         }
95         return j;
96 }
97
98 /* Returns the arity of a machine node. */
99 int _get_mirn_arity(ir_node *n) {
100         ir_node **ins = get_irn_in(n);
101         int i, j, l = ARR_LEN(ins);
102
103         for (i = j = 0; i <= l; ++i) {
104                 if (is_irn_machine_operand(ins[i]))
105                         j += arrity_of_op(ins[i]);
106                 else
107                         ++j;
108         }
109
110         return j;
111 }