factor out code for address of register param taken
[libfirm] / ir / be / beabi.h
1 /*
2  * Copyright (C) 1995-2008 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  * @file
22  * @brief       Backend ABI implementation.
23  * @author      Sebastian Hack
24  * @version     $Id$
25  */
26 #ifndef FIRM_BE_BEABI_H
27 #define FIRM_BE_BEABI_H
28
29 #include "firm_types.h"
30
31 #include "pset.h"
32 #include "pmap.h"
33 #include "bitset.h"
34
35 #include "be.h"
36 #include "beirg.h"
37 #include "bearch.h"
38 #include "beabi.h"
39 #include "beabihelper.h"
40
41 struct be_abi_call_flags_bits_t {
42         unsigned store_args_sequential  : 1;  /**< Use sequential stores for arguments. */
43         unsigned try_omit_fp            : 1;  /**< Try to omit the frame pointer. */
44         unsigned fp_free                : 1;  /**< The function can use any register as frame pointer. */
45         unsigned call_has_imm           : 1;  /**< A call can take the callee's address as an immediate. */
46         unsigned irg_is_leaf            : 1;  /**< 1, if the IRG is a leaf function. */
47         unsigned frame_is_setup_on_call : 1;  /**< Set to one, if there is already enough room on the stack for call args. */
48 };
49
50 union be_abi_call_flags_t {
51         be_abi_call_flags_bits_t bits;
52         unsigned val;
53 };
54
55 struct be_abi_callbacks_t {
56         /**
57          * Get the between type for that call.
58          * @param self The callback object.
59          * @return The between type of for that call.
60          */
61         ir_type *(*get_between_type)(ir_graph *irg);
62 };
63
64 /**
65  * Set the flags for a call.
66  * @param call          The call.
67  * @param flags         Some flags to be set.
68  * @param cb            The call callbacks for that call.
69  * @note                The ABI phase might change the flags due to analysis.
70  */
71 void be_abi_call_set_flags(be_abi_call_t *call, be_abi_call_flags_t flags, const be_abi_callbacks_t *cb);
72
73 /**
74  * Sets the number of bytes the stackframe is shrinked by the callee on return
75  */
76 void be_abi_call_set_pop(be_abi_call_t *call, int pop);
77
78 /**
79  * Set register class for call address.
80  * @param call      The call.
81  * @param cls       The register class for call address.
82  */
83 void be_abi_call_set_call_address_reg_class(be_abi_call_t *call, const arch_register_class_t *cls);
84
85 /**
86  * The ABI can change when we call a function vs. when we have
87  * been called.
88  */
89 typedef enum {
90         ABI_CONTEXT_CALLEE = 1 << 0,
91         ABI_CONTEXT_CALLER = 1 << 1,
92         ABI_CONTEXT_BOTH   = ABI_CONTEXT_CALLEE | ABI_CONTEXT_CALLER
93 } be_abi_context_t;
94
95 /**
96  * Record the that ABI transmits call argument pos on the stack. Modifies the abi object.
97  *
98  * @param call          the abi call object
99  * @param pos           the parameter position
100  * @param load_mode     load the parameter with this mode (if the parameter mode is different from this mode a Conv is inserted)
101  * @param alignment     stack alignment for the parameter on the current architecture
102  * @param space_before  size of allocated additional space before the parameter
103  * @param space_after   size of allocated additional space after the parameter
104  */
105 void be_abi_call_param_stack(be_abi_call_t *call, int pos, ir_mode *load_mode,
106                              unsigned alignment, unsigned space_before,
107                              unsigned space_after, be_abi_context_t context);
108
109 /**
110  * Record the that ABI transmits call argument pos in the given register.
111  *
112  * @param call          the abi call object
113  * @param pos           the parameter position
114  * @param reg           the register used
115  */
116 void be_abi_call_param_reg(be_abi_call_t *call, int pos,
117                            const arch_register_t *reg,
118                            be_abi_context_t context);
119
120 /**
121  * Record the that ABI transmits return value pos in the given register.
122  *
123  * @param call          the abi call object
124  * @param pos           the return value position
125  * @param reg           the register used
126  */
127 void be_abi_call_res_reg(be_abi_call_t *call, int pos,
128                          const arch_register_t *reg,
129                          be_abi_context_t context);
130
131 /**
132  * Get the flags of a ABI call object.
133  * Note that the flags must not be the same as set by be_abi_call_set_flags(). Analysis may have
134  * altered several flags, so getting them from the call object is always a good idea.
135  * @param call The call object.
136  * @return The flags.
137  */
138 be_abi_call_flags_t be_abi_call_get_flags(const be_abi_call_t *call);
139
140 /**
141  * Get the method type of an ABI call object.
142  * @param call The call object.
143  * @return The method type for that call object.
144  */
145 ir_type *be_abi_call_get_method_type(const be_abi_call_t *call);
146
147 void be_abi_introduce(ir_graph *irg);
148
149 void be_abi_free(ir_graph *irg);
150
151 #endif