Fixed memory leak, fixed some typos, add some doxygen docu.
[libfirm] / ir / be / beabihelper.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       Helper functions for handling ABI constraints in the code
23  *              selection phase.
24  * @author      Matthias Braun
25  * @version     $Id$
26  */
27 #ifndef FIRM_BE_BEABI_HELPER_H
28 #define FIRM_BE_BEABI_HELPER_H
29
30 #include "firm_types.h"
31 #include "be_types.h"
32 #include "bearch.h"
33
34 typedef struct beabi_helper_env_t beabi_helper_env_t;
35
36 /**
37  * Creates a helper object for the ABI constraint handling.
38  */
39 beabi_helper_env_t *be_abihelper_prepare(ir_graph *irg);
40
41 /**
42  * Terminates a helper object for the ABI constraint handling.
43  */
44 void be_abihelper_finish(beabi_helper_env_t *env);
45
46 /**
47  * Mark a registers value at the beginning of the function as significant.
48  * This is necessary for things like:
49  *  - Callee-Save registers (we need to restore that value at the end)
50  *  - Parameters passed in registers
51  *  - stack pointer, base pointer, ...
52  * It is possible to specify additional irn flags (useful to mark a value
53  * as ignore or produces_sp).
54  */
55 void be_prolog_add_reg(beabi_helper_env_t *env, const arch_register_t *reg,
56                        arch_register_req_type_t flags);
57
58 /**
59  * Creates a start node.
60  * Must be called after all prolog_add_reg calls
61  */
62 ir_node *be_prolog_create_start(beabi_helper_env_t *env, dbg_info *dbgi,
63                                 ir_node *block);
64
65 /**
66  * Creates a barrier node which lets all registers specified by prolog_add_reg
67  * pass through
68  */
69 ir_node *be_prolog_create_barrier(beabi_helper_env_t *env, ir_node *block);
70
71 /**
72  * Get "value" of a register.
73  * This usually creates a Proj node for the start-node or barrier-node.
74  * Or returns the value set by a abi_helper_set_reg_value call
75  */
76 ir_node *be_prolog_get_reg_value(beabi_helper_env_t *env,
77                                  const arch_register_t *reg);
78
79 ir_node *be_prolog_get_memory(beabi_helper_env_t *env);
80
81 /**
82  * Set current register value.
83  */
84 void be_prolog_set_reg_value(beabi_helper_env_t *env,
85                              const arch_register_t *reg, ir_node *value);
86
87 void be_prolog_set_memory(beabi_helper_env_t *env, ir_node *value);
88
89 /**
90  * Set value of register at the end of the function. Necessary for:
91  *  - Callee-save registers
92  *  - Return values in registers
93  *  - stack pointer, base pointer
94  */
95 void be_epilog_add_reg(beabi_helper_env_t *env, const arch_register_t *reg,
96                        arch_register_req_type_t flags, ir_node *value);
97
98 void be_epilog_set_reg_value(beabi_helper_env_t *env,
99                              const arch_register_t *reg, ir_node *value);
100
101 ir_node *be_epilog_get_reg_value(beabi_helper_env_t *env,
102                              const arch_register_t *reg);
103
104 void be_epilog_set_memory(beabi_helper_env_t *env, ir_node *value);
105
106 ir_node *be_epilog_get_memory(beabi_helper_env_t *env);
107
108 void be_epilog_begin(beabi_helper_env_t *env);
109
110 ir_node *be_epilog_create_barrier(beabi_helper_env_t *env, ir_node *block);
111
112 /**
113  * Create return node and finishes epilog handling
114  */
115 ir_node *be_epilog_create_return(beabi_helper_env_t *env, dbg_info *dbgi,
116                                  ir_node *block);
117
118 /**
119  * Adds a X->Proj->Keep for each output value of X which has no Proj yet
120  */
121 void be_add_missing_keeps(ir_graph *irg);
122
123 /**
124  * Collect firm nodes that will probably modify the stack.
125  * Put them into an order that respects all their dependencies.
126  */
127 void be_collect_stacknodes(beabi_helper_env_t *env);
128
129 /**
130  * return node that should produce the predecessor stack node in a block.
131  * returns NULL if there's no predecessor in the current block.
132  */
133 ir_node *be_get_stack_pred(const beabi_helper_env_t *env, const ir_node *node);
134
135 #endif