beifg: Factorise code to count interference components.
[libfirm] / ir / be / beabi.h
1 /*
2  * This file is part of libFirm.
3  * Copyright (C) 2012 University of Karlsruhe.
4  */
5
6 /**
7  * @file
8  * @brief       Backend ABI implementation.
9  * @author      Sebastian Hack
10  */
11 #ifndef FIRM_BE_BEABI_H
12 #define FIRM_BE_BEABI_H
13
14 #include <stdbool.h>
15
16 #include "be_types.h"
17 #include "firm_types.h"
18
19 struct be_abi_call_flags_t {
20         bool try_omit_fp   : 1; /**< Try to omit the frame pointer. */
21         bool call_has_imm  : 1; /**< A call can take the callee's address as an
22                                      immediate. */
23 };
24
25 struct be_abi_callbacks_t {
26         /**
27          * Get the between type for that call.
28          * @param self The callback object.
29          * @return The between type of for that call.
30          */
31         ir_type *(*get_between_type)(ir_graph *irg);
32 };
33
34 /**
35  * Set the flags for a call.
36  * @param call          The call.
37  * @param flags         Some flags to be set.
38  * @param cb            The call callbacks for that call.
39  * @note                The ABI phase might change the flags due to analysis.
40  */
41 void be_abi_call_set_flags(be_abi_call_t *call, be_abi_call_flags_t flags, const be_abi_callbacks_t *cb);
42
43 /**
44  * Sets the number of bytes the stackframe is shrinked by the callee on return
45  */
46 void be_abi_call_set_pop(be_abi_call_t *call, int pop);
47
48 /**
49  * The ABI can change when we call a function vs. when we have
50  * been called.
51  */
52 typedef enum {
53         ABI_CONTEXT_CALLEE = 1 << 0,
54         ABI_CONTEXT_CALLER = 1 << 1,
55         ABI_CONTEXT_BOTH   = ABI_CONTEXT_CALLEE | ABI_CONTEXT_CALLER
56 } be_abi_context_t;
57
58 /**
59  * Record the that ABI transmits call argument pos on the stack. Modifies the abi object.
60  *
61  * @param call          the abi call object
62  * @param pos           the parameter position
63  * @param load_mode     load the parameter with this mode (if the parameter mode is different from this mode a Conv is inserted)
64  * @param alignment     stack alignment for the parameter on the current architecture
65  * @param space_before  size of allocated additional space before the parameter
66  * @param space_after   size of allocated additional space after the parameter
67  */
68 void be_abi_call_param_stack(be_abi_call_t *call, int pos, ir_mode *load_mode,
69                              unsigned alignment, unsigned space_before,
70                              unsigned space_after, be_abi_context_t context);
71
72 /**
73  * Record the that ABI transmits call argument pos in the given register.
74  *
75  * @param call          the abi call object
76  * @param pos           the parameter position
77  * @param reg           the register used
78  */
79 void be_abi_call_param_reg(be_abi_call_t *call, int pos,
80                            const arch_register_t *reg,
81                            be_abi_context_t context);
82
83 /**
84  * Record the that ABI transmits return value pos in the given register.
85  *
86  * @param call          the abi call object
87  * @param pos           the return value position
88  * @param reg           the register used
89  */
90 void be_abi_call_res_reg(be_abi_call_t *call, int pos,
91                          const arch_register_t *reg,
92                          be_abi_context_t context);
93
94 /**
95  * Get the flags of a ABI call object.
96  * Note that the flags must not be the same as set by be_abi_call_set_flags(). Analysis may have
97  * altered several flags, so getting them from the call object is always a good idea.
98  * @param call The call object.
99  * @return The flags.
100  */
101 be_abi_call_flags_t be_abi_call_get_flags(const be_abi_call_t *call);
102
103 void be_abi_introduce(ir_graph *irg);
104
105 #endif