ia32: Simplify ia32_register_saved_by().
[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  */
25 #ifndef FIRM_BE_BEABI_H
26 #define FIRM_BE_BEABI_H
27
28 #include <stdbool.h>
29
30 #include "be_types.h"
31 #include "firm_types.h"
32
33 struct be_abi_call_flags_t {
34         bool try_omit_fp   : 1; /**< Try to omit the frame pointer. */
35         bool call_has_imm  : 1; /**< A call can take the callee's address as an
36                                      immediate. */
37 };
38
39 struct be_abi_callbacks_t {
40         /**
41          * Get the between type for that call.
42          * @param self The callback object.
43          * @return The between type of for that call.
44          */
45         ir_type *(*get_between_type)(ir_graph *irg);
46 };
47
48 /**
49  * Set the flags for a call.
50  * @param call          The call.
51  * @param flags         Some flags to be set.
52  * @param cb            The call callbacks for that call.
53  * @note                The ABI phase might change the flags due to analysis.
54  */
55 void be_abi_call_set_flags(be_abi_call_t *call, be_abi_call_flags_t flags, const be_abi_callbacks_t *cb);
56
57 /**
58  * Sets the number of bytes the stackframe is shrinked by the callee on return
59  */
60 void be_abi_call_set_pop(be_abi_call_t *call, int pop);
61
62 /**
63  * The ABI can change when we call a function vs. when we have
64  * been called.
65  */
66 typedef enum {
67         ABI_CONTEXT_CALLEE = 1 << 0,
68         ABI_CONTEXT_CALLER = 1 << 1,
69         ABI_CONTEXT_BOTH   = ABI_CONTEXT_CALLEE | ABI_CONTEXT_CALLER
70 } be_abi_context_t;
71
72 /**
73  * Record the that ABI transmits call argument pos on the stack. Modifies the abi object.
74  *
75  * @param call          the abi call object
76  * @param pos           the parameter position
77  * @param load_mode     load the parameter with this mode (if the parameter mode is different from this mode a Conv is inserted)
78  * @param alignment     stack alignment for the parameter on the current architecture
79  * @param space_before  size of allocated additional space before the parameter
80  * @param space_after   size of allocated additional space after the parameter
81  */
82 void be_abi_call_param_stack(be_abi_call_t *call, int pos, ir_mode *load_mode,
83                              unsigned alignment, unsigned space_before,
84                              unsigned space_after, be_abi_context_t context);
85
86 /**
87  * Record the that ABI transmits call argument pos in the given register.
88  *
89  * @param call          the abi call object
90  * @param pos           the parameter position
91  * @param reg           the register used
92  */
93 void be_abi_call_param_reg(be_abi_call_t *call, int pos,
94                            const arch_register_t *reg,
95                            be_abi_context_t context);
96
97 /**
98  * Record the that ABI transmits return value pos in the given register.
99  *
100  * @param call          the abi call object
101  * @param pos           the return value position
102  * @param reg           the register used
103  */
104 void be_abi_call_res_reg(be_abi_call_t *call, int pos,
105                          const arch_register_t *reg,
106                          be_abi_context_t context);
107
108 /**
109  * Get the flags of a ABI call object.
110  * Note that the flags must not be the same as set by be_abi_call_set_flags(). Analysis may have
111  * altered several flags, so getting them from the call object is always a good idea.
112  * @param call The call object.
113  * @return The flags.
114  */
115 be_abi_call_flags_t be_abi_call_get_flags(const be_abi_call_t *call);
116
117 void be_abi_introduce(ir_graph *irg);
118
119 #endif