1 #include "bemachnode.h"
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);
9 for (i = j = 0; i <= l; ++i) {
10 if (is_irn_machine_operand(ins[i]))
11 j += fill_arr(ins[i], &res[j]);
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
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);
30 res = NEW_ARR_F(ir_node **, lr);
32 for (i = j = 0; i <= l; ++i) {
33 if (is_irn_machine_operand(ins[i]))
34 j += fill_arr(ins[i], &res[j]);
39 assert(j > lr && "to many machine predecessors");
44 /* Frees a machine handle. */
45 void free_mirn_in(mirn_handle h) {
49 /* Get the pos-th predecessor of a machine node represented by it's
51 ir_node *get_mirn_n(mirn_handle h, int pos) {
52 assert(-1 <= pos && pos < ARR_LEN(h) - 1);
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);
64 /* Set the pos-th predecessor of a machine node represented by it's
66 void set_mirn_n(mirn_handle h, int pos, ir_node *n) {
67 assert(-1 <= pos && pos < ARR_LEN(h) - 1);
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);
78 /* Returns the arity of a machine node represented by it's
80 int get_mirn_arity(mirn_handle h) {
81 return ARR_LEN(h) - 1;
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);
89 for (i = j = 0; i <= l; ++i) {
90 if (is_irn_machine_operand(ins[i]))
91 j += arrity_of_op(ins[i]);
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);
103 for (i = j = 0; i <= l; ++i) {
104 if (is_irn_machine_operand(ins[i]))
105 j += arrity_of_op(ins[i]);