61efa881a1bc9838c5e1d7a0db56ae5117a27ba0
[libfirm] / ir / be / bemachnode.h
1 /*
2  * Copyright (C) 1995-2007 University of Karlsruhe.  All right reserved.
3  *
4  * This file is part of libFirm.
5  *
6  * This file may be distributed and/or modified under the terms of the
7  * GNU General Public License version 2 as published by the Free Software
8  * Foundation and appearing in the file LICENSE.GPL included in the
9  * packaging of this file.
10  *
11  * Licensees holding valid libFirm Professional Edition licenses may use
12  * this file in accordance with the libFirm Commercial License.
13  * Agreement provided with the Software.
14  *
15  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17  * PURPOSE.
18  */
19
20 /**
21  * Support for machine nodes with machine operands.
22  *
23  * @author Michael Beck
24  */
25 #ifndef _BEMACHNODES_H
26 #define _BEMACHNODES_H
27
28 #include "firm_types.h"
29
30 /*
31  * Machine nodes can have machine operands as inputs.
32  * Machine operands are trees of other machine operands.
33  * The leafs of machine operands are normal Firm nodes
34  * or a machine operand with arity 0.
35  *
36  * The arity of a machine node is the number of leafs
37  * that are NOT machine operands.
38  *
39  * For instance Add(x, Const) have the arity 1 if Const is a
40  * machine operand, Add(x, ADR(b, i)) have arity 3.
41  *
42  * We simulate the the normal concept of get_irn_n/set_irn_n.
43  * Instead of the node machine handle are used which are just
44  * caches for the leaf positions of a machine node.
45  * This means, it is only possible to manipulate the leafs!
46  * Do not mix _mirn_ and _irn_ calls or terrible things can happen :-)
47  *
48  * Note further that currently the number of ins for a machine
49  * instruction is limited to 8 + arity of Firm node which means
50  * up to 8 registers can be added due to machine operands.
51  *
52  * Moreover machine handles must be destroyed yet...
53  *
54  * The convenience functions create the handle and drop it at the end.
55  * as operands are seldom, they have a complexity of O(#predecessors)
56  * which is near to O(1) for most node but use them seldom ...
57  */
58
59 /**
60  * The machine handle. A cache to access and set
61  * the predecessors (leafs) of a machine node.
62  */
63 typedef ir_node *** mirn_handle;
64
65 /**
66  * Returns the machine handle for a machine node with machine operands.
67  * The order of the predecessors in this handle is not guaranteed, except that
68  * lists of operands as predecessors of Block or arguments of a Call are
69  * consecutive.
70  */
71 mirn_handle get_mirn_in(ir_node *n);
72
73 /** Frees a machine handle. */
74 void free_mirn_in(mirn_handle h);
75
76 /** Get the pos-th predecessor of a machine node represented by it's
77     handle.. */
78 ir_node *get_mirn_n(mirn_handle h, int pos);
79
80 /** Convenience: Get the pos-th predecessor of a machine node. */
81 ir_node *_get_mirn_n(ir_node *n, int pos);
82
83 /** Set the n-th predecessor of a machine node represented by it's
84     handle.. */
85 void set_mirn_n(mirn_handle h, int pos, ir_node *n);
86
87 /* Convenience: Set the pos-th predecessor of a machine node. */
88 void _set_mirn_n(ir_node *irn, int pos, ir_node *n);
89
90 /** Returns the arity (in terms of inputs) of a machine node represented by it's
91     handle. */
92 int get_mirn_arity(mirn_handle h);
93
94 /* Convenience: Returns the arity of a machine node. */
95 int _get_mirn_arity(ir_node *n);
96
97 #endif /* _BEMACHNODES_H */