1 #include "bemachnode.h"
4 typedef ir_node *** mirn_handle;
6 /** Helper: fills in the array for machine ops */
7 static int fill_arr(ir_node *op, mirn_handle res) {
8 ir_node **ins = get_irn_in(op);
9 int i, j, l = ARR_LEN(ins);
11 for (i = j = 0; i <= l; ++i) {
12 if (is_irn_machine_operand(ins[i]))
13 j += fill_arr(ins[i], &res[j]);
21 * Returns the machine handle for a machine node with machine operands.
22 * The order of the predecessors in this handle is not guaranteed, except that
23 * lists of operands as predecessors of Block or arguments of a Call are
26 mirn_handle get_mirn_in(ir_node *n) {
27 ir_node **ins = get_irn_in(n);
28 mirn_handle res = NULL;
29 int i, j, l = ARR_LEN(ins);
32 res = NEW_ARR_F(ir_node **, lr);
34 for (i = j = 0; i <= l; ++i) {
35 if (is_irn_machine_operand(ins[i]))
36 j += fill_arr(ins[i], &res[j]);
41 assert(j > lr && "to many machine predecessors");
46 /* Frees a machine handle. */
47 void free_mirn_in(mirn_handle h) {
51 /* Get the pos-th predecessor of a machine node represented by it's
53 ir_node *get_mirn_n(mirn_handle h, int pos) {
54 assert(-1 <= pos && pos < ARR_LEN(h) - 1);
58 /* Get the pos-th predecessor of a machine node. */
59 ir_node *_get_mirn_n(ir_node *n, int pos) {
60 mirn_handle h = get_mirn_in(n);
61 ir_node *res = get_mirn_n(h, pos);
66 /* Set the pos-th predecessor of a machine node represented by it's
68 void set_mirn_n(mirn_handle h, int pos, ir_node *n) {
69 assert(-1 <= pos && pos < ARR_LEN(h) - 1);
73 /* Set the pos-th predecessor of a machine node. */
74 void _set_mirn_n(ir_node *irn, int pos, ir_node *n) {
75 mirn_handle h = get_mirn_in(irn);
76 set_mirn_n(h, pos, n);
80 /* Returns the arity of a machine node represented by it's
82 int get_mirn_arity(mirn_handle h) {
83 return ARR_LEN(h) - 1;
86 /** Helper: calculate the arity for a machine ops */
87 static int arrity_of_op(ir_node *op) {
88 ir_node **ins = get_irn_in(op);
89 int i, j, l = ARR_LEN(ins);
91 for (i = j = 0; i <= l; ++i) {
92 if (is_irn_machine_operand(ins[i]))
93 j += arrity_of_op(ins[i]);
100 /* Returns the arity of a machine node. */
101 int _get_mirn_arity(ir_node *n) {
102 ir_node **ins = get_irn_in(n);
103 int i, j, l = ARR_LEN(ins);
105 for (i = j = 0; i <= l; ++i) {
106 if (is_irn_machine_operand(ins[i]))
107 j += arrity_of_op(ins[i]);