Implement access functions for machine nodes with machine operands
[libfirm] / ir / be / bemachnode.h
1 /**
2  * Support for machine nodes with machine operands.
3  *
4  * @author Michael Beck
5  */
6 #ifndef _BEMACHNODES_H
7 #define _BEMACHNODES_H
8
9 #include "firm_types.h"
10
11 /*
12  * Machine nodes can have machine operands as inputs.
13  * Machine operands are trees of other machine operands.
14  * The leafs of machine operands are normal Firm nodes
15  * or a machine operand with arity 0.
16  *
17  * The arity of a machine node is the number of leafs
18  * that are NOT machine operands.
19  *
20  * For instance Add(x, Const) have the arity 1 if Const is a
21  * machine operand, Add(x, ADR(b, i)) have arity 3.
22  *
23  * We simulate the the normal concept of get_irn_n/set_irn_n.
24  * Instead of the node machine handle are used which are just
25  * caches for the leaf positions of a machine node.
26  * This means, it is only possible to manipulate the leafs!
27  * Do not mix _mirn_ and _irn_ calls or terrible things can happen :-)
28  *
29  * Note further that currently the number of ins for a machine
30  * instruction is limited to 8 + arity of Firm node which means
31  * up to 8 registers can be added due to machine operands.
32  *
33  * Moreover machine handles must be destroyed yet...
34  *
35  * The convenience functions create the handle and drop it at the end.
36  * as operands are seldom, they have a complexity of O(#predecessors)
37  * which is near to O(1) for most node but use them seldom ...
38  */
39
40 /**
41  * The machine handle. A cache to access and set
42  * the predecessors (leafs) of a machine node.
43  */
44 typedef ir_node *** mirn_handle;
45
46 /**
47  * Returns the machine handle for a machine node with machine operands.
48  * The order of the predecessors in this handle is not guaranteed, except that
49  * lists of operands as predecessors of Block or arguments of a Call are
50  * consecutive.
51  */
52 mirn_handle get_mirn_in(ir_node *n);
53
54 /** Frees a machine handle. */
55 void free_mirn_in(mirn_handle h);
56
57 /** Get the pos-th predecessor of a machine node represented by it's
58     handle.. */
59 ir_node *get_mirn_n(mirn_handle h, int pos);
60
61 /** Convenience: Get the pos-th predecessor of a machine node. */
62 ir_node *_get_mirn_n(ir_node *n, int pos);
63
64 /** Set the n-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
68 /* Convenience: Set the pos-th predecessor of a machine node. */
69 void _set_mirn_n(ir_node *irn, int pos, ir_node *n);
70
71 /** Returns the arity (in terms of inputs) of a machine node represented by it's
72     handle. */
73 int get_mirn_arity(mirn_handle h);
74
75 /* Convenience: Returns the arity of a machine node. */
76 int _get_mirn_arity(ir_node *n);
77
78 #endif /* _BEMACHNODES_H */